home/beautybuzzbeyond/public_html/wp-admin/js/common.js 0000604 00000171453 14717742531 0017403 0 ustar 00 /** * @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 }); }, /** * 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 + '