WordPress/wp-includes/js/customize-preview.min.js

1 line
9.8 KiB
JavaScript
Raw Normal View History

!function(o){var s,i,r,a,c,n,u,l,d,p=wp.customize,h={};(i=history).replaceState&&(c=function(e){var t,n=document.createElement("a");return n.href=e,t=p.utils.parseQueryString(location.search.substr(1)),(e=p.utils.parseQueryString(n.search.substr(1))).customize_changeset_uuid=t.customize_changeset_uuid,t.customize_theme&&(e.customize_theme=t.customize_theme),t.customize_messenger_channel&&(e.customize_messenger_channel=t.customize_messenger_channel),n.search=o.param(e),n.href},i.replaceState=(r=i.replaceState,function(e,t,n){return h=e,r.call(i,e,t,"string"==typeof n&&0<n.length?c(n):n)}),i.pushState=(a=i.pushState,function(e,t,n){return h=e,a.call(i,e,t,"string"==typeof n&&0<n.length?c(n):n)}),window.addEventListener("popstate",function(e){h=e.state})),s=function(t,n,i){var s;return function(){var e=arguments;i=i||this,clearTimeout(s),s=setTimeout(function(){s=null,t.apply(i,e)},n)}},p.Preview=p.Messenger.extend({initialize:function(e,t){var n=this,i=document.createElement("a");p.Messenger.prototype.initialize.call(n,e,t),i.href=n.origin(),n.add("scheme",i.protocol.replace(/:$/,"")),n.body=o(document.body),n.window=o(window),p.settings.channel&&(n.body.on("click.preview","a",function(e){n.handleLinkClick(e)}),n.body.on("submit.preview","form",function(e){n.handleFormSubmit(e)}),n.window.on("scroll.preview",s(function(){n.send("scroll",n.window.scrollTop())},200)),n.bind("scroll",function(e){n.window.scrollTop(e)}))},handleLinkClick:function(e){var t=o(e.target).closest("a");if(!_.isUndefined(t.attr("href"))&&!("#"===t.attr("href").substr(0,1))&&/^https?:$/.test(t.prop("protocol"))){if(!p.isLinkPreviewable(t[0]))return wp.a11y.speak(p.settings.l10n.linkUnpreviewable),void e.preventDefault();e.preventDefault(),e.shiftKey||this.send("url",t.prop("href"))}},handleFormSubmit:function(e){var t=document.createElement("a"),n=o(e.target);if(t.href=n.prop("action"),"GET"!==n.prop("method").toUpperCase()||!p.isLinkPreviewable(t))return wp.a11y.speak(p.settings.l10n.formUnpreviewable),void e.preventDefault();e.isDefaultPrevented()||(1<t.search.length&&(t.search+="&"),t.search+=n.serialize(),this.send("url",t.href)),e.preventDefault()}}),p.addLinkPreviewing=function(){var t="a[href], area";o(document.body).find(t).each(function(){p.prepareLinkPreview(this)}),"undefined"!=typeof MutationObserver?(p.mutationObserver=new MutationObserver(function(e){_.each(e,function(e){o(e.target).find(t).each(function(){p.prepareLinkPreview(this)})})}),p.mutationObserver.observe(document.documentElement,{childList:!0,subtree:!0})):o(document.documentElement).on("click focus mouseover",t,function(){p.prepareLinkPreview(this)})},p.isLinkPreviewable=function(t,e){var n,i,e=_.extend({},{allowAdminAjax:!1},e||{});return"javascript:"===t.protocol||("https:"===t.protocol||"http:"===t.protocol)&&(i=t.host.replace(/:(80|443)$/,""),n=document.createElement("a"),!_.isUndefined(_.find(p.settings.url.allowed,function(e){return n.href=e,n.protocol===t.protocol&&n.host.replace(/:(80|443)$/,"")===i&&0===t.pathname.indexOf(n.pathname.replace(/\/$/,""))}))&&(!/\/wp-(login|signup)\.php$/.test(t.pathname)&&(/\/wp-admin\/admin-ajax\.php$/.test(t.pathname)?e.allowAdminAjax:!/\/wp-(admin|includes|content)(\/|$)/.test(t.pathname))))},p.prepareLinkPreview=function(e){var t;o(e).closest("#wpadminbar").length||"#"!==o(e).attr("href").substr(0,1)&&/^https?:$/.test(e.protocol)&&(p.settings.channel&&"https"===p.preview.scheme.get()&&"http:"===e.protocol&&-1!==p.settings.url.allowedHosts.indexOf(e.host)&&(e.protocol="https:"),p.isLinkPreviewable(e)?(o(e).removeClass("customize-unpreviewable"),(t=p.utils.parseQueryString(e.search.substring(1))).customize_changeset_uuid=p.settings.changeset.uuid,p.settings.theme.active||(t.customize_theme=p.settings.theme.stylesheet),p.settings.channel&&(t.customize_messenger_channel=p.settings.channel),e.search=o.param(t),p.settings.channel&&(e.target="_self")):p.settings.channel&&o(e).addClass("customize-unpreviewable"))},p.addRequestPreviewing=function(){o.ajaxPrefilter(function(e,t,n){var i,s,r={},a=document.createElement("a");a.href=e.url,p.isL