PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
/**
|
|
|
|
* PressThis App
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
( function( $, window ) {
|
|
|
|
var PressThis = function() {
|
|
|
|
var editor,
|
|
|
|
saveAlert = false,
|
2015-03-04 20:29:25 +01:00
|
|
|
textarea = document.createElement( 'textarea' ),
|
2015-03-06 23:57:26 +01:00
|
|
|
sidebarIsOpen = false,
|
2015-03-09 22:49:28 +01:00
|
|
|
settings = window.wpPressThisConfig || {},
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
data = window.wpPressThisData || {},
|
|
|
|
smallestWidth = 128,
|
|
|
|
hasSetFocus = false,
|
|
|
|
catsCache = [],
|
2015-03-06 23:57:26 +01:00
|
|
|
isOffScreen = 'is-off-screen',
|
|
|
|
isHidden = 'is-hidden',
|
|
|
|
offscreenHidden = isOffScreen + ' ' + isHidden,
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
transitionEndEvent = ( function() {
|
|
|
|
var style = document.documentElement.style;
|
|
|
|
|
|
|
|
if ( typeof style.transition !== 'undefined' ) {
|
|
|
|
return 'transitionend';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof style.WebkitTransition !== 'undefined' ) {
|
|
|
|
return 'webkitTransitionEnd';
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}() );
|
|
|
|
|
|
|
|
/* ***************************************************************
|
|
|
|
* HELPER FUNCTIONS
|
|
|
|
*************************************************************** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulates our PHP __() gettext function, powered by the strings exported in pressThisL10n.
|
|
|
|
*
|
|
|
|
* @param key string Key of the string to be translated, as found in pressThisL10n.
|
|
|
|
* @returns string Original or translated string, or empty string if no key.
|
|
|
|
*/
|
|
|
|
function __( key ) {
|
|
|
|
if ( key && window.pressThisL10n ) {
|
|
|
|
return window.pressThisL10n[key] || key;
|
|
|
|
}
|
|
|
|
|
|
|
|
return key || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strips HTML tags
|
|
|
|
*
|
|
|
|
* @param string string Text to have the HTML tags striped out of.
|
|
|
|
* @returns string Stripped text.
|
|
|
|
*/
|
|
|
|
function stripTags( string ) {
|
|
|
|
string = string || '';
|
|
|
|
|
|
|
|
return string
|
|
|
|
.replace( /<!--[\s\S]*?(-->|$)/g, '' )
|
|
|
|
.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
|
2015-03-04 20:29:25 +01:00
|
|
|
.replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-04 20:29:25 +01:00
|
|
|
* Strip HTML tags and convert HTML entities.
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
*
|
|
|
|
* @param text string Text.
|
|
|
|
* @returns string Sanitized text.
|
|
|
|
*/
|
|
|
|
function sanitizeText( text ) {
|
2015-03-09 22:49:28 +01:00
|
|
|
var _text = stripTags( text );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
try {
|
|
|
|
textarea.innerHTML = _text;
|
|
|
|
_text = stripTags( textarea.value );
|
|
|
|
} catch ( er ) {}
|
|
|
|
|
|
|
|
return _text;
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow only HTTP or protocol relative URLs.
|
|
|
|
*
|
|
|
|
* @param url string The URL.
|
|
|
|
* @returns string Processed URL.
|
|
|
|
*/
|
|
|
|
function checkUrl( url ) {
|
|
|
|
url = $.trim( url || '' );
|
|
|
|
|
|
|
|
if ( /^(?:https?:)?\/\//.test( url ) ) {
|
|
|
|
url = stripTags( url );
|
|
|
|
return url.replace( /["\\]+/g, '' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show UX spinner
|
|
|
|
*/
|
|
|
|
function showSpinner() {
|
|
|
|
$( '#spinner' ).addClass( 'show' );
|
|
|
|
$( '.post-actions button' ).each( function() {
|
|
|
|
$( this ).attr( 'disabled', 'disabled' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide UX spinner
|
|
|
|
*/
|
|
|
|
function hideSpinner() {
|
|
|
|
$( '#spinner' ).removeClass( 'show' );
|
|
|
|
$( '.post-actions button' ).each( function() {
|
|
|
|
$( this ).removeAttr( 'disabled' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:17:26 +01:00
|
|
|
/**
|
|
|
|
* Prepare the form data for saving.
|
2015-03-08 17:27:28 +01:00
|
|
|
*/
|
2015-03-07 02:17:26 +01:00
|
|
|
function prepareFormData() {
|
2015-03-13 17:57:26 +01:00
|
|
|
var $form = $( '#pressthis-form' ),
|
|
|
|
$input = $( '<input type="hidden" name="post_category[]" value="">' );
|
|
|
|
|
2015-03-07 02:17:26 +01:00
|
|
|
editor && editor.save();
|
|
|
|
|
|
|
|
$( '#post_title' ).val( sanitizeText( $( '#title-container' ).text() ) );
|
|
|
|
|
|
|
|
// Make sure to flush out the tags with tagBox before saving
|
|
|
|
if ( window.tagBox ) {
|
|
|
|
$( 'div.tagsdiv' ).each( function() {
|
|
|
|
window.tagBox.flushTags( this, false, 1 );
|
|
|
|
} );
|
|
|
|
}
|
2015-03-13 17:57:26 +01:00
|
|
|
|
|
|
|
// Get selected categories
|
|
|
|
$( '.categories-select .category' ).each( function( i, element ) {
|
|
|
|
var $cat = $( element );
|
|
|
|
|
|
|
|
if ( $cat.hasClass( 'selected' ) ) {
|
|
|
|
// Have to append a node as we submit the actual form on preview
|
|
|
|
$form.append( $input.clone().val( $cat.attr( 'data-term-id' ) || '' ) );
|
|
|
|
}
|
|
|
|
});
|
2015-03-07 02:17:26 +01:00
|
|
|
}
|
|
|
|
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
/**
|
|
|
|
* Submit the post form via AJAX, and redirect to the proper screen if published vs saved as a draft.
|
|
|
|
*
|
|
|
|
* @param action string publish|draft
|
|
|
|
*/
|
|
|
|
function submitPost( action ) {
|
2015-03-07 02:17:26 +01:00
|
|
|
var data;
|
|
|
|
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
saveAlert = false;
|
|
|
|
showSpinner();
|
|
|
|
|
|
|
|
if ( 'publish' === action ) {
|
|
|
|
$( '#post_status' ).val( 'publish' );
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:17:26 +01:00
|
|
|
prepareFormData();
|
|
|
|
data = $( '#pressthis-form' ).serialize();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
|
|
|
$.ajax( {
|
|
|
|
type: 'post',
|
|
|
|
url: window.ajaxurl,
|
|
|
|
data: data,
|
|
|
|
success: function( response ) {
|
|
|
|
if ( ! response.success ) {
|
|
|
|
renderError( response.data.errorMessage );
|
|
|
|
hideSpinner();
|
|
|
|
} else if ( response.data.redirect ) {
|
2015-03-09 22:49:28 +01:00
|
|
|
if ( window.opener && settings.redirInParent ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
try {
|
|
|
|
window.opener.location.href = response.data.redirect;
|
|
|
|
} catch( er ) {}
|
|
|
|
|
|
|
|
window.self.close();
|
|
|
|
} else {
|
|
|
|
window.location.href = response.data.redirect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts the media a user has selected from the presented list inside the editor, as an image or embed, based on type
|
|
|
|
*
|
|
|
|
* @param type string img|embed
|
|
|
|
* @param src string Source URL
|
|
|
|
* @param link string Optional destination link, for images (defaults to src)
|
|
|
|
*/
|
|
|
|
function insertSelectedMedia( type, src, link ) {
|
|
|
|
var newContent = '';
|
|
|
|
|
|
|
|
if ( ! editor ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
src = checkUrl( src );
|
|
|
|
link = checkUrl( link );
|
|
|
|
|
|
|
|
if ( 'img' === type ) {
|
2015-03-04 22:01:25 +01:00
|
|
|
if ( ! link ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
link = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
newContent = '<a href="' + link + '"><img class="alignnone size-full" src="' + src + '" /></a>\n';
|
|
|
|
} else {
|
|
|
|
newContent = '[embed]' + src + '[/embed]\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! hasSetFocus ) {
|
2015-03-01 23:44:25 +01:00
|
|
|
editor.focus();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 23:44:25 +01:00
|
|
|
editor.execCommand( 'mceInsertContent', false, newContent );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
hasSetFocus = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a new user-generated category via AJAX
|
|
|
|
*/
|
|
|
|
function saveNewCategory() {
|
2015-02-27 03:50:25 +01:00
|
|
|
var data,
|
|
|
|
name = $( '#new-category' ).val();
|
|
|
|
|
|
|
|
if ( ! name ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
action: 'press-this-add-category',
|
|
|
|
post_id: $( '#post_ID' ).val() || 0,
|
2015-02-27 03:50:25 +01:00
|
|
|
name: name,
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
new_cat_nonce: $( '#_ajax_nonce-add-category' ).val() || '',
|
|
|
|
parent: $( '#new-category-parent' ).val() || 0
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post( window.ajaxurl, data, function( response ) {
|
|
|
|
if ( ! response.success ) {
|
|
|
|
renderError( response.data.errorMessage );
|
|
|
|
} else {
|
|
|
|
var $parent, $ul,
|
|
|
|
$wrap = $( 'ul.categories-select' );
|
|
|
|
|
|
|
|
$.each( response.data, function( i, newCat ) {
|
2015-03-13 17:57:26 +01:00
|
|
|
var $node = $( '<li>' ).append( $( '<div class="category selected" tabindex="0" role="checkbox" aria-checked="true">' )
|
|
|
|
.attr( 'data-term-id', newCat.term_id )
|
|
|
|
.text( newCat.name ) );
|
|
|
|
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
if ( newCat.parent ) {
|
|
|
|
if ( ! $ul || ! $ul.length ) {
|
2015-03-13 17:57:26 +01:00
|
|
|
$parent = $wrap.find( 'div[data-term-id="' + newCat.parent + '"]' ).parent();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$ul = $parent.find( 'ul.children:first' );
|
|
|
|
|
|
|
|
if ( ! $ul.length ) {
|
|
|
|
$ul = $( '<ul class="children">' ).appendTo( $parent );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 17:57:26 +01:00
|
|
|
$ul.prepend( $node );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} else {
|
|
|
|
$wrap.prepend( $node );
|
|
|
|
}
|
2015-03-13 17:57:26 +01:00
|
|
|
|
|
|
|
$node.focus();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
refreshCatsCache();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************************************
|
|
|
|
* RENDERING FUNCTIONS
|
|
|
|
*************************************************************** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the form letting users enter a URL to be scanned, if a URL was already passed.
|
|
|
|
*/
|
|
|
|
function renderToolsVisibility() {
|
2015-03-09 22:49:28 +01:00
|
|
|
if ( data.hasData ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$( '#scanbar' ).hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render error notice
|
|
|
|
*
|
|
|
|
* @param msg string Notice/error message
|
|
|
|
* @param error string error|notice CSS class for display
|
|
|
|
*/
|
|
|
|
function renderNotice( msg, error ) {
|
|
|
|
var $alerts = $( '.editor-wrapper div.alerts' ),
|
|
|
|
className = error ? 'is-error' : 'is-notice';
|
|
|
|
|
2015-02-26 02:31:26 +01:00
|
|
|
$alerts.append( $( '<p class="alert ' + className + '">' ).text( msg ) );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render error notice
|
|
|
|
*
|
|
|
|
* @param msg string Error message
|
|
|
|
*/
|
|
|
|
function renderError( msg ) {
|
|
|
|
renderNotice( msg, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render notices on page load, if any already
|
|
|
|
*/
|
|
|
|
function renderStartupNotices() {
|
|
|
|
// Render errors sent in the data, if any
|
2015-03-04 22:01:25 +01:00
|
|
|
if ( data.errors ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$.each( data.errors, function( i, msg ) {
|
|
|
|
renderError( msg );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt user to upgrade their bookmarklet if there is a version mismatch.
|
2015-03-09 22:49:28 +01:00
|
|
|
if ( data.v && settings.version && ( data.v + '' ) !== ( settings.version + '' ) ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$( '.should-upgrade-bookmarklet' ).removeClass( 'is-hidden' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the detected images and embed for selection, if any
|
|
|
|
*/
|
|
|
|
function renderDetectedMedia() {
|
|
|
|
var mediaContainer = $( '#featured-media-container'),
|
|
|
|
listContainer = $( '#all-media-container' ),
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
listContainer.empty();
|
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
if ( data._embeds || data._images ) {
|
|
|
|
listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
if ( data._embeds ) {
|
|
|
|
$.each( data._embeds, function ( i, src ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
src = checkUrl( src );
|
|
|
|
|
|
|
|
var displaySrc = '',
|
|
|
|
cssClass = 'suggested-media-thumbnail suggested-media-embed';
|
|
|
|
|
|
|
|
if ( src.indexOf( 'youtube.com/' ) > -1 ) {
|
|
|
|
displaySrc = 'https://i.ytimg.com/vi/' + src.replace( /.+v=([^&]+).*/, '$1' ) + '/hqdefault.jpg';
|
|
|
|
cssClass += ' is-video';
|
|
|
|
} else if ( src.indexOf( 'youtu.be/' ) > -1 ) {
|
|
|
|
displaySrc = 'https://i.ytimg.com/vi/' + src.replace( /\/([^\/])$/, '$1' ) + '/hqdefault.jpg';
|
|
|
|
cssClass += ' is-video';
|
|
|
|
} else if ( src.indexOf( 'dailymotion.com' ) > -1 ) {
|
|
|
|
displaySrc = src.replace( '/video/', '/thumbnail/video/' );
|
|
|
|
cssClass += ' is-video';
|
|
|
|
} else if ( src.indexOf( 'soundcloud.com' ) > -1 ) {
|
|
|
|
cssClass += ' is-audio';
|
|
|
|
} else if ( src.indexOf( 'twitter.com' ) > -1 ) {
|
|
|
|
cssClass += ' is-tweet';
|
|
|
|
} else {
|
|
|
|
cssClass += ' is-video';
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '<li></li>', {
|
|
|
|
'id': 'embed-' + i + '-container',
|
|
|
|
'class': cssClass,
|
|
|
|
'tabindex': '0'
|
|
|
|
} ).css( {
|
2015-03-04 22:01:25 +01:00
|
|
|
'background-image': ( displaySrc ) ? 'url(' + displaySrc + ')' : null
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} ).html(
|
|
|
|
'<span class="screen-reader-text">' + __( 'suggestedEmbedAlt' ).replace( '%d', i + 1 ) + '</span>'
|
|
|
|
).on( 'click keypress', function ( e ) {
|
|
|
|
if ( e.type === 'click' || e.which === 13 ) {
|
|
|
|
insertSelectedMedia( 'embed',src );
|
|
|
|
}
|
|
|
|
} ).appendTo( '.wppt-all-media-list', listContainer );
|
|
|
|
|
|
|
|
found++;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
if ( data._images ) {
|
|
|
|
$.each( data._images, function( i, src ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
src = checkUrl( src );
|
|
|
|
|
|
|
|
var displaySrc = src.replace(/^(http[^\?]+)(\?.*)?$/, '$1');
|
|
|
|
if ( src.indexOf( 'files.wordpress.com/' ) > -1 ) {
|
|
|
|
displaySrc = displaySrc.replace(/\?.*$/, '') + '?w=' + smallestWidth;
|
|
|
|
} else if ( src.indexOf( 'gravatar.com/' ) > -1 ) {
|
|
|
|
displaySrc = displaySrc.replace( /\?.*$/, '' ) + '?s=' + smallestWidth;
|
|
|
|
} else {
|
|
|
|
displaySrc = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '<li></li>', {
|
|
|
|
'id': 'img-' + i + '-container',
|
|
|
|
'class': 'suggested-media-thumbnail is-image',
|
|
|
|
'tabindex': '0'
|
|
|
|
} ).css( {
|
|
|
|
'background-image': 'url(' + displaySrc + ')'
|
|
|
|
} ).html(
|
|
|
|
'<span class="screen-reader-text">' +__( 'suggestedImgAlt' ).replace( '%d', i + 1 ) + '</span>'
|
|
|
|
).on( 'click keypress', function ( e ) {
|
|
|
|
if ( e.type === 'click' || e.which === 13 ) {
|
|
|
|
insertSelectedMedia( 'img', src, data.u );
|
|
|
|
}
|
|
|
|
} ).appendTo( '.wppt-all-media-list', listContainer );
|
|
|
|
|
|
|
|
found++;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! found ) {
|
|
|
|
mediaContainer.removeClass( 'all-media-visible' ).addClass( 'no-media');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mediaContainer.removeClass( 'no-media' ).addClass( 'all-media-visible' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************************************
|
|
|
|
* MONITORING FUNCTIONS
|
|
|
|
*************************************************************** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interactive navigation behavior for the options modal (post format, tags, categories)
|
|
|
|
*/
|
|
|
|
function monitorOptionsModal() {
|
2015-03-06 23:57:26 +01:00
|
|
|
var $postOptions = $( '.post-options' ),
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$postOption = $( '.post-option' ),
|
|
|
|
$settingModal = $( '.setting-modal' ),
|
|
|
|
$modalClose = $( '.modal-close' );
|
|
|
|
|
2015-03-08 17:27:28 +01:00
|
|
|
$postOption.on( 'click', function() {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
var index = $( this ).index(),
|
|
|
|
$targetSettingModal = $settingModal.eq( index );
|
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
$postOptions.addClass( isOffScreen )
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
.one( transitionEndEvent, function() {
|
|
|
|
$( this ).addClass( isHidden );
|
|
|
|
} );
|
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
$targetSettingModal.removeClass( offscreenHidden )
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
.one( transitionEndEvent, function() {
|
2015-02-27 03:50:25 +01:00
|
|
|
$( this ).find( '.modal-close' ).focus();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-03-08 17:27:28 +01:00
|
|
|
$modalClose.on( 'click', function() {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
var $targetSettingModal = $( this ).parent(),
|
|
|
|
index = $targetSettingModal.index();
|
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
$postOptions.removeClass( offscreenHidden );
|
|
|
|
$targetSettingModal.addClass( isOffScreen );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
if ( transitionEndEvent ) {
|
|
|
|
$targetSettingModal.one( transitionEndEvent, function() {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$( this ).addClass( isHidden );
|
2015-02-27 03:50:25 +01:00
|
|
|
$postOption.eq( index - 1 ).focus();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} );
|
2015-03-06 23:57:26 +01:00
|
|
|
} else {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
setTimeout( function() {
|
|
|
|
$targetSettingModal.addClass( isHidden );
|
2015-02-27 03:50:25 +01:00
|
|
|
$postOption.eq( index - 1 ).focus();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}, 350 );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interactive behavior for the sidebar toggle, to show the options modals
|
|
|
|
*/
|
2015-03-06 23:57:26 +01:00
|
|
|
function openSidebar() {
|
|
|
|
sidebarIsOpen = true;
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
$( '.options-open, .press-this-actions, #scanbar' ).addClass( isHidden );
|
|
|
|
$( '.options-close, .options-panel-back' ).removeClass( isHidden );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
$( '.options-panel' ).removeClass( offscreenHidden )
|
|
|
|
.one( 'transitionend', function() {
|
|
|
|
$( '.post-option:first' ).focus();
|
|
|
|
} );
|
|
|
|
}
|
2015-03-08 17:27:28 +01:00
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
function closeSidebar() {
|
|
|
|
sidebarIsOpen = false;
|
|
|
|
|
|
|
|
$( '.options-close, .options-panel-back' ).addClass( isHidden );
|
|
|
|
$( '.options-open, .press-this-actions, #scanbar' ).removeClass( isHidden );
|
|
|
|
|
|
|
|
$( '.options-panel' ).addClass( isOffScreen )
|
|
|
|
.one( 'transitionend', function() {
|
|
|
|
$( this ).addClass( isHidden );
|
|
|
|
// Reset to options list
|
|
|
|
$( '.post-options' ).removeClass( offscreenHidden );
|
|
|
|
$( '.setting-modal').addClass( offscreenHidden );
|
2015-03-09 22:49:28 +01:00
|
|
|
});
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interactive behavior for the post title's field placeholder
|
|
|
|
*/
|
|
|
|
function monitorPlaceholder() {
|
2015-03-09 22:49:28 +01:00
|
|
|
var $titleField = $( '#title-container'),
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$placeholder = $('.post-title-placeholder');
|
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
$titleField.on( 'focus', function() {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$placeholder.addClass('is-hidden');
|
2015-03-09 22:49:28 +01:00
|
|
|
}).on( 'blur', function() {
|
|
|
|
if ( ! $titleField.text() ) {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$placeholder.removeClass('is-hidden');
|
|
|
|
}
|
2015-03-09 22:49:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if ( $titleField.text() ) {
|
|
|
|
$placeholder.addClass('is-hidden');
|
|
|
|
}
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
2015-03-13 17:57:26 +01:00
|
|
|
function toggleCatItem( $element ) {
|
|
|
|
if ( $element.hasClass( 'selected' ) ) {
|
|
|
|
$element.removeClass( 'selected' ).attr( 'aria-checked', 'false' );
|
|
|
|
} else {
|
|
|
|
$element.addClass( 'selected' ).attr( 'aria-checked', 'true' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function monitorCatList() {
|
|
|
|
$( '.categories-select' ).on( 'click.press-this keydown.press-this', function( event ) {
|
|
|
|
var $element = $( event.target );
|
|
|
|
|
|
|
|
if ( $element.is( 'div.category' ) ) {
|
|
|
|
if ( event.type === 'keydown' && event.keyCode !== 32 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCatItem( $element );
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
/* ***************************************************************
|
|
|
|
* PROCESSING FUNCTIONS
|
|
|
|
*************************************************************** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls all the rendring related functions to happen on page load
|
|
|
|
*/
|
|
|
|
function render(){
|
|
|
|
// We're on!
|
|
|
|
renderToolsVisibility();
|
|
|
|
renderDetectedMedia();
|
|
|
|
renderStartupNotices();
|
2015-03-08 05:54:26 +01:00
|
|
|
|
|
|
|
if ( window.tagBox ) {
|
|
|
|
window.tagBox.init();
|
|
|
|
}
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set app events and other state monitoring related code.
|
|
|
|
*/
|
|
|
|
function monitor(){
|
2015-03-09 22:49:28 +01:00
|
|
|
$( document ).on( 'tinymce-editor-init', function( event, ed ) {
|
|
|
|
editor = ed;
|
|
|
|
|
|
|
|
ed.on( 'focus', function() {
|
|
|
|
hasSetFocus = true;
|
|
|
|
} );
|
|
|
|
});
|
|
|
|
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$( '#current-site a').click( function( e ) {
|
|
|
|
e.preventDefault();
|
|
|
|
} );
|
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
// Publish, Draft and Preview buttons
|
2015-03-07 02:17:26 +01:00
|
|
|
|
|
|
|
$( '.post-actions' ).on( 'click.press-this', function( event ) {
|
|
|
|
var $target = $( event.target );
|
|
|
|
|
|
|
|
if ( $target.hasClass( 'draft-button' ) ) {
|
|
|
|
submitPost( 'draft' );
|
|
|
|
} else if ( $target.hasClass( 'publish-button' ) ) {
|
|
|
|
submitPost( 'publish' );
|
|
|
|
} else if ( $target.hasClass( 'preview-button' ) ) {
|
|
|
|
prepareFormData();
|
|
|
|
window.opener && window.opener.focus();
|
|
|
|
|
|
|
|
$( '#wp-preview' ).val( 'dopreview' );
|
|
|
|
$( '#pressthis-form' ).attr( 'target', '_blank' ).submit().attr( 'target', '' );
|
|
|
|
$( '#wp-preview' ).val( '' );
|
|
|
|
}
|
|
|
|
});
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
|
|
|
monitorOptionsModal();
|
|
|
|
monitorPlaceholder();
|
2015-03-13 17:57:26 +01:00
|
|
|
monitorCatList();
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
2015-03-06 23:57:26 +01:00
|
|
|
$( '.options-open' ).on( 'click.press-this', openSidebar );
|
|
|
|
$( '.options-close' ).on( 'click.press-this', closeSidebar );
|
|
|
|
|
|
|
|
// Close the sidebar when focus moves outside of it.
|
|
|
|
$( '.options-panel, .options-panel-back' ).on( 'focusout.press-this', function() {
|
|
|
|
setTimeout( function() {
|
|
|
|
var node = document.activeElement,
|
|
|
|
$node = $( node );
|
|
|
|
|
|
|
|
if ( sidebarIsOpen && node && ! $node.hasClass( 'options-panel-back' ) &&
|
|
|
|
( node.nodeName === 'BODY' ||
|
|
|
|
( ! $node.closest( '.options-panel' ).length &&
|
|
|
|
! $node.closest( '.options-open' ).length ) ) ) {
|
|
|
|
|
|
|
|
closeSidebar();
|
|
|
|
}
|
|
|
|
}, 50 );
|
|
|
|
});
|
|
|
|
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
$( '#post-formats-select input' ).on( 'change', function() {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
if ( $this.is( ':checked' ) ) {
|
2015-02-28 21:08:27 +01:00
|
|
|
$( '#post-option-post-format' ).text( $( 'label[for="' + $this.attr( 'id' ) + '"]' ).text() || '' );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( window ).on( 'beforeunload.press-this', function() {
|
|
|
|
if ( saveAlert || ( editor && editor.isDirty() ) ) {
|
|
|
|
return __( 'saveAlert' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( 'button.add-cat-toggle' ).on( 'click.press-this', function() {
|
2015-02-27 03:50:25 +01:00
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
$this.toggleClass( 'is-toggled' );
|
2015-03-06 02:51:25 +01:00
|
|
|
$this.attr( 'aria-expanded', 'false' === $this.attr( 'aria-expanded' ) ? 'true' : 'false' );
|
2015-02-27 03:50:25 +01:00
|
|
|
$( '.setting-modal .add-category, .categories-search-wrapper' ).toggleClass( 'is-hidden' );
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
$( 'button.add-cat-submit' ).on( 'click.press-this', saveNewCategory );
|
|
|
|
|
2015-02-27 03:50:25 +01:00
|
|
|
$( '.categories-search' ).on( 'keyup.press-this', function() {
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
var search = $( this ).val().toLowerCase() || '';
|
|
|
|
|
|
|
|
// Don't search when less thasn 3 extended ASCII chars
|
|
|
|
if ( /[\x20-\xFF]+/.test( search ) && search.length < 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.each( catsCache, function( i, cat ) {
|
|
|
|
cat.node.removeClass( 'is-hidden searched-parent' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( search ) {
|
|
|
|
$.each( catsCache, function( i, cat ) {
|
|
|
|
if ( cat.text.indexOf( search ) === -1 ) {
|
|
|
|
cat.node.addClass( 'is-hidden' );
|
|
|
|
} else {
|
|
|
|
cat.parents.addClass( 'searched-parent' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshCatsCache() {
|
|
|
|
$( '.categories-select' ).find( 'li' ).each( function() {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
catsCache.push( {
|
|
|
|
node: $this,
|
|
|
|
parents: $this.parents( 'li' ),
|
2015-03-13 17:57:26 +01:00
|
|
|
text: $this.children( '.category' ).text().toLowerCase()
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's go!
|
|
|
|
$( document ).ready( function() {
|
|
|
|
render();
|
|
|
|
monitor();
|
|
|
|
refreshCatsCache();
|
|
|
|
});
|
|
|
|
|
2015-03-09 22:49:28 +01:00
|
|
|
// Expose public methods?
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
return {
|
|
|
|
renderNotice: renderNotice,
|
|
|
|
renderError: renderError
|
|
|
|
};
|
2015-02-25 05:17:27 +01:00
|
|
|
};
|
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534
git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-25 02:50:26 +01:00
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
window.wp.pressThis = new PressThis();
|
|
|
|
|
|
|
|
}( jQuery, window ));
|