/* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting */
-var tagBox, commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink;
+var commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink;
// Back-compat: prevent fatal errors
makeSlugeditClickable = editPermalink = function(){};
window.wp = window.wp || {};
-// return an array with any duplicate, whitespace or values removed
-function array_unique_noempty(a) {
- var out = [];
- jQuery.each( a, function(key, val) {
- val = jQuery.trim(val);
- if ( val && jQuery.inArray(val, out) == -1 )
- out.push(val);
- } );
- return out;
-}
-
-( function($) {
+( function( $ ) {
var titleHasFocus = false;
-tagBox = {
- clean : function(tags) {
- var comma = postL10n.comma;
- if ( ',' !== comma )
- tags = tags.replace(new RegExp(comma, 'g'), ',');
- tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
- if ( ',' !== comma )
- tags = tags.replace(/,/g, comma);
- return tags;
- },
-
- parseTags : function(el) {
- var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'),
- thetags = taxbox.find('.the-tags'), comma = postL10n.comma,
- current_tags = thetags.val().split(comma), new_tags = [];
- delete current_tags[num];
-
- $.each( current_tags, function(key, val) {
- val = $.trim(val);
- if ( val ) {
- new_tags.push(val);
- }
- });
-
- thetags.val( this.clean( new_tags.join(comma) ) );
-
- this.quickClicks(taxbox);
- return false;
- },
-
- quickClicks : function(el) {
- var thetags = $('.the-tags', el),
- tagchecklist = $('.tagchecklist', el),
- id = $(el).attr('id'),
- current_tags, disabled;
-
- if ( !thetags.length )
- return;
-
- disabled = thetags.prop('disabled');
-
- current_tags = thetags.val().split(postL10n.comma);
- tagchecklist.empty();
-
- $.each( current_tags, function( key, val ) {
- var span, xbutton;
-
- val = $.trim( val );
-
- if ( ! val )
- return;
-
- // Create a new span, and ensure the text is properly escaped.
- span = $('<span />').text( val );
-
- // If tags editing isn't disabled, create the X button.
- if ( ! disabled ) {
- xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' );
- xbutton.click( function(){ tagBox.parseTags(this); });
- span.prepend(' ').prepend( xbutton );
- }
-
- // Append the span to the tag list.
- tagchecklist.append( span );
- });
- },
-
- flushTags : function(el, a, f) {
- var tagsval, newtags, text,
- tags = $('.the-tags', el),
- newtag = $('input.newtag', el),
- comma = postL10n.comma;
- a = a || false;
-
- text = a ? $(a).text() : newtag.val();
- tagsval = tags.val();
- newtags = tagsval ? tagsval + comma + text : text;
-
- newtags = this.clean( newtags );
- newtags = array_unique_noempty( newtags.split(comma) ).join(comma);
- tags.val(newtags);
- this.quickClicks(el);
-
- if ( !a )
- newtag.val('');
- if ( 'undefined' == typeof(f) )
- newtag.focus();
-
- return false;
- },
-
- get : function(id) {
- var tax = id.substr(id.indexOf('-')+1);
-
- $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
- if ( 0 === r || 'success' != stat )
- r = wpAjax.broken;
-
- r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
- $('a', r).click(function(){
- tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
- return false;
- });
-
- $('#'+id).after(r);
- });
- },
-
- init : function() {
- var t = this, ajaxtag = $('div.ajaxtag');
-
- $('.tagsdiv').each( function() {
- tagBox.quickClicks(this);
- });
-
- $('input.tagadd', ajaxtag).click(function(){
- t.flushTags( $(this).closest('.tagsdiv') );
- });
-
- $('div.taghint', ajaxtag).click(function(){
- $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
- });
-
- $('input.newtag', ajaxtag).blur(function() {
- if ( '' === this.value )
- $(this).parent().siblings('.taghint').css('visibility', '');
- }).focus(function(){
- $(this).parent().siblings('.taghint').css('visibility', 'hidden');
- }).keyup(function(e){
- if ( 13 == e.which ) {
- tagBox.flushTags( $(this).closest('.tagsdiv') );
- return false;
- }
- }).keypress(function(e){
- if ( 13 == e.which ) {
- e.preventDefault();
- return false;
- }
- }).each(function(){
- var tax = $(this).closest('div.tagsdiv').attr('id');
- $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } );
- });
-
- // save tags on post save/publish
- $('#post').submit(function(){
- $('div.tagsdiv').each( function() {
- tagBox.flushTags(this, false, 1);
- });
- });
-
- // tag cloud
- $('a.tagcloud-link').click(function(){
- tagBox.get( $(this).attr('id') );
- $(this).unbind().click(function(){
- $(this).siblings('.the-tagcloud').toggle();
- return false;
- });
- return false;
- });
- }
-};
-
commentsBox = {
st : 0,
this.st += num;
this.total = total;
- $('#commentsdiv .spinner').show();
+ $( '#commentsdiv .spinner' ).addClass( 'is-active' );
data = {
'action' : 'get-comments',
function(r) {
r = wpAjax.parseAjaxResponse(r);
$('#commentsdiv .widefat').show();
- $('#commentsdiv .spinner').hide();
+ $( '#commentsdiv .spinner' ).removeClass( 'is-active' );
if ( 'object' == typeof r && r.responses[0] ) {
$('#the-comment-list').append( r.responses[0].data );
}
// The form is being submitted by the user
- $submitButtons = $submitpost.find( ':button, :submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) {
+ $submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) {
var $button = $(this);
if ( $button.hasClass('disabled') ) {
$submitButtons.addClass( 'disabled' );
if ( $button.attr('id') === 'publish' ) {
- $submitpost.find('#major-publishing-actions .spinner').show();
+ $submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' );
} else {
- $submitpost.find('#minor-publishing .spinner').show();
+ $submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' );
}
});
});
// multi-taxonomies
if ( $('#tagsdiv-post_tag').length ) {
- tagBox.init();
+ window.tagBox && window.tagBox.init();
} else {
$('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
if ( this.id.indexOf('tagsdiv-') === 0 ) {
- tagBox.init();
+ window.tagBox && window.tagBox.init();
return false;
}
});
wp.autosave.enableButtons();
}
- $('#publishing-action .spinner').hide();
+ $( '#publishing-action .spinner' ).removeClass( 'is-active' );
}
});
revert_slug = real_slug.val(),
b = $('#edit-slug-buttons'),
revert_b = b.html(),
- full = $('#editable-post-name-full').html();
+ full = $('#editable-post-name-full');
+
+ // Deal with Twemoji in the post-name
+ full.find( 'img' ).replaceWith( function() { return this.alt; } );
+ full = full.html();
$('#view-post-btn').hide();
b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
b.children('.save').click(function() {
var new_slug = e.children('input').val();
if ( new_slug == $('#editable-post-name-full').text() ) {
- return $('#edit-slug-buttons .cancel').click();
+ b.children('.cancel').click();
+ return false;
}
$.post(ajaxurl, {
action: 'sample-permalink',
box.removeClass('hidden');
});
}
+
b.html(revert_b);
real_slug.val(new_slug);
$('#view-post-btn').show();
return false;
});
- $('#edit-slug-buttons .cancel').click(function() {
+ b.children('.cancel').click(function() {
$('#view-post-btn').show();
e.html(revert_e);
b.html(revert_b);
( function() {
var editor, offset, mce,
$textarea = $('textarea#content'),
- $handle = $('#post-status-info');
+ $handle = $('#post-status-info'),
+ $postdivrich = $('#postdivrich');
// No point for touch devices
if ( ! $textarea.length || 'ontouchstart' in window ) {
+ // Hide the resize handle
+ $('#content-resize-handle').hide();
return;
}
function dragging( event ) {
+ if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
+ return;
+ }
+
if ( mce ) {
editor.theme.resizeTo( null, offset + event.pageY );
} else {
function endDrag() {
var height, toolbarHeight;
+ if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
+ return;
+ }
+
if ( mce ) {
editor.focus();
toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 );
}
}
- $textarea.css( 'resize', 'none' );
-
$handle.on( 'mousedown.wp-editor-resize', function( event ) {
if ( typeof tinymce !== 'undefined' ) {
editor = tinymce.get('content');
$( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
var editor, body, format = this.id;
- if ( format && $( this ).prop('checked') ) {
- editor = tinymce.get( 'content' );
-
- if ( editor ) {
- body = editor.getBody();
- body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
- editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
- }
+ if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) {
+ body = editor.getBody();
+ body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
+ editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
+ $( document ).trigger( 'editor-classchange' );
}
});
}