2021-11-03 11:05:58 -04:00
|
|
|
!function(Y){var a,e,s,t,n,i,G=wp.customize,o=window.matchMedia("(prefers-reduced-motion: reduce)"),r=o.matches;o.addEventListener("change",function(e){r=e.matches}),G.OverlayNotification=G.Notification.extend({loading:!1,initialize:function(e,t){var n=this;G.Notification.prototype.initialize.call(n,e,t),n.containerClasses+=" notification-overlay",n.loading&&(n.containerClasses+=" notification-loading")},render:function(){var e=G.Notification.prototype.render.call(this);return e.on("keydown",_.bind(this.handleEscape,this)),e},handleEscape:function(e){var t=this;27===e.which&&(e.stopPropagation(),t.dismissible&&t.parent&&t.parent.remove(t.code))}}),G.Notifications=G.Values.extend({alt:!1,defaultConstructor:G.Notification,initialize:function(e){var t=this;G.Values.prototype.initialize.call(t,e),_.bindAll(t,"constrainFocus"),t._addedIncrement=0,t._addedOrder={},t.bind("add",function(e){t.trigger("change",e)}),t.bind("removed",function(e){t.trigger("change",e)})},count:function(){return _.size(this._value)},add:function(e,t){var n,i=this,e="string"==typeof e?(n=e,t):(n=e.code,e);return i.has(n)||(i._addedIncrement+=1,i._addedOrder[n]=i._addedIncrement),G.Values.prototype.add.call(i,n,e)},remove:function(e){return delete this._addedOrder[e],G.Values.prototype.remove.call(this,e)},get:function(e){var a,o=this,t=_.values(o._value);return _.extend({sort:!1},e).sort&&(a={error:4,warning:3,success:2,info:1},t.sort(function(e,t){var n=0,i=0;return(n=!_.isUndefined(a[e.type])?a[e.type]:n)!==(i=!_.isUndefined(a[t.type])?a[t.type]:i)?i-n:o._addedOrder[t.code]-o._addedOrder[e.code]})),t},render:function(){var e,n,t,i=this,a=!1,o=[],s={};i.container&&i.container.length&&(e=i.get({sort:!0}),i.container.toggle(0!==e.length),i.container.is(i.previousContainer)&&_.isEqual(e,i.previousNotifications)||((n=i.container.children("ul").first()).length||(n=Y("<ul></ul>"),i.container.append(n)),n.find("> [data-code]").remove(),_.each(i.previousNotifications,function(e){s[e.code]=e}),_.each(e,function(e){var t;!wp.a11y||s[e.code]&&_.isEqual(e.message,s[e.code].message)||wp.a11y.speak(e.message,"assertive"),t=Y(e.render()),e.container=t,n.append(t),e.extended(G.OverlayNotification)&&o.push(e)}),(t=Boolean(o.length))!==(a=i.previousNotifications?Boolean(_.find(i.previousNotifications,function(e){return e.extended(G.OverlayNotification)})):a)&&(Y(document.body).toggleClass("customize-loading",t),i.container.toggleClass("has-overlay-notifications",t),t?(i.previousActiveElement=document.activeElement,Y(document).on("keydown",i.constrainFocus)):Y(document).off("keydown",i.constrainFocus)),t?(i.focusContainer=o[o.length-1].container,i.focusContainer.prop("tabIndex",-1),((t=i.focusContainer.find(":focusable")).length?t.first():i.focusContainer).focus()):i.previousActiveElement&&(Y(i.previousActiveElement).trigger("focus"),i.previousActiveElement=null),i.previousNotifications=e,i.previousContainer=i.container,i.trigger("rendered")))},constrainFocus:function(e){var t,n=this;e.stopPropagation(),9===e.which&&(0===(t=n.focusContainer.find(":focusable")).length&&(t=n.focusContainer),!Y.contains(n.focusContainer[0],e.target)||!Y.contains(n.focusContainer[0],document.activeElement)||t.last().is(e.target)&&!e.shiftKey?(e.preventDefault(),t.first().focus()):t.first().is(e.target)&&e.shiftKey&&(e.preventDefault(),t.last().focus()))}}),G.Setting=G.Value.extend({defaults:{transport:"refresh",dirty:!1},initialize:function(e,t,n){var i=this,n=_.extend({previewer:G.previewer},i.defaults,n||{});G.Value.prototype.initialize.call(i,t,n),i.id=e,i._dirty=n.dirty,i.notifications=new G.Notifications,i.bind(i.preview)},preview:function(){var e=this,t=e.transport;"postMessage"===(t="postMessage"===t&&!G.state("previewerAlive").get()?"refresh":t)?e.previewer.send("setting",[e.id,e()]):"refresh"===t&&e.previewer.refresh()},findControls:function(){var n=this,i=[];return G.control.each(function(t){_.each(t.settings,function(e){e.id===n.id&&i.push(t)})}),i}}),G._latestRevision=0,G._lastSavedRevision=0,G._latestSettingRevisions={},G.bind("change",function(e){G._latestRevision+=1,G._late
|