PK! "//customize-widgets.jsnu[/** * @output wp-admin/js/customize-widgets.js */ /* global _wpCustomizeWidgetsSettings */ (function( wp, $ ){ if ( ! wp || ! wp.customize ) { return; } // Set up our namespace... var api = wp.customize, l10n; /** * @namespace wp.customize.Widgets */ api.Widgets = api.Widgets || {}; api.Widgets.savedWidgetIds = {}; // Link settings. api.Widgets.data = _wpCustomizeWidgetsSettings || {}; l10n = api.Widgets.data.l10n; /** * wp.customize.Widgets.WidgetModel * * A single widget model. * * @class wp.customize.Widgets.WidgetModel * @augments Backbone.Model */ api.Widgets.WidgetModel = Backbone.Model.extend(/** @lends wp.customize.Widgets.WidgetModel.prototype */{ id: null, temp_id: null, classname: null, control_tpl: null, description: null, is_disabled: null, is_multi: null, multi_number: null, name: null, id_base: null, transport: null, params: [], width: null, height: null, search_matched: true }); /** * wp.customize.Widgets.WidgetCollection * * Collection for widget models. * * @class wp.customize.Widgets.WidgetCollection * @augments Backbone.Collection */ api.Widgets.WidgetCollection = Backbone.Collection.extend(/** @lends wp.customize.Widgets.WidgetCollection.prototype */{ model: api.Widgets.WidgetModel, // Controls searching on the current widget collection // and triggers an update event. doSearch: function( value ) { // Don't do anything if we've already done this search. // Useful because the search handler fires multiple times per keystroke. if ( this.terms === value ) { return; } // Updates terms with the value passed. this.terms = value; // If we have terms, run a search... if ( this.terms.length > 0 ) { this.search( this.terms ); } // If search is blank, set all the widgets as they matched the search to reset the views. if ( this.terms === '' ) { this.each( function ( widget ) { widget.set( 'search_matched', true ); } ); } }, // Performs a search within the collection. // @uses RegExp search: function( term ) { var match, haystack; // Escape the term string for RegExp meta characters. term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); // Consider spaces as word delimiters and match the whole string // so matching terms can be combined. term = term.replace( / /g, ')(?=.*' ); match = new RegExp( '^(?=.*' + term + ').+', 'i' ); this.each( function ( data ) { haystack = [ data.get( 'name' ), data.get( 'description' ) ].join( ' ' ); data.set( 'search_matched', match.test( haystack ) ); } ); } }); api.Widgets.availableWidgets = new api.Widgets.WidgetCollection( api.Widgets.data.availableWidgets ); /** * wp.customize.Widgets.SidebarModel * * A single sidebar model. * * @class wp.customize.Widgets.SidebarModel * @augments Backbone.Model */ api.Widgets.SidebarModel = Backbone.Model.extend(/** @lends wp.customize.Widgets.SidebarModel.prototype */{ after_title: null, after_widget: null, before_title: null, before_widget: null, 'class': null, description: null, id: null, name: null, is_rendered: false }); /** * wp.customize.Widgets.SidebarCollection * * Collection for sidebar models. * * @class wp.customize.Widgets.SidebarCollection * @augments Backbone.Collection */ api.Widgets.SidebarCollection = Backbone.Collection.extend(/** @lends wp.customize.Widgets.SidebarCollection.prototype */{ model: api.Widgets.SidebarModel }); api.Widgets.registeredSidebars = new api.Widgets.SidebarCollection( api.Widgets.data.registeredSidebars ); api.Widgets.AvailableWidgetsPanelView = wp.Backbone.View.extend(/** @lends wp.customize.Widgets.AvailableWidgetsPanelView.prototype */{ el: '#available-widgets', events: { 'input #widgets-search': 'search', 'focus .widget-tpl' : 'focus', 'click .widget-tpl' : '_submit', 'keypress .widget-tpl' : '_submit', 'keydown' : 'keyboardAccessible' }, // Cache current selected widget. selected: null, // Cache sidebar control which has opened panel. currentSidebarControl: null, $search: null, $clearResults: null, searchMatchesCount: null, /** * View class for the available widgets panel. * * @constructs wp.customize.Widgets.AvailableWidgetsPanelView * @augments wp.Backbone.View */ initialize: function() { var self = this; this.$search = $( '#widgets-search' ); this.$clearResults = this.$el.find( '.clear-results' ); _.bindAll( this, 'close' ); this.listenTo( this.collection, 'change', this.updateList ); this.updateList(); // Set the initial search count to the number of available widgets. this.searchMatchesCount = this.collection.length; /* * If the available widgets panel is open and the customize controls * are interacted with (i.e. available widgets panel is blurred) then * close the available widgets panel. Also close on back button click. */ $( '#customize-controls, #available-widgets .customize-section-title' ).on( 'click keydown', function( e ) { var isAddNewBtn = $( e.target ).is( '.add-new-widget, .add-new-widget *' ); if ( $( 'body' ).hasClass( 'adding-widget' ) && ! isAddNewBtn ) { self.close(); } } ); // Clear the search results and trigger an `input` event to fire a new search. this.$clearResults.on( 'click', function() { self.$search.val( '' ).trigger( 'focus' ).trigger( 'input' ); } ); // Close the panel if the URL in the preview changes. api.previewer.bind( 'url', this.close ); }, /** * Performs a search and handles selected widget. */ search: _.debounce( function( event ) { var firstVisible; this.collection.doSearch( event.target.value ); // Update the search matches count. this.updateSearchMatchesCount(); // Announce how many search results. this.announceSearchMatches(); // Remove a widget from being selected if it is no longer visible. if ( this.selected && ! this.selected.is( ':visible' ) ) { this.selected.removeClass( 'selected' ); this.selected = null; } // If a widget was selected but the filter value has been cleared out, clear selection. if ( this.selected && ! event.target.value ) { this.selected.removeClass( 'selected' ); this.selected = null; } // If a filter has been entered and a widget hasn't been selected, select the first one shown. if ( ! this.selected && event.target.value ) { firstVisible = this.$el.find( '> .widget-tpl:visible:first' ); if ( firstVisible.length ) { this.select( firstVisible ); } } // Toggle the clear search results button. if ( '' !== event.target.value ) { this.$clearResults.addClass( 'is-visible' ); } else if ( '' === event.target.value ) { this.$clearResults.removeClass( 'is-visible' ); } // Set a CSS class on the search container when there are no search results. if ( ! this.searchMatchesCount ) { this.$el.addClass( 'no-widgets-found' ); } else { this.$el.removeClass( 'no-widgets-found' ); } }, 500 ), /** * Updates the count of the available widgets that have the `search_matched` attribute. */ updateSearchMatchesCount: function() { this.searchMatchesCount = this.collection.where({ search_matched: true }).length; }, /** * Sends a message to the aria-live region to announce how many search results. */ announceSearchMatches: function() { var message = l10n.widgetsFound.replace( '%d', this.searchMatchesCount ) ; if ( ! this.searchMatchesCount ) { message = l10n.noWidgetsFound; } wp.a11y.speak( message ); }, /** * Changes visibility of available widgets. */ updateList: function() { this.collection.each( function( widget ) { var widgetTpl = $( '#widget-tpl-' + widget.id ); widgetTpl.toggle( widget.get( 'search_matched' ) && ! widget.get( 'is_disabled' ) ); if ( widget.get( 'is_disabled' ) && widgetTpl.is( this.selected ) ) { this.selected = null; } } ); }, /** * Highlights a widget. */ select: function( widgetTpl ) { this.selected = $( widgetTpl ); this.selected.siblings( '.widget-tpl' ).removeClass( 'selected' ); this.selected.addClass( 'selected' ); }, /** * Highlights a widget on focus. */ focus: function( event ) { this.select( $( event.currentTarget ) ); }, /** * Handles submit for keypress and click on widget. */ _submit: function( event ) { // Only proceed with keypress if it is Enter or Spacebar. if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) { return; } this.submit( $( event.currentTarget ) ); }, /** * Adds a selected widget to the sidebar. */ submit: function( widgetTpl ) { var widgetId, widget, widgetFormControl; if ( ! widgetTpl ) { widgetTpl = this.selected; } if ( ! widgetTpl || ! this.currentSidebarControl ) { return; } this.select( widgetTpl ); widgetId = $( this.selected ).data( 'widget-id' ); widget = this.collection.findWhere( { id: widgetId } ); if ( ! widget ) { return; } widgetFormControl = this.currentSidebarControl.addWidget( widget.get( 'id_base' ) ); if ( widgetFormControl ) { widgetFormControl.focus(); } this.close(); }, /** * Opens the panel. */ open: function( sidebarControl ) { this.currentSidebarControl = sidebarControl; // Wide widget controls appear over the preview, and so they need to be collapsed when the panel opens. _( this.currentSidebarControl.getWidgetFormControls() ).each( function( control ) { if ( control.params.is_wide ) { control.collapseForm(); } } ); if ( api.section.has( 'publish_settings' ) ) { api.section( 'publish_settings' ).collapse(); } $( 'body' ).addClass( 'adding-widget' ); this.$el.find( '.selected' ).removeClass( 'selected' ); // Reset search. this.collection.doSearch( '' ); if ( ! api.settings.browser.mobile ) { this.$search.trigger( 'focus' ); } }, /** * Closes the panel. */ close: function( options ) { options = options || {}; if ( options.returnFocus && this.currentSidebarControl ) { this.currentSidebarControl.container.find( '.add-new-widget' ).focus(); } this.currentSidebarControl = null; this.selected = null; $( 'body' ).removeClass( 'adding-widget' ); this.$search.val( '' ).trigger( 'input' ); }, /** * Adds keyboard accessibility to the panel. */ keyboardAccessible: function( event ) { var isEnter = ( event.which === 13 ), isEsc = ( event.which === 27 ), isDown = ( event.which === 40 ), isUp = ( event.which === 38 ), isTab = ( event.which === 9 ), isShift = ( event.shiftKey ), selected = null, firstVisible = this.$el.find( '> .widget-tpl:visible:first' ), lastVisible = this.$el.find( '> .widget-tpl:visible:last' ), isSearchFocused = $( event.target ).is( this.$search ), isLastWidgetFocused = $( event.target ).is( '.widget-tpl:visible:last' ); if ( isDown || isUp ) { if ( isDown ) { if ( isSearchFocused ) { selected = firstVisible; } else if ( this.selected && this.selected.nextAll( '.widget-tpl:visible' ).length !== 0 ) { selected = this.selected.nextAll( '.widget-tpl:visible:first' ); } } else if ( isUp ) { if ( isSearchFocused ) { selected = lastVisible; } else if ( this.selected && this.selected.prevAll( '.widget-tpl:visible' ).length !== 0 ) { selected = this.selected.prevAll( '.widget-tpl:visible:first' ); } } this.select( selected ); if ( selected ) { selected.trigger( 'focus' ); } else { this.$search.trigger( 'focus' ); } return; } // If enter pressed but nothing entered, don't do anything. if ( isEnter && ! this.$search.val() ) { return; } if ( isEnter ) { this.submit(); } else if ( isEsc ) { this.close( { returnFocus: true } ); } if ( this.currentSidebarControl && isTab && ( isShift && isSearchFocused || ! isShift && isLastWidgetFocused ) ) { this.currentSidebarControl.container.find( '.add-new-widget' ).focus(); event.preventDefault(); } } }); /** * Handlers for the widget-synced event, organized by widget ID base. * Other widgets may provide their own update handlers by adding * listeners for the widget-synced event. * * @alias wp.customize.Widgets.formSyncHandlers */ api.Widgets.formSyncHandlers = { /** * @param {jQuery.Event} e * @param {jQuery} widget * @param {string} newForm */ rss: function( e, widget, newForm ) { var oldWidgetError = widget.find( '.widget-error:first' ), newWidgetError = $( '
' + newForm + '
' ).find( '.widget-error:first' ); if ( oldWidgetError.length && newWidgetError.length ) { oldWidgetError.replaceWith( newWidgetError ); } else if ( oldWidgetError.length ) { oldWidgetError.remove(); } else if ( newWidgetError.length ) { widget.find( '.widget-content:first' ).prepend( newWidgetError ); } } }; api.Widgets.WidgetControl = api.Control.extend(/** @lends wp.customize.Widgets.WidgetControl.prototype */{ defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop }, /** * wp.customize.Widgets.WidgetControl * * Customizer control for widgets. * Note that 'widget_form' must match the WP_Widget_Form_Customize_Control::$type * * @since 4.1.0 * * @constructs wp.customize.Widgets.WidgetControl * @augments wp.customize.Control */ initialize: function( id, options ) { var control = this; control.widgetControlEmbedded = false; control.widgetContentEmbedded = false; control.expanded = new api.Value( false ); control.expandedArgumentsQueue = []; control.expanded.bind( function( expanded ) { var args = control.expandedArgumentsQueue.shift(); args = $.extend( {}, control.defaultExpandedArguments, args ); control.onChangeExpanded( expanded, args ); }); control.altNotice = true; api.Control.prototype.initialize.call( control, id, options ); }, /** * Set up the control. * * @since 3.9.0 */ ready: function() { var control = this; /* * Embed a placeholder once the section is expanded. The full widget * form content will be embedded once the control itself is expanded, * and at this point the widget-added event will be triggered. */ if ( ! control.section() ) { control.embedWidgetControl(); } else { api.section( control.section(), function( section ) { var onExpanded = function( isExpanded ) { if ( isExpanded ) { control.embedWidgetControl(); section.expanded.unbind( onExpanded ); } }; if ( section.expanded() ) { onExpanded( true ); } else { section.expanded.bind( onExpanded ); } } ); } }, /** * Embed the .widget element inside the li container. * * @since 4.4.0 */ embedWidgetControl: function() { var control = this, widgetControl; if ( control.widgetControlEmbedded ) { return; } control.widgetControlEmbedded = true; widgetControl = $( control.params.widget_control ); control.container.append( widgetControl ); control._setupModel(); control._setupWideWidget(); control._setupControlToggle(); control._setupWidgetTitle(); control._setupReorderUI(); control._setupHighlightEffects(); control._setupUpdateUI(); control._setupRemoveUI(); }, /** * Embed the actual widget form inside of .widget-content and finally trigger the widget-added event. * * @since 4.4.0 */ embedWidgetContent: function() { var control = this, widgetContent; control.embedWidgetControl(); if ( control.widgetContentEmbedded ) { return; } control.widgetContentEmbedded = true; // Update the notification container element now that the widget content has been embedded. control.notifications.container = control.getNotificationsContainerElement(); control.notifications.render(); widgetContent = $( control.params.widget_content ); control.container.find( '.widget-content:first' ).append( widgetContent ); /* * Trigger widget-added event so that plugins can attach any event * listeners and dynamic UI elements. */ $( document ).trigger( 'widget-added', [ control.container.find( '.widget:first' ) ] ); }, /** * Handle changes to the setting */ _setupModel: function() { var self = this, rememberSavedWidgetId; // Remember saved widgets so we know which to trash (move to inactive widgets sidebar). rememberSavedWidgetId = function() { api.Widgets.savedWidgetIds[self.params.widget_id] = true; }; api.bind( 'ready', rememberSavedWidgetId ); api.bind( 'saved', rememberSavedWidgetId ); this._updateCount = 0; this.isWidgetUpdating = false; this.liveUpdateMode = true; // Update widget whenever model changes. this.setting.bind( function( to, from ) { if ( ! _( from ).isEqual( to ) && ! self.isWidgetUpdating ) { self.updateWidget( { instance: to } ); } } ); }, /** * Add special behaviors for wide widget controls */ _setupWideWidget: function() { var self = this, $widgetInside, $widgetForm, $customizeSidebar, $themeControlsContainer, positionWidget; if ( ! this.params.is_wide || $( window ).width() <= 640 /* max-width breakpoint in customize-controls.css */ ) { return; } $widgetInside = this.container.find( '.widget-inside' ); $widgetForm = $widgetInside.find( '> .form' ); $customizeSidebar = $( '.wp-full-overlay-sidebar-content:first' ); this.container.addClass( 'wide-widget-control' ); this.container.find( '.form:first' ).css( { 'max-width': this.params.width, 'min-height': this.params.height } ); /** * Keep the widget-inside positioned so the top of fixed-positioned * element is at the same top position as the widget-top. When the * widget-top is scrolled out of view, keep the widget-top in view; * likewise, don't allow the widget to drop off the bottom of the window. * If a widget is too tall to fit in the window, don't let the height * exceed the window height so that the contents of the widget control * will become scrollable (overflow:auto). */ positionWidget = function() { var offsetTop = self.container.offset().top, windowHeight = $( window ).height(), formHeight = $widgetForm.outerHeight(), top; $widgetInside.css( 'max-height', windowHeight ); top = Math.max( 0, // Prevent top from going off screen. Math.min( Math.max( offsetTop, 0 ), // Distance widget in panel is from top of screen. windowHeight - formHeight // Flush up against bottom of screen. ) ); $widgetInside.css( 'top', top ); }; $themeControlsContainer = $( '#customize-theme-controls' ); this.container.on( 'expand', function() { positionWidget(); $customizeSidebar.on( 'scroll', positionWidget ); $( window ).on( 'resize', positionWidget ); $themeControlsContainer.on( 'expanded collapsed', positionWidget ); } ); this.container.on( 'collapsed', function() { $customizeSidebar.off( 'scroll', positionWidget ); $( window ).off( 'resize', positionWidget ); $themeControlsContainer.off( 'expanded collapsed', positionWidget ); } ); // Reposition whenever a sidebar's widgets are changed. api.each( function( setting ) { if ( 0 === setting.id.indexOf( 'sidebars_widgets[' ) ) { setting.bind( function() { if ( self.container.hasClass( 'expanded' ) ) { positionWidget(); } } ); } } ); }, /** * Show/hide the control when clicking on the form title, when clicking * the close button */ _setupControlToggle: function() { var self = this, $closeBtn; this.container.find( '.widget-top' ).on( 'click', function( e ) { e.preventDefault(); var sidebarWidgetsControl = self.getSidebarWidgetsControl(); if ( sidebarWidgetsControl.isReordering ) { return; } self.expanded( ! self.expanded() ); } ); $closeBtn = this.container.find( '.widget-control-close' ); $closeBtn.on( 'click', function() { self.collapse(); self.container.find( '.widget-top .widget-action:first' ).focus(); // Keyboard accessibility. } ); }, /** * Update the title of the form if a title field is entered */ _setupWidgetTitle: function() { var self = this, updateTitle; updateTitle = function() { var title = self.setting().title, inWidgetTitle = self.container.find( '.in-widget-title' ); if ( title ) { inWidgetTitle.text( ': ' + title ); } else { inWidgetTitle.text( '' ); } }; this.setting.bind( updateTitle ); updateTitle(); }, /** * Set up the widget-reorder-nav */ _setupReorderUI: function() { var self = this, selectSidebarItem, $moveWidgetArea, $reorderNav, updateAvailableSidebars, template; /** * select the provided sidebar list item in the move widget area * * @param {jQuery} li */ selectSidebarItem = function( li ) { li.siblings( '.selected' ).removeClass( 'selected' ); li.addClass( 'selected' ); var isSelfSidebar = ( li.data( 'id' ) === self.params.sidebar_id ); self.container.find( '.move-widget-btn' ).prop( 'disabled', isSelfSidebar ); }; /** * Add the widget reordering elements to the widget control */ this.container.find( '.widget-title-action' ).after( $( api.Widgets.data.tpl.widgetReorderNav ) ); template = _.template( api.Widgets.data.tpl.moveWidgetArea ); $moveWidgetArea = $( template( { sidebars: _( api.Widgets.registeredSidebars.toArray() ).pluck( 'attributes' ) } ) ); this.container.find( '.widget-top' ).after( $moveWidgetArea ); /** * Update available sidebars when their rendered state changes */ updateAvailableSidebars = function() { var $sidebarItems = $moveWidgetArea.find( 'li' ), selfSidebarItem, renderedSidebarCount = 0; selfSidebarItem = $sidebarItems.filter( function(){ return $( this ).data( 'id' ) === self.params.sidebar_id; } ); $sidebarItems.each( function() { var li = $( this ), sidebarId, sidebar, sidebarIsRendered; sidebarId = li.data( 'id' ); sidebar = api.Widgets.registeredSidebars.get( sidebarId ); sidebarIsRendered = sidebar.get( 'is_rendered' ); li.toggle( sidebarIsRendered ); if ( sidebarIsRendered ) { renderedSidebarCount += 1; } if ( li.hasClass( 'selected' ) && ! sidebarIsRendered ) { selectSidebarItem( selfSidebarItem ); } } ); if ( renderedSidebarCount > 1 ) { self.container.find( '.move-widget' ).show(); } else { self.container.find( '.move-widget' ).hide(); } }; updateAvailableSidebars(); api.Widgets.registeredSidebars.on( 'change:is_rendered', updateAvailableSidebars ); /** * Handle clicks for up/down/move on the reorder nav */ $reorderNav = this.container.find( '.widget-reorder-nav' ); $reorderNav.find( '.move-widget, .move-widget-down, .move-widget-up' ).each( function() { $( this ).prepend( self.container.find( '.widget-title' ).text() + ': ' ); } ).on( 'click keypress', function( event ) { if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) { return; } $( this ).trigger( 'focus' ); if ( $( this ).is( '.move-widget' ) ) { self.toggleWidgetMoveArea(); } else { var isMoveDown = $( this ).is( '.move-widget-down' ), isMoveUp = $( this ).is( '.move-widget-up' ), i = self.getWidgetSidebarPosition(); if ( ( isMoveUp && i === 0 ) || ( isMoveDown && i === self.getSidebarWidgetsControl().setting().length - 1 ) ) { return; } if ( isMoveUp ) { self.moveUp(); wp.a11y.speak( l10n.widgetMovedUp ); } else { self.moveDown(); wp.a11y.speak( l10n.widgetMovedDown ); } $( this ).trigger( 'focus' ); // Re-focus after the container was moved. } } ); /** * Handle selecting a sidebar to move to */ this.container.find( '.widget-area-select' ).on( 'click keypress', 'li', function( event ) { if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) { return; } event.preventDefault(); selectSidebarItem( $( this ) ); } ); /** * Move widget to another sidebar */ this.container.find( '.move-widget-btn' ).click( function() { self.getSidebarWidgetsControl().toggleReordering( false ); var oldSidebarId = self.params.sidebar_id, newSidebarId = self.container.find( '.widget-area-select li.selected' ).data( 'id' ), oldSidebarWidgetsSetting, newSidebarWidgetsSetting, oldSidebarWidgetIds, newSidebarWidgetIds, i; oldSidebarWidgetsSetting = api( 'sidebars_widgets[' + oldSidebarId + ']' ); newSidebarWidgetsSetting = api( 'sidebars_widgets[' + newSidebarId + ']' ); oldSidebarWidgetIds = Array.prototype.slice.call( oldSidebarWidgetsSetting() ); newSidebarWidgetIds = Array.prototype.slice.call( newSidebarWidgetsSetting() ); i = self.getWidgetSidebarPosition(); oldSidebarWidgetIds.splice( i, 1 ); newSidebarWidgetIds.push( self.params.widget_id ); oldSidebarWidgetsSetting( oldSidebarWidgetIds ); newSidebarWidgetsSetting( newSidebarWidgetIds ); self.focus(); } ); }, /** * Highlight widgets in preview when interacted with in the Customizer */ _setupHighlightEffects: function() { var self = this; // Highlight whenever hovering or clicking over the form. this.container.on( 'mouseenter click', function() { self.setting.previewer.send( 'highlight-widget', self.params.widget_id ); } ); // Highlight when the setting is updated. this.setting.bind( function() { self.setting.previewer.send( 'highlight-widget', self.params.widget_id ); } ); }, /** * Set up event handlers for widget updating */ _setupUpdateUI: function() { var self = this, $widgetRoot, $widgetContent, $saveBtn, updateWidgetDebounced, formSyncHandler; $widgetRoot = this.container.find( '.widget:first' ); $widgetContent = $widgetRoot.find( '.widget-content:first' ); // Configure update button. $saveBtn = this.container.find( '.widget-control-save' ); $saveBtn.val( l10n.saveBtnLabel ); $saveBtn.attr( 'title', l10n.saveBtnTooltip ); $saveBtn.removeClass( 'button-primary' ); $saveBtn.on( 'click', function( e ) { e.preventDefault(); self.updateWidget( { disable_form: true } ); // @todo disable_form is unused? } ); updateWidgetDebounced = _.debounce( function() { self.updateWidget(); }, 250 ); // Trigger widget form update when hitting Enter within an input. $widgetContent.on( 'keydown', 'input', function( e ) { if ( 13 === e.which ) { // Enter. e.preventDefault(); self.updateWidget( { ignoreActiveElement: true } ); } } ); // Handle widgets that support live previews. $widgetContent.on( 'change input propertychange', ':input', function( e ) { if ( ! self.liveUpdateMode ) { return; } if ( e.type === 'change' || ( this.checkValidity && this.checkValidity() ) ) { updateWidgetDebounced(); } } ); // Remove loading indicators when the setting is saved and the preview updates. this.setting.previewer.channel.bind( 'synced', function() { self.container.removeClass( 'previewer-loading' ); } ); api.previewer.bind( 'widget-updated', function( updatedWidgetId ) { if ( updatedWidgetId === self.params.widget_id ) { self.container.removeClass( 'previewer-loading' ); } } ); formSyncHandler = api.Widgets.formSyncHandlers[ this.params.widget_id_base ]; if ( formSyncHandler ) { $( document ).on( 'widget-synced', function( e, widget ) { if ( $widgetRoot.is( widget ) ) { formSyncHandler.apply( document, arguments ); } } ); } }, /** * Update widget control to indicate whether it is currently rendered. * * Overrides api.Control.toggle() * * @since 4.1.0 * * @param {boolean} active * @param {Object} args * @param {function} args.completeCallback */ onChangeActive: function ( active, args ) { // Note: there is a second 'args' parameter being passed, merged on top of this.defaultActiveArguments. this.container.toggleClass( 'widget-rendered', active ); if ( args.completeCallback ) { args.completeCallback(); } }, /** * Set up event handlers for widget removal */ _setupRemoveUI: function() { var self = this, $removeBtn, replaceDeleteWithRemove; // Configure remove button. $removeBtn = this.container.find( '.widget-control-remove' ); $removeBtn.on( 'click', function() { // Find an adjacent element to add focus to when this widget goes away. var $adjacentFocusTarget; if ( self.container.next().is( '.customize-control-widget_form' ) ) { $adjacentFocusTarget = self.container.next().find( '.widget-action:first' ); } else if ( self.container.prev().is( '.customize-control-widget_form' ) ) { $adjacentFocusTarget = self.container.prev().find( '.widget-action:first' ); } else { $adjacentFocusTarget = self.container.next( '.customize-control-sidebar_widgets' ).find( '.add-new-widget:first' ); } self.container.slideUp( function() { var sidebarsWidgetsControl = api.Widgets.getSidebarWidgetControlContainingWidget( self.params.widget_id ), sidebarWidgetIds, i; if ( ! sidebarsWidgetsControl ) { return; } sidebarWidgetIds = sidebarsWidgetsControl.setting().slice(); i = _.indexOf( sidebarWidgetIds, self.params.widget_id ); if ( -1 === i ) { return; } sidebarWidgetIds.splice( i, 1 ); sidebarsWidgetsControl.setting( sidebarWidgetIds ); $adjacentFocusTarget.focus(); // Keyboard accessibility. } ); } ); replaceDeleteWithRemove = function() { $removeBtn.text( l10n.removeBtnLabel ); // wp_widget_control() outputs the button as "Delete". $removeBtn.attr( 'title', l10n.removeBtnTooltip ); }; if ( this.params.is_new ) { api.bind( 'saved', replaceDeleteWithRemove ); } else { replaceDeleteWithRemove(); } }, /** * Find all inputs in a widget container that should be considered when * comparing the loaded form with the sanitized form, whose fields will * be aligned to copy the sanitized over. The elements returned by this * are passed into this._getInputsSignature(), and they are iterated * over when copying sanitized values over to the form loaded. * * @param {jQuery} container element in which to look for inputs * @return {jQuery} inputs * @private */ _getInputs: function( container ) { return $( container ).find( ':input[name]' ); }, /** * Iterate over supplied inputs and create a signature string for all of them together. * This string can be used to compare whether or not the form has all of the same fields. * * @param {jQuery} inputs * @return {string} * @private */ _getInputsSignature: function( inputs ) { var inputsSignatures = _( inputs ).map( function( input ) { var $input = $( input ), signatureParts; if ( $input.is( ':checkbox, :radio' ) ) { signatureParts = [ $input.attr( 'id' ), $input.attr( 'name' ), $input.prop( 'value' ) ]; } else { signatureParts = [ $input.attr( 'id' ), $input.attr( 'name' ) ]; } return signatureParts.join( ',' ); } ); return inputsSignatures.join( ';' ); }, /** * Get the state for an input depending on its type. * * @param {jQuery|Element} input * @return {string|boolean|Array|*} * @private */ _getInputState: function( input ) { input = $( input ); if ( input.is( ':radio, :checkbox' ) ) { return input.prop( 'checked' ); } else if ( input.is( 'select[multiple]' ) ) { return input.find( 'option:selected' ).map( function () { return $( this ).val(); } ).get(); } else { return input.val(); } }, /** * Update an input's state based on its type. * * @param {jQuery|Element} input * @param {string|boolean|Array|*} state * @private */ _setInputState: function ( input, state ) { input = $( input ); if ( input.is( ':radio, :checkbox' ) ) { input.prop( 'checked', state ); } else if ( input.is( 'select[multiple]' ) ) { if ( ! Array.isArray( state ) ) { state = []; } else { // Make sure all state items are strings since the DOM value is a string. state = _.map( state, function ( value ) { return String( value ); } ); } input.find( 'option' ).each( function () { $( this ).prop( 'selected', -1 !== _.indexOf( state, String( this.value ) ) ); } ); } else { input.val( state ); } }, /*********************************************************************** * Begin public API methods **********************************************************************/ /** * @return {wp.customize.controlConstructor.sidebar_widgets[]} */ getSidebarWidgetsControl: function() { var settingId, sidebarWidgetsControl; settingId = 'sidebars_widgets[' + this.params.sidebar_id + ']'; sidebarWidgetsControl = api.control( settingId ); if ( ! sidebarWidgetsControl ) { return; } return sidebarWidgetsControl; }, /** * Submit the widget form via Ajax and get back the updated instance, * along with the new widget control form to render. * * @param {Object} [args] * @param {Object|null} [args.instance=null] When the model changes, the instance is sent here; otherwise, the inputs from the form are used * @param {Function|null} [args.complete=null] Function which is called when the request finishes. Context is bound to the control. First argument is any error. Following arguments are for success. * @param {boolean} [args.ignoreActiveElement=false] Whether or not updating a field will be deferred if focus is still on the element. */ updateWidget: function( args ) { var self = this, instanceOverride, completeCallback, $widgetRoot, $widgetContent, updateNumber, params, data, $inputs, processing, jqxhr, isChanged; // The updateWidget logic requires that the form fields to be fully present. self.embedWidgetContent(); args = $.extend( { instance: null, complete: null, ignoreActiveElement: false }, args ); instanceOverride = args.instance; completeCallback = args.complete; this._updateCount += 1; updateNumber = this._updateCount; $widgetRoot = this.container.find( '.widget:first' ); $widgetContent = $widgetRoot.find( '.widget-content:first' ); // Remove a previous error message. $widgetContent.find( '.widget-error' ).remove(); this.container.addClass( 'widget-form-loading' ); this.container.addClass( 'previewer-loading' ); processing = api.state( 'processing' ); processing( processing() + 1 ); if ( ! this.liveUpdateMode ) { this.container.addClass( 'widget-form-disabled' ); } params = {}; params.action = 'update-widget'; params.wp_customize = 'on'; params.nonce = api.settings.nonce['update-widget']; params.customize_theme = api.settings.theme.stylesheet; params.customized = wp.customize.previewer.query().customized; data = $.param( params ); $inputs = this._getInputs( $widgetContent ); /* * Store the value we're submitting in data so that when the response comes back, * we know if it got sanitized; if there is no difference in the sanitized value, * then we do not need to touch the UI and mess up the user's ongoing editing. */ $inputs.each( function() { $( this ).data( 'state' + updateNumber, self._getInputState( this ) ); } ); if ( instanceOverride ) { data += '&' + $.param( { 'sanitized_widget_setting': JSON.stringify( instanceOverride ) } ); } else { data += '&' + $inputs.serialize(); } data += '&' + $widgetContent.find( '~ :input' ).serialize(); if ( this._previousUpdateRequest ) { this._previousUpdateRequest.abort(); } jqxhr = $.post( wp.ajax.settings.url, data ); this._previousUpdateRequest = jqxhr; jqxhr.done( function( r ) { var message, sanitizedForm, $sanitizedInputs, hasSameInputsInResponse, isLiveUpdateAborted = false; // Check if the user is logged out. if ( '0' === r ) { api.previewer.preview.iframe.hide(); api.previewer.login().done( function() { self.updateWidget( args ); api.previewer.preview.iframe.show(); } ); return; } // Check for cheaters. if ( '-1' === r ) { api.previewer.cheatin(); return; } if ( r.success ) { sanitizedForm = $( '
' + r.data.form + '
' ); $sanitizedInputs = self._getInputs( sanitizedForm ); hasSameInputsInResponse = self._getInputsSignature( $inputs ) === self._getInputsSignature( $sanitizedInputs ); // Restore live update mode if sanitized fields are now aligned with the existing fields. if ( hasSameInputsInResponse && ! self.liveUpdateMode ) { self.liveUpdateMode = true; self.container.removeClass( 'widget-form-disabled' ); self.container.find( 'input[name="savewidget"]' ).hide(); } // Sync sanitized field states to existing fields if they are aligned. if ( hasSameInputsInResponse && self.liveUpdateMode ) { $inputs.each( function( i ) { var $input = $( this ), $sanitizedInput = $( $sanitizedInputs[i] ), submittedState, sanitizedState, canUpdateState; submittedState = $input.data( 'state' + updateNumber ); sanitizedState = self._getInputState( $sanitizedInput ); $input.data( 'sanitized', sanitizedState ); canUpdateState = ( ! _.isEqual( submittedState, sanitizedState ) && ( args.ignoreActiveElement || ! $input.is( document.activeElement ) ) ); if ( canUpdateState ) { self._setInputState( $input, sanitizedState ); } } ); $( document ).trigger( 'widget-synced', [ $widgetRoot, r.data.form ] ); // Otherwise, if sanitized fields are not aligned with existing fields, disable live update mode if enabled. } else if ( self.liveUpdateMode ) { self.liveUpdateMode = false; self.container.find( 'input[name="savewidget"]' ).show(); isLiveUpdateAborted = true; // Otherwise, replace existing form with the sanitized form. } else { $widgetContent.html( r.data.form ); self.container.removeClass( 'widget-form-disabled' ); $( document ).trigger( 'widget-updated', [ $widgetRoot ] ); } /** * If the old instance is identical to the new one, there is nothing new * needing to be rendered, and so we can preempt the event for the * preview finishing loading. */ isChanged = ! isLiveUpdateAborted && ! _( self.setting() ).isEqual( r.data.instance ); if ( isChanged ) { self.isWidgetUpdating = true; // Suppress triggering another updateWidget. self.setting( r.data.instance ); self.isWidgetUpdating = false; } else { // No change was made, so stop the spinner now instead of when the preview would updates. self.container.removeClass( 'previewer-loading' ); } if ( completeCallback ) { completeCallback.call( self, null, { noChange: ! isChanged, ajaxFinished: true } ); } } else { // General error message. message = l10n.error; if ( r.data && r.data.message ) { message = r.data.message; } if ( completeCallback ) { completeCallback.call( self, message ); } else { $widgetContent.prepend( '

' + message + '

' ); } } } ); jqxhr.fail( function( jqXHR, textStatus ) { if ( completeCallback ) { completeCallback.call( self, textStatus ); } } ); jqxhr.always( function() { self.container.removeClass( 'widget-form-loading' ); $inputs.each( function() { $( this ).removeData( 'state' + updateNumber ); } ); processing( processing() - 1 ); } ); }, /** * Expand the accordion section containing a control */ expandControlSection: function() { api.Control.prototype.expand.call( this ); }, /** * @since 4.1.0 * * @param {Boolean} expanded * @param {Object} [params] * @return {Boolean} False if state already applied. */ _toggleExpanded: api.Section.prototype._toggleExpanded, /** * @since 4.1.0 * * @param {Object} [params] * @return {Boolean} False if already expanded. */ expand: api.Section.prototype.expand, /** * Expand the widget form control * * @deprecated 4.1.0 Use this.expand() instead. */ expandForm: function() { this.expand(); }, /** * @since 4.1.0 * * @param {Object} [params] * @return {Boolean} False if already collapsed. */ collapse: api.Section.prototype.collapse, /** * Collapse the widget form control * * @deprecated 4.1.0 Use this.collapse() instead. */ collapseForm: function() { this.collapse(); }, /** * Expand or collapse the widget control * * @deprecated this is poor naming, and it is better to directly set control.expanded( showOrHide ) * * @param {boolean|undefined} [showOrHide] If not supplied, will be inverse of current visibility */ toggleForm: function( showOrHide ) { if ( typeof showOrHide === 'undefined' ) { showOrHide = ! this.expanded(); } this.expanded( showOrHide ); }, /** * Respond to change in the expanded state. * * @param {boolean} expanded * @param {Object} args merged on top of this.defaultActiveArguments */ onChangeExpanded: function ( expanded, args ) { var self = this, $widget, $inside, complete, prevComplete, expandControl, $toggleBtn; self.embedWidgetControl(); // Make sure the outer form is embedded so that the expanded state can be set in the UI. if ( expanded ) { self.embedWidgetContent(); } // If the expanded state is unchanged only manipulate container expanded states. if ( args.unchanged ) { if ( expanded ) { api.Control.prototype.expand.call( self, { completeCallback: args.completeCallback }); } return; } $widget = this.container.find( 'div.widget:first' ); $inside = $widget.find( '.widget-inside:first' ); $toggleBtn = this.container.find( '.widget-top button.widget-action' ); expandControl = function() { // Close all other widget controls before expanding this one. api.control.each( function( otherControl ) { if ( self.params.type === otherControl.params.type && self !== otherControl ) { otherControl.collapse(); } } ); complete = function() { self.container.removeClass( 'expanding' ); self.container.addClass( 'expanded' ); $widget.addClass( 'open' ); $toggleBtn.attr( 'aria-expanded', 'true' ); self.container.trigger( 'expanded' ); }; if ( args.completeCallback ) { prevComplete = complete; complete = function () { prevComplete(); args.completeCallback(); }; } if ( self.params.is_wide ) { $inside.fadeIn( args.duration, complete ); } else { $inside.slideDown( args.duration, complete ); } self.container.trigger( 'expand' ); self.container.addClass( 'expanding' ); }; if ( $toggleBtn.attr( 'aria-expanded' ) === 'false' ) { if ( api.section.has( self.section() ) ) { api.section( self.section() ).expand( { completeCallback: expandControl } ); } else { expandControl(); } } else { complete = function() { self.container.removeClass( 'collapsing' ); self.container.removeClass( 'expanded' ); $widget.removeClass( 'open' ); $toggleBtn.attr( 'aria-expanded', 'false' ); self.container.trigger( 'collapsed' ); }; if ( args.completeCallback ) { prevComplete = complete; complete = function () { prevComplete(); args.completeCallback(); }; } self.container.trigger( 'collapse' ); self.container.addClass( 'collapsing' ); if ( self.params.is_wide ) { $inside.fadeOut( args.duration, complete ); } else { $inside.slideUp( args.duration, function() { $widget.css( { width:'', margin:'' } ); complete(); } ); } } }, /** * Get the position (index) of the widget in the containing sidebar * * @return {number} */ getWidgetSidebarPosition: function() { var sidebarWidgetIds, position; sidebarWidgetIds = this.getSidebarWidgetsControl().setting(); position = _.indexOf( sidebarWidgetIds, this.params.widget_id ); if ( position === -1 ) { return; } return position; }, /** * Move widget up one in the sidebar */ moveUp: function() { this._moveWidgetByOne( -1 ); }, /** * Move widget up one in the sidebar */ moveDown: function() { this._moveWidgetByOne( 1 ); }, /** * @private * * @param {number} offset 1|-1 */ _moveWidgetByOne: function( offset ) { var i, sidebarWidgetsSetting, sidebarWidgetIds, adjacentWidgetId; i = this.getWidgetSidebarPosition(); sidebarWidgetsSetting = this.getSidebarWidgetsControl().setting; sidebarWidgetIds = Array.prototype.slice.call( sidebarWidgetsSetting() ); // Clone. adjacentWidgetId = sidebarWidgetIds[i + offset]; sidebarWidgetIds[i + offset] = this.params.widget_id; sidebarWidgetIds[i] = adjacentWidgetId; sidebarWidgetsSetting( sidebarWidgetIds ); }, /** * Toggle visibility of the widget move area * * @param {boolean} [showOrHide] */ toggleWidgetMoveArea: function( showOrHide ) { var self = this, $moveWidgetArea; $moveWidgetArea = this.container.find( '.move-widget-area' ); if ( typeof showOrHide === 'undefined' ) { showOrHide = ! $moveWidgetArea.hasClass( 'active' ); } if ( showOrHide ) { // Reset the selected sidebar. $moveWidgetArea.find( '.selected' ).removeClass( 'selected' ); $moveWidgetArea.find( 'li' ).filter( function() { return $( this ).data( 'id' ) === self.params.sidebar_id; } ).addClass( 'selected' ); this.container.find( '.move-widget-btn' ).prop( 'disabled', true ); } $moveWidgetArea.toggleClass( 'active', showOrHide ); }, /** * Highlight the widget control and section */ highlightSectionAndControl: function() { var $target; if ( this.container.is( ':hidden' ) ) { $target = this.container.closest( '.control-section' ); } else { $target = this.container; } $( '.highlighted' ).removeClass( 'highlighted' ); $target.addClass( 'highlighted' ); setTimeout( function() { $target.removeClass( 'highlighted' ); }, 500 ); } } ); /** * wp.customize.Widgets.WidgetsPanel * * Customizer panel containing the widget area sections. * * @since 4.4.0 * * @class wp.customize.Widgets.WidgetsPanel * @augments wp.customize.Panel */ api.Widgets.WidgetsPanel = api.Panel.extend(/** @lends wp.customize.Widgets.WigetsPanel.prototype */{ /** * Add and manage the display of the no-rendered-areas notice. * * @since 4.4.0 */ ready: function () { var panel = this; api.Panel.prototype.ready.call( panel ); panel.deferred.embedded.done(function() { var panelMetaContainer, noticeContainer, updateNotice, getActiveSectionCount, shouldShowNotice; panelMetaContainer = panel.container.find( '.panel-meta' ); // @todo This should use the Notifications API introduced to panels. See . noticeContainer = $( '
', { 'class': 'no-widget-areas-rendered-notice', 'role': 'alert' }); panelMetaContainer.append( noticeContainer ); /** * Get the number of active sections in the panel. * * @return {number} Number of active sidebar sections. */ getActiveSectionCount = function() { return _.filter( panel.sections(), function( section ) { return 'sidebar' === section.params.type && section.active(); } ).length; }; /** * Determine whether or not the notice should be displayed. * * @return {boolean} */ shouldShowNotice = function() { var activeSectionCount = getActiveSectionCount(); if ( 0 === activeSectionCount ) { return true; } else { return activeSectionCount !== api.Widgets.data.registeredSidebars.length; } }; /** * Update the notice. * * @return {void} */ updateNotice = function() { var activeSectionCount = getActiveSectionCount(), someRenderedMessage, nonRenderedAreaCount, registeredAreaCount; noticeContainer.empty(); registeredAreaCount = api.Widgets.data.registeredSidebars.length; if ( activeSectionCount !== registeredAreaCount ) { if ( 0 !== activeSectionCount ) { nonRenderedAreaCount = registeredAreaCount - activeSectionCount; someRenderedMessage = l10n.someAreasShown[ nonRenderedAreaCount ]; } else { someRenderedMessage = l10n.noAreasShown; } if ( someRenderedMessage ) { noticeContainer.append( $( '

', { text: someRenderedMessage } ) ); } noticeContainer.append( $( '

', { text: l10n.navigatePreview } ) ); } }; updateNotice(); /* * Set the initial visibility state for rendered notice. * Update the visibility of the notice whenever a reflow happens. */ noticeContainer.toggle( shouldShowNotice() ); api.previewer.deferred.active.done( function () { noticeContainer.toggle( shouldShowNotice() ); }); api.bind( 'pane-contents-reflowed', function() { var duration = ( 'resolved' === api.previewer.deferred.active.state() ) ? 'fast' : 0; updateNotice(); if ( shouldShowNotice() ) { noticeContainer.slideDown( duration ); } else { noticeContainer.slideUp( duration ); } }); }); }, /** * Allow an active widgets panel to be contextually active even when it has no active sections (widget areas). * * This ensures that the widgets panel appears even when there are no * sidebars displayed on the URL currently being previewed. * * @since 4.4.0 * * @return {boolean} */ isContextuallyActive: function() { var panel = this; return panel.active(); } }); /** * wp.customize.Widgets.SidebarSection * * Customizer section representing a widget area widget * * @since 4.1.0 * * @class wp.customize.Widgets.SidebarSection * @augments wp.customize.Section */ api.Widgets.SidebarSection = api.Section.extend(/** @lends wp.customize.Widgets.SidebarSection.prototype */{ /** * Sync the section's active state back to the Backbone model's is_rendered attribute * * @since 4.1.0 */ ready: function () { var section = this, registeredSidebar; api.Section.prototype.ready.call( this ); registeredSidebar = api.Widgets.registeredSidebars.get( section.params.sidebarId ); section.active.bind( function ( active ) { registeredSidebar.set( 'is_rendered', active ); }); registeredSidebar.set( 'is_rendered', section.active() ); } }); /** * wp.customize.Widgets.SidebarControl * * Customizer control for widgets. * Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type * * @since 3.9.0 * * @class wp.customize.Widgets.SidebarControl * @augments wp.customize.Control */ api.Widgets.SidebarControl = api.Control.extend(/** @lends wp.customize.Widgets.SidebarControl.prototype */{ /** * Set up the control */ ready: function() { this.$controlSection = this.container.closest( '.control-section' ); this.$sectionContent = this.container.closest( '.accordion-section-content' ); this._setupModel(); this._setupSortable(); this._setupAddition(); this._applyCardinalOrderClassNames(); }, /** * Update ordering of widget control forms when the setting is updated */ _setupModel: function() { var self = this; this.setting.bind( function( newWidgetIds, oldWidgetIds ) { var widgetFormControls, removedWidgetIds, priority; removedWidgetIds = _( oldWidgetIds ).difference( newWidgetIds ); // Filter out any persistent widget IDs for widgets which have been deactivated. newWidgetIds = _( newWidgetIds ).filter( function( newWidgetId ) { var parsedWidgetId = parseWidgetId( newWidgetId ); return !! api.Widgets.availableWidgets.findWhere( { id_base: parsedWidgetId.id_base } ); } ); widgetFormControls = _( newWidgetIds ).map( function( widgetId ) { var widgetFormControl = api.Widgets.getWidgetFormControlForWidget( widgetId ); if ( ! widgetFormControl ) { widgetFormControl = self.addWidget( widgetId ); } return widgetFormControl; } ); // Sort widget controls to their new positions. widgetFormControls.sort( function( a, b ) { var aIndex = _.indexOf( newWidgetIds, a.params.widget_id ), bIndex = _.indexOf( newWidgetIds, b.params.widget_id ); return aIndex - bIndex; }); priority = 0; _( widgetFormControls ).each( function ( control ) { control.priority( priority ); control.section( self.section() ); priority += 1; }); self.priority( priority ); // Make sure sidebar control remains at end. // Re-sort widget form controls (including widgets form other sidebars newly moved here). self._applyCardinalOrderClassNames(); // If the widget was dragged into the sidebar, make sure the sidebar_id param is updated. _( widgetFormControls ).each( function( widgetFormControl ) { widgetFormControl.params.sidebar_id = self.params.sidebar_id; } ); // Cleanup after widget removal. _( removedWidgetIds ).each( function( removedWidgetId ) { // Using setTimeout so that when moving a widget to another sidebar, // the other sidebars_widgets settings get a chance to update. setTimeout( function() { var removedControl, wasDraggedToAnotherSidebar, inactiveWidgets, removedIdBase, widget, isPresentInAnotherSidebar = false; // Check if the widget is in another sidebar. api.each( function( otherSetting ) { if ( otherSetting.id === self.setting.id || 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) || otherSetting.id === 'sidebars_widgets[wp_inactive_widgets]' ) { return; } var otherSidebarWidgets = otherSetting(), i; i = _.indexOf( otherSidebarWidgets, removedWidgetId ); if ( -1 !== i ) { isPresentInAnotherSidebar = true; } } ); // If the widget is present in another sidebar, abort! if ( isPresentInAnotherSidebar ) { return; } removedControl = api.Widgets.getWidgetFormControlForWidget( removedWidgetId ); // Detect if widget control was dragged to another sidebar. wasDraggedToAnotherSidebar = removedControl && $.contains( document, removedControl.container[0] ) && ! $.contains( self.$sectionContent[0], removedControl.container[0] ); // Delete any widget form controls for removed widgets. if ( removedControl && ! wasDraggedToAnotherSidebar ) { api.control.remove( removedControl.id ); removedControl.container.remove(); } // Move widget to inactive widgets sidebar (move it to Trash) if has been previously saved. // This prevents the inactive widgets sidebar from overflowing with throwaway widgets. if ( api.Widgets.savedWidgetIds[removedWidgetId] ) { inactiveWidgets = api.value( 'sidebars_widgets[wp_inactive_widgets]' )().slice(); inactiveWidgets.push( removedWidgetId ); api.value( 'sidebars_widgets[wp_inactive_widgets]' )( _( inactiveWidgets ).unique() ); } // Make old single widget available for adding again. removedIdBase = parseWidgetId( removedWidgetId ).id_base; widget = api.Widgets.availableWidgets.findWhere( { id_base: removedIdBase } ); if ( widget && ! widget.get( 'is_multi' ) ) { widget.set( 'is_disabled', false ); } } ); } ); } ); }, /** * Allow widgets in sidebar to be re-ordered, and for the order to be previewed */ _setupSortable: function() { var self = this; this.isReordering = false; /** * Update widget order setting when controls are re-ordered */ this.$sectionContent.sortable( { items: '> .customize-control-widget_form', handle: '.widget-top', axis: 'y', tolerance: 'pointer', connectWith: '.accordion-section-content:has(.customize-control-sidebar_widgets)', update: function() { var widgetContainerIds = self.$sectionContent.sortable( 'toArray' ), widgetIds; widgetIds = $.map( widgetContainerIds, function( widgetContainerId ) { return $( '#' + widgetContainerId ).find( ':input[name=widget-id]' ).val(); } ); self.setting( widgetIds ); } } ); /** * Expand other Customizer sidebar section when dragging a control widget over it, * allowing the control to be dropped into another section */ this.$controlSection.find( '.accordion-section-title' ).droppable({ accept: '.customize-control-widget_form', over: function() { var section = api.section( self.section.get() ); section.expand({ allowMultiple: true, // Prevent the section being dragged from to be collapsed. completeCallback: function () { // @todo It is not clear when refreshPositions should be called on which sections, or if it is even needed. api.section.each( function ( otherSection ) { if ( otherSection.container.find( '.customize-control-sidebar_widgets' ).length ) { otherSection.container.find( '.accordion-section-content:first' ).sortable( 'refreshPositions' ); } } ); } }); } }); /** * Keyboard-accessible reordering */ this.container.find( '.reorder-toggle' ).on( 'click', function() { self.toggleReordering( ! self.isReordering ); } ); }, /** * Set up UI for adding a new widget */ _setupAddition: function() { var self = this; this.container.find( '.add-new-widget' ).on( 'click', function() { var addNewWidgetBtn = $( this ); if ( self.$sectionContent.hasClass( 'reordering' ) ) { return; } if ( ! $( 'body' ).hasClass( 'adding-widget' ) ) { addNewWidgetBtn.attr( 'aria-expanded', 'true' ); api.Widgets.availableWidgetsPanel.open( self ); } else { addNewWidgetBtn.attr( 'aria-expanded', 'false' ); api.Widgets.availableWidgetsPanel.close(); } } ); }, /** * Add classes to the widget_form controls to assist with styling */ _applyCardinalOrderClassNames: function() { var widgetControls = []; _.each( this.setting(), function ( widgetId ) { var widgetControl = api.Widgets.getWidgetFormControlForWidget( widgetId ); if ( widgetControl ) { widgetControls.push( widgetControl ); } }); if ( 0 === widgetControls.length || ( 1 === api.Widgets.registeredSidebars.length && widgetControls.length <= 1 ) ) { this.container.find( '.reorder-toggle' ).hide(); return; } else { this.container.find( '.reorder-toggle' ).show(); } $( widgetControls ).each( function () { $( this.container ) .removeClass( 'first-widget' ) .removeClass( 'last-widget' ) .find( '.move-widget-down, .move-widget-up' ).prop( 'tabIndex', 0 ); }); _.first( widgetControls ).container .addClass( 'first-widget' ) .find( '.move-widget-up' ).prop( 'tabIndex', -1 ); _.last( widgetControls ).container .addClass( 'last-widget' ) .find( '.move-widget-down' ).prop( 'tabIndex', -1 ); }, /*********************************************************************** * Begin public API methods **********************************************************************/ /** * Enable/disable the reordering UI * * @param {boolean} showOrHide to enable/disable reordering * * @todo We should have a reordering state instead and rename this to onChangeReordering */ toggleReordering: function( showOrHide ) { var addNewWidgetBtn = this.$sectionContent.find( '.add-new-widget' ), reorderBtn = this.container.find( '.reorder-toggle' ), widgetsTitle = this.$sectionContent.find( '.widget-title' ); showOrHide = Boolean( showOrHide ); if ( showOrHide === this.$sectionContent.hasClass( 'reordering' ) ) { return; } this.isReordering = showOrHide; this.$sectionContent.toggleClass( 'reordering', showOrHide ); if ( showOrHide ) { _( this.getWidgetFormControls() ).each( function( formControl ) { formControl.collapse(); } ); addNewWidgetBtn.attr({ 'tabindex': '-1', 'aria-hidden': 'true' }); reorderBtn.attr( 'aria-label', l10n.reorderLabelOff ); wp.a11y.speak( l10n.reorderModeOn ); // Hide widget titles while reordering: title is already in the reorder controls. widgetsTitle.attr( 'aria-hidden', 'true' ); } else { addNewWidgetBtn.removeAttr( 'tabindex aria-hidden' ); reorderBtn.attr( 'aria-label', l10n.reorderLabelOn ); wp.a11y.speak( l10n.reorderModeOff ); widgetsTitle.attr( 'aria-hidden', 'false' ); } }, /** * Get the widget_form Customize controls associated with the current sidebar. * * @since 3.9.0 * @return {wp.customize.controlConstructor.widget_form[]} */ getWidgetFormControls: function() { var formControls = []; _( this.setting() ).each( function( widgetId ) { var settingId = widgetIdToSettingId( widgetId ), formControl = api.control( settingId ); if ( formControl ) { formControls.push( formControl ); } } ); return formControls; }, /** * @param {string} widgetId or an id_base for adding a previously non-existing widget. * @return {Object|false} widget_form control instance, or false on error. */ addWidget: function( widgetId ) { var self = this, controlHtml, $widget, controlType = 'widget_form', controlContainer, controlConstructor, parsedWidgetId = parseWidgetId( widgetId ), widgetNumber = parsedWidgetId.number, widgetIdBase = parsedWidgetId.id_base, widget = api.Widgets.availableWidgets.findWhere( {id_base: widgetIdBase} ), settingId, isExistingWidget, widgetFormControl, sidebarWidgets, settingArgs, setting; if ( ! widget ) { return false; } if ( widgetNumber && ! widget.get( 'is_multi' ) ) { return false; } // Set up new multi widget. if ( widget.get( 'is_multi' ) && ! widgetNumber ) { widget.set( 'multi_number', widget.get( 'multi_number' ) + 1 ); widgetNumber = widget.get( 'multi_number' ); } controlHtml = $( '#widget-tpl-' + widget.get( 'id' ) ).html().trim(); if ( widget.get( 'is_multi' ) ) { controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) { return m.replace( /__i__|%i%/g, widgetNumber ); } ); } else { widget.set( 'is_disabled', true ); // Prevent single widget from being added again now. } $widget = $( controlHtml ); controlContainer = $( '
  • ' ) .addClass( 'customize-control' ) .addClass( 'customize-control-' + controlType ) .append( $widget ); // Remove icon which is visible inside the panel. controlContainer.find( '> .widget-icon' ).remove(); if ( widget.get( 'is_multi' ) ) { controlContainer.find( 'input[name="widget_number"]' ).val( widgetNumber ); controlContainer.find( 'input[name="multi_number"]' ).val( widgetNumber ); } widgetId = controlContainer.find( '[name="widget-id"]' ).val(); controlContainer.hide(); // To be slid-down below. settingId = 'widget_' + widget.get( 'id_base' ); if ( widget.get( 'is_multi' ) ) { settingId += '[' + widgetNumber + ']'; } controlContainer.attr( 'id', 'customize-control-' + settingId.replace( /\]/g, '' ).replace( /\[/g, '-' ) ); // Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget). isExistingWidget = api.has( settingId ); if ( ! isExistingWidget ) { settingArgs = { transport: api.Widgets.data.selectiveRefreshableWidgets[ widget.get( 'id_base' ) ] ? 'postMessage' : 'refresh', previewer: this.setting.previewer }; setting = api.create( settingId, settingId, '', settingArgs ); setting.set( {} ); // Mark dirty, changing from '' to {}. } controlConstructor = api.controlConstructor[controlType]; widgetFormControl = new controlConstructor( settingId, { settings: { 'default': settingId }, content: controlContainer, sidebar_id: self.params.sidebar_id, widget_id: widgetId, widget_id_base: widget.get( 'id_base' ), type: controlType, is_new: ! isExistingWidget, width: widget.get( 'width' ), height: widget.get( 'height' ), is_wide: widget.get( 'is_wide' ) } ); api.control.add( widgetFormControl ); // Make sure widget is removed from the other sidebars. api.each( function( otherSetting ) { if ( otherSetting.id === self.setting.id ) { return; } if ( 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) ) { return; } var otherSidebarWidgets = otherSetting().slice(), i = _.indexOf( otherSidebarWidgets, widgetId ); if ( -1 !== i ) { otherSidebarWidgets.splice( i ); otherSetting( otherSidebarWidgets ); } } ); // Add widget to this sidebar. sidebarWidgets = this.setting().slice(); if ( -1 === _.indexOf( sidebarWidgets, widgetId ) ) { sidebarWidgets.push( widgetId ); this.setting( sidebarWidgets ); } controlContainer.slideDown( function() { if ( isExistingWidget ) { widgetFormControl.updateWidget( { instance: widgetFormControl.setting() } ); } } ); return widgetFormControl; } } ); // Register models for custom panel, section, and control types. $.extend( api.panelConstructor, { widgets: api.Widgets.WidgetsPanel }); $.extend( api.sectionConstructor, { sidebar: api.Widgets.SidebarSection }); $.extend( api.controlConstructor, { widget_form: api.Widgets.WidgetControl, sidebar_widgets: api.Widgets.SidebarControl }); /** * Init Customizer for widgets. */ api.bind( 'ready', function() { // Set up the widgets panel. api.Widgets.availableWidgetsPanel = new api.Widgets.AvailableWidgetsPanelView({ collection: api.Widgets.availableWidgets }); // Highlight widget control. api.previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl ); // Open and focus widget control. api.previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl ); } ); /** * Highlight a widget control. * * @param {string} widgetId */ api.Widgets.highlightWidgetFormControl = function( widgetId ) { var control = api.Widgets.getWidgetFormControlForWidget( widgetId ); if ( control ) { control.highlightSectionAndControl(); } }, /** * Focus a widget control. * * @param {string} widgetId */ api.Widgets.focusWidgetFormControl = function( widgetId ) { var control = api.Widgets.getWidgetFormControlForWidget( widgetId ); if ( control ) { control.focus(); } }, /** * Given a widget control, find the sidebar widgets control that contains it. * @param {string} widgetId * @return {Object|null} */ api.Widgets.getSidebarWidgetControlContainingWidget = function( widgetId ) { var foundControl = null; // @todo This can use widgetIdToSettingId(), then pass into wp.customize.control( x ).getSidebarWidgetsControl(). api.control.each( function( control ) { if ( control.params.type === 'sidebar_widgets' && -1 !== _.indexOf( control.setting(), widgetId ) ) { foundControl = control; } } ); return foundControl; }; /** * Given a widget ID for a widget appearing in the preview, get the widget form control associated with it. * * @param {string} widgetId * @return {Object|null} */ api.Widgets.getWidgetFormControlForWidget = function( widgetId ) { var foundControl = null; // @todo We can just use widgetIdToSettingId() here. api.control.each( function( control ) { if ( control.params.type === 'widget_form' && control.params.widget_id === widgetId ) { foundControl = control; } } ); return foundControl; }; /** * Initialize Edit Menu button in Nav Menu widget. */ $( document ).on( 'widget-added', function( event, widgetContainer ) { var parsedWidgetId, widgetControl, navMenuSelect, editMenuButton; parsedWidgetId = parseWidgetId( widgetContainer.find( '> .widget-inside > .form > .widget-id' ).val() ); if ( 'nav_menu' !== parsedWidgetId.id_base ) { return; } widgetControl = api.control( 'widget_nav_menu[' + String( parsedWidgetId.number ) + ']' ); if ( ! widgetControl ) { return; } navMenuSelect = widgetContainer.find( 'select[name*="nav_menu"]' ); editMenuButton = widgetContainer.find( '.edit-selected-nav-menu > button' ); if ( 0 === navMenuSelect.length || 0 === editMenuButton.length ) { return; } navMenuSelect.on( 'change', function() { if ( api.section.has( 'nav_menu[' + navMenuSelect.val() + ']' ) ) { editMenuButton.parent().show(); } else { editMenuButton.parent().hide(); } }); editMenuButton.on( 'click', function() { var section = api.section( 'nav_menu[' + navMenuSelect.val() + ']' ); if ( section ) { focusConstructWithBreadcrumb( section, widgetControl ); } } ); } ); /** * Focus (expand) one construct and then focus on another construct after the first is collapsed. * * This overrides the back button to serve the purpose of breadcrumb navigation. * * @param {wp.customize.Section|wp.customize.Panel|wp.customize.Control} focusConstruct - The object to initially focus. * @param {wp.customize.Section|wp.customize.Panel|wp.customize.Control} returnConstruct - The object to return focus. */ function focusConstructWithBreadcrumb( focusConstruct, returnConstruct ) { focusConstruct.focus(); function onceCollapsed( isExpanded ) { if ( ! isExpanded ) { focusConstruct.expanded.unbind( onceCollapsed ); returnConstruct.focus(); } } focusConstruct.expanded.bind( onceCollapsed ); } /** * @param {string} widgetId * @return {Object} */ function parseWidgetId( widgetId ) { var matches, parsed = { number: null, id_base: null }; matches = widgetId.match( /^(.+)-(\d+)$/ ); if ( matches ) { parsed.id_base = matches[1]; parsed.number = parseInt( matches[2], 10 ); } else { // Likely an old single widget. parsed.id_base = widgetId; } return parsed; } /** * @param {string} widgetId * @return {string} settingId */ function widgetIdToSettingId( widgetId ) { var parsed = parseWidgetId( widgetId ), settingId; settingId = 'widget_' + parsed.id_base; if ( parsed.number ) { settingId += '[' + parsed.number + ']'; } return settingId; } })( window.wp, jQuery ); PK!b_44site-health.jsnu[/** * Interactions used by the Site Health modules in WordPress. * * @output wp-admin/js/site-health.js */ /* global ajaxurl, ClipboardJS, SiteHealth, wp */ jQuery( function( $ ) { var __ = wp.i18n.__, _n = wp.i18n._n, sprintf = wp.i18n.sprintf, clipboard = new ClipboardJS( '.site-health-copy-buttons .copy-button' ), isStatusTab = $( '.health-check-body.health-check-status-tab' ).length, isDebugTab = $( '.health-check-body.health-check-debug-tab' ).length, pathsSizesSection = $( '#health-check-accordion-block-wp-paths-sizes' ), menuCounterWrapper = $( '#adminmenu .site-health-counter' ), menuCounter = $( '#adminmenu .site-health-counter .count' ), successTimeout; // Debug information copy section. clipboard.on( 'success', function( e ) { var triggerElement = $( e.trigger ), successElement = $( '.success', triggerElement.closest( 'div' ) ); // Clear the selection and move focus back to the trigger. e.clearSelection(); // Show success visual feedback. clearTimeout( successTimeout ); successElement.removeClass( 'hidden' ); // Hide success visual feedback after 3 seconds since last success. successTimeout = setTimeout( function() { successElement.addClass( 'hidden' ); }, 3000 ); // Handle success audible feedback. wp.a11y.speak( __( 'Site information has been copied to your clipboard.' ) ); } ); // Accordion handling in various areas. $( '.health-check-accordion' ).on( 'click', '.health-check-accordion-trigger', function() { var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) ); if ( isExpanded ) { $( this ).attr( 'aria-expanded', 'false' ); $( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true ); } else { $( this ).attr( 'aria-expanded', 'true' ); $( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false ); } } ); // Site Health test handling. $( '.site-health-view-passed' ).on( 'click', function() { var goodIssuesWrapper = $( '#health-check-issues-good' ); goodIssuesWrapper.toggleClass( 'hidden' ); $( this ).attr( 'aria-expanded', ! goodIssuesWrapper.hasClass( 'hidden' ) ); } ); /** * Validates the Site Health test result format. * * @since 5.6.0 * * @param {Object} issue * * @return {boolean} */ function validateIssueData( issue ) { // Expected minimum format of a valid SiteHealth test response. var minimumExpected = { test: 'string', label: 'string', description: 'string' }, passed = true, key, value, subKey, subValue; // If the issue passed is not an object, return a `false` state early. if ( 'object' !== typeof( issue ) ) { return false; } // Loop over expected data and match the data types. for ( key in minimumExpected ) { value = minimumExpected[ key ]; if ( 'object' === typeof( value ) ) { for ( subKey in value ) { subValue = value[ subKey ]; if ( 'undefined' === typeof( issue[ key ] ) || 'undefined' === typeof( issue[ key ][ subKey ] ) || subValue !== typeof( issue[ key ][ subKey ] ) ) { passed = false; } } } else { if ( 'undefined' === typeof( issue[ key ] ) || value !== typeof( issue[ key ] ) ) { passed = false; } } } return passed; } /** * Appends a new issue to the issue list. * * @since 5.2.0 * * @param {Object} issue The issue data. */ function appendIssue( issue ) { var template = wp.template( 'health-check-issue' ), issueWrapper = $( '#health-check-issues-' + issue.status ), heading, count; /* * Validate the issue data format before using it. * If the output is invalid, discard it. */ if ( ! validateIssueData( issue ) ) { return false; } SiteHealth.site_status.issues[ issue.status ]++; count = SiteHealth.site_status.issues[ issue.status ]; // If no test name is supplied, append a placeholder for markup references. if ( typeof issue.test === 'undefined' ) { issue.test = issue.status + count; } if ( 'critical' === issue.status ) { heading = sprintf( _n( '%s critical issue', '%s critical issues', count ), '' + count + '' ); } else if ( 'recommended' === issue.status ) { heading = sprintf( _n( '%s recommended improvement', '%s recommended improvements', count ), '' + count + '' ); } else if ( 'good' === issue.status ) { heading = sprintf( _n( '%s item with no issues detected', '%s items with no issues detected', count ), '' + count + '' ); } if ( heading ) { $( '.site-health-issue-count-title', issueWrapper ).html( heading ); } menuCounter.text( SiteHealth.site_status.issues.critical ); if ( 0 < parseInt( SiteHealth.site_status.issues.critical, 0 ) ) { $( '#health-check-issues-critical' ).removeClass( 'hidden' ); menuCounterWrapper.removeClass( 'count-0' ); } else { menuCounterWrapper.addClass( 'count-0' ); } if ( 0 < parseInt( SiteHealth.site_status.issues.recommended, 0 ) ) { $( '#health-check-issues-recommended' ).removeClass( 'hidden' ); } $( '.issues', '#health-check-issues-' + issue.status ).append( template( issue ) ); } /** * Updates site health status indicator as asynchronous tests are run and returned. * * @since 5.2.0 */ function recalculateProgression() { var r, c, pct; var $progress = $( '.site-health-progress' ); var $wrapper = $progress.closest( '.site-health-progress-wrapper' ); var $progressLabel = $( '.site-health-progress-label', $wrapper ); var $circle = $( '.site-health-progress svg #bar' ); var totalTests = parseInt( SiteHealth.site_status.issues.good, 0 ) + parseInt( SiteHealth.site_status.issues.recommended, 0 ) + ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 ); var failedTests = ( parseInt( SiteHealth.site_status.issues.recommended, 0 ) * 0.5 ) + ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 ); var val = 100 - Math.ceil( ( failedTests / totalTests ) * 100 ); if ( 0 === totalTests ) { $progress.addClass( 'hidden' ); return; } $wrapper.removeClass( 'loading' ); r = $circle.attr( 'r' ); c = Math.PI * ( r * 2 ); if ( 0 > val ) { val = 0; } if ( 100 < val ) { val = 100; } pct = ( ( 100 - val ) / 100 ) * c + 'px'; $circle.css( { strokeDashoffset: pct } ); if ( 80 <= val && 0 === parseInt( SiteHealth.site_status.issues.critical, 0 ) ) { $wrapper.addClass( 'green' ).removeClass( 'orange' ); $progressLabel.text( __( 'Good' ) ); announceTestsProgression( 'good' ); } else { $wrapper.addClass( 'orange' ).removeClass( 'green' ); $progressLabel.text( __( 'Should be improved' ) ); announceTestsProgression( 'improvable' ); } if ( isStatusTab ) { $.post( ajaxurl, { 'action': 'health-check-site-status-result', '_wpnonce': SiteHealth.nonce.site_status_result, 'counts': SiteHealth.site_status.issues } ); if ( 100 === val ) { $( '.site-status-all-clear' ).removeClass( 'hide' ); $( '.site-status-has-issues' ).addClass( 'hide' ); } } } /** * Queues the next asynchronous test when we're ready to run it. * * @since 5.2.0 */ function maybeRunNextAsyncTest() { var doCalculation = true; if ( 1 <= SiteHealth.site_status.async.length ) { $.each( SiteHealth.site_status.async, function() { var data = { 'action': 'health-check-' + this.test.replace( '_', '-' ), '_wpnonce': SiteHealth.nonce.site_status }; if ( this.completed ) { return true; } doCalculation = false; this.completed = true; if ( 'undefined' !== typeof( this.has_rest ) && this.has_rest ) { wp.apiRequest( { url: wp.url.addQueryArgs( this.test, { _locale: 'user' } ), headers: this.headers } ) .done( function( response ) { /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ appendIssue( wp.hooks.applyFilters( 'site_status_test_result', response ) ); } ) .fail( function( response ) { var description; if ( 'undefined' !== typeof( response.responseJSON ) && 'undefined' !== typeof( response.responseJSON.message ) ) { description = response.responseJSON.message; } else { description = __( 'No details available' ); } addFailedSiteHealthCheckNotice( this.url, description ); } ) .always( function() { maybeRunNextAsyncTest(); } ); } else { $.post( ajaxurl, data ).done( function( response ) { /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ appendIssue( wp.hooks.applyFilters( 'site_status_test_result', response.data ) ); } ).fail( function( response ) { var description; if ( 'undefined' !== typeof( response.responseJSON ) && 'undefined' !== typeof( response.responseJSON.message ) ) { description = response.responseJSON.message; } else { description = __( 'No details available' ); } addFailedSiteHealthCheckNotice( this.url, description ); } ).always( function() { maybeRunNextAsyncTest(); } ); } return false; } ); } if ( doCalculation ) { recalculateProgression(); } } /** * Add the details of a failed asynchronous test to the list of test results. * * @since 5.6.0 */ function addFailedSiteHealthCheckNotice( url, description ) { var issue; issue = { 'status': 'recommended', 'label': __( 'A test is unavailable' ), 'badge': { 'color': 'red', 'label': __( 'Unavailable' ) }, 'description': '

    ' + url + '

    ' + description + '

    ', 'actions': '' }; /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ appendIssue( wp.hooks.applyFilters( 'site_status_test_result', issue ) ); } if ( 'undefined' !== typeof SiteHealth ) { if ( 0 === SiteHealth.site_status.direct.length && 0 === SiteHealth.site_status.async.length ) { recalculateProgression(); } else { SiteHealth.site_status.issues = { 'good': 0, 'recommended': 0, 'critical': 0 }; } if ( 0 < SiteHealth.site_status.direct.length ) { $.each( SiteHealth.site_status.direct, function() { appendIssue( this ); } ); } if ( 0 < SiteHealth.site_status.async.length ) { maybeRunNextAsyncTest(); } else { recalculateProgression(); } } function getDirectorySizes() { var timestamp = ( new Date().getTime() ); // After 3 seconds announce that we're still waiting for directory sizes. var timeout = window.setTimeout( function() { announceTestsProgression( 'waiting-for-directory-sizes' ); }, 3000 ); wp.apiRequest( { path: '/wp-site-health/v1/directory-sizes' } ).done( function( response ) { updateDirSizes( response || {} ); } ).always( function() { var delay = ( new Date().getTime() ) - timestamp; $( '.health-check-wp-paths-sizes.spinner' ).css( 'visibility', 'hidden' ); if ( delay > 3000 ) { /* * We have announced that we're waiting. * Announce that we're ready after giving at least 3 seconds * for the first announcement to be read out, or the two may collide. */ if ( delay > 6000 ) { delay = 0; } else { delay = 6500 - delay; } window.setTimeout( function() { recalculateProgression(); }, delay ); } else { // Cancel the announcement. window.clearTimeout( timeout ); } $( document ).trigger( 'site-health-info-dirsizes-done' ); } ); } function updateDirSizes( data ) { var copyButton = $( 'button.button.copy-button' ); var clipboardText = copyButton.attr( 'data-clipboard-text' ); $.each( data, function( name, value ) { var text = value.debug || value.size; if ( typeof text !== 'undefined' ) { clipboardText = clipboardText.replace( name + ': loading...', name + ': ' + text ); } } ); copyButton.attr( 'data-clipboard-text', clipboardText ); pathsSizesSection.find( 'td[class]' ).each( function( i, element ) { var td = $( element ); var name = td.attr( 'class' ); if ( data.hasOwnProperty( name ) && data[ name ].size ) { td.text( data[ name ].size ); } } ); } if ( isDebugTab ) { if ( pathsSizesSection.length ) { getDirectorySizes(); } else { recalculateProgression(); } } // Trigger a class toggle when the extended menu button is clicked. $( '.health-check-offscreen-nav-wrapper' ).on( 'click', function() { $( this ).toggleClass( 'visible' ); } ); /** * Announces to assistive technologies the tests progression status. * * @since 6.4.0 * * @param {string} type The type of message to be announced. * * @return {void} */ function announceTestsProgression( type ) { // Only announce the messages in the Site Health pages. if ( 'site-health' !== SiteHealth.screen ) { return; } switch ( type ) { case 'good': wp.a11y.speak( __( 'All site health tests have finished running. Your site is looking good.' ) ); break; case 'improvable': wp.a11y.speak( __( 'All site health tests have finished running. There are items that should be addressed.' ) ); break; case 'waiting-for-directory-sizes': wp.a11y.speak( __( 'Running additional tests... please wait.' ) ); break; default: return; } } } ); PK!/mmmedia.jsnu[/** * Creates a dialog containing posts that can have a particular media attached * to it. * * @since 2.7.0 * @output wp-admin/js/media.js * * @namespace findPosts * * @requires jQuery */ /* global ajaxurl, _wpMediaGridSettings, showNotice, findPosts, ClipboardJS */ ( function( $ ){ window.findPosts = { /** * Opens a dialog to attach media to a post. * * Adds an overlay prior to retrieving a list of posts to attach the media to. * * @since 2.7.0 * * @memberOf findPosts * * @param {string} af_name The name of the affected element. * @param {string} af_val The value of the affected post element. * * @return {boolean} Always returns false. */ open: function( af_name, af_val ) { var overlay = $( '.ui-find-overlay' ); if ( overlay.length === 0 ) { $( 'body' ).append( '
    ' ); findPosts.overlay(); } overlay.show(); if ( af_name && af_val ) { // #affected is a hidden input field in the dialog that keeps track of which media should be attached. $( '#affected' ).attr( 'name', af_name ).val( af_val ); } $( '#find-posts' ).show(); // Close the dialog when the escape key is pressed. $('#find-posts-input').trigger( 'focus' ).on( 'keyup', function( event ){ if ( event.which == 27 ) { findPosts.close(); } }); // Retrieves a list of applicable posts for media attachment and shows them. findPosts.send(); return false; }, /** * Clears the found posts lists before hiding the attach media dialog. * * @since 2.7.0 * * @memberOf findPosts * * @return {void} */ close: function() { $('#find-posts-response').empty(); $('#find-posts').hide(); $( '.ui-find-overlay' ).hide(); }, /** * Binds a click event listener to the overlay which closes the attach media * dialog. * * @since 3.5.0 * * @memberOf findPosts * * @return {void} */ overlay: function() { $( '.ui-find-overlay' ).on( 'click', function () { findPosts.close(); }); }, /** * Retrieves and displays posts based on the search term. * * Sends a post request to the admin_ajax.php, requesting posts based on the * search term provided by the user. Defaults to all posts if no search term is * provided. * * @since 2.7.0 * * @memberOf findPosts * * @return {void} */ send: function() { var post = { ps: $( '#find-posts-input' ).val(), action: 'find_posts', _ajax_nonce: $('#_ajax_nonce').val() }, spinner = $( '.find-box-search .spinner' ); spinner.addClass( 'is-active' ); /** * Send a POST request to admin_ajax.php, hide the spinner and replace the list * of posts with the response data. If an error occurs, display it. */ $.ajax( ajaxurl, { type: 'POST', data: post, dataType: 'json' }).always( function() { spinner.removeClass( 'is-active' ); }).done( function( x ) { if ( ! x.success ) { $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) ); } $( '#find-posts-response' ).html( x.data ); }).fail( function() { $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) ); }); } }; /** * Initializes the file once the DOM is fully loaded and attaches events to the * various form elements. * * @return {void} */ $( function() { var settings, $mediaGridWrap = $( '#wp-media-grid' ), copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.media-library' ), copyAttachmentURLSuccessTimeout, previousSuccessElement = null; // Opens a manage media frame into the grid. if ( $mediaGridWrap.length && window.wp && window.wp.media ) { settings = _wpMediaGridSettings; var frame = window.wp.media({ frame: 'manage', container: $mediaGridWrap, library: settings.queryVars }).open(); // Fire a global ready event. $mediaGridWrap.trigger( 'wp-media-grid-ready', frame ); } // Prevents form submission if no post has been selected. $( '#find-posts-submit' ).on( 'click', function( event ) { if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length ) event.preventDefault(); }); // Submits the search query when hitting the enter key in the search input. $( '#find-posts .find-box-search :input' ).on( 'keypress', function( event ) { if ( 13 == event.which ) { findPosts.send(); return false; } }); // Binds the click event to the search button. $( '#find-posts-search' ).on( 'click', findPosts.send ); // Binds the close dialog click event. $( '#find-posts-close' ).on( 'click', findPosts.close ); // Binds the bulk action events to the submit buttons. $( '#doaction' ).on( 'click', function( event ) { /* * Handle the bulk action based on its value. */ $( 'select[name="action"]' ).each( function() { var optionValue = $( this ).val(); if ( 'attach' === optionValue ) { event.preventDefault(); findPosts.open(); } else if ( 'delete' === optionValue ) { if ( ! showNotice.warn() ) { event.preventDefault(); } } }); }); /** * Enables clicking on the entire table row. * * @return {void} */ $( '.find-box-inside' ).on( 'click', 'tr', function() { $( this ).find( '.found-radio input' ).prop( 'checked', true ); }); /** * Handles media list copy media URL button. * * @since 6.0.0 * * @param {MouseEvent} event A click event. * @return {void} */ copyAttachmentURLClipboard.on( 'success', function( event ) { var triggerElement = $( event.trigger ), successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) ); // Clear the selection and move focus back to the trigger. event.clearSelection(); // Checking if the previousSuccessElement is present, adding the hidden class to it. if ( previousSuccessElement ) { previousSuccessElement.addClass( 'hidden' ); } // Show success visual feedback. clearTimeout( copyAttachmentURLSuccessTimeout ); successElement.removeClass( 'hidden' ); // Hide success visual feedback after 3 seconds since last success and unfocus the trigger. copyAttachmentURLSuccessTimeout = setTimeout( function() { successElement.addClass( 'hidden' ); // No need to store the previous success element further. previousSuccessElement = null; }, 3000 ); previousSuccessElement = successElement; // Handle success audible feedback. wp.a11y.speak( wp.i18n.__( 'The file URL has been copied to your clipboard' ) ); } ); }); })( jQuery ); PK!=\Fpost.jsnu[/** * @file Contains all dynamic functionality needed on post and term pages. * * @output wp-admin/js/post.js */ /* global ajaxurl, wpAjax, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */ /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */ /* global WPSetThumbnailHTML, wptitlehint */ // Backward compatibility: prevent fatal errors. window.makeSlugeditClickable = window.editPermalink = function(){}; // Make sure the wp object exists. window.wp = window.wp || {}; ( function( $ ) { var titleHasFocus = false, __ = wp.i18n.__; /** * Control loading of comments on the post and term edit pages. * * @type {{st: number, get: commentsBox.get, load: commentsBox.load}} * * @namespace commentsBox */ window.commentsBox = { // Comment offset to use when fetching new comments. st : 0, /** * Fetch comments using Ajax and display them in the box. * * @memberof commentsBox * * @param {number} total Total number of comments for this post. * @param {number} num Optional. Number of comments to fetch, defaults to 20. * @return {boolean} Always returns false. */ get : function(total, num) { var st = this.st, data; if ( ! num ) num = 20; this.st += num; this.total = total; $( '#commentsdiv .spinner' ).addClass( 'is-active' ); data = { 'action' : 'get-comments', 'mode' : 'single', '_ajax_nonce' : $('#add_comment_nonce').val(), 'p' : $('#post_ID').val(), 'start' : st, 'number' : num }; $.post( ajaxurl, data, function(r) { r = wpAjax.parseAjaxResponse(r); $('#commentsdiv .widefat').show(); $( '#commentsdiv .spinner' ).removeClass( 'is-active' ); if ( 'object' == typeof r && r.responses[0] ) { $('#the-comment-list').append( r.responses[0].data ); theList = theExtraList = null; $( 'a[className*=\':\']' ).off(); // If the offset is over the total number of comments we cannot fetch any more, so hide the button. if ( commentsBox.st > commentsBox.total ) $('#show-comments').hide(); else $('#show-comments').show().children('a').text( __( 'Show more comments' ) ); return; } else if ( 1 == r ) { $('#show-comments').text( __( 'No more comments found.' ) ); return; } $('#the-comment-list').append(''+wpAjax.broken+''); } ); return false; }, /** * Load the next batch of comments. * * @memberof commentsBox * * @param {number} total Total number of comments to load. */ load: function(total){ this.st = jQuery('#the-comment-list tr.comment:visible').length; this.get(total); } }; /** * Overwrite the content of the Featured Image postbox * * @param {string} html New HTML to be displayed in the content area of the postbox. * * @global */ window.WPSetThumbnailHTML = function(html){ $('.inside', '#postimagediv').html(html); }; /** * Set the Image ID of the Featured Image * * @param {number} id The post_id of the image to use as Featured Image. * * @global */ window.WPSetThumbnailID = function(id){ var field = $('input[value="_thumbnail_id"]', '#list-table'); if ( field.length > 0 ) { $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id); } }; /** * Remove the Featured Image * * @param {string} nonce Nonce to use in the request. * * @global */ window.WPRemoveThumbnail = function(nonce){ $.post( ajaxurl, { action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie ) }, /** * Handle server response * * @param {string} str Response, will be '0' when an error occurred otherwise contains link to add Featured Image. */ function(str){ if ( str == '0' ) { alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) ); } else { WPSetThumbnailHTML(str); } } ); }; /** * Heartbeat locks. * * Used to lock editing of an object by only one user at a time. * * When the user does not send a heartbeat in a heartbeat-time * the user is no longer editing and another user can start editing. */ $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) { var lock = $('#active_post_lock').val(), post_id = $('#post_ID').val(), send = {}; if ( ! post_id || ! $('#post-lock-dialog').length ) return; send.post_id = post_id; if ( lock ) send.lock = lock; data['wp-refresh-post-lock'] = send; }).on( 'heartbeat-tick.refresh-lock', function( e, data ) { // Post locks: update the lock string or show the dialog if somebody has taken over editing. var received, wrap, avatar; if ( data['wp-refresh-post-lock'] ) { received = data['wp-refresh-post-lock']; if ( received.lock_error ) { // Show "editing taken over" message. wrap = $('#post-lock-dialog'); if ( wrap.length && ! wrap.is(':visible') ) { if ( wp.autosave ) { // Save the latest changes and disable. $(document).one( 'heartbeat-tick', function() { wp.autosave.server.suspend(); wrap.removeClass('saving').addClass('saved'); $(window).off( 'beforeunload.edit-post' ); }); wrap.addClass('saving'); wp.autosave.server.triggerSave(); } if ( received.lock_error.avatar_src ) { avatar = $( '', { 'class': 'avatar avatar-64 photo', width: 64, height: 64, alt: '', src: received.lock_error.avatar_src, srcset: received.lock_error.avatar_src_2x ? received.lock_error.avatar_src_2x + ' 2x' : undefined } ); wrap.find('div.post-locked-avatar').empty().append( avatar ); } wrap.show().find('.currently-editing').text( received.lock_error.text ); wrap.find('.wp-tab-first').trigger( 'focus' ); } } else if ( received.new_lock ) { $('#active_post_lock').val( received.new_lock ); } } }).on( 'before-autosave.update-post-slug', function() { titleHasFocus = document.activeElement && document.activeElement.id === 'title'; }).on( 'after-autosave.update-post-slug', function() { /* * Create slug area only if not already there * and the title field was not focused (user was not typing a title) when autosave ran. */ if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) { $.post( ajaxurl, { action: 'sample-permalink', post_id: $('#post_ID').val(), new_title: $('#title').val(), samplepermalinknonce: $('#samplepermalinknonce').val() }, function( data ) { if ( data != '-1' ) { $('#edit-slug-box').html(data); } } ); } }); }(jQuery)); /** * Heartbeat refresh nonces. */ (function($) { var check, timeout; /** * Only allow to check for nonce refresh every 30 seconds. */ function schedule() { check = false; window.clearTimeout( timeout ); timeout = window.setTimeout( function(){ check = true; }, 300000 ); } $( function() { schedule(); }).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { var post_id, $authCheck = $('#wp-auth-check-wrap'); if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) { if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) { data['wp-refresh-post-nonces'] = { post_id: post_id }; } } }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) { var nonces = data['wp-refresh-post-nonces']; if ( nonces ) { schedule(); if ( nonces.replace ) { $.each( nonces.replace, function( selector, value ) { $( '#' + selector ).val( value ); }); } if ( nonces.heartbeatNonce ) window.heartbeatSettings.nonce = nonces.heartbeatNonce; } }); }(jQuery)); /** * All post and postbox controls and functionality. */ jQuery( function($) { var stamp, visibility, $submitButtons, updateVisibility, updateText, $textarea = $('#content'), $document = $(document), postId = $('#post_ID').val() || 0, $submitpost = $('#submitpost'), releaseLock = true, $postVisibilitySelect = $('#post-visibility-select'), $timestampdiv = $('#timestampdiv'), $postStatusSelect = $('#post-status-select'), isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false, copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.edit-media' ), copyAttachmentURLSuccessTimeout, __ = wp.i18n.__, _x = wp.i18n._x; postboxes.add_postbox_toggles(pagenow); /* * Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post, * and the first post is still being edited, clicking Preview there will use this window to show the preview. */ window.name = ''; // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item. $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) { // Don't do anything when [Tab] is pressed. if ( e.which != 9 ) return; var target = $(e.target); // [Shift] + [Tab] on first tab cycles back to last tab. if ( target.hasClass('wp-tab-first') && e.shiftKey ) { $(this).find('.wp-tab-last').trigger( 'focus' ); e.preventDefault(); // [Tab] on last tab cycles back to first tab. } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) { $(this).find('.wp-tab-first').trigger( 'focus' ); e.preventDefault(); } }).filter(':visible').find('.wp-tab-first').trigger( 'focus' ); // Set the heartbeat interval to 10 seconds if post lock dialogs are enabled. if ( wp.heartbeat && $('#post-lock-dialog').length ) { wp.heartbeat.interval( 10 ); } // The form is being submitted by the user. $submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) { var $button = $(this); if ( $button.hasClass('disabled') ) { event.preventDefault(); return; } if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) { return; } // The form submission can be blocked from JS or by using HTML 5.0 validation on some fields. // Run this only on an actual 'submit'. $('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) { if ( event.isDefaultPrevented() ) { return; } // Stop auto save. if ( wp.autosave ) { wp.autosave.server.suspend(); } if ( typeof commentReply !== 'undefined' ) { /* * Warn the user they have an unsaved comment before submitting * the post data for update. */ if ( ! commentReply.discardCommentChanges() ) { return false; } /* * Close the comment edit/reply form if open to stop the form * action from interfering with the post's form action. */ commentReply.close(); } releaseLock = false; $(window).off( 'beforeunload.edit-post' ); $submitButtons.addClass( 'disabled' ); if ( $button.attr('id') === 'publish' ) { $submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' ); } else { $submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' ); } }); }); // Submit the form saving a draft or an autosave, and show a preview in a new tab. $('#post-preview').on( 'click.post-preview', function( event ) { var $this = $(this), $form = $('form#post'), $previewField = $('input#wp-preview'), target = $this.attr('target') || 'wp-preview', ua = navigator.userAgent.toLowerCase(); event.preventDefault(); if ( $this.hasClass('disabled') ) { return; } if ( wp.autosave ) { wp.autosave.server.tempBlockSave(); } $previewField.val('dopreview'); $form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' ); // Workaround for WebKit bug preventing a form submitting twice to the same action. // https://bugs.webkit.org/show_bug.cgi?id=28633 if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) { $form.attr( 'action', function( index, value ) { return value + '?t=' + ( new Date() ).getTime(); }); } $previewField.val(''); }); // Auto save new posts after a title is typed. if ( $( '#auto_draft' ).val() ) { $( '#title' ).on( 'blur', function() { var cancel; if ( ! this.value || $('#edit-slug-box > *').length ) { return; } // Cancel the auto save when the blur was triggered by the user submitting the form. $('form#post').one( 'submit', function() { cancel = true; }); window.setTimeout( function() { if ( ! cancel && wp.autosave ) { wp.autosave.server.triggerSave(); } }, 200 ); }); } $document.on( 'autosave-disable-buttons.edit-post', function() { $submitButtons.addClass( 'disabled' ); }).on( 'autosave-enable-buttons.edit-post', function() { if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) { $submitButtons.removeClass( 'disabled' ); } }).on( 'before-autosave.edit-post', function() { $( '.autosave-message' ).text( __( 'Saving Draft…' ) ); }).on( 'after-autosave.edit-post', function( event, data ) { $( '.autosave-message' ).text( data.message ); if ( $( document.body ).hasClass( 'post-new-php' ) ) { $( '.submitbox .submitdelete' ).show(); } }); /* * When the user is trying to load another page, or reloads current page * show a confirmation dialog when there are unsaved changes. */ $( window ).on( 'beforeunload.edit-post', function( event ) { var editor = window.tinymce && window.tinymce.get( 'content' ); var changed = false; if ( wp.autosave ) { changed = wp.autosave.server.postChanged(); } else if ( editor ) { changed = ( ! editor.isHidden() && editor.isDirty() ); } if ( changed ) { event.preventDefault(); // The return string is needed for browser compat. // See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event. return __( 'The changes you made will be lost if you navigate away from this page.' ); } }).on( 'pagehide.edit-post', function( event ) { if ( ! releaseLock ) { return; } /* * Unload is triggered (by hand) on removing the Thickbox iframe. * Make sure we process only the main document unload. */ if ( event.target && event.target.nodeName != '#document' ) { return; } var postID = $('#post_ID').val(); var postLock = $('#active_post_lock').val(); if ( ! postID || ! postLock ) { return; } var data = { action: 'wp-remove-post-lock', _wpnonce: $('#_wpnonce').val(), post_ID: postID, active_post_lock: postLock }; if ( window.FormData && window.navigator.sendBeacon ) { var formData = new window.FormData(); $.each( data, function( key, value ) { formData.append( key, value ); }); if ( window.navigator.sendBeacon( ajaxurl, formData ) ) { return; } } // Fall back to a synchronous POST request. // See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon $.post({ async: false, data: data, url: ajaxurl }); }); // Multiple taxonomies. if ( $('#tagsdiv-post_tag').length ) { window.tagBox && window.tagBox.init(); } else { $('.meta-box-sortables').children('div.postbox').each(function(){ if ( this.id.indexOf('tagsdiv-') === 0 ) { window.tagBox && window.tagBox.init(); return false; } }); } // Handle categories. $('.categorydiv').each( function(){ var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName; taxonomyParts = this_id.split('-'); taxonomyParts.shift(); taxonomy = taxonomyParts.join('-'); settingName = taxonomy + '_tab'; if ( taxonomy == 'category' ) { settingName = 'cats'; } // @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js. $('a', '#' + taxonomy + '-tabs').on( 'click', function( e ) { e.preventDefault(); var t = $(this).attr('href'); $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide(); $(t).show(); if ( '#' + taxonomy + '-all' == t ) { deleteUserSetting( settingName ); } else { setUserSetting( settingName, 'pop' ); } }); if ( getUserSetting( settingName ) ) $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').trigger( 'click' ); // Add category button controls. $('#new' + taxonomy).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); }); // On [Enter] submit the taxonomy. $('#new' + taxonomy).on( 'keypress', function(event){ if( 13 === event.keyCode ) { event.preventDefault(); $('#' + taxonomy + '-add-submit').trigger( 'click' ); } }); // After submitting a new taxonomy, re-focus the input field. $('#' + taxonomy + '-add-submit').on( 'click', function() { $('#new' + taxonomy).trigger( 'focus' ); }); /** * Before adding a new taxonomy, disable submit button. * * @param {Object} s Taxonomy object which will be added. * * @return {Object} */ catAddBefore = function( s ) { if ( !$('#new'+taxonomy).val() ) { return false; } s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize(); $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true ); return s; }; /** * Re-enable submit button after a taxonomy has been added. * * Re-enable submit button. * If the taxonomy has a parent place the taxonomy underneath the parent. * * @param {Object} r Response. * @param {Object} s Taxonomy data. * * @return {void} */ catAddAfter = function( r, s ) { var sup, drop = $('#new'+taxonomy+'_parent'); $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false ); if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) { drop.before(sup); drop.remove(); } }; $('#' + taxonomy + 'checklist').wpList({ alt: '', response: taxonomy + '-ajax-response', addBefore: catAddBefore, addAfter: catAddAfter }); // Add new taxonomy button toggles input form visibility. $('#' + taxonomy + '-add-toggle').on( 'click', function( e ) { e.preventDefault(); $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' ); $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' ); $('#new'+taxonomy).trigger( 'focus' ); }); // Sync checked items between "All {taxonomy}" and "Most used" lists. $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() { var t = $(this), c = t.is(':checked'), id = t.val(); if ( id && t.parents('#taxonomy-'+taxonomy).length ) { $('input#in-' + taxonomy + '-' + id + ', input[id^="in-' + taxonomy + '-' + id + '-"]').prop('checked', c); $('input#in-popular-' + taxonomy + '-' + id).prop('checked', c); } } ); }); // End cats. // Custom Fields postbox. if ( $('#postcustom').length ) { $( '#the-list' ).wpList( { /** * Add current post_ID to request to fetch custom fields * * @ignore * * @param {Object} s Request object. * * @return {Object} Data modified with post_ID attached. */ addBefore: function( s ) { s.data += '&post_id=' + $('#post_ID').val(); return s; }, /** * Show the listing of custom fields after fetching. * * @ignore */ addAfter: function() { $('table#list-table').show(); } }); } /* * Publish Post box (#submitdiv) */ if ( $('#submitdiv').length ) { stamp = $('#timestamp').html(); visibility = $('#post-visibility-display').html(); /** * When the visibility of a post changes sub-options should be shown or hidden. * * @ignore * * @return {void} */ updateVisibility = function() { // Show sticky for public posts. if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) { $('#sticky').prop('checked', false); $('#sticky-span').hide(); } else { $('#sticky-span').show(); } // Show password input field for password protected post. if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) { $('#password-span').hide(); } else { $('#password-span').show(); } }; /** * Make sure all labels represent the current settings. * * @ignore * * @return {boolean} False when an invalid timestamp has been selected, otherwise True. */ updateText = function() { if ( ! $timestampdiv.length ) return true; var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(); attemptedDate = new Date( aa, mm - 1, jj, hh, mn ); originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() ); currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() ); // Catch unexpected date problems. if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) { $timestampdiv.find('.timestamp-wrap').addClass('form-invalid'); return false; } else { $timestampdiv.find('.timestamp-wrap').removeClass('form-invalid'); } // Determine what the publish should be depending on the date and post status. if ( attemptedDate > currentDate ) { publishOn = __( 'Schedule for:' ); $('#publish').val( _x( 'Schedule', 'post action/button label' ) ); } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) { publishOn = __( 'Publish on:' ); $('#publish').val( __( 'Publish' ) ); } else { publishOn = __( 'Published on:' ); $('#publish').val( __( 'Update' ) ); } // If the date is the same, set it to trigger update events. if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { // Re-set to the current value. $('#timestamp').html(stamp); } else { $('#timestamp').html( '\n' + publishOn + ' ' + // translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. __( '%1$s %2$s, %3$s at %4$s:%5$s' ) .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) ) .replace( '%2$s', parseInt( jj, 10 ) ) .replace( '%3$s', aa ) .replace( '%4$s', ( '00' + hh ).slice( -2 ) ) .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) + ' ' ); } // Add "privately published" to post status when applies. if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) { $('#publish').val( __( 'Update' ) ); if ( 0 === optPublish.length ) { postStatus.append(''); } else { optPublish.html( __( 'Privately Published' ) ); } $('option[value="publish"]', postStatus).prop('selected', true); $('#misc-publishing-actions .edit-post-status').hide(); } else { if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { if ( optPublish.length ) { optPublish.remove(); postStatus.val($('#hidden_post_status').val()); } } else { optPublish.html( __( 'Published' ) ); } if ( postStatus.is(':hidden') ) $('#misc-publishing-actions .edit-post-status').show(); } // Update "Status:" to currently selected status. $('#post-status-display').text( // Remove any potential tags from post status text. wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) ); // Show or hide the "Save Draft" button. if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { $('#save-post').hide(); } else { $('#save-post').show(); if ( $('option:selected', postStatus).val() == 'pending' ) { $('#save-post').show().val( __( 'Save as Pending' ) ); } else { $('#save-post').show().val( __( 'Save Draft' ) ); } } return true; }; // Show the visibility options and hide the toggle button when opened. $( '#visibility .edit-visibility').on( 'click', function( e ) { e.preventDefault(); if ( $postVisibilitySelect.is(':hidden') ) { updateVisibility(); $postVisibilitySelect.slideDown( 'fast', function() { $postVisibilitySelect.find( 'input[type="radio"]' ).first().trigger( 'focus' ); } ); $(this).hide(); } }); // Cancel visibility selection area and hide it from view. $postVisibilitySelect.find('.cancel-post-visibility').on( 'click', function( event ) { $postVisibilitySelect.slideUp('fast'); $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); $('#post_password').val($('#hidden-post-password').val()); $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); $('#post-visibility-display').html(visibility); $('#visibility .edit-visibility').show().trigger( 'focus' ); updateText(); event.preventDefault(); }); // Set the selected visibility as current. $postVisibilitySelect.find('.save-post-visibility').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels. var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val(); $postVisibilitySelect.slideUp('fast'); $('#visibility .edit-visibility').show().trigger( 'focus' ); updateText(); if ( 'public' !== selectedVisibility ) { $('#sticky').prop('checked', false); } switch ( selectedVisibility ) { case 'public': visibilityLabel = $( '#sticky' ).prop( 'checked' ) ? __( 'Public, Sticky' ) : __( 'Public' ); break; case 'private': visibilityLabel = __( 'Private' ); break; case 'password': visibilityLabel = __( 'Password Protected' ); break; } $('#post-visibility-display').text( visibilityLabel ); event.preventDefault(); }); // When the selection changes, update labels. $postVisibilitySelect.find('input:radio').on( 'change', function() { updateVisibility(); }); // Edit publish time click. $timestampdiv.siblings('a.edit-timestamp').on( 'click', function( event ) { if ( $timestampdiv.is( ':hidden' ) ) { $timestampdiv.slideDown( 'fast', function() { $( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().trigger( 'focus' ); } ); $(this).hide(); } event.preventDefault(); }); // Cancel editing the publish time and hide the settings. $timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) { $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().trigger( 'focus' ); $('#mm').val($('#hidden_mm').val()); $('#jj').val($('#hidden_jj').val()); $('#aa').val($('#hidden_aa').val()); $('#hh').val($('#hidden_hh').val()); $('#mn').val($('#hidden_mn').val()); updateText(); event.preventDefault(); }); // Save the changed timestamp. $timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels. if ( updateText() ) { $timestampdiv.slideUp('fast'); $timestampdiv.siblings('a.edit-timestamp').show().trigger( 'focus' ); } event.preventDefault(); }); // Cancel submit when an invalid timestamp has been selected. $('#post').on( 'submit', function( event ) { if ( ! updateText() ) { event.preventDefault(); $timestampdiv.show(); if ( wp.autosave ) { wp.autosave.enableButtons(); } $( '#publishing-action .spinner' ).removeClass( 'is-active' ); } }); // Post Status edit click. $postStatusSelect.siblings('a.edit-post-status').on( 'click', function( event ) { if ( $postStatusSelect.is( ':hidden' ) ) { $postStatusSelect.slideDown( 'fast', function() { $postStatusSelect.find('select').trigger( 'focus' ); } ); $(this).hide(); } event.preventDefault(); }); // Save the Post Status changes and hide the options. $postStatusSelect.find('.save-post-status').on( 'click', function( event ) { $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' ); updateText(); event.preventDefault(); }); // Cancel Post Status editing and hide the options. $postStatusSelect.find('.cancel-post-status').on( 'click', function( event ) { $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' ); $('#post_status').val( $('#hidden_post_status').val() ); updateText(); event.preventDefault(); }); } /** * Handle the editing of the post_name. Create the required HTML elements and * update the changes via Ajax. * * @global * * @return {void} */ function editPermalink() { var i, slug_value, slug_label, $el, revert_e, c = 0, real_slug = $('#post_name'), revert_slug = real_slug.val(), permalink = $( '#sample-permalink' ), permalinkOrig = permalink.html(), permalinkInner = $( '#sample-permalink a' ).html(), buttons = $('#edit-slug-buttons'), buttonsOrig = buttons.html(), full = $('#editable-post-name-full'); // Deal with Twemoji in the post-name. full.find( 'img' ).replaceWith( function() { return this.alt; } ); full = full.html(); permalink.html( permalinkInner ); // Save current content to revert to when cancelling. $el = $( '#editable-post-name' ); revert_e = $el.html(); buttons.html( ' ' + '' ); // Save permalink changes. buttons.children( '.save' ).on( 'click', function() { var new_slug = $el.children( 'input' ).val(); if ( new_slug == $('#editable-post-name-full').text() ) { buttons.children('.cancel').trigger( 'click' ); return; } $.post( ajaxurl, { action: 'sample-permalink', post_id: postId, new_slug: new_slug, new_title: $('#title').val(), samplepermalinknonce: $('#samplepermalinknonce').val() }, function(data) { var box = $('#edit-slug-box'); box.html(data); if (box.hasClass('hidden')) { box.fadeIn('fast', function () { box.removeClass('hidden'); }); } buttons.html(buttonsOrig); permalink.html(permalinkOrig); real_slug.val(new_slug); $( '.edit-slug' ).trigger( 'focus' ); wp.a11y.speak( __( 'Permalink saved' ) ); } ); }); // Cancel editing of permalink. buttons.children( '.cancel' ).on( 'click', function() { $('#view-post-btn').show(); $el.html(revert_e); buttons.html(buttonsOrig); permalink.html(permalinkOrig); real_slug.val(revert_slug); $( '.edit-slug' ).trigger( 'focus' ); }); // If more than 1/4th of 'full' is '%', make it empty. for ( i = 0; i < full.length; ++i ) { if ( '%' == full.charAt(i) ) c++; } slug_value = ( c > full.length / 4 ) ? '' : full; slug_label = __( 'URL Slug' ); $el.html( '' + '' ).children( 'input' ).on( 'keydown', function( e ) { var key = e.which; // On [Enter], just save the new slug, don't save the post. if ( 13 === key ) { e.preventDefault(); buttons.children( '.save' ).trigger( 'click' ); } // On [Esc] cancel the editing. if ( 27 === key ) { buttons.children( '.cancel' ).trigger( 'click' ); } } ).on( 'keyup', function() { real_slug.val( this.value ); }).trigger( 'focus' ); } $( '#titlediv' ).on( 'click', '.edit-slug', function() { editPermalink(); }); /** * Adds screen reader text to the title label when needed. * * Use the 'screen-reader-text' class to emulate a placeholder attribute * and hide the label when entering a value. * * @param {string} id Optional. HTML ID to add the screen reader helper text to. * * @global * * @return {void} */ window.wptitlehint = function( id ) { id = id || 'title'; var title = $( '#' + id ), titleprompt = $( '#' + id + '-prompt-text' ); if ( '' === title.val() ) { titleprompt.removeClass( 'screen-reader-text' ); } title.on( 'input', function() { if ( '' === this.value ) { titleprompt.removeClass( 'screen-reader-text' ); return; } titleprompt.addClass( 'screen-reader-text' ); } ); }; wptitlehint(); // Resize the WYSIWYG and plain text editors. ( function() { var editor, offset, mce, $handle = $('#post-status-info'), $postdivrich = $('#postdivrich'); // If there are no textareas or we are on a touch device, we can't do anything. if ( ! $textarea.length || 'ontouchstart' in window ) { // Hide the resize handle. $('#content-resize-handle').hide(); return; } /** * Handle drag event. * * @param {Object} event Event containing details about the drag. */ function dragging( event ) { if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) { return; } if ( mce ) { editor.theme.resizeTo( null, offset + event.pageY ); } else { $textarea.height( Math.max( 50, offset + event.pageY ) ); } event.preventDefault(); } /** * When the dragging stopped make sure we return focus and do a confidence check on the height. */ 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 ); if ( toolbarHeight < 10 || toolbarHeight > 200 ) { toolbarHeight = 30; } height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28; } else { $textarea.trigger( 'focus' ); height = parseInt( $textarea.css('height'), 10 ); } $document.off( '.wp-editor-resize' ); // Confidence check: normalize height to stay within acceptable ranges. if ( height && height > 50 && height < 5000 ) { setUserSetting( 'ed_size', height ); } } $handle.on( 'mousedown.wp-editor-resize', function( event ) { if ( typeof tinymce !== 'undefined' ) { editor = tinymce.get('content'); } if ( editor && ! editor.isHidden() ) { mce = true; offset = $('#content_ifr').height() - event.pageY; } else { mce = false; offset = $textarea.height() - event.pageY; $textarea.trigger( 'blur' ); } $document.on( 'mousemove.wp-editor-resize', dragging ) .on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag ); event.preventDefault(); }).on( 'mouseup.wp-editor-resize', endDrag ); })(); // TinyMCE specific handling of Post Format changes to reflect in the editor. if ( typeof tinymce !== 'undefined' ) { // When changing post formats, change the editor body class. $( '#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' ) ) ) { 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' ); } }); // When changing page template, change the editor body class. $( '#page_template' ).on( 'change.set-editor-class', function() { var editor, body, pageTemplate = $( this ).val() || ''; pageTemplate = pageTemplate.substr( pageTemplate.lastIndexOf( '/' ) + 1, pageTemplate.length ) .replace( /\.php$/, '' ) .replace( /\./g, '-' ); if ( pageTemplate && ( editor = tinymce.get( 'content' ) ) ) { body = editor.getBody(); body.className = body.className.replace( /\bpage-template-[^ ]+/, '' ); editor.dom.addClass( body, 'page-template-' + pageTemplate ); $( document ).trigger( 'editor-classchange' ); } }); } // Save on pressing [Ctrl]/[Command] + [S] in the Text editor. $textarea.on( 'keydown.wp-autosave', function( event ) { // Key [S] has code 83. if ( event.which === 83 ) { if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) { return; } wp.autosave && wp.autosave.server.triggerSave(); event.preventDefault(); } }); // If the last status was auto-draft and the save is triggered, edit the current URL. if ( $( '#original_post_status' ).val() === 'auto-draft' && window.history.replaceState ) { var location; $( '#publish' ).on( 'click', function() { location = window.location.href; location += ( location.indexOf( '?' ) !== -1 ) ? '&' : '?'; location += 'wp-post-new-reload=true'; window.history.replaceState( null, null, location ); }); } /** * Copies the attachment URL in the Edit Media page to the clipboard. * * @since 5.5.0 * * @param {MouseEvent} event A click event. * * @return {void} */ copyAttachmentURLClipboard.on( 'success', function( event ) { var triggerElement = $( event.trigger ), successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) ); // Clear the selection and move focus back to the trigger. event.clearSelection(); // Show success visual feedback. clearTimeout( copyAttachmentURLSuccessTimeout ); successElement.removeClass( 'hidden' ); // Hide success visual feedback after 3 seconds since last success. copyAttachmentURLSuccessTimeout = setTimeout( function() { successElement.addClass( 'hidden' ); }, 3000 ); // Handle success audible feedback. wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) ); } ); } ); /** * TinyMCE word count display */ ( function( $, counter ) { $( function() { var $content = $( '#content' ), $count = $( '#wp-word-count' ).find( '.word-count' ), prevCount = 0, contentEditor; /** * Get the word count from TinyMCE and display it */ function update() { var text, count; if ( ! contentEditor || contentEditor.isHidden() ) { text = $content.val(); } else { text = contentEditor.getContent( { format: 'raw' } ); } count = counter.count( text ); if ( count !== prevCount ) { $count.text( count ); } prevCount = count; } /** * Bind the word count update triggers. * * When a node change in the main TinyMCE editor has been triggered. * When a key has been released in the plain text content editor. */ $( document ).on( 'tinymce-editor-init', function( event, editor ) { if ( editor.id !== 'content' ) { return; } contentEditor = editor; editor.on( 'nodechange keyup', _.debounce( update, 1000 ) ); } ); $content.on( 'input keyup', _.debounce( update, 1000 ) ); update(); } ); } )( jQuery, new wp.utils.WordCounter() ); PK!^custom-background.min.jsnu[/*! This file is auto-generated */ !function(e){e(function(){var c,a=e("#custom-background-image");e("#background-color").wpColorPicker({change:function(n,o){a.css("background-color",o.color.toString())},clear:function(){a.css("background-color","")}}),e('select[name="background-size"]').on("change",function(){a.css("background-size",e(this).val())}),e('input[name="background-position"]').on("change",function(){a.css("background-position",e(this).val())}),e('input[name="background-repeat"]').on("change",function(){a.css("background-repeat",e(this).is(":checked")?"repeat":"no-repeat")}),e('input[name="background-attachment"]').on("change",function(){a.css("background-attachment",e(this).is(":checked")?"scroll":"fixed")}),e("#choose-from-library-link").on("click",function(n){var o=e(this);n.preventDefault(),c||(c=wp.media.frames.customBackground=wp.media({title:o.data("choose"),library:{type:"image"},button:{text:o.data("update"),close:!1}})).on("select",function(){var n=c.state().get("selection").first(),o=e("#_wpnonce").val()||"";e.post(ajaxurl,{action:"set-background-image",attachment_id:n.id,_ajax_nonce:o,size:"full"}).done(function(){window.location.reload()})}),c.open()})})}(jQuery);PK!8 xfn.min.jsnu[/*! This file is auto-generated */ jQuery(function(l){l("#link_rel").prop("readonly",!0),l("#linkxfndiv input").on("click keyup",function(){var e=l("#me").is(":checked"),i="";l("input.valinp").each(function(){e?l(this).prop("disabled",!0).parent().addClass("disabled"):(l(this).removeAttr("disabled").parent().removeClass("disabled"),l(this).is(":checked")&&""!==l(this).val()&&(i+=l(this).val()+" "))}),l("#link_rel").val(e?"me":i.substr(0,i.length-1))})});PK!Dxfn.jsnu[/** * Generates the XHTML Friends Network 'rel' string from the inputs. * * @deprecated 3.5.0 * @output wp-admin/js/xfn.js */ jQuery( function( $ ) { $( '#link_rel' ).prop( 'readonly', true ); $( '#linkxfndiv input' ).on( 'click keyup', function() { var isMe = $( '#me' ).is( ':checked' ), inputs = ''; $( 'input.valinp' ).each( function() { if ( isMe ) { $( this ).prop( 'disabled', true ).parent().addClass( 'disabled' ); } else { $( this ).removeAttr( 'disabled' ).parent().removeClass( 'disabled' ); if ( $( this ).is( ':checked' ) && $( this ).val() !== '') { inputs += $( this ).val() + ' '; } } }); $( '#link_rel' ).val( ( isMe ) ? 'me' : inputs.substr( 0,inputs.length - 1 ) ); }); }); PK! aII post.min.jsnu[/*! This file is auto-generated */ 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 d,e,i,a,n,s,o,l,r,t,c,p,u=h("#content"),v=h(document),f=h("#post_ID").val()||0,m=h("#submitpost"),w=!0,g=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))}),v.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(w&&(!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("input#in-"+a+"-"+i+', input[id^="in-'+a+"-"+i+'-"]').prop("checked",e),h("input#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&&(d=h("#timestamp").html(),e=h("#post-visibility-display").html(),a=function(){"public"!=g.find("input:radio:checked").val()?(h("#sticky").prop("checked",!1),h("#sticky-span").hide()):h("#sticky-span").show(),"password"!=g.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()),p=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"),p"+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"==g.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(),g.is(":hidden")&&(a(),g.slideDown("fast",function(){g.find('input[type="radio"]').first().trigger("focus")}),h(this).hide())}),g.find(".cancel-post-visibility").on("click",function(t){g.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()}),g.find(".save-post-visibility").on("click",function(t){var e="",i=g.find("input:radio:checked").val();switch(g.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()}),g.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(),p=h("#edit-slug-buttons"),d=p.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(),p.html(' "),p.children(".save").on("click",function(){var i=a.children("input").val();i==h("#editable-post-name-full").text()?p.children(".cancel").trigger("click"):h.post(ajaxurl,{action:"sample-permalink",post_id:f,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")}),p.html(d),l.html(r),s.val(i),h(".edit-slug").trigger("focus"),wp.a11y.speak(x("Permalink saved"))})}),p.children(".cancel").on("click",function(){h("#view-post-btn").show(),a.html(i),p.html(d),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(),p.children(".save").trigger("click")),27===e&&p.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")),v.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(){p=(p=window.location.href)+(-1!==p.indexOf("?")?"&":"?")+"wp-post-new-reload=true",window.history.replaceState(null,null,p)}),y.on("success",function(t){var e=h(t.trigger),i=h(".success",e.closest(".copy-to-clipboard-container"));t.clearSelection(),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);PK!gÌpassword-strength-meter.jsnu[/** * @output wp-admin/js/password-strength-meter.js */ /* global zxcvbn */ window.wp = window.wp || {}; (function($){ var __ = wp.i18n.__, sprintf = wp.i18n.sprintf; /** * Contains functions to determine the password strength. * * @since 3.7.0 * * @namespace */ wp.passwordStrength = { /** * Determines the strength of a given password. * * Compares first password to the password confirmation. * * @since 3.7.0 * * @param {string} password1 The subject password. * @param {Array} disallowedList An array of words that will lower the entropy of * the password. * @param {string} password2 The password confirmation. * * @return {number} The password strength score. */ meter : function( password1, disallowedList, password2 ) { if ( ! Array.isArray( disallowedList ) ) disallowedList = [ disallowedList.toString() ]; if (password1 != password2 && password2 && password2.length > 0) return 5; if ( 'undefined' === typeof window.zxcvbn ) { // Password strength unknown. return -1; } var result = zxcvbn( password1, disallowedList ); return result.score; }, /** * Builds an array of words that should be penalized. * * Certain words need to be penalized because it would lower the entropy of a * password if they were used. The disallowedList is based on user input fields such * as username, first name, email etc. * * @since 3.7.0 * @deprecated 5.5.0 Use {@see 'userInputDisallowedList()'} instead. * * @return {string[]} The array of words to be disallowed. */ userInputBlacklist : function() { window.console.log( sprintf( /* translators: 1: Deprecated function name, 2: Version number, 3: Alternative function name. */ __( '%1$s is deprecated since version %2$s! Use %3$s instead. Please consider writing more inclusive code.' ), 'wp.passwordStrength.userInputBlacklist()', '5.5.0', 'wp.passwordStrength.userInputDisallowedList()' ) ); return wp.passwordStrength.userInputDisallowedList(); }, /** * Builds an array of words that should be penalized. * * Certain words need to be penalized because it would lower the entropy of a * password if they were used. The disallowed list is based on user input fields such * as username, first name, email etc. * * @since 5.5.0 * * @return {string[]} The array of words to be disallowed. */ userInputDisallowedList : function() { var i, userInputFieldsLength, rawValuesLength, currentField, rawValues = [], disallowedList = [], userInputFields = [ 'user_login', 'first_name', 'last_name', 'nickname', 'display_name', 'email', 'url', 'description', 'weblog_title', 'admin_email' ]; // Collect all the strings we want to disallow. rawValues.push( document.title ); rawValues.push( document.URL ); userInputFieldsLength = userInputFields.length; for ( i = 0; i < userInputFieldsLength; i++ ) { currentField = $( '#' + userInputFields[ i ] ); if ( 0 === currentField.length ) { continue; } rawValues.push( currentField[0].defaultValue ); rawValues.push( currentField.val() ); } /* * Strip out non-alphanumeric characters and convert each word to an * individual entry. */ rawValuesLength = rawValues.length; for ( i = 0; i < rawValuesLength; i++ ) { if ( rawValues[ i ] ) { disallowedList = disallowedList.concat( rawValues[ i ].replace( /\W/g, ' ' ).split( ' ' ) ); } } /* * Remove empty values, short words and duplicates. Short words are likely to * cause many false positives. */ disallowedList = $.grep( disallowedList, function( value, key ) { if ( '' === value || 4 > value.length ) { return false; } return $.inArray( value, disallowedList ) === key; }); return disallowedList; } }; // Backward compatibility. /** * Password strength meter function. * * @since 2.5.0 * @deprecated 3.7.0 Use wp.passwordStrength.meter instead. * * @global * * @type {wp.passwordStrength.meter} */ window.passwordStrength = wp.passwordStrength.meter; })(jQuery); PK!z common.jsnu[/** * @output wp-admin/js/common.js */ /* global setUserSetting, ajaxurl, alert, confirm, pagenow */ /* global columns, screenMeta */ /** * Adds common WordPress functionality to the window. * * @param {jQuery} $ jQuery object. * @param {Object} window The window object. * @param {mixed} undefined Unused. */ ( function( $, window, undefined ) { var $document = $( document ), $window = $( window ), $body = $( document.body ), __ = wp.i18n.__, sprintf = wp.i18n.sprintf; /** * Throws an error for a deprecated property. * * @since 5.5.1 * * @param {string} propName The property that was used. * @param {string} version The version of WordPress that deprecated the property. * @param {string} replacement The property that should have been used. */ function deprecatedProperty( propName, version, replacement ) { var message; if ( 'undefined' !== typeof replacement ) { message = sprintf( /* translators: 1: Deprecated property name, 2: Version number, 3: Alternative property name. */ __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), propName, version, replacement ); } else { message = sprintf( /* translators: 1: Deprecated property name, 2: Version number. */ __( '%1$s is deprecated since version %2$s with no alternative available.' ), propName, version ); } window.console.warn( message ); } /** * Deprecate all properties on an object. * * @since 5.5.1 * @since 5.6.0 Added the `version` parameter. * * @param {string} name The name of the object, i.e. commonL10n. * @param {object} l10nObject The object to deprecate the properties on. * @param {string} version The version of WordPress that deprecated the property. * * @return {object} The object with all its properties deprecated. */ function deprecateL10nObject( name, l10nObject, version ) { var deprecatedObject = {}; Object.keys( l10nObject ).forEach( function( key ) { var prop = l10nObject[ key ]; var propName = name + '.' + key; if ( 'object' === typeof prop ) { Object.defineProperty( deprecatedObject, key, { get: function() { deprecatedProperty( propName, version, prop.alternative ); return prop.func(); } } ); } else { Object.defineProperty( deprecatedObject, key, { get: function() { deprecatedProperty( propName, version, 'wp.i18n' ); return prop; } } ); } } ); return deprecatedObject; } window.wp.deprecateL10nObject = deprecateL10nObject; /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.6.0 * @deprecated 5.5.0 */ window.commonL10n = window.commonL10n || { warnDelete: '', dismiss: '', collapseMenu: '', expandMenu: '' }; window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 3.3.0 * @deprecated 5.5.0 */ window.wpPointerL10n = window.wpPointerL10n || { dismiss: '' }; window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 4.3.0 * @deprecated 5.5.0 */ window.userProfileL10n = window.userProfileL10n || { warn: '', warnWeak: '', show: '', hide: '', cancel: '', ariaShow: '', ariaHide: '' }; window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 4.9.6 * @deprecated 5.5.0 */ window.privacyToolsL10n = window.privacyToolsL10n || { noDataFound: '', foundAndRemoved: '', noneRemoved: '', someNotRemoved: '', removalError: '', emailSent: '', noExportFile: '', exportError: '' }; window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 3.6.0 * @deprecated 5.5.0 */ window.authcheckL10n = { beforeunload: '' }; window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.8.0 * @deprecated 5.5.0 */ window.tagsl10n = { noPerm: '', broken: '' }; window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.5.0 * @deprecated 5.5.0 */ window.adminCommentsL10n = window.adminCommentsL10n || { hotkeys_highlight_first: { alternative: 'window.adminCommentsSettings.hotkeys_highlight_first', func: function() { return window.adminCommentsSettings.hotkeys_highlight_first; } }, hotkeys_highlight_last: { alternative: 'window.adminCommentsSettings.hotkeys_highlight_last', func: function() { return window.adminCommentsSettings.hotkeys_highlight_last; } }, replyApprove: '', reply: '', warnQuickEdit: '', warnCommentChanges: '', docTitleComments: '', docTitleCommentsCount: '' }; window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.5.0 * @deprecated 5.5.0 */ window.tagsSuggestL10n = window.tagsSuggestL10n || { tagDelimiter: '', removeTerm: '', termSelected: '', termAdded: '', termRemoved: '' }; window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 3.5.0 * @deprecated 5.5.0 */ window.wpColorPickerL10n = window.wpColorPickerL10n || { clear: '', clearAriaLabel: '', defaultString: '', defaultAriaLabel: '', pick: '', defaultLabel: '' }; window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.7.0 * @deprecated 5.5.0 */ window.attachMediaBoxL10n = window.attachMediaBoxL10n || { error: '' }; window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.5.0 * @deprecated 5.5.0 */ window.postL10n = window.postL10n || { ok: '', cancel: '', publishOn: '', publishOnFuture: '', publishOnPast: '', dateFormat: '', showcomm: '', endcomm: '', publish: '', schedule: '', update: '', savePending: '', saveDraft: '', 'private': '', 'public': '', publicSticky: '', password: '', privatelyPublished: '', published: '', saveAlert: '', savingText: '', permalinkSaved: '' }; window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.7.0 * @deprecated 5.5.0 */ window.inlineEditL10n = window.inlineEditL10n || { error: '', ntdeltitle: '', notitle: '', comma: '', saved: '' }; window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.7.0 * @deprecated 5.5.0 */ window.plugininstallL10n = window.plugininstallL10n || { plugin_information: '', plugin_modal_label: '', ays: '' }; window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 3.0.0 * @deprecated 5.5.0 */ window.navMenuL10n = window.navMenuL10n || { noResultsFound: '', warnDeleteMenu: '', saveAlert: '', untitled: '' }; window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.5.0 * @deprecated 5.5.0 */ window.commentL10n = window.commentL10n || { submittedOn: '', dateFormat: '' }; window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n, '5.5.0' ); /** * Removed in 5.5.0, needed for back-compatibility. * * @since 2.9.0 * @deprecated 5.5.0 */ window.setPostThumbnailL10n = window.setPostThumbnailL10n || { setThumbnail: '', saving: '', error: '', done: '' }; window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n, '5.5.0' ); /** * Removed in 6.5.0, needed for back-compatibility. * * @since 4.5.0 * @deprecated 6.5.0 */ window.uiAutocompleteL10n = window.uiAutocompleteL10n || { noResults: '', oneResult: '', manyResults: '', itemSelected: '' }; window.uiAutocompleteL10n = deprecateL10nObject( 'uiAutocompleteL10n', window.uiAutocompleteL10n, '6.5.0' ); /** * Removed in 3.3.0, needed for back-compatibility. * * @since 2.7.0 * @deprecated 3.3.0 */ window.adminMenu = { init : function() {}, fold : function() {}, restoreMenuState : function() {}, toggle : function() {}, favorites : function() {} }; // Show/hide/save table columns. window.columns = { /** * Initializes the column toggles in the screen options. * * Binds an onClick event to the checkboxes to show or hide the table columns * based on their toggled state. And persists the toggled state. * * @since 2.7.0 * * @return {void} */ init : function() { var that = this; $('.hide-column-tog', '#adv-settings').on( 'click', function() { var $t = $(this), column = $t.val(); if ( $t.prop('checked') ) that.checked(column); else that.unchecked(column); columns.saveManageColumnsState(); }); }, /** * Saves the toggled state for the columns. * * Saves whether the columns should be shown or hidden on a page. * * @since 3.0.0 * * @return {void} */ saveManageColumnsState : function() { var hidden = this.hidden(); $.post( ajaxurl, { action: 'hidden-columns', hidden: hidden, screenoptionnonce: $('#screenoptionnonce').val(), page: pagenow }, function() { wp.a11y.speak( __( 'Screen Options updated.' ) ); } ); }, /** * Makes a column visible and adjusts the column span for the table. * * @since 3.0.0 * @param {string} column The column name. * * @return {void} */ checked : function(column) { $('.column-' + column).removeClass( 'hidden' ); this.colSpanChange(+1); }, /** * Hides a column and adjusts the column span for the table. * * @since 3.0.0 * @param {string} column The column name. * * @return {void} */ unchecked : function(column) { $('.column-' + column).addClass( 'hidden' ); this.colSpanChange(-1); }, /** * Gets all hidden columns. * * @since 3.0.0 * * @return {string} The hidden column names separated by a comma. */ hidden : function() { return $( '.manage-column[id]' ).filter( '.hidden' ).map(function() { return this.id; }).get().join( ',' ); }, /** * Gets the checked column toggles from the screen options. * * @since 3.0.0 * * @return {string} String containing the checked column names. */ useCheckboxesForHidden : function() { this.hidden = function(){ return $('.hide-column-tog').not(':checked').map(function() { var id = this.id; return id.substring( id, id.length - 5 ); }).get().join(','); }; }, /** * Adjusts the column span for the table. * * @since 3.1.0 * * @param {number} diff The modifier for the column span. */ colSpanChange : function(diff) { var $t = $('table').find('.colspanchange'), n; if ( !$t.length ) return; n = parseInt( $t.attr('colspan'), 10 ) + diff; $t.attr('colspan', n.toString()); } }; $( function() { columns.init(); } ); /** * Validates that the required form fields are not empty. * * @since 2.9.0 * * @param {jQuery} form The form to validate. * * @return {boolean} Returns true if all required fields are not an empty string. */ window.validateForm = function( form ) { return !$( form ) .find( '.form-required' ) .filter( function() { return $( ':input:visible', this ).val() === ''; } ) .addClass( 'form-invalid' ) .find( ':input:visible' ) .on( 'change', function() { $( this ).closest( '.form-invalid' ).removeClass( 'form-invalid' ); } ) .length; }; // Stub for doing better warnings. /** * Shows message pop-up notice or confirmation message. * * @since 2.7.0 * * @type {{warn: showNotice.warn, note: showNotice.note}} * * @return {void} */ window.showNotice = { /** * Shows a delete confirmation pop-up message. * * @since 2.7.0 * * @return {boolean} Returns true if the message is confirmed. */ warn : function() { if ( confirm( __( 'You are about to permanently delete these items from your site.\nThis action cannot be undone.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) { return true; } return false; }, /** * Shows an alert message. * * @since 2.7.0 * * @param text The text to display in the message. */ note : function(text) { alert(text); } }; /** * Represents the functions for the meta screen options panel. * * @since 3.2.0 * * @type {{element: null, toggles: null, page: null, init: screenMeta.init, * toggleEvent: screenMeta.toggleEvent, open: screenMeta.open, * close: screenMeta.close}} * * @return {void} */ window.screenMeta = { element: null, // #screen-meta toggles: null, // .screen-meta-toggle page: null, // #wpcontent /** * Initializes the screen meta options panel. * * @since 3.2.0 * * @return {void} */ init: function() { this.element = $('#screen-meta'); this.toggles = $( '#screen-meta-links' ).find( '.show-settings' ); this.page = $('#wpcontent'); this.toggles.on( 'click', this.toggleEvent ); }, /** * Toggles the screen meta options panel. * * @since 3.2.0 * * @return {void} */ toggleEvent: function() { var panel = $( '#' + $( this ).attr( 'aria-controls' ) ); if ( !panel.length ) return; if ( panel.is(':visible') ) screenMeta.close( panel, $(this) ); else screenMeta.open( panel, $(this) ); }, /** * Opens the screen meta options panel. * * @since 3.2.0 * * @param {jQuery} panel The screen meta options panel div. * @param {jQuery} button The toggle button. * * @return {void} */ open: function( panel, button ) { $( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' ); panel.parent().show(); /** * Sets the focus to the meta options panel and adds the necessary CSS classes. * * @since 3.2.0 * * @return {void} */ panel.slideDown( 'fast', function() { panel.removeClass( 'hidden' ).trigger( 'focus' ); button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true ); }); $document.trigger( 'screen:options:open' ); }, /** * Closes the screen meta options panel. * * @since 3.2.0 * * @param {jQuery} panel The screen meta options panel div. * @param {jQuery} button The toggle button. * * @return {void} */ close: function( panel, button ) { /** * Hides the screen meta options panel. * * @since 3.2.0 * * @return {void} */ panel.slideUp( 'fast', function() { button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false ); $('.screen-meta-toggle').css('visibility', ''); panel.parent().hide(); panel.addClass( 'hidden' ); }); $document.trigger( 'screen:options:close' ); } }; /** * Initializes the help tabs in the help panel. * * @param {Event} e The event object. * * @return {void} */ $('.contextual-help-tabs').on( 'click', 'a', function(e) { var link = $(this), panel; e.preventDefault(); // Don't do anything if the click is for the tab already showing. if ( link.is('.active a') ) return false; // Links. $('.contextual-help-tabs .active').removeClass('active'); link.parent('li').addClass('active'); panel = $( link.attr('href') ); // Panels. $('.help-tab-content').not( panel ).removeClass('active').hide(); panel.addClass('active').show(); }); /** * Update custom permalink structure via buttons. */ var permalinkStructureFocused = false, $permalinkStructure = $( '#permalink_structure' ), $permalinkStructureInputs = $( '.permalink-structure input:radio' ), $permalinkCustomSelection = $( '#custom_selection' ), $availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' ); // Change permalink structure input when selecting one of the common structures. $permalinkStructureInputs.on( 'change', function() { if ( 'custom' === this.value ) { return; } $permalinkStructure.val( this.value ); // Update button states after selection. $availableStructureTags.each( function() { changeStructureTagButtonState( $( this ) ); } ); } ); $permalinkStructure.on( 'click input', function() { $permalinkCustomSelection.prop( 'checked', true ); } ); // Check if the permalink structure input field has had focus at least once. $permalinkStructure.on( 'focus', function( event ) { permalinkStructureFocused = true; $( this ).off( event ); } ); /** * Enables or disables a structure tag button depending on its usage. * * If the structure is already used in the custom permalink structure, * it will be disabled. * * @param {Object} button Button jQuery object. */ function changeStructureTagButtonState( button ) { if ( -1 !== $permalinkStructure.val().indexOf( button.text().trim() ) ) { button.attr( 'data-label', button.attr( 'aria-label' ) ); button.attr( 'aria-label', button.attr( 'data-used' ) ); button.attr( 'aria-pressed', true ); button.addClass( 'active' ); } else if ( button.attr( 'data-label' ) ) { button.attr( 'aria-label', button.attr( 'data-label' ) ); button.attr( 'aria-pressed', false ); button.removeClass( 'active' ); } } // Check initial button state. $availableStructureTags.each( function() { changeStructureTagButtonState( $( this ) ); } ); // Observe permalink structure field and disable buttons of tags that are already present. $permalinkStructure.on( 'change', function() { $availableStructureTags.each( function() { changeStructureTagButtonState( $( this ) ); } ); } ); $availableStructureTags.on( 'click', function() { var permalinkStructureValue = $permalinkStructure.val(), selectionStart = $permalinkStructure[ 0 ].selectionStart, selectionEnd = $permalinkStructure[ 0 ].selectionEnd, textToAppend = $( this ).text().trim(), textToAnnounce, newSelectionStart; if ( $( this ).hasClass( 'active' ) ) { textToAnnounce = $( this ).attr( 'data-removed' ); } else { textToAnnounce = $( this ).attr( 'data-added' ); } // Remove structure tag if already part of the structure. if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) { permalinkStructureValue = permalinkStructureValue.replace( textToAppend + '/', '' ); $permalinkStructure.val( '/' === permalinkStructureValue ? '' : permalinkStructureValue ); // Announce change to screen readers. $( '#custom_selection_updated' ).text( textToAnnounce ); // Disable button. changeStructureTagButtonState( $( this ) ); return; } // Input field never had focus, move selection to end of input. if ( ! permalinkStructureFocused && 0 === selectionStart && 0 === selectionEnd ) { selectionStart = selectionEnd = permalinkStructureValue.length; } $permalinkCustomSelection.prop( 'checked', true ); // Prepend and append slashes if necessary. if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) { textToAppend = '/' + textToAppend; } if ( '/' !== permalinkStructureValue.substr( selectionEnd, 1 ) ) { textToAppend = textToAppend + '/'; } // Insert structure tag at the specified position. $permalinkStructure.val( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend + permalinkStructureValue.substr( selectionEnd ) ); // Announce change to screen readers. $( '#custom_selection_updated' ).text( textToAnnounce ); // Disable button. changeStructureTagButtonState( $( this ) ); // If input had focus give it back with cursor right after appended text. if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) { newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length; $permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart ); $permalinkStructure.trigger( 'focus' ); } } ); $( function() { var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, lastClicked = false, pageInput = $('input.current-page'), currentPage = pageInput.val(), isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, $adminMenuWrap = $( '#adminmenuwrap' ), $wpwrap = $( '#wpwrap' ), $adminmenu = $( '#adminmenu' ), $overlay = $( '#wp-responsive-overlay' ), $toolbar = $( '#wp-toolbar' ), $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ), $sortables = $('.meta-box-sortables'), wpResponsiveActive = false, $adminbar = $( '#wpadminbar' ), lastScrollPosition = 0, pinnedMenuTop = false, pinnedMenuBottom = false, menuTop = 0, menuState, menuIsPinned = false, height = { window: $window.height(), wpwrap: $wpwrap.height(), adminbar: $adminbar.height(), menu: $adminMenuWrap.height() }, $headerEnd = $( '.wp-header-end' ); /** * Makes the fly-out submenu header clickable, when the menu is folded. * * @param {Event} e The event object. * * @return {void} */ $adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ $(e.target).parent().siblings('a').get(0).click(); }); /** * Collapses the admin menu. * * @return {void} */ $( '#collapse-button' ).on( 'click.collapse-menu', function() { var viewportWidth = getViewportWidth() || 961; // Reset any compensation for submenus near the bottom of the screen. $('#adminmenu div.wp-submenu').css('margin-top', ''); if ( viewportWidth <= 960 ) { if ( $body.hasClass('auto-fold') ) { $body.removeClass('auto-fold').removeClass('folded'); setUserSetting('unfold', 1); setUserSetting('mfold', 'o'); menuState = 'open'; } else { $body.addClass('auto-fold'); setUserSetting('unfold', 0); menuState = 'folded'; } } else { if ( $body.hasClass('folded') ) { $body.removeClass('folded'); setUserSetting('mfold', 'o'); menuState = 'open'; } else { $body.addClass('folded'); setUserSetting('mfold', 'f'); menuState = 'folded'; } } $document.trigger( 'wp-collapse-menu', { state: menuState } ); }); /** * Ensures an admin submenu is within the visual viewport. * * @since 4.1.0 * * @param {jQuery} $menuItem The parent menu item containing the submenu. * * @return {void} */ function adjustSubmenu( $menuItem ) { var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop, $submenu = $menuItem.find( '.wp-submenu' ); menutop = $menuItem.offset().top; wintop = $window.scrollTop(); maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar. bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu. pageHeight = $wpwrap.height(); // Height of the entire page. adjustment = 60 + bottomOffset - pageHeight; theFold = $window.height() + wintop - 50; // The fold. if ( theFold < ( bottomOffset - adjustment ) ) { adjustment = bottomOffset - theFold; } if ( adjustment > maxtop ) { adjustment = maxtop; } if ( adjustment > 1 && $('#wp-admin-bar-menu-toggle').is(':hidden') ) { $submenu.css( 'margin-top', '-' + adjustment + 'px' ); } else { $submenu.css( 'margin-top', '' ); } } if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // Touch screen device. // iOS Safari works with touchstart, the rest work with click. mobileEvent = isIOS ? 'touchstart' : 'click'; /** * Closes any open submenus when touch/click is not on the menu. * * @param {Event} e The event object. * * @return {void} */ $body.on( mobileEvent+'.wp-mobile-hover', function(e) { if ( $adminmenu.data('wp-responsive') ) { return; } if ( ! $( e.target ).closest( '#adminmenu' ).length ) { $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); } }); /** * Handles the opening or closing the submenu based on the mobile click|touch event. * * @param {Event} event The event object. * * @return {void} */ $adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) { var $menuItem = $(this).parent(); if ( $adminmenu.data( 'wp-responsive' ) ) { return; } /* * Show the sub instead of following the link if: * - the submenu is not open. * - the submenu is not shown inline or the menu is not folded. */ if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) { event.preventDefault(); adjustSubmenu( $menuItem ); $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); $menuItem.addClass('opensub'); } }); } if ( ! isIOS && ! isAndroid ) { $adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({ /** * Opens the submenu when hovered over the menu item for desktops. * * @return {void} */ over: function() { var $menuItem = $( this ), $submenu = $menuItem.find( '.wp-submenu' ), top = parseInt( $submenu.css( 'top' ), 10 ); if ( isNaN( top ) || top > -5 ) { // The submenu is visible. return; } if ( $adminmenu.data( 'wp-responsive' ) ) { // The menu is in responsive mode, bail. return; } adjustSubmenu( $menuItem ); $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); $menuItem.addClass( 'opensub' ); }, /** * Closes the submenu when no longer hovering the menu item. * * @return {void} */ out: function(){ if ( $adminmenu.data( 'wp-responsive' ) ) { // The menu is in responsive mode, bail. return; } $( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' ); }, timeout: 200, sensitivity: 7, interval: 90 }); /** * Opens the submenu on when focused on the menu item. * * @param {Event} event The event object. * * @return {void} */ $adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) { if ( $adminmenu.data( 'wp-responsive' ) ) { // The menu is in responsive mode, bail. return; } $( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' ); /** * Closes the submenu on blur from the menu item. * * @param {Event} event The event object. * * @return {void} */ }).on( 'blur.adminmenu', '.wp-submenu a', function( event ) { if ( $adminmenu.data( 'wp-responsive' ) ) { return; } $( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' ); /** * Adjusts the size for the submenu. * * @return {void} */ }).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() { adjustSubmenu( $( this ) ); }); } /* * The `.below-h2` class is here just for backward compatibility with plugins * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570. * If '.wp-header-end' is found, append the notices after it otherwise * after the first h1 or h2 heading found within the main content. */ if ( ! $headerEnd.length ) { $headerEnd = $( '.wrap h1, .wrap h2' ).first(); } $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd ); /** * Makes notices dismissible. * * @since 4.4.0 * * @return {void} */ function makeNoticesDismissible() { $( '.notice.is-dismissible' ).each( function() { var $el = $( this ), $button = $( '' ); if ( $el.find( '.notice-dismiss' ).length ) { return; } // Ensure plain text. $button.find( '.screen-reader-text' ).text( __( 'Dismiss this notice.' ) ); $button.on( 'click.wp-dismiss-notice', function( event ) { event.preventDefault(); $el.fadeTo( 100, 0, function() { $el.slideUp( 100, function() { $el.remove(); }); }); }); $el.append( $button ); }); } $document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error wp-notice-added', makeNoticesDismissible ); // Init screen meta. screenMeta.init(); /** * Checks a checkbox. * * This event needs to be delegated. Ticket #37973. * * @return {boolean} Returns whether a checkbox is checked or not. */ $body.on( 'click', 'tbody > tr > .check-column :checkbox', function( event ) { // Shift click to select a range of checkboxes. if ( 'undefined' == event.shiftKey ) { return true; } if ( event.shiftKey ) { if ( !lastClicked ) { return true; } checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' ); first = checks.index( lastClicked ); last = checks.index( this ); checked = $(this).prop('checked'); if ( 0 < first && 0 < last && first != last ) { sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first ); sliced.prop( 'checked', function() { if ( $(this).closest('tr').is(':visible') ) return checked; return false; }); } } lastClicked = this; // Toggle the "Select all" checkboxes depending if the other ones are all checked or not. var unchecked = $(this).closest('tbody').find('tr').find(':checkbox').filter(':visible:enabled').not(':checked'); /** * Determines if all checkboxes are checked. * * @return {boolean} Returns true if there are no unchecked checkboxes. */ $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { return ( 0 === unchecked.length ); }); return true; }); /** * Controls all the toggles on bulk toggle change. * * When the bulk checkbox is changed, all the checkboxes in the tables are changed accordingly. * When the shift-button is pressed while changing the bulk checkbox the checkboxes in the table are inverted. * * This event needs to be delegated. Ticket #37973. * * @param {Event} event The event object. * * @return {boolean} */ $body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) { var $this = $(this), $table = $this.closest( 'table' ), controlChecked = $this.prop('checked'), toggle = event.shiftKey || $this.data('wp-toggle'); $table.children( 'tbody' ).filter(':visible') .children().children('.check-column').find(':checkbox') /** * Updates the checked state on the checkbox in the table. * * @return {boolean} True checks the checkbox, False unchecks the checkbox. */ .prop('checked', function() { if ( $(this).is(':hidden,:disabled') ) { return false; } if ( toggle ) { return ! $(this).prop( 'checked' ); } else if ( controlChecked ) { return true; } return false; }); $table.children('thead, tfoot').filter(':visible') .children().children('.check-column').find(':checkbox') /** * Syncs the bulk checkboxes on the top and bottom of the table. * * @return {boolean} True checks the checkbox, False unchecks the checkbox. */ .prop('checked', function() { if ( toggle ) { return false; } else if ( controlChecked ) { return true; } return false; }); }); /** * Marries a secondary control to its primary control. * * @param {jQuery} topSelector The top selector element. * @param {jQuery} topSubmit The top submit element. * @param {jQuery} bottomSelector The bottom selector element. * @param {jQuery} bottomSubmit The bottom submit element. * @return {void} */ function marryControls( topSelector, topSubmit, bottomSelector, bottomSubmit ) { /** * Updates the primary selector when the secondary selector is changed. * * @since 5.7.0 * * @return {void} */ function updateTopSelector() { topSelector.val($(this).val()); } bottomSelector.on('change', updateTopSelector); /** * Updates the secondary selector when the primary selector is changed. * * @since 5.7.0 * * @return {void} */ function updateBottomSelector() { bottomSelector.val($(this).val()); } topSelector.on('change', updateBottomSelector); /** * Triggers the primary submit when then secondary submit is clicked. * * @since 5.7.0 * * @return {void} */ function triggerSubmitClick(e) { e.preventDefault(); e.stopPropagation(); topSubmit.trigger('click'); } bottomSubmit.on('click', triggerSubmitClick); } // Marry the secondary "Bulk actions" controls to the primary controls: marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') ); // Marry the secondary "Change role to" controls to the primary controls: marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') ); var addAdminNotice = function( data ) { var $notice = $( data.selector ), $headerEnd = $( '.wp-header-end' ), type, dismissible, $adminNotice; delete data.selector; dismissible = ( data.dismissible && data.dismissible === true ) ? ' is-dismissible' : ''; type = ( data.type ) ? data.type : 'info'; $adminNotice = '

    ' + data.message + '

    '; // Check if this admin notice already exists. if ( ! $notice.length ) { $notice = $( '#' + data.id ); } if ( $notice.length ) { $notice.replaceWith( $adminNotice ); } else if ( $headerEnd.length ) { $headerEnd.after( $adminNotice ); } else { if ( 'customize' === pagenow ) { $( '.customize-themes-notifications' ).append( $adminNotice ); } else { $( '.wrap' ).find( '> h1' ).after( $adminNotice ); } } $document.trigger( 'wp-notice-added' ); }; $( '.bulkactions' ).parents( 'form' ).on( 'submit', function( event ) { var form = this, submitterName = event.originalEvent && event.originalEvent.submitter ? event.originalEvent.submitter.name : false, currentPageSelector = form.querySelector( '#current-page-selector' ); if ( currentPageSelector && currentPageSelector.defaultValue !== currentPageSelector.value ) { return; // Pagination form submission. } // Observe submissions from posts lists for 'bulk_action' or users lists for 'new_role'. var bulkFieldRelations = { 'bulk_action' : window.bulkActionObserverIds.bulk_action, 'changeit' : window.bulkActionObserverIds.changeit }; if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) ) { return; } var values = new FormData(form); var value = values.get( bulkFieldRelations[ submitterName ] ) || '-1'; // Check that the action is not the default one. if ( value !== '-1' ) { // Check that at least one item is selected. var itemsSelected = form.querySelectorAll( '.wp-list-table tbody .check-column input[type="checkbox"]:checked' ); if ( itemsSelected.length > 0 ) { return; } } event.preventDefault(); event.stopPropagation(); $( 'html, body' ).animate( { scrollTop: 0 } ); var errorMessage = __( 'Please select at least one item to perform this action on.' ); addAdminNotice( { id: 'no-items-selected', type: 'error', message: errorMessage, dismissible: true, } ); wp.a11y.speak( errorMessage ); }); /** * Shows row actions on focus of its parent container element or any other elements contained within. * * @return {void} */ $( '#wpbody-content' ).on({ focusin: function() { clearTimeout( transitionTimeout ); focusedRowActions = $( this ).find( '.row-actions' ); // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. $( '.row-actions' ).not( this ).removeClass( 'visible' ); focusedRowActions.addClass( 'visible' ); }, focusout: function() { // Tabbing between post title and .row-actions links needs a brief pause, otherwise // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox). transitionTimeout = setTimeout( function() { focusedRowActions.removeClass( 'visible' ); }, 30 ); } }, '.table-view-list .has-row-actions' ); // Toggle list table rows on small screens. $( 'tbody' ).on( 'click', '.toggle-row', function() { $( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); }); $('#default-password-nag-no').on( 'click', function() { setUserSetting('default_password_nag', 'hide'); $('div.default-password-nag').hide(); return false; }); /** * Handles tab keypresses in theme and plugin file editor textareas. * * @param {Event} e The event object. * * @return {void} */ $('#newcontent').on('keydown.wpevent_InsertTab', function(e) { var el = e.target, selStart, selEnd, val, scroll, sel; // After pressing escape key (keyCode: 27), the tab key should tab out of the textarea. if ( e.keyCode == 27 ) { // When pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them. e.preventDefault(); $(el).data('tab-out', true); return; } // Only listen for plain tab key (keyCode: 9) without any modifiers. if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) return; // After tabbing out, reset it so next time the tab key can be used again. if ( $(el).data('tab-out') ) { $(el).data('tab-out', false); return; } selStart = el.selectionStart; selEnd = el.selectionEnd; val = el.value; // If any text is selected, replace the selection with a tab character. if ( document.selection ) { el.focus(); sel = document.selection.createRange(); sel.text = '\t'; } else if ( selStart >= 0 ) { scroll = this.scrollTop; el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) ); el.selectionStart = el.selectionEnd = selStart + 1; this.scrollTop = scroll; } // Cancel the regular tab functionality, to prevent losing focus of the textarea. if ( e.stopPropagation ) e.stopPropagation(); if ( e.preventDefault ) e.preventDefault(); }); // Reset page number variable for new filters/searches but not for bulk actions. See #17685. if ( pageInput.length ) { /** * Handles pagination variable when filtering the list table. * * Set the pagination argument to the first page when the post-filter form is submitted. * This happens when pressing the 'filter' button on the list table page. * * The pagination argument should not be touched when the bulk action dropdowns are set to do anything. * * The form closest to the pageInput is the post-filter form. * * @return {void} */ pageInput.closest('form').on( 'submit', function() { /* * action = bulk action dropdown at the top of the table */ if ( $('select[name="action"]').val() == -1 && pageInput.val() == currentPage ) pageInput.val('1'); }); } /** * Resets the bulk actions when the search button is clicked. * * @return {void} */ $('.search-box input[type="search"], .search-box input[type="submit"]').on( 'mousedown', function () { $('select[name^="action"]').val('-1'); }); /** * Scrolls into view when focus.scroll-into-view is triggered. * * @param {Event} e The event object. * * @return {void} */ $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){ if ( e.target.scrollIntoViewIfNeeded ) e.target.scrollIntoViewIfNeeded(false); }); /** * Disables the submit upload buttons when no data is entered. * * @return {void} */ (function(){ var button, input, form = $('form.wp-upload-form'); // Exit when no upload form is found. if ( ! form.length ) return; button = form.find('input[type="submit"]'); input = form.find('input[type="file"]'); /** * Determines if any data is entered in any file upload input. * * @since 3.5.0 * * @return {void} */ function toggleUploadButton() { // When no inputs have a value, disable the upload buttons. button.prop('disabled', '' === input.map( function() { return $(this).val(); }).get().join('')); } // Update the status initially. toggleUploadButton(); // Update the status when any file input changes. input.on('change', toggleUploadButton); })(); /** * Pins the menu while distraction-free writing is enabled. * * @param {Event} event Event data. * * @since 4.1.0 * * @return {void} */ function pinMenu( event ) { var windowPos = $window.scrollTop(), resizing = ! event || event.type !== 'scroll'; if ( isIOS || $adminmenu.data( 'wp-responsive' ) ) { return; } /* * When the menu is higher than the window and smaller than the entire page. * It should be adjusted to be able to see the entire menu. * * Otherwise it can be accessed normally. */ if ( height.menu + height.adminbar < height.window || height.menu + height.adminbar + 20 > height.wpwrap ) { unpinMenu(); return; } menuIsPinned = true; // If the menu is higher than the window, compensate on scroll. if ( height.menu + height.adminbar > height.window ) { // Check for overscrolling, this happens when swiping up at the top of the document in modern browsers. if ( windowPos < 0 ) { // Stick the menu to the top. if ( ! pinnedMenuTop ) { pinnedMenuTop = true; pinnedMenuBottom = false; $adminMenuWrap.css({ position: 'fixed', top: '', bottom: '' }); } return; } else if ( windowPos + height.window > $document.height() - 1 ) { // When overscrolling at the bottom, stick the menu to the bottom. if ( ! pinnedMenuBottom ) { pinnedMenuBottom = true; pinnedMenuTop = false; $adminMenuWrap.css({ position: 'fixed', top: '', bottom: 0 }); } return; } if ( windowPos > lastScrollPosition ) { // When a down scroll has been detected. // If it was pinned to the top, unpin and calculate relative scroll. if ( pinnedMenuTop ) { pinnedMenuTop = false; // Calculate new offset position. menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition ); if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) { menuTop = windowPos + height.window - height.menu - height.adminbar; } $adminMenuWrap.css({ position: 'absolute', top: menuTop, bottom: '' }); } else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) { // Pin it to the bottom. pinnedMenuBottom = true; $adminMenuWrap.css({ position: 'fixed', top: '', bottom: 0 }); } } else if ( windowPos < lastScrollPosition ) { // When a scroll up is detected. // If it was pinned to the bottom, unpin and calculate relative scroll. if ( pinnedMenuBottom ) { pinnedMenuBottom = false; // Calculate new offset position. menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos ); if ( menuTop + height.menu > windowPos + height.window ) { menuTop = windowPos; } $adminMenuWrap.css({ position: 'absolute', top: menuTop, bottom: '' }); } else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) { // Pin it to the top. pinnedMenuTop = true; $adminMenuWrap.css({ position: 'fixed', top: '', bottom: '' }); } } else if ( resizing ) { // Window is being resized. pinnedMenuTop = pinnedMenuBottom = false; // Calculate the new offset. menuTop = windowPos + height.window - height.menu - height.adminbar - 1; if ( menuTop > 0 ) { $adminMenuWrap.css({ position: 'absolute', top: menuTop, bottom: '' }); } else { unpinMenu(); } } } lastScrollPosition = windowPos; } /** * Determines the height of certain elements. * * @since 4.1.0 * * @return {void} */ function resetHeights() { height = { window: $window.height(), wpwrap: $wpwrap.height(), adminbar: $adminbar.height(), menu: $adminMenuWrap.height() }; } /** * Unpins the menu. * * @since 4.1.0 * * @return {void} */ function unpinMenu() { if ( isIOS || ! menuIsPinned ) { return; } pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false; $adminMenuWrap.css({ position: '', top: '', bottom: '' }); } /** * Pins and unpins the menu when applicable. * * @since 4.1.0 * * @return {void} */ function setPinMenu() { resetHeights(); if ( $adminmenu.data('wp-responsive') ) { $body.removeClass( 'sticky-menu' ); unpinMenu(); } else if ( height.menu + height.adminbar > height.window ) { pinMenu(); $body.removeClass( 'sticky-menu' ); } else { $body.addClass( 'sticky-menu' ); unpinMenu(); } } if ( ! isIOS ) { $window.on( 'scroll.pin-menu', pinMenu ); $document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) { editor.on( 'wp-autoresize', resetHeights ); }); } /** * Changes the sortables and responsiveness of metaboxes. * * @since 3.8.0 * * @return {void} */ window.wpResponsive = { /** * Initializes the wpResponsive object. * * @since 3.8.0 * * @return {void} */ init: function() { var self = this; this.maybeDisableSortables = this.maybeDisableSortables.bind( this ); // Modify functionality based on custom activate/deactivate event. $document.on( 'wp-responsive-activate.wp-responsive', function() { self.activate(); self.toggleAriaHasPopup( 'add' ); }).on( 'wp-responsive-deactivate.wp-responsive', function() { self.deactivate(); self.toggleAriaHasPopup( 'remove' ); }); $( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' ); // Toggle sidebar when toggle is clicked. $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { event.preventDefault(); // Close any open toolbar submenus. $adminbar.find( '.hover' ).removeClass( 'hover' ); $wpwrap.toggleClass( 'wp-responsive-open' ); if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) { $(this).find('a').attr( 'aria-expanded', 'true' ); $( '#adminmenu a:first' ).trigger( 'focus' ); } else { $(this).find('a').attr( 'aria-expanded', 'false' ); } } ); // Close sidebar when target moves outside of toggle and sidebar. $( document ).on( 'click', function( event ) { if ( ! $wpwrap.hasClass( 'wp-responsive-open' ) || ! document.hasFocus() ) { return; } var focusIsInToggle = $.contains( $( '#wp-admin-bar-menu-toggle' )[0], event.target ); var focusIsInSidebar = $.contains( $( '#adminmenuwrap' )[0], event.target ); if ( ! focusIsInToggle && ! focusIsInSidebar ) { $( '#wp-admin-bar-menu-toggle' ).trigger( 'click.wp-responsive' ); } } ); // Close sidebar when a keypress completes outside of toggle and sidebar. $( document ).on( 'keyup', function( event ) { var toggleButton = $( '#wp-admin-bar-menu-toggle' )[0]; if ( ! $wpwrap.hasClass( 'wp-responsive-open' ) ) { return; } if ( 27 === event.keyCode ) { $( toggleButton ).trigger( 'click.wp-responsive' ); $( toggleButton ).find( 'a' ).trigger( 'focus' ); } else { if ( 9 === event.keyCode ) { var sidebar = $( '#adminmenuwrap' )[0]; var focusedElement = event.relatedTarget || document.activeElement; // A brief delay is required to allow focus to switch to another element. setTimeout( function() { var focusIsInToggle = $.contains( toggleButton, focusedElement ); var focusIsInSidebar = $.contains( sidebar, focusedElement ); if ( ! focusIsInToggle && ! focusIsInSidebar ) { $( toggleButton ).trigger( 'click.wp-responsive' ); } }, 10 ); } } }); // Add menu events. $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) { if ( ! $adminmenu.data('wp-responsive') ) { return; } let state = ( 'false' === $( this ).attr( 'aria-expanded' ) ) ? 'true' : 'false'; $( this ).parent( 'li' ).toggleClass( 'selected' ); $( this ).attr( 'aria-expanded', state ); $( this ).trigger( 'focus' ); event.preventDefault(); }); self.trigger(); $document.on( 'wp-window-resized.wp-responsive', this.trigger.bind( this ) ); // This needs to run later as UI Sortable may be initialized when the document is ready. $window.on( 'load.wp-responsive', this.maybeDisableSortables ); $document.on( 'postbox-toggled', this.maybeDisableSortables ); // When the screen columns are changed, potentially disable sortables. $( '#screen-options-wrap input' ).on( 'click', this.maybeDisableSortables ); }, /** * Disable sortables if there is only one metabox, or the screen is in one column mode. Otherwise, enable sortables. * * @since 5.3.0 * * @return {void} */ maybeDisableSortables: function() { var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth; if ( ( width <= 782 ) || ( 1 >= $sortables.find( '.ui-sortable-handle:visible' ).length && jQuery( '.columns-prefs-1 input' ).prop( 'checked' ) ) ) { this.disableSortables(); } else { this.enableSortables(); } }, /** * Changes properties of body and admin menu. * * Pins and unpins the menu and adds the auto-fold class to the body. * Makes the admin menu responsive and disables the metabox sortables. * * @since 3.8.0 * * @return {void} */ activate: function() { setPinMenu(); if ( ! $body.hasClass( 'auto-fold' ) ) { $body.addClass( 'auto-fold' ); } $adminmenu.data( 'wp-responsive', 1 ); this.disableSortables(); }, /** * Changes properties of admin menu and enables metabox sortables. * * Pin and unpin the menu. * Removes the responsiveness of the admin menu and enables the metabox sortables. * * @since 3.8.0 * * @return {void} */ deactivate: function() { setPinMenu(); $adminmenu.removeData('wp-responsive'); this.maybeDisableSortables(); }, /** * Toggles the aria-haspopup attribute for the responsive admin menu. * * The aria-haspopup attribute is only necessary for the responsive menu. * See ticket https://core.trac.wordpress.org/ticket/43095 * * @since 6.6.0 * * @param {string} action Whether to add or remove the aria-haspopup attribute. * * @return {void} */ toggleAriaHasPopup: function( action ) { var elements = $adminmenu.find( '[data-ariahaspopup]' ); if ( action === 'add' ) { elements.each( function() { $( this ).attr( 'aria-haspopup', 'menu' ).attr( 'aria-expanded', 'false' ); } ); return; } elements.each( function() { $( this ).removeAttr( 'aria-haspopup' ).removeAttr( 'aria-expanded' ); } ); }, /** * Sets the responsiveness and enables the overlay based on the viewport width. * * @since 3.8.0 * * @return {void} */ trigger: function() { var viewportWidth = getViewportWidth(); // Exclude IE < 9, it doesn't support @media CSS rules. if ( ! viewportWidth ) { return; } if ( viewportWidth <= 782 ) { if ( ! wpResponsiveActive ) { $document.trigger( 'wp-responsive-activate' ); wpResponsiveActive = true; } } else { if ( wpResponsiveActive ) { $document.trigger( 'wp-responsive-deactivate' ); wpResponsiveActive = false; } } if ( viewportWidth <= 480 ) { this.enableOverlay(); } else { this.disableOverlay(); } this.maybeDisableSortables(); }, /** * Inserts a responsive overlay and toggles the window. * * @since 3.8.0 * * @return {void} */ enableOverlay: function() { if ( $overlay.length === 0 ) { $overlay = $( '
    ' ) .insertAfter( '#wpcontent' ) .hide() .on( 'click.wp-responsive', function() { $toolbar.find( '.menupop.hover' ).removeClass( 'hover' ); $( this ).hide(); }); } $toolbarPopups.on( 'click.wp-responsive', function() { $overlay.show(); }); }, /** * Disables the responsive overlay and removes the overlay. * * @since 3.8.0 * * @return {void} */ disableOverlay: function() { $toolbarPopups.off( 'click.wp-responsive' ); $overlay.hide(); }, /** * Disables sortables. * * @since 3.8.0 * * @return {void} */ disableSortables: function() { if ( $sortables.length ) { try { $sortables.sortable( 'disable' ); $sortables.find( '.ui-sortable-handle' ).addClass( 'is-non-sortable' ); } catch ( e ) {} } }, /** * Enables sortables. * * @since 3.8.0 * * @return {void} */ enableSortables: function() { if ( $sortables.length ) { try { $sortables.sortable( 'enable' ); $sortables.find( '.ui-sortable-handle' ).removeClass( 'is-non-sortable' ); } catch ( e ) {} } } }; /** * Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on. * * @since 4.5.0 * * @return {void} */ function aria_button_if_js() { $( '.aria-button-if-js' ).attr( 'role', 'button' ); } $( document ).on( 'ajaxComplete', function() { aria_button_if_js(); }); /** * Get the viewport width. * * @since 4.7.0 * * @return {number|boolean} The current viewport width or false if the * browser doesn't support innerWidth (IE < 9). */ function getViewportWidth() { var viewportWidth = false; if ( window.innerWidth ) { // On phones, window.innerWidth is affected by zooming. viewportWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ); } return viewportWidth; } /** * Sets the admin menu collapsed/expanded state. * * Sets the global variable `menuState` and triggers a custom event passing * the current menu state. * * @since 4.7.0 * * @return {void} */ function setMenuState() { var viewportWidth = getViewportWidth() || 961; if ( viewportWidth <= 782 ) { menuState = 'responsive'; } else if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && viewportWidth <= 960 && viewportWidth > 782 ) ) { menuState = 'folded'; } else { menuState = 'open'; } $document.trigger( 'wp-menu-state-set', { state: menuState } ); } // Set the menu state when the window gets resized. $document.on( 'wp-window-resized.set-menu-state', setMenuState ); /** * Sets ARIA attributes on the collapse/expand menu button. * * When the admin menu is open or folded, updates the `aria-expanded` and * `aria-label` attributes of the button to give feedback to assistive * technologies. In the responsive view, the button is always hidden. * * @since 4.7.0 * * @return {void} */ $document.on( 'wp-menu-state-set wp-collapse-menu', function( event, eventData ) { var $collapseButton = $( '#collapse-button' ), ariaExpanded, ariaLabelText; if ( 'folded' === eventData.state ) { ariaExpanded = 'false'; ariaLabelText = __( 'Expand Main menu' ); } else { ariaExpanded = 'true'; ariaLabelText = __( 'Collapse Main menu' ); } $collapseButton.attr({ 'aria-expanded': ariaExpanded, 'aria-label': ariaLabelText }); }); window.wpResponsive.init(); setPinMenu(); setMenuState(); makeNoticesDismissible(); aria_button_if_js(); $document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu ); // Set initial focus on a specific element. $( '.wp-initial-focus' ).trigger( 'focus' ); // Toggle update details on update-core.php. $body.on( 'click', '.js-update-details-toggle', function() { var $updateNotice = $( this ).closest( '.js-update-details' ), $progressDiv = $( '#' + $updateNotice.data( 'update-details' ) ); /* * When clicking on "Show details" move the progress div below the update * notice. Make sure it gets moved just the first time. */ if ( ! $progressDiv.hasClass( 'update-details-moved' ) ) { $progressDiv.insertAfter( $updateNotice ).addClass( 'update-details-moved' ); } // Toggle the progress div visibility. $progressDiv.toggle(); // Toggle the Show Details button expanded state. $( this ).attr( 'aria-expanded', $progressDiv.is( ':visible' ) ); }); }); /** * Hides the update button for expired plugin or theme uploads. * * On the "Update plugin/theme from uploaded zip" screen, once the upload has expired, * hides the "Replace current with uploaded" button and displays a warning. * * @since 5.5.0 */ $( function( $ ) { var $overwrite, $warning; if ( ! $body.hasClass( 'update-php' ) ) { return; } $overwrite = $( 'a.update-from-upload-overwrite' ); $warning = $( '.update-from-upload-expired' ); if ( ! $overwrite.length || ! $warning.length ) { return; } window.setTimeout( function() { $overwrite.hide(); $warning.removeClass( 'hidden' ); if ( window.wp && window.wp.a11y ) { window.wp.a11y.speak( $warning.text() ); } }, 7140000 // 119 minutes. The uploaded file is deleted after 2 hours. ); } ); // Fire a custom jQuery event at the end of window resize. ( function() { var timeout; /** * Triggers the WP window-resize event. * * @since 3.8.0 * * @return {void} */ function triggerEvent() { $document.trigger( 'wp-window-resized' ); } /** * Fires the trigger event again after 200 ms. * * @since 3.8.0 * * @return {void} */ function fireOnce() { window.clearTimeout( timeout ); timeout = window.setTimeout( triggerEvent, 200 ); } $window.on( 'resize.wp-fire-once', fireOnce ); }()); // Make Windows 8 devices play along nicely. (function(){ if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) { var msViewportStyle = document.createElement( 'style' ); msViewportStyle.appendChild( document.createTextNode( '@-ms-viewport{width:auto!important}' ) ); document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle ); } })(); }( jQuery, window )); /** * Freeze animated plugin icons when reduced motion is enabled. * * When the user has enabled the 'prefers-reduced-motion' setting, this module * stops animations for all GIFs on the page with the class 'plugin-icon' or * plugin icon images in the update plugins table. * * @since 6.4.0 */ (function() { // Private variables and methods. var priv = {}, pub = {}, mediaQuery; // Initialize pauseAll to false; it will be set to true if reduced motion is preferred. priv.pauseAll = false; if ( window.matchMedia ) { mediaQuery = window.matchMedia( '(prefers-reduced-motion: reduce)' ); if ( ! mediaQuery || mediaQuery.matches ) { priv.pauseAll = true; } } // Method to replace animated GIFs with a static frame. priv.freezeAnimatedPluginIcons = function( img ) { var coverImage = function() { var width = img.width; var height = img.height; var canvas = document.createElement( 'canvas' ); // Set canvas dimensions. canvas.width = width; canvas.height = height; // Copy classes from the image to the canvas. canvas.className = img.className; // Check if the image is inside a specific table. var isInsideUpdateTable = img.closest( '#update-plugins-table' ); if ( isInsideUpdateTable ) { // Transfer computed styles from image to canvas. var computedStyles = window.getComputedStyle( img ), i, max; for ( i = 0, max = computedStyles.length; i < max; i++ ) { var propName = computedStyles[ i ]; var propValue = computedStyles.getPropertyValue( propName ); canvas.style[ propName ] = propValue; } } // Draw the image onto the canvas. canvas.getContext( '2d' ).drawImage( img, 0, 0, width, height ); // Set accessibility attributes on canvas. canvas.setAttribute( 'aria-hidden', 'true' ); canvas.setAttribute( 'role', 'presentation' ); // Insert canvas before the image and set the image to be near-invisible. var parent = img.parentNode; parent.insertBefore( canvas, img ); img.style.opacity = 0.01; img.style.width = '0px'; img.style.height = '0px'; }; // If the image is already loaded, apply the coverImage function. if ( img.complete ) { coverImage(); } else { // Otherwise, wait for the image to load. img.addEventListener( 'load', coverImage, true ); } }; // Public method to freeze all relevant GIFs on the page. pub.freezeAll = function() { var images = document.querySelectorAll( '.plugin-icon, #update-plugins-table img' ); for ( var x = 0; x < images.length; x++ ) { if ( /\.gif(?:\?|$)/i.test( images[ x ].src ) ) { priv.freezeAnimatedPluginIcons( images[ x ] ); } } }; // Only run the freezeAll method if the user prefers reduced motion. if ( true === priv.pauseAll ) { pub.freezeAll(); } // Listen for jQuery AJAX events. ( function( $ ) { if ( window.pagenow === 'plugin-install' ) { // Only listen for ajaxComplete if this is the plugin-install.php page. $( document ).ajaxComplete( function( event, xhr, settings ) { // Check if this is the 'search-install-plugins' request. if ( settings.data && typeof settings.data === 'string' && settings.data.includes( 'action=search-install-plugins' ) ) { // Recheck if the user prefers reduced motion. if ( window.matchMedia ) { var mediaQuery = window.matchMedia( '(prefers-reduced-motion: reduce)' ); if ( mediaQuery.matches ) { pub.freezeAll(); } } else { // Fallback for browsers that don't support matchMedia. if ( true === priv.pauseAll ) { pub.freezeAll(); } } } } ); } } )( jQuery ); // Expose public methods. return pub; })(); PK!߈ӝggtags.jsnu[/** * Contains logic for deleting and adding tags. * * For deleting tags it makes a request to the server to delete the tag. * For adding tags it makes a request to the server to add the tag. * * @output wp-admin/js/tags.js */ /* global ajaxurl, wpAjax, showNotice, validateForm */ jQuery( function($) { var addingTerm = false; /** * Adds an event handler to the delete term link on the term overview page. * * Cancels default event handling and event bubbling. * * @since 2.8.0 * * @return {boolean} Always returns false to cancel the default event handling. */ $( '#the-list' ).on( 'click', '.delete-tag', function() { var t = $(this), tr = t.parents('tr'), r = true, data; if ( 'undefined' != showNotice ) r = showNotice.warn(); if ( r ) { data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag'); /** * Makes a request to the server to delete the term that corresponds to the * delete term button. * * @param {string} r The response from the server. * * @return {void} */ $.post(ajaxurl, data, function(r){ if ( '1' == r ) { $('#ajax-response').empty(); tr.fadeOut('normal', function(){ tr.remove(); }); /** * Removes the term from the parent box and the tag cloud. * * `data.match(/tag_ID=(\d+)/)[1]` matches the term ID from the data variable. * This term ID is then used to select the relevant HTML elements: * The parent box and the tag cloud. */ $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove(); $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove(); } else if ( '-1' == r ) { $('#ajax-response').empty().append('

    ' + wp.i18n.__( 'Sorry, you are not allowed to do that.' ) + '

    '); tr.children().css('backgroundColor', ''); } else { $('#ajax-response').empty().append('

    ' + wp.i18n.__( 'An error occurred while processing your request. Please try again later.' ) + '

    '); tr.children().css('backgroundColor', ''); } }); tr.children().css('backgroundColor', '#f33'); } return false; }); /** * Adds a deletion confirmation when removing a tag. * * @since 4.8.0 * * @return {void} */ $( '#edittag' ).on( 'click', '.delete', function( e ) { if ( 'undefined' === typeof showNotice ) { return true; } // Confirms the deletion, a negative response means the deletion must not be executed. var response = showNotice.warn(); if ( ! response ) { e.preventDefault(); } }); /** * Adds an event handler to the form submit on the term overview page. * * Cancels default event handling and event bubbling. * * @since 2.8.0 * * @return {boolean} Always returns false to cancel the default event handling. */ $('#submit').on( 'click', function(){ var form = $(this).parents('form'); if ( addingTerm ) { // If we're adding a term, noop the button to avoid duplicate requests. return false; } addingTerm = true; form.find( '.submit .spinner' ).addClass( 'is-active' ); /** * Does a request to the server to add a new term to the database * * @param {string} r The response from the server. * * @return {void} */ $.post(ajaxurl, $('#addtag').serialize(), function(r){ var res, parent, term, indent, i; addingTerm = false; form.find( '.submit .spinner' ).removeClass( 'is-active' ); $('#ajax-response').empty(); res = wpAjax.parseAjaxResponse( r, 'ajax-response' ); if ( res.errors && res.responses[0].errors[0].code === 'empty_term_name' ) { validateForm( form ); } if ( ! res || res.errors ) { return; } parent = form.find( 'select#parent' ).val(); // If the parent exists on this page, insert it below. Else insert it at the top of the list. if ( parent > 0 && $('#tag-' + parent ).length > 0 ) { // As the parent exists, insert the version with - - - prefixed. $( '.tags #tag-' + parent ).after( res.responses[0].supplemental.noparents ); } else { // As the parent is not visible, insert the version with Parent - Child - ThisTerm. $( '.tags' ).prepend( res.responses[0].supplemental.parents ); } $('.tags .no-items').remove(); if ( form.find('select#parent') ) { // Parents field exists, Add new term to the list. term = res.responses[1].supplemental; // Create an indent for the Parent field. indent = ''; for ( i = 0; i < res.responses[1].position; i++ ) indent += '   '; form.find( 'select#parent option:selected' ).after( '' ); } $('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible', form).val(''); }); return false; }); }); PK!:g g comment.jsnu[/** * @output wp-admin/js/comment.js */ /* global postboxes */ /** * Binds to the document ready event. * * @since 2.5.0 * * @param {jQuery} $ The jQuery object. */ jQuery( function($) { postboxes.add_postbox_toggles('comment'); var $timestampdiv = $('#timestampdiv'), $timestamp = $( '#timestamp' ), stamp = $timestamp.html(), $timestampwrap = $timestampdiv.find( '.timestamp-wrap' ), $edittimestamp = $timestampdiv.siblings( 'a.edit-timestamp' ); /** * Adds event that opens the time stamp form if the form is hidden. * * @listens $edittimestamp:click * * @param {Event} event The event object. * @return {void} */ $edittimestamp.on( 'click', function( event ) { if ( $timestampdiv.is( ':hidden' ) ) { // Slide down the form and set focus on the first field. $timestampdiv.slideDown( 'fast', function() { $( 'input, select', $timestampwrap ).first().trigger( 'focus' ); } ); $(this).hide(); } event.preventDefault(); }); /** * Resets the time stamp values when the cancel button is clicked. * * @listens .cancel-timestamp:click * * @param {Event} event The event object. * @return {void} */ $timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) { // Move focus back to the Edit link. $edittimestamp.show().trigger( 'focus' ); $timestampdiv.slideUp( 'fast' ); $('#mm').val($('#hidden_mm').val()); $('#jj').val($('#hidden_jj').val()); $('#aa').val($('#hidden_aa').val()); $('#hh').val($('#hidden_hh').val()); $('#mn').val($('#hidden_mn').val()); $timestamp.html( stamp ); event.preventDefault(); }); /** * Sets the time stamp values when the ok button is clicked. * * @listens .save-timestamp:click * * @param {Event} event The event object. * @return {void} */ $timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels. var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(), newD = new Date( aa, mm - 1, jj, hh, mn ); event.preventDefault(); if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) { $timestampwrap.addClass( 'form-invalid' ); return; } else { $timestampwrap.removeClass( 'form-invalid' ); } $timestamp.html( wp.i18n.__( 'Submitted on:' ) + ' ' + /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */ wp.i18n.__( '%1$s %2$s, %3$s at %4$s:%5$s' ) .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) ) .replace( '%2$s', parseInt( jj, 10 ) ) .replace( '%3$s', aa ) .replace( '%4$s', ( '00' + hh ).slice( -2 ) ) .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) + ' ' ); // Move focus back to the Edit link. $edittimestamp.show().trigger( 'focus' ); $timestampdiv.slideUp( 'fast' ); }); }); PK!1 nav-menu.jsnu[/** * WordPress Administration Navigation Menu * Interface JS functions * * @version 2.0.0 * * @package WordPress * @subpackage Administration * @output wp-admin/js/nav-menu.js */ /* global menus, postboxes, columns, isRtl, ajaxurl, wpNavMenu */ (function($) { var api; /** * Contains all the functions to handle WordPress navigation menus administration. * * @namespace wpNavMenu */ api = window.wpNavMenu = { options : { menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead. globalMaxDepth: 11, sortableItems: '> *', targetTolerance: 0 }, menuList : undefined, // Set in init. targetList : undefined, // Set in init. menusChanged : false, isRTL: !! ( 'undefined' != typeof isRtl && isRtl ), negateIfRTL: ( 'undefined' != typeof isRtl && isRtl ) ? -1 : 1, lastSearch: '', // Functions that run on init. init : function() { api.menuList = $('#menu-to-edit'); api.targetList = api.menuList; this.jQueryExtensions(); this.attachMenuEditListeners(); this.attachBulkSelectButtonListeners(); this.attachMenuCheckBoxListeners(); this.attachMenuItemDeleteButton(); this.attachPendingMenuItemsListForDeletion(); this.attachQuickSearchListeners(); this.attachThemeLocationsListeners(); this.attachMenuSaveSubmitListeners(); this.attachTabsPanelListeners(); this.attachUnsavedChangesListener(); if ( api.menuList.length ) this.initSortables(); if ( menus.oneThemeLocationNoMenus ) $( '#posttype-page' ).addSelectedToMenu( api.addMenuItemToBottom ); this.initManageLocations(); this.initAccessibility(); this.initToggles(); this.initPreviewing(); }, jQueryExtensions : function() { // jQuery extensions. $.fn.extend({ menuItemDepth : function() { var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left'); return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 ); }, updateDepthClass : function(current, prev) { return this.each(function(){ var t = $(this); prev = prev || t.menuItemDepth(); $(this).removeClass('menu-item-depth-'+ prev ) .addClass('menu-item-depth-'+ current ); }); }, shiftDepthClass : function(change) { return this.each(function(){ var t = $(this), depth = t.menuItemDepth(), newDepth = depth + change; t.removeClass( 'menu-item-depth-'+ depth ) .addClass( 'menu-item-depth-'+ ( newDepth ) ); if ( 0 === newDepth ) { t.find( '.is-submenu' ).hide(); } }); }, childMenuItems : function() { var result = $(); this.each(function(){ var t = $(this), depth = t.menuItemDepth(), next = t.next( '.menu-item' ); while( next.length && next.menuItemDepth() > depth ) { result = result.add( next ); next = next.next( '.menu-item' ); } }); return result; }, shiftHorizontally : function( dir ) { return this.each(function(){ var t = $(this), depth = t.menuItemDepth(), newDepth = depth + dir; // Change .menu-item-depth-n class. t.moveHorizontally( newDepth, depth ); }); }, moveHorizontally : function( newDepth, depth ) { return this.each(function(){ var t = $(this), children = t.childMenuItems(), diff = newDepth - depth, subItemText = t.find('.is-submenu'); // Change .menu-item-depth-n class. t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId(); // If it has children, move those too. if ( children ) { children.each(function() { var t = $(this), thisDepth = t.menuItemDepth(), newDepth = thisDepth + diff; t.updateDepthClass(newDepth, thisDepth).updateParentMenuItemDBId(); }); } // Show "Sub item" helper text. if (0 === newDepth) subItemText.hide(); else subItemText.show(); }); }, updateParentMenuItemDBId : function() { return this.each(function(){ var item = $(this), input = item.find( '.menu-item-data-parent-id' ), depth = parseInt( item.menuItemDepth(), 10 ), parentDepth = depth - 1, parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first(); if ( 0 === depth ) { // Item is on the top level, has no parent. input.val(0); } else { // Find the parent item, and retrieve its object id. input.val( parent.find( '.menu-item-data-db-id' ).val() ); } }); }, hideAdvancedMenuItemFields : function() { return this.each(function(){ var that = $(this); $('.hide-column-tog').not(':checked').each(function(){ that.find('.field-' + $(this).val() ).addClass('hidden-field'); }); }); }, /** * Adds selected menu items to the menu. * * @ignore * * @param jQuery metabox The metabox jQuery object. */ addSelectedToMenu : function(processMethod) { if ( 0 === $('#menu-to-edit').length ) { return false; } return this.each(function() { var t = $(this), menuItems = {}, checkboxes = ( menus.oneThemeLocationNoMenus && 0 === t.find( '.tabs-panel-active .categorychecklist li input:checked' ).length ) ? t.find( '#page-all li input[type="checkbox"]' ) : t.find( '.tabs-panel-active .categorychecklist li input:checked' ), re = /menu-item\[([^\]]*)/; processMethod = processMethod || api.addMenuItemToBottom; // If no items are checked, bail. if ( !checkboxes.length ) return false; // Show the Ajax spinner. t.find( '.button-controls .spinner' ).addClass( 'is-active' ); // Retrieve menu item data. $(checkboxes).each(function(){ var t = $(this), listItemDBIDMatch = re.exec( t.attr('name') ), listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); if ( this.className && -1 != this.className.indexOf('add-to-top') ) processMethod = api.addMenuItemToTop; menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID ); }); // Add the items. api.addItemToMenu(menuItems, processMethod, function(){ // Deselect the items and hide the Ajax spinner. checkboxes.prop( 'checked', false ); t.find( '.button-controls .select-all' ).prop( 'checked', false ); t.find( '.button-controls .spinner' ).removeClass( 'is-active' ); t.updateParentDropdown(); t.updateOrderDropdown(); }); }); }, getItemData : function( itemType, id ) { itemType = itemType || 'menu-item'; var itemData = {}, i, fields = [ 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ]; if( !id && itemType == 'menu-item' ) { id = this.find('.menu-item-data-db-id').val(); } if( !id ) return itemData; this.find('input').each(function() { var field; i = fields.length; while ( i-- ) { if( itemType == 'menu-item' ) field = fields[i] + '[' + id + ']'; else if( itemType == 'add-menu-item' ) field = 'menu-item[' + id + '][' + fields[i] + ']'; if ( this.name && field == this.name ) { itemData[fields[i]] = this.value; } } }); return itemData; }, setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id. itemType = itemType || 'menu-item'; if( !id && itemType == 'menu-item' ) { id = $('.menu-item-data-db-id', this).val(); } if( !id ) return this; this.find('input').each(function() { var t = $(this), field; $.each( itemData, function( attr, val ) { if( itemType == 'menu-item' ) field = attr + '[' + id + ']'; else if( itemType == 'add-menu-item' ) field = 'menu-item[' + id + '][' + attr + ']'; if ( field == t.attr('name') ) { t.val( val ); } }); }); return this; }, updateParentDropdown : function() { return this.each(function(){ var menuItems = $( '#menu-to-edit li' ), parentDropdowns = $( '.edit-menu-item-parent' ); $.each( parentDropdowns, function() { var parentDropdown = $( this ), $html = '', $selected = '', currentItemID = parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-db-id' ).val(), currentparentID = parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-parent-id' ).val(), currentItem = parentDropdown.closest( 'li.menu-item' ), currentMenuItemChild = currentItem.childMenuItems(), excludeMenuItem = [ currentItemID ]; if ( currentMenuItemChild.length > 0 ) { $.each( currentMenuItemChild, function(){ var childItem = $(this), childID = childItem.find( '.menu-item-data-db-id' ).val(); excludeMenuItem.push( childID ); }); } if ( currentparentID == 0 ) { $selected = 'selected'; } $html += ''; $.each( menuItems, function() { var menuItem = $(this), $selected = '', menuID = menuItem.find( '.menu-item-data-db-id' ).val(), menuTitle = menuItem.find( '.edit-menu-item-title' ).val(); if ( ! excludeMenuItem.includes( menuID ) ) { if ( currentparentID == menuID ) { $selected = 'selected'; } $html += ''; } }); parentDropdown.html( $html ); }); }); }, updateOrderDropdown : function() { return this.each( function() { var itemPosition, orderDropdowns = $( '.edit-menu-item-order' ); $.each( orderDropdowns, function() { var orderDropdown = $( this ), menuItem = orderDropdown.closest( 'li.menu-item' ).first(), depth = menuItem.menuItemDepth(), isPrimaryMenuItem = ( 0 === depth ), $html = '', $selected = ''; if ( isPrimaryMenuItem ) { var primaryItems = $( '.menu-item-depth-0' ), totalMenuItems = primaryItems.length; itemPosition = primaryItems.index( menuItem ) + 1; for ( let i = 1; i < totalMenuItems + 1; i++ ) { $selected = ''; if ( i == itemPosition ) { $selected = 'selected'; } var itemString = wp.i18n.sprintf( /* translators: 1: The current menu item number, 2: The total number of menu items. */ wp.i18n._x( '%1$s of %2$s', 'part of a total number of menu items' ), i, totalMenuItems ); $html += ''; } } else { var parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(), parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(), subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ), totalSubMenuItems = subItems.length; itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; for ( let i = 1; i < totalSubMenuItems + 1; i++ ) { $selected = ''; if ( i == itemPosition ) { $selected = 'selected'; } var submenuString = wp.i18n.sprintf( /* translators: 1: The current submenu item number, 2: The total number of submenu items. */ wp.i18n._x( '%1$s of %2$s', 'part of a total number of menu items' ), i, totalSubMenuItems ); $html += ''; } } orderDropdown.html( $html ); }); }); } }); }, countMenuItems : function( depth ) { return $( '.menu-item-depth-' + depth ).length; }, moveMenuItem : function( $this, dir ) { var items, newItemPosition, newDepth, menuItems = $( '#menu-to-edit li' ), menuItemsCount = menuItems.length, thisItem = $this.parents( 'li.menu-item' ), thisItemChildren = thisItem.childMenuItems(), thisItemData = thisItem.getItemData(), thisItemDepth = parseInt( thisItem.menuItemDepth(), 10 ), thisItemPosition = parseInt( thisItem.index(), 10 ), nextItem = thisItem.next(), nextItemChildren = nextItem.childMenuItems(), nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1, prevItem = thisItem.prev(), prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ), prevItemId = prevItem.getItemData()['menu-item-db-id'], a11ySpeech = menus[ 'moved' + dir.charAt(0).toUpperCase() + dir.slice(1) ]; switch ( dir ) { case 'up': newItemPosition = thisItemPosition - 1; // Already at top. if ( 0 === thisItemPosition ) break; // If a sub item is moved to top, shift it to 0 depth. if ( 0 === newItemPosition && 0 !== thisItemDepth ) thisItem.moveHorizontally( 0, thisItemDepth ); // If prev item is sub item, shift to match depth. if ( 0 !== prevItemDepth ) thisItem.moveHorizontally( prevItemDepth, thisItemDepth ); // Does this item have sub items? if ( thisItemChildren ) { items = thisItem.add( thisItemChildren ); // Move the entire block. items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId(); } else { thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId(); } break; case 'down': // Does this item have sub items? if ( thisItemChildren ) { items = thisItem.add( thisItemChildren ), nextItem = menuItems.eq( items.length + thisItemPosition ), nextItemChildren = 0 !== nextItem.childMenuItems().length; if ( nextItemChildren ) { newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1; thisItem.moveHorizontally( newDepth, thisItemDepth ); } // Have we reached the bottom? if ( menuItemsCount === thisItemPosition + items.length ) break; items.detach().insertAfter( menuItems.eq( thisItemPosition + items.length ) ).updateParentMenuItemDBId(); } else { // If next item has sub items, shift depth. if ( 0 !== nextItemChildren.length ) thisItem.moveHorizontally( nextItemDepth, thisItemDepth ); // Have we reached the bottom? if ( menuItemsCount === thisItemPosition + 1 ) break; thisItem.detach().insertAfter( menuItems.eq( thisItemPosition + 1 ) ).updateParentMenuItemDBId(); } break; case 'top': // Already at top. if ( 0 === thisItemPosition ) break; // Does this item have sub items? if ( thisItemChildren ) { items = thisItem.add( thisItemChildren ); // Move the entire block. items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId(); } else { thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId(); } break; case 'left': // As far left as possible. if ( 0 === thisItemDepth ) break; thisItem.shiftHorizontally( -1 ); break; case 'right': // Can't be sub item at top. if ( 0 === thisItemPosition ) break; // Already sub item of prevItem. if ( thisItemData['menu-item-parent-id'] === prevItemId ) break; thisItem.shiftHorizontally( 1 ); break; } $this.trigger( 'focus' ); api.registerChange(); api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); thisItem.updateParentDropdown(); thisItem.updateOrderDropdown(); if ( a11ySpeech ) { wp.a11y.speak( a11ySpeech ); } }, initAccessibility : function() { var menu = $( '#menu-to-edit' ); api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); // Refresh the accessibility when the user comes close to the item in any way. menu.on( 'mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility' , '.menu-item' , function(){ api.refreshAdvancedAccessibilityOfItem( $( this ).find( 'a.item-edit' ) ); } ); // We have to update on click as well because we might hover first, change the item, and then click. menu.on( 'click', 'a.item-edit', function() { api.refreshAdvancedAccessibilityOfItem( $( this ) ); } ); // Links for moving items. menu.on( 'click', '.menus-move', function () { var $this = $( this ), dir = $this.data( 'dir' ); if ( 'undefined' !== typeof dir ) { api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), dir ); } }); // Set menu parents data for all menu items. menu.updateParentDropdown(); // Set menu order data for all menu items. menu.updateOrderDropdown(); // Update menu item parent when value is changed. menu.on( 'change', '.edit-menu-item-parent', function() { api.changeMenuParent( $( this ) ); }); // Update menu item order when value is changed. menu.on( 'change', '.edit-menu-item-order', function() { api.changeMenuOrder( $( this ) ); }); }, /** * changeMenuParent( [parentDropdown] ) * * @since 6.7.0 * * @param {object} parentDropdown select field */ changeMenuParent : function( parentDropdown ) { var menuItemNewPosition, menuItems = $( '#menu-to-edit li' ), $this = $( parentDropdown ), newParentID = $this.val(), menuItem = $this.closest( 'li.menu-item' ).first(), menuItemOldDepth = menuItem.menuItemDepth(), menuItemChildren = menuItem.childMenuItems(), menuItemNoChildren = parseInt( menuItem.childMenuItems().length, 10 ), parentItem = $( '#menu-item-' + newParentID ), parentItemDepth = parentItem.menuItemDepth(), menuItemNewDepth = parseInt( parentItemDepth ) + 1; if ( newParentID == 0 ) { menuItemNewDepth = 0; } menuItem.find( '.menu-item-data-parent-id' ).val( newParentID ); menuItem.moveHorizontally( menuItemNewDepth, menuItemOldDepth ); if ( menuItemNoChildren > 0 ) { menuItem = menuItem.add( menuItemChildren ); } menuItem.detach(); menuItems = $( '#menu-to-edit li' ); var parentItemPosition = parseInt( parentItem.index(), 10 ), parentItemNoChild = parseInt( parentItem.childMenuItems().length, 10 ); if ( parentItemNoChild > 0 ){ menuItemNewPosition = parentItemPosition + parentItemNoChild; } else { menuItemNewPosition = parentItemPosition; } if ( newParentID == 0 ) { menuItemNewPosition = menuItems.length - 1; } menuItem.insertAfter( menuItems.eq( menuItemNewPosition ) ).updateParentMenuItemDBId().updateParentDropdown().updateOrderDropdown(); api.registerChange(); api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); $this.trigger( 'focus' ); wp.a11y.speak( menus.parentUpdated, 'polite' ); }, /** * changeMenuOrder( [OrderDropdown] ) * * @since 6.7.0 * * @param {object} orderDropdown select field */ changeMenuOrder : function( orderDropdown ) { var menuItems = $( '#menu-to-edit li' ), $this = $( orderDropdown ), newOrderID = parseInt( $this.val(), 10), menuItem = $this.closest( 'li.menu-item' ).first(), menuItemChildren = menuItem.childMenuItems(), menuItemNoChildren = menuItemChildren.length, menuItemCurrentPosition = parseInt( menuItem.index(), 10 ), parentItemID = menuItem.find( '.menu-item-data-parent-id' ).val(), subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemID + '"]' ), currentItemAtPosition = $(subItems[newOrderID - 1]).closest( 'li.menu-item' ); if ( menuItemNoChildren > 0 ) { menuItem = menuItem.add( menuItemChildren ); } var currentItemNoChildren = currentItemAtPosition.childMenuItems().length, currentItemPosition = parseInt( currentItemAtPosition.index(), 10 ); menuItems = $( '#menu-to-edit li' ); var menuItemNewPosition = currentItemPosition; if(menuItemCurrentPosition > menuItemNewPosition){ menuItemNewPosition = currentItemPosition; menuItem.detach().insertBefore( menuItems.eq( menuItemNewPosition ) ).updateOrderDropdown(); } else { menuItemNewPosition = menuItemNewPosition + currentItemNoChildren; menuItem.detach().insertAfter( menuItems.eq( menuItemNewPosition ) ).updateOrderDropdown(); } api.registerChange(); api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); $this.trigger( 'focus' ); wp.a11y.speak( menus.orderUpdated, 'polite' ); }, /** * refreshAdvancedAccessibilityOfItem( [itemToRefresh] ) * * Refreshes advanced accessibility buttons for one menu item. * Shows or hides buttons based on the location of the menu item. * * @param {Object} itemToRefresh The menu item that might need its advanced accessibility buttons refreshed */ refreshAdvancedAccessibilityOfItem : function( itemToRefresh ) { // Only refresh accessibility when necessary. if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) { return; } var thisLink, thisLinkText, primaryItems, itemPosition, title, parentItem, parentItemId, parentItemName, subItems, totalSubItems, $this = $( itemToRefresh ), menuItem = $this.closest( 'li.menu-item' ).first(), depth = menuItem.menuItemDepth(), isPrimaryMenuItem = ( 0 === depth ), itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(), menuItemType = $this.closest( '.menu-item-handle' ).find( '.item-controls' ).find( '.item-type' ).text(), position = parseInt( menuItem.index(), 10 ), prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ), prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(), prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(), totalMenuItems = $('#menu-to-edit li').length, hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length; menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 ); // Where can they move this menu item? if ( 0 !== position ) { thisLink = menuItem.find( '.menus-move-up' ); thisLink.attr( 'aria-label', menus.moveUp ).css( 'display', 'inline' ); } if ( 0 !== position && isPrimaryMenuItem ) { thisLink = menuItem.find( '.menus-move-top' ); thisLink.attr( 'aria-label', menus.moveToTop ).css( 'display', 'inline' ); } if ( position + 1 !== totalMenuItems && 0 !== position ) { thisLink = menuItem.find( '.menus-move-down' ); thisLink.attr( 'aria-label', menus.moveDown ).css( 'display', 'inline' ); } if ( 0 === position && 0 !== hasSameDepthSibling ) { thisLink = menuItem.find( '.menus-move-down' ); thisLink.attr( 'aria-label', menus.moveDown ).css( 'display', 'inline' ); } if ( ! isPrimaryMenuItem ) { thisLink = menuItem.find( '.menus-move-left' ), thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft ); thisLink.attr( 'aria-label', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).text( thisLinkText ).css( 'display', 'inline' ); } if ( 0 !== position ) { if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) { thisLink = menuItem.find( '.menus-move-right' ), thisLinkText = menus.under.replace( '%s', prevItemNameRight ); thisLink.attr( 'aria-label', menus.moveUnder.replace( '%s', prevItemNameRight ) ).text( thisLinkText ).css( 'display', 'inline' ); } } if ( isPrimaryMenuItem ) { primaryItems = $( '.menu-item-depth-0' ), itemPosition = primaryItems.index( menuItem ) + 1, totalMenuItems = primaryItems.length, // String together help text for primary menu items. title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalMenuItems ); } else { parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(), parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(), parentItemName = parentItem.find( '.menu-item-title' ).text(), subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ), totalSubItems = subItems.length, itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; // String together help text for sub menu items. if ( depth < 2 ) { title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalSubItems ).replace( '%5$s', parentItemName ); } else { title = menus.subMenuMoreDepthFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalSubItems ).replace( '%5$s', parentItemName ).replace( '%6$d', depth ); } } $this.attr( 'aria-label', title ); // Mark this item's accessibility as refreshed. $this.data( 'needs_accessibility_refresh', false ); }, /** * refreshAdvancedAccessibility * * Hides all advanced accessibility buttons and marks them for refreshing. */ refreshAdvancedAccessibility : function() { // Hide all the move buttons by default. $( '.menu-item-settings .field-move .menus-move' ).hide(); // Mark all menu items as unprocessed. $( 'a.item-edit' ).data( 'needs_accessibility_refresh', true ); // All open items have to be refreshed or they will show no links. $( '.menu-item-edit-active a.item-edit' ).each( function() { api.refreshAdvancedAccessibilityOfItem( this ); } ); }, refreshKeyboardAccessibility : function() { $( 'a.item-edit' ).off( 'focus' ).on( 'focus', function(){ $(this).off( 'keydown' ).on( 'keydown', function(e){ var arrows, $this = $( this ), thisItem = $this.parents( 'li.menu-item' ), thisItemData = thisItem.getItemData(); // Bail if it's not an arrow key. if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which ) return; // Avoid multiple keydown events. $this.off('keydown'); // Bail if there is only one menu item. if ( 1 === $('#menu-to-edit li').length ) return; // If RTL, swap left/right arrows. arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' }; if ( $('body').hasClass('rtl') ) arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' }; switch ( arrows[e.which] ) { case 'up': api.moveMenuItem( $this, 'up' ); break; case 'down': api.moveMenuItem( $this, 'down' ); break; case 'left': api.moveMenuItem( $this, 'left' ); break; case 'right': api.moveMenuItem( $this, 'right' ); break; } // Put focus back on same menu item. $( '#edit-' + thisItemData['menu-item-db-id'] ).trigger( 'focus' ); return false; }); }); }, initPreviewing : function() { // Update the item handle title when the navigation label is changed. $( '#menu-to-edit' ).on( 'change input', '.edit-menu-item-title', function(e) { var input = $( e.currentTarget ), title, titleEl; title = input.val(); titleEl = input.closest( '.menu-item' ).find( '.menu-item-title' ); // Don't update to empty title. if ( title ) { titleEl.text( title ).removeClass( 'no-title' ); } else { titleEl.text( wp.i18n._x( '(no label)', 'missing menu item navigation label' ) ).addClass( 'no-title' ); } } ); }, initToggles : function() { // Init postboxes. postboxes.add_postbox_toggles('nav-menus'); // Adjust columns functions for menus UI. columns.useCheckboxesForHidden(); columns.checked = function(field) { $('.field-' + field).removeClass('hidden-field'); }; columns.unchecked = function(field) { $('.field-' + field).addClass('hidden-field'); }; // Hide fields. api.menuList.hideAdvancedMenuItemFields(); $('.hide-postbox-tog').on( 'click', function () { var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(','); $.post(ajaxurl, { action: 'closed-postboxes', hidden: hidden, closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), page: 'nav-menus' }); }); }, initSortables : function() { var currentDepth = 0, originalDepth, minDepth, maxDepth, prev, next, prevBottom, nextThreshold, helperHeight, transport, menuEdge = api.menuList.offset().left, body = $('body'), maxChildDepth, menuMaxDepth = initialMenuMaxDepth(); if( 0 !== $( '#menu-to-edit li' ).length ) $( '.drag-instructions' ).show(); // Use the right edge if RTL. menuEdge += api.isRTL ? api.menuList.width() : 0; api.menuList.sortable({ handle: '.menu-item-handle', placeholder: 'sortable-placeholder', items: api.options.sortableItems, start: function(e, ui) { var height, width, parent, children, tempHolder; // Handle placement for RTL orientation. if ( api.isRTL ) ui.item[0].style.right = 'auto'; transport = ui.item.children('.menu-item-transport'); // Set depths. currentDepth must be set before children are located. originalDepth = ui.item.menuItemDepth(); updateCurrentDepth(ui, originalDepth); // Attach child elements to parent. // Skip the placeholder. parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item; children = parent.childMenuItems(); transport.append( children ); // Update the height of the placeholder to match the moving item. height = transport.outerHeight(); // If there are children, account for distance between top of children and parent. height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0; height += ui.helper.outerHeight(); helperHeight = height; height -= 2; // Subtract 2 for borders. ui.placeholder.height(height); // Update the width of the placeholder to match the moving item. maxChildDepth = originalDepth; children.each(function(){ var depth = $(this).menuItemDepth(); maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth; }); width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width. width += api.depthToPx(maxChildDepth - originalDepth); // Account for children. width -= 2; // Subtract 2 for borders. ui.placeholder.width(width); // Update the list of menu items. tempHolder = ui.placeholder.next( '.menu-item' ); tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder. ui.placeholder.detach(); // Detach or jQuery UI will think the placeholder is a menu item. $(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQuery UI know. ui.item.after( ui.placeholder ); // Reattach the placeholder. tempHolder.css('margin-top', 0); // Reset the margin. // Now that the element is complete, we can update... updateSharedVars(ui); }, stop: function(e, ui) { var children, subMenuTitle, depthChange = currentDepth - originalDepth; // Return child elements to the list. children = transport.children().insertAfter(ui.item); // Add "sub menu" description. subMenuTitle = ui.item.find( '.item-title .is-submenu' ); if ( 0 < currentDepth ) subMenuTitle.show(); else subMenuTitle.hide(); // Update depth classes. if ( 0 !== depthChange ) { ui.item.updateDepthClass( currentDepth ); children.shiftDepthClass( depthChange ); updateMenuMaxDepth( depthChange ); } // Register a change. api.registerChange(); // Update the item data. ui.item.updateParentMenuItemDBId(); // Address sortable's incorrectly-calculated top in Opera. ui.item[0].style.top = 0; // Handle drop placement for rtl orientation. if ( api.isRTL ) { ui.item[0].style.left = 'auto'; ui.item[0].style.right = 0; } api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); ui.item.updateParentDropdown(); ui.item.updateOrderDropdown(); api.refreshAdvancedAccessibilityOfItem( ui.item.find( 'a.item-edit' ) ); }, change: function(e, ui) { // Make sure the placeholder is inside the menu. // Otherwise fix it, or we're in trouble. if( ! ui.placeholder.parent().hasClass('menu') ) (prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder ); updateSharedVars(ui); }, sort: function(e, ui) { var offset = ui.helper.offset(), edge = api.isRTL ? offset.left + ui.helper.width() : offset.left, depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge ); /* * Check and correct if depth is not within range. * Also, if the dragged element is dragged upwards over an item, * shift the placeholder to a child position. */ if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) { depth = maxDepth; } else if ( depth < minDepth ) { depth = minDepth; } if( depth != currentDepth ) updateCurrentDepth(ui, depth); // If we overlap the next element, manually shift downwards. if( nextThreshold && offset.top + helperHeight > nextThreshold ) { next.after( ui.placeholder ); updateSharedVars( ui ); $( this ).sortable( 'refreshPositions' ); } } }); function updateSharedVars(ui) { var depth; prev = ui.placeholder.prev( '.menu-item' ); next = ui.placeholder.next( '.menu-item' ); // Make sure we don't select the moving item. if( prev[0] == ui.item[0] ) prev = prev.prev( '.menu-item' ); if( next[0] == ui.item[0] ) next = next.next( '.menu-item' ); prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0; nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0; minDepth = (next.length) ? next.menuItemDepth() : 0; if( prev.length ) maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth; else maxDepth = 0; } function updateCurrentDepth(ui, depth) { ui.placeholder.updateDepthClass( depth, currentDepth ); currentDepth = depth; } function initialMenuMaxDepth() { if( ! body[0].className ) return 0; var match = body[0].className.match(/menu-max-depth-(\d+)/); return match && match[1] ? parseInt( match[1], 10 ) : 0; } function updateMenuMaxDepth( depthChange ) { var depth, newDepth = menuMaxDepth; if ( depthChange === 0 ) { return; } else if ( depthChange > 0 ) { depth = maxChildDepth + depthChange; if( depth > menuMaxDepth ) newDepth = depth; } else if ( depthChange < 0 && maxChildDepth == menuMaxDepth ) { while( ! $('.menu-item-depth-' + newDepth, api.menuList).length && newDepth > 0 ) newDepth--; } // Update the depth class. body.removeClass( 'menu-max-depth-' + menuMaxDepth ).addClass( 'menu-max-depth-' + newDepth ); menuMaxDepth = newDepth; } }, initManageLocations : function () { $('#menu-locations-wrap form').on( 'submit', function(){ window.onbeforeunload = null; }); $('.menu-location-menus select').on('change', function () { var editLink = $(this).closest('tr').find('.locations-edit-menu-link'); if ($(this).find('option:selected').data('orig')) editLink.show(); else editLink.hide(); }); }, attachMenuEditListeners : function() { var that = this; $('#update-nav-menu').on('click', function(e) { if ( e.target && e.target.className ) { if ( -1 != e.target.className.indexOf('item-edit') ) { return that.eventOnClickEditLink(e.target); } else if ( -1 != e.target.className.indexOf('menu-save') ) { return that.eventOnClickMenuSave(e.target); } else if ( -1 != e.target.className.indexOf('menu-delete') ) { return that.eventOnClickMenuDelete(e.target); } else if ( -1 != e.target.className.indexOf('item-delete') ) { return that.eventOnClickMenuItemDelete(e.target); } else if ( -1 != e.target.className.indexOf('item-cancel') ) { return that.eventOnClickCancelLink(e.target); } } }); $( '#menu-name' ).on( 'input', _.debounce( function () { var menuName = $( document.getElementById( 'menu-name' ) ), menuNameVal = menuName.val(); if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { // Add warning for invalid menu name. menuName.parent().addClass( 'form-invalid' ); } else { // Remove warning for valid menu name. menuName.parent().removeClass( 'form-invalid' ); } }, 500 ) ); $('#add-custom-links input[type="text"]').on( 'keypress', function(e){ $( '#customlinkdiv' ).removeClass( 'form-invalid' ); $( '#custom-menu-item-url' ).removeAttr( 'aria-invalid' ).removeAttr( 'aria-describedby' ); $( '#custom-url-error' ).hide(); if ( e.keyCode === 13 ) { e.preventDefault(); $( '#submit-customlinkdiv' ).trigger( 'click' ); } }); $( '#submit-customlinkdiv' ).on( 'click', function (e) { var urlInput = $( '#custom-menu-item-url' ), url = urlInput.val().trim(), errorMessage = $( '#custom-url-error' ), urlWrap = $( '#menu-item-url-wrap' ), urlRegex; // Hide the error message initially errorMessage.hide(); urlWrap.removeClass( 'has-error' ); /* * Allow URLs including: * - http://example.com/ * - //example.com * - /directory/ * - ?query-param * - #target * - mailto:foo@example.com * * Any further validation will be handled on the server when the setting is attempted to be saved, * so this pattern does not need to be complete. */ urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/; if ( ! urlRegex.test( url ) ) { e.preventDefault(); urlInput.addClass( 'form-invalid' ) .attr( 'aria-invalid', 'true' ) .attr( 'aria-describedby', 'custom-url-error' ); errorMessage.show(); var errorText = errorMessage.text(); urlWrap.addClass( 'has-error' ); // Announce error message via screen reader wp.a11y.speak( errorText, 'assertive' ); } }); }, /** * Handle toggling bulk selection checkboxes for menu items. * * @since 5.8.0 */ attachBulkSelectButtonListeners : function() { var that = this; $( '.bulk-select-switcher' ).on( 'change', function() { if ( this.checked ) { $( '.bulk-select-switcher' ).prop( 'checked', true ); that.enableBulkSelection(); } else { $( '.bulk-select-switcher' ).prop( 'checked', false ); that.disableBulkSelection(); } }); }, /** * Enable bulk selection checkboxes for menu items. * * @since 5.8.0 */ enableBulkSelection : function() { var checkbox = $( '#menu-to-edit .menu-item-checkbox' ); $( '#menu-to-edit' ).addClass( 'bulk-selection' ); $( '#nav-menu-bulk-actions-top' ).addClass( 'bulk-selection' ); $( '#nav-menu-bulk-actions-bottom' ).addClass( 'bulk-selection' ); $.each( checkbox, function() { $(this).prop( 'disabled', false ); }); }, /** * Disable bulk selection checkboxes for menu items. * * @since 5.8.0 */ disableBulkSelection : function() { var checkbox = $( '#menu-to-edit .menu-item-checkbox' ); $( '#menu-to-edit' ).removeClass( 'bulk-selection' ); $( '#nav-menu-bulk-actions-top' ).removeClass( 'bulk-selection' ); $( '#nav-menu-bulk-actions-bottom' ).removeClass( 'bulk-selection' ); if ( $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) { $( '.menu-items-delete' ).removeAttr( 'aria-describedby' ); } $.each( checkbox, function() { $(this).prop( 'disabled', true ).prop( 'checked', false ); }); $( '.menu-items-delete' ).addClass( 'disabled' ); $( '#pending-menu-items-to-delete ul' ).empty(); }, /** * Listen for state changes on bulk action checkboxes. * * @since 5.8.0 */ attachMenuCheckBoxListeners : function() { var that = this; $( '#menu-to-edit' ).on( 'change', '.menu-item-checkbox', function() { that.setRemoveSelectedButtonStatus(); }); }, /** * Create delete button to remove menu items from collection. * * @since 5.8.0 */ attachMenuItemDeleteButton : function() { var that = this; $( document ).on( 'click', '.menu-items-delete', function( e ) { var itemsPendingDeletion, itemsPendingDeletionList, deletionSpeech; e.preventDefault(); if ( ! $(this).hasClass( 'disabled' ) ) { $.each( $( '.menu-item-checkbox:checked' ), function( index, element ) { $( element ).parents( 'li' ).find( 'a.item-delete' ).trigger( 'click' ); }); $( '.menu-items-delete' ).addClass( 'disabled' ); $( '.bulk-select-switcher' ).prop( 'checked', false ); itemsPendingDeletion = ''; itemsPendingDeletionList = $( '#pending-menu-items-to-delete ul li' ); $.each( itemsPendingDeletionList, function( index, element ) { var itemName = $( element ).find( '.pending-menu-item-name' ).text(); var itemSpeech = menus.menuItemDeletion.replace( '%s', itemName ); itemsPendingDeletion += itemSpeech; if ( ( index + 1 ) < itemsPendingDeletionList.length ) { itemsPendingDeletion += ', '; } }); deletionSpeech = menus.itemsDeleted.replace( '%s', itemsPendingDeletion ); wp.a11y.speak( deletionSpeech, 'polite' ); that.disableBulkSelection(); $( '#menu-to-edit' ).updateParentDropdown(); $( '#menu-to-edit' ).updateOrderDropdown(); } }); }, /** * List menu items awaiting deletion. * * @since 5.8.0 */ attachPendingMenuItemsListForDeletion : function() { $( '#post-body-content' ).on( 'change', '.menu-item-checkbox', function() { var menuItemName, menuItemType, menuItemID, listedMenuItem; if ( ! $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) { $( '.menu-items-delete' ).attr( 'aria-describedby', 'pending-menu-items-to-delete' ); } menuItemName = $(this).next().text(); menuItemType = $(this).parent().next( '.item-controls' ).find( '.item-type' ).text(); menuItemID = $(this).attr( 'data-menu-item-id' ); listedMenuItem = $( '#pending-menu-items-to-delete ul' ).find( '[data-menu-item-id=' + menuItemID + ']' ); if ( listedMenuItem.length > 0 ) { listedMenuItem.remove(); } if ( this.checked === true ) { $( '#pending-menu-items-to-delete ul' ).append( '
  • ' + '' + menuItemName + ' ' + '(' + menuItemType + ')' + '' + '
  • ' ); } $( '#pending-menu-items-to-delete li .separator' ).html( ', ' ); $( '#pending-menu-items-to-delete li .separator' ).last().html( '.' ); }); }, /** * Set status of bulk delete checkbox. * * @since 5.8.0 */ setBulkDeleteCheckboxStatus : function() { var that = this; var checkbox = $( '#menu-to-edit .menu-item-checkbox' ); $.each( checkbox, function() { if ( $(this).prop( 'disabled' ) ) { $(this).prop( 'disabled', false ); } else { $(this).prop( 'disabled', true ); } if ( $(this).is( ':checked' ) ) { $(this).prop( 'checked', false ); } }); that.setRemoveSelectedButtonStatus(); }, /** * Set status of menu items removal button. * * @since 5.8.0 */ setRemoveSelectedButtonStatus : function() { var button = $( '.menu-items-delete' ); if ( $( '.menu-item-checkbox:checked' ).length > 0 ) { button.removeClass( 'disabled' ); } else { button.addClass( 'disabled' ); } }, attachMenuSaveSubmitListeners : function() { /* * When a navigation menu is saved, store a JSON representation of all form data * in a single input to avoid PHP `max_input_vars` limitations. See #14134. */ $( '#update-nav-menu' ).on( 'submit', function() { var navMenuData = $( '#update-nav-menu' ).serializeArray(); $( '[name="nav-menu-data"]' ).val( JSON.stringify( navMenuData ) ); }); }, attachThemeLocationsListeners : function() { var loc = $('#nav-menu-theme-locations'), params = {}; params.action = 'menu-locations-save'; params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val(); loc.find('input[type="submit"]').on( 'click', function() { loc.find('select').each(function() { params[this.name] = $(this).val(); }); loc.find( '.spinner' ).addClass( 'is-active' ); $.post( ajaxurl, params, function() { loc.find( '.spinner' ).removeClass( 'is-active' ); }); return false; }); }, attachQuickSearchListeners : function() { var searchTimer; // Prevent form submission. $( '#nav-menu-meta' ).on( 'submit', function( event ) { event.preventDefault(); }); $( '#nav-menu-meta' ).on( 'input', '.quick-search', function() { var $this = $( this ); $this.attr( 'autocomplete', 'off' ); if ( searchTimer ) { clearTimeout( searchTimer ); } searchTimer = setTimeout( function() { api.updateQuickSearchResults( $this ); }, 500 ); }).on( 'blur', '.quick-search', function() { api.lastSearch = ''; }); }, updateQuickSearchResults : function(input) { var panel, params, minSearchLength = 2, q = input.val(); /* * Minimum characters for a search. Also avoid a new Ajax search when * the pressed key (e.g. arrows) doesn't change the searched term. */ if ( q.length < minSearchLength || api.lastSearch == q ) { return; } api.lastSearch = q; panel = input.parents('.tabs-panel'); params = { 'action': 'menu-quick-search', 'response-format': 'markup', 'menu': $('#menu').val(), 'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(), 'q': q, 'type': input.attr('name') }; $( '.spinner', panel ).addClass( 'is-active' ); $.post( ajaxurl, params, function(menuMarkup) { api.processQuickSearchQueryResponse(menuMarkup, params, panel); }); }, addCustomLink : function( processMethod ) { var url = $('#custom-menu-item-url').val().toString(), label = $('#custom-menu-item-name').val(), urlRegex; if ( '' !== url ) { url = url.trim(); } processMethod = processMethod || api.addMenuItemToBottom; /* * Allow URLs including: * - http://example.com/ * - //example.com * - /directory/ * - ?query-param * - #target * - mailto:foo@example.com * * Any further validation will be handled on the server when the setting is attempted to be saved, * so this pattern does not need to be complete. */ urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/; if ( ! urlRegex.test( url ) ) { $('#customlinkdiv').addClass('form-invalid'); return false; } // Show the Ajax spinner. $( '.customlinkdiv .spinner' ).addClass( 'is-active' ); this.addLinkToMenu( url, label, processMethod, function() { // Remove the Ajax spinner. $( '.customlinkdiv .spinner' ).removeClass( 'is-active' ); // Set custom link form back to defaults. $('#custom-menu-item-name').val('').trigger( 'blur' ); $( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' ); }); }, addLinkToMenu : function(url, label, processMethod, callback) { processMethod = processMethod || api.addMenuItemToBottom; callback = callback || function(){}; api.addItemToMenu({ '-1': { 'menu-item-type': 'custom', 'menu-item-url': url, 'menu-item-title': label } }, processMethod, callback); }, addItemToMenu : function(menuItem, processMethod, callback) { var menu = $('#menu').val(), nonce = $('#menu-settings-column-nonce').val(), params; processMethod = processMethod || function(){}; callback = callback || function(){}; params = { 'action': 'add-menu-item', 'menu': menu, 'menu-settings-column-nonce': nonce, 'menu-item': menuItem }; $.post( ajaxurl, params, function(menuMarkup) { var ins = $('#menu-instructions'); menuMarkup = menuMarkup || ''; menuMarkup = menuMarkup.toString().trim(); // Trim leading whitespaces. processMethod(menuMarkup, params); // Make it stand out a bit more visually, by adding a fadeIn. $( 'li.pending' ).hide().fadeIn('slow'); $( '.drag-instructions' ).show(); if( ! ins.hasClass( 'menu-instructions-inactive' ) && ins.siblings().length ) ins.addClass( 'menu-instructions-inactive' ); callback(); }); }, /** * Process the add menu item request response into menu list item. Appends to menu. * * @param {string} menuMarkup The text server response of menu item markup. * * @fires document#menu-item-added Passes menuMarkup as a jQuery object. */ addMenuItemToBottom : function( menuMarkup ) { var $menuMarkup = $( menuMarkup ); $menuMarkup.hideAdvancedMenuItemFields().appendTo( api.targetList ); api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); wp.a11y.speak( menus.itemAdded ); $( document ).trigger( 'menu-item-added', [ $menuMarkup ] ); }, /** * Process the add menu item request response into menu list item. Prepends to menu. * * @param {string} menuMarkup The text server response of menu item markup. * * @fires document#menu-item-added Passes menuMarkup as a jQuery object. */ addMenuItemToTop : function( menuMarkup ) { var $menuMarkup = $( menuMarkup ); $menuMarkup.hideAdvancedMenuItemFields().prependTo( api.targetList ); api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); wp.a11y.speak( menus.itemAdded ); $( document ).trigger( 'menu-item-added', [ $menuMarkup ] ); }, attachUnsavedChangesListener : function() { $('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').on( 'change', function(){ api.registerChange(); }); if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) { window.onbeforeunload = function(){ if ( api.menusChanged ) return wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' ); }; } else { // Make the post boxes read-only, as they can't be used yet. $( '#menu-settings-column' ).find( 'input,select' ).end().find( 'a' ).attr( 'href', '#' ).off( 'click' ); } }, registerChange : function() { api.menusChanged = true; }, attachTabsPanelListeners : function() { $('#menu-settings-column').on('click', function(e) { var selectAreaMatch, selectAll, panelId, wrapper, items, target = $(e.target); if ( target.hasClass('nav-tab-link') ) { panelId = target.data( 'type' ); wrapper = target.parents('.accordion-section-content').first(); // Upon changing tabs, we want to uncheck all checkboxes. $( 'input', wrapper ).prop( 'checked', false ); $('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive'); $('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active'); $('.tabs', wrapper).removeClass('tabs'); target.parent().addClass('tabs'); // Select the search bar. $('.quick-search', wrapper).trigger( 'focus' ); // Hide controls in the search tab if no items found. if ( ! wrapper.find( '.tabs-panel-active .menu-item-title' ).length ) { wrapper.addClass( 'has-no-menu-item' ); } else { wrapper.removeClass( 'has-no-menu-item' ); } e.preventDefault(); } else if ( target.hasClass( 'select-all' ) ) { selectAreaMatch = target.closest( '.button-controls' ).data( 'items-type' ); if ( selectAreaMatch ) { items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' ); if ( items.length === items.filter( ':checked' ).length && ! target.is( ':checked' ) ) { items.prop( 'checked', false ); } else if ( target.is( ':checked' ) ) { items.prop( 'checked', true ); } } } else if ( target.hasClass( 'menu-item-checkbox' ) ) { selectAreaMatch = target.closest( '.tabs-panel-active' ).parent().attr( 'id' ); if ( selectAreaMatch ) { items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' ); selectAll = $( '.button-controls[data-items-type="' + selectAreaMatch + '"] .select-all' ); if ( items.length === items.filter( ':checked' ).length && ! selectAll.is( ':checked' ) ) { selectAll.prop( 'checked', true ); } else if ( selectAll.is( ':checked' ) ) { selectAll.prop( 'checked', false ); } } } else if ( target.hasClass('submit-add-to-menu') ) { api.registerChange(); if ( e.target.id && 'submit-customlinkdiv' == e.target.id ) api.addCustomLink( api.addMenuItemToBottom ); else if ( e.target.id && -1 != e.target.id.indexOf('submit-') ) $('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom ); return false; } }); /* * Delegate the `click` event and attach it just to the pagination * links thus excluding the current page ``. See ticket #35577. */ $( '#nav-menu-meta' ).on( 'click', 'a.page-numbers', function() { var $container = $( this ).closest( '.inside' ); $.post( ajaxurl, this.href.replace( /.*\?/, '' ).replace( /action=([^&]*)/, '' ) + '&action=menu-get-metabox', function( resp ) { var metaBoxData = JSON.parse( resp ), toReplace; if ( -1 === resp.indexOf( 'replace-id' ) ) { return; } // Get the post type menu meta box to update. toReplace = document.getElementById( metaBoxData['replace-id'] ); if ( ! metaBoxData.markup || ! toReplace ) { return; } // Update the post type menu meta box with new content from the response. $container.html( metaBoxData.markup ); } ); return false; }); }, eventOnClickEditLink : function(clickedEl) { var settings, item, matchedSection = /#(.*)$/.exec(clickedEl.href); if ( matchedSection && matchedSection[1] ) { settings = $('#'+matchedSection[1]); item = settings.parent(); if( 0 !== item.length ) { if( item.hasClass('menu-item-edit-inactive') ) { if( ! settings.data('menu-item-data') ) { settings.data( 'menu-item-data', settings.getItemData() ); } settings.slideDown('fast'); item.removeClass('menu-item-edit-inactive') .addClass('menu-item-edit-active'); } else { settings.slideUp('fast'); item.removeClass('menu-item-edit-active') .addClass('menu-item-edit-inactive'); } return false; } } }, eventOnClickCancelLink : function(clickedEl) { var settings = $( clickedEl ).closest( '.menu-item-settings' ), thisMenuItem = $( clickedEl ).closest( '.menu-item' ); thisMenuItem.removeClass( 'menu-item-edit-active' ).addClass( 'menu-item-edit-inactive' ); settings.setItemData( settings.data( 'menu-item-data' ) ).hide(); // Restore the title of the currently active/expanded menu item. thisMenuItem.find( '.menu-item-title' ).text( settings.data( 'menu-item-data' )['menu-item-title'] ); return false; }, eventOnClickMenuSave : function() { var locs = '', menuName = $('#menu-name'), menuNameVal = menuName.val(); // Cancel and warn if invalid menu name. if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { menuName.parent().addClass( 'form-invalid' ); return false; } // Copy menu theme locations. $('#nav-menu-theme-locations select').each(function() { locs += ''; }); $('#update-nav-menu').append( locs ); // Update menu item position data. api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } ); window.onbeforeunload = null; return true; }, eventOnClickMenuDelete : function() { // Delete warning AYS. if ( window.confirm( wp.i18n.__( 'You are about to permanently delete this menu.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) { window.onbeforeunload = null; return true; } return false; }, eventOnClickMenuItemDelete : function(clickedEl) { var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10); api.removeMenuItem( $('#menu-item-' + itemID) ); api.registerChange(); return false; }, /** * Process the quick search response into a search result * * @param string resp The server response to the query. * @param object req The request arguments. * @param jQuery panel The tabs panel we're searching in. */ processQuickSearchQueryResponse : function(resp, req, panel) { var matched, newID, takenIDs = {}, form = document.getElementById('nav-menu-meta'), pattern = /menu-item[(\[^]\]*/, $items = $('
    ').html(resp).find('li'), wrapper = panel.closest( '.accordion-section-content' ), selectAll = wrapper.find( '.button-controls .select-all' ), $item; if( ! $items.length ) { $('.categorychecklist', panel).html( '
  • ' + wp.i18n.__( 'No results found.' ) + '

  • ' ); $( '.spinner', panel ).removeClass( 'is-active' ); wrapper.addClass( 'has-no-menu-item' ); return; } $items.each(function(){ $item = $(this); // Make a unique DB ID number. matched = pattern.exec($item.html()); if ( matched && matched[1] ) { newID = matched[1]; while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) { newID--; } takenIDs[newID] = true; if ( newID != matched[1] ) { $item.html( $item.html().replace(new RegExp( 'menu-item\\[' + matched[1] + '\\]', 'g'), 'menu-item[' + newID + ']' ) ); } } }); $('.categorychecklist', panel).html( $items ); $( '.spinner', panel ).removeClass( 'is-active' ); wrapper.removeClass( 'has-no-menu-item' ); if ( selectAll.is( ':checked' ) ) { selectAll.prop( 'checked', false ); } }, /** * Remove a menu item. * * @param {Object} el The element to be removed as a jQuery object. * * @fires document#menu-removing-item Passes the element to be removed. */ removeMenuItem : function(el) { var children = el.childMenuItems(); $( document ).trigger( 'menu-removing-item', [ el ] ); el.addClass('deleting').animate({ opacity : 0, height: 0 }, 350, function() { var ins = $('#menu-instructions'); el.remove(); children.shiftDepthClass( -1 ).updateParentMenuItemDBId(); if ( 0 === $( '#menu-to-edit li' ).length ) { $( '.drag-instructions' ).hide(); ins.removeClass( 'menu-instructions-inactive' ); } api.refreshAdvancedAccessibility(); wp.a11y.speak( menus.itemRemoved ); $( '#menu-to-edit' ).updateParentDropdown(); $( '#menu-to-edit' ).updateOrderDropdown(); }); }, depthToPx : function(depth) { return depth * api.options.menuItemDepthPerLevel; }, pxToDepth : function(px) { return Math.floor(px / api.options.menuItemDepthPerLevel); } }; $( function() { wpNavMenu.init(); // Prevent focused element from being hidden by the sticky footer. $( '.menu-edit a, .menu-edit button, .menu-edit input, .menu-edit textarea, .menu-edit select' ).on('focus', function() { if ( window.innerWidth >= 783 ) { var navMenuHeight = $( '#nav-menu-footer' ).height() + 20; var bottomOffset = $(this).offset().top - ( $(window).scrollTop() + $(window).height() - $(this).height() ); if ( bottomOffset > 0 ) { bottomOffset = 0; } bottomOffset = bottomOffset * -1; if( bottomOffset < navMenuHeight ) { var scrollTop = $(document).scrollTop(); $(document).scrollTop( scrollTop + ( navMenuHeight - bottomOffset ) ); } } }); }); // Show bulk action. $( document ).on( 'menu-item-added', function() { if ( ! $( '.bulk-actions' ).is( ':visible' ) ) { $( '.bulk-actions' ).show(); } } ); // Hide bulk action. $( document ).on( 'menu-removing-item', function( e, el ) { var menuElement = $( el ).parents( '#menu-to-edit' ); if ( menuElement.find( 'li' ).length === 1 && $( '.bulk-actions' ).is( ':visible' ) ) { $( '.bulk-actions' ).hide(); } } ); })(jQuery); PK!W.llset-post-thumbnail.jsnu[/** * @output wp-admin/js/set-post-thumbnail.js */ /* global ajaxurl, post_id, alert */ /* exported WPSetAsThumbnail */ window.WPSetAsThumbnail = function( id, nonce ) { var $link = jQuery('a#wp-post-thumbnail-' + id); $link.text( wp.i18n.__( 'Saving…' ) ); jQuery.post(ajaxurl, { action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie ) }, function(str){ var win = window.dialogArguments || opener || parent || top; $link.text( wp.i18n.__( 'Use as featured image' ) ); if ( str == '0' ) { alert( wp.i18n.__( 'Could not set that as the thumbnail image. Try a different attachment.' ) ); } else { jQuery('a.wp-post-thumbnail').show(); $link.text( wp.i18n.__( 'Done' ) ); $link.fadeOut( 2000 ); win.WPSetThumbnailID(id); win.WPSetThumbnailHTML(str); } } ); }; PK!G cc site-icon.jsnu[/** * Handle the site icon setting in options-general.php. * * @since 6.5.0 * @output wp-admin/js/site-icon.js */ /* global jQuery, wp */ ( function ( $ ) { var $chooseButton = $( '#choose-from-library-button' ), $iconPreview = $( '#site-icon-preview' ), $browserIconPreview = $( '#browser-icon-preview' ), $appIconPreview = $( '#app-icon-preview' ), $hiddenDataField = $( '#site_icon_hidden_field' ), $removeButton = $( '#js-remove-site-icon' ), frame; /** * Calculate image selection options based on the attachment dimensions. * * @since 6.5.0 * * @param {Object} attachment The attachment object representing the image. * @return {Object} The image selection options. */ function calculateImageSelectOptions( attachment ) { var realWidth = attachment.get( 'width' ), realHeight = attachment.get( 'height' ), xInit = 512, yInit = 512, ratio = xInit / yInit, xImg = xInit, yImg = yInit, x1, y1, imgSelectOptions; if ( realWidth / realHeight > ratio ) { yInit = realHeight; xInit = yInit * ratio; } else { xInit = realWidth; yInit = xInit / ratio; } x1 = ( realWidth - xInit ) / 2; y1 = ( realHeight - yInit ) / 2; imgSelectOptions = { aspectRatio: xInit + ':' + yInit, handles: true, keys: true, instance: true, persistent: true, imageWidth: realWidth, imageHeight: realHeight, minWidth: xImg > xInit ? xInit : xImg, minHeight: yImg > yInit ? yInit : yImg, x1: x1, y1: y1, x2: xInit + x1, y2: yInit + y1, }; return imgSelectOptions; } /** * Initializes the media frame for selecting or cropping an image. * * @since 6.5.0 */ $chooseButton.on( 'click', function () { var $el = $( this ); // Create the media frame. frame = wp.media( { button: { // Set the text of the button. text: $el.data( 'update' ), // Don't close, we might need to crop. close: false, }, states: [ new wp.media.controller.Library( { title: $el.data( 'choose-text' ), library: wp.media.query( { type: 'image' } ), date: false, suggestedWidth: $el.data( 'size' ), suggestedHeight: $el.data( 'size' ), } ), new wp.media.controller.SiteIconCropper( { control: { params: { width: $el.data( 'size' ), height: $el.data( 'size' ), }, }, imgSelectOptions: calculateImageSelectOptions, } ), ], } ); frame.on( 'cropped', function ( attachment ) { $hiddenDataField.val( attachment.id ); switchToUpdate( attachment ); frame.close(); // Start over with a frame that is so fresh and so clean clean. frame = null; } ); // When an image is selected, run a callback. frame.on( 'select', function () { // Grab the selected attachment. var attachment = frame.state().get( 'selection' ).first(); if ( attachment.attributes.height === $el.data( 'size' ) && $el.data( 'size' ) === attachment.attributes.width ) { switchToUpdate( attachment.attributes ); frame.close(); // Set the value of the hidden input to the attachment id. $hiddenDataField.val( attachment.id ); } else { frame.setState( 'cropper' ); } } ); frame.open(); } ); /** * Update the UI when a site icon is selected. * * @since 6.5.0 * * @param {array} attributes The attributes for the attachment. */ function switchToUpdate( attributes ) { var i18nAppAlternativeString, i18nBrowserAlternativeString; if ( attributes.alt ) { i18nAppAlternativeString = wp.i18n.sprintf( /* translators: %s: The selected image alt text. */ wp.i18n.__( 'App icon preview: Current image: %s' ), attributes.alt ); i18nBrowserAlternativeString = wp.i18n.sprintf( /* translators: %s: The selected image alt text. */ wp.i18n.__( 'Browser icon preview: Current image: %s' ), attributes.alt ); } else { i18nAppAlternativeString = wp.i18n.sprintf( /* translators: %s: The selected image filename. */ wp.i18n.__( 'App icon preview: The current image has no alternative text. The file name is: %s' ), attributes.filename ); i18nBrowserAlternativeString = wp.i18n.sprintf( /* translators: %s: The selected image filename. */ wp.i18n.__( 'Browser icon preview: The current image has no alternative text. The file name is: %s' ), attributes.filename ); } // Set site-icon-img src and alternative text to app icon preview. $appIconPreview.attr( { src: attributes.url, alt: i18nAppAlternativeString, } ); // Set site-icon-img src and alternative text to browser preview. $browserIconPreview.attr( { src: attributes.url, alt: i18nBrowserAlternativeString, } ); // Remove hidden class from icon preview div and remove button. $iconPreview.removeClass( 'hidden' ); $removeButton.removeClass( 'hidden' ); // Set the global CSS variable for --site-icon-url to the selected image URL. document.documentElement.style.setProperty( '--site-icon-url', 'url(' + attributes.url + ')' ); // If the choose button is not in the update state, swap the classes. if ( $chooseButton.attr( 'data-state' ) !== '1' ) { $chooseButton.attr( { class: $chooseButton.attr( 'data-alt-classes' ), 'data-alt-classes': $chooseButton.attr( 'class' ), 'data-state': '1', } ); } // Swap the text of the choose button. $chooseButton.text( $chooseButton.attr( 'data-update-text' ) ); } /** * Handles the click event of the remove button. * * @since 6.5.0 */ $removeButton.on( 'click', function () { $hiddenDataField.val( 'false' ); $( this ).toggleClass( 'hidden' ); $iconPreview.toggleClass( 'hidden' ); $browserIconPreview.attr( { src: '', alt: '', } ); $appIconPreview.attr( { src: '', alt: '', } ); /** * Resets state to the button, for correct visual style and state. * Updates the text of the button. * Sets focus state to the button. */ $chooseButton .attr( { class: $chooseButton.attr( 'data-alt-classes' ), 'data-alt-classes': $chooseButton.attr( 'class' ), 'data-state': '', } ) .text( $chooseButton.attr( 'data-choose-text' ) ) .trigger( 'focus' ); } ); } )( jQuery ); PK!@fx;;user-profile.jsnu[/** * @output wp-admin/js/user-profile.js */ /* global ajaxurl, pwsL10n, userProfileL10n, ClipboardJS */ (function($) { var updateLock = false, isSubmitting = false, __ = wp.i18n.__, clipboard = new ClipboardJS( '.application-password-display .copy-button' ), $pass1Row, $pass1, $pass2, $weakRow, $weakCheckbox, $toggleButton, $submitButtons, $submitButton, currentPass, $form, originalFormContent, $passwordWrapper, successTimeout; function generatePassword() { if ( typeof zxcvbn !== 'function' ) { setTimeout( generatePassword, 50 ); return; } else if ( ! $pass1.val() || $passwordWrapper.hasClass( 'is-open' ) ) { // zxcvbn loaded before user entered password, or generating new password. $pass1.val( $pass1.data( 'pw' ) ); $pass1.trigger( 'pwupdate' ); showOrHideWeakPasswordCheckbox(); } else { // zxcvbn loaded after the user entered password, check strength. check_pass_strength(); showOrHideWeakPasswordCheckbox(); } /* * This works around a race condition when zxcvbn loads quickly and * causes `generatePassword()` to run prior to the toggle button being * bound. */ bindToggleButton(); // Install screen. if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) { // Show the password not masked if admin_password hasn't been posted yet. $pass1.attr( 'type', 'text' ); } else { // Otherwise, mask the password. $toggleButton.trigger( 'click' ); } // Once zxcvbn loads, passwords strength is known. $( '#pw-weak-text-label' ).text( __( 'Confirm use of weak password' ) ); // Focus the password field. if ( 'mailserver_pass' !== $pass1.prop('id' ) ) { $( $pass1 ).trigger( 'focus' ); } } function bindPass1() { currentPass = $pass1.val(); if ( 1 === parseInt( $pass1.data( 'reveal' ), 10 ) ) { generatePassword(); } $pass1.on( 'input' + ' pwupdate', function () { if ( $pass1.val() === currentPass ) { return; } currentPass = $pass1.val(); // Refresh password strength area. $pass1.removeClass( 'short bad good strong' ); showOrHideWeakPasswordCheckbox(); } ); } function resetToggle( show ) { $toggleButton .attr({ 'aria-label': show ? __( 'Show password' ) : __( 'Hide password' ) }) .find( '.text' ) .text( show ? __( 'Show' ) : __( 'Hide' ) ) .end() .find( '.dashicons' ) .removeClass( show ? 'dashicons-hidden' : 'dashicons-visibility' ) .addClass( show ? 'dashicons-visibility' : 'dashicons-hidden' ); } function bindToggleButton() { if ( !! $toggleButton ) { // Do not rebind. return; } $toggleButton = $pass1Row.find('.wp-hide-pw'); $toggleButton.show().on( 'click', function () { if ( 'password' === $pass1.attr( 'type' ) ) { $pass1.attr( 'type', 'text' ); resetToggle( false ); } else { $pass1.attr( 'type', 'password' ); resetToggle( true ); } }); } /** * Handle the password reset button. Sets up an ajax callback to trigger sending * a password reset email. */ function bindPasswordResetLink() { $( '#generate-reset-link' ).on( 'click', function() { var $this = $(this), data = { 'user_id': userProfileL10n.user_id, // The user to send a reset to. 'nonce': userProfileL10n.nonce // Nonce to validate the action. }; // Remove any previous error messages. $this.parent().find( '.notice-error' ).remove(); // Send the reset request. var resetAction = wp.ajax.post( 'send-password-reset', data ); // Handle reset success. resetAction.done( function( response ) { addInlineNotice( $this, true, response ); } ); // Handle reset failure. resetAction.fail( function( response ) { addInlineNotice( $this, false, response ); } ); }); } /** * Helper function to insert an inline notice of success or failure. * * @param {jQuery Object} $this The button element: the message will be inserted * above this button * @param {bool} success Whether the message is a success message. * @param {string} message The message to insert. */ function addInlineNotice( $this, success, message ) { var resultDiv = $( '
    ', { role: 'alert' } ); // Set up the notice div. resultDiv.addClass( 'notice inline' ); // Add a class indicating success or failure. resultDiv.addClass( 'notice-' + ( success ? 'success' : 'error' ) ); // Add the message, wrapping in a p tag, with a fadein to highlight each message. resultDiv.text( $( $.parseHTML( message ) ).text() ).wrapInner( '

    '); // Disable the button when the callback has succeeded. $this.prop( 'disabled', success ); // Remove any previous notices. $this.siblings( '.notice' ).remove(); // Insert the notice. $this.before( resultDiv ); } function bindPasswordForm() { var $generateButton, $cancelButton; $pass1Row = $( '.user-pass1-wrap, .user-pass-wrap, .mailserver-pass-wrap, .reset-pass-submit' ); // Hide the confirm password field when JavaScript support is enabled. $('.user-pass2-wrap').hide(); $submitButton = $( '#submit, #wp-submit' ).on( 'click', function () { updateLock = false; }); $submitButtons = $submitButton.add( ' #createusersub' ); $weakRow = $( '.pw-weak' ); $weakCheckbox = $weakRow.find( '.pw-checkbox' ); $weakCheckbox.on( 'change', function() { $submitButtons.prop( 'disabled', ! $weakCheckbox.prop( 'checked' ) ); } ); $pass1 = $('#pass1, #mailserver_pass'); if ( $pass1.length ) { bindPass1(); } else { // Password field for the login form. $pass1 = $( '#user_pass' ); } /* * Fix a LastPass mismatch issue, LastPass only changes pass2. * * This fixes the issue by copying any changes from the hidden * pass2 field to the pass1 field, then running check_pass_strength. */ $pass2 = $( '#pass2' ).on( 'input', function () { if ( $pass2.val().length > 0 ) { $pass1.val( $pass2.val() ); $pass2.val(''); currentPass = ''; $pass1.trigger( 'pwupdate' ); } } ); // Disable hidden inputs to prevent autofill and submission. if ( $pass1.is( ':hidden' ) ) { $pass1.prop( 'disabled', true ); $pass2.prop( 'disabled', true ); } $passwordWrapper = $pass1Row.find( '.wp-pwd' ); $generateButton = $pass1Row.find( 'button.wp-generate-pw' ); bindToggleButton(); $generateButton.show(); $generateButton.on( 'click', function () { updateLock = true; // Make sure the password fields are shown. $generateButton.not( '.skip-aria-expanded' ).attr( 'aria-expanded', 'true' ); $passwordWrapper .show() .addClass( 'is-open' ); // Enable the inputs when showing. $pass1.attr( 'disabled', false ); $pass2.attr( 'disabled', false ); // Set the password to the generated value. generatePassword(); // Show generated password in plaintext by default. resetToggle ( false ); // Generate the next password and cache. wp.ajax.post( 'generate-password' ) .done( function( data ) { $pass1.data( 'pw', data ); } ); } ); $cancelButton = $pass1Row.find( 'button.wp-cancel-pw' ); $cancelButton.on( 'click', function () { updateLock = false; // Disable the inputs when hiding to prevent autofill and submission. $pass1.prop( 'disabled', true ); $pass2.prop( 'disabled', true ); // Clear password field and update the UI. $pass1.val( '' ).trigger( 'pwupdate' ); resetToggle( false ); // Hide password controls. $passwordWrapper .hide() .removeClass( 'is-open' ); // Stop an empty password from being submitted as a change. $submitButtons.prop( 'disabled', false ); $generateButton.attr( 'aria-expanded', 'false' ); } ); $pass1Row.closest( 'form' ).on( 'submit', function () { updateLock = false; $pass1.prop( 'disabled', false ); $pass2.prop( 'disabled', false ); $pass2.val( $pass1.val() ); }); } function check_pass_strength() { var pass1 = $('#pass1').val(), strength; $('#pass-strength-result').removeClass('short bad good strong empty'); if ( ! pass1 || '' === pass1.trim() ) { $( '#pass-strength-result' ).addClass( 'empty' ).html( ' ' ); return; } strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputDisallowedList(), pass1 ); switch ( strength ) { case -1: $( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown ); break; case 2: $('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); break; case 3: $('#pass-strength-result').addClass('good').html( pwsL10n.good ); break; case 4: $('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); break; case 5: $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); break; default: $('#pass-strength-result').addClass('short').html( pwsL10n.short ); } } function showOrHideWeakPasswordCheckbox() { var passStrengthResult = $('#pass-strength-result'); if ( passStrengthResult.length ) { var passStrength = passStrengthResult[0]; if ( passStrength.className ) { $pass1.addClass( passStrength.className ); if ( $( passStrength ).is( '.short, .bad' ) ) { if ( ! $weakCheckbox.prop( 'checked' ) ) { $submitButtons.prop( 'disabled', true ); } $weakRow.show(); } else { if ( $( passStrength ).is( '.empty' ) ) { $submitButtons.prop( 'disabled', true ); $weakCheckbox.prop( 'checked', false ); } else { $submitButtons.prop( 'disabled', false ); } $weakRow.hide(); } } } } // Debug information copy section. clipboard.on( 'success', function( e ) { var triggerElement = $( e.trigger ), successElement = $( '.success', triggerElement.closest( '.application-password-display' ) ); // Clear the selection and move focus back to the trigger. e.clearSelection(); // Show success visual feedback. clearTimeout( successTimeout ); successElement.removeClass( 'hidden' ); // Hide success visual feedback after 3 seconds since last success. successTimeout = setTimeout( function() { successElement.addClass( 'hidden' ); }, 3000 ); // Handle success audible feedback. wp.a11y.speak( __( 'Application password has been copied to your clipboard.' ) ); } ); $( function() { var $colorpicker, $stylesheet, user_id, current_user_id, select = $( '#display_name' ), current_name = select.val(), greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); $( '#pass1' ).val( '' ).on( 'input' + ' pwupdate', check_pass_strength ); $('#pass-strength-result').show(); $('.color-palette').on( 'click', function() { $(this).siblings('input[name="admin_color"]').prop('checked', true); }); if ( select.length ) { $('#first_name, #last_name, #nickname').on( 'blur.user_profile', function() { var dub = [], inputs = { display_nickname : $('#nickname').val() || '', display_username : $('#user_login').val() || '', display_firstname : $('#first_name').val() || '', display_lastname : $('#last_name').val() || '' }; if ( inputs.display_firstname && inputs.display_lastname ) { inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname; inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname; } $.each( $('option', select), function( i, el ){ dub.push( el.value ); }); $.each(inputs, function( id, value ) { if ( ! value ) { return; } var val = value.replace(/<\/?[a-z][^>]*>/gi, ''); if ( inputs[id].length && $.inArray( val, dub ) === -1 ) { dub.push(val); $('

    ' ); }).fail( function( response ) { $this.siblings( '.notice' ).remove(); $this.before( '' ); }); e.preventDefault(); }); window.generatePassword = generatePassword; // Warn the user if password was generated but not saved. $( window ).on( 'beforeunload', function () { if ( true === updateLock ) { return __( 'Your new password has not been saved.' ); } if ( originalFormContent !== $form.serialize() && ! isSubmitting ) { return __( 'The changes you made will be lost if you navigate away from this page.' ); } }); /* * We need to generate a password as soon as the Reset Password page is loaded, * to avoid double clicking the button to retrieve the first generated password. * See ticket #39638. */ $( function() { if ( $( '.reset-pass-submit' ).length ) { $( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' ); } }); })(jQuery); PK!G3Jcustom-header.jsnu[/** * @output wp-admin/js/custom-header.js */ /* global isRtl */ /** * Initializes the custom header selection page. * * @since 3.5.0 * * @deprecated 4.1.0 The page this is used on is never linked to from the UI. * Setting a custom header is completely handled by the Customizer. */ (function($) { var frame; $( function() { // Fetch available headers. var $headers = $('.available-headers'); // Apply jQuery.masonry once the images have loaded. $headers.imagesLoaded( function() { $headers.masonry({ itemSelector: '.default-header', isRTL: !! ( 'undefined' != typeof isRtl && isRtl ) }); }); /** * Opens the 'choose from library' frame and creates it if it doesn't exist. * * @since 3.5.0 * @deprecated 4.1.0 * * @return {void} */ $('#choose-from-library-link').on( 'click', function( event ) { var $el = $(this); event.preventDefault(); // If the media frame already exists, reopen it. if ( frame ) { frame.open(); return; } // Create the media frame. frame = wp.media.frames.customHeader = wp.media({ // Set the title of the modal. title: $el.data('choose'), // Tell the modal to show only images. library: { type: 'image' }, // Customize the submit button. button: { // Set the text of the button. text: $el.data('update'), // Tell the button not to close the modal, since we're // going to refresh the page when the image is selected. close: false } }); /** * Updates the window location to include the selected attachment. * * @since 3.5.0 * @deprecated 4.1.0 * * @return {void} */ frame.on( 'select', function() { // Grab the selected attachment. var attachment = frame.state().get('selection').first(), link = $el.data('updateLink'); // Tell the browser to navigate to the crop step. window.location = link + '&file=' + attachment.id; }); frame.open(); }); }); }(jQuery)); PK! tx""privacy-tools.min.jsnu[/*! This file is auto-generated */ jQuery(function(v){var r,h=wp.i18n.__;function w(e,t){e.children().addClass("hidden"),e.children("."+t).removeClass("hidden")}function x(e){e.removeClass("has-request-results"),e.next().hasClass("request-results")&&e.next().remove()}function T(e,t,a,o){var s="",n="request-results";x(e),o.length&&(v.each(o,function(e,t){s=s+"
  • "+t+"
  • "}),s="
      "+s+"
    "),e.addClass("has-request-results"),e.hasClass("status-request-confirmed")&&(n+=" status-request-confirmed"),e.hasClass("status-request-failed")&&(n+=" status-request-failed"),e.after(function(){return'"})}v(".export-personal-data-handle").on("click",function(e){var t=v(this),n=t.parents(".export-personal-data"),r=t.parents("tr"),a=r.find(".export-progress"),i=t.parents(".row-actions"),c=n.data("request-id"),d=n.data("nonce"),l=n.data("exporters-count"),u=!!n.data("send-as-email");function p(e){var t=h("An error occurred while attempting to export personal data.");w(n,"export-personal-data-failed"),e&&T(r,"notice-error",t,[e]),setTimeout(function(){i.removeClass("processing")},500)}function m(e){e=Math.round(100*(0 3 ) { while ( n.length > 3 ) { n1 = thousandsSeparator + n.substr(n.length - 3) + n1; n = n.substr(0, n.length - 3); } n = n + n1; } el.html(n); }; /** * Updates the number of approved comments on a specific post and the filter bar. * * @since 4.4.0 * @access private * * @param {number} diff The amount to lower or raise the approved count with. * @param {number} commentPostId The ID of the post to be updated. * * @return {void} */ updateApproved = function( diff, commentPostId ) { var postSelector = '.post-com-count-' + commentPostId, noClass = 'comment-count-no-comments', approvedClass = 'comment-count-approved', approved, noComments; updateCountText( 'span.approved-count', diff ); if ( ! commentPostId ) { return; } // Cache selectors to not get duplicates. approved = $( 'span.' + approvedClass, postSelector ); noComments = $( 'span.' + noClass, postSelector ); approved.each(function() { var a = $(this), n = getCount(a) + diff; if ( n < 1 ) n = 0; if ( 0 === n ) { a.removeClass( approvedClass ).addClass( noClass ); } else { a.addClass( approvedClass ).removeClass( noClass ); } updateCount( a, n ); }); noComments.each(function() { var a = $(this); if ( diff > 0 ) { a.removeClass( noClass ).addClass( approvedClass ); } else { a.addClass( noClass ).removeClass( approvedClass ); } updateCount( a, diff ); }); }; /** * Updates a number count in all matched HTML elements * * @since 4.4.0 * @access private * * @param {string} selector The jQuery selector for elements to update a count * for. * @param {number} diff The amount to lower or raise the count with. * * @return {void} */ updateCountText = function( selector, diff ) { $( selector ).each(function() { var a = $(this), n = getCount(a) + diff; if ( n < 1 ) { n = 0; } updateCount( a, n ); }); }; /** * Updates a text about comment count on the dashboard. * * @since 4.4.0 * @access private * * @param {Object} response Ajax response from the server that includes a * translated "comment count" message. * * @return {void} */ updateDashboardText = function( response ) { if ( ! isDashboard || ! response || ! response.i18n_comments_text ) { return; } $( '.comment-count a', '#dashboard_right_now' ).text( response.i18n_comments_text ); }; /** * Updates the "comments in moderation" text across the UI. * * @since 5.2.0 * * @param {Object} response Ajax response from the server that includes a * translated "comments in moderation" message. * * @return {void} */ updateInModerationText = function( response ) { if ( ! response || ! response.i18n_moderation_text ) { return; } // Update the "comment in moderation" text across the UI. $( '.comments-in-moderation-text' ).text( response.i18n_moderation_text ); // Hide the "comment in moderation" text in the Dashboard "At a Glance" widget. if ( isDashboard && response.in_moderation ) { $( '.comment-mod-count', '#dashboard_right_now' ) [ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' ); } }; /** * Updates the title of the document with the number comments to be approved. * * @since 4.4.0 * @access private * * @param {number} diff The amount to lower or raise the number of to be * approved comments with. * * @return {void} */ updateHtmlTitle = function( diff ) { var newTitle, regExMatch, titleCount, commentFrag; /* translators: %s: Comments count. */ titleRegEx = titleRegEx || new RegExp( __( 'Comments (%s)' ).replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' ); // Count funcs operate on a $'d element. titleDiv = titleDiv || $( '
    ' ); newTitle = adminTitle; commentFrag = titleRegEx.exec( document.title ); if ( commentFrag ) { commentFrag = commentFrag[0]; titleDiv.html( commentFrag ); titleCount = getCount( titleDiv ) + diff; } else { titleDiv.html( 0 ); titleCount = diff; } if ( titleCount >= 1 ) { updateCount( titleDiv, titleCount ); regExMatch = titleRegEx.exec( document.title ); if ( regExMatch ) { /* translators: %s: Comments count. */ newTitle = document.title.replace( regExMatch[0], __( 'Comments (%s)' ).replace( '%s', titleDiv.text() ) + ' ' ); } } else { regExMatch = titleRegEx.exec( newTitle ); if ( regExMatch ) { newTitle = newTitle.replace( regExMatch[0], __( 'Comments' ) ); } } document.title = newTitle; }; /** * Updates the number of pending comments on a specific post and the filter bar. * * @since 3.2.0 * @access private * * @param {number} diff The amount to lower or raise the pending count with. * @param {number} commentPostId The ID of the post to be updated. * * @return {void} */ updatePending = function( diff, commentPostId ) { var postSelector = '.post-com-count-' + commentPostId, noClass = 'comment-count-no-pending', noParentClass = 'post-com-count-no-pending', pendingClass = 'comment-count-pending', pending, noPending; if ( ! isDashboard ) { updateHtmlTitle( diff ); } $( 'span.pending-count' ).each(function() { var a = $(this), n = getCount(a) + diff; if ( n < 1 ) n = 0; a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0'); updateCount( a, n ); }); if ( ! commentPostId ) { return; } // Cache selectors to not get dupes. pending = $( 'span.' + pendingClass, postSelector ); noPending = $( 'span.' + noClass, postSelector ); pending.each(function() { var a = $(this), n = getCount(a) + diff; if ( n < 1 ) n = 0; if ( 0 === n ) { a.parent().addClass( noParentClass ); a.removeClass( pendingClass ).addClass( noClass ); } else { a.parent().removeClass( noParentClass ); a.addClass( pendingClass ).removeClass( noClass ); } updateCount( a, n ); }); noPending.each(function() { var a = $(this); if ( diff > 0 ) { a.parent().removeClass( noParentClass ); a.removeClass( noClass ).addClass( pendingClass ); } else { a.parent().addClass( noParentClass ); a.addClass( noClass ).removeClass( pendingClass ); } updateCount( a, diff ); }); }; /** * Initializes the comments list. * * @since 4.4.0 * * @global * * @return {void} */ window.setCommentsList = function() { var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff, lastConfidentTime = 0; totalInput = $('input[name="_total"]', '#comments-form'); perPageInput = $('input[name="_per_page"]', '#comments-form'); pageInput = $('input[name="_page"]', '#comments-form'); /** * Updates the total with the latest count. * * The time parameter makes sure that we only update the total if this value is * a newer value than we previously received. * * The time and setConfidentTime parameters make sure that we only update the * total when necessary. So a value that has been generated earlier will not * update the total. * * @since 2.8.0 * @access private * * @param {number} total Total number of comments. * @param {number} time Unix timestamp of response. * @param {boolean} setConfidentTime Whether to update the last confident time * with the given time. * * @return {void} */ updateTotalCount = function( total, time, setConfidentTime ) { if ( time < lastConfidentTime ) return; if ( setConfidentTime ) lastConfidentTime = time; totalInput.val( total.toString() ); }; /** * Changes DOM that need to be changed after a list item has been dimmed. * * @since 2.5.0 * @access private * * @param {Object} r Ajax response object. * @param {Object} settings Settings for the wpList object. * * @return {void} */ dimAfter = function( r, settings ) { var editRow, replyID, replyButton, response, c = $( '#' + settings.element ); if ( true !== settings.parsed ) { response = settings.parsed.responses[0]; } editRow = $('#replyrow'); replyID = $('#comment_ID', editRow).val(); replyButton = $('#replybtn', editRow); if ( c.is('.unapproved') ) { if ( settings.data.id == replyID ) replyButton.text( __( 'Approve and Reply' ) ); c.find( '.row-actions span.view' ).addClass( 'hidden' ).end() .find( 'div.comment_status' ).html( '0' ); } else { if ( settings.data.id == replyID ) replyButton.text( __( 'Reply' ) ); c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end() .find( 'div.comment_status' ).html( '1' ); } diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; if ( response ) { updateDashboardText( response.supplemental ); updateInModerationText( response.supplemental ); updatePending( diff, response.supplemental.postId ); updateApproved( -1 * diff, response.supplemental.postId ); } else { updatePending( diff ); updateApproved( -1 * diff ); } }; /** * Handles marking a comment as spam or trashing the comment. * * Is executed in the list delBefore hook. * * @since 2.8.0 * @access private * * @param {Object} settings Settings for the wpList object. * @param {HTMLElement} list Comments table element. * * @return {Object} The settings object. */ delBefore = function( settings, list ) { var note, id, el, n, h, a, author, action = false, wpListsData = $( settings.target ).attr( 'data-wp-lists' ); settings.data._total = totalInput.val() || 0; settings.data._per_page = perPageInput.val() || 0; settings.data._page = pageInput.val() || 0; settings.data._url = document.location.href; settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val(); if ( wpListsData.indexOf(':trash=1') != -1 ) action = 'trash'; else if ( wpListsData.indexOf(':spam=1') != -1 ) action = 'spam'; if ( action ) { id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1'); el = $('#comment-' + id); note = $('#' + action + '-undo-holder').html(); el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits. if ( el.siblings('#replyrow').length && commentReply.cid == id ) commentReply.close(); if ( el.is('tr') ) { n = el.children(':visible').length; author = $('.author strong', el).text(); h = $('' + note + ''); } else { author = $('.comment-author', el).text(); h = $(''); } el.before(h); $('strong', '#undo-' + id).text(author); a = $('.undo a', '#undo-' + id); a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1'); a.attr('class', 'vim-z vim-destructive aria-button-if-js'); $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); a.on( 'click', function( e ){ e.preventDefault(); e.stopPropagation(); // Ticket #35904. list.wpList.del(this); $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ $(this).remove(); $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); }); }); }); } return settings; }; /** * Handles actions that need to be done after marking as spam or thrashing a * comment. * * The ajax requests return the unix time stamp a comment was marked as spam or * trashed. We use this to have a correct total amount of comments. * * @since 2.5.0 * @access private * * @param {Object} r Ajax response object. * @param {Object} settings Settings for the wpList object. * * @return {void} */ delAfter = function( r, settings ) { var total_items_i18n, total, animated, animatedCallback, response = true === settings.parsed ? {} : settings.parsed.responses[0], commentStatus = true === settings.parsed ? '' : response.supplemental.status, commentPostId = true === settings.parsed ? '' : response.supplemental.postId, newTotal = true === settings.parsed ? '' : response.supplemental, targetParent = $( settings.target ).parent(), commentRow = $('#' + settings.element), spamDiff, trashDiff, pendingDiff, approvedDiff, /* * As `wpList` toggles only the `unapproved` class, the approved comment * rows can have both the `approved` and `unapproved` classes. */ approved = commentRow.hasClass( 'approved' ) && ! commentRow.hasClass( 'unapproved' ), unapproved = commentRow.hasClass( 'unapproved' ), spammed = commentRow.hasClass( 'spam' ), trashed = commentRow.hasClass( 'trash' ), undoing = false; // Ticket #35904. updateDashboardText( newTotal ); updateInModerationText( newTotal ); /* * The order of these checks is important. * .unspam can also have .approve or .unapprove. * .untrash can also have .approve or .unapprove. */ if ( targetParent.is( 'span.undo' ) ) { // The comment was spammed. if ( targetParent.hasClass( 'unspam' ) ) { spamDiff = -1; if ( 'trash' === commentStatus ) { trashDiff = 1; } else if ( '1' === commentStatus ) { approvedDiff = 1; } else if ( '0' === commentStatus ) { pendingDiff = 1; } // The comment was trashed. } else if ( targetParent.hasClass( 'untrash' ) ) { trashDiff = -1; if ( 'spam' === commentStatus ) { spamDiff = 1; } else if ( '1' === commentStatus ) { approvedDiff = 1; } else if ( '0' === commentStatus ) { pendingDiff = 1; } } undoing = true; // User clicked "Spam". } else if ( targetParent.is( 'span.spam' ) ) { // The comment is currently approved. if ( approved ) { approvedDiff = -1; // The comment is currently pending. } else if ( unapproved ) { pendingDiff = -1; // The comment was in the Trash. } else if ( trashed ) { trashDiff = -1; } // You can't spam an item on the Spam screen. spamDiff = 1; // User clicked "Unspam". } else if ( targetParent.is( 'span.unspam' ) ) { if ( approved ) { pendingDiff = 1; } else if ( unapproved ) { approvedDiff = 1; } else if ( trashed ) { // The comment was previously approved. if ( targetParent.hasClass( 'approve' ) ) { approvedDiff = 1; // The comment was previously pending. } else if ( targetParent.hasClass( 'unapprove' ) ) { pendingDiff = 1; } } else if ( spammed ) { if ( targetParent.hasClass( 'approve' ) ) { approvedDiff = 1; } else if ( targetParent.hasClass( 'unapprove' ) ) { pendingDiff = 1; } } // You can unspam an item on the Spam screen. spamDiff = -1; // User clicked "Trash". } else if ( targetParent.is( 'span.trash' ) ) { if ( approved ) { approvedDiff = -1; } else if ( unapproved ) { pendingDiff = -1; // The comment was in the spam queue. } else if ( spammed ) { spamDiff = -1; } // You can't trash an item on the Trash screen. trashDiff = 1; // User clicked "Restore". } else if ( targetParent.is( 'span.untrash' ) ) { if ( approved ) { pendingDiff = 1; } else if ( unapproved ) { approvedDiff = 1; } else if ( trashed ) { if ( targetParent.hasClass( 'approve' ) ) { approvedDiff = 1; } else if ( targetParent.hasClass( 'unapprove' ) ) { pendingDiff = 1; } } // You can't go from Trash to Spam. // You can untrash on the Trash screen. trashDiff = -1; // User clicked "Approve". } else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) { approvedDiff = 1; pendingDiff = -1; // User clicked "Unapprove". } else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) { approvedDiff = -1; pendingDiff = 1; // User clicked "Delete Permanently". } else if ( targetParent.is( 'span.delete' ) ) { if ( spammed ) { spamDiff = -1; } else if ( trashed ) { trashDiff = -1; } } if ( pendingDiff ) { updatePending( pendingDiff, commentPostId ); updateCountText( 'span.all-count', pendingDiff ); } if ( approvedDiff ) { updateApproved( approvedDiff, commentPostId ); updateCountText( 'span.all-count', approvedDiff ); } if ( spamDiff ) { updateCountText( 'span.spam-count', spamDiff ); } if ( trashDiff ) { updateCountText( 'span.trash-count', trashDiff ); } if ( ( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) || ( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) ) ) { $( '#delete_all' ).hide(); } if ( ! isDashboard ) { total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; if ( $(settings.target).parent().is('span.undo') ) total++; else total--; if ( total < 0 ) total = 0; if ( 'object' === typeof r ) { if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) { total_items_i18n = response.supplemental.total_items_i18n || ''; if ( total_items_i18n ) { $('.displaying-num').text( total_items_i18n.replace( ' ', String.fromCharCode( 160 ) ) ); $('.total-pages').text( response.supplemental.total_pages_i18n.replace( ' ', String.fromCharCode( 160 ) ) ); $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val()); } updateTotalCount( total, response.supplemental.time, true ); } else if ( response.supplemental.time ) { updateTotalCount( total, response.supplemental.time, false ); } } else { updateTotalCount( total, r, false ); } } if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) { return; } theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() ); refillTheExtraList(); animated = $( ':animated', '#the-comment-list' ); animatedCallback = function() { if ( ! $( '#the-comment-list tr:visible' ).length ) { theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() ); } }; if ( animated.length ) { animated.promise().done( animatedCallback ); } else { animatedCallback(); } }; /** * Retrieves additional comments to populate the extra list. * * @since 3.1.0 * @access private * * @param {boolean} [ev] Repopulate the extra comments list if true. * * @return {void} */ refillTheExtraList = function(ev) { var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val(); if (! args.paged) args.paged = 1; if (args.paged > total_pages) { return; } if (ev) { theExtraList.empty(); args.number = Math.min(8, per_page); // See WP_Comments_List_Table::prepare_items() in class-wp-comments-list-table.php. } else { args.number = 1; args.offset = Math.min(8, per_page) - 1; // Fetch only the next item on the extra list. } args.no_placeholder = true; args.paged ++; // $.query.get() needs some correction to be sent into an Ajax request. if ( true === args.comment_type ) args.comment_type = ''; args = $.extend(args, { 'action': 'fetch-list', 'list_args': list_args, '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val() }); $.ajax({ url: ajaxurl, global: false, dataType: 'json', data: args, success: function(response) { theExtraList.get(0).wpList.add( response.rows ); } }); }; /** * Globally available jQuery object referring to the extra comments list. * * @global */ window.theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); /** * Globally available jQuery object referring to the comments list. * * @global */ window.theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) .on('wpListDelEnd', function(e, s){ var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, ''); if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 ) $('#undo-' + id).fadeIn(300, function(){ $(this).show(); }); }); }; /** * Object containing functionality regarding the comment quick editor and reply * editor. * * @since 2.7.0 * * @global */ window.commentReply = { cid : '', act : '', originalContent : '', /** * Initializes the comment reply functionality. * * @since 2.7.0 * * @memberof commentReply */ init : function() { var row = $('#replyrow'); $( '.cancel', row ).on( 'click', function() { return commentReply.revert(); } ); $( '.save', row ).on( 'click', function() { return commentReply.send(); } ); $( 'input#author-name, input#author-email, input#author-url', row ).on( 'keypress', function( e ) { if ( e.which == 13 ) { commentReply.send(); e.preventDefault(); return false; } }); // Add events. $('#the-comment-list .column-comment > p').on( 'dblclick', function(){ commentReply.toggle($(this).parent()); }); $('#doaction, #post-query-submit').on( 'click', function(){ if ( $('#the-comment-list #replyrow').length > 0 ) commentReply.close(); }); this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; }, /** * Adds doubleclick event handler to the given comment list row. * * The double-click event will toggle the comment edit or reply form. * * @since 2.7.0 * * @memberof commentReply * * @param {Object} r The row to add double click handlers to. * * @return {void} */ addEvents : function(r) { r.each(function() { $(this).find('.column-comment > p').on( 'dblclick', function(){ commentReply.toggle($(this).parent()); }); }); }, /** * Opens the quick edit for the given element. * * @since 2.7.0 * * @memberof commentReply * * @param {HTMLElement} el The element you want to open the quick editor for. * * @return {void} */ toggle : function(el) { if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( __( 'Are you sure you want to edit this comment?\nThe changes you made will be lost.' ) ) ) ) { $( el ).find( 'button.vim-q' ).trigger( 'click' ); } }, /** * Closes the comment quick edit or reply form and undoes any changes. * * @since 2.7.0 * * @memberof commentReply * * @return {void} */ revert : function() { if ( $('#the-comment-list #replyrow').length < 1 ) return false; $('#replyrow').fadeOut('fast', function(){ commentReply.close(); }); }, /** * Closes the comment quick edit or reply form and undoes any changes. * * @since 2.7.0 * * @memberof commentReply * * @return {void} */ close : function() { var commentRow = $(), replyRow = $( '#replyrow' ); // Return if the replyrow is not showing. if ( replyRow.parent().is( '#com-reply' ) ) { return; } if ( this.cid ) { commentRow = $( '#comment-' + this.cid ); } /* * When closing the Quick Edit form, show the comment row and move focus * back to the Quick Edit button. */ if ( 'edit-comment' === this.act ) { commentRow.fadeIn( 300, function() { commentRow .show() .find( '.vim-q' ) .attr( 'aria-expanded', 'false' ) .trigger( 'focus' ); } ).css( 'backgroundColor', '' ); } // When closing the Reply form, move focus back to the Reply button. if ( 'replyto-comment' === this.act ) { commentRow.find( '.vim-r' ) .attr( 'aria-expanded', 'false' ) .trigger( 'focus' ); } // Reset the Quicktags buttons. if ( typeof QTags != 'undefined' ) QTags.closeAllTags('replycontent'); $('#add-new-comment').css('display', ''); replyRow.hide(); $( '#com-reply' ).append( replyRow ); $('#replycontent').css('height', '').val(''); $('#edithead input').val(''); $( '.notice-error', replyRow ) .addClass( 'hidden' ) .find( '.error' ).empty(); $( '.spinner', replyRow ).removeClass( 'is-active' ); this.cid = ''; this.originalContent = ''; }, /** * Opens the comment quick edit or reply form. * * @since 2.7.0 * * @memberof commentReply * * @param {number} comment_id The comment ID to open an editor for. * @param {number} post_id The post ID to open an editor for. * @param {string} action The action to perform. Either 'edit' or 'replyto'. * * @return {boolean} Always false. */ open : function(comment_id, post_id, action) { var editRow, rowData, act, replyButton, editHeight, t = this, c = $('#comment-' + comment_id), h = c.height(), colspanVal = 0; if ( ! this.discardCommentChanges() ) { return false; } t.close(); t.cid = comment_id; editRow = $('#replyrow'); rowData = $('#inline-'+comment_id); action = action || 'replyto'; act = 'edit' == action ? 'edit' : 'replyto'; act = t.act = act + '-comment'; t.originalContent = $('textarea.comment', rowData).val(); colspanVal = $( '> th:visible, > td:visible', c ).length; // Make sure it's actually a table and there's a `colspan` value to apply. if ( editRow.hasClass( 'inline-edit-row' ) && 0 !== colspanVal ) { $( 'td', editRow ).attr( 'colspan', colspanVal ); } $('#action', editRow).val(act); $('#comment_post_ID', editRow).val(post_id); $('#comment_ID', editRow).val(comment_id); if ( action == 'edit' ) { $( '#author-name', editRow ).val( $( 'div.author', rowData ).text() ); $('#author-email', editRow).val( $('div.author-email', rowData).text() ); $('#author-url', editRow).val( $('div.author-url', rowData).text() ); $('#status', editRow).val( $('div.comment_status', rowData).text() ); $('#replycontent', editRow).val( $('textarea.comment', rowData).val() ); $( '#edithead, #editlegend, #savebtn', editRow ).show(); $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide(); if ( h > 120 ) { // Limit the maximum height when editing very long comments to make it more manageable. // The textarea is resizable in most browsers, so the user can adjust it if needed. editHeight = h > 500 ? 500 : h; $('#replycontent', editRow).css('height', editHeight + 'px'); } c.after( editRow ).fadeOut('fast', function(){ $('#replyrow').fadeIn(300, function(){ $(this).show(); }); }); } else if ( action == 'add' ) { $('#addhead, #addbtn', editRow).show(); $( '#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow ) .hide(); $('#the-comment-list').prepend(editRow); $('#replyrow').fadeIn(300); } else { replyButton = $('#replybtn', editRow); $( '#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow ).hide(); $('#replyhead, #replybtn', editRow).show(); c.after(editRow); if ( c.hasClass('unapproved') ) { replyButton.text( __( 'Approve and Reply' ) ); } else { replyButton.text( __( 'Reply' ) ); } $('#replyrow').fadeIn(300, function(){ $(this).show(); }); } setTimeout(function() { var rtop, rbottom, scrollTop, vp, scrollBottom, isComposing = false, isContextMenuOpen = false; rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); scrollTop = window.pageYOffset || document.documentElement.scrollTop; vp = document.documentElement.clientHeight || window.innerHeight || 0; scrollBottom = scrollTop + vp; if ( scrollBottom - 20 < rbottom ) window.scroll(0, rbottom - vp + 35); else if ( rtop - 20 < scrollTop ) window.scroll(0, rtop - 35); $( '#replycontent' ) .trigger( 'focus' ) .on( 'contextmenu keydown', function ( e ) { // Check if the context menu is open and set state. if ( e.type === 'contextmenu' ) { isContextMenuOpen = true; } // Update the context menu state if the Escape key is pressed. if ( e.type === 'keydown' && e.which === 27 && isContextMenuOpen ) { isContextMenuOpen = false; } } ) .on( 'keyup', function( e ) { // Close on Escape unless Input Method Editors (IMEs) are in use or the context menu is open. if ( e.which === 27 && ! isComposing && ! isContextMenuOpen ) { commentReply.revert(); } } ) .on( 'compositionstart', function() { isComposing = true; } ); }, 600); return false; }, /** * Submits the comment quick edit or reply form. * * @since 2.7.0 * * @memberof commentReply * * @return {void} */ send : function() { var post = {}, $errorNotice = $( '#replysubmit .error-notice' ); $errorNotice.addClass( 'hidden' ); $( '#replysubmit .spinner' ).addClass( 'is-active' ); $('#replyrow input').not(':button').each(function() { var t = $(this); post[ t.attr('name') ] = t.val(); }); post.content = $('#replycontent').val(); post.id = post.comment_post_ID; post.comments_listing = this.comments_listing; post.p = $('[name="p"]').val(); if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') ) post.approve_parent = 1; $.ajax({ type : 'POST', url : ajaxurl, data : post, success : function(x) { commentReply.show(x); }, error : function(r) { commentReply.error(r); } }); }, /** * Shows the new or updated comment or reply. * * This function needs to be passed the ajax result as received from the server. * It will handle the response and show the comment that has just been saved to * the server. * * @since 2.7.0 * * @memberof commentReply * * @param {Object} xml Ajax response object. * * @return {void} */ show : function(xml) { var t = this, r, c, id, bg, pid; if ( typeof(xml) == 'string' ) { t.error({'responseText': xml}); return false; } r = wpAjax.parseAjaxResponse(xml); if ( r.errors ) { t.error({'responseText': wpAjax.broken}); return false; } t.revert(); r = r.responses[0]; id = '#comment-' + r.id; if ( 'edit-comment' == t.act ) $(id).remove(); if ( r.supplemental.parent_approved ) { pid = $('#comment-' + r.supplemental.parent_approved); updatePending( -1, r.supplemental.parent_post_id ); if ( this.comments_listing == 'moderated' ) { pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){ pid.fadeOut(); }); return; } } if ( r.supplemental.i18n_comments_text ) { updateDashboardText( r.supplemental ); updateInModerationText( r.supplemental ); updateApproved( 1, r.supplemental.parent_post_id ); updateCountText( 'span.all-count', 1 ); } r.data = r.data || ''; c = r.data.toString().trim(); // Trim leading whitespaces. $(c).hide(); $('#replyrow').after(c); id = $(id); t.addEvents(id); bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor'); id.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) .animate( { 'backgroundColor': bg }, 300, function() { if ( pid && pid.length ) { pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) .animate( { 'backgroundColor': bg }, 300 ) .removeClass('unapproved').addClass('approved') .find('div.comment_status').html('1'); } }); }, /** * Shows an error for the failed comment update or reply. * * @since 2.7.0 * * @memberof commentReply * * @param {string} r The Ajax response. * * @return {void} */ error : function(r) { var er = r.statusText, $errorNotice = $( '#replysubmit .notice-error' ), $error = $errorNotice.find( '.error' ); $( '#replysubmit .spinner' ).removeClass( 'is-active' ); if ( r.responseText ) er = r.responseText.replace( /<.[^<>]*?>/g, '' ); if ( er ) { $errorNotice.removeClass( 'hidden' ); $error.html( er ); wp.a11y.speak( er ); } }, /** * Opens the add comments form in the comments metabox on the post edit page. * * @since 3.4.0 * * @memberof commentReply * * @param {number} post_id The post ID. * * @return {void} */ addcomment: function(post_id) { var t = this; $('#add-new-comment').fadeOut(200, function(){ t.open(0, post_id, 'add'); $('table.comments-box').css('display', ''); $('#no-comments').remove(); }); }, /** * Alert the user if they have unsaved changes on a comment that will be lost if * they proceed with the intended action. * * @since 4.6.0 * * @memberof commentReply * * @return {boolean} Whether it is safe the continue with the intended action. */ discardCommentChanges: function() { var editRow = $( '#replyrow' ); if ( '' === $( '#replycontent', editRow ).val() || this.originalContent === $( '#replycontent', editRow ).val() ) { return true; } return window.confirm( __( 'Are you sure you want to do this?\nThe comment changes you made will be lost.' ) ); } }; $( function(){ var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk; setCommentsList(); commentReply.init(); $(document).on( 'click', 'span.delete a.delete', function( e ) { e.preventDefault(); }); if ( typeof $.table_hotkeys != 'undefined' ) { /** * Creates a function that navigates to a previous or next page. * * @since 2.7.0 * @access private * * @param {string} which What page to navigate to: either next or prev. * * @return {Function} The function that executes the navigation. */ make_hotkeys_redirect = function(which) { return function() { var first_last, l; first_last = 'next' == which? 'first' : 'last'; l = $('.tablenav-pages .'+which+'-page:not(.disabled)'); if (l.length) window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; }; }; /** * Navigates to the edit page for the selected comment. * * @since 2.7.0 * @access private * * @param {Object} event The event that triggered this action. * @param {Object} current_row A jQuery object of the selected row. * * @return {void} */ edit_comment = function(event, current_row) { window.location = $('span.edit a', current_row).attr('href'); }; /** * Toggles all comments on the screen, for bulk actions. * * @since 2.7.0 * @access private * * @return {void} */ toggle_all = function() { $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' ); }; /** * Creates a bulk action function that is executed on all selected comments. * * @since 2.7.0 * @access private * * @param {string} value The name of the action to execute. * * @return {Function} The function that executes the bulk action. */ make_bulk = function(value) { return function() { var scope = $('select[name="action"]'); $('option[value="' + value + '"]', scope).prop('selected', true); $('#doaction').trigger( 'click' ); }; }; $.table_hotkeys( $('table.widefat'), [ 'a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')], ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')], ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')] ], { highlight_first: adminCommentsSettings.hotkeys_highlight_first, highlight_last: adminCommentsSettings.hotkeys_highlight_last, prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next'), hotkeys_opts: { disableInInput: true, type: 'keypress', noDisable: '.check-column input[type="checkbox"]' }, cycle_expr: '#the-comment-list tr', start_row_index: 0 } ); } // Quick Edit and Reply have an inline comment editor. $( '#the-comment-list' ).on( 'click', '.comment-inline', function() { var $el = $( this ), action = 'replyto'; if ( 'undefined' !== typeof $el.data( 'action' ) ) { action = $el.data( 'action' ); } $( this ).attr( 'aria-expanded', 'true' ); commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action ); } ); }); })(jQuery); PK! >iZuser-suggest.jsnu[/** * Suggests users in a multisite environment. * * For input fields where the admin can select a user based on email or * username, this script shows an autocompletion menu for these inputs. Should * only be used in a multisite environment. Only users in the currently active * site are shown. * * @since 3.4.0 * @output wp-admin/js/user-suggest.js */ /* global ajaxurl, current_site_id, isRtl */ (function( $ ) { var id = ( typeof current_site_id !== 'undefined' ) ? '&site_id=' + current_site_id : ''; $( function() { var position = { offset: '0, -1' }; if ( typeof isRtl !== 'undefined' && isRtl ) { position.my = 'right top'; position.at = 'right bottom'; } /** * Adds an autocomplete function to input fields marked with the class * 'wp-suggest-user'. * * A minimum of two characters is required to trigger the suggestions. The * autocompletion menu is shown at the left bottom of the input field. On * RTL installations, it is shown at the right top. Adds the class 'open' to * the input field when the autocompletion menu is shown. * * Does a backend call to retrieve the users. * * Optional data-attributes: * - data-autocomplete-type (add, search) * The action that is going to be performed: search for existing users * or add a new one. Default: add * - data-autocomplete-field (user_login, user_email) * The field that is returned as the value for the suggestion. * Default: user_login * * @see wp-admin/includes/admin-actions.php:wp_ajax_autocomplete_user() */ $( '.wp-suggest-user' ).each( function(){ var $this = $( this ), autocompleteType = ( typeof $this.data( 'autocompleteType' ) !== 'undefined' ) ? $this.data( 'autocompleteType' ) : 'add', autocompleteField = ( typeof $this.data( 'autocompleteField' ) !== 'undefined' ) ? $this.data( 'autocompleteField' ) : 'user_login'; $this.autocomplete({ source: ajaxurl + '?action=autocomplete-user&autocomplete_type=' + autocompleteType + '&autocomplete_field=' + autocompleteField + id, delay: 500, minLength: 2, position: position, open: function() { $( this ).addClass( 'open' ); }, close: function() { $( this ).removeClass( 'open' ); } }); }); }); })( jQuery ); PK!'8 media.min.jsnu[/*! This file is auto-generated */ !function(t){window.findPosts={open:function(n,e){var i=t(".ui-find-overlay");return 0===i.length&&(t("body").append('
    '),findPosts.overlay()),i.show(),n&&e&&t("#affected").attr("name",n).val(e),t("#find-posts").show(),t("#find-posts-input").trigger("focus").on("keyup",function(n){27==n.which&&findPosts.close()}),findPosts.send(),!1},close:function(){t("#find-posts-response").empty(),t("#find-posts").hide(),t(".ui-find-overlay").hide()},overlay:function(){t(".ui-find-overlay").on("click",function(){findPosts.close()})},send:function(){var n={ps:t("#find-posts-input").val(),action:"find_posts",_ajax_nonce:t("#_ajax_nonce").val()},e=t(".find-box-search .spinner");e.addClass("is-active"),t.ajax(ajaxurl,{type:"POST",data:n,dataType:"json"}).always(function(){e.removeClass("is-active")}).done(function(n){n.success||t("#find-posts-response").text(wp.i18n.__("An error has occurred. Please reload the page and try again.")),t("#find-posts-response").html(n.data)}).fail(function(){t("#find-posts-response").text(wp.i18n.__("An error has occurred. Please reload the page and try again."))})}},t(function(){var o,n,e=t("#wp-media-grid"),i=new ClipboardJS(".copy-attachment-url.media-library"),s=null;e.length&&window.wp&&window.wp.media&&(n=_wpMediaGridSettings,n=window.wp.media({frame:"manage",container:e,library:n.queryVars}).open(),e.trigger("wp-media-grid-ready",n)),t("#find-posts-submit").on("click",function(n){t('#find-posts-response input[type="radio"]:checked').length||n.preventDefault()}),t("#find-posts .find-box-search :input").on("keypress",function(n){if(13==n.which)return findPosts.send(),!1}),t("#find-posts-search").on("click",findPosts.send),t("#find-posts-close").on("click",findPosts.close),t("#doaction").on("click",function(e){t('select[name="action"]').each(function(){var n=t(this).val();"attach"===n?(e.preventDefault(),findPosts.open()):"delete"!==n||showNotice.warn()||e.preventDefault()})}),t(".find-box-inside").on("click","tr",function(){t(this).find(".found-radio input").prop("checked",!0)}),i.on("success",function(n){var e=t(n.trigger),i=t(".success",e.closest(".copy-to-clipboard-container"));n.clearSelection(),s&&s.addClass("hidden"),clearTimeout(o),i.removeClass("hidden"),o=setTimeout(function(){i.addClass("hidden"),s=null},3e3),s=i,wp.a11y.speak(wp.i18n.__("The file URL has been copied to your clipboard"))})})}(jQuery);PK!iD-D-code-editor.jsnu[/** * @output wp-admin/js/code-editor.js */ if ( 'undefined' === typeof window.wp ) { /** * @namespace wp */ window.wp = {}; } if ( 'undefined' === typeof window.wp.codeEditor ) { /** * @namespace wp.codeEditor */ window.wp.codeEditor = {}; } ( function( $, wp ) { 'use strict'; /** * Default settings for code editor. * * @since 4.9.0 * @type {object} */ wp.codeEditor.defaultSettings = { codemirror: {}, csslint: {}, htmlhint: {}, jshint: {}, onTabNext: function() {}, onTabPrevious: function() {}, onChangeLintingErrors: function() {}, onUpdateErrorNotice: function() {} }; /** * Configure linting. * * @param {CodeMirror} editor - Editor. * @param {Object} settings - Code editor settings. * @param {Object} settings.codeMirror - Settings for CodeMirror. * @param {Function} settings.onChangeLintingErrors - Callback for when there are changes to linting errors. * @param {Function} settings.onUpdateErrorNotice - Callback to update error notice. * * @return {void} */ function configureLinting( editor, settings ) { // eslint-disable-line complexity var currentErrorAnnotations = [], previouslyShownErrorAnnotations = []; /** * Call the onUpdateErrorNotice if there are new errors to show. * * @return {void} */ function updateErrorNotice() { if ( settings.onUpdateErrorNotice && ! _.isEqual( currentErrorAnnotations, previouslyShownErrorAnnotations ) ) { settings.onUpdateErrorNotice( currentErrorAnnotations, editor ); previouslyShownErrorAnnotations = currentErrorAnnotations; } } /** * Get lint options. * * @return {Object} Lint options. */ function getLintOptions() { // eslint-disable-line complexity var options = editor.getOption( 'lint' ); if ( ! options ) { return false; } if ( true === options ) { options = {}; } else if ( _.isObject( options ) ) { options = $.extend( {}, options ); } /* * Note that rules must be sent in the "deprecated" lint.options property * to prevent linter from complaining about unrecognized options. * See . */ if ( ! options.options ) { options.options = {}; } // Configure JSHint. if ( 'javascript' === settings.codemirror.mode && settings.jshint ) { $.extend( options.options, settings.jshint ); } // Configure CSSLint. if ( 'css' === settings.codemirror.mode && settings.csslint ) { $.extend( options.options, settings.csslint ); } // Configure HTMLHint. if ( 'htmlmixed' === settings.codemirror.mode && settings.htmlhint ) { options.options.rules = $.extend( {}, settings.htmlhint ); if ( settings.jshint ) { options.options.rules.jshint = settings.jshint; } if ( settings.csslint ) { options.options.rules.csslint = settings.csslint; } } // Wrap the onUpdateLinting CodeMirror event to route to onChangeLintingErrors and onUpdateErrorNotice. options.onUpdateLinting = (function( onUpdateLintingOverridden ) { return function( annotations, annotationsSorted, cm ) { var errorAnnotations = _.filter( annotations, function( annotation ) { return 'error' === annotation.severity; } ); if ( onUpdateLintingOverridden ) { onUpdateLintingOverridden.apply( annotations, annotationsSorted, cm ); } // Skip if there are no changes to the errors. if ( _.isEqual( errorAnnotations, currentErrorAnnotations ) ) { return; } currentErrorAnnotations = errorAnnotations; if ( settings.onChangeLintingErrors ) { settings.onChangeLintingErrors( errorAnnotations, annotations, annotationsSorted, cm ); } /* * Update notifications when the editor is not focused to prevent error message * from overwhelming the user during input, unless there are now no errors or there * were previously errors shown. In these cases, update immediately so they can know * that they fixed the errors. */ if ( ! editor.state.focused || 0 === currentErrorAnnotations.length || previouslyShownErrorAnnotations.length > 0 ) { updateErrorNotice(); } }; })( options.onUpdateLinting ); return options; } editor.setOption( 'lint', getLintOptions() ); // Keep lint options populated. editor.on( 'optionChange', function( cm, option ) { var options, gutters, gutterName = 'CodeMirror-lint-markers'; if ( 'lint' !== option ) { return; } gutters = editor.getOption( 'gutters' ) || []; options = editor.getOption( 'lint' ); if ( true === options ) { if ( ! _.contains( gutters, gutterName ) ) { editor.setOption( 'gutters', [ gutterName ].concat( gutters ) ); } editor.setOption( 'lint', getLintOptions() ); // Expand to include linting options. } else if ( ! options ) { editor.setOption( 'gutters', _.without( gutters, gutterName ) ); } // Force update on error notice to show or hide. if ( editor.getOption( 'lint' ) ) { editor.performLint(); } else { currentErrorAnnotations = []; updateErrorNotice(); } } ); // Update error notice when leaving the editor. editor.on( 'blur', updateErrorNotice ); // Work around hint selection with mouse causing focus to leave editor. editor.on( 'startCompletion', function() { editor.off( 'blur', updateErrorNotice ); } ); editor.on( 'endCompletion', function() { var editorRefocusWait = 500; editor.on( 'blur', updateErrorNotice ); // Wait for editor to possibly get re-focused after selection. _.delay( function() { if ( ! editor.state.focused ) { updateErrorNotice(); } }, editorRefocusWait ); }); /* * Make sure setting validities are set if the user tries to click Publish * while an autocomplete dropdown is still open. The Customizer will block * saving when a setting has an error notifications on it. This is only * necessary for mouse interactions because keyboards will have already * blurred the field and cause onUpdateErrorNotice to have already been * called. */ $( document.body ).on( 'mousedown', function( event ) { if ( editor.state.focused && ! $.contains( editor.display.wrapper, event.target ) && ! $( event.target ).hasClass( 'CodeMirror-hint' ) ) { updateErrorNotice(); } }); } /** * Configure tabbing. * * @param {CodeMirror} codemirror - Editor. * @param {Object} settings - Code editor settings. * @param {Object} settings.codeMirror - Settings for CodeMirror. * @param {Function} settings.onTabNext - Callback to handle tabbing to the next tabbable element. * @param {Function} settings.onTabPrevious - Callback to handle tabbing to the previous tabbable element. * * @return {void} */ function configureTabbing( codemirror, settings ) { var $textarea = $( codemirror.getTextArea() ); codemirror.on( 'blur', function() { $textarea.data( 'next-tab-blurs', false ); }); codemirror.on( 'keydown', function onKeydown( editor, event ) { var tabKeyCode = 9, escKeyCode = 27; // Take note of the ESC keypress so that the next TAB can focus outside the editor. if ( escKeyCode === event.keyCode ) { $textarea.data( 'next-tab-blurs', true ); return; } // Short-circuit if tab key is not being pressed or the tab key press should move focus. if ( tabKeyCode !== event.keyCode || ! $textarea.data( 'next-tab-blurs' ) ) { return; } // Focus on previous or next focusable item. if ( event.shiftKey ) { settings.onTabPrevious( codemirror, event ); } else { settings.onTabNext( codemirror, event ); } // Reset tab state. $textarea.data( 'next-tab-blurs', false ); // Prevent tab character from being added. event.preventDefault(); }); } /** * @typedef {object} wp.codeEditor~CodeEditorInstance * @property {object} settings - The code editor settings. * @property {CodeMirror} codemirror - The CodeMirror instance. */ /** * Initialize Code Editor (CodeMirror) for an existing textarea. * * @since 4.9.0 * * @param {string|jQuery|Element} textarea - The HTML id, jQuery object, or DOM Element for the textarea that is used for the editor. * @param {Object} [settings] - Settings to override defaults. * @param {Function} [settings.onChangeLintingErrors] - Callback for when the linting errors have changed. * @param {Function} [settings.onUpdateErrorNotice] - Callback for when error notice should be displayed. * @param {Function} [settings.onTabPrevious] - Callback to handle tabbing to the previous tabbable element. * @param {Function} [settings.onTabNext] - Callback to handle tabbing to the next tabbable element. * @param {Object} [settings.codemirror] - Options for CodeMirror. * @param {Object} [settings.csslint] - Rules for CSSLint. * @param {Object} [settings.htmlhint] - Rules for HTMLHint. * @param {Object} [settings.jshint] - Rules for JSHint. * * @return {CodeEditorInstance} Instance. */ wp.codeEditor.initialize = function initialize( textarea, settings ) { var $textarea, codemirror, instanceSettings, instance; if ( 'string' === typeof textarea ) { $textarea = $( '#' + textarea ); } else { $textarea = $( textarea ); } instanceSettings = $.extend( {}, wp.codeEditor.defaultSettings, settings ); instanceSettings.codemirror = $.extend( {}, instanceSettings.codemirror ); codemirror = wp.CodeMirror.fromTextArea( $textarea[0], instanceSettings.codemirror ); configureLinting( codemirror, instanceSettings ); instance = { settings: instanceSettings, codemirror: codemirror }; if ( codemirror.showHint ) { codemirror.on( 'keyup', function( editor, event ) { // eslint-disable-line complexity var shouldAutocomplete, isAlphaKey = /^[a-zA-Z]$/.test( event.key ), lineBeforeCursor, innerMode, token; if ( codemirror.state.completionActive && isAlphaKey ) { return; } // Prevent autocompletion in string literals or comments. token = codemirror.getTokenAt( codemirror.getCursor() ); if ( 'string' === token.type || 'comment' === token.type ) { return; } innerMode = wp.CodeMirror.innerMode( codemirror.getMode(), token.state ).mode.name; lineBeforeCursor = codemirror.doc.getLine( codemirror.doc.getCursor().line ).substr( 0, codemirror.doc.getCursor().ch ); if ( 'html' === innerMode || 'xml' === innerMode ) { shouldAutocomplete = '<' === event.key || '/' === event.key && 'tag' === token.type || isAlphaKey && 'tag' === token.type || isAlphaKey && 'attribute' === token.type || '=' === token.string && token.state.htmlState && token.state.htmlState.tagName; } else if ( 'css' === innerMode ) { shouldAutocomplete = isAlphaKey || ':' === event.key || ' ' === event.key && /:\s+$/.test( lineBeforeCursor ); } else if ( 'javascript' === innerMode ) { shouldAutocomplete = isAlphaKey || '.' === event.key; } else if ( 'clike' === innerMode && 'php' === codemirror.options.mode ) { shouldAutocomplete = 'keyword' === token.type || 'variable' === token.type; } if ( shouldAutocomplete ) { codemirror.showHint( { completeSingle: false } ); } }); } // Facilitate tabbing out of the editor. configureTabbing( codemirror, settings ); return instance; }; })( window.jQuery, window.wp ); PK!-link.jsnu[/** * @output wp-admin/js/link.js */ /* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */ jQuery( function($) { var newCat, noSyncChecks = false, syncChecks, catAddAfter; $('#link_name').trigger( 'focus' ); // Postboxes. postboxes.add_postbox_toggles('link'); /** * Adds event that opens a particular category tab. * * @ignore * * @return {boolean} Always returns false to prevent the default behavior. */ $('#category-tabs a').on( 'click', function(){ var t = $(this).attr('href'); $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); $('.tabs-panel').hide(); $(t).show(); if ( '#categories-all' == t ) deleteUserSetting('cats'); else setUserSetting('cats','pop'); return false; }); if ( getUserSetting('cats') ) $('#category-tabs a[href="#categories-pop"]').trigger( 'click' ); // Ajax Cat. newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } ); /** * After adding a new category, focus on the category add input field. * * @return {void} */ $('#link-category-add-submit').on( 'click', function() { newCat.focus(); } ); /** * Synchronize category checkboxes. * * This function makes sure that the checkboxes are synced between the all * categories tab and the most used categories tab. * * @since 2.5.0 * * @return {void} */ syncChecks = function() { if ( noSyncChecks ) return; noSyncChecks = true; var th = $(this), c = th.is(':checked'), id = th.val().toString(); $('#in-link-category-' + id + ', #in-popular-link_category-' + id).prop( 'checked', c ); noSyncChecks = false; }; /** * Adds event listeners to an added category. * * This is run on the addAfter event to make sure the correct event listeners * are bound to the DOM elements. * * @since 2.5.0 * * @param {string} r Raw XML response returned from the server after adding a * category. * @param {Object} s List manager configuration object; settings for the Ajax * request. * * @return {void} */ catAddAfter = function( r, s ) { $(s.what + ' response_data', r).each( function() { var t = $($(this).text()); t.find( 'label' ).each( function() { var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = th.text().trim(), o; $('#' + id).on( 'change', syncChecks ); o = $( '' ).text( name ); } ); } ); }; /* * Instantiates the list manager. * * @see js/_enqueues/lib/lists.js */ $('#categorychecklist').wpList( { // CSS class name for alternate styling. alt: '', // The type of list. what: 'link-category', // ID of the element the parsed Ajax response will be stored in. response: 'category-ajax-response', // Callback that's run after an item got added to the list. addAfter: catAddAfter } ); // All categories is the default tab, so we delete the user setting. $('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');}); // Set a preference for the popular categories to cookies. $('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');}); if ( 'pop' == getUserSetting('cats') ) $('a[href="#categories-pop"]').trigger( 'click' ); /** * Adds event handler that shows the interface controls to add a new category. * * @ignore * * @param {Event} event The event object. * @return {boolean} Always returns false to prevent regular link * functionality. */ $('#category-add-toggle').on( 'click', function() { $(this).parents('div:first').toggleClass( 'wp-hidden-children' ); $('#category-tabs a[href="#categories-all"]').trigger( 'click' ); $('#newcategory').trigger( 'focus' ); return false; } ); $('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' ); }); PK! zzlanguage-chooser.jsnu[/** * @output wp-admin/js/language-chooser.js */ jQuery( function($) { /* * Set the correct translation to the continue button and show a spinner * when downloading a language. */ var select = $( '#language' ), submit = $( '#language-continue' ); if ( ! $( 'body' ).hasClass( 'language-chooser' ) ) { return; } select.trigger( 'focus' ).on( 'change', function() { /* * When a language is selected, set matching translation to continue button * and attach the language attribute. */ var option = select.children( 'option:selected' ); submit.attr({ value: option.data( 'continue' ), lang: option.attr( 'lang' ) }); }); $( 'form' ).on( 'submit', function() { // Show spinner for languages that need to be downloaded. if ( ! select.children( 'option:selected' ).data( 'installed' ) ) { $( this ).find( '.step .spinner' ).css( 'visibility', 'visible' ); } }); }); PK!oh-|\|\ common.min.jsnu[/*! This file is auto-generated */ !function(B,W){var $=B(document),H=B(W),q=B(document.body),Q=wp.i18n.__,i=wp.i18n.sprintf;function r(e,t,n){n=void 0!==n?i(Q("%1$s is deprecated since version %2$s! Use %3$s instead."),e,t,n):i(Q("%1$s is deprecated since version %2$s with no alternative available."),e,t);W.console.warn(n)}function e(i,o,a){var s={};return Object.keys(o).forEach(function(e){var t=o[e],n=i+"."+e;"object"==typeof t?Object.defineProperty(s,e,{get:function(){return r(n,a,t.alternative),t.func()}}):Object.defineProperty(s,e,{get:function(){return r(n,a,"wp.i18n"),t}})}),s}W.wp.deprecateL10nObject=e,W.commonL10n=W.commonL10n||{warnDelete:"",dismiss:"",collapseMenu:"",expandMenu:""},W.commonL10n=e("commonL10n",W.commonL10n,"5.5.0"),W.wpPointerL10n=W.wpPointerL10n||{dismiss:""},W.wpPointerL10n=e("wpPointerL10n",W.wpPointerL10n,"5.5.0"),W.userProfileL10n=W.userProfileL10n||{warn:"",warnWeak:"",show:"",hide:"",cancel:"",ariaShow:"",ariaHide:""},W.userProfileL10n=e("userProfileL10n",W.userProfileL10n,"5.5.0"),W.privacyToolsL10n=W.privacyToolsL10n||{noDataFound:"",foundAndRemoved:"",noneRemoved:"",someNotRemoved:"",removalError:"",emailSent:"",noExportFile:"",exportError:""},W.privacyToolsL10n=e("privacyToolsL10n",W.privacyToolsL10n,"5.5.0"),W.authcheckL10n={beforeunload:""},W.authcheckL10n=W.authcheckL10n||e("authcheckL10n",W.authcheckL10n,"5.5.0"),W.tagsl10n={noPerm:"",broken:""},W.tagsl10n=W.tagsl10n||e("tagsl10n",W.tagsl10n,"5.5.0"),W.adminCommentsL10n=W.adminCommentsL10n||{hotkeys_highlight_first:{alternative:"window.adminCommentsSettings.hotkeys_highlight_first",func:function(){return W.adminCommentsSettings.hotkeys_highlight_first}},hotkeys_highlight_last:{alternative:"window.adminCommentsSettings.hotkeys_highlight_last",func:function(){return W.adminCommentsSettings.hotkeys_highlight_last}},replyApprove:"",reply:"",warnQuickEdit:"",warnCommentChanges:"",docTitleComments:"",docTitleCommentsCount:""},W.adminCommentsL10n=e("adminCommentsL10n",W.adminCommentsL10n,"5.5.0"),W.tagsSuggestL10n=W.tagsSuggestL10n||{tagDelimiter:"",removeTerm:"",termSelected:"",termAdded:"",termRemoved:""},W.tagsSuggestL10n=e("tagsSuggestL10n",W.tagsSuggestL10n,"5.5.0"),W.wpColorPickerL10n=W.wpColorPickerL10n||{clear:"",clearAriaLabel:"",defaultString:"",defaultAriaLabel:"",pick:"",defaultLabel:""},W.wpColorPickerL10n=e("wpColorPickerL10n",W.wpColorPickerL10n,"5.5.0"),W.attachMediaBoxL10n=W.attachMediaBoxL10n||{error:""},W.attachMediaBoxL10n=e("attachMediaBoxL10n",W.attachMediaBoxL10n,"5.5.0"),W.postL10n=W.postL10n||{ok:"",cancel:"",publishOn:"",publishOnFuture:"",publishOnPast:"",dateFormat:"",showcomm:"",endcomm:"",publish:"",schedule:"",update:"",savePending:"",saveDraft:"",private:"",public:"",publicSticky:"",password:"",privatelyPublished:"",published:"",saveAlert:"",savingText:"",permalinkSaved:""},W.postL10n=e("postL10n",W.postL10n,"5.5.0"),W.inlineEditL10n=W.inlineEditL10n||{error:"",ntdeltitle:"",notitle:"",comma:"",saved:""},W.inlineEditL10n=e("inlineEditL10n",W.inlineEditL10n,"5.5.0"),W.plugininstallL10n=W.plugininstallL10n||{plugin_information:"",plugin_modal_label:"",ays:""},W.plugininstallL10n=e("plugininstallL10n",W.plugininstallL10n,"5.5.0"),W.navMenuL10n=W.navMenuL10n||{noResultsFound:"",warnDeleteMenu:"",saveAlert:"",untitled:""},W.navMenuL10n=e("navMenuL10n",W.navMenuL10n,"5.5.0"),W.commentL10n=W.commentL10n||{submittedOn:"",dateFormat:""},W.commentL10n=e("commentL10n",W.commentL10n,"5.5.0"),W.setPostThumbnailL10n=W.setPostThumbnailL10n||{setThumbnail:"",saving:"",error:"",done:""},W.setPostThumbnailL10n=e("setPostThumbnailL10n",W.setPostThumbnailL10n,"5.5.0"),W.uiAutocompleteL10n=W.uiAutocompleteL10n||{noResults:"",oneResult:"",manyResults:"",itemSelected:""},W.uiAutocompleteL10n=e("uiAutocompleteL10n",W.uiAutocompleteL10n,"6.5.0"),W.adminMenu={init:function(){},fold:function(){},restoreMenuState:function(){},toggle:function(){},favorites:function(){}},W.columns={init:function(){var n=this;B(".hide-column-tog","#adv-settings").on("click",function(){var e=B(this),t=e.val();e.prop("checked")?n.checked(t):n.unchecked(t),columns.saveManageColumnsState()})},saveManageColumnsState:function(){var e=this.hidden();B.post(ajaxurl,{action:"hidden-columns",hidden:e,screenoptionnonce:B("#screenoptionnonce").val(),page:pagenow},function(){wp.a11y.speak(Q("Screen Options updated."))})},checked:function(e){B(".column-"+e).removeClass("hidden"),this.colSpanChange(1)},unchecked:function(e){B(".column-"+e).addClass("hidden"),this.colSpanChange(-1)},hidden:function(){return B(".manage-column[id]").filter(".hidden").map(function(){return this.id}).get().join(",")},useCheckboxesForHidden:function(){this.hidden=function(){return B(".hide-column-tog").not(":checked").map(function(){var e=this.id;return e.substring(e,e.length-5)}).get().join(",")}},colSpanChange:function(e){var t=B("table").find(".colspanchange");t.length&&(e=parseInt(t.attr("colspan"),10)+e,t.attr("colspan",e.toString()))}},B(function(){columns.init()}),W.validateForm=function(e){return!B(e).find(".form-required").filter(function(){return""===B(":input:visible",this).val()}).addClass("form-invalid").find(":input:visible").on("change",function(){B(this).closest(".form-invalid").removeClass("form-invalid")}).length},W.showNotice={warn:function(){return!!confirm(Q("You are about to permanently delete these items from your site.\nThis action cannot be undone.\n'Cancel' to stop, 'OK' to delete."))},note:function(e){alert(e)}},W.screenMeta={element:null,toggles:null,page:null,init:function(){this.element=B("#screen-meta"),this.toggles=B("#screen-meta-links").find(".show-settings"),this.page=B("#wpcontent"),this.toggles.on("click",this.toggleEvent)},toggleEvent:function(){var e=B("#"+B(this).attr("aria-controls"));e.length&&(e.is(":visible")?screenMeta.close(e,B(this)):screenMeta.open(e,B(this)))},open:function(e,t){B("#screen-meta-links").find(".screen-meta-toggle").not(t.parent()).css("visibility","hidden"),e.parent().show(),e.slideDown("fast",function(){e.removeClass("hidden").trigger("focus"),t.addClass("screen-meta-active").attr("aria-expanded",!0)}),$.trigger("screen:options:open")},close:function(e,t){e.slideUp("fast",function(){t.removeClass("screen-meta-active").attr("aria-expanded",!1),B(".screen-meta-toggle").css("visibility",""),e.parent().hide(),e.addClass("hidden")}),$.trigger("screen:options:close")}},B(".contextual-help-tabs").on("click","a",function(e){var t=B(this);if(e.preventDefault(),t.is(".active a"))return!1;B(".contextual-help-tabs .active").removeClass("active"),t.parent("li").addClass("active"),e=B(t.attr("href")),B(".help-tab-content").not(e).removeClass("active").hide(),e.addClass("active").show()});var t,a=!1,s=B("#permalink_structure"),n=B(".permalink-structure input:radio"),l=B("#custom_selection"),o=B(".form-table.permalink-structure .available-structure-tags button");function c(e){-1!==s.val().indexOf(e.text().trim())?(e.attr("data-label",e.attr("aria-label")),e.attr("aria-label",e.attr("data-used")),e.attr("aria-pressed",!0),e.addClass("active")):e.attr("data-label")&&(e.attr("aria-label",e.attr("data-label")),e.attr("aria-pressed",!1),e.removeClass("active"))}function d(){$.trigger("wp-window-resized")}n.on("change",function(){"custom"!==this.value&&(s.val(this.value),o.each(function(){c(B(this))}))}),s.on("click input",function(){l.prop("checked",!0)}),s.on("focus",function(e){a=!0,B(this).off(e)}),o.each(function(){c(B(this))}),s.on("change",function(){o.each(function(){c(B(this))})}),o.on("click",function(){var e=s.val(),t=s[0].selectionStart,n=s[0].selectionEnd,i=B(this).text().trim(),o=B(this).hasClass("active")?B(this).attr("data-removed"):B(this).attr("data-added");-1!==e.indexOf(i)?(e=e.replace(i+"/",""),s.val("/"===e?"":e),B("#custom_selection_updated").text(o),c(B(this))):(a||0!==t||0!==n||(t=n=e.length),l.prop("checked",!0),"/"!==e.substr(0,t).substr(-1)&&(i="/"+i),"/"!==e.substr(n,1)&&(i+="/"),s.val(e.substr(0,t)+i+e.substr(n)),B("#custom_selection_updated").text(o),c(B(this)),a&&s[0].setSelectionRange&&(n=(e.substr(0,t)+i).length,s[0].setSelectionRange(n,n),s.trigger("focus")))}),B(function(){var n,i,o,a,e,t,s,r=!1,l=B("input.current-page"),z=l.val(),c=/iPhone|iPad|iPod/.test(navigator.userAgent),R=-1!==navigator.userAgent.indexOf("Android"),d=B("#adminmenuwrap"),u=B("#wpwrap"),p=B("#adminmenu"),m=B("#wp-responsive-overlay"),h=B("#wp-toolbar"),f=h.find('a[aria-haspopup="true"]'),g=B(".meta-box-sortables"),v=!1,b=B("#wpadminbar"),w=0,k=!1,y=!1,C=0,L=!1,x={window:H.height(),wpwrap:u.height(),adminbar:b.height(),menu:d.height()},S=B(".wp-header-end");function A(e){var t=e.find(".wp-submenu"),e=e.offset().top,n=H.scrollTop(),i=e-n-30,e=e+t.height()+1,o=60+e-u.height(),n=H.height()+n-50;1<(o=i<(o=n');t.find(".notice-dismiss").length||(e.find(".screen-reader-text").text(Q("Dismiss this notice.")),e.on("click.wp-dismiss-notice",function(e){e.preventDefault(),t.fadeTo(100,0,function(){t.slideUp(100,function(){t.remove()})})}),t.append(e))})}function T(e,t,n,i){n.on("change",function(){e.val(B(this).val())}),e.on("change",function(){n.val(B(this).val())}),i.on("click",function(e){e.preventDefault(),e.stopPropagation(),t.trigger("click")})}p.on("click.wp-submenu-head",".wp-submenu-head",function(e){B(e.target).parent().siblings("a").get(0).click()}),B("#collapse-button").on("click.collapse-menu",function(){var e=I()||961;B("#adminmenu div.wp-submenu").css("margin-top",""),s=e<=960?q.hasClass("auto-fold")?(q.removeClass("auto-fold").removeClass("folded"),setUserSetting("unfold",1),setUserSetting("mfold","o"),"open"):(q.addClass("auto-fold"),setUserSetting("unfold",0),"folded"):q.hasClass("folded")?(q.removeClass("folded"),setUserSetting("mfold","o"),"open"):(q.addClass("folded"),setUserSetting("mfold","f"),"folded"),$.trigger("wp-collapse-menu",{state:s})}),("ontouchstart"in W||/IEMobile\/[1-9]/.test(navigator.userAgent))&&(q.on((E=c?"touchstart":"click")+".wp-mobile-hover",function(e){p.data("wp-responsive")||B(e.target).closest("#adminmenu").length||p.find("li.opensub").removeClass("opensub")}),p.find("a.wp-has-submenu").on(E+".wp-mobile-hover",function(e){var t=B(this).parent();p.data("wp-responsive")||t.hasClass("opensub")||t.hasClass("wp-menu-open")&&!(t.width()<40)||(e.preventDefault(),A(t),p.find("li.opensub").removeClass("opensub"),t.addClass("opensub"))})),c||R||(p.find("li.wp-has-submenu").hoverIntent({over:function(){var e=B(this),t=e.find(".wp-submenu"),t=parseInt(t.css("top"),10);isNaN(t)||-5 tr > .check-column :checkbox",function(e){if("undefined"!=e.shiftKey){if(e.shiftKey){if(!r)return!0;n=B(r).closest("form").find(":checkbox").filter(":visible:enabled"),i=n.index(r),o=n.index(this),a=B(this).prop("checked"),0x.wpwrap)O();else{if(L=!0,x.menu+x.adminbar>x.window){if(t<0)return void(k||(y=!(k=!0),d.css({position:"fixed",top:"",bottom:""})));if(t+x.window>$.height()-1)return void(y||(k=!(y=!0),d.css({position:"fixed",top:"",bottom:0})));wt+x.window&&(C=t),d.css({position:"absolute",top:C,bottom:""})):!k&&d.offset().top>=t+x.adminbar&&(k=!0,d.css({position:"fixed",top:"",bottom:""})):e&&(k=y=!1,0<(C=t+x.window-x.menu-x.adminbar-1)?d.css({position:"absolute",top:C,bottom:""}):O())}w=t}}function F(){x={window:H.height(),wpwrap:u.height(),adminbar:b.height(),menu:d.height()}}function O(){!c&&L&&(k=y=L=!1,d.css({position:"",top:"",bottom:""}))}function j(){F(),p.data("wp-responsive")?(q.removeClass("sticky-menu"),O()):x.menu+x.adminbar>x.window?(N(),q.removeClass("sticky-menu")):(q.addClass("sticky-menu"),O())}function U(){B(".aria-button-if-js").attr("role","button")}function I(){var e=!1;return e=W.innerWidth?Math.max(W.innerWidth,document.documentElement.clientWidth):e}function K(){var e=I()||961;s=e<=782?"responsive":q.hasClass("folded")||q.hasClass("auto-fold")&&e<=960&&782

    '+n.message+"

    ",(e=e.length?e:B("#"+n.id)).length?e.replaceWith(i):o.length?o.after(i):"customize"===pagenow?B(".customize-themes-notifications").append(i):B(".wrap").find("> h1").after(i),$.trigger("wp-notice-added"),wp.a11y.speak(t)}}}),B("#wpbody-content").on({focusin:function(){clearTimeout(e),t=B(this).find(".row-actions"),B(".row-actions").not(this).removeClass("visible"),t.addClass("visible")},focusout:function(){e=setTimeout(function(){t.removeClass("visible")},30)}},".table-view-list .has-row-actions"),B("tbody").on("click",".toggle-row",function(){B(this).closest("tr").toggleClass("is-expanded")}),B("#default-password-nag-no").on("click",function(){return setUserSetting("default_password_nag","hide"),B("div.default-password-nag").hide(),!1}),B("#newcontent").on("keydown.wpevent_InsertTab",function(e){var t,n,i,o,a=e.target;27==e.keyCode?(e.preventDefault(),B(a).data("tab-out",!0)):9!=e.keyCode||e.ctrlKey||e.altKey||e.shiftKey||(B(a).data("tab-out")?B(a).data("tab-out",!1):(t=a.selectionStart,n=a.selectionEnd,i=a.value,document.selection?(a.focus(),document.selection.createRange().text="\t"):0<=t&&(o=this.scrollTop,a.value=i.substring(0,t).concat("\t",i.substring(n)),a.selectionStart=a.selectionEnd=t+1,this.scrollTop=o),e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()))}),l.length&&l.closest("form").on("submit",function(){-1==B('select[name="action"]').val()&&l.val()==z&&l.val("1")}),B('.search-box input[type="search"], .search-box input[type="submit"]').on("mousedown",function(){B('select[name^="action"]').val("-1")}),B("#contextual-help-link, #show-settings-link").on("focus.scroll-into-view",function(e){e.target.scrollIntoViewIfNeeded&&e.target.scrollIntoViewIfNeeded(!1)}),(E=B("form.wp-upload-form")).length&&(M=E.find('input[type="submit"]'),_=E.find('input[type="file"]'),D(),_.on("change",D)),c||(H.on("scroll.pin-menu",N),$.on("tinymce-editor-init.pin-menu",function(e,t){t.on("wp-autoresize",F)})),W.wpResponsive={init:function(){var e=this;this.maybeDisableSortables=this.maybeDisableSortables.bind(this),$.on("wp-responsive-activate.wp-responsive",function(){e.activate(),e.toggleAriaHasPopup("add")}).on("wp-responsive-deactivate.wp-responsive",function(){e.deactivate(),e.toggleAriaHasPopup("remove")}),B("#wp-admin-bar-menu-toggle a").attr("aria-expanded","false"),B("#wp-admin-bar-menu-toggle").on("click.wp-responsive",function(e){e.preventDefault(),b.find(".hover").removeClass("hover"),u.toggleClass("wp-responsive-open"),u.hasClass("wp-responsive-open")?(B(this).find("a").attr("aria-expanded","true"),B("#adminmenu a:first").trigger("focus")):B(this).find("a").attr("aria-expanded","false")}),B(document).on("click",function(e){var t;u.hasClass("wp-responsive-open")&&document.hasFocus()&&(t=B.contains(B("#wp-admin-bar-menu-toggle")[0],e.target),e=B.contains(B("#adminmenuwrap")[0],e.target),t||e||B("#wp-admin-bar-menu-toggle").trigger("click.wp-responsive"))}),B(document).on("keyup",function(e){var n,i,o=B("#wp-admin-bar-menu-toggle")[0];u.hasClass("wp-responsive-open")&&(27===e.keyCode?(B(o).trigger("click.wp-responsive"),B(o).find("a").trigger("focus")):9===e.keyCode&&(n=B("#adminmenuwrap")[0],i=e.relatedTarget||document.activeElement,setTimeout(function(){var e=B.contains(o,i),t=B.contains(n,i);e||t||B(o).trigger("click.wp-responsive")},10)))}),p.on("click.wp-responsive","li.wp-has-submenu > a",function(e){var t;p.data("wp-responsive")&&(t="false"===B(this).attr("aria-expanded")?"true":"false",B(this).parent("li").toggleClass("selected"),B(this).attr("aria-expanded",t),B(this).trigger("focus"),e.preventDefault())}),e.trigger(),$.on("wp-window-resized.wp-responsive",this.trigger.bind(this)),H.on("load.wp-responsive",this.maybeDisableSortables),$.on("postbox-toggled",this.maybeDisableSortables),B("#screen-options-wrap input").on("click",this.maybeDisableSortables)},maybeDisableSortables:function(){(-1
    ').insertAfter("#wpcontent").hide().on("click.wp-responsive",function(){h.find(".menupop.hover").removeClass("hover"),B(this).hide()})),f.on("click.wp-responsive",function(){m.show()})},disableOverlay:function(){f.off("click.wp-responsive"),m.hide()},disableSortables:function(){if(g.length)try{g.sortable("disable"),g.find(".ui-sortable-handle").addClass("is-non-sortable")}catch(e){}},enableSortables:function(){if(g.length)try{g.sortable("enable"),g.find(".ui-sortable-handle").removeClass("is-non-sortable")}catch(e){}}},B(document).on("ajaxComplete",function(){U()}),$.on("wp-window-resized.set-menu-state",K),$.on("wp-menu-state-set wp-collapse-menu",function(e,t){var n,i=B("#collapse-button"),t="folded"===t.state?(n="false",Q("Expand Main menu")):(n="true",Q("Collapse Main menu"));i.attr({"aria-expanded":n,"aria-label":t})}),W.wpResponsive.init(),j(),K(),P(),U(),$.on("wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu",j),B(".wp-initial-focus").trigger("focus"),q.on("click",".js-update-details-toggle",function(){var e=B(this).closest(".js-update-details"),t=B("#"+e.data("update-details"));t.hasClass("update-details-moved")||t.insertAfter(e).addClass("update-details-moved"),t.toggle(),B(this).attr("aria-expanded",t.is(":visible"))})}),B(function(e){var t,n;q.hasClass("update-php")&&(t=e("a.update-from-upload-overwrite"),n=e(".update-from-upload-expired"),t.length)&&n.length&&W.setTimeout(function(){t.hide(),n.removeClass("hidden"),W.wp&&W.wp.a11y&&W.wp.a11y.speak(n.text())},714e4)}),H.on("resize.wp-fire-once",function(){W.clearTimeout(t),t=W.setTimeout(d,200)}),"-ms-user-select"in document.documentElement.style&&navigator.userAgent.match(/IEMobile\/10\.0/)&&((n=document.createElement("style")).appendChild(document.createTextNode("@-ms-viewport{width:auto!important}")),document.getElementsByTagName("head")[0].appendChild(n))}(jQuery,window),function(){var e,i={},o={};i.pauseAll=!1,!window.matchMedia||(e=window.matchMedia("(prefers-reduced-motion: reduce)"))&&!e.matches||(i.pauseAll=!0),i.freezeAnimatedPluginIcons=function(l){function e(){var e=l.width,t=l.height,n=document.createElement("canvas");if(n.width=e,n.height=t,n.className=l.className,l.closest("#update-plugins-table"))for(var i=window.getComputedStyle(l),o=0,a=i.length;o
    ' ); var clone = $('.quick-draft-textarea-clone'), editor = $('#content'), editorHeight = editor.height(), /* * 100px roughly accounts for browser chrome and allows the * save draft button to show on-screen at the same time. */ editorMaxHeight = $(window).height() - 100; /* * Match up textarea and clone div as much as possible. * Padding cannot be reliably retrieved using shorthand in all browsers. */ clone.css({ 'font-family': editor.css('font-family'), 'font-size': editor.css('font-size'), 'line-height': editor.css('line-height'), 'padding-bottom': editor.css('paddingBottom'), 'padding-left': editor.css('paddingLeft'), 'padding-right': editor.css('paddingRight'), 'padding-top': editor.css('paddingTop'), 'white-space': 'pre-wrap', 'word-wrap': 'break-word', 'display': 'none' }); // The 'propertychange' is used in IE < 9. editor.on('focus input propertychange', function() { var $this = $(this), // Add a non-breaking space to ensure that the height of a trailing newline is // included. textareaContent = $this.val() + ' ', // Add 2px to compensate for border-top & border-bottom. cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2; // Default to show a vertical scrollbar, if needed. editor.css('overflow-y', 'auto'); // Only change the height if it has changed and both heights are below the max. if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) { return; } /* * Don't allow editor to exceed the height of the window. * This is also bound in CSS to a max-height of 1300px to be extra safe. */ if ( cloneHeight > editorMaxHeight ) { editorHeight = editorMaxHeight; } else { editorHeight = cloneHeight; } // Disable scrollbars because we adjust the height to the content. editor.css('overflow', 'hidden'); $this.css('height', editorHeight + 'px'); }); } } ); jQuery( function( $ ) { 'use strict'; var communityEventsData = window.communityEventsData, dateI18n = wp.date.dateI18n, format = wp.date.format, sprintf = wp.i18n.sprintf, __ = wp.i18n.__, _x = wp.i18n._x, app; /** * Global Community Events namespace. * * @since 4.8.0 * * @memberOf wp * @namespace wp.communityEvents */ app = window.wp.communityEvents = /** @lends wp.communityEvents */{ initialized: false, model: null, /** * Initializes the wp.communityEvents object. * * @since 4.8.0 * * @return {void} */ init: function() { if ( app.initialized ) { return; } var $container = $( '#community-events' ); /* * When JavaScript is disabled, the errors container is shown, so * that "This widget requires JavaScript" message can be seen. * * When JS is enabled, the container is hidden at first, and then * revealed during the template rendering, if there actually are * errors to show. * * The display indicator switches from `hide-if-js` to `aria-hidden` * here in order to maintain consistency with all the other fields * that key off of `aria-hidden` to determine their visibility. * `aria-hidden` can't be used initially, because there would be no * way to set it to false when JavaScript is disabled, which would * prevent people from seeing the "This widget requires JavaScript" * message. */ $( '.community-events-errors' ) .attr( 'aria-hidden', 'true' ) .removeClass( 'hide-if-js' ); $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm ); /** * Filters events based on entered location. * * @return {void} */ $container.on( 'submit', '.community-events-form', function( event ) { var location = $( '#community-events-location' ).val().trim(); event.preventDefault(); /* * Don't trigger a search if the search field is empty or the * search term was made of only spaces before being trimmed. */ if ( ! location ) { return; } app.getEvents({ location: location }); }); if ( communityEventsData && communityEventsData.cache && communityEventsData.cache.location && communityEventsData.cache.events ) { app.renderEventsTemplate( communityEventsData.cache, 'app' ); } else { app.getEvents(); } app.initialized = true; }, /** * Toggles the visibility of the Edit Location form. * * @since 4.8.0 * * @param {event|string} action 'show' or 'hide' to specify a state; * or an event object to flip between states. * * @return {void} */ toggleLocationForm: function( action ) { var $toggleButton = $( '.community-events-toggle-location' ), $cancelButton = $( '.community-events-cancel' ), $form = $( '.community-events-form' ), $target = $(); if ( 'object' === typeof action ) { // The action is the event object: get the clicked element. $target = $( action.target ); /* * Strict comparison doesn't work in this case because sometimes * we explicitly pass a string as value of aria-expanded and * sometimes a boolean as the result of an evaluation. */ action = 'true' == $toggleButton.attr( 'aria-expanded' ) ? 'hide' : 'show'; } if ( 'hide' === action ) { $toggleButton.attr( 'aria-expanded', 'false' ); $cancelButton.attr( 'aria-expanded', 'false' ); $form.attr( 'aria-hidden', 'true' ); /* * If the Cancel button has been clicked, bring the focus back * to the toggle button so users relying on screen readers don't * lose their place. */ if ( $target.hasClass( 'community-events-cancel' ) ) { $toggleButton.trigger( 'focus' ); } } else { $toggleButton.attr( 'aria-expanded', 'true' ); $cancelButton.attr( 'aria-expanded', 'true' ); $form.attr( 'aria-hidden', 'false' ); } }, /** * Sends REST API requests to fetch events for the widget. * * @since 4.8.0 * * @param {Object} requestParams REST API Request parameters object. * * @return {void} */ getEvents: function( requestParams ) { var initiatedBy, app = this, $spinner = $( '.community-events-form' ).children( '.spinner' ); requestParams = requestParams || {}; requestParams._wpnonce = communityEventsData.nonce; requestParams.timezone = window.Intl ? window.Intl.DateTimeFormat().resolvedOptions().timeZone : ''; initiatedBy = requestParams.location ? 'user' : 'app'; $spinner.addClass( 'is-active' ); wp.ajax.post( 'get-community-events', requestParams ) .always( function() { $spinner.removeClass( 'is-active' ); }) .done( function( response ) { if ( 'no_location_available' === response.error ) { if ( requestParams.location ) { response.unknownCity = requestParams.location; } else { /* * No location was passed, which means that this was an automatic query * based on IP, locale, and timezone. Since the user didn't initiate it, * it should fail silently. Otherwise, the error could confuse and/or * annoy them. */ delete response.error; } } app.renderEventsTemplate( response, initiatedBy ); }) .fail( function() { app.renderEventsTemplate({ 'location' : false, 'events' : [], 'error' : true }, initiatedBy ); }); }, /** * Renders the template for the Events section of the Events & News widget. * * @since 4.8.0 * * @param {Object} templateParams The various parameters that will get passed to wp.template. * @param {string} initiatedBy 'user' to indicate that this was triggered manually by the user; * 'app' to indicate it was triggered automatically by the app itself. * * @return {void} */ renderEventsTemplate: function( templateParams, initiatedBy ) { var template, elementVisibility, $toggleButton = $( '.community-events-toggle-location' ), $locationMessage = $( '#community-events-location-message' ), $results = $( '.community-events-results' ); templateParams.events = app.populateDynamicEventFields( templateParams.events, communityEventsData.time_format ); /* * Hide all toggleable elements by default, to keep the logic simple. * Otherwise, each block below would have to turn hide everything that * could have been shown at an earlier point. * * The exception to that is that the .community-events container is hidden * when the page is first loaded, because the content isn't ready yet, * but once we've reached this point, it should always be shown. */ elementVisibility = { '.community-events' : true, '.community-events-loading' : false, '.community-events-errors' : false, '.community-events-error-occurred' : false, '.community-events-could-not-locate' : false, '#community-events-location-message' : false, '.community-events-toggle-location' : false, '.community-events-results' : false }; /* * Determine which templates should be rendered and which elements * should be displayed. */ if ( templateParams.location.ip ) { /* * If the API determined the location by geolocating an IP, it will * provide events, but not a specific location. */ $locationMessage.text( __( 'Attend an upcoming event near you.' ) ); if ( templateParams.events.length ) { template = wp.template( 'community-events-event-list' ); $results.html( template( templateParams ) ); } else { template = wp.template( 'community-events-no-upcoming-events' ); $results.html( template( templateParams ) ); } elementVisibility['#community-events-location-message'] = true; elementVisibility['.community-events-toggle-location'] = true; elementVisibility['.community-events-results'] = true; } else if ( templateParams.location.description ) { template = wp.template( 'community-events-attend-event-near' ); $locationMessage.html( template( templateParams ) ); if ( templateParams.events.length ) { template = wp.template( 'community-events-event-list' ); $results.html( template( templateParams ) ); } else { template = wp.template( 'community-events-no-upcoming-events' ); $results.html( template( templateParams ) ); } if ( 'user' === initiatedBy ) { wp.a11y.speak( sprintf( /* translators: %s: The name of a city. */ __( 'City updated. Listing events near %s.' ), templateParams.location.description ), 'assertive' ); } elementVisibility['#community-events-location-message'] = true; elementVisibility['.community-events-toggle-location'] = true; elementVisibility['.community-events-results'] = true; } else if ( templateParams.unknownCity ) { template = wp.template( 'community-events-could-not-locate' ); $( '.community-events-could-not-locate' ).html( template( templateParams ) ); wp.a11y.speak( sprintf( /* * These specific examples were chosen to highlight the fact that a * state is not needed, even for cities whose name is not unique. * It would be too cumbersome to include that in the instructions * to the user, so it's left as an implication. */ /* * translators: %s is the name of the city we couldn't locate. * Replace the examples with cities related to your locale. Test that * they match the expected location and have upcoming events before * including them. If no cities related to your locale have events, * then use cities related to your locale that would be recognizable * to most users. Use only the city name itself, without any region * or country. Use the endonym (native locale name) instead of the * English name if possible. */ __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ), templateParams.unknownCity ) ); elementVisibility['.community-events-errors'] = true; elementVisibility['.community-events-could-not-locate'] = true; } else if ( templateParams.error && 'user' === initiatedBy ) { /* * Errors messages are only shown for requests that were initiated * by the user, not for ones that were initiated by the app itself. * Showing error messages for an event that user isn't aware of * could be confusing or unnecessarily distracting. */ wp.a11y.speak( __( 'An error occurred. Please try again.' ) ); elementVisibility['.community-events-errors'] = true; elementVisibility['.community-events-error-occurred'] = true; } else { $locationMessage.text( __( 'Enter your closest city to find nearby events.' ) ); elementVisibility['#community-events-location-message'] = true; elementVisibility['.community-events-toggle-location'] = true; } // Set the visibility of toggleable elements. _.each( elementVisibility, function( isVisible, element ) { $( element ).attr( 'aria-hidden', ! isVisible ); }); $toggleButton.attr( 'aria-expanded', elementVisibility['.community-events-toggle-location'] ); if ( templateParams.location && ( templateParams.location.ip || templateParams.location.latitude ) ) { // Hide the form when there's a valid location. app.toggleLocationForm( 'hide' ); if ( 'user' === initiatedBy ) { /* * When the form is programmatically hidden after a user search, * bring the focus back to the toggle button so users relying * on screen readers don't lose their place. */ $toggleButton.trigger( 'focus' ); } } else { app.toggleLocationForm( 'show' ); } }, /** * Populate event fields that have to be calculated on the fly. * * These can't be stored in the database, because they're dependent on * the user's current time zone, locale, etc. * * @since 5.5.2 * * @param {Array} rawEvents The events that should have dynamic fields added to them. * @param {string} timeFormat A time format acceptable by `wp.date.dateI18n()`. * * @returns {Array} */ populateDynamicEventFields: function( rawEvents, timeFormat ) { // Clone the parameter to avoid mutating it, so that this can remain a pure function. var populatedEvents = JSON.parse( JSON.stringify( rawEvents ) ); $.each( populatedEvents, function( index, event ) { var timeZone = app.getTimeZone( event.start_unix_timestamp * 1000 ); event.user_formatted_date = app.getFormattedDate( event.start_unix_timestamp * 1000, event.end_unix_timestamp * 1000, timeZone ); event.user_formatted_time = dateI18n( timeFormat, event.start_unix_timestamp * 1000, timeZone ); event.timeZoneAbbreviation = app.getTimeZoneAbbreviation( event.start_unix_timestamp * 1000 ); } ); return populatedEvents; }, /** * Returns the user's local/browser time zone, in a form suitable for `wp.date.i18n()`. * * @since 5.5.2 * * @param startTimestamp * * @returns {string|number} */ getTimeZone: function( startTimestamp ) { /* * Prefer a name like `Europe/Helsinki`, since that automatically tracks daylight savings. This * doesn't need to take `startTimestamp` into account for that reason. */ var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; /* * Fall back to an offset for IE11, which declares the property but doesn't assign a value. */ if ( 'undefined' === typeof timeZone ) { /* * It's important to use the _event_ time, not the _current_ * time, so that daylight savings time is accounted for. */ timeZone = app.getFlippedTimeZoneOffset( startTimestamp ); } return timeZone; }, /** * Get intuitive time zone offset. * * `Data.prototype.getTimezoneOffset()` returns a positive value for time zones * that are _behind_ UTC, and a _negative_ value for ones that are ahead. * * See https://stackoverflow.com/questions/21102435/why-does-javascript-date-gettimezoneoffset-consider-0500-as-a-positive-off. * * @since 5.5.2 * * @param {number} startTimestamp * * @returns {number} */ getFlippedTimeZoneOffset: function( startTimestamp ) { return new Date( startTimestamp ).getTimezoneOffset() * -1; }, /** * Get a short time zone name, like `PST`. * * @since 5.5.2 * * @param {number} startTimestamp * * @returns {string} */ getTimeZoneAbbreviation: function( startTimestamp ) { var timeZoneAbbreviation, eventDateTime = new Date( startTimestamp ); /* * Leaving the `locales` argument undefined is important, so that the browser * displays the abbreviation that's most appropriate for the current locale. For * some that will be `UTC{+|-}{n}`, and for others it will be a code like `PST`. * * This doesn't need to take `startTimestamp` into account, because a name like * `America/Chicago` automatically tracks daylight savings. */ var shortTimeStringParts = eventDateTime.toLocaleTimeString( undefined, { timeZoneName : 'short' } ).split( ' ' ); if ( 3 === shortTimeStringParts.length ) { timeZoneAbbreviation = shortTimeStringParts[2]; } if ( 'undefined' === typeof timeZoneAbbreviation ) { /* * It's important to use the _event_ time, not the _current_ * time, so that daylight savings time is accounted for. */ var timeZoneOffset = app.getFlippedTimeZoneOffset( startTimestamp ), sign = -1 === Math.sign( timeZoneOffset ) ? '' : '+'; // translators: Used as part of a string like `GMT+5` in the Events Widget. timeZoneAbbreviation = _x( 'GMT', 'Events widget offset prefix' ) + sign + ( timeZoneOffset / 60 ); } return timeZoneAbbreviation; }, /** * Format a start/end date in the user's local time zone and locale. * * @since 5.5.2 * * @param {int} startDate The Unix timestamp in milliseconds when the the event starts. * @param {int} endDate The Unix timestamp in milliseconds when the the event ends. * @param {string} timeZone A time zone string or offset which is parsable by `wp.date.i18n()`. * * @returns {string} */ getFormattedDate: function( startDate, endDate, timeZone ) { var formattedDate; /* * The `date_format` option is not used because it's important * in this context to keep the day of the week in the displayed date, * so that users can tell at a glance if the event is on a day they * are available, without having to open the link. * * The case of crossing a year boundary is intentionally not handled. * It's so rare in practice that it's not worth the complexity * tradeoff. The _ending_ year should be passed to * `multiple_month_event`, though, just in case. */ /* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/manual/datetime.format.php */ var singleDayEvent = __( 'l, M j, Y' ), /* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */ multipleDayEvent = __( '%1$s %2$d–%3$d, %4$d' ), /* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Ending year. */ multipleMonthEvent = __( '%1$s %2$d – %3$s %4$d, %5$d' ); // Detect single-day events. if ( ! endDate || format( 'Y-m-d', startDate ) === format( 'Y-m-d', endDate ) ) { formattedDate = dateI18n( singleDayEvent, startDate, timeZone ); // Multiple day events. } else if ( format( 'Y-m', startDate ) === format( 'Y-m', endDate ) ) { formattedDate = sprintf( multipleDayEvent, dateI18n( _x( 'F', 'upcoming events month format' ), startDate, timeZone ), dateI18n( _x( 'j', 'upcoming events day format' ), startDate, timeZone ), dateI18n( _x( 'j', 'upcoming events day format' ), endDate, timeZone ), dateI18n( _x( 'Y', 'upcoming events year format' ), endDate, timeZone ) ); // Multi-day events that cross a month boundary. } else { formattedDate = sprintf( multipleMonthEvent, dateI18n( _x( 'F', 'upcoming events month format' ), startDate, timeZone ), dateI18n( _x( 'j', 'upcoming events day format' ), startDate, timeZone ), dateI18n( _x( 'F', 'upcoming events month format' ), endDate, timeZone ), dateI18n( _x( 'j', 'upcoming events day format' ), endDate, timeZone ), dateI18n( _x( 'Y', 'upcoming events year format' ), endDate, timeZone ) ); } return formattedDate; } }; if ( $( '#dashboard_primary' ).is( ':visible' ) ) { app.init(); } else { $( document ).on( 'postbox-toggled', function( event, postbox ) { var $postbox = $( postbox ); if ( 'dashboard_primary' === $postbox.attr( 'id' ) && $postbox.is( ':visible' ) ) { app.init(); } }); } }); /** * Removed in 5.6.0, needed for back-compatibility. * * @since 4.8.0 * @deprecated 5.6.0 * * @type {object} */ window.communityEventsData.l10n = window.communityEventsData.l10n || { enter_closest_city: '', error_occurred_please_try_again: '', attend_event_near_generic: '', could_not_locate_city: '', city_updated: '' }; window.communityEventsData.l10n = window.wp.deprecateL10nObject( 'communityEventsData.l10n', window.communityEventsData.l10n, '5.6.0' ); PK!f[##comment.min.jsnu[/*! This file is auto-generated */ jQuery(function(m){postboxes.add_postbox_toggles("comment");var d=m("#timestampdiv"),o=m("#timestamp"),a=o.html(),v=d.find(".timestamp-wrap"),c=d.siblings("a.edit-timestamp");c.on("click",function(e){d.is(":hidden")&&(d.slideDown("fast",function(){m("input, select",v).first().trigger("focus")}),m(this).hide()),e.preventDefault()}),d.find(".cancel-timestamp").on("click",function(e){c.show().trigger("focus"),d.slideUp("fast"),m("#mm").val(m("#hidden_mm").val()),m("#jj").val(m("#hidden_jj").val()),m("#aa").val(m("#hidden_aa").val()),m("#hh").val(m("#hidden_hh").val()),m("#mn").val(m("#hidden_mn").val()),o.html(a),e.preventDefault()}),d.find(".save-timestamp").on("click",function(e){var a=m("#aa").val(),t=m("#mm").val(),i=m("#jj").val(),s=m("#hh").val(),l=m("#mn").val(),n=new Date(a,t-1,i,s,l);e.preventDefault(),n.getFullYear()!=a||1+n.getMonth()!=t||n.getDate()!=i||n.getMinutes()!=l?v.addClass("form-invalid"):(v.removeClass("form-invalid"),o.html(wp.i18n.__("Submitted on:")+" "+wp.i18n.__("%1$s %2$s, %3$s at %4$s:%5$s").replace("%1$s",m('option[value="'+t+'"]',"#mm").attr("data-text")).replace("%2$s",parseInt(i,10)).replace("%3$s",a).replace("%4$s",("00"+s).slice(-2)).replace("%5$s",("00"+l).slice(-2))+" "),c.show().trigger("focus"),d.slideUp("fast"))})});PK!{X auth-app.jsnu[/** * @output wp-admin/js/auth-app.js */ /* global authApp */ ( function( $, authApp ) { var $appNameField = $( '#app_name' ), $approveBtn = $( '#approve' ), $rejectBtn = $( '#reject' ), $form = $appNameField.closest( 'form' ), context = { userLogin: authApp.user_login, successUrl: authApp.success, rejectUrl: authApp.reject }; $approveBtn.on( 'click', function( e ) { var name = $appNameField.val(), appId = $( 'input[name="app_id"]', $form ).val(); e.preventDefault(); if ( $approveBtn.prop( 'aria-disabled' ) ) { return; } if ( 0 === name.length ) { $appNameField.trigger( 'focus' ); return; } $approveBtn.prop( 'aria-disabled', true ).addClass( 'disabled' ); var request = { name: name }; if ( appId.length > 0 ) { request.app_id = appId; } /** * Filters the request data used to Authorize an Application Password request. * * @since 5.6.0 * * @param {Object} request The request data. * @param {Object} context Context about the Application Password request. * @param {string} context.userLogin The user's login username. * @param {string} context.successUrl The URL the user will be redirected to after approving the request. * @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request. */ request = wp.hooks.applyFilters( 'wp_application_passwords_approve_app_request', request, context ); wp.apiRequest( { path: '/wp/v2/users/me/application-passwords?_locale=user', method: 'POST', data: request } ).done( function( response, textStatus, jqXHR ) { /** * Fires when an Authorize Application Password request has been successfully approved. * * In most cases, this should be used in combination with the {@see 'wp_authorize_application_password_form_approved_no_js'} * action to ensure that both the JS and no-JS variants are handled. * * @since 5.6.0 * * @param {Object} response The response from the REST API. * @param {string} response.password The newly created password. * @param {string} textStatus The status of the request. * @param {jqXHR} jqXHR The underlying jqXHR object that made the request. */ wp.hooks.doAction( 'wp_application_passwords_approve_app_request_success', response, textStatus, jqXHR ); var raw = authApp.success, url, message, $notice; if ( raw ) { url = raw + ( -1 === raw.indexOf( '?' ) ? '?' : '&' ) + 'site_url=' + encodeURIComponent( authApp.site_url ) + '&user_login=' + encodeURIComponent( authApp.user_login ) + '&password=' + encodeURIComponent( response.password ); window.location = url; } else { message = wp.i18n.sprintf( /* translators: %s: Application name. */ '', '' ) + ' '; $notice = $( '
    ' ) .attr( 'role', 'alert' ) .attr( 'tabindex', -1 ) .addClass( 'notice notice-success notice-alt' ) .append( $( '

    ' ).addClass( 'application-password-display' ).html( message ) ) .append( '

    ' + wp.i18n.__( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ) + '

    ' ); // We're using .text() to write the variables to avoid any chance of XSS. $( 'strong', $notice ).text( response.name ); $( 'input', $notice ).val( response.password ); $form.replaceWith( $notice ); $notice.trigger( 'focus' ); } } ).fail( function( jqXHR, textStatus, errorThrown ) { var errorMessage = errorThrown, error = null; if ( jqXHR.responseJSON ) { error = jqXHR.responseJSON; if ( error.message ) { errorMessage = error.message; } } var $notice = $( '
    ' ) .attr( 'role', 'alert' ) .addClass( 'notice notice-error' ) .append( $( '

    ' ).text( errorMessage ) ); $( 'h1' ).after( $notice ); $approveBtn.removeProp( 'aria-disabled', false ).removeClass( 'disabled' ); /** * Fires when an Authorize Application Password request encountered an error when trying to approve the request. * * @since 5.6.0 * @since 5.6.1 Corrected action name and signature. * * @param {Object|null} error The error from the REST API. May be null if the server did not send proper JSON. * @param {string} textStatus The status of the request. * @param {string} errorThrown The error message associated with the response status code. * @param {jqXHR} jqXHR The underlying jqXHR object that made the request. */ wp.hooks.doAction( 'wp_application_passwords_approve_app_request_error', error, textStatus, errorThrown, jqXHR ); } ); } ); $rejectBtn.on( 'click', function( e ) { e.preventDefault(); /** * Fires when an Authorize Application Password request has been rejected by the user. * * @since 5.6.0 * * @param {Object} context Context about the Application Password request. * @param {string} context.userLogin The user's login username. * @param {string} context.successUrl The URL the user will be redirected to after approving the request. * @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request. */ wp.hooks.doAction( 'wp_application_passwords_reject_app', context ); // @todo: Make a better way to do this so it feels like less of a semi-open redirect. window.location = authApp.reject; } ); $form.on( 'submit', function( e ) { e.preventDefault(); } ); }( jQuery, authApp ) ); PK!Ƙ---theme-plugin-editor.min.jsnu[/*! This file is auto-generated */ window.wp||(window.wp={}),wp.themePluginEditor=function(i){"use strict";var t,o=wp.i18n.__,s=wp.i18n._n,r=wp.i18n.sprintf,n={codeEditor:{},instance:null,noticeElements:{},dirty:!1,lintErrors:[],init:function(e,t){n.form=e,t&&i.extend(n,t),n.noticeTemplate=wp.template("wp-file-editor-notice"),n.noticesContainer=n.form.find(".editor-notices"),n.submitButton=n.form.find(":input[name=submit]"),n.spinner=n.form.find(".submit .spinner"),n.form.on("submit",n.submit),n.textarea=n.form.find("#newcontent"),n.textarea.on("change",n.onChange),n.warning=i(".file-editor-warning"),n.docsLookUpButton=n.form.find("#docs-lookup"),n.docsLookUpList=n.form.find("#docs-list"),0} Notifications. */ get: function( args ) { var collection = this, notifications, errorTypePriorities, params; notifications = _.values( collection._value ); params = _.extend( { sort: false }, args ); if ( params.sort ) { errorTypePriorities = { error: 4, warning: 3, success: 2, info: 1 }; notifications.sort( function( a, b ) { var aPriority = 0, bPriority = 0; if ( ! _.isUndefined( errorTypePriorities[ a.type ] ) ) { aPriority = errorTypePriorities[ a.type ]; } if ( ! _.isUndefined( errorTypePriorities[ b.type ] ) ) { bPriority = errorTypePriorities[ b.type ]; } if ( aPriority !== bPriority ) { return bPriority - aPriority; // Show errors first. } return collection._addedOrder[ b.code ] - collection._addedOrder[ a.code ]; // Show newer notifications higher. }); } return notifications; }, /** * Render notifications area. * * @since 4.9.0 * @return {void} */ render: function() { var collection = this, notifications, hadOverlayNotification = false, hasOverlayNotification, overlayNotifications = [], previousNotificationsByCode = {}, listElement, focusableElements; // Short-circuit if there are no container to render into. if ( ! collection.container || ! collection.container.length ) { return; } notifications = collection.get( { sort: true } ); collection.container.toggle( 0 !== notifications.length ); // Short-circuit if there are no changes to the notifications. if ( collection.container.is( collection.previousContainer ) && _.isEqual( notifications, collection.previousNotifications ) ) { return; } // Make sure list is part of the container. listElement = collection.container.children( 'ul' ).first(); if ( ! listElement.length ) { listElement = $( '
      ' ); collection.container.append( listElement ); } // Remove all notifications prior to re-rendering. listElement.find( '> [data-code]' ).remove(); _.each( collection.previousNotifications, function( notification ) { previousNotificationsByCode[ notification.code ] = notification; }); // Add all notifications in the sorted order. _.each( notifications, function( notification ) { var notificationContainer; if ( wp.a11y && ( ! previousNotificationsByCode[ notification.code ] || ! _.isEqual( notification.message, previousNotificationsByCode[ notification.code ].message ) ) ) { wp.a11y.speak( notification.message, 'assertive' ); } notificationContainer = $( notification.render() ); notification.container = notificationContainer; listElement.append( notificationContainer ); // @todo Consider slideDown() as enhancement. if ( notification.extended( api.OverlayNotification ) ) { overlayNotifications.push( notification ); } }); hasOverlayNotification = Boolean( overlayNotifications.length ); if ( collection.previousNotifications ) { hadOverlayNotification = Boolean( _.find( collection.previousNotifications, function( notification ) { return notification.extended( api.OverlayNotification ); } ) ); } if ( hasOverlayNotification !== hadOverlayNotification ) { $( document.body ).toggleClass( 'customize-loading', hasOverlayNotification ); collection.container.toggleClass( 'has-overlay-notifications', hasOverlayNotification ); if ( hasOverlayNotification ) { collection.previousActiveElement = document.activeElement; $( document ).on( 'keydown', collection.constrainFocus ); } else { $( document ).off( 'keydown', collection.constrainFocus ); } } if ( hasOverlayNotification ) { collection.focusContainer = overlayNotifications[ overlayNotifications.length - 1 ].container; collection.focusContainer.prop( 'tabIndex', -1 ); focusableElements = collection.focusContainer.find( ':focusable' ); if ( focusableElements.length ) { focusableElements.first().focus(); } else { collection.focusContainer.focus(); } } else if ( collection.previousActiveElement ) { $( collection.previousActiveElement ).trigger( 'focus' ); collection.previousActiveElement = null; } collection.previousNotifications = notifications; collection.previousContainer = collection.container; collection.trigger( 'rendered' ); }, /** * Constrain focus on focus container. * * @since 4.9.0 * * @param {jQuery.Event} event - Event. * @return {void} */ constrainFocus: function constrainFocus( event ) { var collection = this, focusableElements; // Prevent keys from escaping. event.stopPropagation(); if ( 9 !== event.which ) { // Tab key. return; } focusableElements = collection.focusContainer.find( ':focusable' ); if ( 0 === focusableElements.length ) { focusableElements = collection.focusContainer; } if ( ! $.contains( collection.focusContainer[0], event.target ) || ! $.contains( collection.focusContainer[0], document.activeElement ) ) { event.preventDefault(); focusableElements.first().focus(); } else if ( focusableElements.last().is( event.target ) && ! event.shiftKey ) { event.preventDefault(); focusableElements.first().focus(); } else if ( focusableElements.first().is( event.target ) && event.shiftKey ) { event.preventDefault(); focusableElements.last().focus(); } } }); api.Setting = api.Value.extend(/** @lends wp.customize.Setting.prototype */{ /** * Default params. * * @since 4.9.0 * @var {object} */ defaults: { transport: 'refresh', dirty: false }, /** * A Customizer Setting. * * A setting is WordPress data (theme mod, option, menu, etc.) that the user can * draft changes to in the Customizer. * * @see PHP class WP_Customize_Setting. * * @constructs wp.customize.Setting * @augments wp.customize.Value * * @since 3.4.0 * * @param {string} id - The setting ID. * @param {*} value - The initial value of the setting. * @param {Object} [options={}] - Options. * @param {string} [options.transport=refresh] - The transport to use for previewing. Supports 'refresh' and 'postMessage'. * @param {boolean} [options.dirty=false] - Whether the setting should be considered initially dirty. * @param {Object} [options.previewer] - The Previewer instance to sync with. Defaults to wp.customize.previewer. */ initialize: function( id, value, options ) { var setting = this, params; params = _.extend( { previewer: api.previewer }, setting.defaults, options || {} ); api.Value.prototype.initialize.call( setting, value, params ); setting.id = id; setting._dirty = params.dirty; // The _dirty property is what the Customizer reads from. setting.notifications = new api.Notifications(); // Whenever the setting's value changes, refresh the preview. setting.bind( setting.preview ); }, /** * Refresh the preview, respective of the setting's refresh policy. * * If the preview hasn't sent a keep-alive message and is likely * disconnected by having navigated to a non-allowed URL, then the * refresh transport will be forced when postMessage is the transport. * Note that postMessage does not throw an error when the recipient window * fails to match the origin window, so using try/catch around the * previewer.send() call to then fallback to refresh will not work. * * @since 3.4.0 * @access public * * @return {void} */ preview: function() { var setting = this, transport; transport = setting.transport; if ( 'postMessage' === transport && ! api.state( 'previewerAlive' ).get() ) { transport = 'refresh'; } if ( 'postMessage' === transport ) { setting.previewer.send( 'setting', [ setting.id, setting() ] ); } else if ( 'refresh' === transport ) { setting.previewer.refresh(); } }, /** * Find controls associated with this setting. * * @since 4.6.0 * @return {wp.customize.Control[]} Controls associated with setting. */ findControls: function() { var setting = this, controls = []; api.control.each( function( control ) { _.each( control.settings, function( controlSetting ) { if ( controlSetting.id === setting.id ) { controls.push( control ); } } ); } ); return controls; } }); /** * Current change count. * * @alias wp.customize._latestRevision * * @since 4.7.0 * @type {number} * @protected */ api._latestRevision = 0; /** * Last revision that was saved. * * @alias wp.customize._lastSavedRevision * * @since 4.7.0 * @type {number} * @protected */ api._lastSavedRevision = 0; /** * Latest revisions associated with the updated setting. * * @alias wp.customize._latestSettingRevisions * * @since 4.7.0 * @type {object} * @protected */ api._latestSettingRevisions = {}; /* * Keep track of the revision associated with each updated setting so that * requestChangesetUpdate knows which dirty settings to include. Also, once * ready is triggered and all initial settings have been added, increment * revision for each newly-created initially-dirty setting so that it will * also be included in changeset update requests. */ api.bind( 'change', function incrementChangedSettingRevision( setting ) { api._latestRevision += 1; api._latestSettingRevisions[ setting.id ] = api._latestRevision; } ); api.bind( 'ready', function() { api.bind( 'add', function incrementCreatedSettingRevision( setting ) { if ( setting._dirty ) { api._latestRevision += 1; api._latestSettingRevisions[ setting.id ] = api._latestRevision; } } ); } ); /** * Get the dirty setting values. * * @alias wp.customize.dirtyValues * * @since 4.7.0 * @access public * * @param {Object} [options] Options. * @param {boolean} [options.unsaved=false] Whether only values not saved yet into a changeset will be returned (differential changes). * @return {Object} Dirty setting values. */ api.dirtyValues = function dirtyValues( options ) { var values = {}; api.each( function( setting ) { var settingRevision; if ( ! setting._dirty ) { return; } settingRevision = api._latestSettingRevisions[ setting.id ]; // Skip including settings that have already been included in the changeset, if only requesting unsaved. if ( api.state( 'changesetStatus' ).get() && ( options && options.unsaved ) && ( _.isUndefined( settingRevision ) || settingRevision <= api._lastSavedRevision ) ) { return; } values[ setting.id ] = setting.get(); } ); return values; }; /** * Request updates to the changeset. * * @alias wp.customize.requestChangesetUpdate * * @since 4.7.0 * @access public * * @param {Object} [changes] - Mapping of setting IDs to setting params each normally including a value property, or mapping to null. * If not provided, then the changes will still be obtained from unsaved dirty settings. * @param {Object} [args] - Additional options for the save request. * @param {boolean} [args.autosave=false] - Whether changes will be stored in autosave revision if the changeset has been promoted from an auto-draft. * @param {boolean} [args.force=false] - Send request to update even when there are no changes to submit. This can be used to request the latest status of the changeset on the server. * @param {string} [args.title] - Title to update in the changeset. Optional. * @param {string} [args.date] - Date to update in the changeset. Optional. * @return {jQuery.Promise} Promise resolving with the response data. */ api.requestChangesetUpdate = function requestChangesetUpdate( changes, args ) { var deferred, request, submittedChanges = {}, data, submittedArgs; deferred = new $.Deferred(); // Prevent attempting changeset update while request is being made. if ( 0 !== api.state( 'processing' ).get() ) { deferred.reject( 'already_processing' ); return deferred.promise(); } submittedArgs = _.extend( { title: null, date: null, autosave: false, force: false }, args ); if ( changes ) { _.extend( submittedChanges, changes ); } // Ensure all revised settings (changes pending save) are also included, but not if marked for deletion in changes. _.each( api.dirtyValues( { unsaved: true } ), function( dirtyValue, settingId ) { if ( ! changes || null !== changes[ settingId ] ) { submittedChanges[ settingId ] = _.extend( {}, submittedChanges[ settingId ] || {}, { value: dirtyValue } ); } } ); // Allow plugins to attach additional params to the settings. api.trigger( 'changeset-save', submittedChanges, submittedArgs ); // Short-circuit when there are no pending changes. if ( ! submittedArgs.force && _.isEmpty( submittedChanges ) && null === submittedArgs.title && null === submittedArgs.date ) { deferred.resolve( {} ); return deferred.promise(); } // A status would cause a revision to be made, and for this wp.customize.previewer.save() should be used. // Status is also disallowed for revisions regardless. if ( submittedArgs.status ) { return deferred.reject( { code: 'illegal_status_in_changeset_update' } ).promise(); } // Dates not beung allowed for revisions are is a technical limitation of post revisions. if ( submittedArgs.date && submittedArgs.autosave ) { return deferred.reject( { code: 'illegal_autosave_with_date_gmt' } ).promise(); } // Make sure that publishing a changeset waits for all changeset update requests to complete. api.state( 'processing' ).set( api.state( 'processing' ).get() + 1 ); deferred.always( function() { api.state( 'processing' ).set( api.state( 'processing' ).get() - 1 ); } ); // Ensure that if any plugins add data to save requests by extending query() that they get included here. data = api.previewer.query( { excludeCustomizedSaved: true } ); delete data.customized; // Being sent in customize_changeset_data instead. _.extend( data, { nonce: api.settings.nonce.save, customize_theme: api.settings.theme.stylesheet, customize_changeset_data: JSON.stringify( submittedChanges ) } ); if ( null !== submittedArgs.title ) { data.customize_changeset_title = submittedArgs.title; } if ( null !== submittedArgs.date ) { data.customize_changeset_date = submittedArgs.date; } if ( false !== submittedArgs.autosave ) { data.customize_changeset_autosave = 'true'; } // Allow plugins to modify the params included with the save request. api.trigger( 'save-request-params', data ); request = wp.ajax.post( 'customize_save', data ); request.done( function requestChangesetUpdateDone( data ) { var savedChangesetValues = {}; // Ensure that all settings updated subsequently will be included in the next changeset update request. api._lastSavedRevision = Math.max( api._latestRevision, api._lastSavedRevision ); api.state( 'changesetStatus' ).set( data.changeset_status ); if ( data.changeset_date ) { api.state( 'changesetDate' ).set( data.changeset_date ); } deferred.resolve( data ); api.trigger( 'changeset-saved', data ); if ( data.setting_validities ) { _.each( data.setting_validities, function( validity, settingId ) { if ( true === validity && _.isObject( submittedChanges[ settingId ] ) && ! _.isUndefined( submittedChanges[ settingId ].value ) ) { savedChangesetValues[ settingId ] = submittedChanges[ settingId ].value; } } ); } api.previewer.send( 'changeset-saved', _.extend( {}, data, { saved_changeset_values: savedChangesetValues } ) ); } ); request.fail( function requestChangesetUpdateFail( data ) { deferred.reject( data ); api.trigger( 'changeset-error', data ); } ); request.always( function( data ) { if ( data.setting_validities ) { api._handleSettingValidities( { settingValidities: data.setting_validities } ); } } ); return deferred.promise(); }; /** * Watch all changes to Value properties, and bubble changes to parent Values instance * * @alias wp.customize.utils.bubbleChildValueChanges * * @since 4.1.0 * * @param {wp.customize.Class} instance * @param {Array} properties The names of the Value instances to watch. */ api.utils.bubbleChildValueChanges = function ( instance, properties ) { $.each( properties, function ( i, key ) { instance[ key ].bind( function ( to, from ) { if ( instance.parent && to !== from ) { instance.parent.trigger( 'change', instance ); } } ); } ); }; /** * Expand a panel, section, or control and focus on the first focusable element. * * @alias wp.customize~focus * * @since 4.1.0 * * @param {Object} [params] * @param {Function} [params.completeCallback] */ focus = function ( params ) { var construct, completeCallback, focus, focusElement, sections; construct = this; params = params || {}; focus = function () { // If a child section is currently expanded, collapse it. if ( construct.extended( api.Panel ) ) { sections = construct.sections(); if ( 1 < sections.length ) { sections.forEach( function ( section ) { if ( section.expanded() ) { section.collapse(); } } ); } } var focusContainer; if ( ( construct.extended( api.Panel ) || construct.extended( api.Section ) ) && construct.expanded && construct.expanded() ) { focusContainer = construct.contentContainer; } else { focusContainer = construct.container; } focusElement = focusContainer.find( '.control-focus:first' ); if ( 0 === focusElement.length ) { // Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583 focusElement = focusContainer.find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' ).first(); } focusElement.focus(); }; if ( params.completeCallback ) { completeCallback = params.completeCallback; params.completeCallback = function () { focus(); completeCallback(); }; } else { params.completeCallback = focus; } api.state( 'paneVisible' ).set( true ); if ( construct.expand ) { construct.expand( params ); } else { params.completeCallback(); } }; /** * Stable sort for Panels, Sections, and Controls. * * If a.priority() === b.priority(), then sort by their respective params.instanceNumber. * * @alias wp.customize.utils.prioritySort * * @since 4.1.0 * * @param {(wp.customize.Panel|wp.customize.Section|wp.customize.Control)} a * @param {(wp.customize.Panel|wp.customize.Section|wp.customize.Control)} b * @return {number} */ api.utils.prioritySort = function ( a, b ) { if ( a.priority() === b.priority() && typeof a.params.instanceNumber === 'number' && typeof b.params.instanceNumber === 'number' ) { return a.params.instanceNumber - b.params.instanceNumber; } else { return a.priority() - b.priority(); } }; /** * Return whether the supplied Event object is for a keydown event but not the Enter key. * * @alias wp.customize.utils.isKeydownButNotEnterEvent * * @since 4.1.0 * * @param {jQuery.Event} event * @return {boolean} */ api.utils.isKeydownButNotEnterEvent = function ( event ) { return ( 'keydown' === event.type && 13 !== event.which ); }; /** * Return whether the two lists of elements are the same and are in the same order. * * @alias wp.customize.utils.areElementListsEqual * * @since 4.1.0 * * @param {Array|jQuery} listA * @param {Array|jQuery} listB * @return {boolean} */ api.utils.areElementListsEqual = function ( listA, listB ) { var equal = ( listA.length === listB.length && // If lists are different lengths, then naturally they are not equal. -1 === _.indexOf( _.map( // Are there any false values in the list returned by map? _.zip( listA, listB ), // Pair up each element between the two lists. function ( pair ) { return $( pair[0] ).is( pair[1] ); // Compare to see if each pair is equal. } ), false ) // Check for presence of false in map's return value. ); return equal; }; /** * Highlight the existence of a button. * * This function reminds the user of a button represented by the specified * UI element, after an optional delay. If the user focuses the element * before the delay passes, the reminder is canceled. * * @alias wp.customize.utils.highlightButton * * @since 4.9.0 * * @param {jQuery} button - The element to highlight. * @param {Object} [options] - Options. * @param {number} [options.delay=0] - Delay in milliseconds. * @param {jQuery} [options.focusTarget] - A target for user focus that defaults to the highlighted element. * If the user focuses the target before the delay passes, the reminder * is canceled. This option exists to accommodate compound buttons * containing auxiliary UI, such as the Publish button augmented with a * Settings button. * @return {Function} An idempotent function that cancels the reminder. */ api.utils.highlightButton = function highlightButton( button, options ) { var animationClass = 'button-see-me', canceled = false, params; params = _.extend( { delay: 0, focusTarget: button }, options ); function cancelReminder() { canceled = true; } params.focusTarget.on( 'focusin', cancelReminder ); setTimeout( function() { params.focusTarget.off( 'focusin', cancelReminder ); if ( ! canceled ) { button.addClass( animationClass ); button.one( 'animationend', function() { /* * Remove animation class to avoid situations in Customizer where * DOM nodes are moved (re-inserted) and the animation repeats. */ button.removeClass( animationClass ); } ); } }, params.delay ); return cancelReminder; }; /** * Get current timestamp adjusted for server clock time. * * Same functionality as the `current_time( 'mysql', false )` function in PHP. * * @alias wp.customize.utils.getCurrentTimestamp * * @since 4.9.0 * * @return {number} Current timestamp. */ api.utils.getCurrentTimestamp = function getCurrentTimestamp() { var currentDate, currentClientTimestamp, timestampDifferential; currentClientTimestamp = _.now(); currentDate = new Date( api.settings.initialServerDate.replace( /-/g, '/' ) ); timestampDifferential = currentClientTimestamp - api.settings.initialClientTimestamp; timestampDifferential += api.settings.initialClientTimestamp - api.settings.initialServerTimestamp; currentDate.setTime( currentDate.getTime() + timestampDifferential ); return currentDate.getTime(); }; /** * Get remaining time of when the date is set. * * @alias wp.customize.utils.getRemainingTime * * @since 4.9.0 * * @param {string|number|Date} datetime - Date time or timestamp of the future date. * @return {number} remainingTime - Remaining time in milliseconds. */ api.utils.getRemainingTime = function getRemainingTime( datetime ) { var millisecondsDivider = 1000, remainingTime, timestamp; if ( datetime instanceof Date ) { timestamp = datetime.getTime(); } else if ( 'string' === typeof datetime ) { timestamp = ( new Date( datetime.replace( /-/g, '/' ) ) ).getTime(); } else { timestamp = datetime; } remainingTime = timestamp - api.utils.getCurrentTimestamp(); remainingTime = Math.ceil( remainingTime / millisecondsDivider ); return remainingTime; }; /** * Return browser supported `transitionend` event name. * * @since 4.7.0 * * @ignore * * @return {string|null} Normalized `transitionend` event name or null if CSS transitions are not supported. */ normalizedTransitionendEventName = (function () { var el, transitions, prop; el = document.createElement( 'div' ); transitions = { 'transition' : 'transitionend', 'OTransition' : 'oTransitionEnd', 'MozTransition' : 'transitionend', 'WebkitTransition': 'webkitTransitionEnd' }; prop = _.find( _.keys( transitions ), function( prop ) { return ! _.isUndefined( el.style[ prop ] ); } ); if ( prop ) { return transitions[ prop ]; } else { return null; } })(); Container = api.Class.extend(/** @lends wp.customize~Container.prototype */{ defaultActiveArguments: { duration: 'fast', completeCallback: $.noop }, defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop }, containerType: 'container', defaults: { title: '', description: '', priority: 100, type: 'default', content: null, active: true, instanceNumber: null }, /** * Base class for Panel and Section. * * @constructs wp.customize~Container * @augments wp.customize.Class * * @since 4.1.0 * * @borrows wp.customize~focus as focus * * @param {string} id - The ID for the container. * @param {Object} options - Object containing one property: params. * @param {string} options.title - Title shown when panel is collapsed and expanded. * @param {string} [options.description] - Description shown at the top of the panel. * @param {number} [options.priority=100] - The sort priority for the panel. * @param {string} [options.templateId] - Template selector for container. * @param {string} [options.type=default] - The type of the panel. See wp.customize.panelConstructor. * @param {string} [options.content] - The markup to be used for the panel container. If empty, a JS template is used. * @param {boolean} [options.active=true] - Whether the panel is active or not. * @param {Object} [options.params] - Deprecated wrapper for the above properties. */ initialize: function ( id, options ) { var container = this; container.id = id; if ( ! Container.instanceCounter ) { Container.instanceCounter = 0; } Container.instanceCounter++; $.extend( container, { params: _.defaults( options.params || options, // Passing the params is deprecated. container.defaults ) } ); if ( ! container.params.instanceNumber ) { container.params.instanceNumber = Container.instanceCounter; } container.notifications = new api.Notifications(); container.templateSelector = container.params.templateId || 'customize-' + container.containerType + '-' + container.params.type; container.container = $( container.params.content ); if ( 0 === container.container.length ) { container.container = $( container.getContainer() ); } container.headContainer = container.container; container.contentContainer = container.getContent(); container.container = container.container.add( container.contentContainer ); container.deferred = { embedded: new $.Deferred() }; container.priority = new api.Value(); container.active = new api.Value(); container.activeArgumentsQueue = []; container.expanded = new api.Value(); container.expandedArgumentsQueue = []; container.active.bind( function ( active ) { var args = container.activeArgumentsQueue.shift(); args = $.extend( {}, container.defaultActiveArguments, args ); active = ( active && container.isContextuallyActive() ); container.onChangeActive( active, args ); }); container.expanded.bind( function ( expanded ) { var args = container.expandedArgumentsQueue.shift(); args = $.extend( {}, container.defaultExpandedArguments, args ); container.onChangeExpanded( expanded, args ); }); container.deferred.embedded.done( function () { container.setupNotifications(); container.attachEvents(); }); api.utils.bubbleChildValueChanges( container, [ 'priority', 'active' ] ); container.priority.set( container.params.priority ); container.active.set( container.params.active ); container.expanded.set( false ); }, /** * Get the element that will contain the notifications. * * @since 4.9.0 * @return {jQuery} Notification container element. */ getNotificationsContainerElement: function() { var container = this; return container.contentContainer.find( '.customize-control-notifications-container:first' ); }, /** * Set up notifications. * * @since 4.9.0 * @return {void} */ setupNotifications: function() { var container = this, renderNotifications; container.notifications.container = container.getNotificationsContainerElement(); // Render notifications when they change and when the construct is expanded. renderNotifications = function() { if ( container.expanded.get() ) { container.notifications.render(); } }; container.expanded.bind( renderNotifications ); renderNotifications(); container.notifications.bind( 'change', _.debounce( renderNotifications ) ); }, /** * @since 4.1.0 * * @abstract */ ready: function() {}, /** * Get the child models associated with this parent, sorting them by their priority Value. * * @since 4.1.0 * * @param {string} parentType * @param {string} childType * @return {Array} */ _children: function ( parentType, childType ) { var parent = this, children = []; api[ childType ].each( function ( child ) { if ( child[ parentType ].get() === parent.id ) { children.push( child ); } } ); children.sort( api.utils.prioritySort ); return children; }, /** * To override by subclass, to return whether the container has active children. * * @since 4.1.0 * * @abstract */ isContextuallyActive: function () { throw new Error( 'Container.isContextuallyActive() must be overridden in a subclass.' ); }, /** * Active state change handler. * * Shows the container if it is active, hides it if not. * * To override by subclass, update the container's UI to reflect the provided active state. * * @since 4.1.0 * * @param {boolean} active - The active state to transiution to. * @param {Object} [args] - Args. * @param {Object} [args.duration] - The duration for the slideUp/slideDown animation. * @param {boolean} [args.unchanged] - Whether the state is already known to not be changed, and so short-circuit with calling completeCallback early. * @param {Function} [args.completeCallback] - Function to call when the slideUp/slideDown has completed. */ onChangeActive: function( active, args ) { var construct = this, headContainer = construct.headContainer, duration, expandedOtherPanel; if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); } return; } duration = ( 'resolved' === api.previewer.deferred.active.state() ? args.duration : 0 ); if ( construct.extended( api.Panel ) ) { // If this is a panel is not currently expanded but another panel is expanded, do not animate. api.panel.each(function ( panel ) { if ( panel !== construct && panel.expanded() ) { expandedOtherPanel = panel; duration = 0; } }); // Collapse any expanded sections inside of this panel first before deactivating. if ( ! active ) { _.each( construct.sections(), function( section ) { section.collapse( { duration: 0 } ); } ); } } if ( ! $.contains( document, headContainer.get( 0 ) ) ) { // If the element is not in the DOM, then jQuery.fn.slideUp() does nothing. // In this case, a hard toggle is required instead. headContainer.toggle( active ); if ( args.completeCallback ) { args.completeCallback(); } } else if ( active ) { headContainer.slideDown( duration, args.completeCallback ); } else { if ( construct.expanded() ) { construct.collapse({ duration: duration, completeCallback: function() { headContainer.slideUp( duration, args.completeCallback ); } }); } else { headContainer.slideUp( duration, args.completeCallback ); } } }, /** * @since 4.1.0 * * @param {boolean} active * @param {Object} [params] * @return {boolean} False if state already applied. */ _toggleActive: function ( active, params ) { var self = this; params = params || {}; if ( ( active && this.active.get() ) || ( ! active && ! this.active.get() ) ) { params.unchanged = true; self.onChangeActive( self.active.get(), params ); return false; } else { params.unchanged = false; this.activeArgumentsQueue.push( params ); this.active.set( active ); return true; } }, /** * @param {Object} [params] * @return {boolean} False if already active. */ activate: function ( params ) { return this._toggleActive( true, params ); }, /** * @param {Object} [params] * @return {boolean} False if already inactive. */ deactivate: function ( params ) { return this._toggleActive( false, params ); }, /** * To override by subclass, update the container's UI to reflect the provided active state. * @abstract */ onChangeExpanded: function () { throw new Error( 'Must override with subclass.' ); }, /** * Handle the toggle logic for expand/collapse. * * @param {boolean} expanded - The new state to apply. * @param {Object} [params] - Object containing options for expand/collapse. * @param {Function} [params.completeCallback] - Function to call when expansion/collapse is complete. * @return {boolean} False if state already applied or active state is false. */ _toggleExpanded: function( expanded, params ) { var instance = this, previousCompleteCallback; params = params || {}; previousCompleteCallback = params.completeCallback; // Short-circuit expand() if the instance is not active. if ( expanded && ! instance.active() ) { return false; } api.state( 'paneVisible' ).set( true ); params.completeCallback = function() { if ( previousCompleteCallback ) { previousCompleteCallback.apply( instance, arguments ); } if ( expanded ) { instance.container.trigger( 'expanded' ); } else { instance.container.trigger( 'collapsed' ); } }; if ( ( expanded && instance.expanded.get() ) || ( ! expanded && ! instance.expanded.get() ) ) { params.unchanged = true; instance.onChangeExpanded( instance.expanded.get(), params ); return false; } else { params.unchanged = false; instance.expandedArgumentsQueue.push( params ); instance.expanded.set( expanded ); return true; } }, /** * @param {Object} [params] * @return {boolean} False if already expanded or if inactive. */ expand: function ( params ) { return this._toggleExpanded( true, params ); }, /** * @param {Object} [params] * @return {boolean} False if already collapsed. */ collapse: function ( params ) { return this._toggleExpanded( false, params ); }, /** * Animate container state change if transitions are supported by the browser. * * @since 4.7.0 * @private * * @param {function} completeCallback Function to be called after transition is completed. * @return {void} */ _animateChangeExpanded: function( completeCallback ) { // Return if CSS transitions are not supported or if reduced motion is enabled. if ( ! normalizedTransitionendEventName || isReducedMotion ) { // Schedule the callback until the next tick to prevent focus loss. _.defer( function () { if ( completeCallback ) { completeCallback(); } } ); return; } var construct = this, content = construct.contentContainer, overlay = content.closest( '.wp-full-overlay' ), elements, transitionEndCallback, transitionParentPane; // Determine set of elements that are affected by the animation. elements = overlay.add( content ); if ( ! construct.panel || '' === construct.panel() ) { transitionParentPane = true; } else if ( api.panel( construct.panel() ).contentContainer.hasClass( 'skip-transition' ) ) { transitionParentPane = true; } else { transitionParentPane = false; } if ( transitionParentPane ) { elements = elements.add( '#customize-info, .customize-pane-parent' ); } // Handle `transitionEnd` event. transitionEndCallback = function( e ) { if ( 2 !== e.eventPhase || ! $( e.target ).is( content ) ) { return; } content.off( normalizedTransitionendEventName, transitionEndCallback ); elements.removeClass( 'busy' ); if ( completeCallback ) { completeCallback(); } }; content.on( normalizedTransitionendEventName, transitionEndCallback ); elements.addClass( 'busy' ); // Prevent screen flicker when pane has been scrolled before expanding. _.defer( function() { var container = content.closest( '.wp-full-overlay-sidebar-content' ), currentScrollTop = container.scrollTop(), previousScrollTop = content.data( 'previous-scrollTop' ) || 0, expanded = construct.expanded(); if ( expanded && 0 < currentScrollTop ) { content.css( 'top', currentScrollTop + 'px' ); content.data( 'previous-scrollTop', currentScrollTop ); } else if ( ! expanded && 0 < currentScrollTop + previousScrollTop ) { content.css( 'top', previousScrollTop - currentScrollTop + 'px' ); container.scrollTop( previousScrollTop ); } } ); }, /* * is documented using @borrows in the constructor. */ focus: focus, /** * Return the container html, generated from its JS template, if it exists. * * @since 4.3.0 */ getContainer: function () { var template, container = this; if ( 0 !== $( '#tmpl-' + container.templateSelector ).length ) { template = wp.template( container.templateSelector ); } else { template = wp.template( 'customize-' + container.containerType + '-default' ); } if ( template && container.container ) { return template( _.extend( { id: container.id }, container.params ) ).toString().trim(); } return '
    • '; }, /** * Find content element which is displayed when the section is expanded. * * After a construct is initialized, the return value will be available via the `contentContainer` property. * By default the element will be related it to the parent container with `aria-owns` and detached. * Custom panels and sections (such as the `NewMenuSection`) that do not have a sliding pane should * just return the content element without needing to add the `aria-owns` element or detach it from * the container. Such non-sliding pane custom sections also need to override the `onChangeExpanded` * method to handle animating the panel/section into and out of view. * * @since 4.7.0 * @access public * * @return {jQuery} Detached content element. */ getContent: function() { var construct = this, container = construct.container, content = container.find( '.accordion-section-content, .control-panel-content' ).first(), contentId = 'sub-' + container.attr( 'id' ), ownedElements = contentId, alreadyOwnedElements = container.attr( 'aria-owns' ); if ( alreadyOwnedElements ) { ownedElements = ownedElements + ' ' + alreadyOwnedElements; } container.attr( 'aria-owns', ownedElements ); return content.detach().attr( { 'id': contentId, 'class': 'customize-pane-child ' + content.attr( 'class' ) + ' ' + container.attr( 'class' ) } ); } }); api.Section = Container.extend(/** @lends wp.customize.Section.prototype */{ containerType: 'section', containerParent: '#customize-theme-controls', containerPaneParent: '.customize-pane-parent', defaults: { title: '', description: '', priority: 100, type: 'default', content: null, active: true, instanceNumber: null, panel: null, customizeAction: '' }, /** * @constructs wp.customize.Section * @augments wp.customize~Container * * @since 4.1.0 * * @param {string} id - The ID for the section. * @param {Object} options - Options. * @param {string} options.title - Title shown when section is collapsed and expanded. * @param {string} [options.description] - Description shown at the top of the section. * @param {number} [options.priority=100] - The sort priority for the section. * @param {string} [options.type=default] - The type of the section. See wp.customize.sectionConstructor. * @param {string} [options.content] - The markup to be used for the section container. If empty, a JS template is used. * @param {boolean} [options.active=true] - Whether the section is active or not. * @param {string} options.panel - The ID for the panel this section is associated with. * @param {string} [options.customizeAction] - Additional context information shown before the section title when expanded. * @param {Object} [options.params] - Deprecated wrapper for the above properties. */ initialize: function ( id, options ) { var section = this, params; params = options.params || options; // Look up the type if one was not supplied. if ( ! params.type ) { _.find( api.sectionConstructor, function( Constructor, type ) { if ( Constructor === section.constructor ) { params.type = type; return true; } return false; } ); } Container.prototype.initialize.call( section, id, params ); section.id = id; section.panel = new api.Value(); section.panel.bind( function ( id ) { $( section.headContainer ).toggleClass( 'control-subsection', !! id ); }); section.panel.set( section.params.panel || '' ); api.utils.bubbleChildValueChanges( section, [ 'panel' ] ); section.embed(); section.deferred.embedded.done( function () { section.ready(); }); }, /** * Embed the container in the DOM when any parent panel is ready. * * @since 4.1.0 */ embed: function () { var inject, section = this; section.containerParent = api.ensure( section.containerParent ); // Watch for changes to the panel state. inject = function ( panelId ) { var parentContainer; if ( panelId ) { // The panel has been supplied, so wait until the panel object is registered. api.panel( panelId, function ( panel ) { // The panel has been registered, wait for it to become ready/initialized. panel.deferred.embedded.done( function () { parentContainer = panel.contentContainer; if ( ! section.headContainer.parent().is( parentContainer ) ) { parentContainer.append( section.headContainer ); } if ( ! section.contentContainer.parent().is( section.headContainer ) ) { section.containerParent.append( section.contentContainer ); } section.deferred.embedded.resolve(); }); } ); } else { // There is no panel, so embed the section in the root of the customizer. parentContainer = api.ensure( section.containerPaneParent ); if ( ! section.headContainer.parent().is( parentContainer ) ) { parentContainer.append( section.headContainer ); } if ( ! section.contentContainer.parent().is( section.headContainer ) ) { section.containerParent.append( section.contentContainer ); } section.deferred.embedded.resolve(); } }; section.panel.bind( inject ); inject( section.panel.get() ); // Since a section may never get a panel, assume that it won't ever get one. }, /** * Add behaviors for the accordion section. * * @since 4.1.0 */ attachEvents: function () { var meta, content, section = this; if ( section.container.hasClass( 'cannot-expand' ) ) { return; } // Expand/Collapse accordion sections on click. section.container.find( '.accordion-section-title button, .customize-section-back, .accordion-section-title[tabindex]' ).on( 'click keydown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); // Keep this AFTER the key filter above. if ( section.expanded() ) { section.collapse(); } else { section.expand(); } }); // This is very similar to what is found for api.Panel.attachEvents(). section.container.find( '.customize-section-title .customize-help-toggle' ).on( 'click', function() { meta = section.container.find( '.section-meta' ); if ( meta.hasClass( 'cannot-expand' ) ) { return; } content = meta.find( '.customize-section-description:first' ); content.toggleClass( 'open' ); content.slideToggle( section.defaultExpandedArguments.duration, function() { content.trigger( 'toggled' ); } ); $( this ).attr( 'aria-expanded', function( i, attr ) { return 'true' === attr ? 'false' : 'true'; }); }); }, /** * Return whether this section has any active controls. * * @since 4.1.0 * * @return {boolean} */ isContextuallyActive: function () { var section = this, controls = section.controls(), activeCount = 0; _( controls ).each( function ( control ) { if ( control.active() ) { activeCount += 1; } } ); return ( activeCount !== 0 ); }, /** * Get the controls that are associated with this section, sorted by their priority Value. * * @since 4.1.0 * * @return {Array} */ controls: function () { return this._children( 'section', 'control' ); }, /** * Update UI to reflect expanded state. * * @since 4.1.0 * * @param {boolean} expanded * @param {Object} args */ onChangeExpanded: function ( expanded, args ) { var section = this, container = section.headContainer.closest( '.wp-full-overlay-sidebar-content' ), content = section.contentContainer, overlay = section.headContainer.closest( '.wp-full-overlay' ), backBtn = content.find( '.customize-section-back' ), sectionTitle = section.headContainer.find( '.accordion-section-title button, .accordion-section-title[tabindex]' ).first(), expand, panel; if ( expanded && ! content.hasClass( 'open' ) ) { if ( args.unchanged ) { expand = args.completeCallback; } else { expand = function() { section._animateChangeExpanded( function() { backBtn.trigger( 'focus' ); content.css( 'top', '' ); container.scrollTop( 0 ); if ( args.completeCallback ) { args.completeCallback(); } } ); content.addClass( 'open' ); overlay.addClass( 'section-open' ); api.state( 'expandedSection' ).set( section ); }.bind( this ); } if ( ! args.allowMultiple ) { api.section.each( function ( otherSection ) { if ( otherSection !== section ) { otherSection.collapse( { duration: args.duration } ); } }); } if ( section.panel() ) { api.panel( section.panel() ).expand({ duration: args.duration, completeCallback: expand }); } else { if ( ! args.allowMultiple ) { api.panel.each( function( panel ) { panel.collapse(); }); } expand(); } } else if ( ! expanded && content.hasClass( 'open' ) ) { if ( section.panel() ) { panel = api.panel( section.panel() ); if ( panel.contentContainer.hasClass( 'skip-transition' ) ) { panel.collapse(); } } section._animateChangeExpanded( function() { sectionTitle.trigger( 'focus' ); content.css( 'top', '' ); if ( args.completeCallback ) { args.completeCallback(); } } ); content.removeClass( 'open' ); overlay.removeClass( 'section-open' ); if ( section === api.state( 'expandedSection' ).get() ) { api.state( 'expandedSection' ).set( false ); } } else { if ( args.completeCallback ) { args.completeCallback(); } } } }); api.ThemesSection = api.Section.extend(/** @lends wp.customize.ThemesSection.prototype */{ currentTheme: '', overlay: '', template: '', screenshotQueue: null, $window: null, $body: null, loaded: 0, loading: false, fullyLoaded: false, term: '', tags: '', nextTerm: '', nextTags: '', filtersHeight: 0, headerContainer: null, updateCountDebounced: null, /** * wp.customize.ThemesSection * * Custom section for themes that loads themes by category, and also * handles the theme-details view rendering and navigation. * * @constructs wp.customize.ThemesSection * @augments wp.customize.Section * * @since 4.9.0 * * @param {string} id - ID. * @param {Object} options - Options. * @return {void} */ initialize: function( id, options ) { var section = this; section.headerContainer = $(); section.$window = $( window ); section.$body = $( document.body ); api.Section.prototype.initialize.call( section, id, options ); section.updateCountDebounced = _.debounce( section.updateCount, 500 ); }, /** * Embed the section in the DOM when the themes panel is ready. * * Insert the section before the themes container. Assume that a themes section is within a panel, but not necessarily the themes panel. * * @since 4.9.0 */ embed: function() { var inject, section = this; // Watch for changes to the panel state. inject = function( panelId ) { var parentContainer; api.panel( panelId, function( panel ) { // The panel has been registered, wait for it to become ready/initialized. panel.deferred.embedded.done( function() { parentContainer = panel.contentContainer; if ( ! section.headContainer.parent().is( parentContainer ) ) { parentContainer.find( '.customize-themes-full-container-container' ).before( section.headContainer ); } if ( ! section.contentContainer.parent().is( section.headContainer ) ) { section.containerParent.append( section.contentContainer ); } section.deferred.embedded.resolve(); }); } ); }; section.panel.bind( inject ); inject( section.panel.get() ); // Since a section may never get a panel, assume that it won't ever get one. }, /** * Set up. * * @since 4.2.0 * * @return {void} */ ready: function() { var section = this; section.overlay = section.container.find( '.theme-overlay' ); section.template = wp.template( 'customize-themes-details-view' ); // Bind global keyboard events. section.container.on( 'keydown', function( event ) { if ( ! section.overlay.find( '.theme-wrap' ).is( ':visible' ) ) { return; } // Pressing the right arrow key fires a theme:next event. if ( 39 === event.keyCode ) { section.nextTheme(); } // Pressing the left arrow key fires a theme:previous event. if ( 37 === event.keyCode ) { section.previousTheme(); } // Pressing the escape key fires a theme:collapse event. if ( 27 === event.keyCode ) { if ( section.$body.hasClass( 'modal-open' ) ) { // Escape from the details modal. section.closeDetails(); } else { // Escape from the infinite scroll list. section.headerContainer.find( '.customize-themes-section-title' ).focus(); } event.stopPropagation(); // Prevent section from being collapsed. } }); section.renderScreenshots = _.throttle( section.renderScreenshots, 100 ); _.bindAll( section, 'renderScreenshots', 'loadMore', 'checkTerm', 'filtersChecked' ); }, /** * Override Section.isContextuallyActive method. * * Ignore the active states' of the contained theme controls, and just * use the section's own active state instead. This prevents empty search * results for theme sections from causing the section to become inactive. * * @since 4.2.0 * * @return {boolean} */ isContextuallyActive: function () { return this.active(); }, /** * Attach events. * * @since 4.2.0 * * @return {void} */ attachEvents: function () { var section = this, debounced; // Expand/Collapse accordion sections on click. section.container.find( '.customize-section-back' ).on( 'click keydown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); // Keep this AFTER the key filter above. section.collapse(); }); section.headerContainer = $( '#accordion-section-' + section.id ); // Expand section/panel. Only collapse when opening another section. section.headerContainer.on( 'click', '.customize-themes-section-title', function() { // Toggle accordion filters under section headers. if ( section.headerContainer.find( '.filter-details' ).length ) { section.headerContainer.find( '.customize-themes-section-title' ) .toggleClass( 'details-open' ) .attr( 'aria-expanded', function( i, attr ) { return 'true' === attr ? 'false' : 'true'; }); section.headerContainer.find( '.filter-details' ).slideToggle( 180 ); } // Open the section. if ( ! section.expanded() ) { section.expand(); } }); // Preview installed themes. section.container.on( 'click', '.theme-actions .preview-theme', function() { api.panel( 'themes' ).loadThemePreview( $( this ).data( 'slug' ) ); }); // Theme navigation in details view. section.container.on( 'click', '.left', function() { section.previousTheme(); }); section.container.on( 'click', '.right', function() { section.nextTheme(); }); section.container.on( 'click', '.theme-backdrop, .close', function() { section.closeDetails(); }); if ( 'local' === section.params.filter_type ) { // Filter-search all theme objects loaded in the section. section.container.on( 'input', '.wp-filter-search-themes', function( event ) { section.filterSearch( event.currentTarget.value ); }); } else if ( 'remote' === section.params.filter_type ) { // Event listeners for remote queries with user-entered terms. // Search terms. debounced = _.debounce( section.checkTerm, 500 ); // Wait until there is no input for 500 milliseconds to initiate a search. section.contentContainer.on( 'input', '.wp-filter-search', function() { if ( ! api.panel( 'themes' ).expanded() ) { return; } debounced( section ); if ( ! section.expanded() ) { section.expand(); } }); // Feature filters. section.contentContainer.on( 'click', '.filter-group input', function() { section.filtersChecked(); section.checkTerm( section ); }); } // Toggle feature filters. section.contentContainer.on( 'click', '.feature-filter-toggle', function( e ) { var $themeContainer = $( '.customize-themes-full-container' ), $filterToggle = $( e.currentTarget ); section.filtersHeight = $filterToggle.parents( '.themes-filter-bar' ).next( '.filter-drawer' ).height(); if ( 0 < $themeContainer.scrollTop() ) { $themeContainer.animate( { scrollTop: 0 }, 400 ); if ( $filterToggle.hasClass( 'open' ) ) { return; } } $filterToggle .toggleClass( 'open' ) .attr( 'aria-expanded', function( i, attr ) { return 'true' === attr ? 'false' : 'true'; }) .parents( '.themes-filter-bar' ).next( '.filter-drawer' ).slideToggle( 180, 'linear' ); if ( $filterToggle.hasClass( 'open' ) ) { var marginOffset = 1018 < window.innerWidth ? 50 : 76; section.contentContainer.find( '.themes' ).css( 'margin-top', section.filtersHeight + marginOffset ); } else { section.contentContainer.find( '.themes' ).css( 'margin-top', 0 ); } }); // Setup section cross-linking. section.contentContainer.on( 'click', '.no-themes-local .search-dotorg-themes', function() { api.section( 'wporg_themes' ).focus(); }); function updateSelectedState() { var el = section.headerContainer.find( '.customize-themes-section-title' ); el.toggleClass( 'selected', section.expanded() ); el.attr( 'aria-expanded', section.expanded() ? 'true' : 'false' ); if ( ! section.expanded() ) { el.removeClass( 'details-open' ); } } section.expanded.bind( updateSelectedState ); updateSelectedState(); // Move section controls to the themes area. api.bind( 'ready', function () { section.contentContainer = section.container.find( '.customize-themes-section' ); section.contentContainer.appendTo( $( '.customize-themes-full-container' ) ); section.container.add( section.headerContainer ); }); }, /** * Update UI to reflect expanded state * * @since 4.2.0 * * @param {boolean} expanded * @param {Object} args * @param {boolean} args.unchanged * @param {Function} args.completeCallback * @return {void} */ onChangeExpanded: function ( expanded, args ) { // Note: there is a second argument 'args' passed. var section = this, container = section.contentContainer.closest( '.customize-themes-full-container' ); // Immediately call the complete callback if there were no changes. if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); } return; } function expand() { // Try to load controls if none are loaded yet. if ( 0 === section.loaded ) { section.loadThemes(); } // Collapse any sibling sections/panels. api.section.each( function ( otherSection ) { var searchTerm; if ( otherSection !== section ) { // Try to sync the current search term to the new section. if ( 'themes' === otherSection.params.type ) { searchTerm = otherSection.contentContainer.find( '.wp-filter-search' ).val(); section.contentContainer.find( '.wp-filter-search' ).val( searchTerm ); // Directly initialize an empty remote search to avoid a race condition. if ( '' === searchTerm && '' !== section.term && 'local' !== section.params.filter_type ) { section.term = ''; section.initializeNewQuery( section.term, section.tags ); } else { if ( 'remote' === section.params.filter_type ) { section.checkTerm( section ); } else if ( 'local' === section.params.filter_type ) { section.filterSearch( searchTerm ); } } otherSection.collapse( { duration: args.duration } ); } } }); section.contentContainer.addClass( 'current-section' ); container.scrollTop(); container.on( 'scroll', _.throttle( section.renderScreenshots, 300 ) ); container.on( 'scroll', _.throttle( section.loadMore, 300 ) ); if ( args.completeCallback ) { args.completeCallback(); } section.updateCount(); // Show this section's count. } if ( expanded ) { if ( section.panel() && api.panel.has( section.panel() ) ) { api.panel( section.panel() ).expand({ duration: args.duration, completeCallback: expand }); } else { expand(); } } else { section.contentContainer.removeClass( 'current-section' ); // Always hide, even if they don't exist or are already hidden. section.headerContainer.find( '.filter-details' ).slideUp( 180 ); container.off( 'scroll' ); if ( args.completeCallback ) { args.completeCallback(); } } }, /** * Return the section's content element without detaching from the parent. * * @since 4.9.0 * * @return {jQuery} */ getContent: function() { return this.container.find( '.control-section-content' ); }, /** * Load theme data via Ajax and add themes to the section as controls. * * @since 4.9.0 * * @return {void} */ loadThemes: function() { var section = this, params, page, request; if ( section.loading ) { return; // We're already loading a batch of themes. } // Parameters for every API query. Additional params are set in PHP. page = Math.ceil( section.loaded / 100 ) + 1; params = { 'nonce': api.settings.nonce.switch_themes, 'wp_customize': 'on', 'theme_action': section.params.action, 'customized_theme': api.settings.theme.stylesheet, 'page': page }; // Add fields for remote filtering. if ( 'remote' === section.params.filter_type ) { params.search = section.term; params.tags = section.tags; } // Load themes. section.headContainer.closest( '.wp-full-overlay' ).addClass( 'loading' ); section.loading = true; section.container.find( '.no-themes' ).hide(); request = wp.ajax.post( 'customize_load_themes', params ); request.done(function( data ) { var themes = data.themes; // Stop and try again if the term changed while loading. if ( '' !== section.nextTerm || '' !== section.nextTags ) { if ( section.nextTerm ) { section.term = section.nextTerm; } if ( section.nextTags ) { section.tags = section.nextTags; } section.nextTerm = ''; section.nextTags = ''; section.loading = false; section.loadThemes(); return; } if ( 0 !== themes.length ) { section.loadControls( themes, page ); if ( 1 === page ) { // Pre-load the first 3 theme screenshots. _.each( section.controls().slice( 0, 3 ), function( control ) { var img, src = control.params.theme.screenshot[0]; if ( src ) { img = new Image(); img.src = src; } }); if ( 'local' !== section.params.filter_type ) { wp.a11y.speak( api.settings.l10n.themeSearchResults.replace( '%d', data.info.results ) ); } } _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible. if ( 'local' === section.params.filter_type || 100 > themes.length ) { // If we have less than the requested 100 themes, it's the end of the list. section.fullyLoaded = true; } } else { if ( 0 === section.loaded ) { section.container.find( '.no-themes' ).show(); wp.a11y.speak( section.container.find( '.no-themes' ).text() ); } else { section.fullyLoaded = true; } } if ( 'local' === section.params.filter_type ) { section.updateCount(); // Count of visible theme controls. } else { section.updateCount( data.info.results ); // Total number of results including pages not yet loaded. } section.container.find( '.unexpected-error' ).hide(); // Hide error notice in case it was previously shown. // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. section.headContainer.closest( '.wp-full-overlay' ).removeClass( 'loading' ); section.loading = false; }); request.fail(function( data ) { if ( 'undefined' === typeof data ) { section.container.find( '.unexpected-error' ).show(); wp.a11y.speak( section.container.find( '.unexpected-error' ).text() ); } else if ( 'undefined' !== typeof console && console.error ) { console.error( data ); } // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. section.headContainer.closest( '.wp-full-overlay' ).removeClass( 'loading' ); section.loading = false; }); }, /** * Loads controls into the section from data received from loadThemes(). * * @since 4.9.0 * @param {Array} themes - Array of theme data to create controls with. * @param {number} page - Page of results being loaded. * @return {void} */ loadControls: function( themes, page ) { var newThemeControls = [], section = this; // Add controls for each theme. _.each( themes, function( theme ) { var themeControl = new api.controlConstructor.theme( section.params.action + '_theme_' + theme.id, { type: 'theme', section: section.params.id, theme: theme, priority: section.loaded + 1 } ); api.control.add( themeControl ); newThemeControls.push( themeControl ); section.loaded = section.loaded + 1; }); if ( 1 !== page ) { Array.prototype.push.apply( section.screenshotQueue, newThemeControls ); // Add new themes to the screenshot queue. } }, /** * Determines whether more themes should be loaded, and loads them. * * @since 4.9.0 * @return {void} */ loadMore: function() { var section = this, container, bottom, threshold; if ( ! section.fullyLoaded && ! section.loading ) { container = section.container.closest( '.customize-themes-full-container' ); bottom = container.scrollTop() + container.height(); // Use a fixed distance to the bottom of loaded results to avoid unnecessarily // loading results sooner when using a percentage of scroll distance. threshold = container.prop( 'scrollHeight' ) - 3000; if ( bottom > threshold ) { section.loadThemes(); } } }, /** * Event handler for search input that filters visible controls. * * @since 4.9.0 * * @param {string} term - The raw search input value. * @return {void} */ filterSearch: function( term ) { var count = 0, visible = false, section = this, noFilter = ( api.section.has( 'wporg_themes' ) && 'remote' !== section.params.filter_type ) ? '.no-themes-local' : '.no-themes', controls = section.controls(), terms; if ( section.loading ) { return; } // Standardize search term format and split into an array of individual words. terms = term.toLowerCase().trim().replace( /-/g, ' ' ).split( ' ' ); _.each( controls, function( control ) { visible = control.filter( terms ); // Shows/hides and sorts control based on the applicability of the search term. if ( visible ) { count = count + 1; } }); if ( 0 === count ) { section.container.find( noFilter ).show(); wp.a11y.speak( section.container.find( noFilter ).text() ); } else { section.container.find( noFilter ).hide(); } section.renderScreenshots(); api.reflowPaneContents(); // Update theme count. section.updateCountDebounced( count ); }, /** * Event handler for search input that determines if the terms have changed and loads new controls as needed. * * @since 4.9.0 * * @param {wp.customize.ThemesSection} section - The current theme section, passed through the debouncer. * @return {void} */ checkTerm: function( section ) { var newTerm; if ( 'remote' === section.params.filter_type ) { newTerm = section.contentContainer.find( '.wp-filter-search' ).val(); if ( section.term !== newTerm.trim() ) { section.initializeNewQuery( newTerm, section.tags ); } } }, /** * Check for filters checked in the feature filter list and initialize a new query. * * @since 4.9.0 * * @return {void} */ filtersChecked: function() { var section = this, items = section.container.find( '.filter-group' ).find( ':checkbox' ), tags = []; _.each( items.filter( ':checked' ), function( item ) { tags.push( $( item ).prop( 'value' ) ); }); // When no filters are checked, restore initial state. Update filter count. if ( 0 === tags.length ) { tags = ''; section.contentContainer.find( '.feature-filter-toggle .filter-count-0' ).show(); section.contentContainer.find( '.feature-filter-toggle .filter-count-filters' ).hide(); } else { section.contentContainer.find( '.feature-filter-toggle .theme-filter-count' ).text( tags.length ); section.contentContainer.find( '.feature-filter-toggle .filter-count-0' ).hide(); section.contentContainer.find( '.feature-filter-toggle .filter-count-filters' ).show(); } // Check whether tags have changed, and either load or queue them. if ( ! _.isEqual( section.tags, tags ) ) { if ( section.loading ) { section.nextTags = tags; } else { if ( 'remote' === section.params.filter_type ) { section.initializeNewQuery( section.term, tags ); } else if ( 'local' === section.params.filter_type ) { section.filterSearch( tags.join( ' ' ) ); } } } }, /** * Reset the current query and load new results. * * @since 4.9.0 * * @param {string} newTerm - New term. * @param {Array} newTags - New tags. * @return {void} */ initializeNewQuery: function( newTerm, newTags ) { var section = this; // Clear the controls in the section. _.each( section.controls(), function( control ) { control.container.remove(); api.control.remove( control.id ); }); section.loaded = 0; section.fullyLoaded = false; section.screenshotQueue = null; // Run a new query, with loadThemes handling paging, etc. if ( ! section.loading ) { section.term = newTerm; section.tags = newTags; section.loadThemes(); } else { section.nextTerm = newTerm; // This will reload from loadThemes() with the newest term once the current batch is loaded. section.nextTags = newTags; // This will reload from loadThemes() with the newest tags once the current batch is loaded. } if ( ! section.expanded() ) { section.expand(); // Expand the section if it isn't expanded. } }, /** * Render control's screenshot if the control comes into view. * * @since 4.2.0 * * @return {void} */ renderScreenshots: function() { var section = this; // Fill queue initially, or check for more if empty. if ( null === section.screenshotQueue || 0 === section.screenshotQueue.length ) { // Add controls that haven't had their screenshots rendered. section.screenshotQueue = _.filter( section.controls(), function( control ) { return ! control.screenshotRendered; }); } // Are all screenshots rendered (for now)? if ( ! section.screenshotQueue.length ) { return; } section.screenshotQueue = _.filter( section.screenshotQueue, function( control ) { var $imageWrapper = control.container.find( '.theme-screenshot' ), $image = $imageWrapper.find( 'img' ); if ( ! $image.length ) { return false; } if ( $image.is( ':hidden' ) ) { return true; } // Based on unveil.js. var wt = section.$window.scrollTop(), wb = wt + section.$window.height(), et = $image.offset().top, ih = $imageWrapper.height(), eb = et + ih, threshold = ih * 3, inView = eb >= wt - threshold && et <= wb + threshold; if ( inView ) { control.container.trigger( 'render-screenshot' ); } // If the image is in view return false so it's cleared from the queue. return ! inView; } ); }, /** * Get visible count. * * @since 4.9.0 * * @return {number} Visible count. */ getVisibleCount: function() { return this.contentContainer.find( 'li.customize-control:visible' ).length; }, /** * Update the number of themes in the section. * * @since 4.9.0 * * @return {void} */ updateCount: function( count ) { var section = this, countEl, displayed; if ( ! count && 0 !== count ) { count = section.getVisibleCount(); } displayed = section.contentContainer.find( '.themes-displayed' ); countEl = section.contentContainer.find( '.theme-count' ); if ( 0 === count ) { countEl.text( '0' ); } else { // Animate the count change for emphasis. displayed.fadeOut( 180, function() { countEl.text( count ); displayed.fadeIn( 180 ); } ); wp.a11y.speak( api.settings.l10n.announceThemeCount.replace( '%d', count ) ); } }, /** * Advance the modal to the next theme. * * @since 4.2.0 * * @return {void} */ nextTheme: function () { var section = this; if ( section.getNextTheme() ) { section.showDetails( section.getNextTheme(), function() { section.overlay.find( '.right' ).focus(); } ); } }, /** * Get the next theme model. * * @since 4.2.0 * * @return {wp.customize.ThemeControl|boolean} Next theme. */ getNextTheme: function () { var section = this, control, nextControl, sectionControls, i; control = api.control( section.params.action + '_theme_' + section.currentTheme ); sectionControls = section.controls(); i = _.indexOf( sectionControls, control ); if ( -1 === i ) { return false; } nextControl = sectionControls[ i + 1 ]; if ( ! nextControl ) { return false; } return nextControl.params.theme; }, /** * Advance the modal to the previous theme. * * @since 4.2.0 * @return {void} */ previousTheme: function () { var section = this; if ( section.getPreviousTheme() ) { section.showDetails( section.getPreviousTheme(), function() { section.overlay.find( '.left' ).focus(); } ); } }, /** * Get the previous theme model. * * @since 4.2.0 * @return {wp.customize.ThemeControl|boolean} Previous theme. */ getPreviousTheme: function () { var section = this, control, nextControl, sectionControls, i; control = api.control( section.params.action + '_theme_' + section.currentTheme ); sectionControls = section.controls(); i = _.indexOf( sectionControls, control ); if ( -1 === i ) { return false; } nextControl = sectionControls[ i - 1 ]; if ( ! nextControl ) { return false; } return nextControl.params.theme; }, /** * Disable buttons when we're viewing the first or last theme. * * @since 4.2.0 * * @return {void} */ updateLimits: function () { if ( ! this.getNextTheme() ) { this.overlay.find( '.right' ).addClass( 'disabled' ); } if ( ! this.getPreviousTheme() ) { this.overlay.find( '.left' ).addClass( 'disabled' ); } }, /** * Load theme preview. * * @since 4.7.0 * @access public * * @deprecated * @param {string} themeId Theme ID. * @return {jQuery.promise} Promise. */ loadThemePreview: function( themeId ) { return api.ThemesPanel.prototype.loadThemePreview.call( this, themeId ); }, /** * Render & show the theme details for a given theme model. * * @since 4.2.0 * * @param {Object} theme - Theme. * @param {Function} [callback] - Callback once the details have been shown. * @return {void} */ showDetails: function ( theme, callback ) { var section = this, panel = api.panel( 'themes' ); section.currentTheme = theme.id; section.overlay.html( section.template( theme ) ) .fadeIn( 'fast' ) .focus(); function disableSwitchButtons() { return ! panel.canSwitchTheme( theme.id ); } // Temporary special function since supplying SFTP credentials does not work yet. See #42184. function disableInstallButtons() { return disableSwitchButtons() || false === api.settings.theme._canInstall || true === api.settings.theme._filesystemCredentialsNeeded; } section.overlay.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() ); section.overlay.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() ); section.$body.addClass( 'modal-open' ); section.containFocus( section.overlay ); section.updateLimits(); wp.a11y.speak( api.settings.l10n.announceThemeDetails.replace( '%s', theme.name ) ); if ( callback ) { callback(); } }, /** * Close the theme details modal. * * @since 4.2.0 * * @return {void} */ closeDetails: function () { var section = this; section.$body.removeClass( 'modal-open' ); section.overlay.fadeOut( 'fast' ); api.control( section.params.action + '_theme_' + section.currentTheme ).container.find( '.theme' ).focus(); }, /** * Keep tab focus within the theme details modal. * * @since 4.2.0 * * @param {jQuery} el - Element to contain focus. * @return {void} */ containFocus: function( el ) { var tabbables; el.on( 'keydown', function( event ) { // Return if it's not the tab key // When navigating with prev/next focus is already handled. if ( 9 !== event.keyCode ) { return; } // Uses jQuery UI to get the tabbable elements. tabbables = $( ':tabbable', el ); // Keep focus within the overlay. if ( tabbables.last()[0] === event.target && ! event.shiftKey ) { tabbables.first().focus(); return false; } else if ( tabbables.first()[0] === event.target && event.shiftKey ) { tabbables.last().focus(); return false; } }); } }); api.OuterSection = api.Section.extend(/** @lends wp.customize.OuterSection.prototype */{ /** * Class wp.customize.OuterSection. * * Creates section outside of the sidebar, there is no ui to trigger collapse/expand so * it would require custom handling. * * @constructs wp.customize.OuterSection * @augments wp.customize.Section * * @since 4.9.0 * * @return {void} */ initialize: function() { var section = this; section.containerParent = '#customize-outer-theme-controls'; section.containerPaneParent = '.customize-outer-pane-parent'; api.Section.prototype.initialize.apply( section, arguments ); }, /** * Overrides api.Section.prototype.onChangeExpanded to prevent collapse/expand effect * on other sections and panels. * * @since 4.9.0 * * @param {boolean} expanded - The expanded state to transition to. * @param {Object} [args] - Args. * @param {boolean} [args.unchanged] - Whether the state is already known to not be changed, and so short-circuit with calling completeCallback early. * @param {Function} [args.completeCallback] - Function to call when the slideUp/slideDown has completed. * @param {Object} [args.duration] - The duration for the animation. */ onChangeExpanded: function( expanded, args ) { var section = this, container = section.headContainer.closest( '.wp-full-overlay-sidebar-content' ), content = section.contentContainer, backBtn = content.find( '.customize-section-back' ), sectionTitle = section.headContainer.find( '.accordion-section-title button, .accordion-section-title[tabindex]' ).first(), body = $( document.body ), expand, panel; body.toggleClass( 'outer-section-open', expanded ); section.container.toggleClass( 'open', expanded ); section.container.removeClass( 'busy' ); api.section.each( function( _section ) { if ( 'outer' === _section.params.type && _section.id !== section.id ) { _section.container.removeClass( 'open' ); } } ); if ( expanded && ! content.hasClass( 'open' ) ) { if ( args.unchanged ) { expand = args.completeCallback; } else { expand = function() { section._animateChangeExpanded( function() { backBtn.trigger( 'focus' ); content.css( 'top', '' ); container.scrollTop( 0 ); if ( args.completeCallback ) { args.completeCallback(); } } ); content.addClass( 'open' ); }.bind( this ); } if ( section.panel() ) { api.panel( section.panel() ).expand({ duration: args.duration, completeCallback: expand }); } else { expand(); } } else if ( ! expanded && content.hasClass( 'open' ) ) { if ( section.panel() ) { panel = api.panel( section.panel() ); if ( panel.contentContainer.hasClass( 'skip-transition' ) ) { panel.collapse(); } } section._animateChangeExpanded( function() { sectionTitle.trigger( 'focus' ); content.css( 'top', '' ); if ( args.completeCallback ) { args.completeCallback(); } } ); content.removeClass( 'open' ); } else { if ( args.completeCallback ) { args.completeCallback(); } } } }); api.Panel = Container.extend(/** @lends wp.customize.Panel.prototype */{ containerType: 'panel', /** * @constructs wp.customize.Panel * @augments wp.customize~Container * * @since 4.1.0 * * @param {string} id - The ID for the panel. * @param {Object} options - Object containing one property: params. * @param {string} options.title - Title shown when panel is collapsed and expanded. * @param {string} [options.description] - Description shown at the top of the panel. * @param {number} [options.priority=100] - The sort priority for the panel. * @param {string} [options.type=default] - The type of the panel. See wp.customize.panelConstructor. * @param {string} [options.content] - The markup to be used for the panel container. If empty, a JS template is used. * @param {boolean} [options.active=true] - Whether the panel is active or not. * @param {Object} [options.params] - Deprecated wrapper for the above properties. */ initialize: function ( id, options ) { var panel = this, params; params = options.params || options; // Look up the type if one was not supplied. if ( ! params.type ) { _.find( api.panelConstructor, function( Constructor, type ) { if ( Constructor === panel.constructor ) { params.type = type; return true; } return false; } ); } Container.prototype.initialize.call( panel, id, params ); panel.embed(); panel.deferred.embedded.done( function () { panel.ready(); }); }, /** * Embed the container in the DOM when any parent panel is ready. * * @since 4.1.0 */ embed: function () { var panel = this, container = $( '#customize-theme-controls' ), parentContainer = $( '.customize-pane-parent' ); // @todo This should be defined elsewhere, and to be configurable. if ( ! panel.headContainer.parent().is( parentContainer ) ) { parentContainer.append( panel.headContainer ); } if ( ! panel.contentContainer.parent().is( panel.headContainer ) ) { container.append( panel.contentContainer ); } panel.renderContent(); panel.deferred.embedded.resolve(); }, /** * @since 4.1.0 */ attachEvents: function () { var meta, panel = this; // Expand/Collapse accordion sections on click. panel.headContainer.find( '.accordion-section-title button, .accordion-section-title[tabindex]' ).on( 'click keydown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); // Keep this AFTER the key filter above. if ( ! panel.expanded() ) { panel.expand(); } }); // Close panel. panel.container.find( '.customize-panel-back' ).on( 'click keydown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); // Keep this AFTER the key filter above. if ( panel.expanded() ) { panel.collapse(); } }); meta = panel.container.find( '.panel-meta:first' ); meta.find( '> .accordion-section-title .customize-help-toggle' ).on( 'click', function() { if ( meta.hasClass( 'cannot-expand' ) ) { return; } var content = meta.find( '.customize-panel-description:first' ); if ( meta.hasClass( 'open' ) ) { meta.toggleClass( 'open' ); content.slideUp( panel.defaultExpandedArguments.duration, function() { content.trigger( 'toggled' ); } ); $( this ).attr( 'aria-expanded', false ); } else { content.slideDown( panel.defaultExpandedArguments.duration, function() { content.trigger( 'toggled' ); } ); meta.toggleClass( 'open' ); $( this ).attr( 'aria-expanded', true ); } }); }, /** * Get the sections that are associated with this panel, sorted by their priority Value. * * @since 4.1.0 * * @return {Array} */ sections: function () { return this._children( 'panel', 'section' ); }, /** * Return whether this panel has any active sections. * * @since 4.1.0 * * @return {boolean} Whether contextually active. */ isContextuallyActive: function () { var panel = this, sections = panel.sections(), activeCount = 0; _( sections ).each( function ( section ) { if ( section.active() && section.isContextuallyActive() ) { activeCount += 1; } } ); return ( activeCount !== 0 ); }, /** * Update UI to reflect expanded state. * * @since 4.1.0 * * @param {boolean} expanded * @param {Object} args * @param {boolean} args.unchanged * @param {Function} args.completeCallback * @return {void} */ onChangeExpanded: function ( expanded, args ) { // Immediately call the complete callback if there were no changes. if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); } return; } // Note: there is a second argument 'args' passed. var panel = this, accordionSection = panel.contentContainer, overlay = accordionSection.closest( '.wp-full-overlay' ), container = accordionSection.closest( '.wp-full-overlay-sidebar-content' ), topPanel = panel.headContainer.find( '.accordion-section-title button, .accordion-section-title[tabindex]' ), backBtn = accordionSection.find( '.customize-panel-back' ), childSections = panel.sections(), skipTransition; if ( expanded && ! accordionSection.hasClass( 'current-panel' ) ) { // Collapse any sibling sections/panels. api.section.each( function ( section ) { if ( panel.id !== section.panel() ) { section.collapse( { duration: 0 } ); } }); api.panel.each( function ( otherPanel ) { if ( panel !== otherPanel ) { otherPanel.collapse( { duration: 0 } ); } }); if ( panel.params.autoExpandSoleSection && 1 === childSections.length && childSections[0].active.get() ) { accordionSection.addClass( 'current-panel skip-transition' ); overlay.addClass( 'in-sub-panel' ); childSections[0].expand( { completeCallback: args.completeCallback } ); } else { panel._animateChangeExpanded( function() { backBtn.trigger( 'focus' ); accordionSection.css( 'top', '' ); container.scrollTop( 0 ); if ( args.completeCallback ) { args.completeCallback(); } } ); accordionSection.addClass( 'current-panel' ); overlay.addClass( 'in-sub-panel' ); } api.state( 'expandedPanel' ).set( panel ); } else if ( ! expanded && accordionSection.hasClass( 'current-panel' ) ) { skipTransition = accordionSection.hasClass( 'skip-transition' ); if ( ! skipTransition ) { panel._animateChangeExpanded( function() { topPanel.focus(); accordionSection.css( 'top', '' ); if ( args.completeCallback ) { args.completeCallback(); } } ); } else { accordionSection.removeClass( 'skip-transition' ); } overlay.removeClass( 'in-sub-panel' ); accordionSection.removeClass( 'current-panel' ); if ( panel === api.state( 'expandedPanel' ).get() ) { api.state( 'expandedPanel' ).set( false ); } } }, /** * Render the panel from its JS template, if it exists. * * The panel's container must already exist in the DOM. * * @since 4.3.0 */ renderContent: function () { var template, panel = this; // Add the content to the container. if ( 0 !== $( '#tmpl-' + panel.templateSelector + '-content' ).length ) { template = wp.template( panel.templateSelector + '-content' ); } else { template = wp.template( 'customize-panel-default-content' ); } if ( template && panel.headContainer ) { panel.contentContainer.html( template( _.extend( { id: panel.id }, panel.params ) ) ); } } }); api.ThemesPanel = api.Panel.extend(/** @lends wp.customize.ThemsPanel.prototype */{ /** * Class wp.customize.ThemesPanel. * * Custom section for themes that displays without the customize preview. * * @constructs wp.customize.ThemesPanel * @augments wp.customize.Panel * * @since 4.9.0 * * @param {string} id - The ID for the panel. * @param {Object} options - Options. * @return {void} */ initialize: function( id, options ) { var panel = this; panel.installingThemes = []; api.Panel.prototype.initialize.call( panel, id, options ); }, /** * Determine whether a given theme can be switched to, or in general. * * @since 4.9.0 * * @param {string} [slug] - Theme slug. * @return {boolean} Whether the theme can be switched to. */ canSwitchTheme: function canSwitchTheme( slug ) { if ( slug && slug === api.settings.theme.stylesheet ) { return true; } return 'publish' === api.state( 'selectedChangesetStatus' ).get() && ( '' === api.state( 'changesetStatus' ).get() || 'auto-draft' === api.state( 'changesetStatus' ).get() ); }, /** * Attach events. * * @since 4.9.0 * @return {void} */ attachEvents: function() { var panel = this; // Attach regular panel events. api.Panel.prototype.attachEvents.apply( panel ); // Temporary since supplying SFTP credentials does not work yet. See #42184. if ( api.settings.theme._canInstall && api.settings.theme._filesystemCredentialsNeeded ) { panel.notifications.add( new api.Notification( 'theme_install_unavailable', { message: api.l10n.themeInstallUnavailable, type: 'info', dismissible: true } ) ); } function toggleDisabledNotifications() { if ( panel.canSwitchTheme() ) { panel.notifications.remove( 'theme_switch_unavailable' ); } else { panel.notifications.add( new api.Notification( 'theme_switch_unavailable', { message: api.l10n.themePreviewUnavailable, type: 'warning' } ) ); } } toggleDisabledNotifications(); api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications ); api.state( 'changesetStatus' ).bind( toggleDisabledNotifications ); // Collapse panel to customize the current theme. panel.contentContainer.on( 'click', '.customize-theme', function() { panel.collapse(); }); // Toggle between filtering and browsing themes on mobile. panel.contentContainer.on( 'click', '.customize-themes-section-title, .customize-themes-mobile-back', function() { $( '.wp-full-overlay' ).toggleClass( 'showing-themes' ); }); // Install (and maybe preview) a theme. panel.contentContainer.on( 'click', '.theme-install', function( event ) { panel.installTheme( event ); }); // Update a theme. Theme cards have the class, the details modal has the id. panel.contentContainer.on( 'click', '.update-theme, #update-theme', function( event ) { // #update-theme is a link. event.preventDefault(); event.stopPropagation(); panel.updateTheme( event ); }); // Delete a theme. panel.contentContainer.on( 'click', '.delete-theme', function( event ) { panel.deleteTheme( event ); }); _.bindAll( panel, 'installTheme', 'updateTheme' ); }, /** * Update UI to reflect expanded state * * @since 4.9.0 * * @param {boolean} expanded - Expanded state. * @param {Object} args - Args. * @param {boolean} args.unchanged - Whether or not the state changed. * @param {Function} args.completeCallback - Callback to execute when the animation completes. * @return {void} */ onChangeExpanded: function( expanded, args ) { var panel = this, overlay, sections, hasExpandedSection = false; // Expand/collapse the panel normally. api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] ); // Immediately call the complete callback if there were no changes. if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); } return; } overlay = panel.headContainer.closest( '.wp-full-overlay' ); if ( expanded ) { overlay .addClass( 'in-themes-panel' ) .delay( 200 ).find( '.customize-themes-full-container' ).addClass( 'animate' ); _.delay( function() { overlay.addClass( 'themes-panel-expanded' ); }, 200 ); // Automatically open the first section (except on small screens), if one isn't already expanded. if ( 600 < window.innerWidth ) { sections = panel.sections(); _.each( sections, function( section ) { if ( section.expanded() ) { hasExpandedSection = true; } } ); if ( ! hasExpandedSection && sections.length > 0 ) { sections[0].expand(); } } } else { overlay .removeClass( 'in-themes-panel themes-panel-expanded' ) .find( '.customize-themes-full-container' ).removeClass( 'animate' ); } }, /** * Install a theme via wp.updates. * * @since 4.9.0 * * @param {jQuery.Event} event - Event. * @return {jQuery.promise} Promise. */ installTheme: function( event ) { var panel = this, preview, onInstallSuccess, slug = $( event.target ).data( 'slug' ), deferred = $.Deferred(), request; preview = $( event.target ).hasClass( 'preview' ); // Temporary since supplying SFTP credentials does not work yet. See #42184. if ( api.settings.theme._filesystemCredentialsNeeded ) { deferred.reject({ errorCode: 'theme_install_unavailable' }); return deferred.promise(); } // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset. if ( ! panel.canSwitchTheme( slug ) ) { deferred.reject({ errorCode: 'theme_switch_unavailable' }); return deferred.promise(); } // Theme is already being installed. if ( _.contains( panel.installingThemes, slug ) ) { deferred.reject({ errorCode: 'theme_already_installing' }); return deferred.promise(); } wp.updates.maybeRequestFilesystemCredentials( event ); onInstallSuccess = function( response ) { var theme = false, themeControl; if ( preview ) { api.notifications.remove( 'theme_installing' ); panel.loadThemePreview( slug ); } else { api.control.each( function( control ) { if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { theme = control.params.theme; // Used below to add theme control. control.rerenderAsInstalled( true ); } }); // Don't add the same theme more than once. if ( ! theme || api.control.has( 'installed_theme_' + theme.id ) ) { deferred.resolve( response ); return; } // Add theme control to installed section. theme.type = 'installed'; themeControl = new api.controlConstructor.theme( 'installed_theme_' + theme.id, { type: 'theme', section: 'installed_themes', theme: theme, priority: 0 // Add all newly-installed themes to the top. } ); api.control.add( themeControl ); api.control( themeControl.id ).container.trigger( 'render-screenshot' ); // Close the details modal if it's open to the installed theme. api.section.each( function( section ) { if ( 'themes' === section.params.type ) { if ( theme.id === section.currentTheme ) { // Don't close the modal if the user has navigated elsewhere. section.closeDetails(); } } }); } deferred.resolve( response ); }; panel.installingThemes.push( slug ); // Note: we don't remove elements from installingThemes, since they shouldn't be installed again. request = wp.updates.installTheme( { slug: slug } ); // Also preview the theme as the event is triggered on Install & Preview. if ( preview ) { api.notifications.add( new api.OverlayNotification( 'theme_installing', { message: api.l10n.themeDownloading, type: 'info', loading: true } ) ); } request.done( onInstallSuccess ); request.fail( function() { api.notifications.remove( 'theme_installing' ); } ); return deferred.promise(); }, /** * Load theme preview. * * @since 4.9.0 * * @param {string} themeId Theme ID. * @return {jQuery.promise} Promise. */ loadThemePreview: function( themeId ) { var panel = this, deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams; // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset. if ( ! panel.canSwitchTheme( themeId ) ) { deferred.reject({ errorCode: 'theme_switch_unavailable' }); return deferred.promise(); } urlParser = document.createElement( 'a' ); urlParser.href = location.href; queryParams = _.extend( api.utils.parseQueryString( urlParser.search.substr( 1 ) ), { theme: themeId, changeset_uuid: api.settings.changeset.uuid, 'return': api.settings.url['return'] } ); // Include autosaved param to load autosave revision without prompting user to restore it. if ( ! api.state( 'saved' ).get() ) { queryParams.customize_autosaved = 'on'; } urlParser.search = $.param( queryParams ); // Update loading message. Everything else is handled by reloading the page. api.notifications.add( new api.OverlayNotification( 'theme_previewing', { message: api.l10n.themePreviewWait, type: 'info', loading: true } ) ); onceProcessingComplete = function() { var request; if ( api.state( 'processing' ).get() > 0 ) { return; } api.state( 'processing' ).unbind( onceProcessingComplete ); request = api.requestChangesetUpdate( {}, { autosave: true } ); request.done( function() { deferred.resolve(); $( window ).off( 'beforeunload.customize-confirm' ); location.replace( urlParser.href ); } ); request.fail( function() { // @todo Show notification regarding failure. api.notifications.remove( 'theme_previewing' ); deferred.reject(); } ); }; if ( 0 === api.state( 'processing' ).get() ) { onceProcessingComplete(); } else { api.state( 'processing' ).bind( onceProcessingComplete ); } return deferred.promise(); }, /** * Update a theme via wp.updates. * * @since 4.9.0 * * @param {jQuery.Event} event - Event. * @return {void} */ updateTheme: function( event ) { wp.updates.maybeRequestFilesystemCredentials( event ); $( document ).one( 'wp-theme-update-success', function( e, response ) { // Rerender the control to reflect the update. api.control.each( function( control ) { if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { control.params.theme.hasUpdate = false; control.params.theme.version = response.newVersion; setTimeout( function() { control.rerenderAsInstalled( true ); }, 2000 ); } }); } ); wp.updates.updateTheme( { slug: $( event.target ).closest( '.notice' ).data( 'slug' ) } ); }, /** * Delete a theme via wp.updates. * * @since 4.9.0 * * @param {jQuery.Event} event - Event. * @return {void} */ deleteTheme: function( event ) { var theme, section; theme = $( event.target ).data( 'slug' ); section = api.section( 'installed_themes' ); event.preventDefault(); // Temporary since supplying SFTP credentials does not work yet. See #42184. if ( api.settings.theme._filesystemCredentialsNeeded ) { return; } // Confirmation dialog for deleting a theme. if ( ! window.confirm( api.settings.l10n.confirmDeleteTheme ) ) { return; } wp.updates.maybeRequestFilesystemCredentials( event ); $( document ).one( 'wp-theme-delete-success', function() { var control = api.control( 'installed_theme_' + theme ); // Remove theme control. control.container.remove(); api.control.remove( control.id ); // Update installed count. section.loaded = section.loaded - 1; section.updateCount(); // Rerender any other theme controls as uninstalled. api.control.each( function( control ) { if ( 'theme' === control.params.type && control.params.theme.id === theme ) { control.rerenderAsInstalled( false ); } }); } ); wp.updates.deleteTheme( { slug: theme } ); // Close modal and focus the section. section.closeDetails(); section.focus(); } }); api.Control = api.Class.extend(/** @lends wp.customize.Control.prototype */{ defaultActiveArguments: { duration: 'fast', completeCallback: $.noop }, /** * Default params. * * @since 4.9.0 * @var {object} */ defaults: { label: '', description: '', active: true, priority: 10 }, /** * A Customizer Control. * * A control provides a UI element that allows a user to modify a Customizer Setting. * * @see PHP class WP_Customize_Control. * * @constructs wp.customize.Control * @augments wp.customize.Class * * @borrows wp.customize~focus as this#focus * @borrows wp.customize~Container#activate as this#activate * @borrows wp.customize~Container#deactivate as this#deactivate * @borrows wp.customize~Container#_toggleActive as this#_toggleActive * * @param {string} id - Unique identifier for the control instance. * @param {Object} options - Options hash for the control instance. * @param {Object} options.type - Type of control (e.g. text, radio, dropdown-pages, etc.) * @param {string} [options.content] - The HTML content for the control or at least its container. This should normally be left blank and instead supplying a templateId. * @param {string} [options.templateId] - Template ID for control's content. * @param {string} [options.priority=10] - Order of priority to show the control within the section. * @param {string} [options.active=true] - Whether the control is active. * @param {string} options.section - The ID of the section the control belongs to. * @param {mixed} [options.setting] - The ID of the main setting or an instance of this setting. * @param {mixed} options.settings - An object with keys (e.g. default) that maps to setting IDs or Setting/Value objects, or an array of setting IDs or Setting/Value objects. * @param {mixed} options.settings.default - The ID of the setting the control relates to. * @param {string} options.settings.data - @todo Is this used? * @param {string} options.label - Label. * @param {string} options.description - Description. * @param {number} [options.instanceNumber] - Order in which this instance was created in relation to other instances. * @param {Object} [options.params] - Deprecated wrapper for the above properties. * @return {void} */ initialize: function( id, options ) { var control = this, deferredSettingIds = [], settings, gatherSettings; control.params = _.extend( {}, control.defaults, control.params || {}, // In case subclass already defines. options.params || options || {} // The options.params property is deprecated, but it is checked first for back-compat. ); if ( ! api.Control.instanceCounter ) { api.Control.instanceCounter = 0; } api.Control.instanceCounter++; if ( ! control.params.instanceNumber ) { control.params.instanceNumber = api.Control.instanceCounter; } // Look up the type if one was not supplied. if ( ! control.params.type ) { _.find( api.controlConstructor, function( Constructor, type ) { if ( Constructor === control.constructor ) { control.params.type = type; return true; } return false; } ); } if ( ! control.params.content ) { control.params.content = $( '
    • ', { id: 'customize-control-' + id.replace( /]/g, '' ).replace( /\[/g, '-' ), 'class': 'customize-control customize-control-' + control.params.type } ); } control.id = id; control.selector = '#customize-control-' + id.replace( /\]/g, '' ).replace( /\[/g, '-' ); // Deprecated, likely dead code from time before #28709. if ( control.params.content ) { control.container = $( control.params.content ); } else { control.container = $( control.selector ); // Likely dead, per above. See #28709. } if ( control.params.templateId ) { control.templateSelector = control.params.templateId; } else { control.templateSelector = 'customize-control-' + control.params.type + '-content'; } control.deferred = _.extend( control.deferred || {}, { embedded: new $.Deferred() } ); control.section = new api.Value(); control.priority = new api.Value(); control.active = new api.Value(); control.activeArgumentsQueue = []; control.notifications = new api.Notifications({ alt: control.altNotice }); control.elements = []; control.active.bind( function ( active ) { var args = control.activeArgumentsQueue.shift(); args = $.extend( {}, control.defaultActiveArguments, args ); control.onChangeActive( active, args ); } ); control.section.set( control.params.section ); control.priority.set( isNaN( control.params.priority ) ? 10 : control.params.priority ); control.active.set( control.params.active ); api.utils.bubbleChildValueChanges( control, [ 'section', 'priority', 'active' ] ); control.settings = {}; settings = {}; if ( control.params.setting ) { settings['default'] = control.params.setting; } _.extend( settings, control.params.settings ); // Note: Settings can be an array or an object, with values being either setting IDs or Setting (or Value) objects. _.each( settings, function( value, key ) { var setting; if ( _.isObject( value ) && _.isFunction( value.extended ) && value.extended( api.Value ) ) { control.settings[ key ] = value; } else if ( _.isString( value ) ) { setting = api( value ); if ( setting ) { control.settings[ key ] = setting; } else { deferredSettingIds.push( value ); } } } ); gatherSettings = function() { // Fill-in all resolved settings. _.each( settings, function ( settingId, key ) { if ( ! control.settings[ key ] && _.isString( settingId ) ) { control.settings[ key ] = api( settingId ); } } ); // Make sure settings passed as array gets associated with default. if ( control.settings[0] && ! control.settings['default'] ) { control.settings['default'] = control.settings[0]; } // Identify the main setting. control.setting = control.settings['default'] || null; control.linkElements(); // Link initial elements present in server-rendered content. control.embed(); }; if ( 0 === deferredSettingIds.length ) { gatherSettings(); } else { api.apply( api, deferredSettingIds.concat( gatherSettings ) ); } // After the control is embedded on the page, invoke the "ready" method. control.deferred.embedded.done( function () { control.linkElements(); // Link any additional elements after template is rendered by renderContent(). control.setupNotifications(); control.ready(); }); }, /** * Link elements between settings and inputs. * * @since 4.7.0 * @access public * * @return {void} */ linkElements: function () { var control = this, nodes, radios, element; nodes = control.container.find( '[data-customize-setting-link], [data-customize-setting-key-link]' ); radios = {}; nodes.each( function () { var node = $( this ), name, setting; if ( node.data( 'customizeSettingLinked' ) ) { return; } node.data( 'customizeSettingLinked', true ); // Prevent re-linking element. if ( node.is( ':radio' ) ) { name = node.prop( 'name' ); if ( radios[name] ) { return; } radios[name] = true; node = nodes.filter( '[name="' + name + '"]' ); } // Let link by default refer to setting ID. If it doesn't exist, fallback to looking up by setting key. if ( node.data( 'customizeSettingLink' ) ) { setting = api( node.data( 'customizeSettingLink' ) ); } else if ( node.data( 'customizeSettingKeyLink' ) ) { setting = control.settings[ node.data( 'customizeSettingKeyLink' ) ]; } if ( setting ) { element = new api.Element( node ); control.elements.push( element ); element.sync( setting ); element.set( setting() ); } } ); }, /** * Embed the control into the page. */ embed: function () { var control = this, inject; // Watch for changes to the section state. inject = function ( sectionId ) { var parentContainer; if ( ! sectionId ) { // @todo Allow a control to be embedded without a section, for instance a control embedded in the front end. return; } // Wait for the section to be registered. api.section( sectionId, function ( section ) { // Wait for the section to be ready/initialized. section.deferred.embedded.done( function () { parentContainer = ( section.contentContainer.is( 'ul' ) ) ? section.contentContainer : section.contentContainer.find( 'ul:first' ); if ( ! control.container.parent().is( parentContainer ) ) { parentContainer.append( control.container ); } control.renderContent(); control.deferred.embedded.resolve(); }); }); }; control.section.bind( inject ); inject( control.section.get() ); }, /** * Triggered when the control's markup has been injected into the DOM. * * @return {void} */ ready: function() { var control = this, newItem; if ( 'dropdown-pages' === control.params.type && control.params.allow_addition ) { newItem = control.container.find( '.new-content-item-wrapper' ); newItem.hide(); // Hide in JS to preserve flex display when showing. control.container.on( 'click', '.add-new-toggle', function( e ) { $( e.currentTarget ).slideUp( 180 ); newItem.slideDown( 180 ); newItem.find( '.create-item-input' ).focus(); }); control.container.on( 'click', '.add-content', function() { control.addNewPage(); }); control.container.on( 'keydown', '.create-item-input', function( e ) { if ( 13 === e.which ) { // Enter. control.addNewPage(); } }); } }, /** * Get the element inside of a control's container that contains the validation error message. * * Control subclasses may override this to return the proper container to render notifications into. * Injects the notification container for existing controls that lack the necessary container, * including special handling for nav menu items and widgets. * * @since 4.6.0 * @return {jQuery} Setting validation message element. */ getNotificationsContainerElement: function() { var control = this, controlTitle, notificationsContainer; notificationsContainer = control.container.find( '.customize-control-notifications-container:first' ); if ( notificationsContainer.length ) { return notificationsContainer; } notificationsContainer = $( '
      ' ); if ( control.container.hasClass( 'customize-control-nav_menu_item' ) ) { control.container.find( '.menu-item-settings:first' ).prepend( notificationsContainer ); } else if ( control.container.hasClass( 'customize-control-widget_form' ) ) { control.container.find( '.widget-inside:first' ).prepend( notificationsContainer ); } else { controlTitle = control.container.find( '.customize-control-title' ); if ( controlTitle.length ) { controlTitle.after( notificationsContainer ); } else { control.container.prepend( notificationsContainer ); } } return notificationsContainer; }, /** * Set up notifications. * * @since 4.9.0 * @return {void} */ setupNotifications: function() { var control = this, renderNotificationsIfVisible, onSectionAssigned; // Add setting notifications to the control notification. _.each( control.settings, function( setting ) { if ( ! setting.notifications ) { return; } setting.notifications.bind( 'add', function( settingNotification ) { var params = _.extend( {}, settingNotification, { setting: setting.id } ); control.notifications.add( new api.Notification( setting.id + ':' + settingNotification.code, params ) ); } ); setting.notifications.bind( 'remove', function( settingNotification ) { control.notifications.remove( setting.id + ':' + settingNotification.code ); } ); } ); renderNotificationsIfVisible = function() { var sectionId = control.section(); if ( ! sectionId || ( api.section.has( sectionId ) && api.section( sectionId ).expanded() ) ) { control.notifications.render(); } }; control.notifications.bind( 'rendered', function() { var notifications = control.notifications.get(); control.container.toggleClass( 'has-notifications', 0 !== notifications.length ); control.container.toggleClass( 'has-error', 0 !== _.where( notifications, { type: 'error' } ).length ); } ); onSectionAssigned = function( newSectionId, oldSectionId ) { if ( oldSectionId && api.section.has( oldSectionId ) ) { api.section( oldSectionId ).expanded.unbind( renderNotificationsIfVisible ); } if ( newSectionId ) { api.section( newSectionId, function( section ) { section.expanded.bind( renderNotificationsIfVisible ); renderNotificationsIfVisible(); }); } }; control.section.bind( onSectionAssigned ); onSectionAssigned( control.section.get() ); control.notifications.bind( 'change', _.debounce( renderNotificationsIfVisible ) ); }, /** * Render notifications. * * Renders the `control.notifications` into the control's container. * Control subclasses may override this method to do their own handling * of rendering notifications. * * @deprecated in favor of `control.notifications.render()` * @since 4.6.0 * @this {wp.customize.Control} */ renderNotifications: function() { var control = this, container, notifications, hasError = false; if ( 'undefined' !== typeof console && console.warn ) { console.warn( '[DEPRECATED] wp.customize.Control.prototype.renderNotifications() is deprecated in favor of instantiating a wp.customize.Notifications and calling its render() method.' ); } container = control.getNotificationsContainerElement(); if ( ! container || ! container.length ) { return; } notifications = []; control.notifications.each( function( notification ) { notifications.push( notification ); if ( 'error' === notification.type ) { hasError = true; } } ); if ( 0 === notifications.length ) { container.stop().slideUp( 'fast' ); } else { container.stop().slideDown( 'fast', null, function() { $( this ).css( 'height', 'auto' ); } ); } if ( ! control.notificationsTemplate ) { control.notificationsTemplate = wp.template( 'customize-control-notifications' ); } control.container.toggleClass( 'has-notifications', 0 !== notifications.length ); control.container.toggleClass( 'has-error', hasError ); container.empty().append( control.notificationsTemplate( { notifications: notifications, altNotice: Boolean( control.altNotice ) } ).trim() ); }, /** * Normal controls do not expand, so just expand its parent * * @param {Object} [params] */ expand: function ( params ) { api.section( this.section() ).expand( params ); }, /* * Documented using @borrows in the constructor. */ focus: focus, /** * Update UI in response to a change in the control's active state. * This does not change the active state, it merely handles the behavior * for when it does change. * * @since 4.1.0 * * @param {boolean} active * @param {Object} args * @param {number} args.duration * @param {Function} args.completeCallback */ onChangeActive: function ( active, args ) { if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); } return; } if ( ! $.contains( document, this.container[0] ) ) { // jQuery.fn.slideUp is not hiding an element if it is not in the DOM. this.container.toggle( active ); if ( args.completeCallback ) { args.completeCallback(); } } else if ( active ) { this.container.slideDown( args.duration, args.completeCallback ); } else { this.container.slideUp( args.duration, args.completeCallback ); } }, /** * @deprecated 4.1.0 Use this.onChangeActive() instead. */ toggle: function ( active ) { return this.onChangeActive( active, this.defaultActiveArguments ); }, /* * Documented using @borrows in the constructor */ activate: Container.prototype.activate, /* * Documented using @borrows in the constructor */ deactivate: Container.prototype.deactivate, /* * Documented using @borrows in the constructor */ _toggleActive: Container.prototype._toggleActive, // @todo This function appears to be dead code and can be removed. dropdownInit: function() { var control = this, statuses = this.container.find('.dropdown-status'), params = this.params, toggleFreeze = false, update = function( to ) { if ( 'string' === typeof to && params.statuses && params.statuses[ to ] ) { statuses.html( params.statuses[ to ] ).show(); } else { statuses.hide(); } }; // Support the .dropdown class to open/close complex elements. this.container.on( 'click keydown', '.dropdown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); if ( ! toggleFreeze ) { control.container.toggleClass( 'open' ); } if ( control.container.hasClass( 'open' ) ) { control.container.parent().parent().find( 'li.library-selected' ).focus(); } // Don't want to fire focus and click at same time. toggleFreeze = true; setTimeout(function () { toggleFreeze = false; }, 400); }); this.setting.bind( update ); update( this.setting() ); }, /** * Render the control from its JS template, if it exists. * * The control's container must already exist in the DOM. * * @since 4.1.0 */ renderContent: function () { var control = this, template, standardTypes, templateId, sectionId; standardTypes = [ 'button', 'checkbox', 'date', 'datetime-local', 'email', 'month', 'number', 'password', 'radio', 'range', 'search', 'select', 'tel', 'time', 'text', 'textarea', 'week', 'url' ]; templateId = control.templateSelector; // Use default content template when a standard HTML type is used, // there isn't a more specific template existing, and the control container is empty. if ( templateId === 'customize-control-' + control.params.type + '-content' && _.contains( standardTypes, control.params.type ) && ! document.getElementById( 'tmpl-' + templateId ) && 0 === control.container.children().length ) { templateId = 'customize-control-default-content'; } // Replace the container element's content with the control. if ( document.getElementById( 'tmpl-' + templateId ) ) { template = wp.template( templateId ); if ( template && control.container ) { control.container.html( template( control.params ) ); } } // Re-render notifications after content has been re-rendered. control.notifications.container = control.getNotificationsContainerElement(); sectionId = control.section(); if ( ! sectionId || ( api.section.has( sectionId ) && api.section( sectionId ).expanded() ) ) { control.notifications.render(); } }, /** * Add a new page to a dropdown-pages control reusing menus code for this. * * @since 4.7.0 * @access private * * @return {void} */ addNewPage: function () { var control = this, promise, toggle, container, input, title, select; if ( 'dropdown-pages' !== control.params.type || ! control.params.allow_addition || ! api.Menus ) { return; } toggle = control.container.find( '.add-new-toggle' ); container = control.container.find( '.new-content-item-wrapper' ); input = control.container.find( '.create-item-input' ); title = input.val(); select = control.container.find( 'select' ); if ( ! title ) { input.addClass( 'invalid' ); return; } input.removeClass( 'invalid' ); input.attr( 'disabled', 'disabled' ); // The menus functions add the page, publish when appropriate, // and also add the new page to the dropdown-pages controls. promise = api.Menus.insertAutoDraftPost( { post_title: title, post_type: 'page' } ); promise.done( function( data ) { var availableItem, $content, itemTemplate; // Prepare the new page as an available menu item. // See api.Menus.submitNew(). availableItem = new api.Menus.AvailableItemModel( { 'id': 'post-' + data.post_id, // Used for available menu item Backbone models. 'title': title, 'type': 'post_type', 'type_label': api.Menus.data.l10n.page_label, 'object': 'page', 'object_id': data.post_id, 'url': data.url } ); // Add the new item to the list of available menu items. api.Menus.availableMenuItemsPanel.collection.add( availableItem ); $content = $( '#available-menu-items-post_type-page' ).find( '.available-menu-items-list' ); itemTemplate = wp.template( 'available-menu-item' ); $content.prepend( itemTemplate( availableItem.attributes ) ); // Focus the select control. select.focus(); control.setting.set( String( data.post_id ) ); // Triggers a preview refresh and updates the setting. // Reset the create page form. container.slideUp( 180 ); toggle.slideDown( 180 ); } ); promise.always( function() { input.val( '' ).removeAttr( 'disabled' ); } ); } }); /** * A colorpicker control. * * @class wp.customize.ColorControl * @augments wp.customize.Control */ api.ColorControl = api.Control.extend(/** @lends wp.customize.ColorControl.prototype */{ ready: function() { var control = this, isHueSlider = this.params.mode === 'hue', updating = false, picker; if ( isHueSlider ) { picker = this.container.find( '.color-picker-hue' ); picker.val( control.setting() ).wpColorPicker({ change: function( event, ui ) { updating = true; control.setting( ui.color.h() ); updating = false; } }); } else { picker = this.container.find( '.color-picker-hex' ); picker.val( control.setting() ).wpColorPicker({ change: function() { updating = true; control.setting.set( picker.wpColorPicker( 'color' ) ); updating = false; }, clear: function() { updating = true; control.setting.set( '' ); updating = false; } }); } control.setting.bind( function ( value ) { // Bail if the update came from the control itself. if ( updating ) { return; } picker.val( value ); picker.wpColorPicker( 'color', value ); } ); // Collapse color picker when hitting Esc instead of collapsing the current section. control.container.on( 'keydown', function( event ) { var pickerContainer; if ( 27 !== event.which ) { // Esc. return; } pickerContainer = control.container.find( '.wp-picker-container' ); if ( pickerContainer.hasClass( 'wp-picker-active' ) ) { picker.wpColorPicker( 'close' ); control.container.find( '.wp-color-result' ).focus(); event.stopPropagation(); // Prevent section from being collapsed. } } ); } }); /** * A control that implements the media modal. * * @class wp.customize.MediaControl * @augments wp.customize.Control */ api.MediaControl = api.Control.extend(/** @lends wp.customize.MediaControl.prototype */{ /** * When the control's DOM structure is ready, * set up internal event bindings. */ ready: function() { var control = this; // Shortcut so that we don't have to use _.bind every time we add a callback. _.bindAll( control, 'restoreDefault', 'removeFile', 'openFrame', 'select', 'pausePlayer' ); // Bind events, with delegation to facilitate re-rendering. control.container.on( 'click keydown', '.upload-button', control.openFrame ); control.container.on( 'click keydown', '.upload-button', control.pausePlayer ); control.container.on( 'click keydown', '.thumbnail-image img', control.openFrame ); control.container.on( 'click keydown', '.default-button', control.restoreDefault ); control.container.on( 'click keydown', '.remove-button', control.pausePlayer ); control.container.on( 'click keydown', '.remove-button', control.removeFile ); control.container.on( 'click keydown', '.remove-button', control.cleanupPlayer ); // Resize the player controls when it becomes visible (ie when section is expanded). api.section( control.section() ).container .on( 'expanded', function() { if ( control.player ) { control.player.setControlsSize(); } }) .on( 'collapsed', function() { control.pausePlayer(); }); /** * Set attachment data and render content. * * Note that BackgroundImage.prototype.ready applies this ready method * to itself. Since BackgroundImage is an UploadControl, the value * is the attachment URL instead of the attachment ID. In this case * we skip fetching the attachment data because we have no ID available, * and it is the responsibility of the UploadControl to set the control's * attachmentData before calling the renderContent method. * * @param {number|string} value Attachment */ function setAttachmentDataAndRenderContent( value ) { var hasAttachmentData = $.Deferred(); if ( control.extended( api.UploadControl ) ) { hasAttachmentData.resolve(); } else { value = parseInt( value, 10 ); if ( _.isNaN( value ) || value <= 0 ) { delete control.params.attachment; hasAttachmentData.resolve(); } else if ( control.params.attachment && control.params.attachment.id === value ) { hasAttachmentData.resolve(); } } // Fetch the attachment data. if ( 'pending' === hasAttachmentData.state() ) { wp.media.attachment( value ).fetch().done( function() { control.params.attachment = this.attributes; hasAttachmentData.resolve(); // Send attachment information to the preview for possible use in `postMessage` transport. wp.customize.previewer.send( control.setting.id + '-attachment-data', this.attributes ); } ); } hasAttachmentData.done( function() { control.renderContent(); } ); } // Ensure attachment data is initially set (for dynamically-instantiated controls). setAttachmentDataAndRenderContent( control.setting() ); // Update the attachment data and re-render the control when the setting changes. control.setting.bind( setAttachmentDataAndRenderContent ); }, pausePlayer: function () { this.player && this.player.pause(); }, cleanupPlayer: function () { this.player && wp.media.mixin.removePlayer( this.player ); }, /** * Open the media modal. */ openFrame: function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); if ( ! this.frame ) { this.initFrame(); } this.frame.open(); }, /** * Create a media modal select frame, and store it so the instance can be reused when needed. */ initFrame: function() { this.frame = wp.media({ button: { text: this.params.button_labels.frame_button }, states: [ new wp.media.controller.Library({ title: this.params.button_labels.frame_title, library: wp.media.query({ type: this.params.mime_type }), multiple: false, date: false }) ] }); // When a file is selected, run a callback. this.frame.on( 'select', this.select ); }, /** * Callback handler for when an attachment is selected in the media modal. * Gets the selected image information, and sets it within the control. */ select: function() { // Get the attachment from the modal frame. var node, attachment = this.frame.state().get( 'selection' ).first().toJSON(), mejsSettings = window._wpmejsSettings || {}; this.params.attachment = attachment; // Set the Customizer setting; the callback takes care of rendering. this.setting( attachment.id ); node = this.container.find( 'audio, video' ).get(0); // Initialize audio/video previews. if ( node ) { this.player = new MediaElementPlayer( node, mejsSettings ); } else { this.cleanupPlayer(); } }, /** * Reset the setting to the default value. */ restoreDefault: function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); this.params.attachment = this.params.defaultAttachment; this.setting( this.params.defaultAttachment.url ); }, /** * Called when the "Remove" link is clicked. Empties the setting. * * @param {Object} event jQuery Event object */ removeFile: function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); this.params.attachment = {}; this.setting( '' ); this.renderContent(); // Not bound to setting change when emptying. } }); /** * An upload control, which utilizes the media modal. * * @class wp.customize.UploadControl * @augments wp.customize.MediaControl */ api.UploadControl = api.MediaControl.extend(/** @lends wp.customize.UploadControl.prototype */{ /** * Callback handler for when an attachment is selected in the media modal. * Gets the selected image information, and sets it within the control. */ select: function() { // Get the attachment from the modal frame. var node, attachment = this.frame.state().get( 'selection' ).first().toJSON(), mejsSettings = window._wpmejsSettings || {}; this.params.attachment = attachment; // Set the Customizer setting; the callback takes care of rendering. this.setting( attachment.url ); node = this.container.find( 'audio, video' ).get(0); // Initialize audio/video previews. if ( node ) { this.player = new MediaElementPlayer( node, mejsSettings ); } else { this.cleanupPlayer(); } }, // @deprecated success: function() {}, // @deprecated removerVisibility: function() {} }); /** * A control for uploading images. * * This control no longer needs to do anything more * than what the upload control does in JS. * * @class wp.customize.ImageControl * @augments wp.customize.UploadControl */ api.ImageControl = api.UploadControl.extend(/** @lends wp.customize.ImageControl.prototype */{ // @deprecated thumbnailSrc: function() {} }); /** * A control for uploading background images. * * @class wp.customize.BackgroundControl * @augments wp.customize.UploadControl */ api.BackgroundControl = api.UploadControl.extend(/** @lends wp.customize.BackgroundControl.prototype */{ /** * When the control's DOM structure is ready, * set up internal event bindings. */ ready: function() { api.UploadControl.prototype.ready.apply( this, arguments ); }, /** * Callback handler for when an attachment is selected in the media modal. * Does an additional Ajax request for setting the background context. */ select: function() { api.UploadControl.prototype.select.apply( this, arguments ); wp.ajax.post( 'custom-background-add', { nonce: _wpCustomizeBackground.nonces.add, wp_customize: 'on', customize_theme: api.settings.theme.stylesheet, attachment_id: this.params.attachment.id } ); } }); /** * A control for positioning a background image. * * @since 4.7.0 * * @class wp.customize.BackgroundPositionControl * @augments wp.customize.Control */ api.BackgroundPositionControl = api.Control.extend(/** @lends wp.customize.BackgroundPositionControl.prototype */{ /** * Set up control UI once embedded in DOM and settings are created. * * @since 4.7.0 * @access public */ ready: function() { var control = this, updateRadios; control.container.on( 'change', 'input[name="background-position"]', function() { var position = $( this ).val().split( ' ' ); control.settings.x( position[0] ); control.settings.y( position[1] ); } ); updateRadios = _.debounce( function() { var x, y, radioInput, inputValue; x = control.settings.x.get(); y = control.settings.y.get(); inputValue = String( x ) + ' ' + String( y ); radioInput = control.container.find( 'input[name="background-position"][value="' + inputValue + '"]' ); radioInput.trigger( 'click' ); } ); control.settings.x.bind( updateRadios ); control.settings.y.bind( updateRadios ); updateRadios(); // Set initial UI. } } ); /** * A control for selecting and cropping an image. * * @class wp.customize.CroppedImageControl * @augments wp.customize.MediaControl */ api.CroppedImageControl = api.MediaControl.extend(/** @lends wp.customize.CroppedImageControl.prototype */{ /** * Open the media modal to the library state. */ openFrame: function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } this.initFrame(); this.frame.setState( 'library' ).open(); }, /** * Create a media modal select frame, and store it so the instance can be reused when needed. */ initFrame: function() { var l10n = _wpMediaViewsL10n; this.frame = wp.media({ button: { text: l10n.select, close: false }, states: [ new wp.media.controller.Library({ title: this.params.button_labels.frame_title, library: wp.media.query({ type: 'image' }), multiple: false, date: false, priority: 20, suggestedWidth: this.params.width, suggestedHeight: this.params.height }), new wp.media.controller.CustomizeImageCropper({ imgSelectOptions: this.calculateImageSelectOptions, control: this }) ] }); this.frame.on( 'select', this.onSelect, this ); this.frame.on( 'cropped', this.onCropped, this ); this.frame.on( 'skippedcrop', this.onSkippedCrop, this ); }, /** * After an image is selected in the media modal, switch to the cropper * state if the image isn't the right size. */ onSelect: function() { var attachment = this.frame.state().get( 'selection' ).first().toJSON(); if ( this.params.width === attachment.width && this.params.height === attachment.height && ! this.params.flex_width && ! this.params.flex_height ) { this.setImageFromAttachment( attachment ); this.frame.close(); } else { this.frame.setState( 'cropper' ); } }, /** * After the image has been cropped, apply the cropped image data to the setting. * * @param {Object} croppedImage Cropped attachment data. */ onCropped: function( croppedImage ) { this.setImageFromAttachment( croppedImage ); }, /** * Returns a set of options, computed from the attached image data and * control-specific data, to be fed to the imgAreaSelect plugin in * wp.media.view.Cropper. * * @param {wp.media.model.Attachment} attachment * @param {wp.media.controller.Cropper} controller * @return {Object} Options */ calculateImageSelectOptions: function( attachment, controller ) { var control = controller.get( 'control' ), flexWidth = !! parseInt( control.params.flex_width, 10 ), flexHeight = !! parseInt( control.params.flex_height, 10 ), realWidth = attachment.get( 'width' ), realHeight = attachment.get( 'height' ), xInit = parseInt( control.params.width, 10 ), yInit = parseInt( control.params.height, 10 ), requiredRatio = xInit / yInit, realRatio = realWidth / realHeight, xImg = xInit, yImg = yInit, x1, y1, imgSelectOptions; controller.set( 'hasRequiredAspectRatio', control.hasRequiredAspectRatio( requiredRatio, realRatio ) ); controller.set( 'suggestedCropSize', { width: realWidth, height: realHeight, x1: 0, y1: 0, x2: xInit, y2: yInit } ); controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) ); if ( realRatio > requiredRatio ) { yInit = realHeight; xInit = yInit * requiredRatio; } else { xInit = realWidth; yInit = xInit / requiredRatio; } x1 = ( realWidth - xInit ) / 2; y1 = ( realHeight - yInit ) / 2; imgSelectOptions = { handles: true, keys: true, instance: true, persistent: true, imageWidth: realWidth, imageHeight: realHeight, minWidth: xImg > xInit ? xInit : xImg, minHeight: yImg > yInit ? yInit : yImg, x1: x1, y1: y1, x2: xInit + x1, y2: yInit + y1 }; if ( flexHeight === false && flexWidth === false ) { imgSelectOptions.aspectRatio = xInit + ':' + yInit; } if ( true === flexHeight ) { delete imgSelectOptions.minHeight; imgSelectOptions.maxWidth = realWidth; } if ( true === flexWidth ) { delete imgSelectOptions.minWidth; imgSelectOptions.maxHeight = realHeight; } return imgSelectOptions; }, /** * Return whether the image must be cropped, based on required dimensions. * * @param {boolean} flexW Width is flexible. * @param {boolean} flexH Height is flexible. * @param {number} dstW Required width. * @param {number} dstH Required height. * @param {number} imgW Provided image's width. * @param {number} imgH Provided image's height. * @return {boolean} Whether cropping is required. */ mustBeCropped: function( flexW, flexH, dstW, dstH, imgW, imgH ) { if ( true === flexW && true === flexH ) { return false; } if ( true === flexW && dstH === imgH ) { return false; } if ( true === flexH && dstW === imgW ) { return false; } if ( dstW === imgW && dstH === imgH ) { return false; } if ( imgW <= dstW ) { return false; } return true; }, /** * Check if the image's aspect ratio essentially matches the required aspect ratio. * * Floating point precision is low, so this allows a small tolerance. This * tolerance allows for images over 100,000 px on either side to still trigger * the cropping flow. * * @param {number} requiredRatio Required image ratio. * @param {number} realRatio Provided image ratio. * @return {boolean} Whether the image has the required aspect ratio. */ hasRequiredAspectRatio: function ( requiredRatio, realRatio ) { if ( Math.abs( requiredRatio - realRatio ) < 0.000001 ) { return true; } return false; }, /** * If cropping was skipped, apply the image data directly to the setting. */ onSkippedCrop: function() { var attachment = this.frame.state().get( 'selection' ).first().toJSON(); this.setImageFromAttachment( attachment ); }, /** * Updates the setting and re-renders the control UI. * * @param {Object} attachment */ setImageFromAttachment: function( attachment ) { this.params.attachment = attachment; // Set the Customizer setting; the callback takes care of rendering. this.setting( attachment.id ); } }); /** * A control for selecting and cropping Site Icons. * * @class wp.customize.SiteIconControl * @augments wp.customize.CroppedImageControl */ api.SiteIconControl = api.CroppedImageControl.extend(/** @lends wp.customize.SiteIconControl.prototype */{ /** * Create a media modal select frame, and store it so the instance can be reused when needed. */ initFrame: function() { var l10n = _wpMediaViewsL10n; this.frame = wp.media({ button: { text: l10n.select, close: false }, states: [ new wp.media.controller.Library({ title: this.params.button_labels.frame_title, library: wp.media.query({ type: 'image' }), multiple: false, date: false, priority: 20, suggestedWidth: this.params.width, suggestedHeight: this.params.height }), new wp.media.controller.SiteIconCropper({ imgSelectOptions: this.calculateImageSelectOptions, control: this }) ] }); this.frame.on( 'select', this.onSelect, this ); this.frame.on( 'cropped', this.onCropped, this ); this.frame.on( 'skippedcrop', this.onSkippedCrop, this ); }, /** * After an image is selected in the media modal, switch to the cropper * state if the image isn't the right size. */ onSelect: function() { var attachment = this.frame.state().get( 'selection' ).first().toJSON(), controller = this; if ( this.params.width === attachment.width && this.params.height === attachment.height && ! this.params.flex_width && ! this.params.flex_height ) { wp.ajax.post( 'crop-image', { nonce: attachment.nonces.edit, id: attachment.id, context: 'site-icon', cropDetails: { x1: 0, y1: 0, width: this.params.width, height: this.params.height, dst_width: this.params.width, dst_height: this.params.height } } ).done( function( croppedImage ) { controller.setImageFromAttachment( croppedImage ); controller.frame.close(); } ).fail( function() { controller.frame.trigger('content:error:crop'); } ); } else { this.frame.setState( 'cropper' ); } }, /** * Updates the setting and re-renders the control UI. * * @param {Object} attachment */ setImageFromAttachment: function( attachment ) { var sizes = [ 'site_icon-32', 'thumbnail', 'full' ], link, icon; _.each( sizes, function( size ) { if ( ! icon && ! _.isUndefined ( attachment.sizes[ size ] ) ) { icon = attachment.sizes[ size ]; } } ); this.params.attachment = attachment; // Set the Customizer setting; the callback takes care of rendering. this.setting( attachment.id ); if ( ! icon ) { return; } // Update the icon in-browser. link = $( 'link[rel="icon"][sizes="32x32"]' ); link.attr( 'href', icon.url ); }, /** * Called when the "Remove" link is clicked. Empties the setting. * * @param {Object} event jQuery Event object */ removeFile: function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } event.preventDefault(); this.params.attachment = {}; this.setting( '' ); this.renderContent(); // Not bound to setting change when emptying. $( 'link[rel="icon"][sizes="32x32"]' ).attr( 'href', '/favicon.ico' ); // Set to default. } }); /** * @class wp.customize.HeaderControl * @augments wp.customize.Control */ api.HeaderControl = api.Control.extend(/** @lends wp.customize.HeaderControl.prototype */{ ready: function() { this.btnRemove = $('#customize-control-header_image .actions .remove'); this.btnNew = $('#customize-control-header_image .actions .new'); _.bindAll(this, 'openMedia', 'removeImage'); this.btnNew.on( 'click', this.openMedia ); this.btnRemove.on( 'click', this.removeImage ); api.HeaderTool.currentHeader = this.getInitialHeaderImage(); new api.HeaderTool.CurrentView({ model: api.HeaderTool.currentHeader, el: '#customize-control-header_image .current .container' }); new api.HeaderTool.ChoiceListView({ collection: api.HeaderTool.UploadsList = new api.HeaderTool.ChoiceList(), el: '#customize-control-header_image .choices .uploaded .list' }); new api.HeaderTool.ChoiceListView({ collection: api.HeaderTool.DefaultsList = new api.HeaderTool.DefaultsList(), el: '#customize-control-header_image .choices .default .list' }); api.HeaderTool.combinedList = api.HeaderTool.CombinedList = new api.HeaderTool.CombinedList([ api.HeaderTool.UploadsList, api.HeaderTool.DefaultsList ]); // Ensure custom-header-crop Ajax requests bootstrap the Customizer to activate the previewed theme. wp.media.controller.Cropper.prototype.defaults.doCropArgs.wp_customize = 'on'; wp.media.controller.Cropper.prototype.defaults.doCropArgs.customize_theme = api.settings.theme.stylesheet; }, /** * Returns a new instance of api.HeaderTool.ImageModel based on the currently * saved header image (if any). * * @since 4.2.0 * * @return {Object} Options */ getInitialHeaderImage: function() { if ( ! api.get().header_image || ! api.get().header_image_data || _.contains( [ 'remove-header', 'random-default-image', 'random-uploaded-image' ], api.get().header_image ) ) { return new api.HeaderTool.ImageModel(); } // Get the matching uploaded image object. var currentHeaderObject = _.find( _wpCustomizeHeader.uploads, function( imageObj ) { return ( imageObj.attachment_id === api.get().header_image_data.attachment_id ); } ); // Fall back to raw current header image. if ( ! currentHeaderObject ) { currentHeaderObject = { url: api.get().header_image, thumbnail_url: api.get().header_image, attachment_id: api.get().header_image_data.attachment_id }; } return new api.HeaderTool.ImageModel({ header: currentHeaderObject, choice: currentHeaderObject.url.split( '/' ).pop() }); }, /** * Returns a set of options, computed from the attached image data and * theme-specific data, to be fed to the imgAreaSelect plugin in * wp.media.view.Cropper. * * @param {wp.media.model.Attachment} attachment * @param {wp.media.controller.Cropper} controller * @return {Object} Options */ calculateImageSelectOptions: function(attachment, controller) { var xInit = parseInt(_wpCustomizeHeader.data.width, 10), yInit = parseInt(_wpCustomizeHeader.data.height, 10), flexWidth = !! parseInt(_wpCustomizeHeader.data['flex-width'], 10), flexHeight = !! parseInt(_wpCustomizeHeader.data['flex-height'], 10), ratio, xImg, yImg, realHeight, realWidth, imgSelectOptions; realWidth = attachment.get('width'); realHeight = attachment.get('height'); this.headerImage = new api.HeaderTool.ImageModel(); this.headerImage.set({ themeWidth: xInit, themeHeight: yInit, themeFlexWidth: flexWidth, themeFlexHeight: flexHeight, imageWidth: realWidth, imageHeight: realHeight }); controller.set( 'canSkipCrop', ! this.headerImage.shouldBeCropped() ); ratio = xInit / yInit; xImg = realWidth; yImg = realHeight; if ( xImg / yImg > ratio ) { yInit = yImg; xInit = yInit * ratio; } else { xInit = xImg; yInit = xInit / ratio; } imgSelectOptions = { handles: true, keys: true, instance: true, persistent: true, imageWidth: realWidth, imageHeight: realHeight, x1: 0, y1: 0, x2: xInit, y2: yInit }; if (flexHeight === false && flexWidth === false) { imgSelectOptions.aspectRatio = xInit + ':' + yInit; } if (flexHeight === false ) { imgSelectOptions.maxHeight = yInit; } if (flexWidth === false ) { imgSelectOptions.maxWidth = xInit; } return imgSelectOptions; }, /** * Sets up and opens the Media Manager in order to select an image. * Depending on both the size of the image and the properties of the * current theme, a cropping step after selection may be required or * skippable. * * @param {event} event */ openMedia: function(event) { var l10n = _wpMediaViewsL10n; event.preventDefault(); this.frame = wp.media({ button: { text: l10n.selectAndCrop, close: false }, states: [ new wp.media.controller.Library({ title: l10n.chooseImage, library: wp.media.query({ type: 'image' }), multiple: false, date: false, priority: 20, suggestedWidth: _wpCustomizeHeader.data.width, suggestedHeight: _wpCustomizeHeader.data.height }), new wp.media.controller.Cropper({ imgSelectOptions: this.calculateImageSelectOptions }) ] }); this.frame.on('select', this.onSelect, this); this.frame.on('cropped', this.onCropped, this); this.frame.on('skippedcrop', this.onSkippedCrop, this); this.frame.open(); }, /** * After an image is selected in the media modal, * switch to the cropper state. */ onSelect: function() { this.frame.setState('cropper'); }, /** * After the image has been cropped, apply the cropped image data to the setting. * * @param {Object} croppedImage Cropped attachment data. */ onCropped: function(croppedImage) { var url = croppedImage.url, attachmentId = croppedImage.attachment_id, w = croppedImage.width, h = croppedImage.height; this.setImageFromURL(url, attachmentId, w, h); }, /** * If cropping was skipped, apply the image data directly to the setting. * * @param {Object} selection */ onSkippedCrop: function(selection) { var url = selection.get('url'), w = selection.get('width'), h = selection.get('height'); this.setImageFromURL(url, selection.id, w, h); }, /** * Creates a new wp.customize.HeaderTool.ImageModel from provided * header image data and inserts it into the user-uploaded headers * collection. * * @param {string} url * @param {number} attachmentId * @param {number} width * @param {number} height */ setImageFromURL: function(url, attachmentId, width, height) { var choice, data = {}; data.url = url; data.thumbnail_url = url; data.timestamp = _.now(); if (attachmentId) { data.attachment_id = attachmentId; } if (width) { data.width = width; } if (height) { data.height = height; } choice = new api.HeaderTool.ImageModel({ header: data, choice: url.split('/').pop() }); api.HeaderTool.UploadsList.add(choice); api.HeaderTool.currentHeader.set(choice.toJSON()); choice.save(); choice.importImage(); }, /** * Triggers the necessary events to deselect an image which was set as * the currently selected one. */ removeImage: function() { api.HeaderTool.currentHeader.trigger('hide'); api.HeaderTool.CombinedList.trigger('control:removeImage'); } }); /** * wp.customize.ThemeControl * * @class wp.customize.ThemeControl * @augments wp.customize.Control */ api.ThemeControl = api.Control.extend(/** @lends wp.customize.ThemeControl.prototype */{ touchDrag: false, screenshotRendered: false, /** * @since 4.2.0 */ ready: function() { var control = this, panel = api.panel( 'themes' ); function disableSwitchButtons() { return ! panel.canSwitchTheme( control.params.theme.id ); } // Temporary special function since supplying SFTP credentials does not work yet. See #42184. function disableInstallButtons() { return disableSwitchButtons() || false === api.settings.theme._canInstall || true === api.settings.theme._filesystemCredentialsNeeded; } function updateButtons() { control.container.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() ); control.container.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() ); } api.state( 'selectedChangesetStatus' ).bind( updateButtons ); api.state( 'changesetStatus' ).bind( updateButtons ); updateButtons(); control.container.on( 'touchmove', '.theme', function() { control.touchDrag = true; }); // Bind details view trigger. control.container.on( 'click keydown touchend', '.theme', function( event ) { var section; if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } // Bail if the user scrolled on a touch device. if ( control.touchDrag === true ) { return control.touchDrag = false; } // Prevent the modal from showing when the user clicks the action button. if ( $( event.target ).is( '.theme-actions .button, .update-theme' ) ) { return; } event.preventDefault(); // Keep this AFTER the key filter above. section = api.section( control.section() ); section.showDetails( control.params.theme, function() { // Temporary special function since supplying SFTP credentials does not work yet. See #42184. if ( api.settings.theme._filesystemCredentialsNeeded ) { section.overlay.find( '.theme-actions .delete-theme' ).remove(); } } ); }); control.container.on( 'render-screenshot', function() { var $screenshot = $( this ).find( 'img' ), source = $screenshot.data( 'src' ); if ( source ) { $screenshot.attr( 'src', source ); } control.screenshotRendered = true; }); }, /** * Show or hide the theme based on the presence of the term in the title, description, tags, and author. * * @since 4.2.0 * @param {Array} terms - An array of terms to search for. * @return {boolean} Whether a theme control was activated or not. */ filter: function( terms ) { var control = this, matchCount = 0, haystack = control.params.theme.name + ' ' + control.params.theme.description + ' ' + control.params.theme.tags + ' ' + control.params.theme.author + ' '; haystack = haystack.toLowerCase().replace( '-', ' ' ); // Back-compat for behavior in WordPress 4.2.0 to 4.8.X. if ( ! _.isArray( terms ) ) { terms = [ terms ]; } // Always give exact name matches highest ranking. if ( control.params.theme.name.toLowerCase() === terms.join( ' ' ) ) { matchCount = 100; } else { // Search for and weight (by 10) complete term matches. matchCount = matchCount + 10 * ( haystack.split( terms.join( ' ' ) ).length - 1 ); // Search for each term individually (as whole-word and partial match) and sum weighted match counts. _.each( terms, function( term ) { matchCount = matchCount + 2 * ( haystack.split( term + ' ' ).length - 1 ); // Whole-word, double-weighted. matchCount = matchCount + haystack.split( term ).length - 1; // Partial word, to minimize empty intermediate searches while typing. }); // Upper limit on match ranking. if ( matchCount > 99 ) { matchCount = 99; } } if ( 0 !== matchCount ) { control.activate(); control.params.priority = 101 - matchCount; // Sort results by match count. return true; } else { control.deactivate(); // Hide control. control.params.priority = 101; return false; } }, /** * Rerender the theme from its JS template with the installed type. * * @since 4.9.0 * * @return {void} */ rerenderAsInstalled: function( installed ) { var control = this, section; if ( installed ) { control.params.theme.type = 'installed'; } else { section = api.section( control.params.section ); control.params.theme.type = section.params.action; } control.renderContent(); // Replaces existing content. control.container.trigger( 'render-screenshot' ); } }); /** * Class wp.customize.CodeEditorControl * * @since 4.9.0 * * @class wp.customize.CodeEditorControl * @augments wp.customize.Control */ api.CodeEditorControl = api.Control.extend(/** @lends wp.customize.CodeEditorControl.prototype */{ /** * Initialize. * * @since 4.9.0 * @param {string} id - Unique identifier for the control instance. * @param {Object} options - Options hash for the control instance. * @return {void} */ initialize: function( id, options ) { var control = this; control.deferred = _.extend( control.deferred || {}, { codemirror: $.Deferred() } ); api.Control.prototype.initialize.call( control, id, options ); // Note that rendering is debounced so the props will be used when rendering happens after add event. control.notifications.bind( 'add', function( notification ) { // Skip if control notification is not from setting csslint_error notification. if ( notification.code !== control.setting.id + ':csslint_error' ) { return; } // Customize the template and behavior of csslint_error notifications. notification.templateId = 'customize-code-editor-lint-error-notification'; notification.render = (function( render ) { return function() { var li = render.call( this ); li.find( 'input[type=checkbox]' ).on( 'click', function() { control.setting.notifications.remove( 'csslint_error' ); } ); return li; }; })( notification.render ); } ); }, /** * Initialize the editor when the containing section is ready and expanded. * * @since 4.9.0 * @return {void} */ ready: function() { var control = this; if ( ! control.section() ) { control.initEditor(); return; } // Wait to initialize editor until section is embedded and expanded. api.section( control.section(), function( section ) { section.deferred.embedded.done( function() { var onceExpanded; if ( section.expanded() ) { control.initEditor(); } else { onceExpanded = function( isExpanded ) { if ( isExpanded ) { control.initEditor(); section.expanded.unbind( onceExpanded ); } }; section.expanded.bind( onceExpanded ); } } ); } ); }, /** * Initialize editor. * * @since 4.9.0 * @return {void} */ initEditor: function() { var control = this, element, editorSettings = false; // Obtain editorSettings for instantiation. if ( wp.codeEditor && ( _.isUndefined( control.params.editor_settings ) || false !== control.params.editor_settings ) ) { // Obtain default editor settings. editorSettings = wp.codeEditor.defaultSettings ? _.clone( wp.codeEditor.defaultSettings ) : {}; editorSettings.codemirror = _.extend( {}, editorSettings.codemirror, { indentUnit: 2, tabSize: 2 } ); // Merge editor_settings param on top of defaults. if ( _.isObject( control.params.editor_settings ) ) { _.each( control.params.editor_settings, function( value, key ) { if ( _.isObject( value ) ) { editorSettings[ key ] = _.extend( {}, editorSettings[ key ], value ); } } ); } } element = new api.Element( control.container.find( 'textarea' ) ); control.elements.push( element ); element.sync( control.setting ); element.set( control.setting() ); if ( editorSettings ) { control.initSyntaxHighlightingEditor( editorSettings ); } else { control.initPlainTextareaEditor(); } }, /** * Make sure editor gets focused when control is focused. * * @since 4.9.0 * @param {Object} [params] - Focus params. * @param {Function} [params.completeCallback] - Function to call when expansion is complete. * @return {void} */ focus: function( params ) { var control = this, extendedParams = _.extend( {}, params ), originalCompleteCallback; originalCompleteCallback = extendedParams.completeCallback; extendedParams.completeCallback = function() { if ( originalCompleteCallback ) { originalCompleteCallback(); } if ( control.editor ) { control.editor.codemirror.focus(); } }; api.Control.prototype.focus.call( control, extendedParams ); }, /** * Initialize syntax-highlighting editor. * * @since 4.9.0 * @param {Object} codeEditorSettings - Code editor settings. * @return {void} */ initSyntaxHighlightingEditor: function( codeEditorSettings ) { var control = this, $textarea = control.container.find( 'textarea' ), settings, suspendEditorUpdate = false; settings = _.extend( {}, codeEditorSettings, { onTabNext: _.bind( control.onTabNext, control ), onTabPrevious: _.bind( control.onTabPrevious, control ), onUpdateErrorNotice: _.bind( control.onUpdateErrorNotice, control ) }); control.editor = wp.codeEditor.initialize( $textarea, settings ); // Improve the editor accessibility. $( control.editor.codemirror.display.lineDiv ) .attr({ role: 'textbox', 'aria-multiline': 'true', 'aria-label': control.params.label, 'aria-describedby': 'editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4' }); // Focus the editor when clicking on its label. control.container.find( 'label' ).on( 'click', function() { control.editor.codemirror.focus(); }); /* * When the CodeMirror instance changes, mirror to the textarea, * where we have our "true" change event handler bound. */ control.editor.codemirror.on( 'change', function( codemirror ) { suspendEditorUpdate = true; $textarea.val( codemirror.getValue() ).trigger( 'change' ); suspendEditorUpdate = false; }); // Update CodeMirror when the setting is changed by another plugin. control.setting.bind( function( value ) { if ( ! suspendEditorUpdate ) { control.editor.codemirror.setValue( value ); } }); // Prevent collapsing section when hitting Esc to tab out of editor. control.editor.codemirror.on( 'keydown', function onKeydown( codemirror, event ) { var escKeyCode = 27; if ( escKeyCode === event.keyCode ) { event.stopPropagation(); } }); control.deferred.codemirror.resolveWith( control, [ control.editor.codemirror ] ); }, /** * Handle tabbing to the field after the editor. * * @since 4.9.0 * @return {void} */ onTabNext: function onTabNext() { var control = this, controls, controlIndex, section; section = api.section( control.section() ); controls = section.controls(); controlIndex = controls.indexOf( control ); if ( controls.length === controlIndex + 1 ) { $( '#customize-footer-actions .collapse-sidebar' ).trigger( 'focus' ); } else { controls[ controlIndex + 1 ].container.find( ':focusable:first' ).focus(); } }, /** * Handle tabbing to the field before the editor. * * @since 4.9.0 * @return {void} */ onTabPrevious: function onTabPrevious() { var control = this, controls, controlIndex, section; section = api.section( control.section() ); controls = section.controls(); controlIndex = controls.indexOf( control ); if ( 0 === controlIndex ) { section.contentContainer.find( '.customize-section-title .customize-help-toggle, .customize-section-title .customize-section-description.open .section-description-close' ).last().focus(); } else { controls[ controlIndex - 1 ].contentContainer.find( ':focusable:first' ).focus(); } }, /** * Update error notice. * * @since 4.9.0 * @param {Array} errorAnnotations - Error annotations. * @return {void} */ onUpdateErrorNotice: function onUpdateErrorNotice( errorAnnotations ) { var control = this, message; control.setting.notifications.remove( 'csslint_error' ); if ( 0 !== errorAnnotations.length ) { if ( 1 === errorAnnotations.length ) { message = api.l10n.customCssError.singular.replace( '%d', '1' ); } else { message = api.l10n.customCssError.plural.replace( '%d', String( errorAnnotations.length ) ); } control.setting.notifications.add( new api.Notification( 'csslint_error', { message: message, type: 'error' } ) ); } }, /** * Initialize plain-textarea editor when syntax highlighting is disabled. * * @since 4.9.0 * @return {void} */ initPlainTextareaEditor: function() { var control = this, $textarea = control.container.find( 'textarea' ), textarea = $textarea[0]; $textarea.on( 'blur', function onBlur() { $textarea.data( 'next-tab-blurs', false ); } ); $textarea.on( 'keydown', function onKeydown( event ) { var selectionStart, selectionEnd, value, tabKeyCode = 9, escKeyCode = 27; if ( escKeyCode === event.keyCode ) { if ( ! $textarea.data( 'next-tab-blurs' ) ) { $textarea.data( 'next-tab-blurs', true ); event.stopPropagation(); // Prevent collapsing the section. } return; } // Short-circuit if tab key is not being pressed or if a modifier key *is* being pressed. if ( tabKeyCode !== event.keyCode || event.ctrlKey || event.altKey || event.shiftKey ) { return; } // Prevent capturing Tab characters if Esc was pressed. if ( $textarea.data( 'next-tab-blurs' ) ) { return; } selectionStart = textarea.selectionStart; selectionEnd = textarea.selectionEnd; value = textarea.value; if ( selectionStart >= 0 ) { textarea.value = value.substring( 0, selectionStart ).concat( '\t', value.substring( selectionEnd ) ); $textarea.selectionStart = textarea.selectionEnd = selectionStart + 1; } event.stopPropagation(); event.preventDefault(); }); control.deferred.codemirror.rejectWith( control ); } }); /** * Class wp.customize.DateTimeControl. * * @since 4.9.0 * @class wp.customize.DateTimeControl * @augments wp.customize.Control */ api.DateTimeControl = api.Control.extend(/** @lends wp.customize.DateTimeControl.prototype */{ /** * Initialize behaviors. * * @since 4.9.0 * @return {void} */ ready: function ready() { var control = this; control.inputElements = {}; control.invalidDate = false; _.bindAll( control, 'populateSetting', 'updateDaysForMonth', 'populateDateInputs' ); if ( ! control.setting ) { throw new Error( 'Missing setting' ); } control.container.find( '.date-input' ).each( function() { var input = $( this ), component, element; component = input.data( 'component' ); element = new api.Element( input ); control.inputElements[ component ] = element; control.elements.push( element ); // Add invalid date error once user changes (and has blurred the input). input.on( 'change', function() { if ( control.invalidDate ) { control.notifications.add( new api.Notification( 'invalid_date', { message: api.l10n.invalidDate } ) ); } } ); // Remove the error immediately after validity change. input.on( 'input', _.debounce( function() { if ( ! control.invalidDate ) { control.notifications.remove( 'invalid_date' ); } } ) ); // Add zero-padding when blurring field. input.on( 'blur', _.debounce( function() { if ( ! control.invalidDate ) { control.populateDateInputs(); } } ) ); } ); control.inputElements.month.bind( control.updateDaysForMonth ); control.inputElements.year.bind( control.updateDaysForMonth ); control.populateDateInputs(); control.setting.bind( control.populateDateInputs ); // Start populating setting after inputs have been populated. _.each( control.inputElements, function( element ) { element.bind( control.populateSetting ); } ); }, /** * Parse datetime string. * * @since 4.9.0 * * @param {string} datetime - Date/Time string. Accepts Y-m-d[ H:i[:s]] format. * @return {Object|null} Returns object containing date components or null if parse error. */ parseDateTime: function parseDateTime( datetime ) { var control = this, matches, date, midDayHour = 12; if ( datetime ) { matches = datetime.match( /^(\d\d\d\d)-(\d\d)-(\d\d)(?: (\d\d):(\d\d)(?::(\d\d))?)?$/ ); } if ( ! matches ) { return null; } matches.shift(); date = { year: matches.shift(), month: matches.shift(), day: matches.shift(), hour: matches.shift() || '00', minute: matches.shift() || '00', second: matches.shift() || '00' }; if ( control.params.includeTime && control.params.twelveHourFormat ) { date.hour = parseInt( date.hour, 10 ); date.meridian = date.hour >= midDayHour ? 'pm' : 'am'; date.hour = date.hour % midDayHour ? String( date.hour % midDayHour ) : String( midDayHour ); delete date.second; // @todo Why only if twelveHourFormat? } return date; }, /** * Validates if input components have valid date and time. * * @since 4.9.0 * @return {boolean} If date input fields has error. */ validateInputs: function validateInputs() { var control = this, components, validityInput; control.invalidDate = false; components = [ 'year', 'day' ]; if ( control.params.includeTime ) { components.push( 'hour', 'minute' ); } _.find( components, function( component ) { var element, max, min, value; element = control.inputElements[ component ]; validityInput = element.element.get( 0 ); max = parseInt( element.element.attr( 'max' ), 10 ); min = parseInt( element.element.attr( 'min' ), 10 ); value = parseInt( element(), 10 ); control.invalidDate = isNaN( value ) || value > max || value < min; if ( ! control.invalidDate ) { validityInput.setCustomValidity( '' ); } return control.invalidDate; } ); if ( control.inputElements.meridian && ! control.invalidDate ) { validityInput = control.inputElements.meridian.element.get( 0 ); if ( 'am' !== control.inputElements.meridian.get() && 'pm' !== control.inputElements.meridian.get() ) { control.invalidDate = true; } else { validityInput.setCustomValidity( '' ); } } if ( control.invalidDate ) { validityInput.setCustomValidity( api.l10n.invalidValue ); } else { validityInput.setCustomValidity( '' ); } if ( ! control.section() || api.section.has( control.section() ) && api.section( control.section() ).expanded() ) { _.result( validityInput, 'reportValidity' ); } return control.invalidDate; }, /** * Updates number of days according to the month and year selected. * * @since 4.9.0 * @return {void} */ updateDaysForMonth: function updateDaysForMonth() { var control = this, daysInMonth, year, month, day; month = parseInt( control.inputElements.month(), 10 ); year = parseInt( control.inputElements.year(), 10 ); day = parseInt( control.inputElements.day(), 10 ); if ( month && year ) { daysInMonth = new Date( year, month, 0 ).getDate(); control.inputElements.day.element.attr( 'max', daysInMonth ); if ( day > daysInMonth ) { control.inputElements.day( String( daysInMonth ) ); } } }, /** * Populate setting value from the inputs. * * @since 4.9.0 * @return {boolean} If setting updated. */ populateSetting: function populateSetting() { var control = this, date; if ( control.validateInputs() || ! control.params.allowPastDate && ! control.isFutureDate() ) { return false; } date = control.convertInputDateToString(); control.setting.set( date ); return true; }, /** * Converts input values to string in Y-m-d H:i:s format. * * @since 4.9.0 * @return {string} Date string. */ convertInputDateToString: function convertInputDateToString() { var control = this, date = '', dateFormat, hourInTwentyFourHourFormat, getElementValue, pad; pad = function( number, padding ) { var zeros; if ( String( number ).length < padding ) { zeros = padding - String( number ).length; number = Math.pow( 10, zeros ).toString().substr( 1 ) + String( number ); } return number; }; getElementValue = function( component ) { var value = parseInt( control.inputElements[ component ].get(), 10 ); if ( _.contains( [ 'month', 'day', 'hour', 'minute' ], component ) ) { value = pad( value, 2 ); } else if ( 'year' === component ) { value = pad( value, 4 ); } return value; }; dateFormat = [ 'year', '-', 'month', '-', 'day' ]; if ( control.params.includeTime ) { hourInTwentyFourHourFormat = control.inputElements.meridian ? control.convertHourToTwentyFourHourFormat( control.inputElements.hour(), control.inputElements.meridian() ) : control.inputElements.hour(); dateFormat = dateFormat.concat( [ ' ', pad( hourInTwentyFourHourFormat, 2 ), ':', 'minute', ':', '00' ] ); } _.each( dateFormat, function( component ) { date += control.inputElements[ component ] ? getElementValue( component ) : component; } ); return date; }, /** * Check if the date is in the future. * * @since 4.9.0 * @return {boolean} True if future date. */ isFutureDate: function isFutureDate() { var control = this; return 0 < api.utils.getRemainingTime( control.convertInputDateToString() ); }, /** * Convert hour in twelve hour format to twenty four hour format. * * @since 4.9.0 * @param {string} hourInTwelveHourFormat - Hour in twelve hour format. * @param {string} meridian - Either 'am' or 'pm'. * @return {string} Hour in twenty four hour format. */ convertHourToTwentyFourHourFormat: function convertHour( hourInTwelveHourFormat, meridian ) { var hourInTwentyFourHourFormat, hour, midDayHour = 12; hour = parseInt( hourInTwelveHourFormat, 10 ); if ( isNaN( hour ) ) { return ''; } if ( 'pm' === meridian && hour < midDayHour ) { hourInTwentyFourHourFormat = hour + midDayHour; } else if ( 'am' === meridian && midDayHour === hour ) { hourInTwentyFourHourFormat = hour - midDayHour; } else { hourInTwentyFourHourFormat = hour; } return String( hourInTwentyFourHourFormat ); }, /** * Populates date inputs in date fields. * * @since 4.9.0 * @return {boolean} Whether the inputs were populated. */ populateDateInputs: function populateDateInputs() { var control = this, parsed; parsed = control.parseDateTime( control.setting.get() ); if ( ! parsed ) { return false; } _.each( control.inputElements, function( element, component ) { var value = parsed[ component ]; // This will be zero-padded string. // Set month and meridian regardless of focused state since they are dropdowns. if ( 'month' === component || 'meridian' === component ) { // Options in dropdowns are not zero-padded. value = value.replace( /^0/, '' ); element.set( value ); } else { value = parseInt( value, 10 ); if ( ! element.element.is( document.activeElement ) ) { // Populate element with zero-padded value if not focused. element.set( parsed[ component ] ); } else if ( value !== parseInt( element(), 10 ) ) { // Forcibly update the value if its underlying value changed, regardless of zero-padding. element.set( String( value ) ); } } } ); return true; }, /** * Toggle future date notification for date control. * * @since 4.9.0 * @param {boolean} notify Add or remove the notification. * @return {wp.customize.DateTimeControl} */ toggleFutureDateNotification: function toggleFutureDateNotification( notify ) { var control = this, notificationCode, notification; notificationCode = 'not_future_date'; if ( notify ) { notification = new api.Notification( notificationCode, { type: 'error', message: api.l10n.futureDateError } ); control.notifications.add( notification ); } else { control.notifications.remove( notificationCode ); } return control; } }); /** * Class PreviewLinkControl. * * @since 4.9.0 * @class wp.customize.PreviewLinkControl * @augments wp.customize.Control */ api.PreviewLinkControl = api.Control.extend(/** @lends wp.customize.PreviewLinkControl.prototype */{ defaults: _.extend( {}, api.Control.prototype.defaults, { templateId: 'customize-preview-link-control' } ), /** * Initialize behaviors. * * @since 4.9.0 * @return {void} */ ready: function ready() { var control = this, element, component, node, url, input, button; _.bindAll( control, 'updatePreviewLink' ); if ( ! control.setting ) { control.setting = new api.Value(); } control.previewElements = {}; control.container.find( '.preview-control-element' ).each( function() { node = $( this ); component = node.data( 'component' ); element = new api.Element( node ); control.previewElements[ component ] = element; control.elements.push( element ); } ); url = control.previewElements.url; input = control.previewElements.input; button = control.previewElements.button; input.link( control.setting ); url.link( control.setting ); url.bind( function( value ) { url.element.parent().attr( { href: value, target: api.settings.changeset.uuid } ); } ); api.bind( 'ready', control.updatePreviewLink ); api.state( 'saved' ).bind( control.updatePreviewLink ); api.state( 'changesetStatus' ).bind( control.updatePreviewLink ); api.state( 'activated' ).bind( control.updatePreviewLink ); api.previewer.previewUrl.bind( control.updatePreviewLink ); button.element.on( 'click', function( event ) { event.preventDefault(); if ( control.setting() ) { input.element.select(); document.execCommand( 'copy' ); button( button.element.data( 'copied-text' ) ); } } ); url.element.parent().on( 'click', function( event ) { if ( $( this ).hasClass( 'disabled' ) ) { event.preventDefault(); } } ); button.element.on( 'mouseenter', function() { if ( control.setting() ) { button( button.element.data( 'copy-text' ) ); } } ); }, /** * Updates Preview Link * * @since 4.9.0 * @return {void} */ updatePreviewLink: function updatePreviewLink() { var control = this, unsavedDirtyValues; unsavedDirtyValues = ! api.state( 'saved' ).get() || '' === api.state( 'changesetStatus' ).get() || 'auto-draft' === api.state( 'changesetStatus' ).get(); control.toggleSaveNotification( unsavedDirtyValues ); control.previewElements.url.element.parent().toggleClass( 'disabled', unsavedDirtyValues ); control.previewElements.button.element.prop( 'disabled', unsavedDirtyValues ); control.setting.set( api.previewer.getFrontendPreviewUrl() ); }, /** * Toggles save notification. * * @since 4.9.0 * @param {boolean} notify Add or remove notification. * @return {void} */ toggleSaveNotification: function toggleSaveNotification( notify ) { var control = this, notificationCode, notification; notificationCode = 'changes_not_saved'; if ( notify ) { notification = new api.Notification( notificationCode, { type: 'info', message: api.l10n.saveBeforeShare } ); control.notifications.add( notification ); } else { control.notifications.remove( notificationCode ); } } }); /** * Change objects contained within the main customize object to Settings. * * @alias wp.customize.defaultConstructor */ api.defaultConstructor = api.Setting; /** * Callback for resolved controls. * * @callback wp.customize.deferredControlsCallback * @param {wp.customize.Control[]} controls Resolved controls. */ /** * Collection of all registered controls. * * @alias wp.customize.control * * @since 3.4.0 * * @type {Function} * @param {...string} ids - One or more ids for controls to obtain. * @param {deferredControlsCallback} [callback] - Function called when all supplied controls exist. * @return {wp.customize.Control|undefined|jQuery.promise} Control instance or undefined (if function called with one id param), * or promise resolving to requested controls. * * @example Loop over all registered controls. * wp.customize.control.each( function( control ) { ... } ); * * @example Getting `background_color` control instance. * control = wp.customize.control( 'background_color' ); * * @example Check if control exists. * hasControl = wp.customize.control.has( 'background_color' ); * * @example Deferred getting of `background_color` control until it exists, using callback. * wp.customize.control( 'background_color', function( control ) { ... } ); * * @example Get title and tagline controls when they both exist, using promise (only available when multiple IDs are present). * promise = wp.customize.control( 'blogname', 'blogdescription' ); * promise.done( function( titleControl, taglineControl ) { ... } ); * * @example Get title and tagline controls when they both exist, using callback. * wp.customize.control( 'blogname', 'blogdescription', function( titleControl, taglineControl ) { ... } ); * * @example Getting setting value for `background_color` control. * value = wp.customize.control( 'background_color ').setting.get(); * value = wp.customize( 'background_color' ).get(); // Same as above, since setting ID and control ID are the same. * * @example Add new control for site title. * wp.customize.control.add( new wp.customize.Control( 'other_blogname', { * setting: 'blogname', * type: 'text', * label: 'Site title', * section: 'other_site_identify' * } ) ); * * @example Remove control. * wp.customize.control.remove( 'other_blogname' ); * * @example Listen for control being added. * wp.customize.control.bind( 'add', function( addedControl ) { ... } ) * * @example Listen for control being removed. * wp.customize.control.bind( 'removed', function( removedControl ) { ... } ) */ api.control = new api.Values({ defaultConstructor: api.Control }); /** * Callback for resolved sections. * * @callback wp.customize.deferredSectionsCallback * @param {wp.customize.Section[]} sections Resolved sections. */ /** * Collection of all registered sections. * * @alias wp.customize.section * * @since 3.4.0 * * @type {Function} * @param {...string} ids - One or more ids for sections to obtain. * @param {deferredSectionsCallback} [callback] - Function called when all supplied sections exist. * @return {wp.customize.Section|undefined|jQuery.promise} Section instance or undefined (if function called with one id param), * or promise resolving to requested sections. * * @example Loop over all registered sections. * wp.customize.section.each( function( section ) { ... } ) * * @example Getting `title_tagline` section instance. * section = wp.customize.section( 'title_tagline' ) * * @example Expand dynamically-created section when it exists. * wp.customize.section( 'dynamically_created', function( section ) { * section.expand(); * } ); * * @see {@link wp.customize.control} for further examples of how to interact with {@link wp.customize.Values} instances. */ api.section = new api.Values({ defaultConstructor: api.Section }); /** * Callback for resolved panels. * * @callback wp.customize.deferredPanelsCallback * @param {wp.customize.Panel[]} panels Resolved panels. */ /** * Collection of all registered panels. * * @alias wp.customize.panel * * @since 4.0.0 * * @type {Function} * @param {...string} ids - One or more ids for panels to obtain. * @param {deferredPanelsCallback} [callback] - Function called when all supplied panels exist. * @return {wp.customize.Panel|undefined|jQuery.promise} Panel instance or undefined (if function called with one id param), * or promise resolving to requested panels. * * @example Loop over all registered panels. * wp.customize.panel.each( function( panel ) { ... } ) * * @example Getting nav_menus panel instance. * panel = wp.customize.panel( 'nav_menus' ); * * @example Expand dynamically-created panel when it exists. * wp.customize.panel( 'dynamically_created', function( panel ) { * panel.expand(); * } ); * * @see {@link wp.customize.control} for further examples of how to interact with {@link wp.customize.Values} instances. */ api.panel = new api.Values({ defaultConstructor: api.Panel }); /** * Callback for resolved notifications. * * @callback wp.customize.deferredNotificationsCallback * @param {wp.customize.Notification[]} notifications Resolved notifications. */ /** * Collection of all global notifications. * * @alias wp.customize.notifications * * @since 4.9.0 * * @type {Function} * @param {...string} codes - One or more codes for notifications to obtain. * @param {deferredNotificationsCallback} [callback] - Function called when all supplied notifications exist. * @return {wp.customize.Notification|undefined|jQuery.promise} Notification instance or undefined (if function called with one code param), * or promise resolving to requested notifications. * * @example Check if existing notification * exists = wp.customize.notifications.has( 'a_new_day_arrived' ); * * @example Obtain existing notification * notification = wp.customize.notifications( 'a_new_day_arrived' ); * * @example Obtain notification that may not exist yet. * wp.customize.notifications( 'a_new_day_arrived', function( notification ) { ... } ); * * @example Add a warning notification. * wp.customize.notifications.add( new wp.customize.Notification( 'midnight_almost_here', { * type: 'warning', * message: 'Midnight has almost arrived!', * dismissible: true * } ) ); * * @example Remove a notification. * wp.customize.notifications.remove( 'a_new_day_arrived' ); * * @see {@link wp.customize.control} for further examples of how to interact with {@link wp.customize.Values} instances. */ api.notifications = new api.Notifications(); api.PreviewFrame = api.Messenger.extend(/** @lends wp.customize.PreviewFrame.prototype */{ sensitivity: null, // Will get set to api.settings.timeouts.previewFrameSensitivity. /** * An object that fetches a preview in the background of the document, which * allows for seamless replacement of an existing preview. * * @constructs wp.customize.PreviewFrame * @augments wp.customize.Messenger * * @param {Object} params.container * @param {Object} params.previewUrl * @param {Object} params.query * @param {Object} options */ initialize: function( params, options ) { var deferred = $.Deferred(); /* * Make the instance of the PreviewFrame the promise object * so other objects can easily interact with it. */ deferred.promise( this ); this.container = params.container; $.extend( params, { channel: api.PreviewFrame.uuid() }); api.Messenger.prototype.initialize.call( this, params, options ); this.add( 'previewUrl', params.previewUrl ); this.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() }); this.run( deferred ); }, /** * Run the preview request. * * @param {Object} deferred jQuery Deferred object to be resolved with * the request. */ run: function( deferred ) { var previewFrame = this, loaded = false, ready = false, readyData = null, hasPendingChangesetUpdate = '{}' !== previewFrame.query.customized, urlParser, params, form; if ( previewFrame._ready ) { previewFrame.unbind( 'ready', previewFrame._ready ); } previewFrame._ready = function( data ) { ready = true; readyData = data; previewFrame.container.addClass( 'iframe-ready' ); if ( ! data ) { return; } if ( loaded ) { deferred.resolveWith( previewFrame, [ data ] ); } }; previewFrame.bind( 'ready', previewFrame._ready ); urlParser = document.createElement( 'a' ); urlParser.href = previewFrame.previewUrl(); params = _.extend( api.utils.parseQueryString( urlParser.search.substr( 1 ) ), { customize_changeset_uuid: previewFrame.query.customize_changeset_uuid, customize_theme: previewFrame.query.customize_theme, customize_messenger_channel: previewFrame.query.customize_messenger_channel } ); if ( api.settings.changeset.autosaved || ! api.state( 'saved' ).get() ) { params.customize_autosaved = 'on'; } urlParser.search = $.param( params ); previewFrame.iframe = $( '
      "); jQuery("#TB_overlay").on( 'click', tb_remove ); } }else{//all others if(document.getElementById("TB_overlay") === null){ jQuery("body").append("
      "); jQuery("#TB_overlay").on( 'click', tb_remove ); jQuery( 'body' ).addClass( 'modal-open' ); } } if(tb_detectMacXFF()){ jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash }else{ jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity } if(caption===null){caption="";} jQuery("body").append("
      ");//add loader to the page jQuery('#TB_load').show();//show loader var baseURL; if(url.indexOf("?")!==-1){ //ff there is a query string involved baseURL = url.substr(0, url.indexOf("?")); }else{ baseURL = url; } var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.webp$|\.avif$/; var urlType = baseURL.toLowerCase().match(urlString); if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp' || urlType == '.webp' || urlType == '.avif' ){//code to show images TB_PrevCaption = ""; TB_PrevURL = ""; TB_PrevHTML = ""; TB_NextCaption = ""; TB_NextURL = ""; TB_NextHTML = ""; TB_imageCount = ""; TB_FoundURL = false; if(imageGroup){ TB_TempArray = jQuery("a[rel="+imageGroup+"]").get(); for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) { var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString); if (!(TB_TempArray[TB_Counter].href == url)) { if (TB_FoundURL) { TB_NextCaption = TB_TempArray[TB_Counter].title; TB_NextURL = TB_TempArray[TB_Counter].href; TB_NextHTML = "  "+thickboxL10n.next+""; } else { TB_PrevCaption = TB_TempArray[TB_Counter].title; TB_PrevURL = TB_TempArray[TB_Counter].href; TB_PrevHTML = "  "+thickboxL10n.prev+""; } } else { TB_FoundURL = true; TB_imageCount = thickboxL10n.image + ' ' + (TB_Counter + 1) + ' ' + thickboxL10n.of + ' ' + (TB_TempArray.length); } } } imgPreloader = new Image(); imgPreloader.onload = function(){ imgPreloader.onload = null; // Resizing large images - original by Christian Montoya edited by me. var pagesize = tb_getPageSize(); var x = pagesize[0] - 150; var y = pagesize[1] - 150; var imageWidth = imgPreloader.width; var imageHeight = imgPreloader.height; if (imageWidth > x) { imageHeight = imageHeight * (x / imageWidth); imageWidth = x; if (imageHeight > y) { imageWidth = imageWidth * (y / imageHeight); imageHeight = y; } } else if (imageHeight > y) { imageWidth = imageWidth * (y / imageHeight); imageHeight = y; if (imageWidth > x) { imageHeight = imageHeight * (x / imageWidth); imageWidth = x; } } // End Resizing TB_WIDTH = imageWidth + 30; TB_HEIGHT = imageHeight + 60; jQuery("#TB_window").append(""+thickboxL10n.close+""+caption+"" + "
      "+caption+"
      " + TB_imageCount + TB_PrevHTML + TB_NextHTML + "
      "); jQuery("#TB_closeWindowButton").on( 'click', tb_remove ); if (!(TB_PrevHTML === "")) { function goPrev(){ if(jQuery(document).off("click",goPrev)){jQuery(document).off("click",goPrev);} jQuery("#TB_window").remove(); jQuery("body").append("
      "); tb_show(TB_PrevCaption, TB_PrevURL, imageGroup); return false; } jQuery("#TB_prev").on( 'click', goPrev ); } if (!(TB_NextHTML === "")) { function goNext(){ jQuery("#TB_window").remove(); jQuery("body").append("
      "); tb_show(TB_NextCaption, TB_NextURL, imageGroup); return false; } jQuery("#TB_next").on( 'click', goNext ); } jQuery(document).on('keydown.thickbox', function(e){ if ( e.which == 27 ){ // close tb_remove(); } else if ( e.which == 190 ){ // display previous image if(!(TB_NextHTML == "")){ jQuery(document).off('thickbox'); goNext(); } } else if ( e.which == 188 ){ // display next image if(!(TB_PrevHTML == "")){ jQuery(document).off('thickbox'); goPrev(); } } return false; }); tb_position(); jQuery("#TB_load").remove(); jQuery("#TB_ImageOff").on( 'click', tb_remove ); jQuery("#TB_window").css({'visibility':'visible'}); //for safari using css instead of show }; imgPreloader.src = url; }else{//code to show html var queryString = url.replace(/^[^\?]+\??/,''); var params = tb_parseQuery( queryString ); TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no parameters were added to URL TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no parameters were added to URL ajaxContentW = TB_WIDTH - 30; ajaxContentH = TB_HEIGHT - 45; if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window urlNoQuery = url.split('TB_'); jQuery("#TB_iframeContent").remove(); if(params['modal'] != "true"){//iframe no modal jQuery("#TB_window").append("
      "+caption+"
      "); }else{//iframe modal jQuery("#TB_overlay").off(); jQuery("#TB_window").append(""); } }else{// not an iframe, ajax if(jQuery("#TB_window").css("visibility") != "visible"){ if(params['modal'] != "true"){//ajax no modal jQuery("#TB_window").append("
      "+caption+"
      "); }else{//ajax modal jQuery("#TB_overlay").off(); jQuery("#TB_window").append("
      "); } }else{//this means the window is already up, we are just loading new content via ajax jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px"; jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px"; jQuery("#TB_ajaxContent")[0].scrollTop = 0; jQuery("#TB_ajaxWindowTitle").html(caption); } } jQuery("#TB_closeWindowButton").on( 'click', tb_remove ); if(url.indexOf('TB_inline') != -1){ jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children()); jQuery("#TB_window").on('tb_unload', function () { jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished }); tb_position(); jQuery("#TB_load").remove(); jQuery("#TB_window").css({'visibility':'visible'}); }else if(url.indexOf('TB_iframe') != -1){ tb_position(); jQuery("#TB_load").remove(); jQuery("#TB_window").css({'visibility':'visible'}); }else{ var load_url = url; load_url += -1 === url.indexOf('?') ? '?' : '&'; jQuery("#TB_ajaxContent").load(load_url += "random=" + (new Date().getTime()),function(){//to do a post change this load method tb_position(); jQuery("#TB_load").remove(); tb_init("#TB_ajaxContent a.thickbox"); jQuery("#TB_window").css({'visibility':'visible'}); }); } } if(!params['modal']){ jQuery(document).on('keydown.thickbox', function(e){ if ( e.which == 27 ){ // close tb_remove(); return false; } }); } $closeBtn = jQuery( '#TB_closeWindowButton' ); /* * If the native Close button icon is visible, move focus on the button * (e.g. in the Network Admin Themes screen). * In other admin screens is hidden and replaced by a different icon. */ if ( $closeBtn.find( '.tb-close-icon' ).is( ':visible' ) ) { $closeBtn.trigger( 'focus' ); } } catch(e) { //nothing here } } //helper functions below function tb_showIframe(){ jQuery("#TB_load").remove(); jQuery("#TB_window").css({'visibility':'visible'}).trigger( 'thickbox:iframe:loaded' ); } function tb_remove() { jQuery("#TB_imageOff").off("click"); jQuery("#TB_closeWindowButton").off("click"); jQuery( '#TB_window' ).fadeOut( 'fast', function() { jQuery( '#TB_window, #TB_overlay, #TB_HideSelect' ).trigger( 'tb_unload' ).off().remove(); jQuery( 'body' ).trigger( 'thickbox:removed' ); }); jQuery( 'body' ).removeClass( 'modal-open' ); jQuery("#TB_load").remove(); if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 jQuery("body","html").css({height: "auto", width: "auto"}); jQuery("html").css("overflow",""); } jQuery(document).off('.thickbox'); return false; } function tb_position() { var isIE6 = typeof document.body.style.maxHeight === "undefined"; jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'}); if ( ! isIE6 ) { // take away IE6 jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'}); } } function tb_parseQuery ( query ) { var Params = {}; if ( ! query ) {return Params;}// return empty object var Pairs = query.split(/[;&]/); for ( var i = 0; i < Pairs.length; i++ ) { var KeyVal = Pairs[i].split('='); if ( ! KeyVal || KeyVal.length != 2 ) {continue;} var key = unescape( KeyVal[0] ); var val = unescape( KeyVal[1] ); val = val.replace(/\+/g, ' '); Params[key] = val; } return Params; } function tb_getPageSize(){ var de = document.documentElement; var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; arrayPageSize = [w,h]; return arrayPageSize; } function tb_detectMacXFF() { var userAgent = navigator.userAgent.toLowerCase(); if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) { return true; } } PK!k;;thickbox/loadingAnimation.gifnu[GIF89a! NETSCAPE2.0! ,DRihlp,tmx| Ȥrl:P'@0ج(E X\zlXifZunYrt|n~Yzd `w^xoE% U ~¶Ʊ̯ϺsҿeշsjF )Łl?J4aÁ'&h1 D%r#Ȑ #0$0#J#I|y0&ɏ4)dYI6;L;y PJLXf 3kT`h{׮U!%kT jmjZs}/Vu-w/Tbv+XqaÈ7X|_^-|€Ϡ=倁ӨQZ[c^eǦ]wtԼ}\pˍ778 {׽?W{֥g Do`# ^A}G ~Gp H`}1߁ Χv`\! )rx%(!. `%:DXA EciJ4d;)VLR@!:ZdY%S)&`x&ij&m#my_:%)ـXԩ@@mꀠ#2 .*飉F褙x 桜R*꟠R香Zjj) `+l`a ,Ų촽.F{.,j-^ .Ǝ, KlZJ/޶Kλ/K믻{ |K/ X 00GļT|/ h "p?{| =61/@$S.|뼾ʓ?~ˏ#[=kG~Vg-/YX'6 { ˰W=sMb ~b gAaa0 L<SM.vp!nN }D?Lx%L,xuOoDF1[zpvjq4+W fG 18c?a&:=t8n ntZt"#Q5.td#-H.F2WtV%WM*IQr2Y:RnX/=x~c1HC"m082zd&Hc>OuE$npU(7=2A'Pp ;Ce(UNԝV,5K-ELU] (i9OP֒1E^H" XͪVծz3`dhMZךZ\!! ,Ldihlp,tmx|A+Ȥrl:&DX-ƴJ,,c*ayU65{iuVV잠sd}rW{\o`y t|vq(kx)u~z)w', D,+)**()ɲë'Ĺ(ձѽ&&ٰ%&A, p@PA pEA 8ྈ.lE 28"ICU$D9eɏ,ErL1f)m9fG4i.,HEg'Xx:*ZJU [v5-[dpkDܷ'r*lִ*5W-_".!B&Q8dX5bb9`4,>iԞAv=*T´m)t^vn٭h嵍GDqWWq8 ɹ/~sѱ|ܣ(@@8hϢ~ I~}ՙ`%, x߃7 BH " 0Ha}v)lh83FXc%袊D`A-,耐CYAI+i$?RYPf$ Vɣ"%\:ejBXh& E>[)f#Ly uv)hg!~y#9g^tYܩ.6`iDbk*難Rǩ)F) V*eJ:+6jl.[ D W$"p,H ih*H;mfm~n徛.` 䚋+n ڛB0( .6 m&{S ̋1 䍋1 @Op3.Ls0}< tl4 ?|tN\4HO}B^J[]rI?m ,Mk`#k u,t1xM2|+W,Ȃ}[3k.Sy cQg92n:B6^65ֶk u>|WN{ 76og\ǣG={%x=mܫ/1oݿ=_ǿS8oz Lۧ,y>{{'rx3Hɐ#! 9I2a 쭬pyK\3n<]@:m.RէѾ$ * Jo_? D>~)\¡2֩Jq-+{& qD.'馭;Ξ֗K KG$>>z388#"3, K K GG>>ƹ;@}# =~䵫V\(q~%D N,A3P4%2Ui摜>}N6 P1BuIVG<*iMD}xY'֯=N% 2`9+]N>{D.a>+±À ~7q} wV؇eј= |9r8NC!гg zpkگK ‷ 4XEq3D9NjK/>qҩ/!=zCg9G7`!DqPXDsQuxąj&+ (fȠu,H.Zhud=8a)]K\OC*Bf9u.4$8crI@酙Txe^fgi!掇 jf iJ& v` .$Ĩ Ҋ*.ꭹk>+ڊ$L;k>JKv+ˢ.؎.Blzz&P.K; //<p.|1 KkS3 wl2 *v,)ӯb*=}j/w~Nyˌ?￷3揀_1f~T  (AEPt Y2muK=q^=݅_[XЅ%dC0UطְKF> 1^7)Fsx?T61zaDnuZDȨmC׶fz\H-3ݮBP!^$=J&lGօ(3ѕL+e5rR"IKl2l\/s5$ri %Ij@ڐ$r vf'Lbf,f5)Nd)4*Qy3>\:}3\Q;aɹ^g;멹Zp ' I8Ne{"Dȉ0ShEYl5DhⰡJ8Ҍ* eAN%?x~=OT555 ƄԦ:PTJժZXͪVU* %] XJֲhMZ! ,Ldihlp,tmx|﫣pH,ȤrtAZX i  ŕRUW 5ᵪE_c{/ysmu)ix[}pbz|Uwr{n+t')j1, ,+'**())ɫ&Ͻ%(ǹ'۷-A* ,ǂ?O_ װA U0$⿉:Da0F"-&1Ƒ'J\H~iD){̩&Lh"ESOJRf]u\6zve@ںs5WkԴ@-Aw0`vW 낁e0@),.c~ygKysϫ'.tM'D6IFm*N;Y Mܷݵ{69貱;FWX_Pˣ`_`{? Ⳡ~{@}|'w"V{`)(X(dzImx"|$&"/+*`#ӂ4hcf͸8(b==p#i LycrBVn Hb,<\:y馗k9 e‰_>h D!e9 %(H6ʣ()~.z)X('zvxsj蔈Bj*jBZ*록j+ ,V  .`wlӦ:;l,$k-BK .@+m^m ۮm«BR p(nn2̭ྛ# k/&Lqz;OuΜ~:tm з>|[>;{}CgO]O>߽:yI[^]KS 8?R0kdZo7 &KdL`B2sdwWB^0~^0?Y~ ֱ" نh"0HdD=Q\wD# 8_-Vw[I 56{XA;jNpG9 O~]fF.{[:I2zx[3?>g=IPnq#%*wJKO\`(q,d =q%!:Fё#1e&j4_KDJS{&-7n%7/6pB~-,)OM*MyO63 2LjS0PLB|hzЅ:pEf6#Q7R2ڳJ'},9ŕrQy̘/բKU9E𝲧Jqәtc*.Lk6բu*/ R^T}Tdnի]( i&hMZֶ& fm\J׺u`B! , PLdihlp,tmx|醙pH,Ȥrɜ8H( BDvѐNW֖|'V VzW%S0]5buez)m}-yj v~*s(wx`Y'|'%%, ,+$**())ΰý±Ķ('ݪڼ,O ,T/ߊ}N\!P=*p`A}VtcB -v< zH)$j & &S4$82bɖ:$(& 6Uhl:銫XJլPU bSVs[,ݭj_Vݎ \xB޴Q% kF`, >ɊΞ^!iU,P=tγY׆}jڮmz֯5[wU07s=tɱ/\o(Coh+ /ЀUaЖݡ_}ʕ,M$_ 7 8߂!|fX JH ȡ&8X !28 "a]:0 hB9#cԈ/#$ ='BE:pdE MX&) T$M~cYf$N[rg駚3bM:a[4p(A:!h{IBB)=vzߧN# jꪱ6Zi bz+"+,h :v, y ²: m&؎+m*Ϯmߞ{m%n+/.$m  Sko{0 0P13K+L22:O-{|, +|2)k3 27s/Jʹ8?3YW\p m_0Z.q 0^O-qet,7}8pn BRnӊ\3(`u!Mu$lӍNШzױ^Ԟ /mk9>շ;޻ۻS~nOV|Oا}ף-^>?ϽOݺ_m~ӟ,/]gdF<]+c] ρà6 u1궃ZDd2oe EcQZwn#ֲ.sLb+(>X|XEԋ.iS)PijwTl GGя&r-h09ՁVL*AP"QmXJֲhMZֶpk@! ,`HSihlp,tmx|AȤrl:ШCuAG+ht`xY_]>aWvk_,dfopikm}**zr)yl|(t/ %T r.. V-,ýǠ'Ƹ+*(ֿ+*,-߰)A)[U .#Dh"Z ` }Xذ`hq_F0P#CE4Y1%F+(Đ_͘8]yRdϋ$L@A ~) OYDm0ՅUTSl*ְ(f]u hOu+V*]m㚀Y|6{"0zKf;8UkױY&0p bUiC?͢'vtj٫is~"lһmVzEmL)|npUup罉6)jc_} PkY/=*~}G-ހ`~g߃),ȟ Q!~'`!+|(:E Q.N., =xD#@I;࣍Cd/FV$L9ERi% ^&–f Sy($PH5 &rhbc  KRbJ9OBz ʧ6'F䧫z%=飝"jj((pYR-(> @Ǻ`m -,| r ffA P/ j׺B0v[-2 Gnh@$p~%[̲ zr ܱo 1ܲ˼|(q> L#})EK =c)۲le/ NM=q2c'M=8߁m54cLp'R3.M z4}&yԜ;Z@[:w.۩Km{[;W>tx7ߗ7/K?Уn} /?x;;}OomL4[. isTvux[{}bm,o~gk+_w* W B,ƾ¶ǿ+ïʵռ*f)(ꗄ"#FEE (:!C&`ď"-flh#ʔ Is hQ0e>TcѝYX$ %ׯ&aѠlY1`Ӧ ۷gèv슷h oz%pm{໅7fx1Ǝqȗ1? 3qՀv1Mvm] ^m ͻ…/7䶗3-3u;~=wvǹg/ۿg>=/`kN i8 +x  a& *8 NH!a !*(!Ņ6'b?Ȣ>n\ओV8E' Y'qRy[va٧zyP4D*(Mb9Cr6 % Yn@*Tzډ>)*ꨩ©k Z뮷 kJ6ʯ(` (p .[  v;/./z |n| c[&ROL131 {01 _[ .njL3 ¼ 3w8L6"9-t/ tS?Mt;BVtZg[x?5_omtYǝ<2)g|0|2 0>8!}8K~9 ;8*~/z>:}hnL^Jov c]Í+{ '^خ>TcˢߋXٖ.0ys=?%0˿' m8Z|[8#,n@+B 0|"8lT!XX=0#|<0>a ]ݏst 8""Sb.'j̀ [ fEa[Wx1mI1\XTleB)#XF=fx#G[4 Y1<$/&{$#1EN2b|%A9GRaqĖE:)s7W.Ww0)K~sc´%+KqrafRԛXl6ώ֤Pkyڌ7׽|B& kӛ^7Yw:WK\#3y]elf7q2-EX} (G+l+a&pQltd'KɗS)җW7~vW1}晣G>{O~|wG]~&_Y})Gw1M)*PH(! Zj)x"N0 %^(4Rb ᘣ(B(-"yD ,%d6" O˜W 6p"Ș9`& bI—Pg gXYw#%s:a9%PX虖J)@ ,Х ")0 @~%Ċ +:+ **Z+"++zl ,({FZ[-b[..j-$0޻켼Po# 쯸׻pp0#<c 1 GL2\B1&k0.Rln6 mn9=Z-+CC\4G{Z_:nc8ׇ=ۏy 3oo7> x>ݏ֘ ;AvjުX/  (.zs 8AHA" %5\{` W1뱏r"ĸ){X?(qqBlbCubGǵ;<40ie ZFrl#zC1{HVPp[b6.zT"iE*iDd*IjS$>YPJыӣ 8HحQ\wlrKYޒh[+VG*j$;v8O!,jNΚ&#jS{LYiW 0L c;O"s\f_@~ 4.τvp=!: qst8hIsJ8dF14si/RBҥu@Ӛ8ͩNw@ PJT%;PK!c ^^thickbox/macFFBgHack.pngnu[PNG  IHDRc%IDATH! _jM H$D"H_,!ZIENDB`PK!5 api-request.jsnu[/** * Thin jQuery.ajax wrapper for WP REST API requests. * * Currently only applies to requests that do not use the `wp-api.js` Backbone * client library, though this may change. Serves several purposes: * * - Allows overriding these requests as needed by customized WP installations. * - Sends the REST API nonce as a request header. * - Allows specifying only an endpoint namespace/path instead of a full URL. * * @since 4.9.0 * @since 5.6.0 Added overriding of the "PUT" and "DELETE" methods with "POST". * Added an "application/json" Accept header to all requests. * @output wp-includes/js/api-request.js */ ( function( $ ) { var wpApiSettings = window.wpApiSettings; function apiRequest( options ) { options = apiRequest.buildAjaxOptions( options ); return apiRequest.transport( options ); } apiRequest.buildAjaxOptions = function( options ) { var url = options.url; var path = options.path; var method = options.method; var namespaceTrimmed, endpointTrimmed, apiRoot; var headers, addNonceHeader, addAcceptHeader, headerName; if ( typeof options.namespace === 'string' && typeof options.endpoint === 'string' ) { namespaceTrimmed = options.namespace.replace( /^\/|\/$/g, '' ); endpointTrimmed = options.endpoint.replace( /^\//, '' ); if ( endpointTrimmed ) { path = namespaceTrimmed + '/' + endpointTrimmed; } else { path = namespaceTrimmed; } } if ( typeof path === 'string' ) { apiRoot = wpApiSettings.root; path = path.replace( /^\//, '' ); // API root may already include query parameter prefix // if site is configured to use plain permalinks. if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) { path = path.replace( '?', '&' ); } url = apiRoot + path; } // If ?_wpnonce=... is present, no need to add a nonce header. addNonceHeader = ! ( options.data && options.data._wpnonce ); addAcceptHeader = true; headers = options.headers || {}; for ( headerName in headers ) { if ( ! headers.hasOwnProperty( headerName ) ) { continue; } // If an 'X-WP-Nonce' or 'Accept' header (or any case-insensitive variation // thereof) was specified, no need to add the header again. switch ( headerName.toLowerCase() ) { case 'x-wp-nonce': addNonceHeader = false; break; case 'accept': addAcceptHeader = false; break; } } if ( addNonceHeader ) { // Do not mutate the original headers object, if any. headers = $.extend( { 'X-WP-Nonce': wpApiSettings.nonce }, headers ); } if ( addAcceptHeader ) { headers = $.extend( { 'Accept': 'application/json, */*;q=0.1' }, headers ); } if ( typeof method === 'string' ) { method = method.toUpperCase(); if ( 'PUT' === method || 'DELETE' === method ) { headers = $.extend( { 'X-HTTP-Method-Override': method }, headers ); method = 'POST'; } } // Do not mutate the original options object. options = $.extend( {}, options, { headers: headers, url: url, method: method } ); delete options.path; delete options.namespace; delete options.endpoint; return options; }; apiRequest.transport = $.ajax; /** @namespace wp */ window.wp = window.wp || {}; window.wp.apiRequest = apiRequest; } )( jQuery ); PK!\#oowp-auth-check.jsnu[/** * Interim login dialog. * * @output wp-includes/js/wp-auth-check.js */ ( function( $ ) { var wrap, tempHidden, tempHiddenTimeout; /** * Shows the authentication form popup. * * @since 3.6.0 * @private */ function show() { var parent = $( '#wp-auth-check' ), form = $( '#wp-auth-check-form' ), noframe = wrap.find( '.wp-auth-fallback-expired' ), frame, loaded = false; if ( form.length ) { // Add unload confirmation to counter (frame-busting) JS redirects. $( window ).on( 'beforeunload.wp-auth-check', function( event ) { event.originalEvent.returnValue = window.wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' ); }); frame = $( ''),void 0===a&&(a=t.renderHtml(e)),e.statusbar&&(s=e.statusbar.renderHtml()),'
      '+o+'
      '+a+"
      "+s+"
      "},fullscreen:function(e){var n,t,i=this,r=_.document.documentElement,o=i.classPrefix;if(e!==i._fullscreen)if(ye(_.window).on("resize",function(){var e;if(i._fullscreen)if(n)i._timer||(i._timer=u.setTimeout(function(){var e=we.getWindowSize();i.moveTo(0,0).resizeTo(e.w,e.h),i._timer=0},50));else{e=(new Date).getTime();var t=we.getWindowSize();i.moveTo(0,0).resizeTo(t.w,t.h),50<(new Date).getTime()-e&&(n=!0)}}),t=i.layoutRect(),i._fullscreen=e){i._initial={x:t.x,y:t.y,w:t.w,h:t.h},i.borderBox=Me("0"),i.getEl("head").style.display="none",t.deltaH-=t.headerH+2,ye([r,_.document.body]).addClass(o+"fullscreen"),i.classes.add("fullscreen");var s=we.getWindowSize();i.moveTo(0,0).resizeTo(s.w,s.h)}else i.borderBox=Me(i.settings.border),i.getEl("head").style.display="",t.deltaH+=t.headerH,ye([r,_.document.body]).removeClass(o+"fullscreen"),i.classes.remove("fullscreen"),i.moveTo(i._initial.x,i._initial.y).resizeTo(i._initial.w,i._initial.h);return i.reflow()},postRender:function(){var t,n=this;setTimeout(function(){n.classes.add("in"),n.fire("open")},0),n._super(),n.statusbar&&n.statusbar.postRender(),n.focus(),this.dragHelper=new ct(n._id+"-dragh",{start:function(){t={x:n.layoutRect().x,y:n.layoutRect().y}},drag:function(e){n.moveTo(t.x+e.deltaX,t.y+e.deltaY)}}),n.on("submit",function(e){e.isDefaultPrevented()||n.close()}),At.push(n),Lt(!0)},submit:function(){return this.fire("submit",{data:this.toJSON()})},remove:function(){var e,t=this;for(t.dragHelper.destroy(),t._super(),t.statusbar&&this.statusbar.remove(),zt(t.classPrefix,!1),e=At.length;e--;)At[e]===t&&At.splice(e,1);Lt(0'+this._super(e)}}),jt=Nt.extend({Defaults:{classes:"widget btn",role:"button"},init:function(e){var t,n=this;n._super(e),e=n.settings,t=n.settings.size,n.on("click mousedown",function(e){e.preventDefault()}),n.on("touchstart",function(e){n.fire("click",e),e.preventDefault()}),e.subtype&&n.classes.add(e.subtype),t&&n.classes.add("btn-"+t),e.icon&&n.icon(e.icon)},icon:function(e){return arguments.length?(this.state.set("icon",e),this):this.state.get("icon")},repaint:function(){var e,t=this.getEl().firstChild;t&&((e=t.style).width=e.height="100%"),this._super()},renderHtml:function(){var e,t,n=this,i=n._id,r=n.classPrefix,o=n.state.get("icon"),s=n.state.get("text"),a="",l=n.settings;return(e=l.image)?(o="none","string"!=typeof e&&(e=_.window.getSelection?e[0]:e[1]),e=" style=\"background-image: url('"+e+"')\""):e="",s&&(n.classes.add("btn-has-text"),a=''+n.encode(s)+""),o=o?r+"ico "+r+"i-"+o:"",t="boolean"==typeof l.active?' aria-pressed="'+l.active+'"':"",'
      "},bindStates:function(){var o=this,n=o.$,i=o.classPrefix+"txt";function s(e){var t=n("span."+i,o.getEl());e?(t[0]||(n("button:first",o.getEl()).append(''),t=n("span."+i,o.getEl())),t.html(o.encode(e))):t.remove(),o.classes.toggle("btn-has-text",!!e)}return o.state.on("change:text",function(e){s(e.value)}),o.state.on("change:icon",function(e){var t=e.value,n=o.classPrefix;t=(o.settings.icon=t)?n+"ico "+n+"i-"+o.settings.icon:"";var i=o.getEl().firstChild,r=i.getElementsByTagName("i")[0];t?(r&&r===i.firstChild||(r=_.document.createElement("i"),i.insertBefore(r,i.firstChild)),r.className=t):r&&i.removeChild(r),s(o.state.get("text"))}),o._super()}}),Jt=jt.extend({init:function(e){e=w.extend({text:"Browse...",multiple:!1,accept:null},e),this._super(e),this.classes.add("browsebutton"),e.multiple&&this.classes.add("multiple")},postRender:function(){var n=this,t=we.create("input",{type:"file",id:n._id+"-browse",accept:n.settings.accept});n._super(),ye(t).on("change",function(e){var t=e.target.files;n.value=function(){return t.length?n.settings.multiple?t:t[0]:null},e.preventDefault(),t.length&&n.fire("change",e)}),ye(t).on("click",function(e){e.stopPropagation()}),ye(n.getEl("button")).on("click touchstart",function(e){e.stopPropagation(),t.click(),e.preventDefault()}),n.getEl().appendChild(t)},remove:function(){ye(this.getEl("button")).off(),ye(this.getEl("input")).off(),this._super()}}),Gt=lt.extend({Defaults:{defaultType:"button",role:"group"},renderHtml:function(){var e=this,t=e._layout;return e.classes.add("btn-group"),e.preRender(),t.preRender(e),'
      '+(e.settings.html||"")+t.renderHtml(e)+"
      "}}),Kt=Nt.extend({Defaults:{classes:"checkbox",role:"checkbox",checked:!1},init:function(e){var t=this;t._super(e),t.on("click mousedown",function(e){e.preventDefault()}),t.on("click",function(e){e.preventDefault(),t.disabled()||t.checked(!t.checked())}),t.checked(t.settings.checked)},checked:function(e){return arguments.length?(this.state.set("checked",e),this):this.state.get("checked")},value:function(e){return arguments.length?this.checked(e):this.checked()},renderHtml:function(){var e=this,t=e._id,n=e.classPrefix;return'
      '+e.encode(e.state.get("text"))+"
      "},bindStates:function(){var o=this;function t(e){o.classes.toggle("checked",e),o.aria("checked",e)}return o.state.on("change:text",function(e){o.getEl("al").firstChild.data=o.translate(e.value)}),o.state.on("change:checked change:value",function(e){o.fire("change"),t(e.value)}),o.state.on("change:icon",function(e){var t=e.value,n=o.classPrefix;if(void 0===t)return o.settings.icon;t=(o.settings.icon=t)?n+"ico "+n+"i-"+o.settings.icon:"";var i=o.getEl().firstChild,r=i.getElementsByTagName("i")[0];t?(r&&r===i.firstChild||(r=_.document.createElement("i"),i.insertBefore(r,i.firstChild)),r.className=t):r&&i.removeChild(r)}),o.state.get("checked")&&t(!0),o._super()}}),Zt=tinymce.util.Tools.resolve("tinymce.util.VK"),Qt=Nt.extend({init:function(i){var r=this;r._super(i),i=r.settings,r.classes.add("combobox"),r.subinput=!0,r.ariaTarget="inp",i.menu=i.menu||i.values,i.menu&&(i.icon="caret"),r.on("click",function(e){var t=e.target,n=r.getEl();if(ye.contains(n,t)||t===n)for(;t&&t!==n;)t.id&&-1!==t.id.indexOf("-open")&&(r.fire("action"),i.menu&&(r.showMenu(),e.aria&&r.menu.items()[0].focus())),t=t.parentNode}),r.on("keydown",function(e){var t;13===e.keyCode&&"INPUT"===e.target.nodeName&&(e.preventDefault(),r.parents().reverse().each(function(e){if(e.toJSON)return t=e,!1}),r.fire("submit",{data:t.toJSON()}))}),r.on("keyup",function(e){if("INPUT"===e.target.nodeName){var t=r.state.get("value"),n=e.target.value;n!==t&&(r.state.set("value",n),r.fire("autocomplete",e))}}),r.on("mouseover",function(e){var t=r.tooltip().moveTo(-65535);if(r.statusLevel()&&-1!==e.target.className.indexOf(r.classPrefix+"status")){var n=r.statusMessage()||"Ok",i=t.text(n).show().testMoveRel(e.target,["bc-tc","bc-tl","bc-tr"]);t.classes.toggle("tooltip-n","bc-tc"===i),t.classes.toggle("tooltip-nw","bc-tl"===i),t.classes.toggle("tooltip-ne","bc-tr"===i),t.moveRel(e.target,i)}})},statusLevel:function(e){return 0
      "),'
      '},postRender:function(){var t=this,n=t.settings.onclick;return t.on("click",function(e){e.aria&&"down"===e.aria.key||e.control!==t||nn.getParent(e.target,"."+t.classPrefix+"open")||(e.stopImmediatePropagation(),n.call(t,e))}),delete t.settings.onclick,t._super()}}),on=tinymce.util.Tools.resolve("tinymce.util.Color"),sn=Nt.extend({Defaults:{classes:"widget colorpicker"},init:function(e){this._super(e)},postRender:function(){var n,i,r,o,s,a=this,l=a.color();function u(e,t){var n,i,r=we.getPos(e);return n=t.pageX-r.x,i=t.pageY-r.y,{x:n=Math.max(0,Math.min(n/e.clientWidth,1)),y:i=Math.max(0,Math.min(i/e.clientHeight,1))}}function c(e,t){var n=(360-e.h)/360;we.css(r,{top:100*n+"%"}),t||we.css(s,{left:e.s+"%",top:100-e.v+"%"}),o.style.background=on({s:100,v:100,h:e.h}).toHex(),a.color().parse({s:e.s,v:e.v,h:e.h})}function e(e){var t;t=u(o,e),n.s=100*t.x,n.v=100*(1-t.y),c(n),a.fire("change")}function t(e){var t;t=u(i,e),(n=l.toHsv()).h=360*(1-t.y),c(n,!0),a.fire("change")}i=a.getEl("h"),r=a.getEl("hp"),o=a.getEl("sv"),s=a.getEl("svp"),a._repaint=function(){c(n=l.toHsv())},a._super(),a._svdraghelper=new ct(a._id+"-sv",{start:e,drag:e}),a._hdraghelper=new ct(a._id+"-h",{start:t,drag:t}),a._repaint()},rgb:function(){return this.color().toRgb()},value:function(e){if(!arguments.length)return this.color().toHex();this.color().parse(e),this._rendered&&this._repaint()},color:function(){return this._color||(this._color=on()),this._color},renderHtml:function(){var e,t=this._id,o=this.classPrefix,s="#ff0000,#ff0080,#ff00ff,#8000ff,#0000ff,#0080ff,#00ffff,#00ff80,#00ff00,#80ff00,#ffff00,#ff8000,#ff0000";return e='
      '+function(){var e,t,n,i,r="";for(n="filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=",e=0,t=(i=s.split(",")).length-1;e
      ';return r}()+'
      ','
      '+e+"
      "}}),an=Nt.extend({init:function(e){e=w.extend({height:100,text:"Drop an image here",multiple:!1,accept:null},e),this._super(e),this.classes.add("dropzone"),e.multiple&&this.classes.add("multiple")},renderHtml:function(){var e,t,n=this.settings;return e={id:this._id,hidefocus:"1"},t=we.create("div",e,""+this.translate(n.text)+""),n.height&&we.css(t,"height",n.height+"px"),n.width&&we.css(t,"width",n.width+"px"),t.className=this.classes,t.outerHTML},postRender:function(){var i=this,e=function(e){e.preventDefault(),i.classes.toggle("dragenter"),i.getEl().className=i.classes};i._super(),i.$el.on("dragover",function(e){e.preventDefault()}),i.$el.on("dragenter",e),i.$el.on("dragleave",e),i.$el.on("drop",function(e){if(e.preventDefault(),!i.state.get("disabled")){var t=function(e){var t=i.settings.accept;if("string"!=typeof t)return e;var n=new RegExp("("+t.split(/\s*,\s*/).join("|")+")$","i");return w.grep(e,function(e){return n.test(e.name)})}(e.dataTransfer.files);i.value=function(){return t.length?i.settings.multiple?t:t[0]:null},t.length&&i.fire("change",e)}})},remove:function(){this.$el.off(),this._super()}}),ln=Nt.extend({init:function(e){var n=this;e.delimiter||(e.delimiter="\xbb"),n._super(e),n.classes.add("path"),n.canFocus=!0,n.on("click",function(e){var t;(t=e.target.getAttribute("data-index"))&&n.fire("select",{value:n.row()[t],index:t})}),n.row(n.settings.row)},focus:function(){return this.getEl().firstChild.focus(),this},row:function(e){return arguments.length?(this.state.set("row",e),this):this.state.get("row")},renderHtml:function(){return'
      '+this._getDataPathHtml(this.state.get("row"))+"
      "},bindStates:function(){var t=this;return t.state.on("change:row",function(e){t.innerHtml(t._getDataPathHtml(e.value))}),t._super()},_getDataPathHtml:function(e){var t,n,i=e||[],r="",o=this.classPrefix;for(t=0,n=i.length;t