From 2869e3a186e30fb00995a4e805ae0a63c2bd4046 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 9 Oct 2023 21:31:27 +0000 Subject: [PATCH] Administration: Remove deprecated `unload` event handlers and use `pagehide` (and `pageshow`) when appropriate. Use `pagehide` event instead of `unload` in the following cases: * For classic editor to release the post lock. * In Text widget to rebuild editor after dragging widget to new location in classic widgets interface. * To clear out the `window.name` when navigating away from a post preview. * To suspend heartbeat, while also using `pageshow` event to resume as if it had been a focused tab in case page restored from bfcache. Also: * Remove obsolete mobile cleanup code in `js/_enqueues/lib/gallery.js` (introduced in [9894]). Do same for `src/js/_enqueues/wp/media/models.js` (introduced in [22872]). See #22552. * Remove obsolete Firefox-specific workaround in `js/_enqueues/wp/mce-view.js` from [39282]. See #38511. Fixes #55491. Props spenserhale, westonruter, adamsilverstein, azaozz, shawfactor, peterwilsoncc, swissspidy. Built from https://develop.svn.wordpress.org/trunk@56809 git-svn-id: http://core.svn.wordpress.org/trunk@56321 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/gallery.js | 2 -- wp-admin/js/gallery.min.js | 2 +- wp-admin/js/post.js | 2 +- wp-admin/js/post.min.js | 2 +- wp-admin/js/widgets/text-widgets.js | 2 +- wp-admin/js/widgets/text-widgets.min.js | 2 +- wp-includes/functions.php | 4 +-- wp-includes/js/heartbeat.js | 41 ++++++++++++++++++++++--- wp-includes/js/heartbeat.min.js | 2 +- wp-includes/js/mce-view.js | 12 +------- wp-includes/js/mce-view.min.js | 2 +- wp-includes/js/media-models.js | 8 +---- wp-includes/js/media-models.min.js | 2 +- wp-includes/version.php | 2 +- 14 files changed, 50 insertions(+), 35 deletions(-) diff --git a/wp-admin/js/gallery.js b/wp-admin/js/gallery.js index d493946c5b..761b36db97 100644 --- a/wp-admin/js/gallery.js +++ b/wp-admin/js/gallery.js @@ -88,8 +88,6 @@ jQuery( function($) { } }); -jQuery(window).on( 'unload', function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup. - /* gallery settings */ window.tinymce = null; diff --git a/wp-admin/js/gallery.min.js b/wp-admin/js/gallery.min.js index 3cc5afd917..19c13168a9 100644 --- a/wp-admin/js/gallery.min.js +++ b/wp-admin/js/gallery.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -jQuery(function(n){var o=!1,e=function(){n("#media-items").sortable({items:"div.media-item",placeholder:"sorthelper",axis:"y",distance:2,handle:"div.filename",stop:function(){var e=n("#media-items").sortable("toArray"),i=e.length;n.each(e,function(e,t){e=o?i-e:1+e;n("#"+t+" .menu_order input").val(e)})}})},t=function(){var e=n(".menu_order_input"),t=e.length;e.each(function(e){e=o?t-e:1+e;n(this).val(e)})},i=function(e){e=e||0,n(".menu_order_input").each(function(){"0"!==this.value&&!e||(this.value="")})};n("#asc").on("click",function(e){e.preventDefault(),o=!1,t()}),n("#desc").on("click",function(e){e.preventDefault(),o=!0,t()}),n("#clear").on("click",function(e){e.preventDefault(),i(1)}),n("#showall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").hide(),n("a.describe-toggle-off, table.slidetoggle").show(),n("img.pinkynail").toggle(!1)}),n("#hideall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").show(),n("a.describe-toggle-off, table.slidetoggle").hide(),n("img.pinkynail").toggle(!0)}),e(),i(),1*").length&&(e=wpgallery.getWin(),n("#save-all, #gallery-settings").show(),void 0!==e.tinyMCE&&e.tinyMCE.activeEditor&&!e.tinyMCE.activeEditor.isHidden()?(wpgallery.mcemode=!0,wpgallery.init()):n("#insert-gallery").show())}),jQuery(window).on("unload",function(){window.tinymce=window.tinyMCE=window.wpgallery=null}),window.tinymce=null,window.wpgallery={mcemode:!1,editor:{},dom:{},is_update:!1,el:{},I:function(e){return document.getElementById(e)},init:function(){var e,t,i,n,o=this,l=o.getWin();if(o.mcemode){for(e=(""+document.location.search).replace(/^\?/,"").split("&"),t={},i=0;i*").length&&(e=wpgallery.getWin(),n("#save-all, #gallery-settings").show(),void 0!==e.tinyMCE&&e.tinyMCE.activeEditor&&!e.tinyMCE.activeEditor.isHidden()?(wpgallery.mcemode=!0,wpgallery.init()):n("#insert-gallery").show())}),window.tinymce=null,window.wpgallery={mcemode:!1,editor:{},dom:{},is_update:!1,el:{},I:function(e){return document.getElementById(e)},init:function(){var e,t,i,n,o=this,l=o.getWin();if(o.mcemode){for(e=(""+document.location.search).replace(/^\?/,"").split("&"),t={},i=0;icommentsBox.total?s("#show-comments").hide():s("#show-comments").show().children("a").text(a("Show more comments"))):1==t?s("#show-comments").text(a("No more comments found.")):s("#the-comment-list").append(''+wpAjax.broken+"")}),!1},load:function(t){this.st=jQuery("#the-comment-list tr.comment:visible").length,this.get(t)}},window.WPSetThumbnailHTML=function(t){s(".inside","#postimagediv").html(t)},window.WPSetThumbnailID=function(t){var e=s('input[value="_thumbnail_id"]',"#list-table");0",{class:"avatar avatar-64 photo",width:64,height:64,alt:"",src:e.lock_error.avatar_src,srcset:e.lock_error.avatar_src_2x?e.lock_error.avatar_src_2x+" 2x":void 0}),i.find("div.post-locked-avatar").empty().append(a)),i.show().find(".currently-editing").text(e.lock_error.text),i.find(".wp-tab-first").trigger("focus")):e.new_lock&&s("#active_post_lock").val(e.new_lock))}).on("before-autosave.update-post-slug",function(){t=document.activeElement&&"title"===document.activeElement.id}).on("after-autosave.update-post-slug",function(){s("#edit-slug-box > *").length||t||s.post(ajaxurl,{action:"sample-permalink",post_id:s("#post_ID").val(),new_title:s("#title").val(),samplepermalinknonce:s("#samplepermalinknonce").val()},function(t){"-1"!=t&&s("#edit-slug-box").html(t)})})}(jQuery),function(a){var n,t;function i(){n=!1,window.clearTimeout(t),t=window.setTimeout(function(){n=!0},3e5)}a(function(){i()}).on("heartbeat-send.wp-refresh-nonces",function(t,e){var i=a("#wp-auth-check-wrap");(n||i.length&&!i.hasClass("hidden"))&&(i=a("#post_ID").val())&&a("#_wpnonce").val()&&(e["wp-refresh-post-nonces"]={post_id:i})}).on("heartbeat-tick.wp-refresh-nonces",function(t,e){e=e["wp-refresh-post-nonces"];e&&(i(),e.replace&&a.each(e.replace,function(t,e){a("#"+t).val(e)}),e.heartbeatNonce)&&(window.heartbeatSettings.nonce=e.heartbeatNonce)})}(jQuery),jQuery(function(h){var p,e,i,a,n,s,o,l,r,t,c,d,u=h("#content"),f=h(document),v=h("#post_ID").val()||0,m=h("#submitpost"),g=!0,w=h("#post-visibility-select"),b=h("#timestampdiv"),k=h("#post-status-select"),_=!!window.navigator.platform&&-1!==window.navigator.platform.indexOf("Mac"),y=new ClipboardJS(".copy-attachment-url.edit-media"),x=wp.i18n.__,C=wp.i18n._x;function D(t){c.hasClass("wp-editor-expand")||(r?o.theme.resizeTo(null,l+t.pageY):u.height(Math.max(50,l+t.pageY)),t.preventDefault())}function j(){var t;c.hasClass("wp-editor-expand")||(t=r?(o.focus(),((t=parseInt(h("#wp-content-editor-container .mce-toolbar-grp").height(),10))<10||200 *").length&&(h("form#post").one("submit",function(){t=!0}),window.setTimeout(function(){!t&&wp.autosave&&wp.autosave.server.triggerSave()},200))}),f.on("autosave-disable-buttons.edit-post",function(){i.addClass("disabled")}).on("autosave-enable-buttons.edit-post",function(){wp.heartbeat&&wp.heartbeat.hasConnectionError()||i.removeClass("disabled")}).on("before-autosave.edit-post",function(){h(".autosave-message").text(x("Saving Draft\u2026"))}).on("after-autosave.edit-post",function(t,e){h(".autosave-message").text(e.message),h(document.body).hasClass("post-new-php")&&h(".submitbox .submitdelete").show()}),h(window).on("beforeunload.edit-post",function(t){var e=window.tinymce&&window.tinymce.get("content"),i=!1;if(wp.autosave?i=wp.autosave.server.postChanged():e&&(i=!e.isHidden()&&e.isDirty()),i)return t.preventDefault(),x("The changes you made will be lost if you navigate away from this page.")}).on("unload.edit-post",function(t){if(g&&(!t.target||"#document"==t.target.nodeName)){var t=h("#post_ID").val(),e=h("#active_post_lock").val();if(t&&e){t={action:"wp-remove-post-lock",_wpnonce:h("#_wpnonce").val(),post_ID:t,active_post_lock:e};if(window.FormData&&window.navigator.sendBeacon){var i=new window.FormData;if(h.each(t,function(t,e){i.append(t,e)}),window.navigator.sendBeacon(ajaxurl,i))return}h.post({async:!1,data:t,url:ajaxurl})}}}),h("#tagsdiv-post_tag").length?window.tagBox&&window.tagBox.init():h(".meta-box-sortables").children("div.postbox").each(function(){if(0===this.id.indexOf("tagsdiv-"))return window.tagBox&&window.tagBox.init(),!1}),h(".categorydiv").each(function(){var t,a,e,i=h(this).attr("id").split("-");i.shift(),a=i.join("-"),e="category"==a?"cats":a+"_tab",h("a","#"+a+"-tabs").on("click",function(t){t.preventDefault();t=h(this).attr("href");h(this).parent().addClass("tabs").siblings("li").removeClass("tabs"),h("#"+a+"-tabs").siblings(".tabs-panel").hide(),h(t).show(),"#"+a+"-all"==t?deleteUserSetting(e):setUserSetting(e,"pop")}),getUserSetting(e)&&h('a[href="#'+a+'-pop"]',"#"+a+"-tabs").trigger("click"),h("#new"+a).one("focus",function(){h(this).val("").removeClass("form-input-tip")}),h("#new"+a).on("keypress",function(t){13===t.keyCode&&(t.preventDefault(),h("#"+a+"-add-submit").trigger("click"))}),h("#"+a+"-add-submit").on("click",function(){h("#new"+a).trigger("focus")}),i=function(t){return!!h("#new"+a).val()&&(t.data+="&"+h(":checked","#"+a+"checklist").serialize(),h("#"+a+"-add-submit").prop("disabled",!0),t)},t=function(t,e){var i=h("#new"+a+"_parent");h("#"+a+"-add-submit").prop("disabled",!1),"undefined"!=e.parsed.responses[0]&&(e=e.parsed.responses[0].supplemental.newcat_parent)&&(i.before(e),i.remove())},h("#"+a+"checklist").wpList({alt:"",response:a+"-ajax-response",addBefore:i,addAfter:t}),h("#"+a+"-add-toggle").on("click",function(t){t.preventDefault(),h("#"+a+"-adder").toggleClass("wp-hidden-children"),h('a[href="#'+a+'-all"]',"#"+a+"-tabs").trigger("click"),h("#new"+a).trigger("focus")}),h("#"+a+"checklist, #"+a+"checklist-pop").on("click",'li.popular-category > label input[type="checkbox"]',function(){var t=h(this),e=t.is(":checked"),i=t.val();i&&t.parents("#taxonomy-"+a).length&&h("#in-"+a+"-"+i+", #in-popular-"+a+"-"+i).prop("checked",e)})}),h("#postcustom").length&&h("#the-list").wpList({addBefore:function(t){return t.data+="&post_id="+h("#post_ID").val(),t},addAfter:function(){h("table#list-table").show()}}),h("#submitdiv").length&&(p=h("#timestamp").html(),e=h("#post-visibility-display").html(),a=function(){"public"!=w.find("input:radio:checked").val()?(h("#sticky").prop("checked",!1),h("#sticky-span").hide()):h("#sticky-span").show(),"password"!=w.find("input:radio:checked").val()?h("#password-span").hide():h("#password-span").show()},n=function(){if(b.length){var t,e=h("#post_status"),i=h('option[value="publish"]',e),a=h("#aa").val(),n=h("#mm").val(),s=h("#jj").val(),o=h("#hh").val(),l=h("#mn").val(),r=new Date(a,n-1,s,o,l),c=new Date(h("#hidden_aa").val(),h("#hidden_mm").val()-1,h("#hidden_jj").val(),h("#hidden_hh").val(),h("#hidden_mn").val()),d=new Date(h("#cur_aa").val(),h("#cur_mm").val()-1,h("#cur_jj").val(),h("#cur_hh").val(),h("#cur_mn").val());if(r.getFullYear()!=a||1+r.getMonth()!=n||r.getDate()!=s||r.getMinutes()!=l)return b.find(".timestamp-wrap").addClass("form-invalid"),!1;b.find(".timestamp-wrap").removeClass("form-invalid"),d"+x("%1$s %2$s, %3$s at %4$s:%5$s").replace("%1$s",h('option[value="'+n+'"]',"#mm").attr("data-text")).replace("%2$s",parseInt(s,10)).replace("%3$s",a).replace("%4$s",("00"+o).slice(-2)).replace("%5$s",("00"+l).slice(-2))+" "),"private"==w.find("input:radio:checked").val()?(h("#publish").val(x("Update")),0===i.length?e.append('"):i.html(x("Privately Published")),h('option[value="publish"]',e).prop("selected",!0),h("#misc-publishing-actions .edit-post-status").hide()):("future"==h("#original_post_status").val()||"draft"==h("#original_post_status").val()?i.length&&(i.remove(),e.val(h("#hidden_post_status").val())):i.html(x("Published")),e.is(":hidden")&&h("#misc-publishing-actions .edit-post-status").show()),h("#post-status-display").text(wp.sanitize.stripTagsAndEncodeText(h("option:selected",e).text())),"private"==h("option:selected",e).val()||"publish"==h("option:selected",e).val()?h("#save-post").hide():(h("#save-post").show(),"pending"==h("option:selected",e).val()?h("#save-post").show().val(x("Save as Pending")):h("#save-post").show().val(x("Save Draft")))}return!0},h("#visibility .edit-visibility").on("click",function(t){t.preventDefault(),w.is(":hidden")&&(a(),w.slideDown("fast",function(){w.find('input[type="radio"]').first().trigger("focus")}),h(this).hide())}),w.find(".cancel-post-visibility").on("click",function(t){w.slideUp("fast"),h("#visibility-radio-"+h("#hidden-post-visibility").val()).prop("checked",!0),h("#post_password").val(h("#hidden-post-password").val()),h("#sticky").prop("checked",h("#hidden-post-sticky").prop("checked")),h("#post-visibility-display").html(e),h("#visibility .edit-visibility").show().trigger("focus"),n(),t.preventDefault()}),w.find(".save-post-visibility").on("click",function(t){var e="",i=w.find("input:radio:checked").val();switch(w.slideUp("fast"),h("#visibility .edit-visibility").show().trigger("focus"),n(),"public"!==i&&h("#sticky").prop("checked",!1),i){case"public":e=h("#sticky").prop("checked")?x("Public, Sticky"):x("Public");break;case"private":e=x("Private");break;case"password":e=x("Password Protected")}h("#post-visibility-display").text(e),t.preventDefault()}),w.find("input:radio").on("change",function(){a()}),b.siblings("a.edit-timestamp").on("click",function(t){b.is(":hidden")&&(b.slideDown("fast",function(){h("input, select",b.find(".timestamp-wrap")).first().trigger("focus")}),h(this).hide()),t.preventDefault()}),b.find(".cancel-timestamp").on("click",function(t){b.slideUp("fast").siblings("a.edit-timestamp").show().trigger("focus"),h("#mm").val(h("#hidden_mm").val()),h("#jj").val(h("#hidden_jj").val()),h("#aa").val(h("#hidden_aa").val()),h("#hh").val(h("#hidden_hh").val()),h("#mn").val(h("#hidden_mn").val()),n(),t.preventDefault()}),b.find(".save-timestamp").on("click",function(t){n()&&(b.slideUp("fast"),b.siblings("a.edit-timestamp").show().trigger("focus")),t.preventDefault()}),h("#post").on("submit",function(t){n()||(t.preventDefault(),b.show(),wp.autosave&&wp.autosave.enableButtons(),h("#publishing-action .spinner").removeClass("is-active"))}),k.siblings("a.edit-post-status").on("click",function(t){k.is(":hidden")&&(k.slideDown("fast",function(){k.find("select").trigger("focus")}),h(this).hide()),t.preventDefault()}),k.find(".save-post-status").on("click",function(t){k.slideUp("fast").siblings("a.edit-post-status").show().trigger("focus"),n(),t.preventDefault()}),k.find(".cancel-post-status").on("click",function(t){k.slideUp("fast").siblings("a.edit-post-status").show().trigger("focus"),h("#post_status").val(h("#hidden_post_status").val()),n(),t.preventDefault()})),h("#titlediv").on("click",".edit-slug",function(){var t,e,a,i,n=0,s=h("#post_name"),o=s.val(),l=h("#sample-permalink"),r=l.html(),c=h("#sample-permalink a").html(),d=h("#edit-slug-buttons"),p=d.html(),u=h("#editable-post-name-full");for(u.find("img").replaceWith(function(){return this.alt}),u=u.html(),l.html(c),a=h("#editable-post-name"),i=a.html(),d.html(' "),d.children(".save").on("click",function(){var i=a.children("input").val();i==h("#editable-post-name-full").text()?d.children(".cancel").trigger("click"):h.post(ajaxurl,{action:"sample-permalink",post_id:v,new_slug:i,new_title:h("#title").val(),samplepermalinknonce:h("#samplepermalinknonce").val()},function(t){var e=h("#edit-slug-box");e.html(t),e.hasClass("hidden")&&e.fadeIn("fast",function(){e.removeClass("hidden")}),d.html(p),l.html(r),s.val(i),h(".edit-slug").trigger("focus"),wp.a11y.speak(x("Permalink saved"))})}),d.children(".cancel").on("click",function(){h("#view-post-btn").show(),a.html(i),d.html(p),l.html(r),s.val(o),h(".edit-slug").trigger("focus")}),t=0;tu.length/4?"":u,e=x("URL Slug"),a.html('').children("input").on("keydown",function(t){var e=t.which;13===e&&(t.preventDefault(),d.children(".save").trigger("click")),27===e&&d.children(".cancel").trigger("click")}).on("keyup",function(){s.val(this.value)}).trigger("focus")}),window.wptitlehint=function(t){var e=h("#"+(t=t||"title")),i=h("#"+t+"-prompt-text");""===e.val()&&i.removeClass("screen-reader-text"),e.on("input",function(){""===this.value?i.removeClass("screen-reader-text"):i.addClass("screen-reader-text")})},wptitlehint(),t=h("#post-status-info"),c=h("#postdivrich"),!u.length||"ontouchstart"in window?h("#content-resize-handle").hide():t.on("mousedown.wp-editor-resize",function(t){(o="undefined"!=typeof tinymce?tinymce.get("content"):o)&&!o.isHidden()?(r=!0,l=h("#content_ifr").height()-t.pageY):(r=!1,l=u.height()-t.pageY,u.trigger("blur")),f.on("mousemove.wp-editor-resize",D).on("mouseup.wp-editor-resize mouseleave.wp-editor-resize",j),t.preventDefault()}).on("mouseup.wp-editor-resize",j),"undefined"!=typeof tinymce&&(h("#post-formats-select input.post-format").on("change.set-editor-class",function(){var t,e,i=this.id;i&&h(this).prop("checked")&&(t=tinymce.get("content"))&&((e=t.getBody()).className=e.className.replace(/\bpost-format-[^ ]+/,""),t.dom.addClass(e,"post-format-0"==i?"post-format-standard":i),h(document).trigger("editor-classchange"))}),h("#page_template").on("change.set-editor-class",function(){var t,e,i=h(this).val()||"";(i=i.substr(i.lastIndexOf("/")+1,i.length).replace(/\.php$/,"").replace(/\./g,"-"))&&(t=tinymce.get("content"))&&((e=t.getBody()).className=e.className.replace(/\bpage-template-[^ ]+/,""),t.dom.addClass(e,"page-template-"+i),h(document).trigger("editor-classchange"))})),u.on("keydown.wp-autosave",function(t){83!==t.which||t.shiftKey||t.altKey||_&&(!t.metaKey||t.ctrlKey)||!_&&!t.ctrlKey||(wp.autosave&&wp.autosave.server.triggerSave(),t.preventDefault())}),"auto-draft"===h("#original_post_status").val()&&window.history.replaceState&&h("#publish").on("click",function(){d=(d=window.location.href)+(-1!==d.indexOf("?")?"&":"?")+"wp-post-new-reload=true",window.history.replaceState(null,null,d)}),y.on("success",function(t){var e=h(t.trigger),i=h(".success",e.closest(".copy-to-clipboard-container"));t.clearSelection(),e.trigger("focus"),clearTimeout(s),i.removeClass("hidden"),s=setTimeout(function(){i.addClass("hidden")},3e3),wp.a11y.speak(x("The file URL has been copied to your clipboard"))})}),function(t,o){t(function(){var i,e=t("#content"),a=t("#wp-word-count").find(".word-count"),n=0;function s(){var t=!i||i.isHidden()?e.val():i.getContent({format:"raw"}),t=o.count(t);t!==n&&a.text(t),n=t}t(document).on("tinymce-editor-init",function(t,e){"content"===e.id&&(i=e).on("nodechange keyup",_.debounce(s,1e3))}),e.on("input keyup",_.debounce(s,1e3)),s()})}(jQuery,new wp.utils.WordCounter); \ No newline at end of file +window.makeSlugeditClickable=window.editPermalink=function(){},window.wp=window.wp||{},function(s){var t=!1,a=wp.i18n.__;window.commentsBox={st:0,get:function(t,e){var i=this.st;return this.st+=e=e||20,this.total=t,s("#commentsdiv .spinner").addClass("is-active"),t={action:"get-comments",mode:"single",_ajax_nonce:s("#add_comment_nonce").val(),p:s("#post_ID").val(),start:i,number:e},s.post(ajaxurl,t,function(t){t=wpAjax.parseAjaxResponse(t),s("#commentsdiv .widefat").show(),s("#commentsdiv .spinner").removeClass("is-active"),"object"==typeof t&&t.responses[0]?(s("#the-comment-list").append(t.responses[0].data),theList=theExtraList=null,s("a[className*=':']").off(),commentsBox.st>commentsBox.total?s("#show-comments").hide():s("#show-comments").show().children("a").text(a("Show more comments"))):1==t?s("#show-comments").text(a("No more comments found.")):s("#the-comment-list").append(''+wpAjax.broken+"")}),!1},load:function(t){this.st=jQuery("#the-comment-list tr.comment:visible").length,this.get(t)}},window.WPSetThumbnailHTML=function(t){s(".inside","#postimagediv").html(t)},window.WPSetThumbnailID=function(t){var e=s('input[value="_thumbnail_id"]',"#list-table");0",{class:"avatar avatar-64 photo",width:64,height:64,alt:"",src:e.lock_error.avatar_src,srcset:e.lock_error.avatar_src_2x?e.lock_error.avatar_src_2x+" 2x":void 0}),i.find("div.post-locked-avatar").empty().append(a)),i.show().find(".currently-editing").text(e.lock_error.text),i.find(".wp-tab-first").trigger("focus")):e.new_lock&&s("#active_post_lock").val(e.new_lock))}).on("before-autosave.update-post-slug",function(){t=document.activeElement&&"title"===document.activeElement.id}).on("after-autosave.update-post-slug",function(){s("#edit-slug-box > *").length||t||s.post(ajaxurl,{action:"sample-permalink",post_id:s("#post_ID").val(),new_title:s("#title").val(),samplepermalinknonce:s("#samplepermalinknonce").val()},function(t){"-1"!=t&&s("#edit-slug-box").html(t)})})}(jQuery),function(a){var n,t;function i(){n=!1,window.clearTimeout(t),t=window.setTimeout(function(){n=!0},3e5)}a(function(){i()}).on("heartbeat-send.wp-refresh-nonces",function(t,e){var i=a("#wp-auth-check-wrap");(n||i.length&&!i.hasClass("hidden"))&&(i=a("#post_ID").val())&&a("#_wpnonce").val()&&(e["wp-refresh-post-nonces"]={post_id:i})}).on("heartbeat-tick.wp-refresh-nonces",function(t,e){e=e["wp-refresh-post-nonces"];e&&(i(),e.replace&&a.each(e.replace,function(t,e){a("#"+t).val(e)}),e.heartbeatNonce)&&(window.heartbeatSettings.nonce=e.heartbeatNonce)})}(jQuery),jQuery(function(h){var p,e,i,a,n,s,o,l,r,t,c,d,u=h("#content"),f=h(document),v=h("#post_ID").val()||0,m=h("#submitpost"),g=!0,w=h("#post-visibility-select"),b=h("#timestampdiv"),k=h("#post-status-select"),_=!!window.navigator.platform&&-1!==window.navigator.platform.indexOf("Mac"),y=new ClipboardJS(".copy-attachment-url.edit-media"),x=wp.i18n.__,C=wp.i18n._x;function D(t){c.hasClass("wp-editor-expand")||(r?o.theme.resizeTo(null,l+t.pageY):u.height(Math.max(50,l+t.pageY)),t.preventDefault())}function j(){var t;c.hasClass("wp-editor-expand")||(t=r?(o.focus(),((t=parseInt(h("#wp-content-editor-container .mce-toolbar-grp").height(),10))<10||200 *").length&&(h("form#post").one("submit",function(){t=!0}),window.setTimeout(function(){!t&&wp.autosave&&wp.autosave.server.triggerSave()},200))}),f.on("autosave-disable-buttons.edit-post",function(){i.addClass("disabled")}).on("autosave-enable-buttons.edit-post",function(){wp.heartbeat&&wp.heartbeat.hasConnectionError()||i.removeClass("disabled")}).on("before-autosave.edit-post",function(){h(".autosave-message").text(x("Saving Draft\u2026"))}).on("after-autosave.edit-post",function(t,e){h(".autosave-message").text(e.message),h(document.body).hasClass("post-new-php")&&h(".submitbox .submitdelete").show()}),h(window).on("beforeunload.edit-post",function(t){var e=window.tinymce&&window.tinymce.get("content"),i=!1;if(wp.autosave?i=wp.autosave.server.postChanged():e&&(i=!e.isHidden()&&e.isDirty()),i)return t.preventDefault(),x("The changes you made will be lost if you navigate away from this page.")}).on("pagehide.edit-post",function(t){if(g&&(!t.target||"#document"==t.target.nodeName)){var t=h("#post_ID").val(),e=h("#active_post_lock").val();if(t&&e){t={action:"wp-remove-post-lock",_wpnonce:h("#_wpnonce").val(),post_ID:t,active_post_lock:e};if(window.FormData&&window.navigator.sendBeacon){var i=new window.FormData;if(h.each(t,function(t,e){i.append(t,e)}),window.navigator.sendBeacon(ajaxurl,i))return}h.post({async:!1,data:t,url:ajaxurl})}}}),h("#tagsdiv-post_tag").length?window.tagBox&&window.tagBox.init():h(".meta-box-sortables").children("div.postbox").each(function(){if(0===this.id.indexOf("tagsdiv-"))return window.tagBox&&window.tagBox.init(),!1}),h(".categorydiv").each(function(){var t,a,e,i=h(this).attr("id").split("-");i.shift(),a=i.join("-"),e="category"==a?"cats":a+"_tab",h("a","#"+a+"-tabs").on("click",function(t){t.preventDefault();t=h(this).attr("href");h(this).parent().addClass("tabs").siblings("li").removeClass("tabs"),h("#"+a+"-tabs").siblings(".tabs-panel").hide(),h(t).show(),"#"+a+"-all"==t?deleteUserSetting(e):setUserSetting(e,"pop")}),getUserSetting(e)&&h('a[href="#'+a+'-pop"]',"#"+a+"-tabs").trigger("click"),h("#new"+a).one("focus",function(){h(this).val("").removeClass("form-input-tip")}),h("#new"+a).on("keypress",function(t){13===t.keyCode&&(t.preventDefault(),h("#"+a+"-add-submit").trigger("click"))}),h("#"+a+"-add-submit").on("click",function(){h("#new"+a).trigger("focus")}),i=function(t){return!!h("#new"+a).val()&&(t.data+="&"+h(":checked","#"+a+"checklist").serialize(),h("#"+a+"-add-submit").prop("disabled",!0),t)},t=function(t,e){var i=h("#new"+a+"_parent");h("#"+a+"-add-submit").prop("disabled",!1),"undefined"!=e.parsed.responses[0]&&(e=e.parsed.responses[0].supplemental.newcat_parent)&&(i.before(e),i.remove())},h("#"+a+"checklist").wpList({alt:"",response:a+"-ajax-response",addBefore:i,addAfter:t}),h("#"+a+"-add-toggle").on("click",function(t){t.preventDefault(),h("#"+a+"-adder").toggleClass("wp-hidden-children"),h('a[href="#'+a+'-all"]',"#"+a+"-tabs").trigger("click"),h("#new"+a).trigger("focus")}),h("#"+a+"checklist, #"+a+"checklist-pop").on("click",'li.popular-category > label input[type="checkbox"]',function(){var t=h(this),e=t.is(":checked"),i=t.val();i&&t.parents("#taxonomy-"+a).length&&h("#in-"+a+"-"+i+", #in-popular-"+a+"-"+i).prop("checked",e)})}),h("#postcustom").length&&h("#the-list").wpList({addBefore:function(t){return t.data+="&post_id="+h("#post_ID").val(),t},addAfter:function(){h("table#list-table").show()}}),h("#submitdiv").length&&(p=h("#timestamp").html(),e=h("#post-visibility-display").html(),a=function(){"public"!=w.find("input:radio:checked").val()?(h("#sticky").prop("checked",!1),h("#sticky-span").hide()):h("#sticky-span").show(),"password"!=w.find("input:radio:checked").val()?h("#password-span").hide():h("#password-span").show()},n=function(){if(b.length){var t,e=h("#post_status"),i=h('option[value="publish"]',e),a=h("#aa").val(),n=h("#mm").val(),s=h("#jj").val(),o=h("#hh").val(),l=h("#mn").val(),r=new Date(a,n-1,s,o,l),c=new Date(h("#hidden_aa").val(),h("#hidden_mm").val()-1,h("#hidden_jj").val(),h("#hidden_hh").val(),h("#hidden_mn").val()),d=new Date(h("#cur_aa").val(),h("#cur_mm").val()-1,h("#cur_jj").val(),h("#cur_hh").val(),h("#cur_mn").val());if(r.getFullYear()!=a||1+r.getMonth()!=n||r.getDate()!=s||r.getMinutes()!=l)return b.find(".timestamp-wrap").addClass("form-invalid"),!1;b.find(".timestamp-wrap").removeClass("form-invalid"),d"+x("%1$s %2$s, %3$s at %4$s:%5$s").replace("%1$s",h('option[value="'+n+'"]',"#mm").attr("data-text")).replace("%2$s",parseInt(s,10)).replace("%3$s",a).replace("%4$s",("00"+o).slice(-2)).replace("%5$s",("00"+l).slice(-2))+" "),"private"==w.find("input:radio:checked").val()?(h("#publish").val(x("Update")),0===i.length?e.append('"):i.html(x("Privately Published")),h('option[value="publish"]',e).prop("selected",!0),h("#misc-publishing-actions .edit-post-status").hide()):("future"==h("#original_post_status").val()||"draft"==h("#original_post_status").val()?i.length&&(i.remove(),e.val(h("#hidden_post_status").val())):i.html(x("Published")),e.is(":hidden")&&h("#misc-publishing-actions .edit-post-status").show()),h("#post-status-display").text(wp.sanitize.stripTagsAndEncodeText(h("option:selected",e).text())),"private"==h("option:selected",e).val()||"publish"==h("option:selected",e).val()?h("#save-post").hide():(h("#save-post").show(),"pending"==h("option:selected",e).val()?h("#save-post").show().val(x("Save as Pending")):h("#save-post").show().val(x("Save Draft")))}return!0},h("#visibility .edit-visibility").on("click",function(t){t.preventDefault(),w.is(":hidden")&&(a(),w.slideDown("fast",function(){w.find('input[type="radio"]').first().trigger("focus")}),h(this).hide())}),w.find(".cancel-post-visibility").on("click",function(t){w.slideUp("fast"),h("#visibility-radio-"+h("#hidden-post-visibility").val()).prop("checked",!0),h("#post_password").val(h("#hidden-post-password").val()),h("#sticky").prop("checked",h("#hidden-post-sticky").prop("checked")),h("#post-visibility-display").html(e),h("#visibility .edit-visibility").show().trigger("focus"),n(),t.preventDefault()}),w.find(".save-post-visibility").on("click",function(t){var e="",i=w.find("input:radio:checked").val();switch(w.slideUp("fast"),h("#visibility .edit-visibility").show().trigger("focus"),n(),"public"!==i&&h("#sticky").prop("checked",!1),i){case"public":e=h("#sticky").prop("checked")?x("Public, Sticky"):x("Public");break;case"private":e=x("Private");break;case"password":e=x("Password Protected")}h("#post-visibility-display").text(e),t.preventDefault()}),w.find("input:radio").on("change",function(){a()}),b.siblings("a.edit-timestamp").on("click",function(t){b.is(":hidden")&&(b.slideDown("fast",function(){h("input, select",b.find(".timestamp-wrap")).first().trigger("focus")}),h(this).hide()),t.preventDefault()}),b.find(".cancel-timestamp").on("click",function(t){b.slideUp("fast").siblings("a.edit-timestamp").show().trigger("focus"),h("#mm").val(h("#hidden_mm").val()),h("#jj").val(h("#hidden_jj").val()),h("#aa").val(h("#hidden_aa").val()),h("#hh").val(h("#hidden_hh").val()),h("#mn").val(h("#hidden_mn").val()),n(),t.preventDefault()}),b.find(".save-timestamp").on("click",function(t){n()&&(b.slideUp("fast"),b.siblings("a.edit-timestamp").show().trigger("focus")),t.preventDefault()}),h("#post").on("submit",function(t){n()||(t.preventDefault(),b.show(),wp.autosave&&wp.autosave.enableButtons(),h("#publishing-action .spinner").removeClass("is-active"))}),k.siblings("a.edit-post-status").on("click",function(t){k.is(":hidden")&&(k.slideDown("fast",function(){k.find("select").trigger("focus")}),h(this).hide()),t.preventDefault()}),k.find(".save-post-status").on("click",function(t){k.slideUp("fast").siblings("a.edit-post-status").show().trigger("focus"),n(),t.preventDefault()}),k.find(".cancel-post-status").on("click",function(t){k.slideUp("fast").siblings("a.edit-post-status").show().trigger("focus"),h("#post_status").val(h("#hidden_post_status").val()),n(),t.preventDefault()})),h("#titlediv").on("click",".edit-slug",function(){var t,e,a,i,n=0,s=h("#post_name"),o=s.val(),l=h("#sample-permalink"),r=l.html(),c=h("#sample-permalink a").html(),d=h("#edit-slug-buttons"),p=d.html(),u=h("#editable-post-name-full");for(u.find("img").replaceWith(function(){return this.alt}),u=u.html(),l.html(c),a=h("#editable-post-name"),i=a.html(),d.html(' "),d.children(".save").on("click",function(){var i=a.children("input").val();i==h("#editable-post-name-full").text()?d.children(".cancel").trigger("click"):h.post(ajaxurl,{action:"sample-permalink",post_id:v,new_slug:i,new_title:h("#title").val(),samplepermalinknonce:h("#samplepermalinknonce").val()},function(t){var e=h("#edit-slug-box");e.html(t),e.hasClass("hidden")&&e.fadeIn("fast",function(){e.removeClass("hidden")}),d.html(p),l.html(r),s.val(i),h(".edit-slug").trigger("focus"),wp.a11y.speak(x("Permalink saved"))})}),d.children(".cancel").on("click",function(){h("#view-post-btn").show(),a.html(i),d.html(p),l.html(r),s.val(o),h(".edit-slug").trigger("focus")}),t=0;tu.length/4?"":u,e=x("URL Slug"),a.html('').children("input").on("keydown",function(t){var e=t.which;13===e&&(t.preventDefault(),d.children(".save").trigger("click")),27===e&&d.children(".cancel").trigger("click")}).on("keyup",function(){s.val(this.value)}).trigger("focus")}),window.wptitlehint=function(t){var e=h("#"+(t=t||"title")),i=h("#"+t+"-prompt-text");""===e.val()&&i.removeClass("screen-reader-text"),e.on("input",function(){""===this.value?i.removeClass("screen-reader-text"):i.addClass("screen-reader-text")})},wptitlehint(),t=h("#post-status-info"),c=h("#postdivrich"),!u.length||"ontouchstart"in window?h("#content-resize-handle").hide():t.on("mousedown.wp-editor-resize",function(t){(o="undefined"!=typeof tinymce?tinymce.get("content"):o)&&!o.isHidden()?(r=!0,l=h("#content_ifr").height()-t.pageY):(r=!1,l=u.height()-t.pageY,u.trigger("blur")),f.on("mousemove.wp-editor-resize",D).on("mouseup.wp-editor-resize mouseleave.wp-editor-resize",j),t.preventDefault()}).on("mouseup.wp-editor-resize",j),"undefined"!=typeof tinymce&&(h("#post-formats-select input.post-format").on("change.set-editor-class",function(){var t,e,i=this.id;i&&h(this).prop("checked")&&(t=tinymce.get("content"))&&((e=t.getBody()).className=e.className.replace(/\bpost-format-[^ ]+/,""),t.dom.addClass(e,"post-format-0"==i?"post-format-standard":i),h(document).trigger("editor-classchange"))}),h("#page_template").on("change.set-editor-class",function(){var t,e,i=h(this).val()||"";(i=i.substr(i.lastIndexOf("/")+1,i.length).replace(/\.php$/,"").replace(/\./g,"-"))&&(t=tinymce.get("content"))&&((e=t.getBody()).className=e.className.replace(/\bpage-template-[^ ]+/,""),t.dom.addClass(e,"page-template-"+i),h(document).trigger("editor-classchange"))})),u.on("keydown.wp-autosave",function(t){83!==t.which||t.shiftKey||t.altKey||_&&(!t.metaKey||t.ctrlKey)||!_&&!t.ctrlKey||(wp.autosave&&wp.autosave.server.triggerSave(),t.preventDefault())}),"auto-draft"===h("#original_post_status").val()&&window.history.replaceState&&h("#publish").on("click",function(){d=(d=window.location.href)+(-1!==d.indexOf("?")?"&":"?")+"wp-post-new-reload=true",window.history.replaceState(null,null,d)}),y.on("success",function(t){var e=h(t.trigger),i=h(".success",e.closest(".copy-to-clipboard-container"));t.clearSelection(),e.trigger("focus"),clearTimeout(s),i.removeClass("hidden"),s=setTimeout(function(){i.addClass("hidden")},3e3),wp.a11y.speak(x("The file URL has been copied to your clipboard"))})}),function(t,o){t(function(){var i,e=t("#content"),a=t("#wp-word-count").find(".word-count"),n=0;function s(){var t=!i||i.isHidden()?e.val():i.getContent({format:"raw"}),t=o.count(t);t!==n&&a.text(t),n=t}t(document).on("tinymce-editor-init",function(t,e){"content"===e.id&&(i=e).on("nodechange keyup",_.debounce(s,1e3))}),e.on("input keyup",_.debounce(s,1e3)),s()})}(jQuery,new wp.utils.WordCounter); \ No newline at end of file diff --git a/wp-admin/js/widgets/text-widgets.js b/wp-admin/js/widgets/text-widgets.js index ee4dbb9529..48d72475ee 100644 --- a/wp-admin/js/widgets/text-widgets.js +++ b/wp-admin/js/widgets/text-widgets.js @@ -291,7 +291,7 @@ wp.textWidgets = ( function( $ ) { onInit = function() { // When a widget is moved in the DOM the dynamically-created TinyMCE iframe will be destroyed and has to be re-built. - $( editor.getWin() ).on( 'unload', function() { + $( editor.getWin() ).on( 'pagehide', function() { _.defer( buildEditor ); }); diff --git a/wp-admin/js/widgets/text-widgets.min.js b/wp-admin/js/widgets/text-widgets.min.js index fbb3ff585f..6877ac8e79 100644 --- a/wp-admin/js/widgets/text-widgets.min.js +++ b/wp-admin/js/widgets/text-widgets.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -wp.textWidgets=function(r){"use strict";var u={dismissedPointers:[],idBases:["text"]};return u.TextWidgetControl=Backbone.View.extend({events:{},initialize:function(t){var n=this;if(!t.el)throw new Error("Missing options.el");if(!t.syncContainer)throw new Error("Missing options.syncContainer");Backbone.View.prototype.initialize.call(n,t),n.syncContainer=t.syncContainer,n.$el.addClass("text-widget-fields"),n.$el.html(wp.template("widget-text-control-fields")),n.customHtmlWidgetPointer=n.$el.find(".wp-pointer.custom-html-widget-pointer"),n.customHtmlWidgetPointer.length&&(n.customHtmlWidgetPointer.find(".close").on("click",function(t){t.preventDefault(),n.customHtmlWidgetPointer.hide(),r("#"+n.fields.text.attr("id")+"-html").trigger("focus"),n.dismissPointers(["text_widget_custom_html"])}),n.customHtmlWidgetPointer.find(".add-widget").on("click",function(t){t.preventDefault(),n.customHtmlWidgetPointer.hide(),n.openAvailableWidgetsPanel()})),n.pasteHtmlPointer=n.$el.find(".wp-pointer.paste-html-pointer"),n.pasteHtmlPointer.length&&n.pasteHtmlPointer.find(".close").on("click",function(t){t.preventDefault(),n.pasteHtmlPointer.hide(),n.editor.focus(),n.dismissPointers(["text_widget_custom_html","text_widget_paste_html"])}),n.fields={title:n.$el.find(".title"),text:n.$el.find(".text")},_.each(n.fields,function(e,i){e.on("input change",function(){var t=n.syncContainer.find(".sync-input."+i);t.val()!==e.val()&&(t.val(e.val()),t.trigger("change"))}),e.val(n.syncContainer.find(".sync-input."+i).val())})},dismissPointers:function(t){_.each(t,function(t){wp.ajax.post("dismiss-wp-pointer",{pointer:t}),u.dismissedPointers.push(t)})},openAvailableWidgetsPanel:function(){var e;wp.customize.section.each(function(t){t.extended(wp.customize.Widgets.SidebarSection)&&t.expanded()&&(e=wp.customize.control("sidebars_widgets["+t.params.sidebarId+"]"))}),e&&setTimeout(function(){wp.customize.Widgets.availableWidgetsPanel.open(e),wp.customize.Widgets.availableWidgetsPanel.$search.val("HTML").trigger("keyup")})},updateFields:function(){var t,e=this;e.fields.title.is(document.activeElement)||(t=e.syncContainer.find(".sync-input.title"),e.fields.title.val(t.val())),t=e.syncContainer.find(".sync-input.text"),e.fields.text.is(":visible")?e.fields.text.is(document.activeElement)||e.fields.text.val(t.val()):e.editor&&!e.editorFocused&&t.val()!==e.fields.text.val()&&e.editor.setContent(wp.oldEditor.autop(t.val()))},initializeEditor:function(){var d,t,o,e,s=this,a=1e3,l=!1,c=!1;t=s.fields.text,d=t.attr("id"),e=t.val(),o=function(){s.editor.isDirty()&&(wp.customize&&wp.customize.state&&(wp.customize.state("processing").set(wp.customize.state("processing").get()+1),_.delay(function(){wp.customize.state("processing").set(wp.customize.state("processing").get()-1)},300)),s.editor.isHidden()||s.editor.save()),c&&e!==t.val()&&(t.trigger("change"),c=!1,e=t.val())},s.syncContainer.closest(".widget").find("[name=savewidget]:first").on("click",function(){o()}),function t(){var e,i,n;if(document.getElementById(d))if(void 0===window.tinymce)wp.oldEditor.initialize(d,{quicktags:!0,mediaButtons:!0});else{if(tinymce.get(d)&&(l=tinymce.get(d).isHidden(),wp.oldEditor.remove(d)),r(document).one("wp-before-tinymce-init.text-widget-init",function(t,e){e.plugins&&!/\bwpview\b/.test(e.plugins)&&(e.plugins+=",wpview")}),wp.oldEditor.initialize(d,{tinymce:{wpautop:!0},quicktags:!0,mediaButtons:!0}),n=function(t){t.show(),t.find(".close").trigger("focus"),wp.a11y.speak(t.find("h3, p").map(function(){return r(this).text()}).get().join("\n\n"))},!(e=window.tinymce.get(d)))throw new Error("Failed to initialize editor");i=function(){r(e.getWin()).on("unload",function(){_.defer(t)}),l&&switchEditors.go(d,"html"),r("#"+d+"-html").on("click",function(){s.pasteHtmlPointer.hide(),-1===u.dismissedPointers.indexOf("text_widget_custom_html")&&n(s.customHtmlWidgetPointer)}),r("#"+d+"-tmce").on("click",function(){s.customHtmlWidgetPointer.hide()}),e.on("pastepreprocess",function(t){t=t.content,-1===u.dismissedPointers.indexOf("text_widget_paste_html")&&t&&/<\w+.*?>/.test(t)&&_.delay(function(){n(s.pasteHtmlPointer)},250)})},e.initialized?i():e.on("init",i),s.editorFocused=!1,e.on("focus",function(){s.editorFocused=!0}),e.on("paste",function(){e.setDirty(!0),o()}),e.on("NodeChange",function(){c=!0}),e.on("NodeChange",_.debounce(o,a)),e.on("blur hide",function(){s.editorFocused=!1,o()}),s.editor=e}}()}}),u.widgetControls={},u.handleWidgetAdded=function(t,e){var i,n,d,o=e.find("> .widget-inside > .form, > .widget-inside > form"),s=o.find("> .id_base").val();-1===u.idBases.indexOf(s)||(s=o.find(".widget-id").val(),u.widgetControls[s])||o.find(".visual").val()&&(o=r("
"),(d=e.find(".widget-content:first")).before(o),i=new u.TextWidgetControl({el:o,syncContainer:d}),u.widgetControls[s]=i,(n=function(){e.hasClass("open")?i.initializeEditor():setTimeout(n,50)})())},u.setupAccessibleMode=function(){var t,e=r(".editwidget > form");0!==e.length&&(t=e.find(".id_base").val(),-1!==u.idBases.indexOf(t))&&e.find(".visual").val()&&(t=r("
"),(e=e.find("> .widget-inside")).before(t),new u.TextWidgetControl({el:t,syncContainer:e}).initializeEditor())},u.handleWidgetUpdated=function(t,e){var e=e.find("> .widget-inside > .form, > .widget-inside > form"),i=e.find("> .id_base").val();-1!==u.idBases.indexOf(i)&&(i=e.find("> .widget-id").val(),e=u.widgetControls[i])&&e.updateFields()},u.init=function(){var t=r(document);t.on("widget-added",u.handleWidgetAdded),t.on("widget-synced widget-updated",u.handleWidgetUpdated),r(function(){"widgets"===window.pagenow&&(r(".widgets-holder-wrap:not(#available-widgets)").find("div.widget").one("click.toggle-widget-expanded",function(){var t=r(this);u.handleWidgetAdded(new jQuery.Event("widget-added"),t)}),u.setupAccessibleMode())})},u}(jQuery); \ No newline at end of file +wp.textWidgets=function(r){"use strict";var u={dismissedPointers:[],idBases:["text"]};return u.TextWidgetControl=Backbone.View.extend({events:{},initialize:function(e){var n=this;if(!e.el)throw new Error("Missing options.el");if(!e.syncContainer)throw new Error("Missing options.syncContainer");Backbone.View.prototype.initialize.call(n,e),n.syncContainer=e.syncContainer,n.$el.addClass("text-widget-fields"),n.$el.html(wp.template("widget-text-control-fields")),n.customHtmlWidgetPointer=n.$el.find(".wp-pointer.custom-html-widget-pointer"),n.customHtmlWidgetPointer.length&&(n.customHtmlWidgetPointer.find(".close").on("click",function(e){e.preventDefault(),n.customHtmlWidgetPointer.hide(),r("#"+n.fields.text.attr("id")+"-html").trigger("focus"),n.dismissPointers(["text_widget_custom_html"])}),n.customHtmlWidgetPointer.find(".add-widget").on("click",function(e){e.preventDefault(),n.customHtmlWidgetPointer.hide(),n.openAvailableWidgetsPanel()})),n.pasteHtmlPointer=n.$el.find(".wp-pointer.paste-html-pointer"),n.pasteHtmlPointer.length&&n.pasteHtmlPointer.find(".close").on("click",function(e){e.preventDefault(),n.pasteHtmlPointer.hide(),n.editor.focus(),n.dismissPointers(["text_widget_custom_html","text_widget_paste_html"])}),n.fields={title:n.$el.find(".title"),text:n.$el.find(".text")},_.each(n.fields,function(t,i){t.on("input change",function(){var e=n.syncContainer.find(".sync-input."+i);e.val()!==t.val()&&(e.val(t.val()),e.trigger("change"))}),t.val(n.syncContainer.find(".sync-input."+i).val())})},dismissPointers:function(e){_.each(e,function(e){wp.ajax.post("dismiss-wp-pointer",{pointer:e}),u.dismissedPointers.push(e)})},openAvailableWidgetsPanel:function(){var t;wp.customize.section.each(function(e){e.extended(wp.customize.Widgets.SidebarSection)&&e.expanded()&&(t=wp.customize.control("sidebars_widgets["+e.params.sidebarId+"]"))}),t&&setTimeout(function(){wp.customize.Widgets.availableWidgetsPanel.open(t),wp.customize.Widgets.availableWidgetsPanel.$search.val("HTML").trigger("keyup")})},updateFields:function(){var e,t=this;t.fields.title.is(document.activeElement)||(e=t.syncContainer.find(".sync-input.title"),t.fields.title.val(e.val())),e=t.syncContainer.find(".sync-input.text"),t.fields.text.is(":visible")?t.fields.text.is(document.activeElement)||t.fields.text.val(e.val()):t.editor&&!t.editorFocused&&e.val()!==t.fields.text.val()&&t.editor.setContent(wp.oldEditor.autop(e.val()))},initializeEditor:function(){var d,e,o,t,s=this,a=1e3,l=!1,c=!1;e=s.fields.text,d=e.attr("id"),t=e.val(),o=function(){s.editor.isDirty()&&(wp.customize&&wp.customize.state&&(wp.customize.state("processing").set(wp.customize.state("processing").get()+1),_.delay(function(){wp.customize.state("processing").set(wp.customize.state("processing").get()-1)},300)),s.editor.isHidden()||s.editor.save()),c&&t!==e.val()&&(e.trigger("change"),c=!1,t=e.val())},s.syncContainer.closest(".widget").find("[name=savewidget]:first").on("click",function(){o()}),function e(){var t,i,n;if(document.getElementById(d))if(void 0===window.tinymce)wp.oldEditor.initialize(d,{quicktags:!0,mediaButtons:!0});else{if(tinymce.get(d)&&(l=tinymce.get(d).isHidden(),wp.oldEditor.remove(d)),r(document).one("wp-before-tinymce-init.text-widget-init",function(e,t){t.plugins&&!/\bwpview\b/.test(t.plugins)&&(t.plugins+=",wpview")}),wp.oldEditor.initialize(d,{tinymce:{wpautop:!0},quicktags:!0,mediaButtons:!0}),n=function(e){e.show(),e.find(".close").trigger("focus"),wp.a11y.speak(e.find("h3, p").map(function(){return r(this).text()}).get().join("\n\n"))},!(t=window.tinymce.get(d)))throw new Error("Failed to initialize editor");i=function(){r(t.getWin()).on("pagehide",function(){_.defer(e)}),l&&switchEditors.go(d,"html"),r("#"+d+"-html").on("click",function(){s.pasteHtmlPointer.hide(),-1===u.dismissedPointers.indexOf("text_widget_custom_html")&&n(s.customHtmlWidgetPointer)}),r("#"+d+"-tmce").on("click",function(){s.customHtmlWidgetPointer.hide()}),t.on("pastepreprocess",function(e){e=e.content,-1===u.dismissedPointers.indexOf("text_widget_paste_html")&&e&&/<\w+.*?>/.test(e)&&_.delay(function(){n(s.pasteHtmlPointer)},250)})},t.initialized?i():t.on("init",i),s.editorFocused=!1,t.on("focus",function(){s.editorFocused=!0}),t.on("paste",function(){t.setDirty(!0),o()}),t.on("NodeChange",function(){c=!0}),t.on("NodeChange",_.debounce(o,a)),t.on("blur hide",function(){s.editorFocused=!1,o()}),s.editor=t}}()}}),u.widgetControls={},u.handleWidgetAdded=function(e,t){var i,n,d,o=t.find("> .widget-inside > .form, > .widget-inside > form"),s=o.find("> .id_base").val();-1===u.idBases.indexOf(s)||(s=o.find(".widget-id").val(),u.widgetControls[s])||o.find(".visual").val()&&(o=r("
"),(d=t.find(".widget-content:first")).before(o),i=new u.TextWidgetControl({el:o,syncContainer:d}),u.widgetControls[s]=i,(n=function(){t.hasClass("open")?i.initializeEditor():setTimeout(n,50)})())},u.setupAccessibleMode=function(){var e,t=r(".editwidget > form");0!==t.length&&(e=t.find(".id_base").val(),-1!==u.idBases.indexOf(e))&&t.find(".visual").val()&&(e=r("
"),(t=t.find("> .widget-inside")).before(e),new u.TextWidgetControl({el:e,syncContainer:t}).initializeEditor())},u.handleWidgetUpdated=function(e,t){var t=t.find("> .widget-inside > .form, > .widget-inside > form"),i=t.find("> .id_base").val();-1!==u.idBases.indexOf(i)&&(i=t.find("> .widget-id").val(),t=u.widgetControls[i])&&t.updateFields()},u.init=function(){var e=r(document);e.on("widget-added",u.handleWidgetAdded),e.on("widget-synced widget-updated",u.handleWidgetUpdated),r(function(){"widgets"===window.pagenow&&(r(".widgets-holder-wrap:not(#available-widgets)").find("div.widget").one("click.toggle-widget-expanded",function(){var e=r(this);u.handleWidgetAdded(new jQuery.Event("widget-added"),e)}),u.setupAccessibleMode())})},u}(jQuery); \ No newline at end of file diff --git a/wp-includes/functions.php b/wp-includes/functions.php index bb799802ad..c467961c98 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7585,7 +7585,7 @@ function wp_delete_file_from_directory( $file, $directory ) { } /** - * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload. + * Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page. * * This prevents reusing the same tab for a preview when the user has navigated away. * @@ -7614,7 +7614,7 @@ function wp_post_preview_js() { } if ( window.addEventListener ) { - window.addEventListener( 'unload', function() { window.name = ''; }, false ); + window.addEventListener( 'pagehide', function() { window.name = ''; } ); } }()); diff --git a/wp-includes/js/heartbeat.js b/wp-includes/js/heartbeat.js index c6950ef7df..f3a92b0a1f 100644 --- a/wp-includes/js/heartbeat.js +++ b/wp-includes/js/heartbeat.js @@ -223,9 +223,9 @@ settings.checkFocusTimer = window.setInterval( checkFocus, 10000 ); } - $(window).on( 'unload.wp-heartbeat', function() { + $(window).on( 'pagehide.wp-heartbeat', function() { // Don't connect anymore. - settings.suspend = true; + suspend(); // Abort the last request if not completed. if ( settings.xhr && settings.xhr.readyState !== 4 ) { @@ -233,6 +233,25 @@ } }); + $(window).on( + 'pageshow.wp-heartbeat', + /** + * Handles pageshow event, specifically when page navigation is restored from back/forward cache. + * + * @param {jQuery.Event} event + * @param {PageTransitionEvent} event.originalEvent + */ + function ( event ) { + if ( event.originalEvent.persisted ) { + /* + * When page navigation is stored via bfcache (Back/Forward Cache), consider this the same as + * if the user had just switched to the tab since the behavior is similar. + */ + focused(); + } + } + ); + // Check for user activity every 30 seconds. window.setInterval( checkUserActivity, 30000 ); @@ -541,7 +560,7 @@ settings.userActivity = time(); // Resume if suspended. - settings.suspend = false; + resume(); if ( ! settings.hasFocus ) { settings.hasFocus = true; @@ -549,6 +568,20 @@ } } + /** + * Suspends connecting. + */ + function suspend() { + settings.suspend = true; + } + + /** + * Resumes connecting. + */ + function resume() { + settings.suspend = false; + } + /** * Runs when the user becomes active after a period of inactivity. * @@ -593,7 +626,7 @@ // Suspend after 10 minutes of inactivity when suspending is enabled. // Always suspend after 60 minutes of inactivity. This will release the post lock, etc. if ( ( settings.suspendEnabled && lastActive > 600000 ) || lastActive > 3600000 ) { - settings.suspend = true; + suspend(); } if ( ! settings.userActivityEvents ) { diff --git a/wp-includes/js/heartbeat.min.js b/wp-includes/js/heartbeat.min.js index aa53d3683a..cdc130d1b4 100644 --- a/wp-includes/js/heartbeat.min.js +++ b/wp-includes/js/heartbeat.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(f,w){w.wp=w.wp||{},w.wp.heartbeat=new function(){var e,t,n,a,i=f(document),r={suspend:!1,suspendEnabled:!0,screenId:"",url:"",lastTick:0,queue:{},mainInterval:60,tempInterval:0,originalInterval:0,minimalInterval:0,countdown:0,connecting:!1,connectionError:!1,errorcount:0,hasConnected:!1,hasFocus:!0,userActivity:0,userActivityEvents:!1,checkFocusTimer:0,beatTimer:0};function o(){return(new Date).getTime()}function c(e){var t,n=e.src;if(!n||!/^https?:\/\//.test(n)||(t=w.location.origin||w.location.protocol+"//"+w.location.host,0===n.indexOf(t)))try{if(e.contentWindow.document)return 1}catch(e){}}function s(){r.hasFocus&&!document.hasFocus()?d():!r.hasFocus&&document.hasFocus()&&v()}function u(e,t){var n;if(e){switch(e){case"abort":break;case"timeout":n=!0;break;case"error":if(503===t&&r.hasConnected){n=!0;break}case"parsererror":case"empty":case"unknown":r.errorcount++,2'+n+"

",processed:!0}),i=i.slice(t.index+t.content.length);i&&d.push({content:i})}})}),(e=_.pluck(d,"content").join("")).replace(/

\s*

")},createInstance:function(e,t,n,i){var s,e=this.get(e);return-1!==t.indexOf("[")&&-1!==t.indexOf("]")&&(t=t.replace(/\[[^\]]+\]/g,function(e){return e.replace(/[\r\n]/g,"")})),!i&&(s=this.getInstance(t))?s:(i=encodeURIComponent(t),n=_.extend(n||{},{text:t,encodedText:i}),o[i]=new e(n))},getInstance:function(e){return"string"==typeof e?o[encodeURIComponent(e)]:o[v(e).attr("data-wpview-text")]},getText:function(e){return decodeURIComponent(v(e).attr("data-wpview-text")||"")},render:function(t){_.each(o,function(e){e.render(null,t)})},update:function(e,t,n,i){var s=this.getInstance(n);s&&s.update(e,t,n,i)},edit:function(n,i){var s=this.getInstance(i);s&&s.edit&&s.edit(s.text,function(e,t){s.update(e,n,i,t)})},remove:function(e,t){var n=this.getInstance(t);n&&n.remove(e,t)}},w.mce.View=function(e){_.extend(this,e),this.initialize()},w.mce.View.extend=Backbone.View.extend,_.extend(w.mce.View.prototype,{content:null,loader:!0,initialize:function(){},getContent:function(){return this.content},render:function(e,t){null!=e&&(this.content=e),e=this.getContent(),(this.loader||e)&&(t&&this.unbind(),this.replaceMarkers(),e?this.setContent(e,function(e,t){v(t).data("rendered",!0),this.bindNode.call(this,e,t)},!!t&&null):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(e,t){this.unbindNode.call(this,e,t)},!0)},getEditors:function(t){_.each(tinymce.editors,function(e){e.plugins.wpview&&t.call(this,e)},this)},getNodes:function(n,i){this.getEditors(function(e){var t=this;v(e.getBody()).find('[data-wpview-text="'+t.encodedText+'"]').filter(function(){var e;return null==i||(e=!0===v(this).data("rendered"),i?e:!e)}).each(function(){n.call(t,e,this,this)})})},getMarkers:function(n){this.getEditors(function(e){var t=this;v(e.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){n.call(t,e,this)})})},replaceMarkers:function(){this.getMarkers(function(e,t){var n,i=t===e.selection.getNode();this.loader||v(t).text()===tinymce.DOM.decode(this.text)?(n=e.$('

'),e.undoManager.ignore(function(){e.$(t).replaceWith(n)}),i&&setTimeout(function(){e.undoManager.ignore(function(){e.selection.select(n[0]),e.selection.collapse()})})):e.dom.setAttrib(t,"data-wpview-marker",null)})},removeMarkers:function(){this.getMarkers(function(e,t){e.dom.setAttrib(t,"data-wpview-marker",null)})},setContent:function(n,i,e){_.isObject(n)&&(n.sandbox||n.head||-1!==n.body.indexOf("'),e.undoManager.transact(function(){t.innerHTML="",t.appendChild(_.isString(n)?e.dom.createFragment(n):n),e.dom.add(t,"span",{class:"wpview-end"})}),i&&i.call(this,e,t)},e)},setIframes:function(p,f,m,e){var t,g=this;-1!==f.indexOf("[")&&-1!==f.indexOf("]")&&(t=new RegExp("\\[\\/?(?:"+n.mceViewL10n.shortcodes.join("|")+")[^\\]]*?\\]","g"),f=f.replace(t,function(e){return e.replace(//g,">")})),this.getNodes(function(t,e){var n,i,s,o,a,r=t.dom,d="",c=t.getBody().className||"",l=t.getDoc().getElementsByTagName("head")[0];if(tinymce.each(r.$('link[rel="stylesheet"]',l),function(e){e.href&&-1===e.href.indexOf("skins/lightgray/content.min.css")&&-1===e.href.indexOf("skins/wordpress/wp-content.css")&&(d+=r.getOuterHTML(e))}),g.iframeHeight&&r.add(e,"span",{"data-mce-bogus":1,style:{display:"block",width:"100%",height:g.iframeHeight}},"\u200b"),t.undoManager.transact(function(){e.innerHTML="",n=r.add(e,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no",class:"wpview-sandbox",style:{width:"100%",display:"block"},height:g.iframeHeight}),r.add(e,"span",{class:"mce-shim"}),r.add(e,"span",{class:"wpview-end"})}),n.contentWindow){if(l=n.contentWindow,(i=l.document).open(),i.write(''+p+d+''+f+""),i.close(),g.iframeHeight&&(a=!0,setTimeout(function(){a=!1,u()},3e3)),v(l).on("load",u).on("unload",function(){t.isHidden()||(v(e).data("rendered",null),setTimeout(function(){w.mce.views.render()}))}),s=l.MutationObserver||l.WebKitMutationObserver||l.MozMutationObserver)i.body?h():i.addEventListener("DOMContentLoaded",h,!1);else for(o=1;o<6;o++)setTimeout(u,700*o);m&&m.call(g,t,e)}function u(){var e;a||n.contentWindow&&(e=v(n),g.iframeHeight=v(i.body).height(),e.height()!==g.iframeHeight)&&(e.height(g.iframeHeight),t.nodeChanged())}function h(){new s(_.debounce(u,100)).observe(i.body,{attributes:!0,childList:!0,subtree:!0})}},e)},setLoader:function(e){this.setContent('
')},setError:function(e,t){this.setContent('

'+e+"

")},match:function(e){e=t.next(this.type,e);if(e)return{index:e.index,content:e.content,options:{shortcode:e.shortcode}}},update:function(n,i,s,o){_.find(l,function(e,t){e=e.prototype.match(n);if(e)return v(s).data("rendered",!1),i.dom.setAttrib(s,"data-wpview-text",encodeURIComponent(n)),w.mce.views.createInstance(t,n,e.options,o).render(),i.selection.select(s),i.nodeChanged(),i.focus(),!0})},remove:function(e,t){this.unbindNode.call(this,e,t),e.dom.remove(t),e.focus()}})}(window,window.wp,window.wp.shortcode,window.jQuery),function(n,e,s,i){var t,o,a,r,d,c;function l(e){var t={};return n.tinymce?!e||-1===e.indexOf("<")&&-1===e.indexOf(">")?e:(r=r||new n.tinymce.html.Schema(t),d=d||new n.tinymce.html.DomParser(t,r),(c=c||new n.tinymce.html.Serializer(t,r)).serialize(d.parse(e,{forced_root_block:!1}))):e.replace(/<[^>]+>/g,"")}o={state:[],edit:function(e,t){var n=this.type,i=s[n].edit(e);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(e){i.state(e).on("update",function(e){t(s[n].shortcode(e).string(),"gallery"===n)})}),i.on("close",function(){i.detach()}),i.open()}},t=_.extend({},o,{state:["gallery-edit"],template:s.template("editor-gallery"),initialize:function(){var e=s.gallery.attachments(this.shortcode,s.view.settings.post.id),t=this.shortcode.attrs.named,n=this;e.more().done(function(){e=e.toJSON(),_.each(e,function(e){e.sizes&&(t.size&&e.sizes[t.size]?e.thumbnail=e.sizes[t.size]:e.sizes.thumbnail?e.thumbnail=e.sizes.thumbnail:e.sizes.full&&(e.thumbnail=e.sizes.full))}),n.render(n.template({verifyHTML:l,attachments:e,columns:t.columns?parseInt(t.columns,10):s.galleryDefaults.columns}))}).fail(function(e,t){n.setError(t)})}}),o=_.extend({},o,{action:"parse-media-shortcode",initialize:function(){var t=this,e=null;this.url&&(this.loader=!1,this.shortcode=s.embed.shortcode({url:this.text})),t.editor&&(e=t.editor.getBody().clientWidth),wp.ajax.post(this.action,{post_ID:s.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string(),maxwidth:e}).done(function(e){t.render(e)}).fail(function(e){t.url?(t.ignore=!0,t.removeMarkers()):t.setError(e.message||e.statusText,"admin-media")}),this.getEditors(function(e){e.on("wpview-selected",function(){t.pausePlayers()})})},pausePlayers:function(){this.getNodes(function(e,t,n){n=i("iframe.wpview-sandbox",n).get(0);(n=n&&n.contentWindow)&&n.mejs&&_.each(n.mejs.players,function(e){try{e.pause()}catch(e){}})})}}),a=_.extend({},o,{action:"parse-embed",edit:function(e,t){var n=s.embed.edit(e,this.url),i=this;this.pausePlayers(),n.state("embed").props.on("change:url",function(e,t){t&&e.get("url")&&(n.state("embed").metadata=e.toJSON())}),n.state("embed").on("select",function(){var e=n.state("embed").metadata;i.url?t(e.url):t(s.embed.shortcode(e).string())}),n.on("close",function(){n.detach()}),n.open()}}),e.register("gallery",_.extend({},t)),e.register("audio",_.extend({},o,{state:["audio-details"]})),e.register("video",_.extend({},o,{state:["video-details"]})),e.register("playlist",_.extend({},o,{state:["playlist-edit","video-playlist-edit"]})),e.register("embed",_.extend({},a)),e.register("embedURL",_.extend({},a,{match:function(e){e=/(^|

(?:]+>\s*<\/span>)?)(https?:\/\/[^\s"]+?)((?:]+>\s*<\/span>)?<\/p>\s*|$)/gi.exec(e);if(e)return{index:e.index+e[1].length,content:e[2],options:{url:!0}}}}))}(window,window.wp.mce.views,window.wp.media,window.jQuery); \ No newline at end of file +!function(n,a,t,w){"use strict";var l={},o={};a.mce=a.mce||{},a.mce.views={register:function(e,t){l[e]=a.mce.View.extend(_.extend(t,{type:e}))},unregister:function(e){delete l[e]},get:function(e){return l[e]},unbind:function(){_.each(o,function(e){e.unbind()})},setMarkers:function(e,a){var r,t,d=[{content:e}],c=this;return _.each(l,function(s,o){t=d.slice(),d=[],_.each(t,function(e){var t,n,i=e.content;if(e.processed)d.push(e);else{for(;i&&(t=s.prototype.match(i));)t.index&&d.push({content:i.substring(0,t.index)}),t.options.editor=a,n=(r=c.createInstance(o,t.content,t.options)).loader?".":r.text,d.push({content:r.ignore?n:'

'+n+"

",processed:!0}),i=i.slice(t.index+t.content.length);i&&d.push({content:i})}})}),(e=_.pluck(d,"content").join("")).replace(/

\s*

")},createInstance:function(e,t,n,i){var s,e=this.get(e);return-1!==t.indexOf("[")&&-1!==t.indexOf("]")&&(t=t.replace(/\[[^\]]+\]/g,function(e){return e.replace(/[\r\n]/g,"")})),!i&&(s=this.getInstance(t))?s:(i=encodeURIComponent(t),n=_.extend(n||{},{text:t,encodedText:i}),o[i]=new e(n))},getInstance:function(e){return"string"==typeof e?o[encodeURIComponent(e)]:o[w(e).attr("data-wpview-text")]},getText:function(e){return decodeURIComponent(w(e).attr("data-wpview-text")||"")},render:function(t){_.each(o,function(e){e.render(null,t)})},update:function(e,t,n,i){var s=this.getInstance(n);s&&s.update(e,t,n,i)},edit:function(n,i){var s=this.getInstance(i);s&&s.edit&&s.edit(s.text,function(e,t){s.update(e,n,i,t)})},remove:function(e,t){var n=this.getInstance(t);n&&n.remove(e,t)}},a.mce.View=function(e){_.extend(this,e),this.initialize()},a.mce.View.extend=Backbone.View.extend,_.extend(a.mce.View.prototype,{content:null,loader:!0,initialize:function(){},getContent:function(){return this.content},render:function(e,t){null!=e&&(this.content=e),e=this.getContent(),(this.loader||e)&&(t&&this.unbind(),this.replaceMarkers(),e?this.setContent(e,function(e,t){w(t).data("rendered",!0),this.bindNode.call(this,e,t)},!!t&&null):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(e,t){this.unbindNode.call(this,e,t)},!0)},getEditors:function(t){_.each(tinymce.editors,function(e){e.plugins.wpview&&t.call(this,e)},this)},getNodes:function(n,i){this.getEditors(function(e){var t=this;w(e.getBody()).find('[data-wpview-text="'+t.encodedText+'"]').filter(function(){var e;return null==i||(e=!0===w(this).data("rendered"),i?e:!e)}).each(function(){n.call(t,e,this,this)})})},getMarkers:function(n){this.getEditors(function(e){var t=this;w(e.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){n.call(t,e,this)})})},replaceMarkers:function(){this.getMarkers(function(e,t){var n,i=t===e.selection.getNode();this.loader||w(t).text()===tinymce.DOM.decode(this.text)?(n=e.$('

'),e.undoManager.ignore(function(){e.$(t).replaceWith(n)}),i&&setTimeout(function(){e.undoManager.ignore(function(){e.selection.select(n[0]),e.selection.collapse()})})):e.dom.setAttrib(t,"data-wpview-marker",null)})},removeMarkers:function(){this.getMarkers(function(e,t){e.dom.setAttrib(t,"data-wpview-marker",null)})},setContent:function(n,i,e){_.isObject(n)&&(n.sandbox||n.head||-1!==n.body.indexOf("'),e.undoManager.transact(function(){t.innerHTML="",t.appendChild(_.isString(n)?e.dom.createFragment(n):n),e.dom.add(t,"span",{class:"wpview-end"})}),i&&i.call(this,e,t)},e)},setIframes:function(p,f,m,e){var t,g=this;-1!==f.indexOf("[")&&-1!==f.indexOf("]")&&(t=new RegExp("\\[\\/?(?:"+n.mceViewL10n.shortcodes.join("|")+")[^\\]]*?\\]","g"),f=f.replace(t,function(e){return e.replace(//g,">")})),this.getNodes(function(t,e){var n,i,s,o,a,r=t.dom,d="",c=t.getBody().className||"",l=t.getDoc().getElementsByTagName("head")[0];if(tinymce.each(r.$('link[rel="stylesheet"]',l),function(e){e.href&&-1===e.href.indexOf("skins/lightgray/content.min.css")&&-1===e.href.indexOf("skins/wordpress/wp-content.css")&&(d+=r.getOuterHTML(e))}),g.iframeHeight&&r.add(e,"span",{"data-mce-bogus":1,style:{display:"block",width:"100%",height:g.iframeHeight}},"\u200b"),t.undoManager.transact(function(){e.innerHTML="",n=r.add(e,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no",class:"wpview-sandbox",style:{width:"100%",display:"block"},height:g.iframeHeight}),r.add(e,"span",{class:"mce-shim"}),r.add(e,"span",{class:"wpview-end"})}),n.contentWindow){if(l=n.contentWindow,(i=l.document).open(),i.write(''+p+d+''+f+""),i.close(),g.iframeHeight&&(a=!0,setTimeout(function(){a=!1,u()},3e3)),w(l).on("load",u),s=l.MutationObserver||l.WebKitMutationObserver||l.MozMutationObserver)i.body?h():i.addEventListener("DOMContentLoaded",h,!1);else for(o=1;o<6;o++)setTimeout(u,700*o);m&&m.call(g,t,e)}function u(){var e;a||n.contentWindow&&(e=w(n),g.iframeHeight=w(i.body).height(),e.height()!==g.iframeHeight)&&(e.height(g.iframeHeight),t.nodeChanged())}function h(){new s(_.debounce(u,100)).observe(i.body,{attributes:!0,childList:!0,subtree:!0})}},e)},setLoader:function(e){this.setContent('
')},setError:function(e,t){this.setContent('

'+e+"

")},match:function(e){e=t.next(this.type,e);if(e)return{index:e.index,content:e.content,options:{shortcode:e.shortcode}}},update:function(n,i,s,o){_.find(l,function(e,t){e=e.prototype.match(n);if(e)return w(s).data("rendered",!1),i.dom.setAttrib(s,"data-wpview-text",encodeURIComponent(n)),a.mce.views.createInstance(t,n,e.options,o).render(),i.selection.select(s),i.nodeChanged(),i.focus(),!0})},remove:function(e,t){this.unbindNode.call(this,e,t),e.dom.remove(t),e.focus()}})}(window,window.wp,window.wp.shortcode,window.jQuery),function(n,e,s,i){var t,o,a,r,d,c;function l(e){var t={};return n.tinymce?!e||-1===e.indexOf("<")&&-1===e.indexOf(">")?e:(r=r||new n.tinymce.html.Schema(t),d=d||new n.tinymce.html.DomParser(t,r),(c=c||new n.tinymce.html.Serializer(t,r)).serialize(d.parse(e,{forced_root_block:!1}))):e.replace(/<[^>]+>/g,"")}o={state:[],edit:function(e,t){var n=this.type,i=s[n].edit(e);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(e){i.state(e).on("update",function(e){t(s[n].shortcode(e).string(),"gallery"===n)})}),i.on("close",function(){i.detach()}),i.open()}},t=_.extend({},o,{state:["gallery-edit"],template:s.template("editor-gallery"),initialize:function(){var e=s.gallery.attachments(this.shortcode,s.view.settings.post.id),t=this.shortcode.attrs.named,n=this;e.more().done(function(){e=e.toJSON(),_.each(e,function(e){e.sizes&&(t.size&&e.sizes[t.size]?e.thumbnail=e.sizes[t.size]:e.sizes.thumbnail?e.thumbnail=e.sizes.thumbnail:e.sizes.full&&(e.thumbnail=e.sizes.full))}),n.render(n.template({verifyHTML:l,attachments:e,columns:t.columns?parseInt(t.columns,10):s.galleryDefaults.columns}))}).fail(function(e,t){n.setError(t)})}}),o=_.extend({},o,{action:"parse-media-shortcode",initialize:function(){var t=this,e=null;this.url&&(this.loader=!1,this.shortcode=s.embed.shortcode({url:this.text})),t.editor&&(e=t.editor.getBody().clientWidth),wp.ajax.post(this.action,{post_ID:s.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string(),maxwidth:e}).done(function(e){t.render(e)}).fail(function(e){t.url?(t.ignore=!0,t.removeMarkers()):t.setError(e.message||e.statusText,"admin-media")}),this.getEditors(function(e){e.on("wpview-selected",function(){t.pausePlayers()})})},pausePlayers:function(){this.getNodes(function(e,t,n){n=i("iframe.wpview-sandbox",n).get(0);(n=n&&n.contentWindow)&&n.mejs&&_.each(n.mejs.players,function(e){try{e.pause()}catch(e){}})})}}),a=_.extend({},o,{action:"parse-embed",edit:function(e,t){var n=s.embed.edit(e,this.url),i=this;this.pausePlayers(),n.state("embed").props.on("change:url",function(e,t){t&&e.get("url")&&(n.state("embed").metadata=e.toJSON())}),n.state("embed").on("select",function(){var e=n.state("embed").metadata;i.url?t(e.url):t(s.embed.shortcode(e).string())}),n.on("close",function(){n.detach()}),n.open()}}),e.register("gallery",_.extend({},t)),e.register("audio",_.extend({},o,{state:["audio-details"]})),e.register("video",_.extend({},o,{state:["video-details"]})),e.register("playlist",_.extend({},o,{state:["playlist-edit","video-playlist-edit"]})),e.register("embed",_.extend({},a)),e.register("embedURL",_.extend({},a,{match:function(e){e=/(^|

(?:]+>\s*<\/span>)?)(https?:\/\/[^\s"]+?)((?:]+>\s*<\/span>)?<\/p>\s*|$)/gi.exec(e);if(e)return{index:e.index+e[1].length,content:e[2],options:{url:!0}}}}))}(window,window.wp.mce.views,window.wp.media,window.jQuery); \ No newline at end of file diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index 70f292af90..34b79aaec9 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -1395,8 +1395,7 @@ var __webpack_exports__ = {}; * @output wp-includes/js/media-models.js */ -var $ = jQuery, - Attachment, Attachments, l10n, media; +var Attachment, Attachments, l10n, media; /** @namespace wp */ window.wp = window.wp || {}; @@ -1631,11 +1630,6 @@ media.query = function( props ) { }); }; -// Clean up. Prevents mobile browsers caching. -$(window).on('unload', function(){ - window.wp = null; -}); - }(); /******/ })() ; \ No newline at end of file diff --git a/wp-includes/js/media-models.min.js b/wp-includes/js/media-models.min.js index 4d1af34259..2e0ee0484f 100644 --- a/wp-includes/js/media-models.min.js +++ b/wp-includes/js/media-models.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(){var i={7727:function(t){var n=Backbone.$,e=Backbone.Model.extend({sync:function(t,e,i){return _.isUndefined(this.id)?n.Deferred().rejectWith(this).promise():"read"===t?((i=i||{}).context=this,i.data=_.extend(i.data||{},{action:"get-attachment",id:this.id}),wp.media.ajax(i)):"update"===t?this.get("nonces")&&this.get("nonces").update?((i=i||{}).context=this,i.data=_.extend(i.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:wp.media.model.settings.post.id}),e.hasChanged()&&(i.data.changes={},_.each(e.changed,function(t,e){i.data.changes[e]=this.get(e)},this)),wp.media.ajax(i)):n.Deferred().rejectWith(this).promise():"delete"===t?((i=i||{}).wait||(this.destroyed=!0),i.context=this,i.data=_.extend(i.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces").delete}),wp.media.ajax(i).done(function(){this.destroyed=!0}).fail(function(){this.destroyed=!1})):Backbone.Model.prototype.sync.apply(this,arguments)},parse:function(t){return t&&(t.date=new Date(t.date),t.modified=new Date(t.modified)),t},saveCompat:function(t,s){var r=this;return this.get("nonces")&&this.get("nonces").update?wp.media.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:wp.media.model.settings.post.id},t)).done(function(t,e,i){r.set(r.parse(t,i),s)}):n.Deferred().rejectWith(this).promise()}},{create:function(t){return wp.media.model.Attachments.all.push(t)},get:_.memoize(function(t,e){return wp.media.model.Attachments.all.push(e||{id:t})})});t.exports=e},6940:function(t){var n=Backbone.Collection.extend({model:wp.media.model.Attachment,initialize:function(t,e){e=e||{},this.props=new Backbone.Model,this.filters=e.filters||{},this.props.on("change",this._changeFilteredProps,this),this.props.on("change:order",this._changeOrder,this),this.props.on("change:orderby",this._changeOrderby,this),this.props.on("change:query",this._changeQuery,this),this.props.set(_.defaults(e.props||{})),e.observe&&this.observe(e.observe)},_changeOrder:function(){this.comparator&&this.sort()},_changeOrderby:function(t,e){this.comparator&&this.comparator!==n.comparator||(e&&"post__in"!==e?this.comparator=n.comparator:delete this.comparator)},_changeQuery:function(t,e){e?(this.props.on("change",this._requery,this),this._requery()):this.props.off("change",this._requery,this)},_changeFilteredProps:function(r){this.props.get("query")||_.chain(r.changed).map(function(t,e){var i=n.filters[e],s=r.get(e);if(i){if(s&&!this.filters[e])this.filters[e]=i;else{if(s||this.filters[e]!==i)return;delete this.filters[e]}return!0}},this).any().value()&&(this._source||(this._source=new n(this.models)),this.reset(this._source.filter(this.validator,this)))},validateDestroyed:!1,validator:function(e){return!(!this.validateDestroyed&&e.destroyed)&&_.all(this.filters,function(t){return!!t.call(this,e)},this)},validate:function(t,e){var i=this.validator(t),s=!!this.get(t.cid);return!i&&s?this.remove(t,e):i&&!s&&this.add(t,e),this},validateAll:function(t,e){return e=e||{},_.each(t.models,function(t){this.validate(t,{silent:!0})},this),e.silent||this.trigger("reset",this,e),this},observe:function(t){return this.observers=this.observers||[],this.observers.push(t),t.on("add change remove",this._validateHandler,this),t.on("add",this._addToTotalAttachments,this),t.on("remove",this._removeFromTotalAttachments,this),t.on("reset",this._validateAllHandler,this),this.validateAll(t),this},unobserve:function(t){return t?(t.off(null,null,this),this.observers=_.without(this.observers,t)):(_.each(this.observers,function(t){t.off(null,null,this)},this),delete this.observers),this},_removeFromTotalAttachments:function(){this.mirroring&&(this.mirroring.totalAttachments=this.mirroring.totalAttachments-1)},_addToTotalAttachments:function(){this.mirroring&&(this.mirroring.totalAttachments=this.mirroring.totalAttachments+1)},_validateHandler:function(t,e,i){return i=e===this.mirroring?i:{silent:i&&i.silent},this.validate(t,i)},_validateAllHandler:function(t,e){return this.validateAll(t,e)},mirror:function(t){return this.mirroring&&this.mirroring===t||(this.unmirror(),this.mirroring=t,this.reset([],{silent:!0}),this.observe(t),this.trigger("attachments:received",this)),this},unmirror:function(){this.mirroring&&(this.unobserve(this.mirroring),delete this.mirroring)},more:function(t){var e=jQuery.Deferred(),i=this.mirroring,s=this;return(i&&i.more?(i.more(t).done(function(){this===s.mirroring&&e.resolveWith(this),s.trigger("attachments:received",this)}),e):e.resolveWith(this)).promise()},hasMore:function(){return!!this.mirroring&&this.mirroring.hasMore()},totalAttachments:0,getTotalAttachments:function(){return this.mirroring?this.mirroring.totalAttachments:0},parse:function(t,i){return _.isArray(t)||(t=[t]),_.map(t,function(t){var e;return t instanceof Backbone.Model?(e=t.get("id"),t=t.attributes):e=t.id,t=(e=wp.media.model.Attachment.get(e)).parse(t,i),_.isEqual(e.attributes,t)||e.set(t),e})},_requery:function(){var t;this.props.get("query")&&(t=this.props.toJSON(),this.mirror(wp.media.model.Query.get(t)))},saveMenuOrder:function(){if("menuOrder"===this.props.get("orderby")){var t=this.chain().filter(function(t){return!_.isUndefined(t.id)}).map(function(t,e){return t.set("menuOrder",e+=1),[t.id,e]}).object().value();if(!_.isEmpty(t))return wp.media.post("save-attachment-order",{nonce:wp.media.model.settings.post.nonce,post_id:wp.media.model.settings.post.id,attachments:t})}}},{comparator:function(t,e,i){var s=this.props.get("orderby"),r=this.props.get("order")||"DESC",n=t.cid,a=e.cid;return t=t.get(s),e=e.get(s),"date"!==s&&"modified"!==s||(t=t||new Date,e=e||new Date),i&&i.ties&&(n=a=null),"DESC"===r?wp.media.compare(t,e,n,a):wp.media.compare(e,t,a,n)},filters:{search:function(e){return!this.props.get("search")||_.any(["title","filename","description","caption","name"],function(t){t=e.get(t);return t&&-1!==t.search(this.props.get("search"))},this)},type:function(t){var e,i=this.props.get("type"),t=t.toJSON();return!(i&&(!_.isArray(i)||i.length))||(e=t.mime||t.file&&t.file.type||"",_.isArray(i)?_.find(i,function(t){return-1!==e.indexOf(t)}):-1!==e.indexOf(i))},uploadedTo:function(t){var e=this.props.get("uploadedTo");return!!_.isUndefined(e)||e===t.get("uploadedTo")},status:function(t){var e=this.props.get("status");return!!_.isUndefined(e)||e===t.get("status")}}});t.exports=n},5927:function(t){var e=Backbone.Model.extend({initialize:function(t){var e=wp.media.model.Attachment;this.attachment=!1,t.attachment_id&&(this.attachment=e.get(t.attachment_id),this.attachment.get("url")?(this.dfd=jQuery.Deferred(),this.dfd.resolve()):this.dfd=this.attachment.fetch(),this.bindAttachmentListeners()),this.on("change:link",this.updateLinkUrl,this),this.on("change:size",this.updateSize,this),this.setLinkTypeFromUrl(),this.setAspectRatio(),this.set("originalUrl",t.url)},bindAttachmentListeners:function(){this.listenTo(this.attachment,"sync",this.setLinkTypeFromUrl),this.listenTo(this.attachment,"sync",this.setAspectRatio),this.listenTo(this.attachment,"change",this.updateSize)},changeAttachment:function(t,e){this.stopListening(this.attachment),this.attachment=t,this.bindAttachmentListeners(),this.set("attachment_id",this.attachment.get("id")),this.set("caption",this.attachment.get("caption")),this.set("alt",this.attachment.get("alt")),this.set("size",e.get("size")),this.set("align",e.get("align")),this.set("link",e.get("link")),this.updateLinkUrl(),this.updateSize()},setLinkTypeFromUrl:function(){var t,e=this.get("linkUrl");e?(t="custom",this.attachment?this.attachment.get("url")===e?t="file":this.attachment.get("link")===e&&(t="post"):this.get("url")===e&&(t="file"),this.set("link",t)):this.set("link","none")},updateLinkUrl:function(){var t;switch(this.get("link")){case"file":t=(this.attachment||this).get("url"),this.set("linkUrl",t);break;case"post":this.set("linkUrl",this.attachment.get("link"));break;case"none":this.set("linkUrl","")}},updateSize:function(){var t;this.attachment&&("custom"===this.get("size")?(this.set("width",this.get("customWidth")),this.set("height",this.get("customHeight")),this.set("url",this.get("originalUrl"))):(t=this.attachment.get("sizes")[this.get("size")])&&(this.set("url",t.url),this.set("width",t.width),this.set("height",t.height)))},setAspectRatio:function(){var t;this.attachment&&this.attachment.get("sizes")&&(t=this.attachment.get("sizes").full)?this.set("aspectRatio",t.width/t.height):this.set("aspectRatio",this.get("customWidth")/this.get("customHeight"))}});t.exports=e},4009:function(t){var a,r=wp.media.model.Attachments,o=r.extend({initialize:function(t,e){var i;e=e||{},r.prototype.initialize.apply(this,arguments),this.args=e.args,this._hasMore=!0,this.created=new Date,this.filters.order=function(t){var e=this.props.get("orderby"),i=this.props.get("order");return!this.comparator||(this.length?1!==this.comparator(t,this.last(),{ties:!0}):"DESC"!==i||"date"!==e&&"modified"!==e?"ASC"===i&&"menuOrder"===e&&0===t.get(e):t.get(e)>=this.created)},i=["s","order","orderby","posts_per_page","post_mime_type","post_parent","author"],wp.Uploader&&_(this.args).chain().keys().difference(i).isEmpty().value()&&this.observe(wp.Uploader.queue)},hasMore:function(){return this._hasMore},more:function(t){var e=this;return this._more&&"pending"===this._more.state()?this._more:this.hasMore()?((t=t||{}).remove=!1,this._more=this.fetch(t).done(function(t){(_.isEmpty(t)||-1===e.args.posts_per_page||t.length=this.created)},i=["s","order","orderby","posts_per_page","post_mime_type","post_parent","author"],wp.Uploader&&_(this.args).chain().keys().difference(i).isEmpty().value()&&this.observe(wp.Uploader.queue)},hasMore:function(){return this._hasMore},more:function(t){var e=this;return this._more&&"pending"===this._more.state()?this._more:this.hasMore()?((t=t||{}).remove=!1,this._more=this.fetch(t).done(function(t){(_.isEmpty(t)||-1===e.args.posts_per_page||t.length