diff --git a/wp-admin/js/press-this.js b/wp-admin/js/press-this.js index 2c61b605d1..057ce0e5f7 100644 --- a/wp-admin/js/press-this.js +++ b/wp-admin/js/press-this.js @@ -6,6 +6,7 @@ var PressThis = function() { var editor, $mediaList, $mediaThumbWrap, saveAlert = false, + editLinkVisible = false, textarea = document.createElement( 'textarea' ), sidebarIsOpen = false, settings = window.wpPressThisConfig || {}, @@ -102,9 +103,7 @@ */ function showSpinner() { $( '.spinner' ).addClass( 'is-active' ); - $( '.post-actions button' ).each( function() { - $( this ).attr( 'disabled', 'disabled' ); - } ); + $( '.post-actions button' ).attr( 'disabled', 'disabled' ); } /** @@ -112,9 +111,7 @@ */ function hideSpinner() { $( '.spinner' ).removeClass( 'is-active' ); - $( '.post-actions button' ).each( function() { - $( this ).removeAttr( 'disabled' ); - } ); + $( '.post-actions button' ).removeAttr( 'disabled' ); } /** @@ -166,7 +163,8 @@ * @param action string publish|draft */ function submitPost( action ) { - var data; + var data, + keepFocus = $( document.activeElement ).hasClass( 'draft-button' ); saveAlert = false; showSpinner(); @@ -186,7 +184,7 @@ hideSpinner(); clearNotices(); }).done( function( response ) { - var $link, $button, keepFocus; + var $link, $button; if ( ! response.success ) { renderError( response.data.errorMessage ); @@ -203,18 +201,17 @@ } else if ( response.data.postSaved ) { $link = $( '.edit-post-link' ); $button = $( '.draft-button' ); - - if ( document.activeElement && document.activeElement.className.indexOf( 'draft-button' ) > -1 ) { - keepFocus = true; - } + editLinkVisible = true; $button.fadeOut( 200, function() { $button.removeClass( 'is-saving' ); - $link.fadeIn( 200 ); - - if ( keepFocus ) { - $link.focus(); - } + $link.fadeIn( 200, function() { + var active = document.activeElement; + // Different browsers move the focus to different places when the button is disabled. + if ( keepFocus && ( active === $button[0] || $( active ).hasClass( 'post-actions' ) || active.nodeName === 'BODY' ) ) { + $link.focus(); + } + }); }); } }).fail( function() { @@ -223,9 +220,13 @@ } function resetDraftButton() { - $( '.edit-post-link' ).fadeOut( 200, function() { - $( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 ); - }); + if ( editLinkVisible ) { + editLinkVisible = false; + + $( '.edit-post-link' ).fadeOut( 200, function() { + $( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 ); + }); + } } /** @@ -655,16 +656,10 @@ $( document ).on( 'tinymce-editor-init', function( event, ed ) { editor = ed; - function focus() { + editor.on( 'nodechange', function() { hasSetFocus = true; resetDraftButton(); - } - - if ( window.tinymce.Env.iOS ) { - editor.on( 'click', focus ); - } else { - editor.on( 'focus', focus ); - } + } ); }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) { if ( event.type === 'click' || event.keyCode === 13 ) { insertSelectedMedia( $( this ) ); diff --git a/wp-admin/js/press-this.min.js b/wp-admin/js/press-this.min.js index 5526cd11de..b8fb18bc99 100644 --- a/wp-admin/js/press-this.min.js +++ b/wp-admin/js/press-this.min.js @@ -1 +1 @@ -!function(a,b){var c=function(){function c(a){return a&&b.pressThisL10n?b.pressThisL10n[a]||a:a||""}function d(a){return a=a||"",a.replace(/|$)/g,"").replace(/<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/gi,"").replace(/<\/?[a-z][\s\S]*?(>|$)/gi,"")}function e(a){var b=d(a);try{I.innerHTML=b,b=d(I.value)}catch(c){}return b}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(){a(".spinner").addClass("is-active"),a(".post-actions button").each(function(){a(this).attr("disabled","disabled")})}function h(){a(".spinner").removeClass("is-active"),a(".post-actions button").each(function(){a(this).removeAttr("disabled")})}function i(){var b=a("#title-container");return b.find("img.emoji").each(function(){var b=a(this);b.replaceWith(a("").text(b.attr("alt")))}),e(b.text())}function j(){var c=a("#pressthis-form"),d=a('');E&&E.save(),a("#post_title").val(i()),b.tagBox&&a("div.tagsdiv").each(function(){b.tagBox.flushTags(this,!1,1)}),a(".categories-select .category").each(function(b,e){var f=a(e);f.hasClass("selected")&&c.append(d.clone().val(f.attr("data-term-id")||""))})}function k(d){var e;H=!1,g(),"publish"===d&&a("#post_status").val("publish"),j(),e=a("#pressthis-form").serialize(),a.ajax({type:"post",url:b.ajaxurl,data:e}).always(function(){h(),r()}).done(function(c){var d,e,f;if(c.success)if(c.data.redirect)if(b.opener&&K.redirInParent){try{b.opener.location.href=c.data.redirect}catch(g){}b.self.close()}else b.location.href=c.data.redirect;else c.data.postSaved&&(d=a(".edit-post-link"),e=a(".draft-button"),document.activeElement&&document.activeElement.className.indexOf("draft-button")>-1&&(f=!0),e.fadeOut(200,function(){e.removeClass("is-saving"),d.fadeIn(200),f&&d.focus()}));else q(c.data.errorMessage)}).fail(function(){q(c("serverError"))})}function l(){a(".edit-post-link").fadeOut(200,function(){a(".draft-button").removeClass("is-saving").fadeIn(200)})}function m(a){var b,c,d="";E&&(b=f(a.attr("data-wp-src")||""),c=f(L.u),a.hasClass("is-image")?(c||(c=b),d=''):d="[embed]"+b+"[/embed]",N?E.execCommand("mceInsertContent",!1,d):E.setContent("

"+d+"

"+E.getContent()))}function n(){var c,d=a("#new-category").val();d&&(c={action:"press-this-add-category",post_id:a("#post_ID").val()||0,name:d,new_cat_nonce:a("#_ajax_nonce-add-category").val()||"",parent:a("#new-category-parent").val()||0},a.post(b.ajaxurl,c,function(b){if(b.success){var c,d,e=a("ul.categories-select");a.each(b.data,function(b,f){var g=a("
  • ").append(a('