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-24 20:50:26 -05:00
|
|
|
/**
|
|
|
|
* PressThis App
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
( function( $, window ) {
|
|
|
|
var PressThis = function() {
|
2015-03-16 16:51:26 -04:00
|
|
|
var editor, $mediaList, $mediaThumbWrap,
|
2015-06-29 23:58:27 -04:00
|
|
|
$window = $( window ),
|
|
|
|
$document = $( document ),
|
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-24 20:50:26 -05:00
|
|
|
saveAlert = false,
|
2015-03-04 14:29:25 -05:00
|
|
|
textarea = document.createElement( 'textarea' ),
|
2015-03-06 17:57:26 -05:00
|
|
|
sidebarIsOpen = false,
|
2015-03-09 17:49:28 -04: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-24 20:50:26 -05:00
|
|
|
data = window.wpPressThisData || {},
|
|
|
|
smallestWidth = 128,
|
|
|
|
hasSetFocus = false,
|
|
|
|
catsCache = [],
|
2015-03-06 17:57:26 -05:00
|
|
|
isOffScreen = 'is-off-screen',
|
|
|
|
isHidden = 'is-hidden',
|
|
|
|
offscreenHidden = isOffScreen + ' ' + isHidden,
|
2015-06-26 22:15:24 -04:00
|
|
|
iOS = /iPad|iPod|iPhone/.test( window.navigator.userAgent ),
|
2015-06-29 23:58:27 -04:00
|
|
|
$textEditor = $( '#pressthis' ),
|
|
|
|
textEditor = $textEditor[0],
|
|
|
|
textEditorMinHeight = 600,
|
|
|
|
textLength = 0,
|
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-24 20:50:26 -05: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 14:29:25 -05: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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-04 14:29:25 -05: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-24 20:50:26 -05:00
|
|
|
*
|
|
|
|
* @param text string Text.
|
|
|
|
* @returns string Sanitized text.
|
|
|
|
*/
|
|
|
|
function sanitizeText( text ) {
|
2015-03-09 17:49:28 -04: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-24 20:50:26 -05:00
|
|
|
|
2015-03-09 17:49:28 -04: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-24 20:50:26 -05: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() {
|
2015-04-03 00:52:27 -04:00
|
|
|
$( '.spinner' ).addClass( 'is-active' );
|
2015-04-09 15:07:28 -04:00
|
|
|
$( '.post-actions button' ).attr( 'disabled', 'disabled' );
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide UX spinner
|
|
|
|
*/
|
|
|
|
function hideSpinner() {
|
2015-04-03 00:52:27 -04:00
|
|
|
$( '.spinner' ).removeClass( 'is-active' );
|
2015-04-09 15:07:28 -04:00
|
|
|
$( '.post-actions button' ).removeAttr( 'disabled' );
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
2015-06-29 23:58:27 -04:00
|
|
|
function textEditorResize( reset ) {
|
|
|
|
var pageYOffset, height;
|
|
|
|
|
|
|
|
if ( editor && ! editor.isHidden() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reset = ( reset === 'reset' ) || ( textLength && textLength > textEditor.value.length );
|
|
|
|
height = textEditor.style.height;
|
|
|
|
|
|
|
|
if ( reset ) {
|
|
|
|
pageYOffset = window.pageYOffset;
|
|
|
|
|
|
|
|
textEditor.style.height = 'auto';
|
|
|
|
textEditor.style.height = Math.max( textEditor.scrollHeight, textEditorMinHeight ) + 'px';
|
|
|
|
window.scrollTo( window.pageXOffset, pageYOffset );
|
|
|
|
} else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) {
|
|
|
|
textEditor.style.height = textEditor.scrollHeight + 'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
textLength = textEditor.value.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mceGetCursorOffset() {
|
|
|
|
if ( ! editor ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var node = editor.selection.getNode(),
|
|
|
|
range, view, offset;
|
|
|
|
|
|
|
|
if ( editor.wp && editor.wp.getView && ( view = editor.wp.getView( node ) ) ) {
|
|
|
|
offset = view.getBoundingClientRect();
|
|
|
|
} else {
|
|
|
|
range = editor.selection.getRng();
|
|
|
|
|
|
|
|
try {
|
|
|
|
offset = range.getClientRects()[0];
|
|
|
|
} catch( er ) {}
|
|
|
|
|
|
|
|
if ( ! offset ) {
|
|
|
|
offset = node.getBoundingClientRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset.height ? offset : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the caret is always visible.
|
|
|
|
function mceKeyup( event ) {
|
|
|
|
var VK = window.tinymce.util.VK,
|
|
|
|
key = event.keyCode;
|
|
|
|
|
|
|
|
// Bail on special keys.
|
|
|
|
if ( key <= 47 && ! ( key === VK.SPACEBAR || key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE || key === VK.UP || key === VK.LEFT || key === VK.DOWN || key === VK.UP ) ) {
|
|
|
|
return;
|
|
|
|
// OS keys, function keys, num lock, scroll lock
|
|
|
|
} else if ( ( key >= 91 && key <= 93 ) || ( key >= 112 && key <= 123 ) || key === 144 || key === 145 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mceScroll( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
function mceScroll( key ) {
|
|
|
|
var cursorTop, cursorBottom, editorBottom,
|
|
|
|
offset = mceGetCursorOffset(),
|
|
|
|
bufferTop = 50,
|
|
|
|
bufferBottom = 65,
|
|
|
|
VK = window.tinymce.util.VK;
|
|
|
|
|
|
|
|
if ( ! offset ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursorTop = offset.top + editor.iframeElement.getBoundingClientRect().top;
|
|
|
|
cursorBottom = cursorTop + offset.height;
|
|
|
|
cursorTop = cursorTop - bufferTop;
|
|
|
|
cursorBottom = cursorBottom + bufferBottom;
|
|
|
|
editorBottom = $window.height();
|
|
|
|
|
|
|
|
// Don't scroll if the node is taller than the visible part of the editor
|
|
|
|
if ( editorBottom < offset.height ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( cursorTop < 0 && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) {
|
|
|
|
window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset );
|
|
|
|
} else if ( cursorBottom > editorBottom ) {
|
|
|
|
window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-28 23:14:28 -04:00
|
|
|
/**
|
|
|
|
* Replace emoji images with chars and sanitize the text content.
|
|
|
|
*/
|
|
|
|
function getTitleText() {
|
|
|
|
var $element = $( '#title-container' );
|
|
|
|
|
|
|
|
$element.find( 'img.emoji' ).each( function() {
|
|
|
|
var $image = $( this );
|
|
|
|
$image.replaceWith( $( '<span>' ).text( $image.attr( 'alt' ) ) );
|
|
|
|
});
|
|
|
|
|
|
|
|
return sanitizeText( $element.text() );
|
|
|
|
}
|
|
|
|
|
2015-03-06 20:17:26 -05:00
|
|
|
/**
|
|
|
|
* Prepare the form data for saving.
|
2015-03-08 12:27:28 -04:00
|
|
|
*/
|
2015-03-06 20:17:26 -05:00
|
|
|
function prepareFormData() {
|
2015-03-13 12:57:26 -04:00
|
|
|
var $form = $( '#pressthis-form' ),
|
|
|
|
$input = $( '<input type="hidden" name="post_category[]" value="">' );
|
|
|
|
|
2015-03-06 20:17:26 -05:00
|
|
|
editor && editor.save();
|
|
|
|
|
2015-03-28 23:14:28 -04:00
|
|
|
$( '#post_title' ).val( getTitleText() );
|
2015-03-06 20:17:26 -05:00
|
|
|
|
|
|
|
// 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 12:57:26 -04: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-06 20:17:26 -05: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-24 20:50:26 -05: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-06-23 22:46:27 -04:00
|
|
|
var data;
|
2015-03-06 20:17:26 -05: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-24 20:50:26 -05:00
|
|
|
saveAlert = false;
|
|
|
|
showSpinner();
|
|
|
|
|
|
|
|
if ( 'publish' === action ) {
|
|
|
|
$( '#post_status' ).val( 'publish' );
|
|
|
|
}
|
|
|
|
|
2015-03-06 20:17:26 -05: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-24 20:50:26 -05:00
|
|
|
|
|
|
|
$.ajax( {
|
|
|
|
type: 'post',
|
|
|
|
url: window.ajaxurl,
|
2015-04-02 21:34:26 -04:00
|
|
|
data: data
|
|
|
|
}).always( function() {
|
|
|
|
hideSpinner();
|
2015-04-08 19:14:28 -04:00
|
|
|
clearNotices();
|
2015-06-28 00:59:24 -04:00
|
|
|
$( '.publish-button' ).removeClass( 'is-saving' );
|
2015-04-02 21:34:26 -04:00
|
|
|
}).done( function( response ) {
|
|
|
|
if ( ! response.success ) {
|
|
|
|
renderError( response.data.errorMessage );
|
|
|
|
} else if ( response.data.redirect ) {
|
2015-06-28 00:59:24 -04:00
|
|
|
if ( window.opener && ( settings.redirInParent || response.data.force ) ) {
|
2015-04-02 21:34:26 -04:00
|
|
|
try {
|
|
|
|
window.opener.location.href = response.data.redirect;
|
|
|
|
|
2015-06-28 00:59:24 -04:00
|
|
|
window.setTimeout( function() {
|
|
|
|
window.self.close();
|
2015-06-28 07:41:24 -04:00
|
|
|
}, 200 );
|
2015-06-28 00:59:24 -04:00
|
|
|
} catch( er ) {
|
|
|
|
window.location.href = response.data.redirect;
|
|
|
|
}
|
2015-04-02 21:34:26 -04:00
|
|
|
} else {
|
|
|
|
window.location.href = response.data.redirect;
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
}
|
2015-04-02 21:34:26 -04:00
|
|
|
}).fail( function() {
|
|
|
|
renderError( __( 'serverError' ) );
|
|
|
|
});
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2015-03-23 21:33:29 -04:00
|
|
|
function insertSelectedMedia( $element ) {
|
|
|
|
var src, link, 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-24 20:50:26 -05:00
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
src = checkUrl( $element.attr( 'data-wp-src' ) || '' );
|
|
|
|
link = checkUrl( data.u );
|
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-24 20:50:26 -05:00
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
if ( $element.hasClass( 'is-image' ) ) {
|
2015-03-04 16:01:25 -05: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-24 20:50:26 -05:00
|
|
|
link = src;
|
|
|
|
}
|
|
|
|
|
2015-11-07 11:12:27 -05:00
|
|
|
newContent = '<a href="' + link + '"><img class="alignnone size-full" src="' + src + '" alt="" /></a>';
|
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-24 20:50:26 -05:00
|
|
|
} else {
|
2015-03-23 21:33:29 -04:00
|
|
|
newContent = '[embed]' + src + '[/embed]';
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
2015-06-29 23:58:27 -04:00
|
|
|
if ( editor && ! editor.isHidden() ) {
|
|
|
|
if ( ! hasSetFocus ) {
|
|
|
|
editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() );
|
|
|
|
} else {
|
|
|
|
editor.execCommand( 'mceInsertContent', false, newContent );
|
|
|
|
}
|
|
|
|
} else if ( window.QTags ) {
|
|
|
|
window.QTags.insertContent( 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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a new user-generated category via AJAX
|
|
|
|
*/
|
|
|
|
function saveNewCategory() {
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05:00
|
|
|
action: 'press-this-add-category',
|
|
|
|
post_id: $( '#post_ID' ).val() || 0,
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05: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 12:57:26 -04: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 ) );
|
2015-03-16 16:51:26 -04: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-24 20:50:26 -05:00
|
|
|
if ( newCat.parent ) {
|
|
|
|
if ( ! $ul || ! $ul.length ) {
|
2015-03-13 12:57:26 -04: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-24 20:50:26 -05:00
|
|
|
$ul = $parent.find( 'ul.children:first' );
|
|
|
|
|
|
|
|
if ( ! $ul.length ) {
|
|
|
|
$ul = $( '<ul class="children">' ).appendTo( $parent );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 12:57:26 -04: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-24 20:50:26 -05:00
|
|
|
} else {
|
|
|
|
$wrap.prepend( $node );
|
|
|
|
}
|
2015-03-13 12:57:26 -04: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-24 20:50:26 -05: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 17:49:28 -04: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-24 20:50:26 -05: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-25 20:31:26 -05: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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render error notice
|
|
|
|
*
|
|
|
|
* @param msg string Error message
|
|
|
|
*/
|
|
|
|
function renderError( msg ) {
|
|
|
|
renderNotice( msg, true );
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:14:28 -04:00
|
|
|
function clearNotices() {
|
|
|
|
$( 'div.alerts' ).empty();
|
|
|
|
}
|
|
|
|
|
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-24 20:50:26 -05:00
|
|
|
/**
|
|
|
|
* Render notices on page load, if any already
|
|
|
|
*/
|
|
|
|
function renderStartupNotices() {
|
|
|
|
// Render errors sent in the data, if any
|
2015-03-04 16:01:25 -05: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-24 20:50:26 -05:00
|
|
|
$.each( data.errors, function( i, msg ) {
|
|
|
|
renderError( msg );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 16:51:26 -04:00
|
|
|
/**
|
|
|
|
* Add an image to the list of found images.
|
|
|
|
*/
|
|
|
|
function addImg( src, displaySrc, i ) {
|
|
|
|
var $element = $mediaThumbWrap.clone().addClass( 'is-image' );
|
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
$element.attr( 'data-wp-src', src ).css( 'background-image', 'url(' + displaySrc + ')' )
|
2015-03-16 16:51:26 -04:00
|
|
|
.find( 'span' ).text( __( 'suggestedImgAlt' ).replace( '%d', i + 1 ) );
|
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
$mediaList.append( $element );
|
2015-03-16 16:51:26 -04: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-24 20:50:26 -05:00
|
|
|
/**
|
|
|
|
* Render the detected images and embed for selection, if any
|
|
|
|
*/
|
|
|
|
function renderDetectedMedia() {
|
2015-03-16 16:51:26 -04:00
|
|
|
var found = 0;
|
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-24 20:50:26 -05:00
|
|
|
|
2015-03-16 16:51:26 -04:00
|
|
|
$mediaList = $( 'ul.media-list' );
|
|
|
|
$mediaThumbWrap = $( '<li class="suggested-media-thumbnail" tabindex="0"><span class="screen-reader-text"></span></li>' );
|
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-24 20:50:26 -05:00
|
|
|
|
2015-03-09 17:49:28 -04: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-24 20:50:26 -05:00
|
|
|
var displaySrc = '',
|
2015-03-16 16:51:26 -04:00
|
|
|
cssClass = '',
|
|
|
|
$element = $mediaThumbWrap.clone().addClass( 'is-embed' );
|
|
|
|
|
|
|
|
src = checkUrl( 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-24 20:50:26 -05:00
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
$element.attr( 'data-wp-src', src ).find( 'span' ).text( __( 'suggestedEmbedAlt' ).replace( '%d', i + 1 ) );
|
2015-03-16 16:51:26 -04:00
|
|
|
|
|
|
|
if ( displaySrc ) {
|
|
|
|
$element.css( 'background-image', 'url(' + displaySrc + ')' );
|
|
|
|
}
|
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
$mediaList.append( $element );
|
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-24 20:50:26 -05:00
|
|
|
found++;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2015-03-09 17:49:28 -04:00
|
|
|
if ( data._images ) {
|
|
|
|
$.each( data._images, function( i, src ) {
|
2015-03-16 16:51:26 -04:00
|
|
|
var displaySrc, img = new Image();
|
|
|
|
|
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-24 20:50:26 -05:00
|
|
|
src = checkUrl( src );
|
2015-03-16 16:51:26 -04:00
|
|
|
displaySrc = src.replace( /^(http[^\?]+)(\?.*)?$/, '$1' );
|
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-24 20:50:26 -05:00
|
|
|
|
|
|
|
if ( src.indexOf( 'files.wordpress.com/' ) > -1 ) {
|
2015-03-16 16:51:26 -04:00
|
|
|
displaySrc = displaySrc.replace( /\?.*$/, '' ) + '?w=' + smallestWidth;
|
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-24 20:50:26 -05:00
|
|
|
} else if ( src.indexOf( 'gravatar.com/' ) > -1 ) {
|
|
|
|
displaySrc = displaySrc.replace( /\?.*$/, '' ) + '?s=' + smallestWidth;
|
|
|
|
} else {
|
|
|
|
displaySrc = src;
|
|
|
|
}
|
|
|
|
|
2015-03-16 16:51:26 -04:00
|
|
|
img.onload = function() {
|
|
|
|
if ( ( img.width && img.width < 256 ) ||
|
|
|
|
( img.height && img.height < 128 ) ) {
|
|
|
|
|
|
|
|
return;
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
2015-03-16 16:51:26 -04:00
|
|
|
addImg( src, displaySrc, i );
|
|
|
|
};
|
|
|
|
|
|
|
|
img.src = 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-24 20:50:26 -05:00
|
|
|
found++;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2015-03-16 16:51:26 -04:00
|
|
|
if ( found ) {
|
|
|
|
$( '.media-list-container' ).addClass( 'has-media' );
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************************************
|
|
|
|
* MONITORING FUNCTIONS
|
|
|
|
*************************************************************** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interactive navigation behavior for the options modal (post format, tags, categories)
|
|
|
|
*/
|
|
|
|
function monitorOptionsModal() {
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
$postOption = $( '.post-option' ),
|
|
|
|
$settingModal = $( '.setting-modal' ),
|
|
|
|
$modalClose = $( '.modal-close' );
|
|
|
|
|
2015-03-08 12:27:28 -04: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-24 20:50:26 -05:00
|
|
|
var index = $( this ).index(),
|
|
|
|
$targetSettingModal = $settingModal.eq( index );
|
|
|
|
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
.one( transitionEndEvent, function() {
|
|
|
|
$( this ).addClass( isHidden );
|
|
|
|
} );
|
|
|
|
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
.one( transitionEndEvent, function() {
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-03-08 12:27:28 -04: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-24 20:50:26 -05:00
|
|
|
var $targetSettingModal = $( this ).parent(),
|
|
|
|
index = $targetSettingModal.index();
|
|
|
|
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
$( this ).addClass( isHidden );
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05:00
|
|
|
} );
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
setTimeout( function() {
|
|
|
|
$targetSettingModal.addClass( isHidden );
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05:00
|
|
|
}, 350 );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interactive behavior for the sidebar toggle, to show the options modals
|
|
|
|
*/
|
2015-03-06 17:57:26 -05: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-24 20:50:26 -05:00
|
|
|
|
2015-03-29 23:09:51 -04:00
|
|
|
$( '.options' ).removeClass( 'closed' ).addClass( 'open' );
|
|
|
|
$( '.press-this-actions, #scanbar' ).addClass( isHidden );
|
|
|
|
$( '.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-24 20:50:26 -05:00
|
|
|
|
2015-03-06 17:57:26 -05:00
|
|
|
$( '.options-panel' ).removeClass( offscreenHidden )
|
2015-03-29 23:09:51 -04:00
|
|
|
.one( transitionEndEvent, function() {
|
2015-03-06 17:57:26 -05:00
|
|
|
$( '.post-option:first' ).focus();
|
|
|
|
} );
|
|
|
|
}
|
2015-03-08 12:27:28 -04:00
|
|
|
|
2015-03-06 17:57:26 -05:00
|
|
|
function closeSidebar() {
|
|
|
|
sidebarIsOpen = false;
|
|
|
|
|
2015-03-29 23:09:51 -04:00
|
|
|
$( '.options' ).removeClass( 'open' ).addClass( 'closed' );
|
|
|
|
$( '.options-panel-back' ).addClass( isHidden );
|
|
|
|
$( '.press-this-actions, #scanbar' ).removeClass( isHidden );
|
2015-03-06 17:57:26 -05:00
|
|
|
|
|
|
|
$( '.options-panel' ).addClass( isOffScreen )
|
2015-03-29 23:09:51 -04:00
|
|
|
.one( transitionEndEvent, function() {
|
2015-03-06 17:57:26 -05:00
|
|
|
$( this ).addClass( isHidden );
|
|
|
|
// Reset to options list
|
|
|
|
$( '.post-options' ).removeClass( offscreenHidden );
|
|
|
|
$( '.setting-modal').addClass( offscreenHidden );
|
2015-03-09 17:49:28 -04: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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interactive behavior for the post title's field placeholder
|
|
|
|
*/
|
|
|
|
function monitorPlaceholder() {
|
2015-03-28 23:14:28 -04:00
|
|
|
var $titleField = $( '#title-container' ),
|
|
|
|
$placeholder = $( '.post-title-placeholder' );
|
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-24 20:50:26 -05:00
|
|
|
|
2015-03-09 17:49:28 -04:00
|
|
|
$titleField.on( 'focus', function() {
|
2015-03-28 23:14:28 -04:00
|
|
|
$placeholder.addClass( 'is-hidden' );
|
2015-03-09 17:49:28 -04:00
|
|
|
}).on( 'blur', function() {
|
2015-03-28 23:14:28 -04:00
|
|
|
if ( ! $titleField.text() && ! $titleField.html() ) {
|
|
|
|
$placeholder.removeClass( '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-24 20:50:26 -05:00
|
|
|
}
|
2015-03-28 23:14:28 -04:00
|
|
|
}).on( 'keyup', function() {
|
|
|
|
saveAlert = true;
|
2015-04-02 17:11:30 -04:00
|
|
|
}).on( 'paste', function( event ) {
|
|
|
|
var text, range,
|
|
|
|
clipboard = event.originalEvent.clipboardData || window.clipboardData;
|
|
|
|
|
|
|
|
if ( clipboard ) {
|
|
|
|
try{
|
|
|
|
text = clipboard.getData( 'Text' ) || clipboard.getData( 'text/plain' );
|
|
|
|
|
|
|
|
if ( text ) {
|
|
|
|
text = $.trim( text.replace( /\s+/g, ' ' ) );
|
|
|
|
|
|
|
|
if ( window.getSelection ) {
|
|
|
|
range = window.getSelection().getRangeAt(0);
|
|
|
|
|
|
|
|
if ( range ) {
|
|
|
|
if ( ! range.collapsed ) {
|
|
|
|
range.deleteContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
range.insertNode( document.createTextNode( text ) );
|
|
|
|
}
|
|
|
|
} else if ( document.selection ) {
|
|
|
|
range = document.selection.createRange();
|
|
|
|
|
|
|
|
if ( range ) {
|
|
|
|
range.text = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch ( er ) {}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2015-03-28 23:14:28 -04:00
|
|
|
saveAlert = true;
|
|
|
|
|
|
|
|
setTimeout( function() {
|
|
|
|
$titleField.text( getTitleText() );
|
2015-04-02 17:11:30 -04:00
|
|
|
}, 50 );
|
2015-03-09 17:49:28 -04:00
|
|
|
});
|
|
|
|
|
2015-03-28 23:14:28 -04:00
|
|
|
if ( $titleField.text() || $titleField.html() ) {
|
2015-03-09 17:49:28 -04:00
|
|
|
$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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
2015-03-13 12:57:26 -04: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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:46:27 -04:00
|
|
|
function splitButtonClose() {
|
|
|
|
$( '.split-button' ).removeClass( 'is-open' );
|
|
|
|
$( '.split-button-toggle' ).attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
|
|
|
|
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-24 20:50:26 -05:00
|
|
|
/* ***************************************************************
|
|
|
|
* PROCESSING FUNCTIONS
|
|
|
|
*************************************************************** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls all the rendring related functions to happen on page load
|
|
|
|
*/
|
|
|
|
function render(){
|
|
|
|
// We're on!
|
|
|
|
renderToolsVisibility();
|
|
|
|
renderDetectedMedia();
|
|
|
|
renderStartupNotices();
|
2015-03-07 23:54:26 -05:00
|
|
|
|
|
|
|
if ( window.tagBox ) {
|
|
|
|
window.tagBox.init();
|
|
|
|
}
|
2015-06-26 22:15:24 -04:00
|
|
|
|
|
|
|
// iOS doesn't fire click events on "standard" elements without this...
|
|
|
|
if ( iOS ) {
|
|
|
|
$( document.body ).css( 'cursor', 'pointer' );
|
|
|
|
}
|
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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set app events and other state monitoring related code.
|
|
|
|
*/
|
2015-04-08 19:14:28 -04:00
|
|
|
function monitor() {
|
2015-06-23 22:46:27 -04:00
|
|
|
var $splitButton = $( '.split-button' );
|
|
|
|
|
2015-06-29 23:58:27 -04:00
|
|
|
$document.on( 'tinymce-editor-init', function( event, ed ) {
|
2015-03-09 17:49:28 -04:00
|
|
|
editor = ed;
|
|
|
|
|
2015-04-09 15:07:28 -04:00
|
|
|
editor.on( 'nodechange', function() {
|
2015-03-09 17:49:28 -04:00
|
|
|
hasSetFocus = true;
|
2015-06-23 22:46:27 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
editor.on( 'focus', function() {
|
|
|
|
splitButtonClose();
|
|
|
|
});
|
2015-06-29 23:58:27 -04:00
|
|
|
|
|
|
|
editor.on( 'show', function() {
|
|
|
|
setTimeout( function() {
|
|
|
|
editor.execCommand( 'wpAutoResize' );
|
|
|
|
}, 300 );
|
|
|
|
});
|
|
|
|
|
|
|
|
editor.on( 'hide', function() {
|
|
|
|
setTimeout( function() {
|
|
|
|
textEditorResize( 'reset' );
|
|
|
|
}, 100 );
|
|
|
|
});
|
|
|
|
|
|
|
|
editor.on( 'keyup', mceKeyup );
|
|
|
|
editor.on( 'undo redo', mceScroll );
|
|
|
|
|
2015-03-23 21:33:29 -04:00
|
|
|
}).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) {
|
|
|
|
if ( event.type === 'click' || event.keyCode === 13 ) {
|
|
|
|
insertSelectedMedia( $( this ) );
|
|
|
|
}
|
2015-06-23 22:46:27 -04:00
|
|
|
}).on( 'click.press-this', function( event ) {
|
|
|
|
if ( ! $( event.target ).closest( 'button' ).hasClass( 'split-button-toggle' ) ) {
|
|
|
|
splitButtonClose();
|
|
|
|
}
|
2015-03-09 17:49:28 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Publish, Draft and Preview buttons
|
2015-03-06 20:17:26 -05:00
|
|
|
$( '.post-actions' ).on( 'click.press-this', function( event ) {
|
2015-08-31 19:08:22 -04:00
|
|
|
var location,
|
|
|
|
$target = $( event.target ),
|
2015-04-08 19:14:28 -04:00
|
|
|
$button = $target.closest( 'button' );
|
|
|
|
|
|
|
|
if ( $button.length ) {
|
|
|
|
if ( $button.hasClass( 'draft-button' ) ) {
|
2015-06-28 00:59:24 -04:00
|
|
|
$( '.publish-button' ).addClass( 'is-saving' );
|
2015-04-08 19:14:28 -04:00
|
|
|
submitPost( 'draft' );
|
|
|
|
} else if ( $button.hasClass( 'publish-button' ) ) {
|
2015-06-28 00:59:24 -04:00
|
|
|
$button.addClass( 'is-saving' );
|
2015-08-31 19:08:22 -04:00
|
|
|
|
|
|
|
if ( window.history.replaceState ) {
|
|
|
|
location = window.location.href;
|
|
|
|
location += ( location.indexOf( '?' ) !== -1 ) ? '&' : '?';
|
|
|
|
location += 'wp-press-this-reload=true';
|
|
|
|
|
|
|
|
window.history.replaceState( null, null, location );
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:14:28 -04:00
|
|
|
submitPost( 'publish' );
|
|
|
|
} else if ( $button.hasClass( 'preview-button' ) ) {
|
|
|
|
prepareFormData();
|
|
|
|
window.opener && window.opener.focus();
|
|
|
|
|
|
|
|
$( '#wp-preview' ).val( 'dopreview' );
|
|
|
|
$( '#pressthis-form' ).attr( 'target', '_blank' ).submit().attr( 'target', '' );
|
|
|
|
$( '#wp-preview' ).val( '' );
|
2015-06-28 00:59:24 -04:00
|
|
|
} else if ( $button.hasClass( 'standard-editor-button' ) ) {
|
|
|
|
$( '.publish-button' ).addClass( 'is-saving' );
|
|
|
|
$( '#pt-force-redirect' ).val( 'true' );
|
|
|
|
submitPost( 'draft' );
|
2015-06-23 22:46:27 -04:00
|
|
|
} else if ( $button.hasClass( 'split-button-toggle' ) ) {
|
|
|
|
if ( $splitButton.hasClass( 'is-open' ) ) {
|
|
|
|
$splitButton.removeClass( 'is-open' );
|
|
|
|
$button.attr( 'aria-expanded', 'false' );
|
|
|
|
} else {
|
|
|
|
$splitButton.addClass( 'is-open' );
|
|
|
|
$button.attr( 'aria-expanded', 'true' );
|
|
|
|
}
|
2015-04-08 19:14:28 -04:00
|
|
|
}
|
2015-03-06 20:17:26 -05: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-24 20:50:26 -05:00
|
|
|
|
|
|
|
monitorOptionsModal();
|
|
|
|
monitorPlaceholder();
|
2015-03-13 12:57:26 -04: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-24 20:50:26 -05:00
|
|
|
|
2015-03-29 23:09:51 -04:00
|
|
|
$( '.options' ).on( 'click.press-this', function() {
|
|
|
|
if ( $( this ).hasClass( 'open' ) ) {
|
|
|
|
closeSidebar();
|
|
|
|
} else {
|
|
|
|
openSidebar();
|
|
|
|
}
|
|
|
|
});
|
2015-03-06 17:57:26 -05:00
|
|
|
|
|
|
|
// 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 &&
|
2015-03-29 23:09:51 -04:00
|
|
|
! $node.closest( '.options' ).length ) ) ) {
|
2015-03-06 17:57:26 -05:00
|
|
|
|
|
|
|
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-24 20:50:26 -05:00
|
|
|
$( '#post-formats-select input' ).on( 'change', function() {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
if ( $this.is( ':checked' ) ) {
|
2015-02-28 15:08:27 -05: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-24 20:50:26 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2015-06-29 23:58:27 -04:00
|
|
|
$window.on( 'beforeunload.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-24 20:50:26 -05:00
|
|
|
if ( saveAlert || ( editor && editor.isDirty() ) ) {
|
|
|
|
return __( 'saveAlert' );
|
|
|
|
}
|
2015-06-29 23:58:27 -04:00
|
|
|
} ).on( 'resize.press-this', function() {
|
|
|
|
if ( ! editor || editor.isHidden() ) {
|
|
|
|
textEditorResize( 'reset' );
|
|
|
|
}
|
|
|
|
});
|
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-24 20:50:26 -05:00
|
|
|
|
|
|
|
$( 'button.add-cat-toggle' ).on( 'click.press-this', function() {
|
2015-02-26 21:50:25 -05:00
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
$this.toggleClass( 'is-toggled' );
|
2015-03-05 20:51:25 -05:00
|
|
|
$this.attr( 'aria-expanded', 'false' === $this.attr( 'aria-expanded' ) ? 'true' : 'false' );
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
$( 'button.add-cat-submit' ).on( 'click.press-this', saveNewCategory );
|
|
|
|
|
2015-02-26 21:50:25 -05: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-24 20:50:26 -05: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' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2015-06-29 23:58:27 -04:00
|
|
|
$textEditor.on( 'focus.press-this input.press-this propertychange.press-this', textEditorResize );
|
|
|
|
|
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-24 20:50:26 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshCatsCache() {
|
|
|
|
$( '.categories-select' ).find( 'li' ).each( function() {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
catsCache.push( {
|
|
|
|
node: $this,
|
|
|
|
parents: $this.parents( 'li' ),
|
2015-03-13 12:57:26 -04: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-24 20:50:26 -05:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's go!
|
2015-06-29 23:58:27 -04:00
|
|
|
$document.ready( 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-24 20:50:26 -05:00
|
|
|
render();
|
|
|
|
monitor();
|
|
|
|
refreshCatsCache();
|
|
|
|
});
|
|
|
|
|
2015-03-09 17:49:28 -04: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-24 20:50:26 -05:00
|
|
|
return {
|
|
|
|
renderNotice: renderNotice,
|
|
|
|
renderError: renderError
|
|
|
|
};
|
2015-02-24 23:17:27 -05: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-24 20:50:26 -05:00
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
window.wp.pressThis = new PressThis();
|
|
|
|
|
|
|
|
}( jQuery, window ));
|