initial
This commit is contained in:
commit
9883323161
17470 files changed
+4470592
No files matched your search
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Accordion-folding functionality.
|
||||
*
|
||||
* Markup with the appropriate classes will be automatically hidden,
|
||||
* with one section opening at a time when its title is clicked.
|
||||
* Use the following markup structure for accordion behavior:
|
||||
*
|
||||
* <div class="accordion-container">
|
||||
* <div class="accordion-section open">
|
||||
* <h3 class="accordion-section-title"><button type="button" aria-expanded="true" aria-controls="target-1"></button></h3>
|
||||
* <div class="accordion-section-content" id="target">
|
||||
* </div>
|
||||
* </div>
|
||||
* <div class="accordion-section">
|
||||
* <h3 class="accordion-section-title"><button type="button" aria-expanded="false" aria-controls="target-2"></button></h3>
|
||||
* <div class="accordion-section-content" id="target-2">
|
||||
* </div>
|
||||
* </div>
|
||||
* <div class="accordion-section">
|
||||
* <h3 class="accordion-section-title"><button type="button" aria-expanded="false" aria-controls="target-3"></button></h3>
|
||||
* <div class="accordion-section-content" id="target-3">
|
||||
* </div>
|
||||
* </div>
|
||||
* </div>
|
||||
*
|
||||
* Note that any appropriate tags may be used, as long as the above classes are present.
|
||||
*
|
||||
* @since 3.6.0
|
||||
* @output wp-admin/js/accordion.js
|
||||
*/
|
||||
|
||||
( function( $ ){
|
||||
|
||||
$( function () {
|
||||
|
||||
// Expand/Collapse accordion sections on click.
|
||||
$( '.accordion-container' ).on( 'click', '.accordion-section-title button', function() {
|
||||
accordionSwitch( $( this ) );
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Close the current accordion section and open a new one.
|
||||
*
|
||||
* @param {Object} el Title element of the accordion section to toggle.
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function accordionSwitch ( el ) {
|
||||
var section = el.closest( '.accordion-section' ),
|
||||
container = section.closest( '.accordion-container' ),
|
||||
siblings = container.find( '.open' ),
|
||||
siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(),
|
||||
content = section.find( '.accordion-section-content' );
|
||||
|
||||
// This section has no content and cannot be expanded.
|
||||
if ( section.hasClass( 'cannot-expand' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a class to the container to let us know something is happening inside.
|
||||
// This helps in cases such as hiding a scrollbar while animations are executing.
|
||||
container.addClass( 'opening' );
|
||||
|
||||
if ( section.hasClass( 'open' ) ) {
|
||||
section.toggleClass( 'open' );
|
||||
content.toggle( true ).slideToggle( 150 );
|
||||
} else {
|
||||
siblingsToggleControl.attr( 'aria-expanded', 'false' );
|
||||
siblings.removeClass( 'open' );
|
||||
siblings.find( '.accordion-section-content' ).show().slideUp( 150 );
|
||||
content.toggle( false ).slideToggle( 150 );
|
||||
section.toggleClass( 'open' );
|
||||
}
|
||||
|
||||
// We have to wait for the animations to finish.
|
||||
setTimeout(function(){
|
||||
container.removeClass( 'opening' );
|
||||
}, 150);
|
||||
|
||||
// If there's an element with an aria-expanded attribute, assume it's a toggle control and toggle the aria-expanded value.
|
||||
if ( el ) {
|
||||
el.attr( 'aria-expanded', String( el.attr( 'aria-expanded' ) === 'false' ) );
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(s){s(function(){s(".accordion-container").on("click",".accordion-section-title button",function(){var n,o,e,a,t,i;n=s(this),o=n.closest(".accordion-section"),e=o.closest(".accordion-container"),a=e.find(".open"),t=a.find("[aria-expanded]").first(),i=o.find(".accordion-section-content"),o.hasClass("cannot-expand")||(e.addClass("opening"),o.hasClass("open")?(o.toggleClass("open"),i.toggle(!0).slideToggle(150)):(t.attr("aria-expanded","false"),a.removeClass("open"),a.find(".accordion-section-content").show().slideUp(150),i.toggle(!1).slideToggle(150),o.toggleClass("open")),setTimeout(function(){e.removeClass("opening")},150),n&&n.attr("aria-expanded",String("false"===n.attr("aria-expanded"))))})})}(jQuery);
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* @output wp-admin/js/application-passwords.js
|
||||
*/
|
||||
|
||||
( function( $ ) {
|
||||
var $appPassSection = $( '#application-passwords-section' ),
|
||||
$newAppPassForm = $appPassSection.find( '.create-application-password' ),
|
||||
$newAppPassField = $newAppPassForm.find( '.input' ),
|
||||
$newAppPassButton = $newAppPassForm.find( '.button' ),
|
||||
$appPassTwrapper = $appPassSection.find( '.application-passwords-list-table-wrapper' ),
|
||||
$appPassTbody = $appPassSection.find( 'tbody' ),
|
||||
$appPassTrNoItems = $appPassTbody.find( '.no-items' ),
|
||||
$removeAllBtn = $( '#revoke-all-application-passwords' ),
|
||||
tmplNewAppPass = wp.template( 'new-application-password' ),
|
||||
tmplAppPassRow = wp.template( 'application-password-row' ),
|
||||
userId = $( '#user_id' ).val();
|
||||
|
||||
$newAppPassButton.on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( $newAppPassButton.prop( 'aria-disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var name = $newAppPassField.val();
|
||||
|
||||
if ( 0 === name.length ) {
|
||||
$newAppPassField.trigger( 'focus' );
|
||||
return;
|
||||
}
|
||||
|
||||
clearNotices();
|
||||
$newAppPassButton.prop( 'aria-disabled', true ).addClass( 'disabled' );
|
||||
|
||||
var request = {
|
||||
name: name
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters the request data used to create a new Application Password.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param {Object} request The request data.
|
||||
* @param {number} userId The id of the user the password is added for.
|
||||
*/
|
||||
request = wp.hooks.applyFilters( 'wp_application_passwords_new_password_request', request, userId );
|
||||
|
||||
wp.apiRequest( {
|
||||
path: '/wp/v2/users/' + userId + '/application-passwords?_locale=user',
|
||||
method: 'POST',
|
||||
data: request
|
||||
} ).always( function() {
|
||||
$newAppPassButton.removeProp( 'aria-disabled' ).removeClass( 'disabled' );
|
||||
} ).done( function( response ) {
|
||||
$newAppPassField.val( '' );
|
||||
$newAppPassButton.prop( 'disabled', false );
|
||||
|
||||
$newAppPassForm.after( tmplNewAppPass( {
|
||||
name: response.name,
|
||||
password: response.password
|
||||
} ) );
|
||||
$( '.new-application-password-notice' ).attr( 'tabindex', '-1' ).trigger( 'focus' );
|
||||
|
||||
$appPassTbody.prepend( tmplAppPassRow( response ) );
|
||||
|
||||
$appPassTwrapper.show();
|
||||
$appPassTrNoItems.remove();
|
||||
|
||||
/**
|
||||
* Fires after an application password has been successfully created.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param {Object} response The response data from the REST API.
|
||||
* @param {Object} request The request data used to create the password.
|
||||
*/
|
||||
wp.hooks.doAction( 'wp_application_passwords_created_password', response, request );
|
||||
} ).fail( handleErrorResponse );
|
||||
} );
|
||||
|
||||
$appPassTbody.on( 'click', '.delete', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( ! window.confirm( wp.i18n.__( 'Are you sure you want to revoke this password? This action cannot be undone.' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $submitButton = $( this ),
|
||||
$tr = $submitButton.closest( 'tr' ),
|
||||
uuid = $tr.data( 'uuid' );
|
||||
|
||||
clearNotices();
|
||||
$submitButton.prop( 'disabled', true );
|
||||
|
||||
wp.apiRequest( {
|
||||
path: '/wp/v2/users/' + userId + '/application-passwords/' + uuid + '?_locale=user',
|
||||
method: 'DELETE'
|
||||
} ).always( function() {
|
||||
$submitButton.prop( 'disabled', false );
|
||||
} ).done( function( response ) {
|
||||
if ( response.deleted ) {
|
||||
if ( 0 === $tr.siblings().length ) {
|
||||
$appPassTwrapper.hide();
|
||||
}
|
||||
$tr.remove();
|
||||
|
||||
addNotice( wp.i18n.__( 'Application password revoked.' ), 'success' ).trigger( 'focus' );
|
||||
}
|
||||
} ).fail( handleErrorResponse );
|
||||
} );
|
||||
|
||||
$removeAllBtn.on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( ! window.confirm( wp.i18n.__( 'Are you sure you want to revoke all passwords? This action cannot be undone.' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $submitButton = $( this );
|
||||
|
||||
clearNotices();
|
||||
$submitButton.prop( 'disabled', true );
|
||||
|
||||
wp.apiRequest( {
|
||||
path: '/wp/v2/users/' + userId + '/application-passwords?_locale=user',
|
||||
method: 'DELETE'
|
||||
} ).always( function() {
|
||||
$submitButton.prop( 'disabled', false );
|
||||
} ).done( function( response ) {
|
||||
if ( response.deleted ) {
|
||||
$appPassTbody.children().remove();
|
||||
$appPassSection.children( '.new-application-password' ).remove();
|
||||
$appPassTwrapper.hide();
|
||||
|
||||
addNotice( wp.i18n.__( 'All application passwords revoked.' ), 'success' ).trigger( 'focus' );
|
||||
}
|
||||
} ).fail( handleErrorResponse );
|
||||
} );
|
||||
|
||||
$appPassSection.on( 'click', '.notice-dismiss', function( e ) {
|
||||
e.preventDefault();
|
||||
var $el = $( this ).parent();
|
||||
$el.removeAttr( 'role' );
|
||||
$el.fadeTo( 100, 0, function () {
|
||||
$el.slideUp( 100, function () {
|
||||
$el.remove();
|
||||
$newAppPassField.trigger( 'focus' );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
$newAppPassField.on( 'keypress', function ( e ) {
|
||||
if ( 13 === e.which ) {
|
||||
e.preventDefault();
|
||||
$newAppPassButton.trigger( 'click' );
|
||||
}
|
||||
} );
|
||||
|
||||
// If there are no items, don't display the table yet. If there are, show it.
|
||||
if ( 0 === $appPassTbody.children( 'tr' ).not( $appPassTrNoItems ).length ) {
|
||||
$appPassTwrapper.hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an error response from the REST API.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param {jqXHR} xhr The XHR object from the ajax call.
|
||||
* @param {string} textStatus The string categorizing the ajax request's status.
|
||||
* @param {string} errorThrown The HTTP status error text.
|
||||
*/
|
||||
function handleErrorResponse( xhr, textStatus, errorThrown ) {
|
||||
var errorMessage = errorThrown;
|
||||
|
||||
if ( xhr.responseJSON && xhr.responseJSON.message ) {
|
||||
errorMessage = xhr.responseJSON.message;
|
||||
}
|
||||
|
||||
addNotice( errorMessage, 'error' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a message in the Application Passwords section.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param {string} message The message to display.
|
||||
* @param {string} type The notice type. Either 'success' or 'error'.
|
||||
* @returns {jQuery} The notice element.
|
||||
*/
|
||||
function addNotice( message, type ) {
|
||||
var $notice = $( '<div></div>' )
|
||||
.attr( 'role', 'alert' )
|
||||
.attr( 'tabindex', '-1' )
|
||||
.addClass( 'is-dismissible notice notice-' + type )
|
||||
.append( $( '<p></p>' ).text( message ) )
|
||||
.append(
|
||||
$( '<button></button>' )
|
||||
.attr( 'type', 'button' )
|
||||
.addClass( 'notice-dismiss' )
|
||||
.append( $( '<span></span>' ).addClass( 'screen-reader-text' ).text( wp.i18n.__( 'Dismiss this notice.' ) ) )
|
||||
);
|
||||
|
||||
$newAppPassForm.after( $notice );
|
||||
|
||||
return $notice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears notice messages from the Application Passwords section.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*/
|
||||
function clearNotices() {
|
||||
$( '.notice', $appPassSection ).remove();
|
||||
}
|
||||
}( jQuery ) );
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(o){var a=o("#application-passwords-section"),i=a.find(".create-application-password"),t=i.find(".input"),n=i.find(".button"),p=a.find(".application-passwords-list-table-wrapper"),r=a.find("tbody"),d=r.find(".no-items"),e=o("#revoke-all-application-passwords"),l=wp.template("new-application-password"),c=wp.template("application-password-row"),u=o("#user_id").val();function w(e,s,a){f(a=e.responseJSON&&e.responseJSON.message?e.responseJSON.message:a,"error")}function f(e,s){s=o("<div></div>").attr("role","alert").attr("tabindex","-1").addClass("is-dismissible notice notice-"+s).append(o("<p></p>").text(e)).append(o("<button></button>").attr("type","button").addClass("notice-dismiss").append(o("<span></span>").addClass("screen-reader-text").text(wp.i18n.__("Dismiss this notice."))));return i.after(s),s}function v(){o(".notice",a).remove()}n.on("click",function(e){var s;e.preventDefault(),n.prop("aria-disabled")||(0===(e=t.val()).length?t.trigger("focus"):(v(),n.prop("aria-disabled",!0).addClass("disabled"),s={name:e},s=wp.hooks.applyFilters("wp_application_passwords_new_password_request",s,u),wp.apiRequest({path:"/wp/v2/users/"+u+"/application-passwords?_locale=user",method:"POST",data:s}).always(function(){n.removeProp("aria-disabled").removeClass("disabled")}).done(function(e){t.val(""),n.prop("disabled",!1),i.after(l({name:e.name,password:e.password})),o(".new-application-password-notice").attr("tabindex","-1").trigger("focus"),r.prepend(c(e)),p.show(),d.remove(),wp.hooks.doAction("wp_application_passwords_created_password",e,s)}).fail(w)))}),r.on("click",".delete",function(e){var s,a;e.preventDefault(),window.confirm(wp.i18n.__("Are you sure you want to revoke this password? This action cannot be undone."))&&(s=o(this),e=(a=s.closest("tr")).data("uuid"),v(),s.prop("disabled",!0),wp.apiRequest({path:"/wp/v2/users/"+u+"/application-passwords/"+e+"?_locale=user",method:"DELETE"}).always(function(){s.prop("disabled",!1)}).done(function(e){e.deleted&&(0===a.siblings().length&&p.hide(),a.remove(),f(wp.i18n.__("Application password revoked."),"success").trigger("focus"))}).fail(w))}),e.on("click",function(e){var s;e.preventDefault(),window.confirm(wp.i18n.__("Are you sure you want to revoke all passwords? This action cannot be undone."))&&(s=o(this),v(),s.prop("disabled",!0),wp.apiRequest({path:"/wp/v2/users/"+u+"/application-passwords?_locale=user",method:"DELETE"}).always(function(){s.prop("disabled",!1)}).done(function(e){e.deleted&&(r.children().remove(),a.children(".new-application-password").remove(),p.hide(),f(wp.i18n.__("All application passwords revoked."),"success").trigger("focus"))}).fail(w))}),a.on("click",".notice-dismiss",function(e){e.preventDefault();var s=o(this).parent();s.removeAttr("role"),s.fadeTo(100,0,function(){s.slideUp(100,function(){s.remove(),t.trigger("focus")})})}),t.on("keypress",function(e){13===e.which&&(e.preventDefault(),n.trigger("click"))}),0===r.children("tr").not(d).length&&p.hide()}(jQuery);
|
||||
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @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. */
|
||||
'<label for="new-application-password-value">' + wp.i18n.__( 'Your new password for %s is:' ) + '</label>',
|
||||
'<strong></strong>'
|
||||
) + ' <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="" />';
|
||||
$notice = $( '<div></div>' )
|
||||
.attr( 'role', 'alert' )
|
||||
.attr( 'tabindex', -1 )
|
||||
.addClass( 'notice notice-success notice-alt' )
|
||||
.append( $( '<p></p>' ).addClass( 'application-password-display' ).html( message ) )
|
||||
.append( '<p>' + wp.i18n.__( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ) + '</p>' );
|
||||
|
||||
// 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 = $( '<div></div>' )
|
||||
.attr( 'role', 'alert' )
|
||||
.addClass( 'notice notice-error' )
|
||||
.append( $( '<p></p>' ).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 ) );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(t,s){var p=t("#app_name"),r=t("#approve"),e=t("#reject"),n=p.closest("form"),i={userLogin:s.user_login,successUrl:s.success,rejectUrl:s.reject};r.on("click",function(e){var a=p.val(),o=t('input[name="app_id"]',n).val();e.preventDefault(),r.prop("aria-disabled")||(0===a.length?p.trigger("focus"):(r.prop("aria-disabled",!0).addClass("disabled"),e={name:a},0<o.length&&(e.app_id=o),e=wp.hooks.applyFilters("wp_application_passwords_approve_app_request",e,i),wp.apiRequest({path:"/wp/v2/users/me/application-passwords?_locale=user",method:"POST",data:e}).done(function(e,a,o){wp.hooks.doAction("wp_application_passwords_approve_app_request_success",e,a,o);var a=s.success;a?(o=a+(-1===a.indexOf("?")?"?":"&")+"site_url="+encodeURIComponent(s.site_url)+"&user_login="+encodeURIComponent(s.user_login)+"&password="+encodeURIComponent(e.password),window.location=o):(a=wp.i18n.sprintf('<label for="new-application-password-value">'+wp.i18n.__("Your new password for %s is:")+"</label>","<strong></strong>")+' <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="" />',o=t("<div></div>").attr("role","alert").attr("tabindex",-1).addClass("notice notice-success notice-alt").append(t("<p></p>").addClass("application-password-display").html(a)).append("<p>"+wp.i18n.__("Be sure to save this in a safe location. You will not be able to retrieve it.")+"</p>"),t("strong",o).text(e.name),t("input",o).val(e.password),n.replaceWith(o),o.trigger("focus"))}).fail(function(e,a,o){var s=o,p=null,s=(e.responseJSON&&(p=e.responseJSON).message&&(s=p.message),t("<div></div>").attr("role","alert").addClass("notice notice-error").append(t("<p></p>").text(s)));t("h1").after(s),r.removeProp("aria-disabled",!1).removeClass("disabled"),wp.hooks.doAction("wp_application_passwords_approve_app_request_error",p,a,o,e)})))}),e.on("click",function(e){e.preventDefault(),wp.hooks.doAction("wp_application_passwords_reject_app",i),window.location=s.reject}),n.on("submit",function(e){e.preventDefault()})}(jQuery,authApp);
|
||||
@@ -0,0 +1,512 @@
|
||||
/**
|
||||
* @output wp-admin/js/code-editor.js
|
||||
*/
|
||||
|
||||
/* global console */
|
||||
|
||||
/* eslint-env es2020 */
|
||||
|
||||
if ( 'undefined' === typeof window.wp ) {
|
||||
/**
|
||||
* @namespace wp
|
||||
*/
|
||||
window.wp = {};
|
||||
}
|
||||
if ( 'undefined' === typeof window.wp.codeEditor ) {
|
||||
/**
|
||||
* @namespace wp.codeEditor
|
||||
*/
|
||||
window.wp.codeEditor = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} CodeMirrorState
|
||||
* @property {boolean} [completionActive] - Whether completion is active.
|
||||
* @property {boolean} [focused] - Whether the editor is focused.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('codemirror').EditorFromTextArea & {
|
||||
* options: import('codemirror').EditorConfiguration,
|
||||
* performLint?: () => void,
|
||||
* showHint?: (options: import('codemirror').ShowHintOptions) => void,
|
||||
* state: CodeMirrorState
|
||||
* }} CodeMirrorEditor
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} LintAnnotation
|
||||
* @property {string} message - Message.
|
||||
* @property {'error'|'warning'} severity - Severity.
|
||||
* @property {import('codemirror').Position} from - From position.
|
||||
* @property {import('codemirror').Position} to - To position.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} CodeMirrorTokenState
|
||||
* @property {object} [htmlState] - HTML state.
|
||||
* @property {string} [htmlState.tagName] - Tag name.
|
||||
* @property {CodeMirrorTokenState} [curState] - Current state.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('codemirror').EditorConfiguration & {
|
||||
* lint?: boolean | CombinedLintOptions,
|
||||
* autoCloseBrackets?: boolean,
|
||||
* matchBrackets?: boolean,
|
||||
* continueComments?: boolean,
|
||||
* styleActiveLine?: boolean
|
||||
* }} CodeMirrorSettings
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} CSSLintRules
|
||||
* @property {boolean} [errors] - Errors.
|
||||
* @property {boolean} [box-model] - Box model rules.
|
||||
* @property {boolean} [display-property-grouping] - Display property grouping rules.
|
||||
* @property {boolean} [duplicate-properties] - Duplicate properties rules.
|
||||
* @property {boolean} [known-properties] - Known properties rules.
|
||||
* @property {boolean} [outline-none] - Outline none rules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} JSHintRules
|
||||
* @property {number} [esversion] - ECMAScript version.
|
||||
* @property {boolean} [module] - Whether to use modules.
|
||||
* @property {boolean} [boss] - Whether to allow assignments in control expressions.
|
||||
* @property {boolean} [curly] - Whether to require curly braces.
|
||||
* @property {boolean} [eqeqeq] - Whether to require === and !==.
|
||||
* @property {boolean} [eqnull] - Whether to allow == null.
|
||||
* @property {boolean} [expr] - Whether to allow expressions.
|
||||
* @property {boolean} [immed] - Whether to require immediate function invocation.
|
||||
* @property {boolean} [noarg] - Whether to prohibit arguments.caller/callee.
|
||||
* @property {boolean} [nonbsp] - Whether to prohibit non-breaking spaces.
|
||||
* @property {string} [quotmark] - Quote mark preference.
|
||||
* @property {boolean} [undef] - Whether to prohibit undefined variables.
|
||||
* @property {boolean} [unused] - Whether to prohibit unused variables.
|
||||
* @property {boolean} [browser] - Whether to enable browser globals.
|
||||
* @property {Record<string, boolean>} [globals] - Global variables.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} HTMLHintRules
|
||||
* @property {boolean} [tagname-lowercase] - Tag name lowercase rules.
|
||||
* @property {boolean} [attr-lowercase] - Attribute lowercase rules.
|
||||
* @property {boolean} [attr-value-double-quotes] - Attribute value double quotes rules.
|
||||
* @property {boolean} [doctype-first] - Doctype first rules.
|
||||
* @property {boolean} [tag-pair] - Tag pair rules.
|
||||
* @property {boolean} [spec-char-escape] - Spec char escape rules.
|
||||
* @property {boolean} [id-unique] - ID unique rules.
|
||||
* @property {boolean} [src-not-empty] - Src not empty rules.
|
||||
* @property {boolean} [attr-no-duplication] - Attribute no duplication rules.
|
||||
* @property {boolean} [alt-require] - Alt require rules.
|
||||
* @property {string} [space-tab-mixed-disabled] - Space tab mixed disabled rules.
|
||||
* @property {boolean} [attr-unsafe-chars] - Attribute unsafe chars rules.
|
||||
* @property {JSHintRules} [jshint] - JSHint rules.
|
||||
* @property {CSSLintRules} [csslint] - CSSLint rules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Settings for the code editor.
|
||||
*
|
||||
* @typedef {object} CodeEditorSettings
|
||||
*
|
||||
* @property {CodeMirrorSettings} [codemirror] - CodeMirror settings.
|
||||
* @property {CSSLintRules} [csslint] - CSSLint rules.
|
||||
* @property {JSHintRules} [jshint] - JSHint rules.
|
||||
* @property {HTMLHintRules} [htmlhint] - HTMLHint rules.
|
||||
*
|
||||
* @property {(codemirror: CodeMirrorEditor, event: KeyboardEvent|JQuery.KeyDownEvent) => void} [onTabNext] - Callback to handle tabbing to the next tabbable element.
|
||||
* @property {(codemirror: CodeMirrorEditor, event: KeyboardEvent|JQuery.KeyDownEvent) => void} [onTabPrevious] - Callback to handle tabbing to the previous tabbable element.
|
||||
* @property {(errorAnnotations: LintAnnotation[], annotations: LintAnnotation[], annotationsSorted: LintAnnotation[], cm: CodeMirrorEditor) => void} [onChangeLintingErrors] - Callback for when the linting errors have changed.
|
||||
* @property {(errorAnnotations: LintAnnotation[], editor: CodeMirrorEditor) => void} [onUpdateErrorNotice] - Callback for when error notice should be displayed.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('codemirror/addon/lint/lint').LintStateOptions<Record<string, unknown>> & JSHintRules & CSSLintRules & { rules?: HTMLHintRules }} CombinedLintOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} CodeEditorInstance
|
||||
* @property {CodeEditorSettings} settings - The code editor settings.
|
||||
* @property {CodeMirrorEditor} codemirror - The CodeMirror instance.
|
||||
* @property {() => void} updateErrorNotice - Force update the error notice.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} WpCodeEditor
|
||||
* @property {CodeEditorSettings} defaultSettings - Default settings.
|
||||
* @property {(textarea: string|JQuery|Element, settings?: CodeEditorSettings) => CodeEditorInstance} initialize - Initialize.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {JQueryStatic} $ - jQuery.
|
||||
* @param {Object & {
|
||||
* codeEditor: WpCodeEditor,
|
||||
* CodeMirror: typeof import('codemirror'),
|
||||
* }} wp - WordPress namespace.
|
||||
*/
|
||||
( function( $, wp ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Default settings for code editor.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @type {CodeEditorSettings}
|
||||
*/
|
||||
wp.codeEditor.defaultSettings = {
|
||||
codemirror: {},
|
||||
csslint: {},
|
||||
htmlhint: {},
|
||||
jshint: {},
|
||||
onTabNext: function() {},
|
||||
onTabPrevious: function() {},
|
||||
onChangeLintingErrors: function() {},
|
||||
onUpdateErrorNotice: function() {},
|
||||
};
|
||||
|
||||
/**
|
||||
* Configure linting.
|
||||
*
|
||||
* @param {CodeEditorSettings} settings - Code editor settings.
|
||||
*
|
||||
* @return {LintingController} Linting controller.
|
||||
*/
|
||||
function configureLinting( settings ) { // eslint-disable-line complexity
|
||||
/** @type {LintAnnotation[]} */
|
||||
let currentErrorAnnotations = [];
|
||||
|
||||
/** @type {LintAnnotation[]} */
|
||||
let previouslyShownErrorAnnotations = [];
|
||||
|
||||
/**
|
||||
* Call the onUpdateErrorNotice if there are new errors to show.
|
||||
*
|
||||
* @param {import('codemirror').Editor} editor - Editor.
|
||||
* @return {void}
|
||||
*/
|
||||
function updateErrorNotice( editor ) {
|
||||
if ( settings.onUpdateErrorNotice && ! _.isEqual( currentErrorAnnotations, previouslyShownErrorAnnotations ) ) {
|
||||
settings.onUpdateErrorNotice( currentErrorAnnotations, /** @type {CodeMirrorEditor} */ ( editor ) );
|
||||
previouslyShownErrorAnnotations = currentErrorAnnotations;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lint options.
|
||||
*
|
||||
* @return {CombinedLintOptions|false} Lint options.
|
||||
*/
|
||||
function getLintOptions() { // eslint-disable-line complexity
|
||||
/** @type {CombinedLintOptions | boolean} */
|
||||
let options = settings.codemirror?.lint ?? false;
|
||||
|
||||
if ( ! options ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( true === options ) {
|
||||
options = {};
|
||||
} else if ( _.isObject( options ) ) {
|
||||
options = $.extend( {}, options );
|
||||
}
|
||||
const linterOptions = /** @type {CombinedLintOptions} */ ( options );
|
||||
|
||||
// Configure JSHint.
|
||||
if ( 'javascript' === settings.codemirror?.mode && settings.jshint ) {
|
||||
$.extend( linterOptions, settings.jshint );
|
||||
}
|
||||
|
||||
// Configure CSSLint.
|
||||
if ( 'css' === settings.codemirror?.mode && settings.csslint ) {
|
||||
$.extend( linterOptions, settings.csslint );
|
||||
}
|
||||
|
||||
// Configure HTMLHint.
|
||||
if ( 'htmlmixed' === settings.codemirror?.mode && settings.htmlhint ) {
|
||||
linterOptions.rules = $.extend( {}, settings.htmlhint );
|
||||
|
||||
if ( settings.jshint && linterOptions.rules ) {
|
||||
linterOptions.rules.jshint = settings.jshint;
|
||||
}
|
||||
if ( settings.csslint && linterOptions.rules ) {
|
||||
linterOptions.rules.csslint = settings.csslint;
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap the onUpdateLinting CodeMirror event to route to onChangeLintingErrors and onUpdateErrorNotice.
|
||||
linterOptions.onUpdateLinting = (function( onUpdateLintingOverridden ) {
|
||||
/**
|
||||
* @param {LintAnnotation[]} annotations - Annotations.
|
||||
* @param {LintAnnotation[]} annotationsSorted - Sorted annotations.
|
||||
* @param {CodeMirrorEditor} cm - Editor.
|
||||
*/
|
||||
return function( annotations, annotationsSorted, cm ) {
|
||||
const errorAnnotations = annotations.filter( function( annotation ) {
|
||||
return 'error' === annotation.severity;
|
||||
} );
|
||||
|
||||
if ( onUpdateLintingOverridden ) {
|
||||
onUpdateLintingOverridden( 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 ( ! cm.state.focused || 0 === currentErrorAnnotations.length || previouslyShownErrorAnnotations.length > 0 ) {
|
||||
updateErrorNotice( cm );
|
||||
}
|
||||
};
|
||||
})( linterOptions.onUpdateLinting );
|
||||
|
||||
return linterOptions;
|
||||
}
|
||||
|
||||
return {
|
||||
getLintOptions,
|
||||
/**
|
||||
* @param {CodeMirrorEditor} editor - Editor instance.
|
||||
* @return {void}
|
||||
*/
|
||||
init: function( editor ) {
|
||||
// Keep lint options populated.
|
||||
editor.on( 'optionChange', function( _cm, option ) {
|
||||
const gutterName = 'CodeMirror-lint-markers';
|
||||
if ( 'lint' !== ( /** @type {string} */ ( option ) ) ) {
|
||||
return;
|
||||
}
|
||||
const gutters = ( /** @type {string[]} */ ( editor.getOption( 'gutters' ) ) ) || [];
|
||||
const 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 ) {
|
||||
editor.performLint();
|
||||
} else {
|
||||
currentErrorAnnotations = [];
|
||||
updateErrorNotice( editor );
|
||||
}
|
||||
} );
|
||||
|
||||
// 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() {
|
||||
const editorRefocusWait = 500;
|
||||
editor.on( 'blur', updateErrorNotice );
|
||||
|
||||
// Wait for editor to possibly get re-focused after selection.
|
||||
_.delay( function() {
|
||||
if ( ! editor.state.focused ) {
|
||||
updateErrorNotice( editor );
|
||||
}
|
||||
}, 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( /** @type {JQuery.MouseDownEvent} */ event ) {
|
||||
if (
|
||||
editor.state.focused &&
|
||||
! editor.getWrapperElement().contains( event.target ) &&
|
||||
! event.target.classList.contains( 'CodeMirror-hint' )
|
||||
) {
|
||||
updateErrorNotice( editor );
|
||||
}
|
||||
} );
|
||||
},
|
||||
/**
|
||||
* @param {CodeMirrorEditor} editor - Editor instance.
|
||||
* @return {void}
|
||||
*/
|
||||
updateErrorNotice,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure tabbing.
|
||||
*
|
||||
* @param {CodeMirrorEditor} codemirror - Editor.
|
||||
* @param {CodeEditorSettings} settings - Code editor settings.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function configureTabbing( codemirror, settings ) {
|
||||
const $textarea = $( codemirror.getTextArea() );
|
||||
|
||||
codemirror.on( 'blur', function() {
|
||||
$textarea.data( 'next-tab-blurs', false );
|
||||
});
|
||||
codemirror.on( 'keydown', function onKeydown( _editor, event ) {
|
||||
// Take note of the ESC keypress so that the next TAB can focus outside the editor.
|
||||
if ( 'Escape' === event.key ) {
|
||||
$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 ( 'Tab' !== event.key || ! $textarea.data( 'next-tab-blurs' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Focus on previous or next focusable item.
|
||||
if ( event.shiftKey && settings.onTabPrevious ) {
|
||||
settings.onTabPrevious( codemirror, event );
|
||||
} else if ( ! event.shiftKey && settings.onTabNext ) {
|
||||
settings.onTabNext( codemirror, event );
|
||||
}
|
||||
|
||||
// Reset tab state.
|
||||
$textarea.data( 'next-tab-blurs', false );
|
||||
|
||||
// Prevent tab character from being added.
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} LintingController
|
||||
* @property {() => CombinedLintOptions|false} getLintOptions - Get lint options.
|
||||
* @property {(editor: CodeMirrorEditor) => void} init - Initialize.
|
||||
* @property {(editor: import('codemirror').Editor) => void} updateErrorNotice - Update error notice.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialize Code Editor (CodeMirror) for an existing textarea.
|
||||
*
|
||||
* @since 4.9.0
|
||||
*
|
||||
* @param {string|JQuery<HTMLElement>|HTMLElement} textarea - The HTML id, jQuery object, or DOM Element for the textarea that is used for the editor.
|
||||
* @param {CodeEditorSettings} [settings] - Settings to override defaults.
|
||||
*
|
||||
* @return {CodeEditorInstance} Instance.
|
||||
*/
|
||||
wp.codeEditor.initialize = function initialize( textarea, settings ) {
|
||||
if ( document.readyState === 'loading' ) {
|
||||
console.warn( 'wp.codeEditor.initialize() ran too early. Invoke this function in a `DOMContentLoaded` event listener.' );
|
||||
}
|
||||
|
||||
let $textarea;
|
||||
if ( 'string' === typeof textarea ) {
|
||||
$textarea = $( '#' + textarea );
|
||||
} else {
|
||||
$textarea = $( textarea );
|
||||
}
|
||||
|
||||
/** @type {CodeEditorSettings} */
|
||||
const instanceSettings = $.extend( true, {}, wp.codeEditor.defaultSettings, settings );
|
||||
|
||||
const lintingController = configureLinting( instanceSettings );
|
||||
if ( instanceSettings.codemirror ) {
|
||||
instanceSettings.codemirror.lint = lintingController.getLintOptions();
|
||||
}
|
||||
|
||||
const codemirror = /** @type {CodeMirrorEditor} */ ( wp.CodeMirror.fromTextArea( $textarea[0], instanceSettings.codemirror ) );
|
||||
|
||||
lintingController.init( codemirror );
|
||||
|
||||
/** @type {CodeEditorInstance} */
|
||||
const instance = {
|
||||
settings: instanceSettings,
|
||||
codemirror,
|
||||
updateErrorNotice: function() {
|
||||
lintingController.updateErrorNotice( codemirror );
|
||||
},
|
||||
};
|
||||
|
||||
if ( codemirror.showHint ) {
|
||||
codemirror.on( 'inputRead', function( _editor, change ) {
|
||||
// Only trigger autocompletion for typed input or IME composition.
|
||||
if ( ! change.origin || ( '+input' !== change.origin && ! change.origin.startsWith( '*compose' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only trigger autocompletion for single-character inputs.
|
||||
// The text property is an array of strings, one for each line.
|
||||
// We check that there is only one line and that line has only one character.
|
||||
if ( 1 !== change.text.length || 1 !== change.text[0].length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char = change.text[0];
|
||||
const isAlphaKey = /^[a-zA-Z]$/.test( char );
|
||||
if ( codemirror.state.completionActive && isAlphaKey ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent autocompletion in string literals or comments.
|
||||
const token = /** @type {import('codemirror').Token & { state: CodeMirrorTokenState }} */ ( codemirror.getTokenAt( codemirror.getCursor() ) );
|
||||
if ( 'string' === token.type || 'comment' === token.type ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const innerMode = wp.CodeMirror.innerMode( codemirror.getMode(), token.state ).mode.name;
|
||||
const doc = codemirror.getDoc();
|
||||
const lineBeforeCursor = doc.getLine( doc.getCursor().line ).slice( 0, doc.getCursor().ch );
|
||||
let shouldAutocomplete = false;
|
||||
if ( 'html' === innerMode || 'xml' === innerMode ) {
|
||||
shouldAutocomplete = (
|
||||
'<' === char ||
|
||||
( '/' === char && 'tag' === token.type ) ||
|
||||
( isAlphaKey && 'tag' === token.type ) ||
|
||||
( isAlphaKey && 'attribute' === token.type ) ||
|
||||
( '=' === char && !! (
|
||||
token.state.htmlState?.tagName ||
|
||||
token.state.curState?.htmlState?.tagName
|
||||
) )
|
||||
);
|
||||
} else if ( 'css' === innerMode ) {
|
||||
shouldAutocomplete =
|
||||
isAlphaKey ||
|
||||
':' === char ||
|
||||
( ' ' === char && /:\s+$/.test( lineBeforeCursor ) );
|
||||
} else if ( 'javascript' === innerMode ) {
|
||||
shouldAutocomplete = isAlphaKey || '.' === char;
|
||||
} else if ( 'clike' === innerMode && 'php' === codemirror.options.mode ) {
|
||||
shouldAutocomplete = isAlphaKey && ( 'keyword' === token.type || 'variable' === token.type );
|
||||
}
|
||||
if ( shouldAutocomplete ) {
|
||||
codemirror.showHint( { completeSingle: false } );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
// Facilitate tabbing out of the editor.
|
||||
configureTabbing( codemirror, instanceSettings );
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
})( jQuery, window.wp );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
void 0===window.wp&&(window.wp={}),void 0===window.wp.codeEditor&&(window.wp.codeEditor={}),function(u,c){"use strict";function d(r){let s=[],a=[];function c(t){r.onUpdateErrorNotice&&!_.isEqual(s,a)&&(r.onUpdateErrorNotice(s,t),a=s)}function d(){let t=r.codemirror?.lint??!1;if(!t)return!1;!0===t?t={}:_.isObject(t)&&(t=u.extend({},t));var i,e=t;return"javascript"===r.codemirror?.mode&&r.jshint&&u.extend(e,r.jshint),"css"===r.codemirror?.mode&&r.csslint&&u.extend(e,r.csslint),"htmlmixed"===r.codemirror?.mode&&r.htmlhint&&(e.rules=u.extend({},r.htmlhint),r.jshint&&e.rules&&(e.rules.jshint=r.jshint),r.csslint)&&e.rules&&(e.rules.csslint=r.csslint),e.onUpdateLinting=(i=e.onUpdateLinting,function(t,e,n){var o=t.filter(function(t){return"error"===t.severity});i&&i(t,e,n),!_.isEqual(o,s)&&(s=o,r.onChangeLintingErrors&&r.onChangeLintingErrors(o,t,e,n),!n.state.focused||0===s.length||0<a.length)&&c(n)}),e}return{getLintOptions:d,init:function(i){i.on("optionChange",function(t,e){var n,o="CodeMirror-lint-markers";"lint"===e&&(e=i.getOption("gutters")||[],!0===(n=i.getOption("lint"))?(_.contains(e,o)||i.setOption("gutters",[o].concat(e)),i.setOption("lint",d())):n||i.setOption("gutters",_.without(e,o)),i.getOption("lint")&&i.performLint?i.performLint():(s=[],c(i)))}),i.on("blur",c),i.on("startCompletion",function(){i.off("blur",c)}),i.on("endCompletion",function(){i.on("blur",c),_.delay(function(){i.state.focused||c(i)},500)}),u(document.body).on("mousedown",function(t){!i.state.focused||i.getWrapperElement().contains(t.target)||t.target.classList.contains("CodeMirror-hint")||c(i)})},updateErrorNotice:c}}c.codeEditor.defaultSettings={codemirror:{},csslint:{},htmlhint:{},jshint:{},onTabNext:function(){},onTabPrevious:function(){},onChangeLintingErrors:function(){},onUpdateErrorNotice:function(){}},c.codeEditor.initialize=function(t,e){"loading"===document.readyState&&console.warn("wp.codeEditor.initialize() ran too early. Invoke this function in a `DOMContentLoaded` event listener.");let n;n=u("string"==typeof t?"#"+t:t);t=u.extend(!0,{},c.codeEditor.defaultSettings,e);const o=d(t),s=(t.codemirror&&(t.codemirror.lint=o.getLintOptions()),c.CodeMirror.fromTextArea(n[0],t.codemirror));o.init(s);e={settings:t,codemirror:s,updateErrorNotice:function(){o.updateErrorNotice(s)}};s.showHint&&s.on("inputRead",function(t,e){if(e.origin&&("+input"===e.origin||e.origin.startsWith("*compose"))&&1===e.text.length&&1===e.text[0].length){var e=e.text[0],n=/^[a-zA-Z]$/.test(e);if(!s.state.completionActive||!n){var o=s.getTokenAt(s.getCursor());if("string"!==o.type&&"comment"!==o.type){var i=c.CodeMirror.innerMode(s.getMode(),o.state).mode.name,r=s.getDoc(),r=r.getLine(r.getCursor().line).slice(0,r.getCursor().ch);let t=!1;"html"===i||"xml"===i?t="<"===e||"/"===e&&"tag"===o.type||n&&"tag"===o.type||n&&"attribute"===o.type||"="===e&&!(!o.state.htmlState?.tagName&&!o.state.curState?.htmlState?.tagName):"css"===i?t=n||":"===e||" "===e&&/:\s+$/.test(r):"javascript"===i?t=n||"."===e:"clike"===i&&"php"===s.options.mode&&(t=n&&("keyword"===o.type||"variable"===o.type)),t&&s.showHint({completeSingle:!1})}}}});{var i=s,r=t;const a=u(i.getTextArea());i.on("blur",function(){a.data("next-tab-blurs",!1)}),i.on("keydown",function(t,e){"Escape"===e.key?a.data("next-tab-blurs",!0):"Tab"===e.key&&a.data("next-tab-blurs")&&(e.shiftKey&&r.onTabPrevious?r.onTabPrevious(i,e):!e.shiftKey&&r.onTabNext&&r.onTabNext(i,e),a.data("next-tab-blurs",!1),e.preventDefault())})}return e}}(jQuery,window.wp);
|
||||
@@ -0,0 +1,356 @@
|
||||
/**
|
||||
* @output wp-admin/js/color-picker.js
|
||||
*/
|
||||
|
||||
( function( $, undef ) {
|
||||
|
||||
var ColorPicker,
|
||||
_before = '<button type="button" class="button wp-color-result" aria-expanded="false"><span class="wp-color-result-text"></span></button>',
|
||||
_after = '<div class="wp-picker-holder" />',
|
||||
_wrap = '<div class="wp-picker-container" />',
|
||||
_button = '<input type="button" class="button button-small" />',
|
||||
_wrappingLabel = '<label></label>',
|
||||
_wrappingLabelText = '<span class="screen-reader-text"></span>',
|
||||
__ = wp.i18n.__;
|
||||
|
||||
/**
|
||||
* Creates a jQuery UI color picker that is used in the theme customizer.
|
||||
*
|
||||
* @class $.widget.wp.wpColorPicker
|
||||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
ColorPicker = /** @lends $.widget.wp.wpColorPicker.prototype */{
|
||||
options: {
|
||||
defaultColor: false,
|
||||
change: false,
|
||||
clear: false,
|
||||
hide: true,
|
||||
palettes: true,
|
||||
width: 255,
|
||||
mode: 'hsv',
|
||||
type: 'full',
|
||||
slider: 'horizontal'
|
||||
},
|
||||
/**
|
||||
* Creates a color picker that only allows you to adjust the hue.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @access private
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
_createHueOnly: function() {
|
||||
var self = this,
|
||||
el = self.element,
|
||||
color;
|
||||
|
||||
el.hide();
|
||||
|
||||
// Set the saturation to the maximum level.
|
||||
color = 'hsl(' + el.val() + ', 100, 50)';
|
||||
|
||||
// Create an instance of the color picker, using the hsl mode.
|
||||
el.iris( {
|
||||
mode: 'hsl',
|
||||
type: 'hue',
|
||||
hide: false,
|
||||
color: color,
|
||||
/**
|
||||
* Handles the onChange event if one has been defined in the options.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @param {Event} event The event that's being called.
|
||||
* @param {HTMLElement} ui The HTMLElement containing the color picker.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
change: function( event, ui ) {
|
||||
if ( typeof self.options.change === 'function' ) {
|
||||
self.options.change.call( this, event, ui );
|
||||
}
|
||||
},
|
||||
width: self.options.width,
|
||||
slider: self.options.slider
|
||||
} );
|
||||
},
|
||||
/**
|
||||
* Creates the color picker, sets default values, css classes and wraps it all in HTML.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @access private
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
_create: function() {
|
||||
// Return early if Iris support is missing.
|
||||
if ( ! $.support.iris ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this,
|
||||
el = self.element;
|
||||
|
||||
// Override default options with options bound to the element.
|
||||
$.extend( self.options, el.data() );
|
||||
|
||||
// Create a color picker which only allows adjustments to the hue.
|
||||
if ( self.options.type === 'hue' ) {
|
||||
return self._createHueOnly();
|
||||
}
|
||||
|
||||
// Bind the close event.
|
||||
self.close = self.close.bind( self );
|
||||
|
||||
self.initialValue = el.val();
|
||||
|
||||
// Add a CSS class to the input field.
|
||||
el.addClass( 'wp-color-picker' );
|
||||
|
||||
/*
|
||||
* Check if there's already a wrapping label, e.g. in the Customizer.
|
||||
* If there's no label, add a default one to match the Customizer template.
|
||||
*/
|
||||
if ( ! el.parent( 'label' ).length ) {
|
||||
// Wrap the input field in the default label.
|
||||
el.wrap( _wrappingLabel );
|
||||
// Insert the default label text.
|
||||
self.wrappingLabelText = $( _wrappingLabelText )
|
||||
.insertBefore( el )
|
||||
.text( __( 'Color value' ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* At this point, either it's the standalone version or the Customizer
|
||||
* one, we have a wrapping label to use as hook in the DOM, let's store it.
|
||||
*/
|
||||
self.wrappingLabel = el.parent();
|
||||
|
||||
// Wrap the label in the main wrapper.
|
||||
self.wrappingLabel.wrap( _wrap );
|
||||
// Store a reference to the main wrapper.
|
||||
self.wrap = self.wrappingLabel.parent();
|
||||
// Set up the toggle button and insert it before the wrapping label.
|
||||
self.toggler = $( _before )
|
||||
.insertBefore( self.wrappingLabel )
|
||||
.css( { backgroundColor: self.initialValue } );
|
||||
// Set the toggle button span element text.
|
||||
self.toggler.find( '.wp-color-result-text' ).text( __( 'Select Color' ) );
|
||||
// Set up the Iris container and insert it after the wrapping label.
|
||||
self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel );
|
||||
// Store a reference to the Clear/Default button.
|
||||
self.button = $( _button );
|
||||
|
||||
// Set up the Clear/Default button.
|
||||
if ( self.options.defaultColor ) {
|
||||
self.button
|
||||
.addClass( 'wp-picker-default' )
|
||||
.val( __( 'Default' ) )
|
||||
.attr( 'aria-label', __( 'Select default color' ) );
|
||||
} else {
|
||||
self.button
|
||||
.addClass( 'wp-picker-clear' )
|
||||
.val( __( 'Clear' ) )
|
||||
.attr( 'aria-label', __( 'Clear color' ) );
|
||||
}
|
||||
|
||||
// Wrap the wrapping label in its wrapper and append the Clear/Default button.
|
||||
self.wrappingLabel
|
||||
.wrap( '<span class="wp-picker-input-wrap hidden" />' )
|
||||
.after( self.button );
|
||||
|
||||
/*
|
||||
* The input wrapper now contains the label+input+Clear/Default button.
|
||||
* Store a reference to the input wrapper: we'll use this to toggle
|
||||
* the controls visibility.
|
||||
*/
|
||||
self.inputWrapper = el.closest( '.wp-picker-input-wrap' );
|
||||
|
||||
el.iris( {
|
||||
target: self.pickerContainer,
|
||||
hide: self.options.hide,
|
||||
width: self.options.width,
|
||||
mode: self.options.mode,
|
||||
palettes: self.options.palettes,
|
||||
/**
|
||||
* Handles the onChange event if one has been defined in the options and additionally
|
||||
* sets the background color for the toggler element.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @param {Event} event The event that's being called.
|
||||
* @param {HTMLElement} ui The HTMLElement containing the color picker.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
change: function( event, ui ) {
|
||||
self.toggler.css( { backgroundColor: ui.color.toString() } );
|
||||
|
||||
if ( typeof self.options.change === 'function' ) {
|
||||
self.options.change.call( this, event, ui );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
el.val( self.initialValue );
|
||||
self._addListeners();
|
||||
|
||||
// Force the color picker to always be closed on initial load.
|
||||
if ( ! self.options.hide ) {
|
||||
self.toggler.click();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Binds event listeners to the color picker.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @access private
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
_addListeners: function() {
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* Prevent any clicks inside this widget from leaking to the top and closing it.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param {Event} event The event that's being called.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.wrap.on( 'click.wpcolorpicker', function( event ) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
/**
|
||||
* Open or close the color picker depending on the class.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
self.toggler.on( 'click', function(){
|
||||
if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
|
||||
self.close();
|
||||
} else {
|
||||
self.open();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Checks if value is empty when changing the color in the color picker.
|
||||
* If so, the background color is cleared.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param {Event} event The event that's being called.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.element.on( 'change', function( event ) {
|
||||
var me = $( this ),
|
||||
val = me.val();
|
||||
|
||||
if ( val === '' || val === '#' ) {
|
||||
self.toggler.css( 'backgroundColor', '' );
|
||||
// Fire clear callback if we have one.
|
||||
if ( typeof self.options.clear === 'function' ) {
|
||||
self.options.clear.call( this, event );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Enables the user to either clear the color in the color picker or revert back to the default color.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param {Event} event The event that's being called.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.button.on( 'click', function( event ) {
|
||||
var me = $( this );
|
||||
if ( me.hasClass( 'wp-picker-clear' ) ) {
|
||||
self.element.val( '' );
|
||||
self.toggler.css( 'backgroundColor', '' );
|
||||
if ( typeof self.options.clear === 'function' ) {
|
||||
self.options.clear.call( this, event );
|
||||
}
|
||||
} else if ( me.hasClass( 'wp-picker-default' ) ) {
|
||||
self.element.val( self.options.defaultColor ).change();
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Opens the color picker dialog.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
open: function() {
|
||||
this.element.iris( 'toggle' );
|
||||
this.inputWrapper.removeClass( 'hidden' );
|
||||
this.wrap.addClass( 'wp-picker-active' );
|
||||
this.toggler
|
||||
.addClass( 'wp-picker-open' )
|
||||
.attr( 'aria-expanded', 'true' );
|
||||
$( 'body' ).trigger( 'click.wpcolorpicker' ).on( 'click.wpcolorpicker', this.close );
|
||||
},
|
||||
/**
|
||||
* Closes the color picker dialog.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
close: function() {
|
||||
this.element.iris( 'toggle' );
|
||||
this.inputWrapper.addClass( 'hidden' );
|
||||
this.wrap.removeClass( 'wp-picker-active' );
|
||||
this.toggler
|
||||
.removeClass( 'wp-picker-open' )
|
||||
.attr( 'aria-expanded', 'false' );
|
||||
$( 'body' ).off( 'click.wpcolorpicker', this.close );
|
||||
},
|
||||
/**
|
||||
* Returns the iris object if no new color is provided. If a new color is provided, it sets the new color.
|
||||
*
|
||||
* @param newColor {string|*} The new color to use. Can be undefined.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return {string} The element's color.
|
||||
*/
|
||||
color: function( newColor ) {
|
||||
if ( newColor === undef ) {
|
||||
return this.element.iris( 'option', 'color' );
|
||||
}
|
||||
this.element.iris( 'option', 'color', newColor );
|
||||
},
|
||||
/**
|
||||
* Returns the iris object if no new default color is provided.
|
||||
* If a new default color is provided, it sets the new default color.
|
||||
*
|
||||
* @param newDefaultColor {string|*} The new default color to use. Can be undefined.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return {boolean|string} The element's color.
|
||||
*/
|
||||
defaultColor: function( newDefaultColor ) {
|
||||
if ( newDefaultColor === undef ) {
|
||||
return this.options.defaultColor;
|
||||
}
|
||||
|
||||
this.options.defaultColor = newDefaultColor;
|
||||
}
|
||||
};
|
||||
|
||||
// Register the color picker as a widget.
|
||||
$.widget( 'wp.wpColorPicker', ColorPicker );
|
||||
}( jQuery ) );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(i,t){var a=wp.i18n.__;i.widget("wp.wpColorPicker",{options:{defaultColor:!1,change:!1,clear:!1,hide:!0,palettes:!0,width:255,mode:"hsv",type:"full",slider:"horizontal"},_createHueOnly:function(){var e,o=this,t=o.element;t.hide(),e="hsl("+t.val()+", 100, 50)",t.iris({mode:"hsl",type:"hue",hide:!1,color:e,change:function(e,t){"function"==typeof o.options.change&&o.options.change.call(this,e,t)},width:o.options.width,slider:o.options.slider})},_create:function(){if(i.support.iris){var o=this,e=o.element;if(i.extend(o.options,e.data()),"hue"===o.options.type)return o._createHueOnly();o.close=o.close.bind(o),o.initialValue=e.val(),e.addClass("wp-color-picker"),e.parent("label").length||(e.wrap("<label></label>"),o.wrappingLabelText=i('<span class="screen-reader-text"></span>').insertBefore(e).text(a("Color value"))),o.wrappingLabel=e.parent(),o.wrappingLabel.wrap('<div class="wp-picker-container" />'),o.wrap=o.wrappingLabel.parent(),o.toggler=i('<button type="button" class="button wp-color-result" aria-expanded="false"><span class="wp-color-result-text"></span></button>').insertBefore(o.wrappingLabel).css({backgroundColor:o.initialValue}),o.toggler.find(".wp-color-result-text").text(a("Select Color")),o.pickerContainer=i('<div class="wp-picker-holder" />').insertAfter(o.wrappingLabel),o.button=i('<input type="button" class="button button-small" />'),o.options.defaultColor?o.button.addClass("wp-picker-default").val(a("Default")).attr("aria-label",a("Select default color")):o.button.addClass("wp-picker-clear").val(a("Clear")).attr("aria-label",a("Clear color")),o.wrappingLabel.wrap('<span class="wp-picker-input-wrap hidden" />').after(o.button),o.inputWrapper=e.closest(".wp-picker-input-wrap"),e.iris({target:o.pickerContainer,hide:o.options.hide,width:o.options.width,mode:o.options.mode,palettes:o.options.palettes,change:function(e,t){o.toggler.css({backgroundColor:t.color.toString()}),"function"==typeof o.options.change&&o.options.change.call(this,e,t)}}),e.val(o.initialValue),o._addListeners(),o.options.hide||o.toggler.click()}},_addListeners:function(){var o=this;o.wrap.on("click.wpcolorpicker",function(e){e.stopPropagation()}),o.toggler.on("click",function(){o.toggler.hasClass("wp-picker-open")?o.close():o.open()}),o.element.on("change",function(e){var t=i(this).val();""!==t&&"#"!==t||(o.toggler.css("backgroundColor",""),"function"==typeof o.options.clear&&o.options.clear.call(this,e))}),o.button.on("click",function(e){var t=i(this);t.hasClass("wp-picker-clear")?(o.element.val(""),o.toggler.css("backgroundColor",""),"function"==typeof o.options.clear&&o.options.clear.call(this,e)):t.hasClass("wp-picker-default")&&o.element.val(o.options.defaultColor).change()})},open:function(){this.element.iris("toggle"),this.inputWrapper.removeClass("hidden"),this.wrap.addClass("wp-picker-active"),this.toggler.addClass("wp-picker-open").attr("aria-expanded","true"),i("body").trigger("click.wpcolorpicker").on("click.wpcolorpicker",this.close)},close:function(){this.element.iris("toggle"),this.inputWrapper.addClass("hidden"),this.wrap.removeClass("wp-picker-active"),this.toggler.removeClass("wp-picker-open").attr("aria-expanded","false"),i("body").off("click.wpcolorpicker",this.close)},color:function(e){if(e===t)return this.element.iris("option","color");this.element.iris("option","color",e)},defaultColor:function(e){if(e===t)return this.options.defaultColor;this.options.defaultColor=e}})}(jQuery);
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @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:' ) + ' <b>' +
|
||||
/* 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 ) ) +
|
||||
'</b> '
|
||||
);
|
||||
|
||||
// Move focus back to the Edit link.
|
||||
$edittimestamp.show().trigger( 'focus' );
|
||||
$timestampdiv.slideUp( 'fast' );
|
||||
});
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! 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:")+" <b>"+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))+"</b> "),c.show().trigger("focus"),d.slideUp("fast"))})});
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! 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)Line truncated
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* @output wp-admin/js/custom-background.js
|
||||
*/
|
||||
|
||||
/* global ajaxurl */
|
||||
|
||||
/**
|
||||
* Registers all events for customizing the background.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @requires jQuery
|
||||
*/
|
||||
(function($) {
|
||||
$( function() {
|
||||
var frame,
|
||||
bgImage = $( '#custom-background-image' );
|
||||
|
||||
/**
|
||||
* Instantiates the WordPress color picker and binds the change and clear events.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$('#background-color').wpColorPicker({
|
||||
change: function( event, ui ) {
|
||||
bgImage.css('background-color', ui.color.toString());
|
||||
},
|
||||
clear: function() {
|
||||
bgImage.css('background-color', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Alters the background size CSS property whenever the background size input has changed.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$( 'select[name="background-size"]' ).on( 'change', function() {
|
||||
bgImage.css( 'background-size', $( this ).val() );
|
||||
});
|
||||
|
||||
/**
|
||||
* Alters the background position CSS property whenever the background position input has changed.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$( 'input[name="background-position"]' ).on( 'change', function() {
|
||||
bgImage.css( 'background-position', $( this ).val() );
|
||||
});
|
||||
|
||||
/**
|
||||
* Alters the background repeat CSS property whenever the background repeat input has changed.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$( 'input[name="background-repeat"]' ).on( 'change', function() {
|
||||
bgImage.css( 'background-repeat', $( this ).is( ':checked' ) ? 'repeat' : 'no-repeat' );
|
||||
});
|
||||
|
||||
/**
|
||||
* Alters the background attachment CSS property whenever the background attachment input has changed.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$( 'input[name="background-attachment"]' ).on( 'change', function() {
|
||||
bgImage.css( 'background-attachment', $( this ).is( ':checked' ) ? 'scroll' : 'fixed' );
|
||||
});
|
||||
|
||||
/**
|
||||
* Binds the event for opening the WP Media dialog.
|
||||
*
|
||||
* @since 3.5.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.customBackground = 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
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* When an image is selected, run a callback.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
frame.on( 'select', function() {
|
||||
// Grab the selected attachment.
|
||||
var attachment = frame.state().get('selection').first();
|
||||
var nonceValue = $( '#_wpnonce' ).val() || '';
|
||||
|
||||
// Run an Ajax request to set the background image.
|
||||
$.post( ajaxurl, {
|
||||
action: 'set-background-image',
|
||||
attachment_id: attachment.id,
|
||||
_ajax_nonce: nonceValue,
|
||||
size: 'full'
|
||||
}).done( function() {
|
||||
// When the request completes, reload the window.
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
// Finally, open the modal.
|
||||
frame.open();
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! 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);
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* @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));
|
||||
File diff suppressed because it is too large.
Load diff
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(J){var a,s,t,e,n,i,Y=wp.customize,o=window.matchMedia("(prefers-reduced-motion: reduce)"),r=o.matches;o.addEventListener("change",function(e){r=e.matches}),Y.OverlayNotification=Y.Notification.extend({loading:!1,initialize:function(e,t){var n=this;Y.Notification.prototype.initialize.call(n,e,t),n.containerClasses+=" notification-overlay",n.loading&&(n.containerClasses+=" notification-loading")},render:function(){var e=Y.Notification.prototype.render.call(this);return e.on("keydown",_.bind(this.handleEscape,this)),e},handleEscape:function(e){var t=this;27===e.which&&(e.stopPropagation(),t.dismissible)&&t.parent&&t.parent.remove(t.code)}}),Y.Notifications=Y.Values.extend({alt:!1,defaultConstructor:Y.Notification,initialize:function(e){var t=this;Y.Values.prototype.initialize.call(t,e),_.bindAll(t,"constrainFocus"),t._addedIncrement=0,t._addedOrder={},t.bind("add",function(e){t.trigger("change",e)}),t.bind("removed",function(e){t.trigger("change",e)})},count:function(){return _.size(this._value)},add:function(e,t){var n,i=this,t="string"==typeof e?(n=e,t):(n=e.code,e);return i.has(n)||(i._addedIncrement+=1,i._addedOrder[n]=i._addedIncrement),Y.Values.prototype.add.call(i,n,t)},remove:function(e){return delete this._addedOrder[e],Y.Values.prototype.remove.call(this,e)},get:function(e){var a,o=this,t=_.values(o._value);return _.extend({sort:!1},e).sort&&(a={error:4,warning:3,success:2,info:1},t.sort(function(e,t){var n=0,i=0;return(n=_.isUndefined(a[e.type])?n:a[e.type])!==(i=_.isUndefined(a[t.type])?i:a[t.type])?i-n:o._addedOrder[t.code]-o._addedOrder[e.code]})),t},render:function(){var e,t,n,i=this,a=!1,o=[],s={};i.container&&i.container.length&&(e=i.get({sort:!0}),i.container.toggle(0!==e.length),i.container.is(i.previousContainer)&&_.isEqual(e,i.previousNotifications)||((n=i.container.children("ul").first()).length||(n=J("<ul></ul>"),i.container.append(n)),n.find("> [data-code]").remove(),_.each(i.previousNotifications,function(e){s[e.code]=e}),_.each(e,function(e){var t;!wp.a11y||s[e.code]&&_.isEqual(e.message,s[e.code].message)||wp.a11y.speak(e.message,"assertive"),t=J(e.render()),e.container=t,n.append(t),e.extended(Y.OverlayNotification)&&o.push(e)}),(t=Boolean(o.length))!==(a=i.previousNotifications?Boolean(_.find(i.previousNotifications,function(e){return e.extended(Y.OverlayNotification)})):a)&&(J(document.body).toggleClass("customize-loading",t),i.container.toggleClass("has-overlay-notifications",t),t?(i.previousActiveElement=document.activeElement,J(document).on("keydown",i.constrainFocus)):J(document).off("keydown",i.constrainFocus)),t?(i.focusContainer=o[o.length-1].container,i.focusContainer.prop("tabIndex",-1),((a=i.focusContainer.find(":focusable")).length?a.first():i.focusContainer).focus()):i.previousActiveElement&&(J(i.previousActiveElement).trigger("focus"),i.previousActiveElement=null),i.previousNotifications=e,i.previousContainer=i.container,i.trigger("rendered")))},constrainFocus:function(e){var t,n=this;e.stopPropagation(),9===e.which&&(0===(t=n.focusContainer.find(":focusable")).length&&(t=n.focusContainer),!J.contains(n.focusContainer[0],e.target)||!J.contains(n.focusContainer[0],document.activeElement)||t.last().is(e.target)&&!e.shiftKey?(e.preventDefault(),t.first().focus()):t.first().is(e.target)&&e.shiftKey&&(e.preventDefault(),t.last().focus()))}}),Y.Setting=Y.Value.extend({defaults:{transport:"refresh",dirty:!1},initialize:function(e,t,n){var i=this,n=_.extend({previewer:Y.previewer},i.defaults,n||{});Y.Value.prototype.initialize.call(i,t,n),i.id=e,i._dirty=n.dirty,i.notifications=new Y.Notifications,i.bind(i.preview)},preview:function(){var e=this,t=e.transport;"postMessage"===(t="postMessage"!==t||Y.state("previewerAlive").get()?t:"refresh")?e.previewer.send("setting",[e.id,e()]):"refresh"===t&&e.previewer.refresh()},findControls:function(){var n=this,i=[];return Y.control.each(function(t){_.each(t.settings,function(e){e.id===n.id&&i.push(t)})}),i}}),Y._latestRevision=0,Y._lastSavedRevision=0,Y._latestSettingRevisions={},Y.bind("change",function(e){Y._latestRevision+=1,Y._latestSettingRevisions[e.id]=Y._latestRevision}),Y.bind("ready",function(){Y.bind("add",function(e){e._dirty&&(Y._latestRevision+=1,Y._latestSettingRevisions[e.id]=Y._latestRevision)})}),Y.dirtyValues=function(n){var i={};return Y.each(function(e){var t;e._dirty&&(t=Y._latestSettingRevisions[e.id],Y.state("changesetStatus").get()&&n&&n.unsaved&&(_.isUndefined(t)||t<=Y._lastSavedRevision)||(i[e.id]=e.get()))}),i},Y.requestChangesetUpdate=function(n,e){var t,i={},a=new J.Deferred;if(0!==Y.state("processing").get())a.reject("already_processing");else if(e=_.extend({title:null,date:null,autosave:!1,force:!1},e),n&&_.extend(i,n),_.each(Y.dirtyValues({unsaved:!0}),function(e,t){n&&null===n[t]||(i[t]=_.extend({},i[t]||{},{value:e}))}),Y.trigger("changeset-save",i,e),!e.force&&_.isEmpty(i)&&null===e.title&&null===e.date)a.resolve({});else{if(e.status)return a.reject({code:"illegal_status_in_changeset_updatLine truncated
|
||||
File diff suppressed because it is too large.
Load diff
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(u,l,m){"use strict";function c(e){return(e=(e=l.sanitize.stripTagsAndEncodeText(e=e||"")).toString().trim())||u.Menus.data.l10n.unnamed}wpNavMenu.originalInit=wpNavMenu.init,wpNavMenu.options.menuItemDepthPerLevel=20,wpNavMenu.options.sortableItems="> .customize-control-nav_menu_item",wpNavMenu.options.targetTolerance=10,wpNavMenu.init=function(){this.jQueryExtensions()},u.Menus=u.Menus||{},u.Menus.data={itemTypes:[],l10n:{},settingTransport:"refresh",phpIntMax:0,defaultSettingValues:{nav_menu:{},nav_menu_item:{}},locationSlugMappedToName:{}},"undefined"!=typeof _wpCustomizeNavMenusSettings&&m.extend(u.Menus.data,_wpCustomizeNavMenusSettings),u.Menus.generatePlaceholderAutoIncrementId=function(){return-Math.ceil(u.Menus.data.phpIntMax*Math.random())},u.Menus.AvailableItemModel=Backbone.Model.extend(m.extend({id:null},u.Menus.data.defaultSettingValues.nav_menu_item)),u.Menus.AvailableItemCollection=Backbone.Collection.extend({model:u.Menus.AvailableItemModel,sort_key:"order",comparator:function(e){return-e.get(this.sort_key)},sortByField:function(e){this.sort_key=e,this.sort()}}),u.Menus.availableMenuItems=new u.Menus.AvailableItemCollection(u.Menus.data.availableMenuItems),u.Menus.insertAutoDraftPost=function(n){var i=m.Deferred(),e=l.ajax.post("customize-nav-menus-insert-auto-draft",{"customize-menus-nonce":u.settings.nonce["customize-menus"],wp_customize:"on",customize_changeset_uuid:u.settings.changeset.uuid,params:n});return e.done(function(t){t.post_id&&(u("nav_menus_created_posts").set(u("nav_menus_created_posts").get().concat([t.post_id])),"page"===n.post_type&&(u.section.has("static_front_page")&&u.section("static_front_page").activate(),u.control.each(function(e){"dropdown-pages"===e.params.type&&e.container.find('select[name^="_customize-dropdown-pages-"]').append(new Option(n.post_title,t.post_id))})),i.resolve(t))}),e.fail(function(e){var t=e||"";void 0!==e.message&&(t=e.message),console.error(t),i.rejectWith(t)}),i.promise()},u.Menus.AvailableMenuItemsPanelView=l.Backbone.View.extend({el:"#available-menu-items",events:{"input #menu-items-search":"debounceSearch","focus .menu-item-tpl":"focus","click .menu-item-tpl":"_submit","click #custom-menu-item-submit":"_submitLink","keypress #custom-menu-item-name":"_submitLink","click .new-content-item .add-content":"_submitNew","keypress .create-item-input":"_submitNew",keydown:"keyboardAccessible"},selected:null,currentMenuControl:null,debounceSearch:null,$search:null,$clearResults:null,searchTerm:"",rendered:!1,pages:{},sectionContent:"",loading:!1,addingNew:!1,initialize:function(){var n=this;u.panel.has("nav_menus")&&(this.$search=m("#menu-items-search"),this.$clearResults=this.$el.find(".clear-results"),this.sectionContent=this.$el.find(".available-menu-items-list"),this.debounceSearch=_.debounce(n.search,500),_.bindAll(this,"close"),m("#customize-controls, .customize-section-back").on("click keydown",function(e){var t=m(e.target).is(".item-delete, .item-delete *"),e=m(e.target).is(".add-new-menu-item, .add-new-menu-item *");!m("body").hasClass("adding-menu-items")||t||e||n.close()}),this.$clearResults.on("click",function(){n.$search.val("").trigger("focus").trigger("input")}),this.$el.on("input","#custom-menu-item-name.invalid, #custom-menu-item-url.invalid",function(){m(this).removeClass("invalid");var e=m(this).attr("aria-describedby");m("#"+e).hide(),m(this).removeAttr("aria-invalid").removeAttr("aria-describedby")}),u.panel("nav_menus").container.on("expanded",function(){n.rendered||(n.initList(),n.rendered=!0)}),this.sectionContent.on("scroll",function(){var e=n.$el.find(".accordion-section.open .available-menu-items-list").prop("scrollHeight"),t=n.$el.find(".accordion-section.open").height();!n.loading&&m(this).scrollTop()>.75*e-t&&(e=m(this).data("type"),t=m(this).data("object"),"search"===e?n.searchTerm&&n.doSearch(n.pages.search):n.loadItems([{type:e,object:t}]))}),u.previewer.bind("url",this.close),n.delegateEvents())},search:function(e){var t=m("#available-menu-items-search"),n=m("#available-menu-items .accordion-section").not(t);e&&this.searchTerm!==e.target.value&&(""===e.target.value||t.hasClass("open")?""===e.target.value&&(t.removeClass("open"),n.show(),this.$clearResults.removeClass("is-visible")):(n.fadeOut(100),t.find(".accordion-section-content").slideDown("fast"),t.addClass("open"),this.$clearResults.addClass("is-visible")),this.searchTerm=e.target.value,this.pages.search=1,this.doSearch(1))},doSearch:function(t){var e,n=this,i=m("#available-menu-items-search"),a=i.find(".accordion-section-content"),o=l.template("available-menu-item");if(n.currentRequest&&n.currentRequest.abort(),!(t<0)){if(1<t)i.addClass("loading-more"),a.attr("aria-busy","true"),l.a11y.speak(u.Menus.data.l10n.itemsLoadingMore);else if(""===n.searchTerm)return a.html(""),void l.a11y.speak("");i.addClass("loading"),n.loading=!0,e=u.previewer.query({excludeCustomizedSaved:!0}),_.extend(e,{"customize-menus-nonce":u.settings.nonce["customize-menus"],wpLine truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(u,h){var p,f;function c(e){var t={number:null,id_base:null},i=e.match(/^(.+)-(\d+)$/);return i?(t.id_base=i[1],t.number=parseInt(i[2],10)):t.id_base=e,t}u&&u.customize&&((p=u.customize).Widgets=p.Widgets||{},p.Widgets.savedWidgetIds={},p.Widgets.data=_wpCustomizeWidgetsSettings||{},f=p.Widgets.data.l10n,p.Widgets.WidgetModel=Backbone.Model.extend({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:!0}),p.Widgets.WidgetCollection=Backbone.Collection.extend({model:p.Widgets.WidgetModel,doSearch:function(e){this.terms!==e&&(this.terms=e,0<this.terms.length&&this.search(this.terms),""===this.terms)&&this.each(function(e){e.set("search_matched",!0)})},search:function(e){var t,i;e=(e=e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")).replace(/ /g,")(?=.*"),t=new RegExp("^(?=.*"+e+").+","i"),this.each(function(e){i=[e.get("name"),e.get("description")].join(" "),e.set("search_matched",t.test(i))})}}),p.Widgets.availableWidgets=new p.Widgets.WidgetCollection(p.Widgets.data.availableWidgets),p.Widgets.SidebarModel=Backbone.Model.extend({after_title:null,after_widget:null,before_title:null,before_widget:null,class:null,description:null,id:null,name:null,is_rendered:!1}),p.Widgets.SidebarCollection=Backbone.Collection.extend({model:p.Widgets.SidebarModel}),p.Widgets.registeredSidebars=new p.Widgets.SidebarCollection(p.Widgets.data.registeredSidebars),p.Widgets.AvailableWidgetsPanelView=u.Backbone.View.extend({el:"#available-widgets",events:{"input #widgets-search":"search","focus .widget-tpl":"focus","click .widget-tpl":"_submit","keypress .widget-tpl":"_submit",keydown:"keyboardAccessible"},selected:null,currentSidebarControl:null,$search:null,$clearResults:null,searchMatchesCount:null,initialize:function(){var t=this;this.$search=h("#widgets-search"),this.$clearResults=this.$el.find(".clear-results"),_.bindAll(this,"close"),this.listenTo(this.collection,"change",this.updateList),this.updateList(),this.searchMatchesCount=this.collection.length,h("#customize-controls, #available-widgets .customize-section-title").on("click keydown",function(e){e=h(e.target).is(".add-new-widget, .add-new-widget *");h("body").hasClass("adding-widget")&&!e&&t.close()}),this.$clearResults.on("click",function(){t.$search.val("").trigger("focus").trigger("input")}),p.previewer.bind("url",this.close)},search:_.debounce(function(e){var t;this.collection.doSearch(e.target.value),this.updateSearchMatchesCount(),this.announceSearchMatches(),this.selected&&!this.selected.is(":visible")&&(this.selected.removeClass("selected"),this.selected=null),this.selected&&!e.target.value&&(this.selected.removeClass("selected"),this.selected=null),!this.selected&&e.target.value&&(t=this.$el.find("> .widget-tpl:visible:first")).length&&this.select(t),""!==e.target.value?this.$clearResults.addClass("is-visible"):""===e.target.value&&this.$clearResults.removeClass("is-visible"),this.searchMatchesCount?this.$el.removeClass("no-widgets-found"):this.$el.addClass("no-widgets-found")},500),updateSearchMatchesCount:function(){this.searchMatchesCount=this.collection.where({search_matched:!0}).length},announceSearchMatches:function(){var e=f.widgetsFound.replace("%d",this.searchMatchesCount);this.searchMatchesCount||(e=f.noWidgetsFound),u.a11y.speak(e)},updateList:function(){this.collection.each(function(e){var t=h("#widget-tpl-"+e.id);t.toggle(e.get("search_matched")&&!e.get("is_disabled")),e.get("is_disabled")&&t.is(this.selected)&&(this.selected=null)})},select:function(e){this.selected=h(e),this.selected.siblings(".widget-tpl").removeClass("selected"),this.selected.addClass("selected")},focus:function(e){this.select(h(e.currentTarget))},_submit:function(e){"keypress"===e.type&&13!==e.which&&32!==e.which||this.submit(h(e.currentTarget))},submit:function(e){(e=e||this.selected)&&this.currentSidebarControl&&(this.select(e),e=h(this.selected).data("widget-id"),e=this.collection.findWhere({id:e}))&&((e=this.currentSidebarControl.addWidget(e.get("id_base")))&&e.focus(),this.close())},open:function(e){this.currentSidebarControl=e,_(this.currentSidebarControl.getWidgetFormControls()).each(function(e){e.params.is_wide&&e.collapseForm()}),p.section.has("publish_settings")&&p.section("publish_settings").collapse(),h("body").addClass("adding-widget"),this.$el.find(".selected").removeClass("selected"),this.collection.doSearch(""),p.settings.browser.mobile||this.$search.trigger("focus")},close:function(e){(e=e||{}).returnFocus&&this.currentSidebarControl&&this.currentSidebarControl.container.find(".add-new-widget").focus(),this.currentSidebarControl=null,this.selected=null,h("body").removeClass("adding-widget"),this.$search.val("").trigger("input")},keyboardAccessible:function(e){var t=13===e.which,i=27===e.which,n=40===e.which,s=38===e.which,d=9===e.which,a=e.shiftKey,o=null,r=this.$el.find("> .widget-tpl:visible:first"),l=thLine truncated
|
||||
@@ -0,0 +1,845 @@
|
||||
/**
|
||||
* @output wp-admin/js/dashboard.js
|
||||
*/
|
||||
|
||||
/* global pagenow, ajaxurl, postboxes, wpActiveEditor:true, ajaxWidgets */
|
||||
/* global ajaxPopulateWidgets, quickPressLoad, */
|
||||
window.wp = window.wp || {};
|
||||
window.communityEventsData = window.communityEventsData || {};
|
||||
|
||||
/**
|
||||
* Initializes the dashboard widget functionality.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
jQuery( function($) {
|
||||
var welcomePanel = $( '#welcome-panel' ),
|
||||
welcomePanelHide = $('#wp_welcome_panel-hide'),
|
||||
updateWelcomePanel;
|
||||
|
||||
/**
|
||||
* Saves the visibility of the welcome panel.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @param {boolean} visible Should it be visible or not.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
updateWelcomePanel = function( visible ) {
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'update-welcome-panel',
|
||||
visible: visible,
|
||||
welcomepanelnonce: $( '#welcomepanelnonce' ).val()
|
||||
},
|
||||
function() {
|
||||
wp.a11y.speak( wp.i18n.__( 'Screen Options updated.' ) );
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Unhide the welcome panel if the Welcome Option checkbox is checked.
|
||||
if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) {
|
||||
welcomePanel.removeClass('hidden');
|
||||
}
|
||||
|
||||
// Hide the welcome panel when the dismiss button or close button is clicked.
|
||||
$('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).on( 'click', function(e) {
|
||||
e.preventDefault();
|
||||
welcomePanel.addClass('hidden');
|
||||
updateWelcomePanel( 0 );
|
||||
$('#wp_welcome_panel-hide').prop('checked', false);
|
||||
});
|
||||
|
||||
// Set welcome panel visibility based on Welcome Option checkbox value.
|
||||
welcomePanelHide.on( 'click', function() {
|
||||
welcomePanel.toggleClass('hidden', ! this.checked );
|
||||
updateWelcomePanel( this.checked ? 1 : 0 );
|
||||
});
|
||||
|
||||
/**
|
||||
* These widgets can be populated via ajax.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @type {string[]}
|
||||
*
|
||||
* @global
|
||||
*/
|
||||
window.ajaxWidgets = ['dashboard_primary'];
|
||||
|
||||
/**
|
||||
* Triggers widget updates via Ajax.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @global
|
||||
*
|
||||
* @param {string} el Optional. Widget to fetch or none to update all.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
window.ajaxPopulateWidgets = function(el) {
|
||||
/**
|
||||
* Fetch the latest representation of the widget via Ajax and show it.
|
||||
*
|
||||
* @param {number} i Number of half-seconds to use as the timeout.
|
||||
* @param {string} id ID of the element which is going to be checked for changes.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function show(i, id) {
|
||||
var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
|
||||
// If the element is found in the dom, queue to load latest representation.
|
||||
if ( e.length ) {
|
||||
p = e.parent();
|
||||
setTimeout( function(){
|
||||
// Request the widget content.
|
||||
p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
|
||||
// Hide the parent and slide it out for visual fanciness.
|
||||
p.hide().slideDown('normal', function(){
|
||||
$(this).css('display', '');
|
||||
});
|
||||
});
|
||||
}, i * 500 );
|
||||
}
|
||||
}
|
||||
|
||||
// If we have received a specific element to fetch, check if it is valid.
|
||||
if ( el ) {
|
||||
el = el.toString();
|
||||
// If the element is available as Ajax widget, show it.
|
||||
if ( $.inArray(el, ajaxWidgets) !== -1 ) {
|
||||
// Show element without any delay.
|
||||
show(0, el);
|
||||
}
|
||||
} else {
|
||||
// Walk through all ajaxWidgets, loading them after each other.
|
||||
$.each( ajaxWidgets, show );
|
||||
}
|
||||
};
|
||||
|
||||
// Initially populate ajax widgets.
|
||||
ajaxPopulateWidgets();
|
||||
|
||||
// Register ajax widgets as postbox toggles.
|
||||
postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
|
||||
|
||||
/**
|
||||
* Control the Quick Press (Quick Draft) widget.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @global
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
window.quickPressLoad = function() {
|
||||
var act = $('#quickpost-action'), t;
|
||||
|
||||
// Enable the submit buttons.
|
||||
$( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false );
|
||||
|
||||
t = $('#quick-press').on( 'submit', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
// Show a spinner.
|
||||
$('#dashboard_quick_press #publishing-action .spinner').show();
|
||||
|
||||
// Disable the submit button to prevent duplicate submissions.
|
||||
$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
|
||||
|
||||
// Post the entered data to save it.
|
||||
$.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
|
||||
// Replace the form, and prepend the published post.
|
||||
$('#dashboard_quick_press .inside').html( data );
|
||||
$('#quick-press').removeClass('initial-form');
|
||||
quickPressLoad();
|
||||
highlightLatestPost();
|
||||
|
||||
// Focus the title to allow for quickly drafting another post.
|
||||
$('#title').trigger( 'focus' );
|
||||
});
|
||||
|
||||
/**
|
||||
* Highlights the latest post for one second.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function highlightLatestPost () {
|
||||
var latestPost = $('.drafts ul li').first();
|
||||
latestPost.css('background', '#fffbe5');
|
||||
setTimeout(function () {
|
||||
latestPost.css('background', 'none');
|
||||
}, 1000);
|
||||
}
|
||||
} );
|
||||
|
||||
// Change the QuickPost action to the publish value.
|
||||
$('#publish').on( 'click', function() { act.val( 'post-quickpress-publish' ); } );
|
||||
|
||||
$('#quick-press').on( 'click focusin', function() {
|
||||
wpActiveEditor = 'content';
|
||||
});
|
||||
|
||||
autoResizeTextarea();
|
||||
};
|
||||
window.quickPressLoad();
|
||||
|
||||
// Enable the dragging functionality of the widgets.
|
||||
$( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' );
|
||||
|
||||
/**
|
||||
* Adjust the height of the textarea based on the content.
|
||||
*
|
||||
* @since 3.6.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function autoResizeTextarea() {
|
||||
// When IE8 or older is used to render this document, exit.
|
||||
if ( document.documentMode && document.documentMode < 9 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a hidden div. We'll copy over the text from the textarea to measure its height.
|
||||
$('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
|
||||
|
||||
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' );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},window.communityEventsData=window.communityEventsData||{},jQuery(function(s){var t,n=s("#welcome-panel"),e=s("#wp_welcome_panel-hide");t=function(e){s.post(ajaxurl,{action:"update-welcome-panel",visible:e,welcomepanelnonce:s("#welcomepanelnonce").val()},function(){wp.a11y.speak(wp.i18n.__("Screen Options updated."))})},n.hasClass("hidden")&&e.prop("checked")&&n.removeClass("hidden"),s(".welcome-panel-close, .welcome-panel-dismiss a",n).on("click",function(e){e.preventDefault(),n.addClass("hidden"),t(0),s("#wp_welcome_panel-hide").prop("checked",!1)}),e.on("click",function(){n.toggleClass("hidden",!this.checked),t(this.checked?1:0)}),window.ajaxWidgets=["dashboard_primary"],window.ajaxPopulateWidgets=function(e){function t(e,t){var n,o=s("#"+t+" div.inside:visible").find(".widget-loading");o.length&&(n=o.parent(),setTimeout(function(){n.load(ajaxurl+"?action=dashboard-widgets&widget="+t+"&pagenow="+pagenow,"",function(){n.hide().slideDown("normal",function(){s(this).css("display","")})})},500*e))}e?(e=e.toString(),-1!==s.inArray(e,ajaxWidgets)&&t(0,e)):s.each(ajaxWidgets,t)},ajaxPopulateWidgets(),postboxes.add_postbox_toggles(pagenow,{pbshow:ajaxPopulateWidgets}),window.quickPressLoad=function(){var t,n,o,i,a,e=s("#quickpost-action");s('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop("disabled",!1),t=s("#quick-press").on("submit",function(e){e.preventDefault(),s("#dashboard_quick_press #publishing-action .spinner").show(),s('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop("disabled",!0),s.post(t.attr("action"),t.serializeArray(),function(e){var t;s("#dashboard_quick_press .inside").html(e),s("#quick-press").removeClass("initial-form"),quickPressLoad(),(t=s(".drafts ul li").first()).css("background","#fffbe5"),setTimeout(function(){t.css("background","none")},1e3),s("#title").trigger("focus")})}),s("#publish").on("click",function(){e.val("post-quickpress-publish")}),s("#quick-press").on("click focusin",function(){wpActiveEditor="content"}),document.documentMode&&document.documentMode<9||(s("body").append('<div class="quick-draft-textarea-clone" style="display: none;"></div>'),n=s(".quick-draft-textarea-clone"),o=s("#content"),i=o.height(),a=s(window).height()-100,n.css({"font-family":o.css("font-family"),"font-size":o.css("font-size"),"line-height":o.css("line-height"),"padding-bottom":o.css("paddingBottom"),"padding-left":o.css("paddingLeft"),"padding-right":o.css("paddingRight"),"padding-top":o.css("paddingTop"),"white-space":"pre-wrap","word-wrap":"break-word",display:"none"}),o.on("focus input propertychange",function(){var e=s(this),t=e.val()+" ",t=n.css("width",e.css("width")).text(t).outerHeight()+2;o.css("overflow-y","auto"),t===i||a<=t&&a<=i||(i=a<t?a:t,o.css("overflow","hidden"),e.css("height",i+"px"))}))},window.quickPressLoad(),s(".meta-box-sortables").sortable("option","containment","#wpwrap")}),jQuery(function(c){"use strict";var r=window.communityEventsData,s=wp.date.dateI18n,m=wp.date.format,d=wp.i18n.sprintf,u=wp.i18n.__,l=wp.i18n._x,p=window.wp.communityEvents={initialized:!1,model:null,init:function(){var e;p.initialized||(e=c("#community-events"),c(".community-events-errors").attr("aria-hidden","true").removeClass("hide-if-js"),e.on("click",".community-events-toggle-location, .community-events-cancel",p.toggleLocationForm),e.on("submit",".community-events-form",function(e){var t=c("#community-events-location").val().trim();e.preventDefault(),t&&p.getEvents({location:t})}),r&&r.cache&&r.cache.location&&r.cache.events?p.renderEventsTemplate(r.cache,"app"):p.getEvents(),p.initialized=!0)},toggleLocationForm:function(e){var t=c(".community-events-toggle-location"),n=c(".community-events-cancel"),o=c(".community-events-form"),i=c();"object"==typeof e&&(i=c(e.target),e="true"==t.attr("aria-expanded")?"hide":"show"),"hide"===e?(t.attr("aria-expanded","false"),n.attr("aria-expanded","false"),o.attr("aria-hidden","true"),i.hasClass("community-events-cancel")&&t.trigger("focus")):(t.attr("aria-expanded","true"),n.attr("aria-expanded","true"),o.attr("aria-hidden","false"))},getEvents:function(t){var n,o=this,e=c(".community-events-form").children(".spinner");(t=t||{})._wpnonce=r.nonce,t.timezone=window.Intl?window.Intl.DateTimeFormat().resolvedOptions().timeZone:"",n=t.location?"user":"app",e.addClass("is-active"),wp.ajax.post("get-community-events",t).always(function(){e.removeClass("is-active")}).done(function(e){"no_location_available"===e.error&&(t.location?e.unknownCity=t.location:delete e.error),o.renderEventsTemplate(e,n)}).fail(function(){o.renderEventsTemplate({location:!1,events:[],error:!0},n)})},renderEventsTemplate:function(e,t){var n,o,i=c(".community-events-toggle-location"),a=c("#community-events-location-message"),s=c(".community-events-results");e.events=p.populateDynamicEventFields(e.events,r.time_format),o={".community-events":!0,".community-events-loading":!1,".commLine truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(w){var o,s,i=document.title,C=w("#dashboard_right_now").length,c=wp.i18n.__,d=wp.i18n._x,x=function(t){t=parseInt(t.html().replace(/[^0-9]+/g,""),10);return isNaN(t)?0:t},r=function(t,e){var n="";if(!isNaN(e)){if(3<(e=e<1?"0":e.toString()).length){for(;3<e.length;)n=thousandsSeparator+e.substr(e.length-3)+n,e=e.substr(0,e.length-3);e+=n}t.html(e)}},b=function(n,t){var e=".post-com-count-"+t,a="comment-count-no-comments",o="comment-count-approved";k("span.approved-count",n),t&&(t=w("span."+o,e),e=w("span."+a,e),t.each(function(){var t=w(this),e=x(t)+n;0===(e=e<1?0:e)?t.removeClass(o).addClass(a):t.addClass(o).removeClass(a),r(t,e)}),e.each(function(){var t=w(this);0<n?t.removeClass(a).addClass(o):t.addClass(a).removeClass(o),r(t,n)}))},k=function(t,n){w(t).each(function(){var t=w(this),e=x(t)+n;r(t,e=e<1?0:e)})},E=function(t){C&&t&&t.i18n_comments_text&&w(".comment-count a","#dashboard_right_now").text(t.i18n_comments_text)},R=function(t){t&&t.i18n_moderation_text&&(w(".comments-in-moderation-text").text(t.i18n_moderation_text),C)&&t.in_moderation&&w(".comment-mod-count","#dashboard_right_now")[0<t.in_moderation?"removeClass":"addClass"]("hidden")},l=function(t){var e,n,a;s=s||new RegExp(c("Comments (%s)").replace("%s","\\([0-9"+thousandsSeparator+"]+\\)")+"?"),o=o||w("<div />"),e=i,1<=(a=(a=s.exec(document.title))?(a=a[0],o.html(a),x(o)+t):(o.html(0),t))?(r(o,a),(n=s.exec(document.title))&&(e=document.title.replace(n[0],c("Comments (%s)").replace("%s",o.text())+" "))):(n=s.exec(e))&&(e=e.replace(n[0],c("Comments"))),document.title=e},I=function(n,t){var e=".post-com-count-"+t,a="comment-count-no-pending",o="post-com-count-no-pending",s="comment-count-pending";C||l(n),w("span.pending-count").each(function(){var t=w(this),e=x(t)+n;e<1&&(e=0),t.closest(".awaiting-mod")[0===e?"addClass":"removeClass"]("count-0"),r(t,e)}),t&&(t=w("span."+s,e),e=w("span."+a,e),t.each(function(){var t=w(this),e=x(t)+n;0===(e=e<1?0:e)?(t.parent().addClass(o),t.removeClass(s).addClass(a)):(t.parent().removeClass(o),t.addClass(s).removeClass(a)),r(t,e)}),e.each(function(){var t=w(this);0<n?(t.parent().removeClass(o),t.removeClass(a).addClass(s)):(t.parent().addClass(o),t.addClass(a).removeClass(s)),r(t,n)}))};window.setCommentsList=function(){var i,v=0,g=w('input[name="_total"]',"#comments-form"),l=w('input[name="_per_page"]',"#comments-form"),p=w('input[name="_page"]',"#comments-form"),y=function(t,e,n){e<v||(n&&(v=e),g.val(t.toString()))},t=function(t,e){var n,a,o,s=w("#"+e.element);!0!==e.parsed&&(o=e.parsed.responses[0]),a=w("#replyrow"),n=w("#comment_ID",a).val(),a=w("#replybtn",a),s.is(".unapproved")?(e.data.id==n&&a.text(c("Approve and Reply")),s.find(".row-actions span.view").addClass("hidden").end().find("div.comment_status").html("0")):(e.data.id==n&&a.text(d("Reply","verb")),s.find(".row-actions span.view").removeClass("hidden").end().find("div.comment_status").html("1")),i=w("#"+e.element).is("."+e.dimClass)?1:-1,o?(E(o.supplemental),R(o.supplemental),I(i,o.supplemental.postId),b(-1*i,o.supplemental.postId)):(I(i),b(-1*i))},e=function(t,e){var n,a,o,s,i=!1,r=w(t.target).attr("data-wp-lists");return t.data._total=g.val()||0,t.data._per_page=l.val()||0,t.data._page=p.val()||0,t.data._url=document.location.href,t.data.comment_status=w('input[name="comment_status"]',"#comments-form").val(),-1!=r.indexOf(":trash=1")?i="trash":-1!=r.indexOf(":spam=1")&&(i="spam"),i&&(n=r.replace(/.*?comment-([0-9]+).*/,"$1"),r=w("#comment-"+n),o=w("#"+i+"-undo-holder").html(),r.find(".check-column :checkbox").prop("checked",!1),r.siblings("#replyrow").length&&commentReply.cid==n&&commentReply.close(),a=r.is("tr")?(a=r.children(":visible").length,s=w(".author strong",r).text(),w('<tr id="undo-'+n+'" class="undo un'+i+'" style="display:none;"><td colspan="'+a+'">'+o+"</td></tr>")):(s=w(".comment-author",r).text(),w('<div id="undo-'+n+'" style="display:none;" class="undo un'+i+'">'+o+"</div>")),r.before(a),w("strong","#undo-"+n).text(s),(o=w(".undo a","#undo-"+n)).attr("href","comment.php?action=un"+i+"comment&c="+n+"&_wpnonce="+t.data._ajax_nonce),o.attr("data-wp-lists","delete:the-comment-list:comment-"+n+"::un"+i+"=1"),o.attr("class","vim-z vim-destructive aria-button-if-js"),w(".avatar",r).first().clone().prependTo("#undo-"+n+" ."+i+"-undo-inside"),o.on("click",function(t){t.preventDefault(),t.stopPropagation(),e.wpList.del(this),w("#undo-"+n).css({backgroundColor:"#ceb"}).fadeOut(350,function(){w(this).remove(),w("#comment-"+n).css("backgroundColor","").fadeIn(300,function(){w(this).show()})})})),t},n=function(t,e){var n,a,o,s,i=!0===e.parsed?{}:e.parsed.responses[0],r=!0===e.parsed?"":i.supplemental.status,l=!0===e.parsed?"":i.supplemental.postId,p=!0===e.parsed?"":i.supplemental,c=w(e.target).parent(),d=w("#"+e.element),m=d.hasClass("approved")&&!d.hasClass("unapproved"),u=d.hasClass("unapproved"),h=d.hasClass("spam"),d=d.hasClass("trash"),f=!1;E(p),R(p),c.is("span.undo")?(c.hasClass("unspam")?(n=-1,"trash"===r?a=1:"1"===r?s=1:"0Line truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(F,I){"use strict";var L=I(F),M=I(document),V=I("#wpadminbar"),N=I("#wpfooter");I(function(){var g,e,u=I("#postdivrich"),h=I("#wp-content-wrap"),m=I("#wp-content-editor-tools"),w=I(),H=I(),b=I("#ed_toolbar"),v=I("#content"),i=v[0],o=0,x=I("#post-status-info"),y=I(),T=I(),B=I("#side-sortables"),C=I("#postbox-container-1"),S=I("#post-body"),O=F.wp.editor&&F.wp.editor.fullscreen,r=function(){},l=function(){},z=!1,E=!1,k=!1,A=!1,W=0,K=56,R=20,Y=300,f=h.hasClass("tmce-active")?"tinymce":"html",U=!!parseInt(F.getUserSetting("hidetb"),10),D={windowHeight:0,windowWidth:0,adminBarHeight:0,toolsHeight:0,menuBarHeight:0,visualTopHeight:0,textTopHeight:0,bottomHeight:0,statusBarHeight:0,sideSortablesHeight:0},a=F._.throttle(function(){var t=F.scrollX||document.documentElement.scrollLeft,e=F.scrollY||document.documentElement.scrollTop,o=parseInt(i.style.height,10);i.style.height=Y+"px",i.scrollHeight>Y&&(i.style.height=i.scrollHeight+"px"),void 0!==t&&F.scrollTo(t,e),i.scrollHeight<o&&p()},300);function P(){var t=i.value.length;g&&!g.isHidden()||!g&&"tinymce"===f||(t<o?a():parseInt(i.style.height,10)<i.scrollHeight&&(i.style.height=Math.ceil(i.scrollHeight)+"px",p()),o=t)}function p(t){var e,o,i,n,s,f,a,d,c,u,r,l,p;O&&O.settings.visible||(e=L.scrollTop(),o="scroll"!==(u=t&&t.type),i=g&&!g.isHidden(),n=Y,s=S.offset().top,f=h.width(),!o&&D.windowHeight||(p=L.width(),(D={windowHeight:L.height(),windowWidth:p,adminBarHeight:600<p?V.outerHeight():0,toolsHeight:m.outerHeight()||0,menuBarHeight:y.outerHeight()||0,visualTopHeight:w.outerHeight()||0,textTopHeight:b.outerHeight()||0,bottomHeight:x.outerHeight()||0,statusBarHeight:T.outerHeight()||0,sideSortablesHeight:B.height()||0}).menuBarHeight<3&&(D.menuBarHeight=0)),i||"resize"!==u||P(),p=i?(a=w,l=H,D.visualTopHeight):(a=b,l=v,D.textTopHeight),(i||a.length)&&(u=a.parent().offset().top,r=l.offset().top,l=l.outerHeight(),(i?Y+p:Y+20)+5<l?((!z||o)&&e>=u-D.toolsHeight-D.adminBarHeight&&e<=u-D.toolsHeight-D.adminBarHeight+l-n?(z=!0,m.css({position:"fixed",top:D.adminBarHeight,width:f}),i&&y.length&&y.css({position:"fixed",top:D.adminBarHeight+D.toolsHeight,width:f-2-(i?0:a.outerWidth()-a.width())}),a.css({position:"fixed",top:D.adminBarHeight+D.toolsHeight+D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())})):(z||o)&&(e<=u-D.toolsHeight-D.adminBarHeight?(z=!1,m.css({position:"absolute",top:0,width:f}),i&&y.length&&y.css({position:"absolute",top:0,width:f-2}),a.css({position:"absolute",top:D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())})):e>=u-D.toolsHeight-D.adminBarHeight+l-n&&(z=!1,m.css({position:"absolute",top:l-n,width:f}),i&&y.length&&y.css({position:"absolute",top:l-n,width:f-2}),a.css({position:"absolute",top:l-n+D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())}))),(!E||o&&U)&&e+D.windowHeight<=r+l+D.bottomHeight+D.statusBarHeight+1?t&&0<t.deltaHeight&&t.deltaHeight<100?F.scrollBy(0,t.deltaHeight):i&&U&&(E=!0,T.css({position:"fixed",bottom:D.bottomHeight,visibility:"",width:f-2}),x.css({position:"fixed",bottom:0,width:f})):(!U&&E||(E||o)&&e+D.windowHeight>r+l+D.bottomHeight+D.statusBarHeight-1)&&(E=!1,T.attr("style",U?"":"visibility: hidden;"),x.attr("style",""))):o&&(m.css({position:"absolute",top:0,width:f}),i&&y.length&&y.css({position:"absolute",top:0,width:f-2}),a.css({position:"absolute",top:D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())}),T.attr("style",U?"":"visibility: hidden;"),x.attr("style","")),C.width()<300&&600<D.windowWidth&&M.height()>B.height()+s+120&&D.windowHeight<l?(D.sideSortablesHeight+K+R>D.windowHeight||k||A?e+K<=s?(B.attr("style",""),k=A=!1):W<e?k?(k=!1,d=B.offset().top-D.adminBarHeight,(c=N.offset().top)<d+D.sideSortablesHeight+R&&(d=c-D.sideSortablesHeight-12),B.css({position:"absolute",top:d,bottom:""})):!A&&D.sideSortablesHeight+B.offset().top+R<e+D.windowHeight&&(A=!0,B.css({position:"fixed",top:"auto",bottom:R})):e<W&&(A?(A=!1,d=B.offset().top-R,(c=N.offset().top)<d+D.sideSortablesHeight+R&&(d=c-D.sideSortablesHeight-12),B.css({position:"absolute",top:d,bottom:""})):!k&&B.offset().top>=e+K&&(k=!0,B.css({position:"fixed",top:K,bottom:""}))):(s-K<=e?B.css({position:"fixed",top:K}):B.attr("style",""),k=A=!1),W=e):(B.attr("style",""),k=A=!1),o)&&(h.css({paddingTop:D.toolsHeight}),i?H.css({paddingTop:D.visualTopHeight+D.menuBarHeight}):v.css({marginTop:D.textTopHeight})))}function n(){P(),p()}function X(t){for(var e=1;e<6;e++)setTimeout(t,500*e)}function t(){F.pageYOffset&&130<F.pageYOffset&&F.scrollTo(F.pageXOffset,0),u.addClass("wp-editor-expand"),L.on("scroll.editor-expand resize.editor-expand",function(t){p(t.type),clearTimeout(e),e=setTimeout(p,100)}),M.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",p).on("postbox-toggled.editor-expand postbox-moved.editor-expand",function(){!k&&!A&&F.pageYOffset>K&&(A=!0,F.scrollBy(0,-1),p(),F.scrollBy(0,1)),p()}).on("wp-window-resized.editor-expand",function(){g&&!g.isHidden()?g.execCommand("wpAutoResizeLine truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},function(g,u){u.editor=u.editor||{},window.switchEditors=new function(){var v,x,t={};function e(){!v&&window.tinymce&&(v=window.tinymce,(x=v.$)(document).on("click",function(e){e=x(e.target);e.hasClass("wp-switch-editor")&&n(e.attr("data-wp-editor-id"),e.hasClass("switch-tmce")?"tmce":"html")}))}function E(e){e=x(".mce-toolbar-grp",e.getContainer())[0],e=e&&e.clientHeight;return e&&10<e&&e<200?parseInt(e,10):30}function n(e,t){t=t||"toggle";var n,r,i,a,o,c,s,d,p,l,g,u=v.get(e=e||"content"),w=x("#wp-"+e+"-wrap"),f=w.find(".switch-tmce"),m=w.find(".switch-html"),h=x("#"+e),b=h[0];if("tmce"===(t="toggle"===t?u&&!u.isHidden()?"html":"tmce":t)||"tinymce"===t){if(u&&!u.isHidden())return!1;void 0!==window.QTags&&window.QTags.closeAllTags(e),n=parseInt(b.style.height,10)||0,(o=h)&&o.length&&(o=o[0],s=function(e,t){var n=t.cursorStart,t=t.cursorEnd,r=y(e,n);r&&(n=-1!==["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(r.tagType)?r.ltPos:r.gtPos);r=y(e,t);r&&(t=r.gtPos);r=S(e,n);r&&!r.showAsPlainText&&(n=r.urlAtStartOfContent?r.endIndex:r.startIndex);r=S(e,t);r&&!r.showAsPlainText&&(t=r.urlAtEndOfContent?r.startIndex:r.endIndex);return{cursorStart:n,cursorEnd:t}}(o.value,{cursorStart:o.selectionStart,cursorEnd:o.selectionEnd}),c=s.cursorStart,l=c!==(s=s.cursorEnd)?"range":"single",d=null,p=$(x,"").attr("data-mce-type","bookmark"),"range"==l&&(l=o.value.slice(c,s),g=p.clone().addClass("mce_SELRES_end"),d=[l,g[0].outerHTML].join("")),o.value=[o.value.slice(0,c),p.clone().addClass("mce_SELRES_start")[0].outerHTML,d,o.value.slice(s)].join("")),u?(u.show(),!v.Env.iOS&&n&&50<(n=n-E(u)+14)&&n<5e3&&u.theme.resizeTo(null,n),_(u)):v.init(window.tinyMCEPreInit.mceInit[e]),w.removeClass("html-active").addClass("tmce-active"),m.attr("aria-pressed",!1),f.attr("aria-pressed",!0),h.attr("aria-hidden",!0),window.setUserSetting("editor","tinymce")}else if("html"===t){if(u&&u.isHidden())return!1;u?(v.Env.iOS||(n=(l=u.iframeElement)?parseInt(l.style.height,10):0)&&50<(n=n+E(u)-14)&&n<5e3&&(b.style.height=n+"px"),g=null,g=function(e){var t,n,r,i,a,o,c,s=e.getWin().getSelection();if(s&&!(s.rangeCount<1))return c="SELRES_"+Math.random(),o=$(e.$,c),a=o.clone().addClass("mce_SELRES_start"),o=o.clone().addClass("mce_SELRES_end"),i=s.getRangeAt(0),t=i.startContainer,n=i.startOffset,r=i.cloneRange(),0<e.$(t).parents(".mce-offscreen-selection").length?(t=e.$("[data-mce-selected]")[0],a.attr("data-mce-object-selection","true"),o.attr("data-mce-object-selection","true"),e.$(t).before(a[0]),e.$(t).after(o[0])):(r.collapse(!1),r.insertNode(o[0]),r.setStart(t,n),r.collapse(!0),r.insertNode(a[0]),i.setStartAfter(a[0]),i.setEndBefore(o[0]),s.removeAllRanges(),s.addRange(i)),e.on("GetContent",k),t=R(e.getContent()),e.off("GetContent",k),a.remove(),o.remove(),n=new RegExp('<span[^>]*\\s*class="mce_SELRES_start"[^>]+>\\s*'+c+"[^<]*<\\/span>(\\s*)"),r=new RegExp('(\\s*)<span[^>]*\\s*class="mce_SELRES_end"[^>]+>\\s*'+c+"[^<]*<\\/span>"),s=t.match(n),i=t.match(r),s?(e=s.index,a=s[0].length,o=null,i&&(-1!==s[0].indexOf("data-mce-object-selection")&&(a-=s[1].length),c=i.index,-1!==i[0].indexOf("data-mce-object-selection")&&(c-=i[1].length),o=c-a),{start:e,end:o}):null}(u),u.hide(),g&&(c=u,p=g)&&(r=c.getElement(),i=p.start,a=p.end||p.start,r.focus)&&setTimeout(function(){r.setSelectionRange(i,a),r.blur&&r.blur(),r.focus()},100)):h.css({display:"",visibility:""}),w.removeClass("tmce-active").addClass("html-active"),m.attr("aria-pressed",!0),f.attr("aria-pressed",!1),h.attr("aria-hidden",!1),window.setUserSetting("editor","html")}}function y(e,t){var n,r=e.lastIndexOf("<",t-1);return(e.lastIndexOf(">",t)<r||">"===e.substr(t,1))&&(e=(t=e.substr(r)).match(/<\s*(\/)?(\w+|\!-{2}.*-{2})/))?(n=e[2],{ltPos:r,gtPos:r+t.indexOf(">")+1,tagType:n,isClosingTag:!!e[1]}):null}function S(e,t){for(var n=function(e){var t,n=function(e){var t=e.match(/\[+([\w_-])+/g),n=[];if(t)for(var r=0;r<t.length;r++){var i=t[r].replace(/^\[+/g,"");-1===n.indexOf(i)&&n.push(i)}return n}(e);if(0===n.length)return[];var r,i=u.shortcode.regexp(n.join("|")),a=[];for(;r=i.exec(e);){var o="["===r[1];t={shortcodeName:r[2],showAsPlainText:o,startIndex:r.index,endIndex:r.index+r[0].length,length:r[0].length},a.push(t)}var c=new RegExp('(^|[\\n\\r][\\n\\r]|<p>)(https?:\\/\\/[^s"]+?)(<\\/p>s*|[\\n\\r][\\n\\r]|$)',"gi");for(;r=c.exec(e);)t={shortcodeName:"url",showAsPlainText:!1,startIndex:r.index,endIndex:r.index+r[0].length,length:r[0].length,urlAtStartOfContent:""===r[1],urlAtEndOfContent:""===r[3]},a.push(t);return a}(e),r=0;r<n.length;r++){var i=n[r];if(t>=i.startIndex&&t<=i.endIndex)return i}}function $(e,t){return e("<span>").css({display:"inline-block",width:0,overflow:"hidden","line-height":0}).html(t||"")}function _(e){var t,n=e.$(".mce_SELRES_start").attr("data-mce-bogus",1),r=e.$(".mce_SELRES_end").attr("data-mce-bogus",1),i=(n.length&&(e.focus(),r.length?((i=e.getDoc().createRange()).setStartAfterLine truncated
|
||||
@@ -0,0 +1,282 @@
|
||||
/*!
|
||||
* Farbtastic: jQuery color picker plug-in v1.3u
|
||||
* https://github.com/mattfarina/farbtastic
|
||||
*
|
||||
* Licensed under the GPL license:
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
/**
|
||||
* Modified for WordPress: replaced deprecated jQuery methods.
|
||||
* See https://core.trac.wordpress.org/ticket/57946.
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.fn.farbtastic = function (options) {
|
||||
$.farbtastic(this, options);
|
||||
return this;
|
||||
};
|
||||
|
||||
$.farbtastic = function (container, callback) {
|
||||
var container = $(container).get(0);
|
||||
return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback));
|
||||
};
|
||||
|
||||
$._farbtastic = function (container, callback) {
|
||||
// Store farbtastic object
|
||||
var fb = this;
|
||||
|
||||
// Insert markup
|
||||
$(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');
|
||||
var e = $('.farbtastic', container);
|
||||
fb.wheel = $('.wheel', container).get(0);
|
||||
// Dimensions
|
||||
fb.radius = 84;
|
||||
fb.square = 100;
|
||||
fb.width = 194;
|
||||
|
||||
// Fix background PNGs in IE6
|
||||
if (navigator.appVersion.match(/MSIE [0-6]\./)) {
|
||||
$('*', e).each(function () {
|
||||
if (this.currentStyle.backgroundImage != 'none') {
|
||||
var image = this.currentStyle.backgroundImage;
|
||||
image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
|
||||
$(this).css({
|
||||
'backgroundImage': 'none',
|
||||
'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the given element(s) or callback.
|
||||
*/
|
||||
fb.linkTo = function (callback) {
|
||||
// Unbind previous nodes
|
||||
if (typeof fb.callback == 'object') {
|
||||
$(fb.callback).off('keyup', fb.updateValue);
|
||||
}
|
||||
|
||||
// Reset color
|
||||
fb.color = null;
|
||||
|
||||
// Bind callback or elements
|
||||
if (typeof callback == 'function') {
|
||||
fb.callback = callback;
|
||||
}
|
||||
else if (typeof callback == 'object' || typeof callback == 'string') {
|
||||
fb.callback = $(callback);
|
||||
fb.callback.on('keyup', fb.updateValue);
|
||||
if (fb.callback.get(0).value) {
|
||||
fb.setColor(fb.callback.get(0).value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
fb.updateValue = function (event) {
|
||||
if (this.value && this.value != fb.color) {
|
||||
fb.setColor(this.value);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Change color with HTML syntax #123456
|
||||
*/
|
||||
fb.setColor = function (color) {
|
||||
var unpack = fb.unpack(color);
|
||||
if (fb.color != color && unpack) {
|
||||
fb.color = color;
|
||||
fb.rgb = unpack;
|
||||
fb.hsl = fb.RGBToHSL(fb.rgb);
|
||||
fb.updateDisplay();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Change color with HSL triplet [0..1, 0..1, 0..1]
|
||||
*/
|
||||
fb.setHSL = function (hsl) {
|
||||
fb.hsl = hsl;
|
||||
fb.rgb = fb.HSLToRGB(hsl);
|
||||
fb.color = fb.pack(fb.rgb);
|
||||
fb.updateDisplay();
|
||||
return this;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Retrieve the coordinates of the given event relative to the center
|
||||
* of the widget.
|
||||
*/
|
||||
fb.widgetCoords = function (event) {
|
||||
var offset = $(fb.wheel).offset();
|
||||
return { x: (event.pageX - offset.left) - fb.width / 2, y: (event.pageY - offset.top) - fb.width / 2 };
|
||||
};
|
||||
|
||||
/**
|
||||
* Mousedown handler
|
||||
*/
|
||||
fb.mousedown = function (event) {
|
||||
// Capture mouse
|
||||
if (!document.dragging) {
|
||||
$(document).on('mousemove', fb.mousemove).on('mouseup', fb.mouseup);
|
||||
document.dragging = true;
|
||||
}
|
||||
|
||||
// Check which area is being dragged
|
||||
var pos = fb.widgetCoords(event);
|
||||
fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square;
|
||||
|
||||
// Process
|
||||
fb.mousemove(event);
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mousemove handler
|
||||
*/
|
||||
fb.mousemove = function (event) {
|
||||
// Get coordinates relative to color picker center
|
||||
var pos = fb.widgetCoords(event);
|
||||
|
||||
// Set new HSL parameters
|
||||
if (fb.circleDrag) {
|
||||
var hue = Math.atan2(pos.x, -pos.y) / 6.28;
|
||||
if (hue < 0) hue += 1;
|
||||
fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]);
|
||||
}
|
||||
else {
|
||||
var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5));
|
||||
var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5));
|
||||
fb.setHSL([fb.hsl[0], sat, lum]);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mouseup handler
|
||||
*/
|
||||
fb.mouseup = function () {
|
||||
// Uncapture mouse
|
||||
$(document).off('mousemove', fb.mousemove);
|
||||
$(document).off('mouseup', fb.mouseup);
|
||||
document.dragging = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the markers and styles
|
||||
*/
|
||||
fb.updateDisplay = function () {
|
||||
// Markers
|
||||
var angle = fb.hsl[0] * 6.28;
|
||||
$('.h-marker', e).css({
|
||||
left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px',
|
||||
top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px'
|
||||
});
|
||||
|
||||
$('.sl-marker', e).css({
|
||||
left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px',
|
||||
top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px'
|
||||
});
|
||||
|
||||
// Saturation/Luminance gradient
|
||||
$('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5])));
|
||||
|
||||
// Linked elements or callback
|
||||
if (typeof fb.callback == 'object') {
|
||||
// Set background/foreground color
|
||||
$(fb.callback).css({
|
||||
backgroundColor: fb.color,
|
||||
color: fb.hsl[2] > 0.5 ? '#000' : '#fff'
|
||||
});
|
||||
|
||||
// Change linked value
|
||||
$(fb.callback).each(function() {
|
||||
if (this.value && this.value != fb.color) {
|
||||
this.value = fb.color;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (typeof fb.callback == 'function') {
|
||||
fb.callback.call(fb, fb.color);
|
||||
}
|
||||
};
|
||||
|
||||
/* Various color utility functions */
|
||||
fb.pack = function (rgb) {
|
||||
var r = Math.round(rgb[0] * 255);
|
||||
var g = Math.round(rgb[1] * 255);
|
||||
var b = Math.round(rgb[2] * 255);
|
||||
return '#' + (r < 16 ? '0' : '') + r.toString(16) +
|
||||
(g < 16 ? '0' : '') + g.toString(16) +
|
||||
(b < 16 ? '0' : '') + b.toString(16);
|
||||
};
|
||||
|
||||
fb.unpack = function (color) {
|
||||
if (color.length == 7) {
|
||||
return [parseInt('0x' + color.substring(1, 3)) / 255,
|
||||
parseInt('0x' + color.substring(3, 5)) / 255,
|
||||
parseInt('0x' + color.substring(5, 7)) / 255];
|
||||
}
|
||||
else if (color.length == 4) {
|
||||
return [parseInt('0x' + color.substring(1, 2)) / 15,
|
||||
parseInt('0x' + color.substring(2, 3)) / 15,
|
||||
parseInt('0x' + color.substring(3, 4)) / 15];
|
||||
}
|
||||
};
|
||||
|
||||
fb.HSLToRGB = function (hsl) {
|
||||
var m1, m2, r, g, b;
|
||||
var h = hsl[0], s = hsl[1], l = hsl[2];
|
||||
m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s;
|
||||
m1 = l * 2 - m2;
|
||||
return [this.hueToRGB(m1, m2, h+0.33333),
|
||||
this.hueToRGB(m1, m2, h),
|
||||
this.hueToRGB(m1, m2, h-0.33333)];
|
||||
};
|
||||
|
||||
fb.hueToRGB = function (m1, m2, h) {
|
||||
h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
|
||||
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
|
||||
if (h * 2 < 1) return m2;
|
||||
if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
|
||||
return m1;
|
||||
};
|
||||
|
||||
fb.RGBToHSL = function (rgb) {
|
||||
var min, max, delta, h, s, l;
|
||||
var r = rgb[0], g = rgb[1], b = rgb[2];
|
||||
min = Math.min(r, Math.min(g, b));
|
||||
max = Math.max(r, Math.max(g, b));
|
||||
delta = max - min;
|
||||
l = (min + max) / 2;
|
||||
s = 0;
|
||||
if (l > 0 && l < 1) {
|
||||
s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
|
||||
}
|
||||
h = 0;
|
||||
if (delta > 0) {
|
||||
if (max == r && max != g) h += (g - b) / delta;
|
||||
if (max == g && max != b) h += (2 + (b - r) / delta);
|
||||
if (max == b && max != r) h += (4 + (r - g) / delta);
|
||||
h /= 6;
|
||||
}
|
||||
return [h, s, l];
|
||||
};
|
||||
|
||||
// Install mousedown handler (the others are set on the document on-demand)
|
||||
$('*', e).on('mousedown', fb.mousedown);
|
||||
|
||||
// Init color
|
||||
fb.setColor('#000000');
|
||||
|
||||
// Set linked elements/callback
|
||||
if (callback) {
|
||||
fb.linkTo(callback);
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,239 @@
|
||||
/**
|
||||
* @output wp-admin/js/gallery.js
|
||||
*/
|
||||
|
||||
/* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */
|
||||
|
||||
jQuery( function($) {
|
||||
var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
|
||||
|
||||
gallerySortableInit = function() {
|
||||
gallerySortable = $('#media-items').sortable( {
|
||||
items: 'div.media-item',
|
||||
placeholder: 'sorthelper',
|
||||
axis: 'y',
|
||||
distance: 2,
|
||||
handle: 'div.filename',
|
||||
stop: function() {
|
||||
// When an update has occurred, adjust the order for each item.
|
||||
var all = $('#media-items').sortable('toArray'), len = all.length;
|
||||
$.each(all, function(i, id) {
|
||||
var order = desc ? (len - i) : (1 + i);
|
||||
$('#' + id + ' .menu_order input').val(order);
|
||||
});
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
sortIt = function() {
|
||||
var all = $('.menu_order_input'), len = all.length;
|
||||
all.each(function(i){
|
||||
var order = desc ? (len - i) : (1 + i);
|
||||
$(this).val(order);
|
||||
});
|
||||
};
|
||||
|
||||
clearAll = function(c) {
|
||||
c = c || 0;
|
||||
$('.menu_order_input').each( function() {
|
||||
if ( this.value === '0' || c ) {
|
||||
this.value = '';
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$('#asc').on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
desc = false;
|
||||
sortIt();
|
||||
});
|
||||
$('#desc').on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
desc = true;
|
||||
sortIt();
|
||||
});
|
||||
$('#clear').on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
clearAll(1);
|
||||
});
|
||||
$('#showall').on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
$('#sort-buttons span a').toggle();
|
||||
$('a.describe-toggle-on').hide();
|
||||
$('a.describe-toggle-off, table.slidetoggle').show();
|
||||
$('img.pinkynail').toggle(false);
|
||||
});
|
||||
$('#hideall').on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
$('#sort-buttons span a').toggle();
|
||||
$('a.describe-toggle-on').show();
|
||||
$('a.describe-toggle-off, table.slidetoggle').hide();
|
||||
$('img.pinkynail').toggle(true);
|
||||
});
|
||||
|
||||
// Initialize sortable.
|
||||
gallerySortableInit();
|
||||
clearAll();
|
||||
|
||||
if ( $('#media-items>*').length > 1 ) {
|
||||
w = wpgallery.getWin();
|
||||
|
||||
$('#save-all, #gallery-settings').show();
|
||||
if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
|
||||
wpgallery.mcemode = true;
|
||||
wpgallery.init();
|
||||
} else {
|
||||
$('#insert-gallery').show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* gallery settings */
|
||||
window.tinymce = null;
|
||||
|
||||
window.wpgallery = {
|
||||
mcemode : false,
|
||||
editor : {},
|
||||
dom : {},
|
||||
is_update : false,
|
||||
el : {},
|
||||
|
||||
I : function(e) {
|
||||
return document.getElementById(e);
|
||||
},
|
||||
|
||||
init: function() {
|
||||
var t = this, li, q, i, it, w = t.getWin();
|
||||
|
||||
if ( ! t.mcemode ) {
|
||||
return;
|
||||
}
|
||||
|
||||
li = ('' + document.location.search).replace(/^\?/, '').split('&');
|
||||
q = {};
|
||||
for (i=0; i<li.length; i++) {
|
||||
it = li[i].split('=');
|
||||
q[unescape(it[0])] = unescape(it[1]);
|
||||
}
|
||||
|
||||
if ( q.mce_rdomain ) {
|
||||
document.domain = q.mce_rdomain;
|
||||
}
|
||||
|
||||
// Find window & API.
|
||||
window.tinymce = w.tinymce;
|
||||
window.tinyMCE = w.tinyMCE;
|
||||
t.editor = tinymce.EditorManager.activeEditor;
|
||||
|
||||
t.setup();
|
||||
},
|
||||
|
||||
getWin : function() {
|
||||
return window.dialogArguments || opener || parent || top;
|
||||
},
|
||||
|
||||
setup : function() {
|
||||
var t = this, a, ed = t.editor, g, columns, link, order, orderby;
|
||||
if ( ! t.mcemode ) {
|
||||
return;
|
||||
}
|
||||
|
||||
t.el = ed.selection.getNode();
|
||||
|
||||
if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
|
||||
if ( ( g = ed.dom.select('img.wpGallery') ) && g[0] ) {
|
||||
t.el = g[0];
|
||||
} else {
|
||||
if ( getUserSetting('galfile') === '1' ) {
|
||||
t.I('linkto-file').checked = 'checked';
|
||||
}
|
||||
if ( getUserSetting('galdesc') === '1' ) {
|
||||
t.I('order-desc').checked = 'checked';
|
||||
}
|
||||
if ( getUserSetting('galcols') ) {
|
||||
t.I('columns').value = getUserSetting('galcols');
|
||||
}
|
||||
if ( getUserSetting('galord') ) {
|
||||
t.I('orderby').value = getUserSetting('galord');
|
||||
}
|
||||
jQuery('#insert-gallery').show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
a = ed.dom.getAttrib(t.el, 'title');
|
||||
a = ed.dom.decode(a);
|
||||
|
||||
if ( a ) {
|
||||
jQuery('#update-gallery').show();
|
||||
t.is_update = true;
|
||||
|
||||
columns = a.match(/columns=['"]([0-9]+)['"]/);
|
||||
link = a.match(/link=['"]([^'"]+)['"]/i);
|
||||
order = a.match(/order=['"]([^'"]+)['"]/i);
|
||||
orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
|
||||
|
||||
if ( link && link[1] ) {
|
||||
t.I('linkto-file').checked = 'checked';
|
||||
}
|
||||
if ( order && order[1] ) {
|
||||
t.I('order-desc').checked = 'checked';
|
||||
}
|
||||
if ( columns && columns[1] ) {
|
||||
t.I('columns').value = '' + columns[1];
|
||||
}
|
||||
if ( orderby && orderby[1] ) {
|
||||
t.I('orderby').value = orderby[1];
|
||||
}
|
||||
} else {
|
||||
jQuery('#insert-gallery').show();
|
||||
}
|
||||
},
|
||||
|
||||
update : function() {
|
||||
var t = this, ed = t.editor, all = '', s;
|
||||
|
||||
if ( ! t.mcemode || ! t.is_update ) {
|
||||
s = '[gallery' + t.getSettings() + ']';
|
||||
t.getWin().send_to_editor(s);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( t.el.nodeName !== 'IMG' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
|
||||
all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
|
||||
all += t.getSettings();
|
||||
|
||||
ed.dom.setAttrib(t.el, 'title', all);
|
||||
t.getWin().tb_remove();
|
||||
},
|
||||
|
||||
getSettings : function() {
|
||||
var I = this.I, s = '';
|
||||
|
||||
if ( I('linkto-file').checked ) {
|
||||
s += ' link="file"';
|
||||
setUserSetting('galfile', '1');
|
||||
}
|
||||
|
||||
if ( I('order-desc').checked ) {
|
||||
s += ' order="DESC"';
|
||||
setUserSetting('galdesc', '1');
|
||||
}
|
||||
|
||||
if ( I('columns').value !== 3 ) {
|
||||
s += ' columns="' + I('columns').value + '"';
|
||||
setUserSetting('galcols', I('columns').value);
|
||||
}
|
||||
|
||||
if ( I('orderby').value !== 'menu_order' ) {
|
||||
s += ' orderby="' + I('orderby').value + '"';
|
||||
setUserSetting('galord', I('orderby').value);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
};
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(n){var o=!1,e=function(){n("#media-items").sortable({items:"div.media-item",placeholder:"sorthelper",axis:"y",distance:2,handle:"div.filename",stop:function(){var e=n("#media-items").sortable("toArray"),i=e.length;n.each(e,function(e,t){e=o?i-e:1+e;n("#"+t+" .menu_order input").val(e)})}})},t=function(){var e=n(".menu_order_input"),t=e.length;e.each(function(e){e=o?t-e:1+e;n(this).val(e)})},i=function(e){e=e||0,n(".menu_order_input").each(function(){"0"!==this.value&&!e||(this.value="")})};n("#asc").on("click",function(e){e.preventDefault(),o=!1,t()}),n("#desc").on("click",function(e){e.preventDefault(),o=!0,t()}),n("#clear").on("click",function(e){e.preventDefault(),i(1)}),n("#showall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").hide(),n("a.describe-toggle-off, table.slidetoggle").show(),n("img.pinkynail").toggle(!1)}),n("#hideall").on("click",function(e){e.preventDefault(),n("#sort-buttons span a").toggle(),n("a.describe-toggle-on").show(),n("a.describe-toggle-off, table.slidetoggle").hide(),n("img.pinkynail").toggle(!0)}),e(),i(),1<n("#media-items>*").length&&(e=wpgallery.getWin(),n("#save-all, #gallery-settings").show(),void 0!==e.tinyMCE&&e.tinyMCE.activeEditor&&!e.tinyMCE.activeEditor.isHidden()?(wpgallery.mcemode=!0,wpgallery.init()):n("#insert-gallery").show())}),window.tinymce=null,window.wpgallery={mcemode:!1,editor:{},dom:{},is_update:!1,el:{},I:function(e){return document.getElementById(e)},init:function(){var e,t,i,n,o=this,l=o.getWin();if(o.mcemode){for(e=(""+document.location.search).replace(/^\?/,"").split("&"),t={},i=0;i<e.length;i++)n=e[i].split("="),t[unescape(n[0])]=unescape(n[1]);t.mce_rdomain&&(document.domain=t.mce_rdomain),window.tinymce=l.tinymce,window.tinyMCE=l.tinyMCE,o.editor=tinymce.EditorManager.activeEditor,o.setup()}},getWin:function(){return window.dialogArguments||opener||parent||top},setup:function(){var e,t,i,n=this,o=n.editor;if(n.mcemode){if(n.el=o.selection.getNode(),"IMG"!==n.el.nodeName||!o.dom.hasClass(n.el,"wpGallery")){if(!(i=o.dom.select("img.wpGallery"))||!i[0])return"1"===getUserSetting("galfile")&&(n.I("linkto-file").checked="checked"),"1"===getUserSetting("galdesc")&&(n.I("order-desc").checked="checked"),getUserSetting("galcols")&&(n.I("columns").value=getUserSetting("galcols")),getUserSetting("galord")&&(n.I("orderby").value=getUserSetting("galord")),void jQuery("#insert-gallery").show();n.el=i[0]}i=o.dom.getAttrib(n.el,"title"),(i=o.dom.decode(i))?(jQuery("#update-gallery").show(),n.is_update=!0,o=i.match(/columns=['"]([0-9]+)['"]/),e=i.match(/link=['"]([^'"]+)['"]/i),t=i.match(/order=['"]([^'"]+)['"]/i),i=i.match(/orderby=['"]([^'"]+)['"]/i),e&&e[1]&&(n.I("linkto-file").checked="checked"),t&&t[1]&&(n.I("order-desc").checked="checked"),o&&o[1]&&(n.I("columns").value=""+o[1]),i&&i[1]&&(n.I("orderby").value=i[1])):jQuery("#insert-gallery").show()}},update:function(){var e=this,t=e.editor,i="";e.mcemode&&e.is_update?"IMG"===e.el.nodeName&&(i=(i=t.dom.decode(t.dom.getAttrib(e.el,"title"))).replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi,""),i+=e.getSettings(),t.dom.setAttrib(e.el,"title",i),e.getWin().tb_remove()):(t="[gallery"+e.getSettings()+"]",e.getWin().send_to_editor(t))},getSettings:function(){var e=this.I,t="";return e("linkto-file").checked&&(t+=' link="file"',setUserSetting("galfile","1")),e("order-desc").checked&&(t+=' order="DESC"',setUserSetting("galdesc","1")),3!==e("columns").value&&(t+=' columns="'+e("columns").value+'"',setUserSetting("galcols",e("columns").value)),"menu_order"!==e("orderby").value&&(t+=' orderby="'+e("orderby").value+'"',setUserSetting("galord",e("orderby").value)),t}};
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(c){var s=wp.i18n.__,d=window.imageEdit={iasapi:{},hold:{},postid:"",_view:!1,toggleCropTool:function(t,i,e){var a,o,r,n=c("#image-preview-"+t),s=this.iasapi.getSelection();d.toggleControls(e),"false"==("true"===c(e).attr("aria-expanded")?"true":"false")?(this.iasapi.cancelSelection(),d.setDisabled(c(".imgedit-crop-clear"),0)):(d.setDisabled(c(".imgedit-crop-clear"),1),e=c("#imgedit-start-x-"+t).val()?c("#imgedit-start-x-"+t).val():0,a=c("#imgedit-start-y-"+t).val()?c("#imgedit-start-y-"+t).val():0,o=c("#imgedit-sel-width-"+t).val()?c("#imgedit-sel-width-"+t).val():n.innerWidth(),r=c("#imgedit-sel-height-"+t).val()?c("#imgedit-sel-height-"+t).val():n.innerHeight(),isNaN(s.x1)&&(this.setCropSelection(t,{x1:e,y1:a,x2:o,y2:r,width:o,height:r}),s=this.iasapi.getSelection()),0===s.x1&&0===s.y1&&0===s.x2&&0===s.y2?this.iasapi.setSelection(0,0,n.innerWidth(),n.innerHeight(),!0):this.iasapi.setSelection(e,a,o,r,!0),this.iasapi.setOptions({show:!0}),this.iasapi.update())},handleCropToolClick:function(t,i,e){e.classList.contains("imgedit-crop-clear")?(this.iasapi.cancelSelection(),d.setDisabled(c(".imgedit-crop-apply"),0),c("#imgedit-sel-width-"+t).val(""),c("#imgedit-sel-height-"+t).val(""),c("#imgedit-start-x-"+t).val("0"),c("#imgedit-start-y-"+t).val("0"),c("#imgedit-selection-"+t).val("")):d.crop(t,i,e)},intval:function(t){return 0|t},setDisabled:function(t,i){i?t.removeClass("disabled").prop("disabled",!1):t.addClass("disabled").prop("disabled",!0)},init:function(e){var t=this,i=c("#image-editor-"+t.postid);t.postid!==e&&i.length&&t.close(t.postid),t.hold.sizer=parseFloat(c("#imgedit-sizer-"+e).val()),t.postid=e,c("#imgedit-response-"+e).empty(),c("#imgedit-panel-"+e).on("keypress",function(t){var i=c("#imgedit-nonce-"+e).val();26===t.which&&t.ctrlKey&&d.undo(e,i),25===t.which&&t.ctrlKey&&d.redo(e,i)}),c("#imgedit-panel-"+e).on("keypress",'input[type="text"]',function(t){var i=t.keyCode;if(36<i&&i<41&&c(this).trigger("blur"),13===i)return t.preventDefault(),t.stopPropagation(),!1}),c(document).on("image-editor-ui-ready",this.focusManager)},calculateImgSize:function(t){var i=this,e=i.intval(c("#imgedit-x-"+t).val()),a=i.intval(c("#imgedit-y-"+t).val());i.hold.w=i.hold.ow=e,i.hold.h=i.hold.oh=a,i.hold.xy_ratio=e/a,i.hold.sizer=parseFloat(c("#imgedit-sizer-"+t).val()),i.currentCropSelection=null},toggleEditor:function(t,i,e){t=c("#imgedit-wait-"+t);i?t.fadeIn("fast"):t.fadeOut("fast",function(){e&&c(document).trigger("image-editor-ui-ready")})},togglePopup:function(t){var i=c(t),t=c(t).attr("aria-controls"),t=c("#"+t);return i.attr("aria-expanded","false"===i.attr("aria-expanded")?"true":"false"),t.toggleClass("imgedit-popup-menu-open").slideToggle("fast").css({"z-index":2e5}),"true"===i.attr("aria-expanded")&&t.find("button").first().trigger("focus"),!1},monitorPopup:function(){var e=document.querySelector(".imgedit-rotate-menu-container"),a=document.querySelector(".imgedit-rotate-menu-container .imgedit-rotate");return setTimeout(function(){var t=document.activeElement,i=e.contains(t);t&&!i&&"true"===a.getAttribute("aria-expanded")&&d.togglePopup(a)},100),!1},browsePopup:function(t,i){var e=c(i),i=c(i).parent(".imgedit-popup-menu").find("button"),e=i.index(e),a=e-1,e=e+1,o=i.length,o=(a<0&&(a=o-1),e===o&&(e=0),!1);return 40===t.keyCode?o=i.get(e):38===t.keyCode&&(o=i.get(a)),o&&(o.focus(),t.preventDefault()),!1},closePopup:function(t){var t=c(t).parent(".imgedit-popup-menu"),i=t.attr("id");return c('button[aria-controls="'+i+'"]').attr("aria-expanded","false").trigger("focus"),t.toggleClass("imgedit-popup-menu-open").slideToggle("fast"),!1},toggleHelp:function(t){t=c(t);return t.attr("aria-expanded","false"===t.attr("aria-expanded")?"true":"false").parents(".imgedit-group-top").toggleClass("imgedit-help-toggled").find(".imgedit-help").slideToggle("fast"),!1},toggleControls:function(t){var t=c(t),i=c("#"+t.attr("aria-controls"));return t.attr("aria-expanded","false"===t.attr("aria-expanded")?"true":"false"),i.parent(".imgedit-group").toggleClass("imgedit-panel-active"),!1},getTarget:function(t){var i=c("#imgedit-save-target-"+t);return i.length?i.find('input[name="imgedit-target-'+t+'"]:checked').val()||"full":"all"},scaleChanged:function(t,i,e){var a=c("#imgedit-scale-width-"+t),o=c("#imgedit-scale-height-"+t),t=c("#imgedit-scale-warn-"+t),r="",n="",s=c("#imgedit-scale-button");!1!==this.validateNumeric(e)&&(i?(n=""!==a.val()?Math.round(a.val()/this.hold.xy_ratio):"",o.val(n)):(r=""!==o.val()?Math.round(o.val()*this.hold.xy_ratio):"",a.val(r)),n&&n>this.hold.oh||r&&r>this.hold.ow?(t.css("visibility","visible"),s.prop("disabled",!0)):(t.css("visibility","hidden"),s.prop("disabled",!1)))},getSelRatio:function(t){var i=this.hold.w,e=this.hold.h,a=this.intval(c("#imgedit-crop-width-"+t).val()),t=this.intval(c("#imgedit-crop-height-"+t).val());return a&&t?a+":"+t:i&&e?i+":"+e:"1:1"},filterHistory:function(t,i){var e,a,o,r=c("#imgedit-history-"+t).val(),n=[];if(""===r)return"";if(r=JSON.parse(r),0<(e=this.intLine truncated
|
||||
@@ -0,0 +1,659 @@
|
||||
/**
|
||||
* This file contains the functions needed for the inline editing of posts.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @output wp-admin/js/inline-edit-post.js
|
||||
*/
|
||||
|
||||
/* global ajaxurl, typenow, inlineEditPost */
|
||||
|
||||
window.wp = window.wp || {};
|
||||
|
||||
/**
|
||||
* Manages the quick edit and bulk edit windows for editing posts or pages.
|
||||
*
|
||||
* @namespace inlineEditPost
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @type {Object}
|
||||
*
|
||||
* @property {string} type The type of inline editor.
|
||||
* @property {string} what The prefix before the post ID.
|
||||
*
|
||||
*/
|
||||
( function( $, wp ) {
|
||||
|
||||
window.inlineEditPost = {
|
||||
|
||||
/**
|
||||
* Initializes the inline and bulk post editor.
|
||||
*
|
||||
* Binds event handlers to the Escape key to close the inline editor
|
||||
* and to the save and close buttons. Changes DOM to be ready for inline
|
||||
* editing. Adds event handler to bulk edit.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditPost
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
init : function(){
|
||||
var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
|
||||
|
||||
t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post';
|
||||
// Post ID prefix.
|
||||
t.what = '#post-';
|
||||
|
||||
/**
|
||||
* Binds the Escape key to revert the changes and close the quick editor.
|
||||
*
|
||||
* @return {boolean} The result of revert.
|
||||
*/
|
||||
qeRow.on( 'keyup', function(e){
|
||||
// Revert changes if Escape key is pressed.
|
||||
if ( e.which === 27 ) {
|
||||
return inlineEditPost.revert();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Binds the Escape key to revert the changes and close the bulk editor.
|
||||
*
|
||||
* @return {boolean} The result of revert.
|
||||
*/
|
||||
bulkRow.on( 'keyup', function(e){
|
||||
// Revert changes if Escape key is pressed.
|
||||
if ( e.which === 27 ) {
|
||||
return inlineEditPost.revert();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Reverts changes and close the quick editor if the cancel button is clicked.
|
||||
*
|
||||
* @return {boolean} The result of revert.
|
||||
*/
|
||||
$( '.cancel', qeRow ).on( 'click', function() {
|
||||
return inlineEditPost.revert();
|
||||
});
|
||||
|
||||
/**
|
||||
* Saves changes in the quick editor if the save(named: update) button is clicked.
|
||||
*
|
||||
* @return {boolean} The result of save.
|
||||
*/
|
||||
$( '.save', qeRow ).on( 'click', function() {
|
||||
return inlineEditPost.save(this);
|
||||
});
|
||||
|
||||
/**
|
||||
* If Enter is pressed, and the target is not the cancel button, save the post.
|
||||
*
|
||||
* @return {boolean} The result of save.
|
||||
*/
|
||||
$('td', qeRow).on( 'keydown', function(e){
|
||||
if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) {
|
||||
return inlineEditPost.save(this);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Reverts changes and close the bulk editor if the cancel button is clicked.
|
||||
*
|
||||
* @return {boolean} The result of revert.
|
||||
*/
|
||||
$( '.cancel', bulkRow ).on( 'click', function() {
|
||||
return inlineEditPost.revert();
|
||||
});
|
||||
|
||||
/**
|
||||
* Disables the password input field when the private post checkbox is checked.
|
||||
*/
|
||||
$('#inline-edit .inline-edit-private input[value="private"]').on( 'click', function(){
|
||||
var pw = $('input.inline-edit-password-input');
|
||||
if ( $(this).prop('checked') ) {
|
||||
pw.val('').prop('disabled', true);
|
||||
} else {
|
||||
pw.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Binds click event to the .editinline button which opens the quick editor.
|
||||
*/
|
||||
$( '#the-list' ).on( 'click', '.editinline', function() {
|
||||
$( this ).attr( 'aria-expanded', 'true' );
|
||||
inlineEditPost.edit( this );
|
||||
});
|
||||
|
||||
// Clone quick edit categories for the bulk editor.
|
||||
var beCategories = $( '#inline-edit fieldset.inline-edit-categories' ).clone();
|
||||
|
||||
// Make "id" attributes globally unique.
|
||||
beCategories.find( '*[id]' ).each( function() {
|
||||
this.id = 'bulk-edit-' + this.id;
|
||||
});
|
||||
|
||||
$('#bulk-edit').find('fieldset:first').after(
|
||||
beCategories
|
||||
).siblings( 'fieldset:last' ).prepend(
|
||||
$( '#inline-edit .inline-edit-tags-wrap' ).clone()
|
||||
);
|
||||
|
||||
$('select[name="_status"] option[value="future"]', bulkRow).remove();
|
||||
|
||||
/**
|
||||
* Adds onclick events to the apply buttons.
|
||||
*/
|
||||
$('#doaction').on( 'click', function(e){
|
||||
var n,
|
||||
$itemsSelected = $( '#posts-filter .check-column input[type="checkbox"]:checked' );
|
||||
|
||||
if ( $itemsSelected.length < 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
t.whichBulkButtonId = $( this ).attr( 'id' );
|
||||
n = t.whichBulkButtonId.substr( 2 );
|
||||
|
||||
if ( 'edit' === $( 'select[name="' + n + '"]' ).val() ) {
|
||||
e.preventDefault();
|
||||
t.setBulk();
|
||||
} else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
|
||||
t.revert();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles the quick edit window, hiding it when it's active and showing it when
|
||||
* inactive.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditPost
|
||||
*
|
||||
* @param {Object} el Element within a post table row.
|
||||
*/
|
||||
toggle : function(el){
|
||||
var t = this;
|
||||
$( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el );
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates the bulk editor row to edit multiple posts at once.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditPost
|
||||
*/
|
||||
setBulk : function(){
|
||||
var te = '', type = this.type, c = true;
|
||||
var checkedPosts = $( 'tbody th.check-column input[type="checkbox"]:checked' );
|
||||
var categories = {};
|
||||
this.revert();
|
||||
|
||||
$( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
|
||||
|
||||
// Insert the editor at the top of the table with an empty row above to maintain zebra striping.
|
||||
$('table.widefat tbody').prepend( $('#bulk-edit') ).prepend('<tr class="hidden"></tr>');
|
||||
$('#bulk-edit').addClass('inline-editor').show();
|
||||
|
||||
/**
|
||||
* Create a HTML div with the title and a link(delete-icon) for each selected
|
||||
* post.
|
||||
*
|
||||
* Get the selected posts based on the checked checkboxes in the post table.
|
||||
*/
|
||||
$( 'tbody th.check-column input[type="checkbox"]' ).each( function() {
|
||||
|
||||
// If the checkbox for a post is selected, add the post to the edit list.
|
||||
if ( $(this).prop('checked') ) {
|
||||
c = false;
|
||||
var id = $( this ).val(),
|
||||
theTitle = $( '#inline_' + id + ' .post_title' ).html() || wp.i18n.__( '(no title)' ),
|
||||
buttonVisuallyHiddenText = wp.i18n.sprintf(
|
||||
/* translators: %s: Post title. */
|
||||
wp.i18n.__( 'Remove “%s” from Bulk Edit' ),
|
||||
theTitle
|
||||
);
|
||||
|
||||
te += '<li class="ntdelitem"><button type="button" id="_' + id + '" class="button-link ntdelbutton"><span class="screen-reader-text">' + buttonVisuallyHiddenText + '</span></button><span class="ntdeltitle" aria-hidden="true">' + theTitle + '</span></li>';
|
||||
}
|
||||
});
|
||||
|
||||
// If no checkboxes where checked, just hide the quick/bulk edit rows.
|
||||
if ( c ) {
|
||||
return this.revert();
|
||||
}
|
||||
|
||||
// Populate the list of items to bulk edit.
|
||||
$( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' );
|
||||
|
||||
// Gather up some statistics on which of these checked posts are in which categories.
|
||||
checkedPosts.each( function() {
|
||||
var id = $( this ).val();
|
||||
var checked = $( '#category_' + id ).text().split( ',' );
|
||||
|
||||
checked.map( function( cid ) {
|
||||
categories[ cid ] || ( categories[ cid ] = 0 );
|
||||
// Just record that this category is checked.
|
||||
categories[ cid ]++;
|
||||
} );
|
||||
} );
|
||||
|
||||
// Compute initial states.
|
||||
$( '.inline-edit-categories input[name="post_category[]"]' ).each( function() {
|
||||
if ( categories[ $( this ).val() ] == checkedPosts.length ) {
|
||||
// If the number of checked categories matches the number of selected posts, then all posts are in this category.
|
||||
$( this ).prop( 'checked', true );
|
||||
} else if ( categories[ $( this ).val() ] > 0 ) {
|
||||
// If the number is less than the number of selected posts, then it's indeterminate.
|
||||
$( this ).prop( 'indeterminate', true );
|
||||
if ( ! $( this ).parent().find( 'input[name="indeterminate_post_category[]"]' ).length ) {
|
||||
// Get the term label text.
|
||||
var label = $( this ).parent().text();
|
||||
// Set indeterminate states for the backend. Add accessible text for indeterminate inputs.
|
||||
$( this ).after( '<input type="hidden" name="indeterminate_post_category[]" value="' + $( this ).val() + '">' ).attr( 'aria-label', label.trim() + ': ' + wp.i18n.__( 'Some selected posts have this category' ) );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.inline-edit-categories input[name="post_category[]"]:indeterminate' ).on( 'change', function() {
|
||||
// Remove accessible label text. Remove the indeterminate flags as there was a specific state change.
|
||||
$( this ).removeAttr( 'aria-label' ).parent().find( 'input[name="indeterminate_post_category[]"]' ).remove();
|
||||
} );
|
||||
|
||||
$( '.inline-edit-save button' ).on( 'click', function() {
|
||||
$( '.inline-edit-categories input[name="post_category[]"]' ).prop( 'indeterminate', false );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Binds on click events to handle the list of items to bulk edit.
|
||||
*
|
||||
* @listens click
|
||||
*/
|
||||
$( '#bulk-titles .ntdelbutton' ).click( function() {
|
||||
var $this = $( this ),
|
||||
id = $this.attr( 'id' ).substr( 1 ),
|
||||
$prev = $this.parent().prev().children( '.ntdelbutton' ),
|
||||
$next = $this.parent().next().children( '.ntdelbutton' );
|
||||
|
||||
$( 'input#cb-select-all-1, input#cb-select-all-2' ).prop( 'checked', false );
|
||||
$( 'table.widefat input[value="' + id + '"]' ).prop( 'checked', false );
|
||||
$( '#_' + id ).parent().remove();
|
||||
wp.a11y.speak( wp.i18n.__( 'Item removed.' ), 'assertive' );
|
||||
|
||||
// Move focus to a proper place when items are removed.
|
||||
if ( $next.length ) {
|
||||
$next.focus();
|
||||
} else if ( $prev.length ) {
|
||||
$prev.focus();
|
||||
} else {
|
||||
$( '#bulk-titles-list' ).remove();
|
||||
inlineEditPost.revert();
|
||||
wp.a11y.speak( wp.i18n.__( 'All selected items have been removed. Select new items to use Bulk Actions.' ) );
|
||||
}
|
||||
});
|
||||
|
||||
// Enable auto-complete for tags when editing posts.
|
||||
if ( 'post' === type ) {
|
||||
$( 'tr.inline-editor textarea[data-wp-taxonomy]' ).each( function ( i, element ) {
|
||||
/*
|
||||
* While Quick Edit clones the form each time, Bulk Edit always re-uses
|
||||
* the same form. Let's check if an autocomplete instance already exists.
|
||||
*/
|
||||
if ( $( element ).autocomplete( 'instance' ) ) {
|
||||
// jQuery equivalent of `continue` within an `each()` loop.
|
||||
return;
|
||||
}
|
||||
|
||||
$( element ).wpTagsSuggest();
|
||||
} );
|
||||
}
|
||||
|
||||
// Set initial focus on the Bulk Edit region.
|
||||
$( '#bulk-edit .inline-edit-wrapper' ).attr( 'tabindex', '-1' ).focus();
|
||||
// Scrolls to the top of the table where the editor is rendered.
|
||||
$('html, body').animate( { scrollTop: 0 }, 'fast' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a quick edit window for the post that has been clicked.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditPost
|
||||
*
|
||||
* @param {number|Object} id The ID of the clicked post or an element within a post
|
||||
* table row.
|
||||
* @return {boolean} Always returns false at the end of execution.
|
||||
*/
|
||||
edit : function(id) {
|
||||
var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, f, val, pw;
|
||||
t.revert();
|
||||
|
||||
if ( typeof(id) === 'object' ) {
|
||||
id = t.getId(id);
|
||||
}
|
||||
|
||||
fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order', 'page_template'];
|
||||
if ( t.type === 'page' ) {
|
||||
fields.push('post_parent');
|
||||
}
|
||||
|
||||
// Add the new edit row with an extra blank row underneath to maintain zebra striping.
|
||||
editRow = $('#inline-edit').clone(true);
|
||||
$( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
|
||||
|
||||
// Remove the ID from the copied row and let the `for` attribute reference the hidden ID.
|
||||
$( 'td', editRow ).find('#quick-edit-legend').removeAttr('id');
|
||||
$( 'td', editRow ).find('p[id^="quick-edit-"]').removeAttr('id');
|
||||
|
||||
$(t.what+id).removeClass('is-expanded').hide().after(editRow).after('<tr class="hidden"></tr>');
|
||||
|
||||
// Populate fields in the quick edit window.
|
||||
rowData = $('#inline_'+id);
|
||||
if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
|
||||
|
||||
// The post author no longer has edit capabilities, so we need to add them to the list of authors.
|
||||
$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#post-' + id + ' .author').text() + '</option>');
|
||||
}
|
||||
if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) {
|
||||
$('label.inline-edit-author', editRow).hide();
|
||||
}
|
||||
|
||||
for ( f = 0; f < fields.length; f++ ) {
|
||||
val = $('.'+fields[f], rowData);
|
||||
|
||||
/**
|
||||
* Replaces the image for a Twemoji(Twitter emoji) with it's alternate text.
|
||||
*
|
||||
* @return {string} Alternate text from the image.
|
||||
*/
|
||||
val.find( 'img' ).replaceWith( function() { return this.alt; } );
|
||||
val = val.text();
|
||||
$(':input[name="' + fields[f] + '"]', editRow).val( val );
|
||||
}
|
||||
|
||||
if ( $( '.comment_status', rowData ).text() === 'open' ) {
|
||||
$( 'input[name="comment_status"]', editRow ).prop( 'checked', true );
|
||||
}
|
||||
if ( $( '.ping_status', rowData ).text() === 'open' ) {
|
||||
$( 'input[name="ping_status"]', editRow ).prop( 'checked', true );
|
||||
}
|
||||
if ( $( '.sticky', rowData ).text() === 'sticky' ) {
|
||||
$( 'input[name="sticky"]', editRow ).prop( 'checked', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the select boxes for the categories.
|
||||
*/
|
||||
$('.post_category', rowData).each(function(){
|
||||
var taxname,
|
||||
term_ids = $(this).text();
|
||||
|
||||
if ( term_ids ) {
|
||||
taxname = $(this).attr('id').replace('_'+id, '');
|
||||
$('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(','));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets all the taxonomies for live auto-fill suggestions when typing the name
|
||||
* of a tag.
|
||||
*/
|
||||
$('.tags_input', rowData).each(function(){
|
||||
var terms = $(this),
|
||||
taxname = $(this).attr('id').replace('_' + id, ''),
|
||||
textarea = $('textarea.tax_input_' + taxname, editRow),
|
||||
comma = wp.i18n._x( ',', 'tag delimiter' ).trim();
|
||||
|
||||
// Ensure the textarea exists.
|
||||
if ( ! textarea.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
terms.find( 'img' ).replaceWith( function() { return this.alt; } );
|
||||
terms = terms.text();
|
||||
|
||||
if ( terms ) {
|
||||
if ( ',' !== comma ) {
|
||||
terms = terms.replace(/,/g, comma);
|
||||
}
|
||||
textarea.val(terms);
|
||||
}
|
||||
|
||||
textarea.wpTagsSuggest();
|
||||
});
|
||||
|
||||
// Handle the post status.
|
||||
var post_date_string = $(':input[name="aa"]').val() + '-' + $(':input[name="mm"]').val() + '-' + $(':input[name="jj"]').val();
|
||||
post_date_string += ' ' + $(':input[name="hh"]').val() + ':' + $(':input[name="mn"]').val() + ':' + $(':input[name="ss"]').val();
|
||||
var post_date = new Date( post_date_string );
|
||||
status = $('._status', rowData).text();
|
||||
if ( 'future' !== status && Date.now() > post_date ) {
|
||||
$('select[name="_status"] option[value="future"]', editRow).remove();
|
||||
} else {
|
||||
$('select[name="_status"] option[value="publish"]', editRow).remove();
|
||||
}
|
||||
|
||||
pw = $( '.inline-edit-password-input' ).prop( 'disabled', false );
|
||||
if ( 'private' === status ) {
|
||||
$('input[name="keep_private"]', editRow).prop('checked', true);
|
||||
pw.val( '' ).prop( 'disabled', true );
|
||||
}
|
||||
|
||||
// Remove the current page and children from the parent dropdown.
|
||||
pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow);
|
||||
if ( pageOpt.length > 0 ) {
|
||||
pageLevel = pageOpt[0].className.split('-')[1];
|
||||
nextPage = pageOpt;
|
||||
while ( pageLoop ) {
|
||||
nextPage = nextPage.next('option');
|
||||
if ( nextPage.length === 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
nextLevel = nextPage[0].className.split('-')[1];
|
||||
|
||||
if ( nextLevel <= pageLevel ) {
|
||||
pageLoop = false;
|
||||
} else {
|
||||
nextPage.remove();
|
||||
nextPage = pageOpt;
|
||||
}
|
||||
}
|
||||
pageOpt.remove();
|
||||
}
|
||||
|
||||
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
|
||||
$('.ptitle', editRow).trigger( 'focus' );
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves the changes made in the quick edit window to the post.
|
||||
* Ajax saving is only for Quick Edit and not for bulk edit.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @param {number} id The ID for the post that has been changed.
|
||||
* @return {boolean} False, so the form does not submit when pressing
|
||||
* Enter on a focused field.
|
||||
*/
|
||||
save : function(id) {
|
||||
var params, fields, page = $('.post_status_page').val() || '';
|
||||
|
||||
if ( typeof(id) === 'object' ) {
|
||||
id = this.getId(id);
|
||||
}
|
||||
|
||||
$( 'table.widefat .spinner' ).addClass( 'is-active' );
|
||||
|
||||
params = {
|
||||
action: 'inline-save',
|
||||
post_type: typenow,
|
||||
post_ID: id,
|
||||
edit_date: 'true',
|
||||
post_status: page
|
||||
};
|
||||
|
||||
fields = $('#edit-'+id).find(':input').serialize();
|
||||
params = fields + '&' + $.param(params);
|
||||
|
||||
// Make Ajax request.
|
||||
$.post( ajaxurl, params,
|
||||
function(r) {
|
||||
var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ),
|
||||
$error = $errorNotice.find( '.error' );
|
||||
|
||||
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
|
||||
|
||||
if (r) {
|
||||
if ( -1 !== r.indexOf( '<tr' ) ) {
|
||||
$(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove();
|
||||
$('#edit-'+id).before(r).remove();
|
||||
$( inlineEditPost.what + id ).hide().fadeIn( 400, function() {
|
||||
// Move focus back to the Quick Edit button. $( this ) is the row being animated.
|
||||
$( this ).find( '.editinline' )
|
||||
.attr( 'aria-expanded', 'false' )
|
||||
.trigger( 'focus' );
|
||||
wp.a11y.speak( wp.i18n.__( 'Changes saved.' ) );
|
||||
});
|
||||
} else {
|
||||
r = r.replace( /<.[^<>]*?>/g, '' );
|
||||
$errorNotice.removeClass( 'hidden' );
|
||||
$error.html( r );
|
||||
wp.a11y.speak( $error.text() );
|
||||
}
|
||||
} else {
|
||||
$errorNotice.removeClass( 'hidden' );
|
||||
$error.text( wp.i18n.__( 'Error while saving the changes.' ) );
|
||||
wp.a11y.speak( wp.i18n.__( 'Error while saving the changes.' ) );
|
||||
}
|
||||
},
|
||||
'html');
|
||||
|
||||
// Prevent submitting the form when pressing Enter on a focused field.
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Hides and empties the Quick Edit and/or Bulk Edit windows.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditPost
|
||||
*
|
||||
* @return {boolean} Always returns false.
|
||||
*/
|
||||
revert : function(){
|
||||
var $tableWideFat = $( '.widefat' ),
|
||||
id = $( '.inline-editor', $tableWideFat ).attr( 'id' );
|
||||
|
||||
if ( id ) {
|
||||
$( '.spinner', $tableWideFat ).removeClass( 'is-active' );
|
||||
|
||||
if ( 'bulk-edit' === id ) {
|
||||
|
||||
// Hide the bulk editor.
|
||||
$( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove();
|
||||
$('#bulk-titles').empty();
|
||||
|
||||
// Store the empty bulk editor in a hidden element.
|
||||
$('#inlineedit').append( $('#bulk-edit') );
|
||||
|
||||
// Move focus back to the Bulk Action button that was activated.
|
||||
$( '#' + inlineEditPost.whichBulkButtonId ).trigger( 'focus' );
|
||||
} else {
|
||||
|
||||
// Remove both the inline-editor and its hidden tr siblings.
|
||||
$('#'+id).siblings('tr.hidden').addBack().remove();
|
||||
id = id.substr( id.lastIndexOf('-') + 1 );
|
||||
|
||||
// Show the post row and move focus back to the Quick Edit button.
|
||||
$( this.what + id ).show().find( '.editinline' )
|
||||
.attr( 'aria-expanded', 'false' )
|
||||
.trigger( 'focus' );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the ID for a the post that you want to quick edit from the row in the quick
|
||||
* edit table.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditPost
|
||||
*
|
||||
* @param {Object} o DOM row object to get the ID for.
|
||||
* @return {string} The post ID extracted from the table row in the object.
|
||||
*/
|
||||
getId : function(o) {
|
||||
var id = $(o).closest('tr').attr('id'),
|
||||
parts = id.split('-');
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
$( function() { inlineEditPost.init(); } );
|
||||
|
||||
// Show/hide locks on posts.
|
||||
$( function() {
|
||||
|
||||
// Set the heartbeat interval to 10 seconds.
|
||||
if ( typeof wp !== 'undefined' && wp.heartbeat ) {
|
||||
wp.heartbeat.interval( 10 );
|
||||
}
|
||||
}).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
|
||||
var locked = data['wp-check-locked-posts'] || {},
|
||||
lockedClass = 'wp-locked';
|
||||
|
||||
$('#the-list tr').each( function(i, el) {
|
||||
var key = el.id, row = $(el), lock_data, avatar;
|
||||
|
||||
if ( locked.hasOwnProperty( key ) ) {
|
||||
if ( ! row.hasClass( lockedClass ) ) {
|
||||
lock_data = locked[key];
|
||||
row.find('.column-title .locked-text').text( lock_data.text );
|
||||
row.find('.check-column checkbox').prop('checked', false);
|
||||
|
||||
if ( lock_data.avatar_src ) {
|
||||
avatar = $( '<img />', {
|
||||
'class': 'avatar avatar-18 photo',
|
||||
width: 18,
|
||||
height: 18,
|
||||
alt: '',
|
||||
src: lock_data.avatar_src,
|
||||
srcset: lock_data.avatar_src_2x ? lock_data.avatar_src_2x + ' 2x' : undefined
|
||||
} );
|
||||
row.find('.column-title .locked-avatar').empty().append( avatar );
|
||||
}
|
||||
row.addClass( lockedClass );
|
||||
}
|
||||
} else if ( row.hasClass( lockedClass ) ) {
|
||||
row.removeClass( lockedClass ).find( '.locked-info span' ).empty();
|
||||
}
|
||||
});
|
||||
}).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) {
|
||||
var check = [];
|
||||
|
||||
$('#the-list tr').each( function(i, el) {
|
||||
if ( el.id ) {
|
||||
check.push( el.id );
|
||||
}
|
||||
});
|
||||
|
||||
if ( check.length ) {
|
||||
data['wp-check-locked-posts'] = check;
|
||||
}
|
||||
});
|
||||
|
||||
})( jQuery, window.wp );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},function(u,h){window.inlineEditPost={init:function(){var i=this,t=u("#inline-edit"),e=u("#bulk-edit"),t=(i.type=u("table.widefat").hasClass("pages")?"page":"post",i.what="#post-",t.on("keyup",function(t){if(27===t.which)return inlineEditPost.revert()}),e.on("keyup",function(t){if(27===t.which)return inlineEditPost.revert()}),u(".cancel",t).on("click",function(){return inlineEditPost.revert()}),u(".save",t).on("click",function(){return inlineEditPost.save(this)}),u("td",t).on("keydown",function(t){if(13===t.which&&!u(t.target).hasClass("cancel"))return inlineEditPost.save(this)}),u(".cancel",e).on("click",function(){return inlineEditPost.revert()}),u('#inline-edit .inline-edit-private input[value="private"]').on("click",function(){var t=u("input.inline-edit-password-input");u(this).prop("checked")?t.val("").prop("disabled",!0):t.prop("disabled",!1)}),u("#the-list").on("click",".editinline",function(){u(this).attr("aria-expanded","true"),inlineEditPost.edit(this)}),u("#inline-edit fieldset.inline-edit-categories").clone());t.find("*[id]").each(function(){this.id="bulk-edit-"+this.id}),u("#bulk-edit").find("fieldset:first").after(t).siblings("fieldset:last").prepend(u("#inline-edit .inline-edit-tags-wrap").clone()),u('select[name="_status"] option[value="future"]',e).remove(),u("#doaction").on("click",function(t){var e;u('#posts-filter .check-column input[type="checkbox"]:checked').length<1||(i.whichBulkButtonId=u(this).attr("id"),e=i.whichBulkButtonId.substr(2),"edit"===u('select[name="'+e+'"]').val()?(t.preventDefault(),i.setBulk()):0<u("form#posts-filter tr.inline-editor").length&&i.revert())})},toggle:function(t){var e=this;"none"===u(e.what+e.getId(t)).css("display")?e.revert():e.edit(t)},setBulk:function(){var n="",t=this.type,a=!0,e=u('tbody th.check-column input[type="checkbox"]:checked'),i={};if(this.revert(),u("#bulk-edit td").attr("colspan",u("th:visible, td:visible",".widefat:first thead").length),u("table.widefat tbody").prepend(u("#bulk-edit")).prepend('<tr class="hidden"></tr>'),u("#bulk-edit").addClass("inline-editor").show(),u('tbody th.check-column input[type="checkbox"]').each(function(){var t,e,i;u(this).prop("checked")&&(a=!1,t=u(this).val(),e=u("#inline_"+t+" .post_title").html()||h.i18n.__("(no title)"),i=h.i18n.sprintf(h.i18n.__("Remove “%s” from Bulk Edit"),e),n+='<li class="ntdelitem"><button type="button" id="_'+t+'" class="button-link ntdelbutton"><span class="screen-reader-text">'+i+'</span></button><span class="ntdeltitle" aria-hidden="true">'+e+"</span></li>")}),a)return this.revert();u("#bulk-titles").html('<ul id="bulk-titles-list" role="list">'+n+"</ul>"),e.each(function(){var t=u(this).val();u("#category_"+t).text().split(",").map(function(t){i[t]||(i[t]=0),i[t]++})}),u('.inline-edit-categories input[name="post_category[]"]').each(function(){var t;i[u(this).val()]==e.length?u(this).prop("checked",!0):0<i[u(this).val()]&&(u(this).prop("indeterminate",!0),u(this).parent().find('input[name="indeterminate_post_category[]"]').length||(t=u(this).parent().text(),u(this).after('<input type="hidden" name="indeterminate_post_category[]" value="'+u(this).val()+'">').attr("aria-label",t.trim()+": "+h.i18n.__("Some selected posts have this category"))))}),u('.inline-edit-categories input[name="post_category[]"]:indeterminate').on("change",function(){u(this).removeAttr("aria-label").parent().find('input[name="indeterminate_post_category[]"]').remove()}),u(".inline-edit-save button").on("click",function(){u('.inline-edit-categories input[name="post_category[]"]').prop("indeterminate",!1)}),u("#bulk-titles .ntdelbutton").click(function(){var t=u(this),e=t.attr("id").substr(1),i=t.parent().prev().children(".ntdelbutton"),t=t.parent().next().children(".ntdelbutton");u("input#cb-select-all-1, input#cb-select-all-2").prop("checked",!1),u('table.widefat input[value="'+e+'"]').prop("checked",!1),u("#_"+e).parent().remove(),h.a11y.speak(h.i18n.__("Item removed."),"assertive"),t.length?t.focus():i.length?i.focus():(u("#bulk-titles-list").remove(),inlineEditPost.revert(),h.a11y.speak(h.i18n.__("All selected items have been removed. Select new items to use Bulk Actions.")))}),"post"===t&&u("tr.inline-editor textarea[data-wp-taxonomy]").each(function(t,e){u(e).autocomplete("instance")||u(e).wpTagsSuggest()}),u("#bulk-edit .inline-edit-wrapper").attr("tabindex","-1").focus(),u("html, body").animate({scrollTop:0},"fast")},edit:function(n){var t,a,e,i,s,r,o,l,d=this,c=!0;for(d.revert(),"object"==typeof n&&(n=d.getId(n)),t=["post_title","post_name","post_author","_status","jj","mm","aa","hh","mn","ss","post_password","post_format","menu_order","page_template"],"page"===d.type&&t.push("post_parent"),a=u("#inline-edit").clone(!0),u("td",a).attr("colspan",u("th:visible, td:visible",".widefat:first thead").length),u("td",a).find("#quick-edit-legend").removeAttr("id"),u("td",a).find('p[id^="quick-edit-"]').removeAttr("id"),u(d.what+n).removeClass("is-expanded").hide().after(Line truncated
|
||||
@@ -0,0 +1,294 @@
|
||||
/**
|
||||
* This file is used on the term overview page to power quick-editing terms.
|
||||
*
|
||||
* @output wp-admin/js/inline-edit-tax.js
|
||||
*/
|
||||
|
||||
/* global ajaxurl, inlineEditTax */
|
||||
|
||||
window.wp = window.wp || {};
|
||||
|
||||
/**
|
||||
* Consists of functions relevant to the inline taxonomy editor.
|
||||
*
|
||||
* @namespace inlineEditTax
|
||||
*
|
||||
* @property {string} type The type of inline edit we are currently on.
|
||||
* @property {string} what The type property with a hash prefixed and a dash
|
||||
* suffixed.
|
||||
*/
|
||||
( function( $, wp ) {
|
||||
|
||||
window.inlineEditTax = {
|
||||
|
||||
/**
|
||||
* Initializes the inline taxonomy editor by adding event handlers to be able to
|
||||
* quick edit.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @this inlineEditTax
|
||||
* @memberof inlineEditTax
|
||||
* @return {void}
|
||||
*/
|
||||
init : function() {
|
||||
var t = this, row = $('#inline-edit');
|
||||
|
||||
t.type = $('#the-list').attr('data-wp-lists').substr(5);
|
||||
t.what = '#'+t.type+'-';
|
||||
|
||||
$( '#the-list' ).on( 'click', '.editinline', function() {
|
||||
$( this ).attr( 'aria-expanded', 'true' );
|
||||
inlineEditTax.edit( this );
|
||||
});
|
||||
|
||||
/**
|
||||
* Cancels inline editing when pressing Escape inside the inline editor.
|
||||
*
|
||||
* @param {Object} e The keyup event that has been triggered.
|
||||
*/
|
||||
row.on( 'keyup', function( e ) {
|
||||
// 27 = [Escape].
|
||||
if ( e.which === 27 ) {
|
||||
return inlineEditTax.revert();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Cancels inline editing when clicking the cancel button.
|
||||
*/
|
||||
$( '.cancel', row ).on( 'click', function() {
|
||||
return inlineEditTax.revert();
|
||||
});
|
||||
|
||||
/**
|
||||
* Saves the inline edits when clicking the save button.
|
||||
*/
|
||||
$( '.save', row ).on( 'click', function() {
|
||||
return inlineEditTax.save(this);
|
||||
});
|
||||
|
||||
/**
|
||||
* Saves the inline edits when pressing Enter inside the inline editor.
|
||||
*/
|
||||
$( 'input, select', row ).on( 'keydown', function( e ) {
|
||||
// 13 = [Enter].
|
||||
if ( e.which === 13 ) {
|
||||
return inlineEditTax.save( this );
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Saves the inline edits on submitting the inline edit form.
|
||||
*/
|
||||
$( '#posts-filter input[type="submit"]' ).on( 'mousedown', function() {
|
||||
t.revert();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles the quick edit based on if it is currently shown or hidden.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @this inlineEditTax
|
||||
* @memberof inlineEditTax
|
||||
*
|
||||
* @param {HTMLElement} el An element within the table row or the table row
|
||||
* itself that we want to quick edit.
|
||||
* @return {void}
|
||||
*/
|
||||
toggle : function(el) {
|
||||
var t = this;
|
||||
|
||||
$(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el);
|
||||
},
|
||||
|
||||
/**
|
||||
* Shows the quick editor
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @this inlineEditTax
|
||||
* @memberof inlineEditTax
|
||||
*
|
||||
* @param {string|HTMLElement} id The ID of the term we want to quick edit or an
|
||||
* element within the table row or the
|
||||
* table row itself.
|
||||
* @return {boolean} Always returns false.
|
||||
*/
|
||||
edit : function(id) {
|
||||
var editRow, rowData, val,
|
||||
t = this;
|
||||
t.revert();
|
||||
|
||||
// Makes sure we can pass an HTMLElement as the ID.
|
||||
if ( typeof(id) === 'object' ) {
|
||||
id = t.getId(id);
|
||||
}
|
||||
|
||||
editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
|
||||
$( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.wp-list-table.widefat:first thead' ).length );
|
||||
|
||||
$(t.what+id).hide().after(editRow).after('<tr class="hidden"></tr>');
|
||||
|
||||
val = $('.name', rowData);
|
||||
val.find( 'img' ).replaceWith( function() { return this.alt; } );
|
||||
val = val.text();
|
||||
$(':input[name="name"]', editRow).val( val );
|
||||
|
||||
val = $('.slug', rowData);
|
||||
val.find( 'img' ).replaceWith( function() { return this.alt; } );
|
||||
val = val.text();
|
||||
$(':input[name="slug"]', editRow).val( val );
|
||||
|
||||
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
|
||||
$('.ptitle', editRow).eq(0).trigger( 'focus' );
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves the quick edit data.
|
||||
*
|
||||
* Saves the quick edit data to the server and replaces the table row with the
|
||||
* HTML retrieved from the server.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @this inlineEditTax
|
||||
* @memberof inlineEditTax
|
||||
*
|
||||
* @param {string|HTMLElement} id The ID of the term we want to quick edit or an
|
||||
* element within the table row or the
|
||||
* table row itself.
|
||||
* @return {boolean} Always returns false.
|
||||
*/
|
||||
save : function(id) {
|
||||
var params, fields, tax = $('input[name="taxonomy"]').val() || '';
|
||||
|
||||
// Makes sure we can pass an HTMLElement as the ID.
|
||||
if( typeof(id) === 'object' ) {
|
||||
id = this.getId(id);
|
||||
}
|
||||
|
||||
$( 'table.widefat .spinner' ).addClass( 'is-active' );
|
||||
|
||||
params = {
|
||||
action: 'inline-save-tax',
|
||||
tax_type: this.type,
|
||||
tax_ID: id,
|
||||
taxonomy: tax
|
||||
};
|
||||
|
||||
fields = $('#edit-'+id).find(':input').serialize();
|
||||
params = fields + '&' + $.param(params);
|
||||
|
||||
// Do the Ajax request to save the data to the server.
|
||||
$.post( ajaxurl, params,
|
||||
/**
|
||||
* Handles the response from the server
|
||||
*
|
||||
* Handles the response from the server, replaces the table row with the response
|
||||
* from the server.
|
||||
*
|
||||
* @param {string} r The string with which to replace the table row.
|
||||
*/
|
||||
function(r) {
|
||||
var row, new_id, option_value,
|
||||
$errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ),
|
||||
$error = $errorNotice.find( '.error' );
|
||||
|
||||
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
|
||||
|
||||
if (r) {
|
||||
if ( -1 !== r.indexOf( '<tr' ) ) {
|
||||
$(inlineEditTax.what+id).siblings('tr.hidden').addBack().remove();
|
||||
new_id = $(r).attr('id');
|
||||
|
||||
$('#edit-'+id).before(r).remove();
|
||||
|
||||
if ( new_id ) {
|
||||
option_value = new_id.replace( inlineEditTax.type + '-', '' );
|
||||
row = $( '#' + new_id );
|
||||
} else {
|
||||
option_value = id;
|
||||
row = $( inlineEditTax.what + id );
|
||||
}
|
||||
|
||||
// Update the value in the Parent dropdown.
|
||||
$( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
|
||||
|
||||
row.hide().fadeIn( 400, function() {
|
||||
// Move focus back to the Quick Edit button.
|
||||
row.find( '.editinline' )
|
||||
.attr( 'aria-expanded', 'false' )
|
||||
.trigger( 'focus' );
|
||||
wp.a11y.speak( wp.i18n.__( 'Changes saved.' ) );
|
||||
});
|
||||
|
||||
} else {
|
||||
$errorNotice.removeClass( 'hidden' );
|
||||
$error.html( r );
|
||||
/*
|
||||
* Some error strings may contain HTML entities (e.g. `“`), let's use
|
||||
* the HTML element's text.
|
||||
*/
|
||||
wp.a11y.speak( $error.text() );
|
||||
}
|
||||
} else {
|
||||
$errorNotice.removeClass( 'hidden' );
|
||||
$error.text( wp.i18n.__( 'Error while saving the changes.' ) );
|
||||
wp.a11y.speak( wp.i18n.__( 'Error while saving the changes.' ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Prevent submitting the form when pressing Enter on a focused field.
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Closes the quick edit form.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @this inlineEditTax
|
||||
* @memberof inlineEditTax
|
||||
* @return {void}
|
||||
*/
|
||||
revert : function() {
|
||||
var id = $('table.widefat tr.inline-editor').attr('id');
|
||||
|
||||
if ( id ) {
|
||||
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
|
||||
$('#'+id).siblings('tr.hidden').addBack().remove();
|
||||
id = id.substr( id.lastIndexOf('-') + 1 );
|
||||
|
||||
// Show the taxonomy row and move focus back to the Quick Edit button.
|
||||
$( this.what + id ).show().find( '.editinline' )
|
||||
.attr( 'aria-expanded', 'false' )
|
||||
.trigger( 'focus' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves the ID of the term of the element inside the table row.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof inlineEditTax
|
||||
*
|
||||
* @param {HTMLElement} o An element within the table row or the table row itself.
|
||||
* @return {string} The ID of the term based on the element.
|
||||
*/
|
||||
getId : function(o) {
|
||||
var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
|
||||
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
$( function() { inlineEditTax.init(); } );
|
||||
|
||||
})( jQuery, window.wp );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},function(s,l){window.inlineEditTax={init:function(){var t=this,i=s("#inline-edit");t.type=s("#the-list").attr("data-wp-lists").substr(5),t.what="#"+t.type+"-",s("#the-list").on("click",".editinline",function(){s(this).attr("aria-expanded","true"),inlineEditTax.edit(this)}),i.on("keyup",function(t){if(27===t.which)return inlineEditTax.revert()}),s(".cancel",i).on("click",function(){return inlineEditTax.revert()}),s(".save",i).on("click",function(){return inlineEditTax.save(this)}),s("input, select",i).on("keydown",function(t){if(13===t.which)return inlineEditTax.save(this)}),s('#posts-filter input[type="submit"]').on("mousedown",function(){t.revert()})},toggle:function(t){var i=this;"none"===s(i.what+i.getId(t)).css("display")?i.revert():i.edit(t)},edit:function(t){var i,e,n=this;return n.revert(),"object"==typeof t&&(t=n.getId(t)),i=s("#inline-edit").clone(!0),e=s("#inline_"+t),s("td",i).attr("colspan",s("th:visible, td:visible",".wp-list-table.widefat:first thead").length),s(n.what+t).hide().after(i).after('<tr class="hidden"></tr>'),(n=s(".name",e)).find("img").replaceWith(function(){return this.alt}),n=n.text(),s(':input[name="name"]',i).val(n),(n=s(".slug",e)).find("img").replaceWith(function(){return this.alt}),n=n.text(),s(':input[name="slug"]',i).val(n),s(i).attr("id","edit-"+t).addClass("inline-editor").show(),s(".ptitle",i).eq(0).trigger("focus"),!1},save:function(d){var t=s('input[name="taxonomy"]').val()||"";return"object"==typeof d&&(d=this.getId(d)),s("table.widefat .spinner").addClass("is-active"),t={action:"inline-save-tax",tax_type:this.type,tax_ID:d,taxonomy:t},t=s("#edit-"+d).find(":input").serialize()+"&"+s.param(t),s.post(ajaxurl,t,function(t){var i,e,n,a=s("#edit-"+d+" .inline-edit-save .notice-error"),r=a.find(".error");s("table.widefat .spinner").removeClass("is-active"),t?-1!==t.indexOf("<tr")?(s(inlineEditTax.what+d).siblings("tr.hidden").addBack().remove(),e=s(t).attr("id"),s("#edit-"+d).before(t).remove(),i=e?(n=e.replace(inlineEditTax.type+"-",""),s("#"+e)):(n=d,s(inlineEditTax.what+d)),s("#parent").find("option[value="+n+"]").text(i.find(".row-title").text()),i.hide().fadeIn(400,function(){i.find(".editinline").attr("aria-expanded","false").trigger("focus"),l.a11y.speak(l.i18n.__("Changes saved."))})):(a.removeClass("hidden"),r.html(t),l.a11y.speak(r.text())):(a.removeClass("hidden"),r.text(l.i18n.__("Error while saving the changes.")),l.a11y.speak(l.i18n.__("Error while saving the changes.")))}),!1},revert:function(){var t=s("table.widefat tr.inline-editor").attr("id");t&&(s("table.widefat .spinner").removeClass("is-active"),s("#"+t).siblings("tr.hidden").addBack().remove(),t=t.substr(t.lastIndexOf("-")+1),s(this.what+t).show().find(".editinline").attr("aria-expanded","false").trigger("focus"))},getId:function(t){t=("TR"===t.tagName?t.id:s(t).parents("tr").attr("id")).split("-");return t[t.length-1]}},s(function(){inlineEditTax.init()})}(jQuery,window.wp);
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/*! This file is auto-generated */
|
||||
/*! Iris Color Picker - v1.1.1 - 2021-10-05
|
||||
* https://github.com/Automattic/Iris
|
||||
* Copyright (c) 2021 Matt Wiebe; Licensed GPLv2 */
|
||||
!function(a,b){function c(){var b,c,d="backgroundImage";j?k="filter":(b=a('<div id="iris-gradtest" />'),c="linear-gradient(top,#fff,#000)",a.each(l,function(a,e){if(b.css(d,e+c),b.css(d).match("gradient"))return k=a,!1}),!1===k&&(b.css("background","-webkit-gradient(linear,0% 0%,0% 100%,from(#fff),to(#000))"),b.css(d).match("gradient")&&(k="webkit")),b.remove())}function d(a,b){return a="top"===a?"top":"left",b=Array.isArray(b)?b:Array.prototype.slice.call(arguments,1),"webkit"===k?f(a,b):l[k]+"linear-gradient("+a+", "+b.join(", ")+")"}function e(b,c){var d,e,f,h,i,j,k,l,m;b="top"===b?"top":"left",c=Array.isArray(c)?c:Array.prototype.slice.call(arguments,1),d="top"===b?0:1,e=a(this),f=c.length-1,h="filter",i=1===d?"left":"top",j=1===d?"right":"bottom",k=1===d?"height":"width",l='<div class="iris-ie-gradient-shim" style="position:absolute;'+k+":100%;"+i+":%start%;"+j+":%end%;"+h+':%filter%;" data-color:"%color%"></div>',m="","static"===e.css("position")&&e.css({position:"relative"}),c=g(c),a.each(c,function(a,b){var e,g,h;if(a===f)return!1;e=c[a+1],b.stop!==e.stop&&(g=100-parseFloat(e.stop)+"%",b.octoHex=new Color(b.color).toIEOctoHex(),e.octoHex=new Color(e.color).toIEOctoHex(),h="progid:DXImageTransform.Microsoft.Gradient(GradientType="+d+", StartColorStr='"+b.octoHex+"', EndColorStr='"+e.octoHex+"')",m+=l.replace("%start%",b.stop).replace("%end%",g).replace("%filter%",h))}),e.find(".iris-ie-gradient-shim").remove(),a(m).prependTo(e)}function f(b,c){var d=[];return b="top"===b?"0% 0%,0% 100%,":"0% 100%,100% 100%,",c=g(c),a.each(c,function(a,b){d.push("color-stop("+parseFloat(b.stop)/100+", "+b.color+")")}),"-webkit-gradient(linear,"+b+d.join(",")+")"}function g(b){var c=[],d=[],e=[],f=b.length-1;return a.each(b,function(a,b){var e=b,f=!1,g=b.match(/1?[0-9]{1,2}%$/);g&&(e=b.replace(/\s?1?[0-9]{1,2}%$/,""),f=g.shift()),c.push(e),d.push(f)}),!1===d[0]&&(d[0]="0%"),!1===d[f]&&(d[f]="100%"),d=h(d),a.each(d,function(a){e[a]={color:c[a],stop:d[a]}}),e}function h(b){var c,d,e,f,g=0,i=b.length-1,j=0,k=!1;if(b.length<=2||a.inArray(!1,b)<0)return b;for(;j<b.length-1;)k||!1!==b[j]?k&&!1!==b[j]&&(i=j,j=b.length):(g=j-1,k=!0),j++;for(d=i-g,f=parseInt(b[g].replace("%"),10),c=(parseFloat(b[i].replace("%"))-f)/d,j=g+1,e=1;j<i;)b[j]=f+e*c+"%",e++,j++;return h(b)}var i,j,k,l,m,n,o,p,q;if(i='<div class="iris-picker"><div class="iris-picker-inner"><div class="iris-square"><a class="iris-square-value" href="#"><span class="iris-square-handle ui-slider-handle"></span></a><div class="iris-square-inner iris-square-horiz"></div><div class="iris-square-inner iris-square-vert"></div></div><div class="iris-slider iris-strip"><div class="iris-slider-offset"></div></div></div></div>',m='.iris-picker{display:block;position:relative}.iris-picker,.iris-picker *{-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input+.iris-picker{margin-top:4px}.iris-error{background-color:#ffafaf}.iris-border{border-radius:3px;border:1px solid #aaa;width:200px;background-color:#fff}.iris-picker-inner{position:absolute;top:0;right:0;left:0;bottom:0}.iris-border .iris-picker-inner{top:10px;right:10px;left:10px;bottom:10px}.iris-picker .iris-square-inner{position:absolute;left:0;right:0;top:0;bottom:0}.iris-picker .iris-square,.iris-picker .iris-slider,.iris-picker .iris-square-inner,.iris-picker .iris-palette{border-radius:3px;box-shadow:inset 0 0 5px rgba(0,0,0,.4);height:100%;width:12.5%;float:left;margin-right:5%}.iris-only-strip .iris-slider{width:100%}.iris-picker .iris-square{width:76%;margin-right:10%;position:relative}.iris-only-strip .iris-square{display:none}.iris-picker .iris-square-inner{width:auto;margin:0}.iris-ie-9 .iris-square,.iris-ie-9 .iris-slider,.iris-ie-9 .iris-square-inner,.iris-ie-9 .iris-palette{box-shadow:none;border-radius:0}.iris-ie-9 .iris-square,.iris-ie-9 .iris-slider,.iris-ie-9 .iris-palette{outline:1px solid rgba(0,0,0,.1)}.iris-ie-lt9 .iris-square,.iris-ie-lt9 .iris-slider,.iris-ie-lt9 .iris-square-inner,.iris-ie-lt9 .iris-palette{outline:1px solid #aaa}.iris-ie-lt9 .iris-square .ui-slider-handle{outline:1px solid #aaa;background-color:#fff;-ms-filter:"alpha(Opacity=30)"}.iris-ie-lt9 .iris-square .iris-square-handle{background:0 0;border:3px solid #fff;-ms-filter:"alpha(Opacity=50)"}.iris-picker .iris-strip{margin-right:0;position:relative}.iris-picker .iris-strip .ui-slider-handle{position:absolute;background:0 0;margin:0;right:-3px;left:-3px;border:4px solid #aaa;border-width:4px 3px;width:auto;height:6px;border-radius:4px;box-shadow:0 1px 2px rgba(0,0,0,.2);opacity:.9;z-index:5;cursor:ns-resize}.iris-strip-horiz .iris-strip .ui-slider-handle{right:auto;left:auto;bottom:-3px;top:-3px;height:auto;width:6px;cursor:ew-resize}.iris-strip .ui-slider-handle:before{content:" ";position:absolute;left:-2px;right:-2px;top:-3px;bottom:-3px;border:2px solid #fff;border-radius:3px}.iris-picker .iris-slider-offset{position:absolute;top:11px;left:0;right:0;bottom:-3px;width:auto;height:auto;background:traLine truncated
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @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' );
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(n){var e=n("#language"),a=n("#language-continue");n("body").hasClass("language-chooser")&&(e.trigger("focus").on("change",function(){var n=e.children("option:selected");a.attr({value:n.data("continue"),lang:n.attr("lang")})}),n("form").on("submit",function(){e.children("option:selected").data("installed")||n(this).find(".step .spinner").css("visibility","visible")}))});
|
||||
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* @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 keyup keydown', function( event ){
|
||||
var t = $(this).attr('href');
|
||||
if ( event.type === 'keydown' && event.key === ' ' ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
if ( ( event.type === 'keyup' && event.key === ' ' ) || ( event.type === 'keydown' && event.key === 'Enter' ) || event.type === 'click' ) {
|
||||
event.preventDefault();
|
||||
$('#category-tabs a').removeAttr( 'aria-selected' ).attr( 'tabindex', '-1' );
|
||||
$(this).attr( 'aria-selected', 'true' ).removeAttr( 'tabindex' );
|
||||
$(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 ( event.type === 'keyup' && ( event.key === 'ArrowRight' || event.key === 'ArrowLeft' ) ) {
|
||||
$(this).attr( 'tabindex', '-1' );
|
||||
let next = $(this).parent('li').next();
|
||||
let prev = $(this).parent('li').prev();
|
||||
if ( next.length > 0 ) {
|
||||
next.find('a').removeAttr( 'tabindex');
|
||||
next.find('a').trigger( 'focus' );
|
||||
} else {
|
||||
prev.find('a').removeAttr( 'tabindex');
|
||||
prev.find('a').trigger( 'focus' );
|
||||
}
|
||||
}
|
||||
});
|
||||
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 = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).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' );
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(i){var e,r,t,a=!1;i("#link_name").trigger("focus"),postboxes.add_postbox_toggles("link"),i("#category-tabs a").on("click keyup keydown",function(e){var t=i(this).attr("href");if("keydown"===e.type&&" "===e.key&&e.preventDefault(),"keyup"===e.type&&" "===e.key||"keydown"===e.type&&"Enter"===e.key||"click"===e.type)return e.preventDefault(),i("#category-tabs a").removeAttr("aria-selected").attr("tabindex","-1"),i(this).attr("aria-selected","true").removeAttr("tabindex"),i(this).parent().addClass("tabs").siblings("li").removeClass("tabs"),i(".tabs-panel").hide(),i(t).show(),"#categories-all"==t?deleteUserSetting("cats"):setUserSetting("cats","pop"),!1;"keyup"!==e.type||"ArrowRight"!==e.key&&"ArrowLeft"!==e.key||(i(this).attr("tabindex","-1"),t=i(this).parent("li").next(),e=i(this).parent("li").prev(),(0<t.length?(t.find("a").removeAttr("tabindex"),t):(e.find("a").removeAttr("tabindex"),e)).find("a").trigger("focus"))}),getUserSetting("cats")&&i('#category-tabs a[href="#categories-pop"]').trigger("click"),e=i("#newcat").one("focus",function(){i(this).val("").removeClass("form-input-tip")}),i("#link-category-add-submit").on("click",function(){e.focus()}),r=function(){var e,t;a||(a=!0,e=(t=i(this)).is(":checked"),t=t.val().toString(),i("#in-link-category-"+t+", #in-popular-link_category-"+t).prop("checked",e),a=!1)},t=function(e,t){i(t.what+" response_data",e).each(function(){i(i(this).text()).find("label").each(function(){var e=i(this),t=e.find("input").val(),a=e.find("input")[0].id,e=e.text().trim();i("#"+a).on("change",r),i('<option value="'+parseInt(t,10)+'"></option>').text(e)})})},i("#categorychecklist").wpList({alt:"",what:"link-category",response:"category-ajax-response",addAfter:t}),i('a[href="#categories-all"]').on("click",function(){deleteUserSetting("cats")}),i('a[href="#categories-pop"]').on("click",function(){setUserSetting("cats","pop")}),"pop"==getUserSetting("cats")&&i('a[href="#categories-pop"]').trigger("click"),i("#category-add-toggle").on("click",function(){return i(this).parents("div:first").toggleClass("wp-hidden-children"),i('#category-tabs a[href="#categories-all"]').trigger("click"),i("#newcategory").trigger("focus"),!1}),i(".categorychecklist :checkbox").on("change",r).filter(":checked").trigger("change")});
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* This file is used on media-upload.php which has been replaced by media-new.php and upload.php
|
||||
*
|
||||
* @deprecated 3.5.0
|
||||
* @output wp-admin/js/media-gallery.js
|
||||
*/
|
||||
|
||||
/* global ajaxurl */
|
||||
jQuery(function($) {
|
||||
/**
|
||||
* Adds a click event handler to the element with a 'wp-gallery' class.
|
||||
*/
|
||||
$( 'body' ).on( 'click.wp-gallery', function(e) {
|
||||
var target = $( e.target ), id, img_size, nonceValue;
|
||||
|
||||
if ( target.hasClass( 'wp-set-header' ) ) {
|
||||
// Opens the image to preview it full size.
|
||||
( window.dialogArguments || opener || parent || top ).location.href = target.data( 'location' );
|
||||
e.preventDefault();
|
||||
} else if ( target.hasClass( 'wp-set-background' ) ) {
|
||||
// Sets the image as background of the theme.
|
||||
id = target.data( 'attachment-id' );
|
||||
img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val();
|
||||
nonceValue = $( '#_wpnonce' ).val() && '';
|
||||
|
||||
/**
|
||||
* This Ajax action has been deprecated since 3.5.0, see custom-background.php
|
||||
*/
|
||||
jQuery.post(ajaxurl, {
|
||||
action: 'set-background-image',
|
||||
attachment_id: id,
|
||||
_ajax_nonce: nonceValue,
|
||||
size: img_size
|
||||
}, function() {
|
||||
var win = window.dialogArguments || opener || parent || top;
|
||||
win.tb_remove();
|
||||
win.location.reload();
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(o){o("body").on("click.wp-gallery",function(a){var e,t,n=o(a.target);n.hasClass("wp-set-header")?((window.dialogArguments||opener||parent||top).location.href=n.data("location"),a.preventDefault()):n.hasClass("wp-set-background")&&(n=n.data("attachment-id"),e=o('input[name="attachments['+n+'][image-size]"]:checked').val(),t=o("#_wpnonce").val()&&"",jQuery.post(ajaxurl,{action:"set-background-image",attachment_id:n,_ajax_nonce:t,size:e},function(){var a=window.dialogArguments||opener||parent||top;a.tb_remove(),a.location.reload()}),a.preventDefault())})});
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Contains global functions for the media upload within the post edit screen.
|
||||
*
|
||||
* Updates the ThickBox anchor href and the ThickBox's own properties in order
|
||||
* to set the size and position on every resize event. Also adds a function to
|
||||
* send HTML or text to the currently active editor.
|
||||
*
|
||||
* @file
|
||||
* @since 2.5.0
|
||||
* @output wp-admin/js/media-upload.js
|
||||
*
|
||||
* @requires jQuery
|
||||
*/
|
||||
|
||||
/* global tinymce, QTags, wpActiveEditor, tb_position */
|
||||
|
||||
/**
|
||||
* Sends the HTML passed in the parameters to TinyMCE.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @global
|
||||
*
|
||||
* @param {string} html The HTML to be sent to the editor.
|
||||
* @return {void|boolean} Returns false when both TinyMCE and QTags instances
|
||||
* are unavailable. This means that the HTML was not
|
||||
* sent to the editor.
|
||||
*/
|
||||
window.send_to_editor = function( html ) {
|
||||
var editor,
|
||||
hasTinymce = typeof tinymce !== 'undefined',
|
||||
hasQuicktags = typeof QTags !== 'undefined';
|
||||
|
||||
// If no active editor is set, try to set it.
|
||||
if ( ! wpActiveEditor ) {
|
||||
if ( hasTinymce && tinymce.activeEditor ) {
|
||||
editor = tinymce.activeEditor;
|
||||
window.wpActiveEditor = editor.id;
|
||||
} else if ( ! hasQuicktags ) {
|
||||
return false;
|
||||
}
|
||||
} else if ( hasTinymce ) {
|
||||
editor = tinymce.get( wpActiveEditor );
|
||||
}
|
||||
|
||||
// If the editor is set and not hidden,
|
||||
// insert the HTML into the content of the editor.
|
||||
if ( editor && ! editor.isHidden() ) {
|
||||
editor.execCommand( 'mceInsertContent', false, html );
|
||||
} else if ( hasQuicktags ) {
|
||||
// If quick tags are available, insert the HTML into its content.
|
||||
QTags.insertContent( html );
|
||||
} else {
|
||||
// If neither the TinyMCE editor and the quick tags are available,
|
||||
// add the HTML to the current active editor.
|
||||
document.getElementById( wpActiveEditor ).value += html;
|
||||
}
|
||||
|
||||
// If the old thickbox remove function exists, call it.
|
||||
if ( window.tb_remove ) {
|
||||
try { window.tb_remove(); } catch( e ) {}
|
||||
}
|
||||
};
|
||||
|
||||
(function($) {
|
||||
/**
|
||||
* Recalculates and applies the new ThickBox position based on the current
|
||||
* window size.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*
|
||||
* @global
|
||||
*
|
||||
* @return {Object[]} Array containing jQuery objects for all the found
|
||||
* ThickBox anchors.
|
||||
*/
|
||||
window.tb_position = function() {
|
||||
var tbWindow = $('#TB_window'),
|
||||
width = $(window).width(),
|
||||
H = $(window).height(),
|
||||
W = ( 833 < width ) ? 833 : width,
|
||||
adminbar_height = 0;
|
||||
|
||||
if ( $('#wpadminbar').length ) {
|
||||
adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 );
|
||||
}
|
||||
|
||||
if ( tbWindow.length ) {
|
||||
tbWindow.width( W - 50 ).height( H - 45 - adminbar_height );
|
||||
$('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height );
|
||||
tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'});
|
||||
if ( typeof document.body.style.maxWidth !== 'undefined' )
|
||||
tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'});
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the new height and width for all links with a ThickBox class.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
return $('a.thickbox').each( function() {
|
||||
var href = $(this).attr('href');
|
||||
if ( ! href ) return;
|
||||
href = href.replace(/&width=[0-9]+/g, '');
|
||||
href = href.replace(/&height=[0-9]+/g, '');
|
||||
$(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 - adminbar_height ) );
|
||||
});
|
||||
};
|
||||
|
||||
// Add handler to recalculates the ThickBox position when the window is resized.
|
||||
$(window).on( 'resize', function(){ tb_position(); });
|
||||
|
||||
})(jQuery);
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.send_to_editor=function(t){var e,i="undefined"!=typeof tinymce,n="undefined"!=typeof QTags;if(wpActiveEditor)i&&(e=tinymce.get(wpActiveEditor));else if(i&&tinymce.activeEditor)e=tinymce.activeEditor,window.wpActiveEditor=e.id;else if(!n)return!1;if(e&&!e.isHidden()?e.execCommand("mceInsertContent",!1,t):n?QTags.insertContent(t):document.getElementById(wpActiveEditor).value+=t,window.tb_remove)try{window.tb_remove()}catch(t){}},function(d){window.tb_position=function(){var t=d("#TB_window"),e=d(window).width(),i=d(window).height(),n=833<e?833:e,o=0;return d("#wpadminbar").length&&(o=parseInt(d("#wpadminbar").css("height"),10)),t.length&&(t.width(n-50).height(i-45-o),d("#TB_iframeContent").width(n-50).height(i-75-o),t.css({"margin-left":"-"+parseInt((n-50)/2,10)+"px"}),void 0!==document.body.style.maxWidth)&&t.css({top:20+o+"px","margin-top":"0"}),d("a.thickbox").each(function(){var t=d(this).attr("href");t&&(t=(t=t.replace(/&width=[0-9]+/g,"")).replace(/&height=[0-9]+/g,""),d(this).attr("href",t+"&width="+(n-80)+"&height="+(i-85-o)))})},d(window).on("resize",function(){tb_position()})}(jQuery);
|
||||
@@ -0,0 +1,250 @@
|
||||
/**
|
||||
* 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( '<div class="ui-find-overlay"></div>' );
|
||||
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 );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! 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('<div class="ui-find-overlay"></div>'),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);
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(k){var I=window.wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11,sortableItems:"> *",targetTolerance:0},menuList:void 0,targetList:void 0,menusChanged:!1,isRTL:!("undefined"==typeof isRtl||!isRtl),negateIfRTL:"undefined"!=typeof isRtl&&isRtl?-1:1,lastSearch:"",init:function(){I.menuList=k("#menu-to-edit"),I.targetList=I.menuList,this.jQueryExtensions(),this.attachMenuEditListeners(),this.attachBulkSelectButtonListeners(),this.attachMenuCheckBoxListeners(),this.attachMenuItemDeleteButton(),this.attachPendingMenuItemsListForDeletion(),this.attachQuickSearchListeners(),this.attachThemeLocationsListeners(),this.attachMenuSaveSubmitListeners(),this.attachTabsPanelListeners(),this.attachUnsavedChangesListener(),I.menuList.length&&this.initSortables(),menus.oneThemeLocationNoMenus&&k("#posttype-page").addSelectedToMenu(I.addMenuItemToBottom),this.initManageLocations(),this.initAccessibility(),this.initToggles(),this.initPreviewing()},jQueryExtensions:function(){k.fn.extend({menuItemDepth:function(){var e=I.isRTL?this.eq(0).css("margin-right"):this.eq(0).css("margin-left");return I.pxToDepth(e&&-1!=e.indexOf("px")?e.slice(0,-2):0)},updateDepthClass:function(t,n){return this.each(function(){var e=k(this);n=n||e.menuItemDepth(),k(this).removeClass("menu-item-depth-"+n).addClass("menu-item-depth-"+t)})},shiftDepthClass:function(i){return this.each(function(){var e=k(this),t=e.menuItemDepth(),n=t+i;e.removeClass("menu-item-depth-"+t).addClass("menu-item-depth-"+n),0===n&&e.find(".is-submenu").hide()})},childMenuItems:function(){var i=k();return this.each(function(){for(var e=k(this),t=e.menuItemDepth(),n=e.next(".menu-item");n.length&&n.menuItemDepth()>t;)i=i.add(n),n=n.next(".menu-item")}),i},shiftHorizontally:function(n){return this.each(function(){var e=k(this),t=e.menuItemDepth();e.moveHorizontally(t+n,t)})},moveHorizontally:function(a,s){return this.each(function(){var e=k(this),t=e.childMenuItems(),n=a-s,i=e.find(".is-submenu");e.updateDepthClass(a,s).updateParentMenuItemDBId(),t&&t.each(function(){var e=k(this),t=e.menuItemDepth();e.updateDepthClass(t+n,t).updateParentMenuItemDBId()}),0===a?i.hide():i.show()})},updateParentMenuItemDBId:function(){return this.each(function(){var e=k(this),t=e.find(".menu-item-data-parent-id"),n=parseInt(e.menuItemDepth(),10),e=e.prevAll(".menu-item-depth-"+(n-1)).first();0===n?t.val(0):t.val(e.find(".menu-item-data-db-id").val())})},hideAdvancedMenuItemFields:function(){return this.each(function(){var e=k(this);k(".hide-column-tog").not(":checked").each(function(){e.find(".field-"+k(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(a){return 0!==k("#menu-to-edit").length&&this.each(function(){var e=k(this),n={},t=menus.oneThemeLocationNoMenus&&0===e.find(".tabs-panel-active .categorychecklist li input:checked").length?e.find('#page-all li input[type="checkbox"]'):e.find(".tabs-panel-active .categorychecklist li input:checked"),i=/menu-item\[([^\]]*)/;if(a=a||I.addMenuItemToBottom,!t.length)return!1;e.find(".button-controls .spinner").addClass("is-active"),k(t).each(function(){var e=k(this),t=i.exec(e.attr("name")),t=void 0===t[1]?0:parseInt(t[1],10);this.className&&-1!=this.className.indexOf("add-to-top")&&(a=I.addMenuItemToTop),n[t]=e.closest("li").getItemData("add-menu-item",t)}),I.addItemToMenu(n,a,function(){t.prop("checked",!1),e.find(".button-controls .select-all").prop("checked",!1),e.find(".button-controls .spinner").removeClass("is-active"),e.updateParentDropdown(),e.updateOrderDropdown()})})},getItemData:function(t,n){t=t||"menu-item";var i,a={},s=["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"];return(n=n||"menu-item"!=t?n:this.find(".menu-item-data-db-id").val())&&this.find("input").each(function(){var e;for(i=s.length;i--;)"menu-item"==t?e=s[i]+"["+n+"]":"add-menu-item"==t&&(e="menu-item["+n+"]["+s[i]+"]"),this.name&&e==this.name&&(a[s[i]]=this.value)}),a},setItemData:function(e,a,s){return a=a||"menu-item",(s=s||"menu-item"!=a?s:k(".menu-item-data-db-id",this).val())&&this.find("input").each(function(){var n,i=k(this);k.each(e,function(e,t){"menu-item"==a?n=e+"["+s+"]":"add-menu-item"==a&&(n="menu-item["+s+"]["+e+"]"),n==i.attr("name")&&i.val(t)})}),this},updateParentDropdown:function(){return this.each(function(){var s=k("#menu-to-edit li"),e=k(".edit-menu-item-parent");k.each(e,function(){var n=k(this),e=parseInt(n.closest("li.menu-item").find(".menu-item-data-db-id").val()),i=parseInt(n.closest("li.menu-item").find(".menu-item-data-parent-id").val()),t=n.closest("li.menu-item").childMenuItems(),a=[e];n.empty(),0<t.length&&k.each(t,function(){var e=k(this),e=parseInt(e.find(".menu-item-data-db-id").val());a.push(e)}),n.append(k("<option>",{value:"0",selected:0===i,text:wp.i18n._x("No Parent","menu item without a parLine truncated
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* @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);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},function(a){var e=wp.i18n.__,n=wp.i18n.sprintf;wp.passwordStrength={meter:function(e,n,t){return Array.isArray(n)||(n=[n.toString()]),e!=t&&t&&0<t.length?5:void 0===window.zxcvbn?-1:zxcvbn(e,n).score},userInputBlacklist:function(){return window.console.log(n(e("%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()")),wp.passwordStrength.userInputDisallowedList()},userInputDisallowedList:function(){var e,n,t,r,s=[],i=[],o=["user_login","first_name","last_name","nickname","display_name","email","url","description","weblog_title","admin_email"];for(s.push(document.title),s.push(document.URL),n=o.length,e=0;e<n;e++)0!==(r=a("#"+o[e])).length&&(s.push(r[0].defaultValue),s.push(r.val()));for(t=s.length,e=0;e<t;e++)s[e]&&(i=i.concat(s[e].replace(/\W/g," ").split(" ")));return i=a.grep(i,function(e,n){return!(""===e||e.length<4)&&a.inArray(e,i)===n})}},window.passwordStrength=wp.passwordStrength.meter}(jQuery);
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Adds functionality for password visibility buttons to toggle between text and password input types.
|
||||
*
|
||||
* @since 6.3.0
|
||||
* @output wp-admin/js/password-toggle.js
|
||||
*/
|
||||
|
||||
( function () {
|
||||
var toggleElements, status, input, icon, label, __ = wp.i18n.__;
|
||||
|
||||
toggleElements = document.querySelectorAll( '.pwd-toggle' );
|
||||
|
||||
toggleElements.forEach( function (toggle) {
|
||||
toggle.classList.remove( 'hide-if-no-js' );
|
||||
toggle.addEventListener( 'click', togglePassword );
|
||||
} );
|
||||
|
||||
function togglePassword() {
|
||||
status = this.getAttribute( 'data-toggle' );
|
||||
input = this.parentElement.children.namedItem( 'pwd' );
|
||||
icon = this.getElementsByClassName( 'dashicons' )[ 0 ];
|
||||
label = this.getElementsByClassName( 'text' )[ 0 ];
|
||||
|
||||
if ( 0 === parseInt( status, 10 ) ) {
|
||||
this.setAttribute( 'data-toggle', 1 );
|
||||
this.setAttribute( 'aria-label', __( 'Hide password' ) );
|
||||
input.setAttribute( 'type', 'text' );
|
||||
label.innerHTML = __( 'Hide' );
|
||||
icon.classList.remove( 'dashicons-visibility' );
|
||||
icon.classList.add( 'dashicons-hidden' );
|
||||
} else {
|
||||
this.setAttribute( 'data-toggle', 0 );
|
||||
this.setAttribute( 'aria-label', __( 'Show password' ) );
|
||||
input.setAttribute( 'type', 'password' );
|
||||
label.innerHTML = __( 'Show' );
|
||||
icon.classList.remove( 'dashicons-hidden' );
|
||||
icon.classList.add( 'dashicons-visibility' );
|
||||
}
|
||||
}
|
||||
} )();
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(){var t,e,s,i,a=wp.i18n.__;function d(){t=this.getAttribute("data-toggle"),e=this.parentElement.children.namedItem("pwd"),s=this.getElementsByClassName("dashicons")[0],i=this.getElementsByClassName("text")[0],0===parseInt(t,10)?(this.setAttribute("data-toggle",1),this.setAttribute("aria-label",a("Hide password")),e.setAttribute("type","text"),i.innerHTML=a("Hide"),s.classList.remove("dashicons-visibility"),s.classList.add("dashicons-hidden")):(this.setAttribute("data-toggle",0),this.setAttribute("aria-label",a("Show password")),e.setAttribute("type","password"),i.innerHTML=a("Show"),s.classList.remove("dashicons-hidden"),s.classList.add("dashicons-visibility"))}document.querySelectorAll(".pwd-toggle").forEach(function(t){t.classList.remove("hide-if-no-js"),t.addEventListener("click",d)})}();
|
||||
@@ -0,0 +1,229 @@
|
||||
/**
|
||||
* @file Functionality for the plugin install screens.
|
||||
*
|
||||
* @output wp-admin/js/plugin-install.js
|
||||
*/
|
||||
|
||||
/* global tb_click, tb_remove, tb_position */
|
||||
|
||||
jQuery( function( $ ) {
|
||||
|
||||
var tbWindow,
|
||||
$iframeBody,
|
||||
$tabbables,
|
||||
$firstTabbable,
|
||||
$lastTabbable,
|
||||
$focusedBefore = $(),
|
||||
$uploadViewToggle = $( '.upload-view-toggle' ),
|
||||
$wrap = $ ( '.wrap' ),
|
||||
$body = $( document.body );
|
||||
|
||||
window.tb_position = function() {
|
||||
var width = $( window ).width(),
|
||||
H = $( window ).height() - ( ( 792 < width ) ? 60 : 20 ),
|
||||
W = ( 792 < width ) ? 772 : width - 20;
|
||||
|
||||
tbWindow = $( '#TB_window' );
|
||||
|
||||
if ( tbWindow.length ) {
|
||||
tbWindow.width( W ).height( H );
|
||||
$( '#TB_iframeContent' ).width( W ).height( H );
|
||||
tbWindow.css({
|
||||
'margin-left': '-' + parseInt( ( W / 2 ), 10 ) + 'px'
|
||||
});
|
||||
if ( typeof document.body.style.maxWidth !== 'undefined' ) {
|
||||
tbWindow.css({
|
||||
'top': '30px',
|
||||
'margin-top': '0'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return $( 'a.thickbox' ).each( function() {
|
||||
var href = $( this ).attr( 'href' );
|
||||
if ( ! href ) {
|
||||
return;
|
||||
}
|
||||
href = href.replace( /&width=[0-9]+/g, '' );
|
||||
href = href.replace( /&height=[0-9]+/g, '' );
|
||||
$(this).attr( 'href', href + '&width=' + W + '&height=' + ( H ) );
|
||||
});
|
||||
};
|
||||
|
||||
$( window ).on( 'resize', function() {
|
||||
tb_position();
|
||||
});
|
||||
|
||||
/*
|
||||
* Custom events: when a Thickbox iframe has loaded and when the Thickbox
|
||||
* modal gets removed from the DOM.
|
||||
*/
|
||||
$body
|
||||
.on( 'thickbox:iframe:loaded', tbWindow, function() {
|
||||
/*
|
||||
* Return if it's not the modal with the plugin details iframe. Other
|
||||
* thickbox instances might want to load an iframe with content from
|
||||
* an external domain. Avoid to access the iframe contents when we're
|
||||
* not sure the iframe loads from the same domain.
|
||||
*/
|
||||
if ( ! tbWindow.hasClass( 'plugin-details-modal' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
iframeLoaded();
|
||||
})
|
||||
.on( 'thickbox:removed', function() {
|
||||
// Set focus back to the element that opened the modal dialog.
|
||||
// Note: IE 8 would need this wrapped in a fake setTimeout `0`.
|
||||
$focusedBefore.trigger( 'focus' );
|
||||
});
|
||||
|
||||
function iframeLoaded() {
|
||||
var $iframe = tbWindow.find( '#TB_iframeContent' );
|
||||
|
||||
// Get the iframe body.
|
||||
$iframeBody = $iframe.contents().find( 'body' );
|
||||
|
||||
// Get the tabbable elements and handle the keydown event on first load.
|
||||
handleTabbables();
|
||||
|
||||
// Set initial focus on the "Close" button.
|
||||
$firstTabbable.trigger( 'focus' );
|
||||
|
||||
/*
|
||||
* When the "Install" button is disabled (e.g. the Plugin is already installed)
|
||||
* then we can't predict where the last focusable element is. We need to get
|
||||
* the tabbable elements and handle the keydown event again and again,
|
||||
* each time the active tab panel changes.
|
||||
*/
|
||||
$( '#plugin-information-tabs a', $iframeBody ).on( 'click', function() {
|
||||
handleTabbables();
|
||||
});
|
||||
|
||||
// Close the modal when pressing Escape.
|
||||
$iframeBody.on( 'keydown', function( event ) {
|
||||
if ( 27 !== event.which ) {
|
||||
return;
|
||||
}
|
||||
tb_remove();
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the tabbable elements and detach/attach the keydown event.
|
||||
* Called after the iframe has fully loaded so we have all the elements we need.
|
||||
* Called again each time a Tab gets clicked.
|
||||
* @todo Consider to implement a WordPress general utility for this and don't use jQuery UI.
|
||||
*/
|
||||
function handleTabbables() {
|
||||
var $firstAndLast;
|
||||
// Get all the tabbable elements.
|
||||
$tabbables = $( ':tabbable', $iframeBody );
|
||||
// Our first tabbable element is always the "Close" button.
|
||||
$firstTabbable = tbWindow.find( '#TB_closeWindowButton' );
|
||||
// Get the last tabbable element.
|
||||
$lastTabbable = $tabbables.last();
|
||||
// Make a jQuery collection.
|
||||
$firstAndLast = $firstTabbable.add( $lastTabbable );
|
||||
// Detach any previously attached keydown event.
|
||||
$firstAndLast.off( 'keydown.wp-plugin-details' );
|
||||
// Attach again the keydown event on the first and last focusable elements.
|
||||
$firstAndLast.on( 'keydown.wp-plugin-details', function( event ) {
|
||||
constrainTabbing( event );
|
||||
});
|
||||
}
|
||||
|
||||
// Constrain tabbing within the plugin modal dialog.
|
||||
function constrainTabbing( event ) {
|
||||
if ( 9 !== event.which ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $lastTabbable[0] === event.target && ! event.shiftKey ) {
|
||||
event.preventDefault();
|
||||
$firstTabbable.trigger( 'focus' );
|
||||
} else if ( $firstTabbable[0] === event.target && event.shiftKey ) {
|
||||
event.preventDefault();
|
||||
$lastTabbable.trigger( 'focus' );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the Plugin details modal. The event is delegated to get also the links
|
||||
* in the plugins search tab, after the Ajax search rebuilds the HTML. It's
|
||||
* delegated on the closest ancestor and not on the body to avoid conflicts
|
||||
* with other handlers, see Trac ticket #43082.
|
||||
*/
|
||||
$( '.wrap' ).on( 'click', '.thickbox.open-plugin-details-modal', function( e ) {
|
||||
// The `data-title` attribute is used only in the Plugin screens.
|
||||
var title = $( this ).data( 'title' ) ?
|
||||
wp.i18n.sprintf(
|
||||
// translators: %s: Plugin name.
|
||||
wp.i18n.__( 'Plugin: %s' ),
|
||||
$( this ).data( 'title' )
|
||||
) :
|
||||
wp.i18n.__( 'Plugin details' );
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Store the element that has focus before opening the modal dialog, i.e. the control which opens it.
|
||||
$focusedBefore = $( this );
|
||||
|
||||
tb_click.call(this);
|
||||
|
||||
// Set ARIA role, ARIA label, and add a CSS class.
|
||||
tbWindow
|
||||
.attr({
|
||||
'role': 'dialog',
|
||||
'aria-label': wp.i18n.__( 'Plugin details' )
|
||||
})
|
||||
.addClass( 'plugin-details-modal' );
|
||||
|
||||
// Set title attribute on the iframe.
|
||||
tbWindow.find( '#TB_iframeContent' ).attr( 'title', title );
|
||||
});
|
||||
|
||||
/* Plugin install related JS */
|
||||
$( '#plugin-information-tabs a' ).on( 'click', function( event ) {
|
||||
var tab = $( this ).attr( 'name' );
|
||||
event.preventDefault();
|
||||
|
||||
// Flip the tab.
|
||||
$( '#plugin-information-tabs a.current' ).removeClass( 'current' );
|
||||
$( this ).addClass( 'current' );
|
||||
|
||||
// Only show the fyi box in the description section, on smaller screen,
|
||||
// where it's otherwise always displayed at the top.
|
||||
if ( 'description' !== tab && $( window ).width() < 772 ) {
|
||||
$( '#plugin-information-content' ).find( '.fyi' ).hide();
|
||||
} else {
|
||||
$( '#plugin-information-content' ).find( '.fyi' ).show();
|
||||
}
|
||||
|
||||
// Flip the content.
|
||||
$( '#section-holder div.section' ).hide(); // Hide 'em all.
|
||||
$( '#section-' + tab ).show();
|
||||
});
|
||||
|
||||
/*
|
||||
* When a user presses the "Upload Plugin" button, show the upload form in place
|
||||
* rather than sending them to the devoted upload plugin page.
|
||||
* The `?tab=upload` page still exists for no-js support and for plugins that
|
||||
* might access it directly. When we're in this page, let the link behave
|
||||
* like a link. Otherwise we're in the normal plugin installer pages and the
|
||||
* link should behave like a toggle button.
|
||||
*/
|
||||
if ( ! $wrap.hasClass( 'plugin-install-tab-upload' ) ) {
|
||||
$uploadViewToggle
|
||||
.attr({
|
||||
role: 'button',
|
||||
'aria-expanded': 'false'
|
||||
})
|
||||
.on( 'click', function( event ) {
|
||||
event.preventDefault();
|
||||
$body.toggleClass( 'show-upload-view' );
|
||||
$uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
|
||||
});
|
||||
}
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(e){var o,i,n,a,l,r=e(),s=e(".upload-view-toggle"),t=e(".wrap"),d=e(document.body);function c(){var t;n=e(":tabbable",i),a=o.find("#TB_closeWindowButton"),l=n.last(),(t=a.add(l)).off("keydown.wp-plugin-details"),t.on("keydown.wp-plugin-details",function(t){9===(t=t).which&&(l[0]!==t.target||t.shiftKey?a[0]===t.target&&t.shiftKey&&(t.preventDefault(),l.trigger("focus")):(t.preventDefault(),a.trigger("focus")))})}window.tb_position=function(){var t=e(window).width(),i=e(window).height()-(792<t?60:20),n=792<t?772:t-20;return(o=e("#TB_window")).length&&(o.width(n).height(i),e("#TB_iframeContent").width(n).height(i),o.css({"margin-left":"-"+parseInt(n/2,10)+"px"}),void 0!==document.body.style.maxWidth)&&o.css({top:"30px","margin-top":"0"}),e("a.thickbox").each(function(){var t=e(this).attr("href");t&&(t=(t=t.replace(/&width=[0-9]+/g,"")).replace(/&height=[0-9]+/g,""),e(this).attr("href",t+"&width="+n+"&height="+i))})},e(window).on("resize",function(){tb_position()}),d.on("thickbox:iframe:loaded",o,function(){var t;o.hasClass("plugin-details-modal")&&(t=o.find("#TB_iframeContent"),i=t.contents().find("body"),c(),a.trigger("focus"),e("#plugin-information-tabs a",i).on("click",function(){c()}),i.on("keydown",function(t){27===t.which&&tb_remove()}))}).on("thickbox:removed",function(){r.trigger("focus")}),e(".wrap").on("click",".thickbox.open-plugin-details-modal",function(t){var i=e(this).data("title")?wp.i18n.sprintf(wp.i18n.__("Plugin: %s"),e(this).data("title")):wp.i18n.__("Plugin details");t.preventDefault(),t.stopPropagation(),r=e(this),tb_click.call(this),o.attr({role:"dialog","aria-label":wp.i18n.__("Plugin details")}).addClass("plugin-details-modal"),o.find("#TB_iframeContent").attr("title",i)}),e("#plugin-information-tabs a").on("click",function(t){var i=e(this).attr("name");t.preventDefault(),e("#plugin-information-tabs a.current").removeClass("current"),e(this).addClass("current"),"description"!==i&&e(window).width()<772?e("#plugin-information-content").find(".fyi").hide():e("#plugin-information-content").find(".fyi").show(),e("#section-holder div.section").hide(),e("#section-"+i).show()}),t.hasClass("plugin-install-tab-upload")||s.attr({role:"button","aria-expanded":"false"}).on("click",function(t){t.preventDefault(),d.toggleClass("show-upload-view"),s.attr("aria-expanded",d.hasClass("show-upload-view"))})});
|
||||
+1375
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! 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('<tr><td colspan="2">'+wpAjax.broken+"</td></tr>")}),!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<e.length&&s("#meta\\["+e.attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(t)},window.WPRemoveThumbnail=function(t){s.post(ajaxurl,{action:"set-post-thumbnail",post_id:s("#post_ID").val(),thumbnail_id:-1,_ajax_nonce:t,cookie:encodeURIComponent(document.cookie)},function(t){"0"==t?alert(a("Could not set that as the thumbnail image. Try a different attachment.")):WPSetThumbnailHTML(t)})},s(document).on("heartbeat-send.refresh-lock",function(t,e){var i=s("#active_post_lock").val(),a=s("#post_ID").val(),n={};a&&s("#post-lock-dialog").length&&(n.post_id=a,i&&(n.lock=i),e["wp-refresh-post-lock"]=n)}).on("heartbeat-tick.refresh-lock",function(t,e){var i,a;e["wp-refresh-post-lock"]&&((e=e["wp-refresh-post-lock"]).lock_error?(i=s("#post-lock-dialog")).length&&!i.is(":visible")&&(wp.autosave&&(s(document).one("heartbeat-tick",function(){wp.autosave.server.suspend(),i.removeClass("saving").addClass("saved"),s(window).off("beforeunload.edit-post")}),i.addClass("saving"),wp.autosave.server.triggerSave()),e.lock_error.avatar_src&&(a=s("<img />",{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"),y=!!window.navigator.platform&&-1!==window.navigator.platform.indexOf("Mac"),_=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<t)&&(t=30),parseInt(h("#content_ifr").css("height"),10)+t-28):(u.trigger("focus"),parseInt(u.css("height"),10)),v.off(".wp-editor-resize"),t&&50<t&&t<5e3&&setUserSetting("ed_size",t))}postboxes.add_postbox_toggles(pagenow),window.name="",h("#post-lock-dialog .notification-dialog").on("keydown",function(t){var e;9==t.which&&((e=h(t.target)).hasClass("wp-tab-first")&&t.shiftKey?(h(this).find(".wp-tab-last").trigger("focus"),t.preventDefault()):e.hasClass("wp-tab-last")&&!t.shiftKey&&(h(this).find(".wp-tab-first").trigger("focus"),t.preventDefault()))}).filter(":visible").find(".wp-tab-first").trigger("focus"),wp.heartbeat&&h("#post-lock-dialog").length&&wp.heartbeat.interval(10),i=m.find(":submit, a.submitdelete, #post-preview").on("clickLine truncated
|
||||
@@ -0,0 +1,660 @@
|
||||
/**
|
||||
* Contains the postboxes logic, opening and closing postboxes, reordering and saving
|
||||
* the state and ordering to the database.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @requires jQuery
|
||||
* @output wp-admin/js/postbox.js
|
||||
*/
|
||||
|
||||
/* global ajaxurl, postboxes */
|
||||
|
||||
(function($) {
|
||||
var $document = $( document ),
|
||||
__ = wp.i18n.__;
|
||||
|
||||
/**
|
||||
* This object contains all function to handle the behavior of the post boxes. The post boxes are the boxes you see
|
||||
* around the content on the edit page.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @namespace postboxes
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
window.postboxes = {
|
||||
|
||||
/**
|
||||
* Handles a click on either the postbox heading or the postbox open/close icon.
|
||||
*
|
||||
* Opens or closes the postbox. Expects `this` to equal the clicked element.
|
||||
* Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide
|
||||
* if the postbox has been closed.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @fires postboxes#postbox-toggled
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
handle_click : function () {
|
||||
var $el = $( this ),
|
||||
p = $el.closest( '.postbox' ),
|
||||
id = p.attr( 'id' ),
|
||||
ariaExpandedValue;
|
||||
|
||||
if ( 'dashboard_browser_nag' === id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.toggleClass( 'closed' );
|
||||
ariaExpandedValue = ! p.hasClass( 'closed' );
|
||||
|
||||
if ( $el.hasClass( 'handlediv' ) ) {
|
||||
// The handle button was clicked.
|
||||
$el.attr( 'aria-expanded', ariaExpandedValue );
|
||||
} else {
|
||||
// The handle heading was clicked.
|
||||
$el.closest( '.postbox' ).find( 'button.handlediv' )
|
||||
.attr( 'aria-expanded', ariaExpandedValue );
|
||||
}
|
||||
|
||||
if ( postboxes.page !== 'press-this' ) {
|
||||
postboxes.save_state( postboxes.page );
|
||||
}
|
||||
|
||||
if ( id ) {
|
||||
if ( !p.hasClass('closed') && typeof postboxes.pbshow === 'function' ) {
|
||||
postboxes.pbshow( id );
|
||||
} else if ( p.hasClass('closed') && typeof postboxes.pbhide === 'function' ) {
|
||||
postboxes.pbhide( id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires when a postbox has been opened or closed.
|
||||
*
|
||||
* Contains a jQuery object with the relevant postbox element.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @ignore
|
||||
*
|
||||
* @event postboxes#postbox-toggled
|
||||
* @type {Object}
|
||||
*/
|
||||
$document.trigger( 'postbox-toggled', p );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles clicks on the move up/down buttons.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
handleOrder: function() {
|
||||
var button = $( this ),
|
||||
postbox = button.closest( '.postbox' ),
|
||||
postboxId = postbox.attr( 'id' ),
|
||||
postboxesWithinSortables = postbox.closest( '.meta-box-sortables' ).find( '.postbox:visible' ),
|
||||
postboxesWithinSortablesCount = postboxesWithinSortables.length,
|
||||
postboxWithinSortablesIndex = postboxesWithinSortables.index( postbox ),
|
||||
firstOrLastPositionMessage;
|
||||
|
||||
if ( 'dashboard_browser_nag' === postboxId ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If on the first or last position, do nothing and send an audible message to screen reader users.
|
||||
if ( 'true' === button.attr( 'aria-disabled' ) ) {
|
||||
firstOrLastPositionMessage = button.hasClass( 'handle-order-higher' ) ?
|
||||
__( 'The box is on the first position' ) :
|
||||
__( 'The box is on the last position' );
|
||||
|
||||
wp.a11y.speak( firstOrLastPositionMessage );
|
||||
return;
|
||||
}
|
||||
|
||||
// Move a postbox up.
|
||||
if ( button.hasClass( 'handle-order-higher' ) ) {
|
||||
// If the box is first within a sortable area, move it to the previous sortable area.
|
||||
if ( 0 === postboxWithinSortablesIndex ) {
|
||||
postboxes.handleOrderBetweenSortables( 'previous', button, postbox );
|
||||
return;
|
||||
}
|
||||
|
||||
postbox.prevAll( '.postbox:visible' ).eq( 0 ).before( postbox );
|
||||
button.trigger( 'focus' );
|
||||
postboxes.updateOrderButtonsProperties();
|
||||
postboxes.save_order( postboxes.page );
|
||||
}
|
||||
|
||||
// Move a postbox down.
|
||||
if ( button.hasClass( 'handle-order-lower' ) ) {
|
||||
// If the box is last within a sortable area, move it to the next sortable area.
|
||||
if ( postboxWithinSortablesIndex + 1 === postboxesWithinSortablesCount ) {
|
||||
postboxes.handleOrderBetweenSortables( 'next', button, postbox );
|
||||
return;
|
||||
}
|
||||
|
||||
postbox.nextAll( '.postbox:visible' ).eq( 0 ).after( postbox );
|
||||
button.trigger( 'focus' );
|
||||
postboxes.updateOrderButtonsProperties();
|
||||
postboxes.save_order( postboxes.page );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves postboxes between the sortables areas.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param {string} position The "previous" or "next" sortables area.
|
||||
* @param {Object} button The jQuery object representing the button that was clicked.
|
||||
* @param {Object} postbox The jQuery object representing the postbox to be moved.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
handleOrderBetweenSortables: function( position, button, postbox ) {
|
||||
var closestSortablesId = button.closest( '.meta-box-sortables' ).attr( 'id' ),
|
||||
sortablesIds = [],
|
||||
sortablesIndex,
|
||||
detachedPostbox;
|
||||
|
||||
// Get the list of sortables within the page.
|
||||
$( '.meta-box-sortables:visible' ).each( function() {
|
||||
sortablesIds.push( $( this ).attr( 'id' ) );
|
||||
});
|
||||
|
||||
// Return if there's only one visible sortables area, e.g. in the block editor page.
|
||||
if ( 1 === sortablesIds.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the index of the current sortables area within all the sortable areas.
|
||||
sortablesIndex = $.inArray( closestSortablesId, sortablesIds );
|
||||
// Detach the postbox to be moved.
|
||||
detachedPostbox = postbox.detach();
|
||||
|
||||
// Move the detached postbox to its new position.
|
||||
if ( 'previous' === position ) {
|
||||
$( detachedPostbox ).appendTo( '#' + sortablesIds[ sortablesIndex - 1 ] );
|
||||
}
|
||||
|
||||
if ( 'next' === position ) {
|
||||
$( detachedPostbox ).prependTo( '#' + sortablesIds[ sortablesIndex + 1 ] );
|
||||
}
|
||||
|
||||
postboxes._mark_area();
|
||||
button.focus();
|
||||
postboxes.updateOrderButtonsProperties();
|
||||
postboxes.save_order( postboxes.page );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the move buttons properties depending on the postbox position.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
updateOrderButtonsProperties: function() {
|
||||
var firstSortablesId = $( '.meta-box-sortables:visible:first' ).attr( 'id' ),
|
||||
lastSortablesId = $( '.meta-box-sortables:visible:last' ).attr( 'id' ),
|
||||
firstPostbox = $( '.postbox:visible:first' ),
|
||||
lastPostbox = $( '.postbox:visible:last' ),
|
||||
firstPostboxId = firstPostbox.attr( 'id' ),
|
||||
lastPostboxId = lastPostbox.attr( 'id' ),
|
||||
firstPostboxSortablesId = firstPostbox.closest( '.meta-box-sortables' ).attr( 'id' ),
|
||||
lastPostboxSortablesId = lastPostbox.closest( '.meta-box-sortables' ).attr( 'id' ),
|
||||
moveUpButtons = $( '.handle-order-higher' ),
|
||||
moveDownButtons = $( '.handle-order-lower' );
|
||||
|
||||
// Enable all buttons as a reset first.
|
||||
moveUpButtons
|
||||
.attr( 'aria-disabled', 'false' )
|
||||
.removeClass( 'hidden' );
|
||||
moveDownButtons
|
||||
.attr( 'aria-disabled', 'false' )
|
||||
.removeClass( 'hidden' );
|
||||
|
||||
// When there's only one "sortables" area (e.g. in the block editor) and only one visible postbox, hide the buttons.
|
||||
if ( firstSortablesId === lastSortablesId && firstPostboxId === lastPostboxId ) {
|
||||
moveUpButtons.addClass( 'hidden' );
|
||||
moveDownButtons.addClass( 'hidden' );
|
||||
}
|
||||
|
||||
// Set an aria-disabled=true attribute on the first visible "move" buttons.
|
||||
if ( firstSortablesId === firstPostboxSortablesId ) {
|
||||
$( firstPostbox ).find( '.handle-order-higher' ).attr( 'aria-disabled', 'true' );
|
||||
}
|
||||
|
||||
// Set an aria-disabled=true attribute on the last visible "move" buttons.
|
||||
if ( lastSortablesId === lastPostboxSortablesId ) {
|
||||
$( '.postbox:visible .handle-order-lower' ).last().attr( 'aria-disabled', 'true' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds event handlers to all postboxes and screen option on the current page.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @param {string} page The page we are currently on.
|
||||
* @param {Object} [args]
|
||||
* @param {Function} args.pbshow A callback that is called when a postbox opens.
|
||||
* @param {Function} args.pbhide A callback that is called when a postbox closes.
|
||||
* @return {void}
|
||||
*/
|
||||
add_postbox_toggles : function (page, args) {
|
||||
var $handles = $( '.postbox .hndle, .postbox .handlediv' ),
|
||||
$orderButtons = $( '.postbox .handle-order-higher, .postbox .handle-order-lower' );
|
||||
|
||||
this.page = page;
|
||||
this.init( page, args );
|
||||
|
||||
$handles.on( 'click.postboxes', this.handle_click );
|
||||
|
||||
// Handle the order of the postboxes.
|
||||
$orderButtons.on( 'click.postboxes', this.handleOrder );
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
*/
|
||||
$('.postbox .hndle a').on( 'click', function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
/**
|
||||
* Hides a postbox.
|
||||
*
|
||||
* Event handler for the postbox dismiss button. After clicking the button
|
||||
* the postbox will be hidden.
|
||||
*
|
||||
* As of WordPress 5.5, this is only used for the browser update nag.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) {
|
||||
var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
|
||||
e.preventDefault();
|
||||
$( '#' + hide_id ).prop('checked', false).triggerHandler('click');
|
||||
});
|
||||
|
||||
/**
|
||||
* Hides the postbox element
|
||||
*
|
||||
* Event handler for the screen options checkboxes. When a checkbox is
|
||||
* clicked this function will hide or show the relevant postboxes.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @ignore
|
||||
*
|
||||
* @fires postboxes#postbox-toggled
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$('.hide-postbox-tog').on('click.postboxes', function() {
|
||||
var $el = $(this),
|
||||
boxId = $el.val(),
|
||||
$postbox = $( '#' + boxId );
|
||||
|
||||
if ( $el.prop( 'checked' ) ) {
|
||||
$postbox.show();
|
||||
if ( typeof postboxes.pbshow === 'function' ) {
|
||||
postboxes.pbshow( boxId );
|
||||
}
|
||||
} else {
|
||||
$postbox.hide();
|
||||
if ( typeof postboxes.pbhide === 'function' ) {
|
||||
postboxes.pbhide( boxId );
|
||||
}
|
||||
}
|
||||
|
||||
postboxes.save_state( page );
|
||||
postboxes._mark_area();
|
||||
|
||||
/**
|
||||
* @since 4.0.0
|
||||
* @see postboxes.handle_click
|
||||
*/
|
||||
$document.trigger( 'postbox-toggled', $postbox );
|
||||
});
|
||||
|
||||
/**
|
||||
* Changes the amount of columns based on the layout preferences.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$('.columns-prefs input[type="radio"]').on('click.postboxes', function(){
|
||||
var n = parseInt($(this).val(), 10);
|
||||
|
||||
if ( n ) {
|
||||
postboxes._pb_edit(n);
|
||||
postboxes.save_order( page );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes all the postboxes, mainly their sortable behavior.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @param {string} page The page we are currently on.
|
||||
* @param {Object} [args={}] The arguments for the postbox initializer.
|
||||
* @param {Function} args.pbshow A callback that is called when a postbox opens.
|
||||
* @param {Function} args.pbhide A callback that is called when a postbox
|
||||
* closes.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
init : function(page, args) {
|
||||
var isMobile = $( document.body ).hasClass( 'mobile' ),
|
||||
$handleButtons = $( '.postbox .handlediv' );
|
||||
|
||||
$.extend( this, args || {} );
|
||||
$('.meta-box-sortables').sortable({
|
||||
placeholder: 'sortable-placeholder',
|
||||
connectWith: '.meta-box-sortables',
|
||||
items: '.postbox',
|
||||
handle: '.hndle',
|
||||
cursor: 'move',
|
||||
delay: ( isMobile ? 200 : 0 ),
|
||||
distance: 2,
|
||||
tolerance: 'pointer',
|
||||
forcePlaceholderSize: true,
|
||||
helper: function( event, element ) {
|
||||
/* `helper: 'clone'` is equivalent to `return element.clone();`
|
||||
* Cloning a checked radio and then inserting that clone next to the original
|
||||
* radio unchecks the original radio (since only one of the two can be checked).
|
||||
* We get around this by renaming the helper's inputs' name attributes so that,
|
||||
* when the helper is inserted into the DOM for the sortable, no radios are
|
||||
* duplicated, and no original radio gets unchecked.
|
||||
*/
|
||||
return element.clone()
|
||||
.find( ':input' )
|
||||
.attr( 'name', function( i, currentName ) {
|
||||
return 'sort_' + parseInt( Math.random() * 100000, 10 ).toString() + '_' + currentName;
|
||||
} )
|
||||
.end();
|
||||
},
|
||||
opacity: 0.65,
|
||||
start: function() {
|
||||
$( 'body' ).addClass( 'is-dragging-metaboxes' );
|
||||
// Refresh the cached positions of all the sortable items so that the min-height set while dragging works.
|
||||
$( '.meta-box-sortables' ).sortable( 'refreshPositions' );
|
||||
},
|
||||
stop: function() {
|
||||
var $el = $( this );
|
||||
|
||||
$( 'body' ).removeClass( 'is-dragging-metaboxes' );
|
||||
|
||||
if ( $el.find( '#dashboard_browser_nag' ).is( ':visible' ) && 'dashboard_browser_nag' != this.firstChild.id ) {
|
||||
$el.sortable('cancel');
|
||||
return;
|
||||
}
|
||||
|
||||
postboxes.updateOrderButtonsProperties();
|
||||
postboxes.save_order(page);
|
||||
},
|
||||
receive: function(e,ui) {
|
||||
if ( 'dashboard_browser_nag' == ui.item[0].id )
|
||||
$(ui.sender).sortable('cancel');
|
||||
|
||||
postboxes._mark_area();
|
||||
$document.trigger( 'postbox-moved', ui.item );
|
||||
}
|
||||
});
|
||||
|
||||
if ( isMobile ) {
|
||||
$(document.body).on('orientationchange.postboxes', function(){ postboxes._pb_change(); });
|
||||
this._pb_change();
|
||||
}
|
||||
|
||||
this._mark_area();
|
||||
|
||||
// Update the "move" buttons properties.
|
||||
this.updateOrderButtonsProperties();
|
||||
$document.on( 'postbox-toggled', this.updateOrderButtonsProperties );
|
||||
|
||||
// Set the handle buttons `aria-expanded` attribute initial value on page load.
|
||||
$handleButtons.each( function () {
|
||||
var $el = $( this );
|
||||
$el.attr( 'aria-expanded', ! $el.closest( '.postbox' ).hasClass( 'closed' ) );
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves the state of the postboxes to the server.
|
||||
*
|
||||
* It sends two lists, one with all the closed postboxes, one with all the
|
||||
* hidden postboxes.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @param {string} page The page we are currently on.
|
||||
* @return {void}
|
||||
*/
|
||||
save_state : function(page) {
|
||||
var closed, hidden;
|
||||
|
||||
// Return on the nav-menus.php screen, see #35112.
|
||||
if ( 'nav-menus' === page ) {
|
||||
return;
|
||||
}
|
||||
|
||||
closed = $( '.postbox' ).filter( '.closed' ).map( function() { return this.id; } ).get().join( ',' );
|
||||
hidden = $( '.postbox' ).filter( ':hidden' ).map( function() { return this.id; } ).get().join( ',' );
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'closed-postboxes',
|
||||
closed: closed,
|
||||
hidden: hidden,
|
||||
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
|
||||
page: page
|
||||
},
|
||||
function() {
|
||||
wp.a11y.speak( __( 'Screen Options updated.' ) );
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves the order of the postboxes to the server.
|
||||
*
|
||||
* Sends a list of all postboxes inside a sortable area to the server.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @param {string} page The page we are currently on.
|
||||
* @return {void}
|
||||
*/
|
||||
save_order : function(page) {
|
||||
var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
|
||||
|
||||
postVars = {
|
||||
action: 'meta-box-order',
|
||||
_ajax_nonce: $('#meta-box-order-nonce').val(),
|
||||
page_columns: page_columns,
|
||||
page: page
|
||||
};
|
||||
|
||||
$('.meta-box-sortables').each( function() {
|
||||
postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
|
||||
} );
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
postVars,
|
||||
function( response ) {
|
||||
if ( response.success ) {
|
||||
wp.a11y.speak( __( 'The boxes order has been saved.' ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Marks empty postbox areas.
|
||||
*
|
||||
* Adds a message to empty sortable areas on the dashboard page. Also adds a
|
||||
* border around the side area on the post edit screen if there are no postboxes
|
||||
* present.
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @access private
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
_mark_area : function() {
|
||||
var visible = $( 'div.postbox:visible' ).length,
|
||||
visibleSortables = $( '#dashboard-widgets .meta-box-sortables:visible, #post-body .meta-box-sortables:visible' ),
|
||||
areAllVisibleSortablesEmpty = true;
|
||||
|
||||
visibleSortables.each( function() {
|
||||
var t = $(this);
|
||||
|
||||
if ( visible == 1 || t.children( '.postbox:visible' ).length ) {
|
||||
t.removeClass('empty-container');
|
||||
areAllVisibleSortablesEmpty = false;
|
||||
}
|
||||
else {
|
||||
t.addClass('empty-container');
|
||||
}
|
||||
});
|
||||
|
||||
postboxes.updateEmptySortablesText( visibleSortables, areAllVisibleSortablesEmpty );
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the text for the empty sortable areas on the Dashboard.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param {Object} visibleSortables The jQuery object representing the visible sortable areas.
|
||||
* @param {boolean} areAllVisibleSortablesEmpty Whether all the visible sortable areas are "empty".
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
updateEmptySortablesText: function( visibleSortables, areAllVisibleSortablesEmpty ) {
|
||||
var isDashboard = $( '#dashboard-widgets' ).length,
|
||||
emptySortableText = areAllVisibleSortablesEmpty ? __( 'Add boxes from the Screen Options menu' ) : __( 'Drag boxes here' );
|
||||
|
||||
if ( ! isDashboard ) {
|
||||
return;
|
||||
}
|
||||
|
||||
visibleSortables.each( function() {
|
||||
if ( $( this ).hasClass( 'empty-container' ) ) {
|
||||
$( this ).attr( 'data-emptyString', emptySortableText );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the amount of columns on the post edit page.
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @access private
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @fires postboxes#postboxes-columnchange
|
||||
*
|
||||
* @param {number} n The amount of columns to divide the post edit page in.
|
||||
* @return {void}
|
||||
*/
|
||||
_pb_edit : function(n) {
|
||||
var el = $('.metabox-holder').get(0);
|
||||
|
||||
if ( el ) {
|
||||
el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires when the amount of columns on the post edit page has been changed.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @ignore
|
||||
*
|
||||
* @event postboxes#postboxes-columnchange
|
||||
*/
|
||||
$( document ).trigger( 'postboxes-columnchange' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the amount of columns the postboxes are in based on the current
|
||||
* orientation of the browser.
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @access private
|
||||
*
|
||||
* @memberof postboxes
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
_pb_change : function() {
|
||||
var check = $( 'label.columns-prefs-1 input[type="radio"]' );
|
||||
|
||||
switch ( window.orientation ) {
|
||||
case 90:
|
||||
case -90:
|
||||
if ( !check.length || !check.is(':checked') )
|
||||
this._pb_edit(2);
|
||||
break;
|
||||
case 0:
|
||||
case 180:
|
||||
if ( $( '#poststuff' ).length ) {
|
||||
this._pb_edit(1);
|
||||
} else {
|
||||
if ( !check.length || !check.is(':checked') )
|
||||
this._pb_edit(2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/* Callbacks */
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @access public
|
||||
*
|
||||
* @property {Function|boolean} pbshow A callback that is called when a postbox
|
||||
* is opened.
|
||||
* @memberof postboxes
|
||||
*/
|
||||
pbshow : false,
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @access public
|
||||
* @property {Function|boolean} pbhide A callback that is called when a postbox
|
||||
* is closed.
|
||||
* @memberof postboxes
|
||||
*/
|
||||
pbhide : false
|
||||
};
|
||||
|
||||
}(jQuery));
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(l){var a=l(document),r=wp.i18n.__;window.postboxes={handle_click:function(){var e,o=l(this),s=o.closest(".postbox"),t=s.attr("id");"dashboard_browser_nag"!==t&&(s.toggleClass("closed"),e=!s.hasClass("closed"),(o.hasClass("handlediv")?o:o.closest(".postbox").find("button.handlediv")).attr("aria-expanded",e),"press-this"!==postboxes.page&&postboxes.save_state(postboxes.page),t&&(s.hasClass("closed")||"function"!=typeof postboxes.pbshow?s.hasClass("closed")&&"function"==typeof postboxes.pbhide&&postboxes.pbhide(t):postboxes.pbshow(t)),a.trigger("postbox-toggled",s))},handleOrder:function(){var e=l(this),o=e.closest(".postbox"),s=o.attr("id"),t=o.closest(".meta-box-sortables").find(".postbox:visible"),a=t.length,t=t.index(o);if("dashboard_browser_nag"!==s)if("true"===e.attr("aria-disabled"))s=e.hasClass("handle-order-higher")?r("The box is on the first position"):r("The box is on the last position"),wp.a11y.speak(s);else{if(e.hasClass("handle-order-higher")){if(0===t)return void postboxes.handleOrderBetweenSortables("previous",e,o);o.prevAll(".postbox:visible").eq(0).before(o),e.trigger("focus"),postboxes.updateOrderButtonsProperties(),postboxes.save_order(postboxes.page)}e.hasClass("handle-order-lower")&&(t+1===a?postboxes.handleOrderBetweenSortables("next",e,o):(o.nextAll(".postbox:visible").eq(0).after(o),e.trigger("focus"),postboxes.updateOrderButtonsProperties(),postboxes.save_order(postboxes.page)))}},handleOrderBetweenSortables:function(e,o,s){var t=o.closest(".meta-box-sortables").attr("id"),a=[];l(".meta-box-sortables:visible").each(function(){a.push(l(this).attr("id"))}),1!==a.length&&(t=l.inArray(t,a),s=s.detach(),"previous"===e&&l(s).appendTo("#"+a[t-1]),"next"===e&&l(s).prependTo("#"+a[t+1]),postboxes._mark_area(),o.focus(),postboxes.updateOrderButtonsProperties(),postboxes.save_order(postboxes.page))},updateOrderButtonsProperties:function(){var e=l(".meta-box-sortables:visible:first").attr("id"),o=l(".meta-box-sortables:visible:last").attr("id"),s=l(".postbox:visible:first"),t=l(".postbox:visible:last"),a=s.attr("id"),r=t.attr("id"),i=s.closest(".meta-box-sortables").attr("id"),t=t.closest(".meta-box-sortables").attr("id"),n=l(".handle-order-higher"),d=l(".handle-order-lower");n.attr("aria-disabled","false").removeClass("hidden"),d.attr("aria-disabled","false").removeClass("hidden"),e===o&&a===r&&(n.addClass("hidden"),d.addClass("hidden")),e===i&&l(s).find(".handle-order-higher").attr("aria-disabled","true"),o===t&&l(".postbox:visible .handle-order-lower").last().attr("aria-disabled","true")},add_postbox_toggles:function(t,e){var o=l(".postbox .hndle, .postbox .handlediv"),s=l(".postbox .handle-order-higher, .postbox .handle-order-lower");this.page=t,this.init(t,e),o.on("click.postboxes",this.handle_click),s.on("click.postboxes",this.handleOrder),l(".postbox .hndle a").on("click",function(e){e.stopPropagation()}),l(".postbox a.dismiss").on("click.postboxes",function(e){var o=l(this).parents(".postbox").attr("id")+"-hide";e.preventDefault(),l("#"+o).prop("checked",!1).triggerHandler("click")}),l(".hide-postbox-tog").on("click.postboxes",function(){var e=l(this),o=e.val(),s=l("#"+o);e.prop("checked")?(s.show(),"function"==typeof postboxes.pbshow&&postboxes.pbshow(o)):(s.hide(),"function"==typeof postboxes.pbhide&&postboxes.pbhide(o)),postboxes.save_state(t),postboxes._mark_area(),a.trigger("postbox-toggled",s)}),l('.columns-prefs input[type="radio"]').on("click.postboxes",function(){var e=parseInt(l(this).val(),10);e&&(postboxes._pb_edit(e),postboxes.save_order(t))})},init:function(o,e){var s=l(document.body).hasClass("mobile"),t=l(".postbox .handlediv");l.extend(this,e||{}),l(".meta-box-sortables").sortable({placeholder:"sortable-placeholder",connectWith:".meta-box-sortables",items:".postbox",handle:".hndle",cursor:"move",delay:s?200:0,distance:2,tolerance:"pointer",forcePlaceholderSize:!0,helper:function(e,o){return o.clone().find(":input").attr("name",function(e,o){return"sort_"+parseInt(1e5*Math.random(),10).toString()+"_"+o}).end()},opacity:.65,start:function(){l("body").addClass("is-dragging-metaboxes"),l(".meta-box-sortables").sortable("refreshPositions")},stop:function(){var e=l(this);l("body").removeClass("is-dragging-metaboxes"),e.find("#dashboard_browser_nag").is(":visible")&&"dashboard_browser_nag"!=this.firstChild.id?e.sortable("cancel"):(postboxes.updateOrderButtonsProperties(),postboxes.save_order(o))},receive:function(e,o){"dashboard_browser_nag"==o.item[0].id&&l(o.sender).sortable("cancel"),postboxes._mark_area(),a.trigger("postbox-moved",o.item)}}),s&&(l(document.body).on("orientationchange.postboxes",function(){postboxes._pb_change()}),this._pb_change()),this._mark_area(),this.updateOrderButtonsProperties(),a.on("postbox-toggled",this.updateOrderButtonsProperties),t.each(function(){var e=l(this);e.attr("aria-expanded",!e.closest(".postbox").hasClass("closed"))})},save_state:function(e){var o,s;"nav-menus"!==e&&(o=l(".postbox").filter(".closed").map(function(){return thiLine truncated
|
||||
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* Interactions used by the User Privacy tools in WordPress.
|
||||
*
|
||||
* @output wp-admin/js/privacy-tools.js
|
||||
*/
|
||||
|
||||
// Privacy request action handling.
|
||||
jQuery( function( $ ) {
|
||||
var __ = wp.i18n.__,
|
||||
copiedNoticeTimeout;
|
||||
|
||||
function setActionState( $action, state ) {
|
||||
$action.children().addClass( 'hidden' );
|
||||
$action.children( '.' + state ).removeClass( 'hidden' );
|
||||
}
|
||||
|
||||
function clearResultsAfterRow( $requestRow ) {
|
||||
$requestRow.removeClass( 'has-request-results' );
|
||||
|
||||
if ( $requestRow.next().hasClass( 'request-results' ) ) {
|
||||
$requestRow.next().remove();
|
||||
}
|
||||
}
|
||||
|
||||
function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
|
||||
var itemList = '',
|
||||
resultRowClasses = 'request-results';
|
||||
|
||||
clearResultsAfterRow( $requestRow );
|
||||
|
||||
if ( additionalMessages.length ) {
|
||||
$.each( additionalMessages, function( index, value ) {
|
||||
itemList = itemList + '<li>' + value + '</li>';
|
||||
});
|
||||
itemList = '<ul>' + itemList + '</ul>';
|
||||
}
|
||||
|
||||
$requestRow.addClass( 'has-request-results' );
|
||||
|
||||
if ( $requestRow.hasClass( 'status-request-confirmed' ) ) {
|
||||
resultRowClasses = resultRowClasses + ' status-request-confirmed';
|
||||
}
|
||||
|
||||
if ( $requestRow.hasClass( 'status-request-failed' ) ) {
|
||||
resultRowClasses = resultRowClasses + ' status-request-failed';
|
||||
}
|
||||
|
||||
$requestRow.after( function() {
|
||||
return '<tr class="' + resultRowClasses + '"><th colspan="5">' +
|
||||
'<div class="notice inline notice-alt ' + classes + '" role="alert">' +
|
||||
'<p>' + summaryMessage + '</p>' +
|
||||
itemList +
|
||||
'</div>' +
|
||||
'</td>' +
|
||||
'</tr>';
|
||||
});
|
||||
}
|
||||
|
||||
$( '.export-personal-data-handle' ).on( 'click', function( event ) {
|
||||
var $this = $( this ),
|
||||
$action = $this.parents( '.export-personal-data' ),
|
||||
$requestRow = $this.parents( 'tr' ),
|
||||
$progress = $requestRow.find( '.export-progress' ),
|
||||
$rowActions = $this.parents( '.row-actions' ),
|
||||
requestID = $action.data( 'request-id' ),
|
||||
nonce = $action.data( 'nonce' ),
|
||||
exportersCount = $action.data( 'exporters-count' ),
|
||||
sendAsEmail = $action.data( 'send-as-email' ) ? true : false;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
$rowActions.addClass( 'processing' );
|
||||
|
||||
$action.trigger( 'blur' );
|
||||
clearResultsAfterRow( $requestRow );
|
||||
setExportProgress( 0 );
|
||||
|
||||
function onExportDoneSuccess( zipUrl ) {
|
||||
var summaryMessage = __( 'This user’s personal data export link was sent.' );
|
||||
|
||||
if ( 'undefined' !== typeof zipUrl ) {
|
||||
summaryMessage = __( 'This user’s personal data export file was downloaded.' );
|
||||
}
|
||||
|
||||
setActionState( $action, 'export-personal-data-success' );
|
||||
|
||||
appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
|
||||
|
||||
if ( 'undefined' !== typeof zipUrl ) {
|
||||
window.location = zipUrl;
|
||||
} else if ( ! sendAsEmail ) {
|
||||
onExportFailure( __( 'No personal data export file was generated.' ) );
|
||||
}
|
||||
|
||||
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
||||
}
|
||||
|
||||
function onExportFailure( errorMessage ) {
|
||||
var summaryMessage = __( 'An error occurred while attempting to export personal data.' );
|
||||
|
||||
setActionState( $action, 'export-personal-data-failed' );
|
||||
|
||||
if ( errorMessage ) {
|
||||
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [ errorMessage ] );
|
||||
}
|
||||
|
||||
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
||||
}
|
||||
|
||||
function setExportProgress( exporterIndex ) {
|
||||
var progress = ( exportersCount > 0 ? exporterIndex / exportersCount : 0 ),
|
||||
progressString = Math.round( progress * 100 ).toString() + '%';
|
||||
|
||||
$progress.html( progressString );
|
||||
}
|
||||
|
||||
function doNextExport( exporterIndex, pageIndex ) {
|
||||
$.ajax(
|
||||
{
|
||||
url: window.ajaxurl,
|
||||
data: {
|
||||
action: 'wp-privacy-export-personal-data',
|
||||
exporter: exporterIndex,
|
||||
id: requestID,
|
||||
page: pageIndex,
|
||||
security: nonce,
|
||||
sendAsEmail: sendAsEmail
|
||||
},
|
||||
method: 'post'
|
||||
}
|
||||
).done( function( response ) {
|
||||
var responseData = response.data;
|
||||
|
||||
if ( ! response.success ) {
|
||||
// e.g. invalid request ID.
|
||||
setTimeout( function() { onExportFailure( response.data ); }, 500 );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! responseData.done ) {
|
||||
setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) );
|
||||
} else {
|
||||
setExportProgress( exporterIndex );
|
||||
if ( exporterIndex < exportersCount ) {
|
||||
setTimeout( doNextExport( exporterIndex + 1, 1 ) );
|
||||
} else {
|
||||
setTimeout( function() { onExportDoneSuccess( responseData.url ); }, 500 );
|
||||
}
|
||||
}
|
||||
}).fail( function( jqxhr, textStatus, error ) {
|
||||
// e.g. Nonce failure.
|
||||
setTimeout( function() { onExportFailure( error ); }, 500 );
|
||||
});
|
||||
}
|
||||
|
||||
// And now, let's begin.
|
||||
setActionState( $action, 'export-personal-data-processing' );
|
||||
doNextExport( 1, 1 );
|
||||
});
|
||||
|
||||
$( '.remove-personal-data-handle' ).on( 'click', function( event ) {
|
||||
var $this = $( this ),
|
||||
$action = $this.parents( '.remove-personal-data' ),
|
||||
$requestRow = $this.parents( 'tr' ),
|
||||
$progress = $requestRow.find( '.erasure-progress' ),
|
||||
$rowActions = $this.parents( '.row-actions' ),
|
||||
requestID = $action.data( 'request-id' ),
|
||||
nonce = $action.data( 'nonce' ),
|
||||
erasersCount = $action.data( 'erasers-count' ),
|
||||
hasRemoved = false,
|
||||
hasRetained = false,
|
||||
messages = [];
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
$rowActions.addClass( 'processing' );
|
||||
|
||||
$action.trigger( 'blur' );
|
||||
clearResultsAfterRow( $requestRow );
|
||||
setErasureProgress( 0 );
|
||||
|
||||
function onErasureDoneSuccess() {
|
||||
var summaryMessage = __( 'No personal data was found for this user.' ),
|
||||
classes = 'notice-success';
|
||||
|
||||
setActionState( $action, 'remove-personal-data-success' );
|
||||
|
||||
if ( false === hasRemoved ) {
|
||||
if ( false === hasRetained ) {
|
||||
summaryMessage = __( 'No personal data was found for this user.' );
|
||||
} else {
|
||||
summaryMessage = __( 'Personal data was found for this user but was not erased.' );
|
||||
classes = 'notice-warning';
|
||||
}
|
||||
} else {
|
||||
if ( false === hasRetained ) {
|
||||
summaryMessage = __( 'All of the personal data found for this user was erased.' );
|
||||
} else {
|
||||
summaryMessage = __( 'Personal data was found for this user but some of the personal data found was not erased.' );
|
||||
classes = 'notice-warning';
|
||||
}
|
||||
}
|
||||
appendResultsAfterRow( $requestRow, classes, summaryMessage, messages );
|
||||
|
||||
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
||||
}
|
||||
|
||||
function onErasureFailure() {
|
||||
var summaryMessage = __( 'An error occurred while attempting to find and erase personal data.' );
|
||||
|
||||
setActionState( $action, 'remove-personal-data-failed' );
|
||||
|
||||
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [] );
|
||||
|
||||
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
||||
}
|
||||
|
||||
function setErasureProgress( eraserIndex ) {
|
||||
var progress = ( erasersCount > 0 ? eraserIndex / erasersCount : 0 ),
|
||||
progressString = Math.round( progress * 100 ).toString() + '%';
|
||||
|
||||
$progress.html( progressString );
|
||||
}
|
||||
|
||||
function doNextErasure( eraserIndex, pageIndex ) {
|
||||
$.ajax({
|
||||
url: window.ajaxurl,
|
||||
data: {
|
||||
action: 'wp-privacy-erase-personal-data',
|
||||
eraser: eraserIndex,
|
||||
id: requestID,
|
||||
page: pageIndex,
|
||||
security: nonce
|
||||
},
|
||||
method: 'post'
|
||||
}).done( function( response ) {
|
||||
var responseData = response.data;
|
||||
|
||||
if ( ! response.success ) {
|
||||
setTimeout( function() { onErasureFailure(); }, 500 );
|
||||
return;
|
||||
}
|
||||
if ( responseData.items_removed ) {
|
||||
hasRemoved = hasRemoved || responseData.items_removed;
|
||||
}
|
||||
if ( responseData.items_retained ) {
|
||||
hasRetained = hasRetained || responseData.items_retained;
|
||||
}
|
||||
if ( responseData.messages ) {
|
||||
messages = messages.concat( responseData.messages );
|
||||
}
|
||||
if ( ! responseData.done ) {
|
||||
setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) );
|
||||
} else {
|
||||
setErasureProgress( eraserIndex );
|
||||
if ( eraserIndex < erasersCount ) {
|
||||
setTimeout( doNextErasure( eraserIndex + 1, 1 ) );
|
||||
} else {
|
||||
setTimeout( function() { onErasureDoneSuccess(); }, 500 );
|
||||
}
|
||||
}
|
||||
}).fail( function() {
|
||||
setTimeout( function() { onErasureFailure(); }, 500 );
|
||||
});
|
||||
}
|
||||
|
||||
// And now, let's begin.
|
||||
setActionState( $action, 'remove-personal-data-processing' );
|
||||
|
||||
doNextErasure( 1, 1 );
|
||||
});
|
||||
|
||||
// Privacy Policy page, copy action.
|
||||
$( document ).on( 'click', function( event ) {
|
||||
var $parent,
|
||||
range,
|
||||
$target = $( event.target ),
|
||||
copiedNotice = $target.siblings( '.success' );
|
||||
|
||||
clearTimeout( copiedNoticeTimeout );
|
||||
|
||||
if ( $target.is( 'button.privacy-text-copy' ) ) {
|
||||
$parent = $target.closest( '.privacy-settings-accordion-panel' );
|
||||
|
||||
if ( $parent.length ) {
|
||||
try {
|
||||
var documentPosition = document.documentElement.scrollTop,
|
||||
bodyPosition = document.body.scrollTop;
|
||||
|
||||
// Setup copy.
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
// Hide tutorial content to remove from copied content.
|
||||
range = document.createRange();
|
||||
$parent.addClass( 'hide-privacy-policy-tutorial' );
|
||||
|
||||
// Copy action.
|
||||
range.selectNodeContents( $parent[0] );
|
||||
window.getSelection().addRange( range );
|
||||
document.execCommand( 'copy' );
|
||||
|
||||
// Reset section.
|
||||
$parent.removeClass( 'hide-privacy-policy-tutorial' );
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
// Return scroll position - see #49540.
|
||||
if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) {
|
||||
document.documentElement.scrollTop = documentPosition;
|
||||
} else if ( bodyPosition > 0 && bodyPosition !== document.body.scrollTop ) {
|
||||
document.body.scrollTop = bodyPosition;
|
||||
}
|
||||
|
||||
// Display and speak notice to indicate action complete.
|
||||
copiedNotice.addClass( 'visible' );
|
||||
wp.a11y.speak( __( 'The suggested policy text has been copied to your clipboard.' ) );
|
||||
|
||||
// Delay notice dismissal.
|
||||
copiedNoticeTimeout = setTimeout( function() {
|
||||
copiedNotice.removeClass( 'visible' );
|
||||
}, 3000 );
|
||||
} catch ( er ) {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Label handling to focus the create page button on Privacy settings page.
|
||||
$( 'body.options-privacy-php label[for=create-page]' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
$( 'input#create-page' ).trigger( 'focus' );
|
||||
} );
|
||||
|
||||
// Accordion handling in various new Privacy settings pages.
|
||||
$( '.privacy-settings-accordion' ).on( 'click', '.privacy-settings-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 );
|
||||
}
|
||||
} );
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! 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+"<li>"+t+"</li>"}),s="<ul>"+s+"</ul>"),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'<tr class="'+n+'"><th colspan="5"><div class="notice inline notice-alt '+t+'" role="alert"><p>'+a+"</p>"+s+"</div></td></tr>"})}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<l?e/l:0)).toString()+"%";a.html(e)}e.preventDefault(),e.stopPropagation(),i.addClass("processing"),n.trigger("blur"),x(r),m(0),w(n,"export-personal-data-processing"),function t(o,s){v.ajax({url:window.ajaxurl,data:{action:"wp-privacy-export-personal-data",exporter:o,id:c,page:s,security:d,sendAsEmail:u},method:"post"}).done(function(e){var a=e.data;e.success?a.done?(m(o),o<l?setTimeout(t(o+1,1)):setTimeout(function(){var e,t;e=a.url,t=h("This user’s personal data export link was sent."),void 0!==e&&(t=h("This user’s personal data export file was downloaded.")),w(n,"export-personal-data-success"),T(r,"notice-success",t,[]),void 0!==e?window.location=e:u||p(h("No personal data export file was generated.")),setTimeout(function(){i.removeClass("processing")},500)},500)):setTimeout(t(o,s+1)):setTimeout(function(){p(e.data)},500)}).fail(function(e,t,a){setTimeout(function(){p(a)},500)})}(1,1)}),v(".remove-personal-data-handle").on("click",function(e){var t=v(this),n=t.parents(".remove-personal-data"),r=t.parents("tr"),a=r.find(".erasure-progress"),i=t.parents(".row-actions"),c=n.data("request-id"),d=n.data("nonce"),l=n.data("erasers-count"),u=!1,p=!1,m=[];function f(){var e=h("An error occurred while attempting to find and erase personal data.");w(n,"remove-personal-data-failed"),T(r,"notice-error",e,[]),setTimeout(function(){i.removeClass("processing")},500)}function g(e){e=Math.round(100*(0<l?e/l:0)).toString()+"%";a.html(e)}e.preventDefault(),e.stopPropagation(),i.addClass("processing"),n.trigger("blur"),x(r),g(0),w(n,"remove-personal-data-processing"),function a(o,s){v.ajax({url:window.ajaxurl,data:{action:"wp-privacy-erase-personal-data",eraser:o,id:c,page:s,security:d},method:"post"}).done(function(e){var t=e.data;e.success?(t.items_removed&&(u=u||t.items_removed),t.items_retained&&(p=p||t.items_retained),t.messages&&(m=m.concat(t.messages)),t.done?(g(o),o<l?setTimeout(a(o+1,1)):setTimeout(function(){var e,t;e=h("No personal data was found for this user."),t="notice-success",w(n,"remove-personal-data-success"),!1===u?!1===p?e=h("No personal data was found for this user."):(e=h("Personal data was found for this user but was not erased."),t="notice-warning"):!1===p?e=h("All of the personal data found for this user was erased."):(e=h("Personal data was found for this user but some of the personal data found was not erased."),t="notice-warning"),T(r,t,e,m),setTimeout(function(){i.removeClass("processing")},500)},500)):setTimeout(a(o,s+1))):setTimeout(function(){f()},500)}).fail(function(){setTimeout(function(){f()},500)})}(1,1)}),v(document).on("click",function(e){var t,a,e=v(e.target),o=e.siblings(".success");if(clearTimeout(r),e.is("button.privacy-text-copy")&&(t=e.closest(".privacy-settings-accordion-panel")).length)try{var s=document.documentElement.scrollTop,n=document.body.scrollTop;window.getSelection().removeAllRanges(),a=document.createRange(),t.addClass("hide-privacy-policy-tutorial"),a.selectNodeContents(t[0]),window.getSelection().addRange(a),document.execCommand("copy"),t.removeClass("hide-privacy-policy-tutorial"),window.getSelection().removeAllRanges(),0<s&&s!==document.documentElement.scrollTop?document.documentElement.scrollTop=s:0<n&&n!==document.body.scrollTop&&(document.body.scrollTop=n),o.addClass("visible"),wp.a11y.speak(h("The suggested policy text has been copied to your clipboard.")),r=setTimeout(function(){o.removeClass("visible")},3e3)}catch(e){}}),v("body.options-privacy-php label[for=create-page]").on("click",function(e){e.preventDefault(),v("input#create-page").trigger("focus")}),v(".privacy-settings-accordion").on("click",".privacy-settings-accordion-trigger",function(){"true"===v(this).attr("aria-expanded")?(v(this).attr("aria-expanded","false"),v("#"+v(this).attr("aria-controls"Line truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},function(a){var s=wp.revisions={model:{},view:{},controller:{}};s.settings=window._wpRevisionsSettings||{},s.debug=!1,s.log=function(){window.console&&s.debug&&window.console.log.apply(window.console,arguments)},a.fn.allOffsets=function(){var e=this.offset()||{top:0,left:0},i=a(window);return _.extend(e,{right:i.width()-e.left-this.outerWidth(),bottom:i.height()-e.top-this.outerHeight()})},a.fn.allPositions=function(){var e=this.position()||{top:0,left:0},i=this.parent();return _.extend(e,{right:i.outerWidth()-e.left-this.outerWidth(),bottom:i.outerHeight()-e.top-this.outerHeight()})},s.model.Slider=Backbone.Model.extend({defaults:{value:null,values:null,min:0,max:1,step:1,range:!1,compareTwoMode:!1},initialize:function(e){this.frame=e.frame,this.revisions=e.revisions,this.listenTo(this.frame,"update:revisions",this.receiveRevisions),this.listenTo(this.frame,"change:compareTwoMode",this.updateMode),this.on("change:from",this.handleLocalChanges),this.on("change:to",this.handleLocalChanges),this.on("change:compareTwoMode",this.updateSliderSettings),this.on("update:revisions",this.updateSliderSettings),this.on("change:hoveredRevision",this.hoverRevision),this.set({max:this.revisions.length-1,compareTwoMode:this.frame.get("compareTwoMode"),from:this.frame.get("from"),to:this.frame.get("to")}),this.updateSliderSettings()},getSliderValue:function(e,i){return isRtl?this.revisions.length-this.revisions.indexOf(this.get(e))-1:this.revisions.indexOf(this.get(i))},updateSliderSettings:function(){this.get("compareTwoMode")?this.set({values:[this.getSliderValue("to","from"),this.getSliderValue("from","to")],value:null,range:!0}):this.set({value:this.getSliderValue("to","to"),values:null,range:!1}),this.trigger("update:slider")},hoverRevision:function(e,i){this.trigger("hovered:revision",i)},updateMode:function(e,i){this.set({compareTwoMode:i})},handleLocalChanges:function(){this.frame.set({from:this.get("from"),to:this.get("to")})},receiveRevisions:function(e,i){this.get("from")===e&&this.get("to")===i||(this.set({from:e,to:i},{silent:!0}),this.trigger("update:revisions",e,i))}}),s.model.Tooltip=Backbone.Model.extend({defaults:{revision:null,offset:{},hovering:!1,scrubbing:!1},initialize:function(e){this.frame=e.frame,this.revisions=e.revisions,this.slider=e.slider,this.listenTo(this.slider,"hovered:revision",this.updateRevision),this.listenTo(this.slider,"change:hovering",this.setHovering),this.listenTo(this.slider,"change:scrubbing",this.setScrubbing)},updateRevision:function(e){this.set({revision:e})},setHovering:function(e,i){this.set({hovering:i})},setScrubbing:function(e,i){this.set({scrubbing:i})}}),s.model.Revision=Backbone.Model.extend({}),s.model.Revisions=Backbone.Collection.extend({model:s.model.Revision,initialize:function(){_.bindAll(this,"next","prev")},next:function(e){e=this.indexOf(e);if(-1!==e&&e!==this.length-1)return this.at(e+1)},prev:function(e){e=this.indexOf(e);if(-1!==e&&0!==e)return this.at(e-1)}}),s.model.Field=Backbone.Model.extend({}),s.model.Fields=Backbone.Collection.extend({model:s.model.Field}),s.model.Diff=Backbone.Model.extend({initialize:function(){var e=this.get("fields");this.unset("fields"),this.fields=new s.model.Fields(e)}}),s.model.Diffs=Backbone.Collection.extend({initialize:function(e,i){_.bindAll(this,"getClosestUnloaded"),this.loadAll=_.once(this._loadAll),this.revisions=i.revisions,this.postId=i.postId,this.requests={}},model:s.model.Diff,ensure:function(e,i){var t=this.get(e),s=this.requests[e],o=a.Deferred(),n={},r=e.split(":")[0],l=e.split(":")[1];return n[e]=!0,wp.revisions.log("ensure",e),this.trigger("ensure",n,r,l,o.promise()),t?o.resolveWith(i,[t]):(this.trigger("ensure:load",n,r,l,o.promise()),_.each(n,_.bind(function(e){this.requests[e]&&delete n[e],this.get(e)&&delete n[e]},this)),s||(n[e]=!0,s=this.load(_.keys(n))),s.done(_.bind(function(){o.resolveWith(i,[this.get(e)])},this)).fail(_.bind(function(){o.reject()}))),o.promise()},getClosestUnloaded:function(e,i){var t=this;return _.chain([0].concat(e)).initial().zip(e).sortBy(function(e){return Math.abs(i-e[1])}).map(function(e){return e.join(":")}).filter(function(e){return _.isUndefined(t.get(e))&&!t.requests[e]}).value()},_loadAll:function(e,i,t){var s=this,o=a.Deferred(),n=_.first(this.getClosestUnloaded(e,i),t);return 0<_.size(n)?this.load(n).done(function(){s._loadAll(e,i,t).done(function(){o.resolve()})}).fail(function(){1===t?o.reject():s._loadAll(e,i,Math.ceil(t/2)).done(function(){o.resolve()})}):o.resolve(),o},load:function(e){return wp.revisions.log("load",e),this.fetch({data:{compare:e},remove:!1}).done(function(){wp.revisions.log("load:complete",e)})},sync:function(e,i,t){var s,o;return"read"===e?((t=t||{}).context=this,t.data=_.extend(t.data||{},{action:"get-revision-diffs",post_id:this.postId}),s=wp.ajax.send(t),o=this.requests,t.data.compare&&_.each(t.data.compare,function(e){o[e]=s}),s.always(function(){t.data.compare&&_.each(t.data.compare,function(e){delete o[e]})}),s)Line truncated
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.WPSetAsThumbnail=function(n,t){var a=jQuery("a#wp-post-thumbnail-"+n);a.text(wp.i18n.__("Saving\u2026")),jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:post_id,thumbnail_id:n,_ajax_nonce:t,cookie:encodeURIComponent(document.cookie)},function(t){var e=window.dialogArguments||opener||parent||top;a.text(wp.i18n.__("Use as featured image")),"0"==t?alert(wp.i18n.__("Could not set that as the thumbnail image. Try a different attachment.")):(jQuery("a.wp-post-thumbnail").show(),a.text(wp.i18n.__("Done")),a.fadeOut(2e3),e.WPSetThumbnailID(n),e.WPSetThumbnailHTML(t))})};
|
||||
@@ -0,0 +1,500 @@
|
||||
/**
|
||||
* 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 ( $( this ).prop( 'id' ) ) {
|
||||
window.location.hash = $( this ).prop( 'id' );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
} );
|
||||
|
||||
/* global setTimeout */
|
||||
wp.domReady( function() {
|
||||
// Get hash from query string and open the related accordion.
|
||||
var hash = window.location.hash;
|
||||
|
||||
if ( hash ) {
|
||||
var requestedPanel = $( hash );
|
||||
|
||||
if ( requestedPanel.is( '.health-check-accordion-trigger' ) ) {
|
||||
requestedPanel.trigger( 'click' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
// 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 ),
|
||||
'<span class="issue-count">' + count + '</span>'
|
||||
);
|
||||
} else if ( 'recommended' === issue.status ) {
|
||||
heading = sprintf(
|
||||
_n( '%s recommended improvement', '%s recommended improvements', count ),
|
||||
'<span class="issue-count">' + count + '</span>'
|
||||
);
|
||||
} else if ( 'good' === issue.status ) {
|
||||
heading = sprintf(
|
||||
_n( '%s item with no issues detected', '%s items with no issues detected', count ),
|
||||
'<span class="issue-count">' + count + '</span>'
|
||||
);
|
||||
}
|
||||
|
||||
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': '<p>' + url + '</p><p>' + description + '</p>',
|
||||
'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;
|
||||
}
|
||||
}
|
||||
} );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(o){var a,r=wp.i18n.__,n=wp.i18n._n,c=wp.i18n.sprintf,e=new ClipboardJS(".site-health-copy-buttons .copy-button"),l=o(".health-check-body.health-check-status-tab").length,t=o(".health-check-body.health-check-debug-tab").length,i=o("#health-check-accordion-block-wp-paths-sizes"),h=o("#adminmenu .site-health-counter"),d=o("#adminmenu .site-health-counter .count");function u(e){var t,s,a=wp.template("health-check-issue"),i=o("#health-check-issues-"+e.status);!function(e){var t,s,a,i,n={test:"string",label:"string",description:"string"},o=!0;if("object"==typeof e){for(t in n)if("object"==typeof(s=n[t]))for(a in s)i=s[a],void 0!==e[t]&&void 0!==e[t][a]&&i===typeof e[t][a]||(o=!1);else void 0!==e[t]&&s===typeof e[t]||(o=!1);return o}}(e)||(SiteHealth.site_status.issues[e.status]++,s=SiteHealth.site_status.issues[e.status],void 0===e.test&&(e.test=e.status+s),"critical"===e.status?t=c(n("%s critical issue","%s critical issues",s),'<span class="issue-count">'+s+"</span>"):"recommended"===e.status?t=c(n("%s recommended improvement","%s recommended improvements",s),'<span class="issue-count">'+s+"</span>"):"good"===e.status&&(t=c(n("%s item with no issues detected","%s items with no issues detected",s),'<span class="issue-count">'+s+"</span>")),t&&o(".site-health-issue-count-title",i).html(t),d.text(SiteHealth.site_status.issues.critical),0<parseInt(SiteHealth.site_status.issues.critical,0)?(o("#health-check-issues-critical").removeClass("hidden"),h.removeClass("count-0")):h.addClass("count-0"),0<parseInt(SiteHealth.site_status.issues.recommended,0)&&o("#health-check-issues-recommended").removeClass("hidden"),o(".issues","#health-check-issues-"+e.status).append(a(e)))}function p(){var e=o(".site-health-progress"),t=e.closest(".site-health-progress-wrapper"),s=o(".site-health-progress-label",t),a=o(".site-health-progress svg #bar"),i=parseInt(SiteHealth.site_status.issues.good,0)+parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),n=.5*parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),n=100-Math.ceil(n/i*100);0===i?e.addClass("hidden"):(t.removeClass("loading"),i=a.attr("r"),e=Math.PI*(2*i),a.css({strokeDashoffset:(100-(n=100<(n=n<0?0:n)?100:n))/100*e+"px"}),80<=n&&0===parseInt(SiteHealth.site_status.issues.critical,0)?(t.addClass("green").removeClass("orange"),s.text(r("Good")),m("good")):(t.addClass("orange").removeClass("green"),s.text(r("Should be improved")),m("improvable")),l&&(o.post(ajaxurl,{action:"health-check-site-status-result",_wpnonce:SiteHealth.nonce.site_status_result,counts:SiteHealth.site_status.issues}),100===n)&&(o(".site-status-all-clear").removeClass("hide"),o(".site-status-has-issues").addClass("hide")))}function g(e,t){e={status:"recommended",label:r("A test is unavailable"),badge:{color:"red",label:r("Unavailable")},description:"<p>"+e+"</p><p>"+t+"</p>",actions:""};u(wp.hooks.applyFilters("site_status_test_result",e))}function s(){var t=(new Date).getTime(),s=window.setTimeout(function(){m("waiting-for-directory-sizes")},3e3);wp.apiRequest({path:"/wp-site-health/v1/directory-sizes"}).done(function(e){var a,s;a=e||{},e=o("button.button.copy-button"),s=e.attr("data-clipboard-text"),o.each(a,function(e,t){t=t.debug||t.size;void 0!==t&&(s=s.replace(e+": loading...",e+": "+t))}),e.attr("data-clipboard-text",s),i.find("td[class]").each(function(e,t){var t=o(t),s=t.attr("class");a.hasOwnProperty(s)&&a[s].size&&t.text(a[s].size)})}).always(function(){var e=(new Date).getTime()-t;o(".health-check-wp-paths-sizes.spinner").css("visibility","hidden"),3e3<e?(e=6e3<e?0:6500-e,window.setTimeout(function(){p()},e)):window.clearTimeout(s),o(document).trigger("site-health-info-dirsizes-done")})}function m(e){if("site-health"===SiteHealth.screen)switch(e){case"good":wp.a11y.speak(r("All site health tests have finished running. Your site is looking good."));break;case"improvable":wp.a11y.speak(r("All site health tests have finished running. There are items that should be addressed."));break;case"waiting-for-directory-sizes":wp.a11y.speak(r("Running additional tests... please wait."))}}e.on("success",function(e){var t=o(e.trigger),s=o(".success",t.closest("div"));e.clearSelection(),clearTimeout(a),s.removeClass("hidden"),a=setTimeout(function(){s.addClass("hidden")},3e3),wp.a11y.speak(r("Site information has been copied to your clipboard."))}),o(".health-check-accordion").on("click",".health-check-accordion-trigger",function(){var e="true"===o(this).attr("aria-expanded");o(this).prop("id")&&(window.location.hash=o(this).prop("id")),e?(o(this).attr("aria-expanded","false"),o("#"+o(this).attr("aria-controls")).attr("hidden",!0)):(o(this).attr("aria-expanded","true"),o("#"+o(this).attr("aria-controls")).attr("hidden",!1))}),wp.domReady(function(){var e=window.location.hash;e&&(e=o(e)).is(".health-check-accordion-trigger")&&e.trigger("click")}),o(".site-health-view-passed").on("click",fuLine truncated
|
||||
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* 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 );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(t){var a,i=t("#choose-from-library-button"),s=t("#site-icon-preview"),r=t("#browser-icon-preview"),n=t("#app-icon-preview"),l=t("#site_icon_hidden_field"),o=t("#js-remove-site-icon");function c(t){var e=t.get("width"),t=t.get("height"),a=512,i=512,s=a/i,r=a,n=i;return s<e/t?a=(i=t)*s:i=(a=e)/s,{aspectRatio:a+":"+i,handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:e,imageHeight:t,minWidth:a<r?a:r,minHeight:i<n?i:n,x1:s=(e-a)/2,y1:r=(t-i)/2,x2:a+s,y2:i+r}}function d(t){var e,a=t.alt?(e=wp.i18n.sprintf(wp.i18n.__("App icon preview: Current image: %s"),t.alt),wp.i18n.sprintf(wp.i18n.__("Browser icon preview: Current image: %s"),t.alt)):(e=wp.i18n.sprintf(wp.i18n.__("App icon preview: The current image has no alternative text. The file name is: %s"),t.filename),wp.i18n.sprintf(wp.i18n.__("Browser icon preview: The current image has no alternative text. The file name is: %s"),t.filename));n.attr({src:t.url,alt:e}),r.attr({src:t.url,alt:a}),s.removeClass("hidden"),o.removeClass("hidden"),document.documentElement.style.setProperty("--site-icon-url","url("+t.url+")"),"1"!==i.attr("data-state")&&i.attr({class:i.attr("data-alt-classes"),"data-alt-classes":i.attr("class"),"data-state":"1"}),i.text(i.attr("data-update-text"))}i.on("click",function(){var e=t(this);(a=wp.media({button:{text:e.data("update"),close:!1},states:[new wp.media.controller.Library({title:e.data("choose-text"),library:wp.media.query({type:"image"}),date:!1,suggestedWidth:e.data("size"),suggestedHeight:e.data("size")}),new wp.media.controller.SiteIconCropper({control:{params:{width:e.data("size"),height:e.data("size")}},imgSelectOptions:c})]})).on("cropped",function(t){l.val(t.id),d(t),a.close(),a=null}),a.on("select",function(){var t=a.state().get("selection").first();t.attributes.height===e.data("size")&&e.data("size")===t.attributes.width?(d(t.attributes),a.close(),l.val(t.id)):a.setState("cropper")}),a.open()}),o.on("click",function(){l.val("false"),t(this).toggleClass("hidden"),s.toggleClass("hidden"),r.attr({src:"",alt:""}),n.attr({src:"",alt:""}),i.attr({class:i.attr("data-alt-classes"),"data-alt-classes":i.attr("class"),"data-state":""}).text(i.attr("data-choose-text")).trigger("focus")})}(jQuery);
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Attempt to re-color SVG icons used in the admin menu or the toolbar
|
||||
*
|
||||
* @output wp-admin/js/svg-painter.js
|
||||
*/
|
||||
|
||||
window.wp = window.wp || {};
|
||||
|
||||
wp.svgPainter = ( function( $, window, document, undefined ) {
|
||||
'use strict';
|
||||
var selector, painter,
|
||||
colorscheme = {},
|
||||
elements = [];
|
||||
|
||||
$( function() {
|
||||
wp.svgPainter.init();
|
||||
});
|
||||
|
||||
return {
|
||||
init: function() {
|
||||
painter = this;
|
||||
selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );
|
||||
|
||||
painter.setColors();
|
||||
painter.findElements();
|
||||
painter.paint();
|
||||
},
|
||||
|
||||
setColors: function( colors ) {
|
||||
if ( typeof colors === 'undefined' && typeof window._wpColorScheme !== 'undefined' ) {
|
||||
colors = window._wpColorScheme;
|
||||
}
|
||||
|
||||
if ( colors && colors.icons && colors.icons.base && colors.icons.current && colors.icons.focus ) {
|
||||
colorscheme = colors.icons;
|
||||
}
|
||||
},
|
||||
|
||||
findElements: function() {
|
||||
selector.each( function() {
|
||||
var $this = $(this), bgImage = $this.css( 'background-image' );
|
||||
|
||||
if ( bgImage && bgImage.indexOf( 'data:image/svg+xml;base64' ) != -1 ) {
|
||||
elements.push( $this );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
paint: function() {
|
||||
// Loop through all elements.
|
||||
$.each( elements, function( index, $element ) {
|
||||
var $menuitem = $element.parent().parent();
|
||||
|
||||
if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
|
||||
// Paint icon in 'current' color.
|
||||
painter.paintElement( $element, 'current' );
|
||||
} else {
|
||||
// Paint icon in base color.
|
||||
painter.paintElement( $element, 'base' );
|
||||
|
||||
// Set hover callbacks.
|
||||
$menuitem.on( 'mouseenter', function() {
|
||||
painter.paintElement( $element, 'focus' );
|
||||
} ).on( 'mouseleave', function() {
|
||||
// Match the delay from hoverIntent.
|
||||
window.setTimeout( function() {
|
||||
painter.paintElement( $element, 'base' );
|
||||
}, 100 );
|
||||
} );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
paintElement: function( $element, colorType ) {
|
||||
var xml, encoded, color;
|
||||
|
||||
if ( ! colorType || ! colorscheme.hasOwnProperty( colorType ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
color = colorscheme[ colorType ];
|
||||
|
||||
// Only accept hex colors: #101 or #101010.
|
||||
if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
xml = $element.data( 'wp-ui-svg-' + color );
|
||||
|
||||
if ( xml === 'none' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! xml ) {
|
||||
encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,([A-Za-z0-9\+\/\=]+)/ );
|
||||
|
||||
if ( ! encoded || ! encoded[1] ) {
|
||||
$element.data( 'wp-ui-svg-' + color, 'none' );
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
xml = window.atob( encoded[1] );
|
||||
} catch ( error ) {}
|
||||
|
||||
if ( xml ) {
|
||||
// Replace `fill` attributes.
|
||||
xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
|
||||
|
||||
// Replace `style` attributes.
|
||||
xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
|
||||
|
||||
// Replace `fill` properties in `<style>` tags.
|
||||
xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
|
||||
|
||||
xml = window.btoa( xml );
|
||||
|
||||
$element.data( 'wp-ui-svg-' + color, xml );
|
||||
} else {
|
||||
$element.data( 'wp-ui-svg-' + color, 'none' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
|
||||
}
|
||||
};
|
||||
|
||||
})( jQuery, window, document );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},wp.svgPainter=function(a,i){"use strict";var n,t,s={},o=[];return a(function(){wp.svgPainter.init()}),{init:function(){t=this,n=a("#adminmenu .wp-menu-image, #wpadminbar .ab-item"),t.setColors(),t.findElements(),t.paint()},setColors:function(n){(n=void 0===n&&void 0!==i._wpColorScheme?i._wpColorScheme:n)&&n.icons&&n.icons.base&&n.icons.current&&n.icons.focus&&(s=n.icons)},findElements:function(){n.each(function(){var n=a(this),e=n.css("background-image");e&&-1!=e.indexOf("data:image/svg+xml;base64")&&o.push(n)})},paint:function(){a.each(o,function(n,e){var a=e.parent().parent();a.hasClass("current")||a.hasClass("wp-has-current-submenu")?t.paintElement(e,"current"):(t.paintElement(e,"base"),a.on("mouseenter",function(){t.paintElement(e,"focus")}).on("mouseleave",function(){i.setTimeout(function(){t.paintElement(e,"base")},100)}))})},paintElement:function(n,e){var a,t;if(e&&s.hasOwnProperty(e)&&(e=s[e]).match(/^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i)&&"none"!==(a=n.data("wp-ui-svg-"+e))){if(!a){if(!(t=n.css("background-image").match(/.+data:image\/svg\+xml;base64,([A-Za-z0-9\+\/\=]+)/))||!t[1])return void n.data("wp-ui-svg-"+e,"none");try{a=i.atob(t[1])}catch(n){}if(!a)return void n.data("wp-ui-svg-"+e,"none");a=(a=(a=a.replace(/fill="(.+?)"/g,'fill="'+e+'"')).replace(/style="(.+?)"/g,'style="fill:'+e+'"')).replace(/fill:.*?;/g,"fill: "+e+";"),a=i.btoa(a),n.data("wp-ui-svg-"+e,a)}n.attr("style",'background-image: url("data:image/svg+xml;base64,'+a+'") !important;')}}}}(jQuery,window,document);
|
||||
@@ -0,0 +1,440 @@
|
||||
/**
|
||||
* @output wp-admin/js/tags-box.js
|
||||
*/
|
||||
|
||||
/* jshint curly: false, eqeqeq: false */
|
||||
/* global ajaxurl, tagBox, array_unique_noempty */
|
||||
|
||||
( function( $ ) {
|
||||
var tagDelimiter = wp.i18n._x( ',', 'tag delimiter' ) || ',';
|
||||
|
||||
/**
|
||||
* Filters unique items and returns a new array.
|
||||
*
|
||||
* Filters all items from an array into a new array containing only the unique
|
||||
* items. This also excludes whitespace or empty values.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @global
|
||||
*
|
||||
* @param {Array} array The array to filter through.
|
||||
*
|
||||
* @return {Array} A new array containing only the unique items.
|
||||
*/
|
||||
window.array_unique_noempty = function( array ) {
|
||||
var out = [];
|
||||
|
||||
// Trim the values and ensure they are unique.
|
||||
$.each( array, function( key, val ) {
|
||||
val = val || '';
|
||||
val = val.trim();
|
||||
|
||||
if ( val && $.inArray( val, out ) === -1 ) {
|
||||
out.push( val );
|
||||
}
|
||||
} );
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* The TagBox object.
|
||||
*
|
||||
* Contains functions to create and manage tags that can be associated with a
|
||||
* post.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @global
|
||||
*/
|
||||
window.tagBox = {
|
||||
/**
|
||||
* Cleans up tags by removing redundant characters.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @param {string} tags Comma separated tags that need to be cleaned up.
|
||||
*
|
||||
* @return {string} The cleaned up tags.
|
||||
*/
|
||||
clean : function( tags ) {
|
||||
if ( ',' !== tagDelimiter ) {
|
||||
tags = tags.replace( new RegExp( tagDelimiter, 'g' ), ',' );
|
||||
}
|
||||
|
||||
tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
|
||||
|
||||
if ( ',' !== tagDelimiter ) {
|
||||
tags = tags.replace( /,/g, tagDelimiter );
|
||||
}
|
||||
|
||||
return tags;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses tags and makes them editable.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @param {Object} el The tag element to retrieve the ID from.
|
||||
*
|
||||
* @return {boolean} Always returns false.
|
||||
*/
|
||||
parseTags : function(el) {
|
||||
var id = el.id,
|
||||
num = id.split('-check-num-')[1],
|
||||
taxbox = $(el).closest('.tagsdiv'),
|
||||
thetags = taxbox.find('.the-tags'),
|
||||
current_tags = thetags.val().split( tagDelimiter ),
|
||||
new_tags = [];
|
||||
|
||||
delete current_tags[num];
|
||||
|
||||
// Sanitize the current tags and push them as if they're new tags.
|
||||
$.each( current_tags, function( key, val ) {
|
||||
val = val || '';
|
||||
val = val.trim();
|
||||
if ( val ) {
|
||||
new_tags.push( val );
|
||||
}
|
||||
});
|
||||
|
||||
thetags.val( this.clean( new_tags.join( tagDelimiter ) ) );
|
||||
|
||||
this.quickClicks( taxbox );
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates clickable links, buttons and fields for adding or editing tags.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @param {Object} el The container HTML element.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
quickClicks : function( el ) {
|
||||
var thetags = $('.the-tags', el),
|
||||
tagchecklist = $('.tagchecklist', el),
|
||||
id = $(el).attr('id'),
|
||||
current_tags, disabled;
|
||||
|
||||
if ( ! thetags.length )
|
||||
return;
|
||||
|
||||
disabled = thetags.prop('disabled');
|
||||
|
||||
current_tags = thetags.val().split( tagDelimiter );
|
||||
tagchecklist.empty();
|
||||
|
||||
/**
|
||||
* Creates a delete button if tag editing is enabled, before adding it to the tag list.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @param {string} key The index of the current tag.
|
||||
* @param {string} val The value of the current tag.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$.each( current_tags, function( key, val ) {
|
||||
var listItem, xbutton;
|
||||
|
||||
val = val || '';
|
||||
val = val.trim();
|
||||
|
||||
if ( ! val )
|
||||
return;
|
||||
|
||||
// Create a new list item, and ensure the text is properly escaped.
|
||||
listItem = $( '<li />' ).text( val );
|
||||
|
||||
// If tags editing isn't disabled, create the X button.
|
||||
if ( ! disabled ) {
|
||||
/*
|
||||
* Build the X buttons, hide the X icon with aria-hidden and
|
||||
* use visually hidden text for screen readers.
|
||||
*/
|
||||
xbutton = $( '<button type="button" id="' + id + '-check-num-' + key + '" class="ntdelbutton">' +
|
||||
'<span class="remove-tag-icon" aria-hidden="true"></span>' +
|
||||
'<span class="screen-reader-text">' + wp.i18n.__( 'Remove term:' ) + ' ' + listItem.html() + '</span>' +
|
||||
'</button>' );
|
||||
|
||||
/**
|
||||
* Handles the click and keypress event of the tag remove button.
|
||||
*
|
||||
* Makes sure the focus ends up in the tag input field when using
|
||||
* the keyboard to delete the tag.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param {Event} e The click or keypress event to handle.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
xbutton.on( 'click keypress', function( e ) {
|
||||
// On click or when using the Enter/Spacebar keys.
|
||||
if ( 'click' === e.type || 13 === e.keyCode || 32 === e.keyCode ) {
|
||||
/*
|
||||
* When using the keyboard, move focus back to the
|
||||
* add new tag field. Note: when releasing the pressed
|
||||
* key this will fire the `keyup` event on the input.
|
||||
*/
|
||||
if ( 13 === e.keyCode || 32 === e.keyCode ) {
|
||||
$( this ).closest( '.tagsdiv' ).find( 'input.newtag' ).trigger( 'focus' );
|
||||
}
|
||||
|
||||
tagBox.userAction = 'remove';
|
||||
tagBox.parseTags( this );
|
||||
}
|
||||
});
|
||||
|
||||
listItem.prepend( ' ' ).prepend( xbutton );
|
||||
}
|
||||
|
||||
// Append the list item to the tag list.
|
||||
tagchecklist.append( listItem );
|
||||
});
|
||||
|
||||
// The buttons list is built now, give feedback to screen reader users.
|
||||
tagBox.screenReadersMessage();
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new tag.
|
||||
*
|
||||
* Also ensures that the quick links are properly generated.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @param {Object} el The container HTML element.
|
||||
* @param {Object|boolean} a When this is an HTML element the text of that
|
||||
* element will be used for the new tag.
|
||||
* @param {number|boolean} f If this value is not passed then the tag input
|
||||
* field is focused.
|
||||
*
|
||||
* @return {boolean} Always returns false.
|
||||
*/
|
||||
flushTags : function( el, a, f ) {
|
||||
var tagsval, newtags, text,
|
||||
tags = $( '.the-tags', el ),
|
||||
newtag = $( 'input.newtag', el );
|
||||
|
||||
a = a || false;
|
||||
|
||||
text = a ? $(a).text() : newtag.val();
|
||||
|
||||
/*
|
||||
* Return if there's no new tag or if the input field is empty.
|
||||
* Note: when using the keyboard to add tags, focus is moved back to
|
||||
* the input field and the `keyup` event attached on this field will
|
||||
* fire when releasing the pressed key. Checking also for the field
|
||||
* emptiness avoids to set the tags and call quickClicks() again.
|
||||
*/
|
||||
if ( 'undefined' == typeof( text ) || '' === text ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tagsval = tags.val();
|
||||
newtags = tagsval ? tagsval + tagDelimiter + text : text;
|
||||
|
||||
newtags = this.clean( newtags );
|
||||
newtags = array_unique_noempty( newtags.split( tagDelimiter ) ).join( tagDelimiter );
|
||||
tags.val( newtags );
|
||||
this.quickClicks( el );
|
||||
|
||||
if ( ! a )
|
||||
newtag.val('');
|
||||
if ( 'undefined' == typeof( f ) )
|
||||
newtag.trigger( 'focus' );
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves the available tags and creates a tagcloud.
|
||||
*
|
||||
* Retrieves the available tags from the database and creates an interactive
|
||||
* tagcloud. Clicking a tag will add it.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @param {string} id The ID to extract the taxonomy from.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
get : function( id ) {
|
||||
var tax = id.substr( id.indexOf('-') + 1 );
|
||||
|
||||
/**
|
||||
* Puts a received tag cloud into a DOM element.
|
||||
*
|
||||
* The tag cloud HTML is generated on the server.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param {number|string} r The response message from the Ajax call.
|
||||
* @param {string} stat The status of the Ajax request.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$.post( ajaxurl, { 'action': 'get-tagcloud', 'tax': tax }, function( r, stat ) {
|
||||
if ( 0 === r || 'success' != stat ) {
|
||||
return;
|
||||
}
|
||||
|
||||
r = $( '<div id="tagcloud-' + tax + '" class="the-tagcloud">' + r + '</div>' );
|
||||
|
||||
/**
|
||||
* Adds a new tag when a tag in the tagcloud is clicked.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @return {boolean} Returns false to prevent the default action.
|
||||
*/
|
||||
$( 'a', r ).on( 'click', function() {
|
||||
tagBox.userAction = 'add';
|
||||
tagBox.flushTags( $( '#' + tax ), this );
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '#' + id ).after( r );
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Track the user's last action.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*/
|
||||
userAction: '',
|
||||
|
||||
/**
|
||||
* Dispatches an audible message to screen readers.
|
||||
*
|
||||
* This will inform the user when a tag has been added or removed.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
screenReadersMessage: function() {
|
||||
var message;
|
||||
|
||||
switch ( this.userAction ) {
|
||||
case 'remove':
|
||||
message = wp.i18n.__( 'Term removed.' );
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
message = wp.i18n.__( 'Term added.' );
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
window.wp.a11y.speak( message, 'assertive' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes the tags box by setting up the links, buttons. Sets up event
|
||||
* handling.
|
||||
*
|
||||
* This includes handling of pressing the enter key in the input field and the
|
||||
* retrieval of tag suggestions.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @memberOf tagBox
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
init : function() {
|
||||
var ajaxtag = $('div.ajaxtag');
|
||||
|
||||
$('.tagsdiv').each( function() {
|
||||
tagBox.quickClicks( this );
|
||||
});
|
||||
|
||||
$( '.tagadd', ajaxtag ).on( 'click', function() {
|
||||
tagBox.userAction = 'add';
|
||||
tagBox.flushTags( $( this ).closest( '.tagsdiv' ) );
|
||||
});
|
||||
|
||||
/**
|
||||
* Handles pressing enter on the new tag input field.
|
||||
*
|
||||
* Prevents submitting the post edit form. Uses `keypress` to take
|
||||
* into account Input Method Editor (IME) converters.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param {Event} event The keypress event that occurred.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$( 'input.newtag', ajaxtag ).on( 'keypress', function( event ) {
|
||||
if ( 13 == event.which ) {
|
||||
tagBox.userAction = 'add';
|
||||
tagBox.flushTags( $( this ).closest( '.tagsdiv' ) );
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}).each( function( i, element ) {
|
||||
$( element ).wpTagsSuggest();
|
||||
});
|
||||
|
||||
/**
|
||||
* Before a post is saved the value currently in the new tag input field will be
|
||||
* added as a tag.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$('#post').on( 'submit', function(){
|
||||
$('div.tagsdiv').each( function() {
|
||||
tagBox.flushTags(this, false, 1);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Handles clicking on the tag cloud link.
|
||||
*
|
||||
* Makes sure the ARIA attributes are set correctly.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
$('.tagcloud-link').on( 'click', function(){
|
||||
// On the first click, fetch the tag cloud and insert it in the DOM.
|
||||
tagBox.get( $( this ).attr( 'id' ) );
|
||||
// Update button state, remove previous click event and attach a new one to toggle the cloud.
|
||||
$( this )
|
||||
.attr( 'aria-expanded', 'true' )
|
||||
.off()
|
||||
.on( 'click', function() {
|
||||
$( this )
|
||||
.attr( 'aria-expanded', 'false' === $( this ).attr( 'aria-expanded' ) ? 'true' : 'false' )
|
||||
.siblings( '.the-tagcloud' ).toggle();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}( jQuery ));
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(o){var r=wp.i18n._x(",","tag delimiter")||",";window.array_unique_noempty=function(t){var a=[];return o.each(t,function(t,e){(e=(e=e||"").trim())&&-1===o.inArray(e,a)&&a.push(e)}),a},window.tagBox={clean:function(t){return t=(t=","!==r?t.replace(new RegExp(r,"g"),","):t).replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,""),t=","!==r?t.replace(/,/g,r):t},parseTags:function(t){var e=t.id.split("-check-num-")[1],t=o(t).closest(".tagsdiv"),a=t.find(".the-tags"),i=a.val().split(r),n=[];return delete i[e],o.each(i,function(t,e){(e=(e=e||"").trim())&&n.push(e)}),a.val(this.clean(n.join(r))),this.quickClicks(t),!1},quickClicks:function(t){var a,e=o(".the-tags",t),i=o(".tagchecklist",t),n=o(t).attr("id");e.length&&(a=e.prop("disabled"),t=e.val().split(r),i.empty(),o.each(t,function(t,e){(e=(e=e||"").trim())&&(e=o("<li />").text(e),a||((t=o('<button type="button" id="'+n+"-check-num-"+t+'" class="ntdelbutton"><span class="remove-tag-icon" aria-hidden="true"></span><span class="screen-reader-text">'+wp.i18n.__("Remove term:")+" "+e.html()+"</span></button>")).on("click keypress",function(t){"click"!==t.type&&13!==t.keyCode&&32!==t.keyCode||(13!==t.keyCode&&32!==t.keyCode||o(this).closest(".tagsdiv").find("input.newtag").trigger("focus"),tagBox.userAction="remove",tagBox.parseTags(this))}),e.prepend(" ").prepend(t)),i.append(e))}),tagBox.screenReadersMessage())},flushTags:function(t,e,a){var i,n,s=o(".the-tags",t),c=o("input.newtag",t);return void 0!==(n=(e=e||!1)?o(e).text():c.val())&&""!==n&&(i=s.val(),i=this.clean(i=i?i+r+n:n),i=array_unique_noempty(i.split(r)).join(r),s.val(i),this.quickClicks(t),e||c.val(""),void 0===a)&&c.trigger("focus"),!1},get:function(a){var i=a.substr(a.indexOf("-")+1);o.post(ajaxurl,{action:"get-tagcloud",tax:i},function(t,e){0!==t&&"success"==e&&(t=o('<div id="tagcloud-'+i+'" class="the-tagcloud">'+t+"</div>"),o("a",t).on("click",function(){return tagBox.userAction="add",tagBox.flushTags(o("#"+i),this),!1}),o("#"+a).after(t))})},userAction:"",screenReadersMessage:function(){var t;switch(this.userAction){case"remove":t=wp.i18n.__("Term removed.");break;case"add":t=wp.i18n.__("Term added.");break;default:return}window.wp.a11y.speak(t,"assertive")},init:function(){var t=o("div.ajaxtag");o(".tagsdiv").each(function(){tagBox.quickClicks(this)}),o(".tagadd",t).on("click",function(){tagBox.userAction="add",tagBox.flushTags(o(this).closest(".tagsdiv"))}),o("input.newtag",t).on("keypress",function(t){13==t.which&&(tagBox.userAction="add",tagBox.flushTags(o(this).closest(".tagsdiv")),t.preventDefault(),t.stopPropagation())}).each(function(t,e){o(e).wpTagsSuggest()}),o("#post").on("submit",function(){o("div.tagsdiv").each(function(){tagBox.flushTags(this,!1,1)})}),o(".tagcloud-link").on("click",function(){tagBox.get(o(this).attr("id")),o(this).attr("aria-expanded","true").off().on("click",function(){o(this).attr("aria-expanded","false"===o(this).attr("aria-expanded")?"true":"false").siblings(".the-tagcloud").toggle()})})}}}(jQuery);
|
||||
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Default settings for jQuery UI Autocomplete for use with non-hierarchical taxonomies.
|
||||
*
|
||||
* @output wp-admin/js/tags-suggest.js
|
||||
*/
|
||||
( function( $ ) {
|
||||
var tempID = 0;
|
||||
var separator = wp.i18n._x( ',', 'tag delimiter' ) || ',';
|
||||
var __ = wp.i18n.__,
|
||||
_n = wp.i18n._n,
|
||||
sprintf = wp.i18n.sprintf;
|
||||
|
||||
function split( val ) {
|
||||
return val.split( new RegExp( separator + '\\s*' ) );
|
||||
}
|
||||
|
||||
function getLast( term ) {
|
||||
return split( term ).pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add UI Autocomplete to an input or textarea element with presets for use
|
||||
* with non-hierarchical taxonomies.
|
||||
*
|
||||
* Example: `$( element ).wpTagsSuggest( options )`.
|
||||
*
|
||||
* The taxonomy can be passed in a `data-wp-taxonomy` attribute on the element or
|
||||
* can be in `options.taxonomy`.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param {Object} options Options that are passed to UI Autocomplete. Can be used to override the default settings.
|
||||
* @return {Object} jQuery instance.
|
||||
*/
|
||||
$.fn.wpTagsSuggest = function( options ) {
|
||||
var cache;
|
||||
var last;
|
||||
var $element = $( this );
|
||||
|
||||
// Do not initialize if the element doesn't exist.
|
||||
if ( ! $element.length ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
var taxonomy = options.taxonomy || $element.attr( 'data-wp-taxonomy' ) || 'post_tag';
|
||||
|
||||
delete( options.taxonomy );
|
||||
|
||||
options = $.extend( {
|
||||
source: function( request, response ) {
|
||||
var term;
|
||||
|
||||
if ( last === request.term ) {
|
||||
response( cache );
|
||||
return;
|
||||
}
|
||||
|
||||
term = getLast( request.term );
|
||||
|
||||
$.get( window.ajaxurl, {
|
||||
action: 'ajax-tag-search',
|
||||
tax: taxonomy,
|
||||
q: term,
|
||||
number: 20
|
||||
} ).always( function() {
|
||||
$element.removeClass( 'ui-autocomplete-loading' ); // UI fails to remove this sometimes?
|
||||
} ).done( function( data ) {
|
||||
var tagName;
|
||||
var tags = [];
|
||||
|
||||
if ( data ) {
|
||||
data = data.split( '\n' );
|
||||
|
||||
for ( tagName in data ) {
|
||||
var id = ++tempID;
|
||||
|
||||
tags.push({
|
||||
id: id,
|
||||
name: data[tagName]
|
||||
});
|
||||
}
|
||||
|
||||
cache = tags;
|
||||
response( tags );
|
||||
} else {
|
||||
response( tags );
|
||||
}
|
||||
} );
|
||||
|
||||
last = request.term;
|
||||
},
|
||||
focus: function( event, ui ) {
|
||||
$element.attr( 'aria-activedescendant', 'wp-tags-autocomplete-' + ui.item.id );
|
||||
|
||||
// Don't empty the input field when using the arrow keys
|
||||
// to highlight items. See api.jqueryui.com/autocomplete/#event-focus
|
||||
event.preventDefault();
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
var tags = split( $element.val() );
|
||||
// Remove the last user input.
|
||||
tags.pop();
|
||||
// Append the new tag and an empty element to get one more separator at the end.
|
||||
tags.push( ui.item.name, '' );
|
||||
|
||||
$element.val( tags.join( separator + ' ' ) );
|
||||
|
||||
if ( $.ui.keyCode.TAB === event.keyCode ) {
|
||||
// Audible confirmation message when a tag has been selected.
|
||||
window.wp.a11y.speak( wp.i18n.__( 'Term selected.' ), 'assertive' );
|
||||
event.preventDefault();
|
||||
} else if ( $.ui.keyCode.ENTER === event.keyCode ) {
|
||||
// If we're in the edit post Tags meta box, add the tag.
|
||||
if ( window.tagBox ) {
|
||||
window.tagBox.userAction = 'add';
|
||||
window.tagBox.flushTags( $( this ).closest( '.tagsdiv' ) );
|
||||
}
|
||||
|
||||
// Do not close Quick Edit / Bulk Edit.
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
open: function() {
|
||||
$element.attr( 'aria-expanded', 'true' );
|
||||
},
|
||||
close: function() {
|
||||
$element.attr( 'aria-expanded', 'false' );
|
||||
},
|
||||
minLength: 2,
|
||||
position: {
|
||||
my: 'left top+2',
|
||||
at: 'left bottom',
|
||||
collision: 'none'
|
||||
},
|
||||
messages: {
|
||||
noResults: __( 'No results found.' ),
|
||||
results: function( number ) {
|
||||
return sprintf(
|
||||
/* translators: %d: Number of search results found. */
|
||||
_n(
|
||||
'%d result found. Use up and down arrow keys to navigate.',
|
||||
'%d results found. Use up and down arrow keys to navigate.',
|
||||
number
|
||||
),
|
||||
number
|
||||
);
|
||||
}
|
||||
}
|
||||
}, options );
|
||||
|
||||
$element.on( 'keydown', function() {
|
||||
$element.removeAttr( 'aria-activedescendant' );
|
||||
} );
|
||||
|
||||
$element.autocomplete( options );
|
||||
|
||||
// Ensure the autocomplete instance exists.
|
||||
if ( ! $element.autocomplete( 'instance' ) ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
$element.autocomplete( 'instance' )._renderItem = function( ul, item ) {
|
||||
return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
|
||||
.text( item.name )
|
||||
.appendTo( ul );
|
||||
};
|
||||
|
||||
$element.attr( {
|
||||
'role': 'combobox',
|
||||
'aria-autocomplete': 'list',
|
||||
'aria-expanded': 'false',
|
||||
'aria-owns': $element.autocomplete( 'widget' ).attr( 'id' )
|
||||
} )
|
||||
.on( 'focus', function() {
|
||||
var inputValue = split( $element.val() ).pop();
|
||||
|
||||
// Don't trigger a search if the field is empty.
|
||||
// Also, avoids screen readers announce `No search results`.
|
||||
if ( inputValue ) {
|
||||
$element.autocomplete( 'search' );
|
||||
}
|
||||
} );
|
||||
|
||||
// Returns a jQuery object containing the menu element.
|
||||
$element.autocomplete( 'widget' )
|
||||
.addClass( 'wp-tags-autocomplete' )
|
||||
.attr( 'role', 'listbox' )
|
||||
.removeAttr( 'tabindex' ) // Remove the `tabindex=0` attribute added by jQuery UI.
|
||||
|
||||
/*
|
||||
* Looks like Safari and VoiceOver need an `aria-selected` attribute. See ticket #33301.
|
||||
* The `menufocus` and `menublur` events are the same events used to add and remove
|
||||
* the `ui-state-focus` CSS class on the menu items. See jQuery UI Menu Widget.
|
||||
*/
|
||||
.on( 'menufocus', function( event, ui ) {
|
||||
ui.item.attr( 'aria-selected', 'true' );
|
||||
})
|
||||
.on( 'menublur', function() {
|
||||
// The `menublur` event returns an object where the item is `null`,
|
||||
// so we need to find the active item with other means.
|
||||
$( this ).find( '[aria-selected="true"]' ).removeAttr( 'aria-selected' );
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
}( jQuery ) );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(s){var u=0,n=wp.i18n._x(",","tag delimiter")||",",t=wp.i18n.__,d=wp.i18n._n,l=wp.i18n.sprintf;function p(e){return e.split(new RegExp(n+"\\s*"))}s.fn.wpTagsSuggest=function(e){var i,o,a,r=s(this);return r.length&&(a=(e=e||{}).taxonomy||r.attr("data-wp-taxonomy")||"post_tag",delete e.taxonomy,e=s.extend({source:function(e,n){var t;o===e.term?n(i):(t=p(e.term).pop(),s.get(window.ajaxurl,{action:"ajax-tag-search",tax:a,q:t,number:20}).always(function(){r.removeClass("ui-autocomplete-loading")}).done(function(e){var t,o=[];if(e){for(t in e=e.split("\n")){var a=++u;o.push({id:a,name:e[t]})}n(i=o)}else n(o)}),o=e.term)},focus:function(e,t){r.attr("aria-activedescendant","wp-tags-autocomplete-"+t.item.id),e.preventDefault()},select:function(e,t){var o=p(r.val());return o.pop(),o.push(t.item.name,""),r.val(o.join(n+" ")),s.ui.keyCode.TAB===e.keyCode?(window.wp.a11y.speak(wp.i18n.__("Term selected."),"assertive"),e.preventDefault()):s.ui.keyCode.ENTER===e.keyCode&&(window.tagBox&&(window.tagBox.userAction="add",window.tagBox.flushTags(s(this).closest(".tagsdiv"))),e.preventDefault(),e.stopPropagation()),!1},open:function(){r.attr("aria-expanded","true")},close:function(){r.attr("aria-expanded","false")},minLength:2,position:{my:"left top+2",at:"left bottom",collision:"none"},messages:{noResults:t("No results found."),results:function(e){return l(d("%d result found. Use up and down arrow keys to navigate.","%d results found. Use up and down arrow keys to navigate.",e),e)}}},e),r.on("keydown",function(){r.removeAttr("aria-activedescendant")}),r.autocomplete(e),r.autocomplete("instance"))&&(r.autocomplete("instance")._renderItem=function(e,t){return s('<li role="option" id="wp-tags-autocomplete-'+t.id+'">').text(t.name).appendTo(e)},r.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":r.autocomplete("widget").attr("id")}).on("focus",function(){p(r.val()).pop()&&r.autocomplete("search")}),r.autocomplete("widget").addClass("wp-tags-autocomplete").attr("role","listbox").removeAttr("tabindex").on("menufocus",function(e,t){t.item.attr("aria-selected","true")}).on("menublur",function(){s(this).find('[aria-selected="true"]').removeAttr("aria-selected")})),this}}(jQuery);
|
||||
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
* 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');
|
||||
|
||||
tr.children().css('backgroundColor', '#faafaa');
|
||||
|
||||
// Disable pointer events and all form controls/links in the row
|
||||
tr.css('pointer-events', 'none');
|
||||
tr.find(':input, a').prop('disabled', true).attr('tabindex', -1);
|
||||
|
||||
/**
|
||||
* 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){
|
||||
var message;
|
||||
if ( '1' == r ) {
|
||||
$('#ajax-response').empty();
|
||||
let nextFocus = tr.next( 'tr' ).find( 'a.row-title' );
|
||||
let prevFocus = tr.prev( 'tr' ).find( 'a.row-title' );
|
||||
// If there is neither a next row or a previous row, focus the tag input field.
|
||||
if ( nextFocus.length < 1 && prevFocus.length < 1 ) {
|
||||
nextFocus = $( '#tag-name' ).trigger( 'focus' );
|
||||
} else {
|
||||
if ( nextFocus.length < 1 ) {
|
||||
nextFocus = prevFocus;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
nextFocus.trigger( 'focus' );
|
||||
message = wp.i18n.__( 'The selected tag has been deleted.' );
|
||||
|
||||
} else if ( '-1' == r ) {
|
||||
message = wp.i18n.__( 'Sorry, you are not allowed to do that.' );
|
||||
$('#ajax-response').empty().append('<div class="notice notice-error"><p>' + message + '</p></div>');
|
||||
resetRowAfterFailure( tr );
|
||||
|
||||
} else {
|
||||
message = wp.i18n.__( 'An error occurred while processing your request. Please try again later.' );
|
||||
$('#ajax-response').empty().append('<div class="notice notice-error"><p>' + message + '</p></div>');
|
||||
resetRowAfterFailure( tr );
|
||||
}
|
||||
wp.a11y.speak( message, 'assertive' );
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* Restores the original UI state of a table row after an AJAX failure.
|
||||
*
|
||||
* @param {jQuery} tr The table row to reset.
|
||||
* @return {void}
|
||||
*/
|
||||
function resetRowAfterFailure( tr ) {
|
||||
tr.children().css( 'backgroundColor', '' );
|
||||
tr.css( 'pointer-events', '' );
|
||||
tr.find( ':input, a' ).prop( 'disabled', false ).removeAttr( 'tabindex' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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( '<option value="' + term.term_id + '">' + indent + term.name + '</option>' );
|
||||
}
|
||||
|
||||
$('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible', form).val('');
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(s){var o=!1;function a(e){e.children().css("backgroundColor",""),e.css("pointer-events",""),e.find(":input, a").prop("disabled",!1).removeAttr("tabindex")}s("#the-list").on("click",".delete-tag",function(){var n,e=s(this),r=e.parents("tr"),t=!0;return(t="undefined"!=showNotice?showNotice.warn():t)&&(n=e.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag"),r.children().css("backgroundColor","#faafaa"),r.css("pointer-events","none"),r.find(":input, a").prop("disabled",!0).attr("tabindex",-1),s.post(ajaxurl,n,function(e){if("1"==e){s("#ajax-response").empty();let e=r.next("tr").find("a.row-title");var t=r.prev("tr").find("a.row-title");e.length<1&&t.length<1?e=s("#tag-name").trigger("focus"):e.length<1&&(e=t),r.fadeOut("normal",function(){r.remove()}),s('select#parent option[value="'+n.match(/tag_ID=(\d+)/)[1]+'"]').remove(),s("a.tag-link-"+n.match(/tag_ID=(\d+)/)[1]).remove(),e.trigger("focus"),t=wp.i18n.__("The selected tag has been deleted.")}else t="-1"==e?wp.i18n.__("Sorry, you are not allowed to do that."):wp.i18n.__("An error occurred while processing your request. Please try again later."),s("#ajax-response").empty().append('<div class="notice notice-error"><p>'+t+"</p></div>"),a(r);wp.a11y.speak(t,"assertive")})),!1}),s("#edittag").on("click",".delete",function(e){if("undefined"==typeof showNotice)return!0;showNotice.warn()||e.preventDefault()}),s("#submit").on("click",function(){var a=s(this).parents("form");return o||(o=!0,a.find(".submit .spinner").addClass("is-active"),s.post(ajaxurl,s("#addtag").serialize(),function(e){var t,n,r;if(o=!1,a.find(".submit .spinner").removeClass("is-active"),s("#ajax-response").empty(),(t=wpAjax.parseAjaxResponse(e,"ajax-response")).errors&&"empty_term_name"===t.responses[0].errors[0].code&&validateForm(a),t&&!t.errors){if(0<(e=a.find("select#parent").val())&&0<s("#tag-"+e).length?s(".tags #tag-"+e).after(t.responses[0].supplemental.noparents):s(".tags").prepend(t.responses[0].supplemental.parents),s(".tags .no-items").remove(),a.find("select#parent")){for(e=t.responses[1].supplemental,n="",r=0;r<t.responses[1].position;r++)n+=" ";a.find("select#parent option:selected").after('<option value="'+e.term_id+'">'+n+e.name+"</option>")}s('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible',a).val("")}})),!1})});
|
||||
File diff suppressed because it is too large.
Load diff
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp||(window.wp={}),wp.themePluginEditor=function(o){"use strict";var t,i=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&&o.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=o(".file-editor-warning"),n.docsLookUpButton=n.form.find("#docs-lookup"),n.docsLookUpList=n.form.find("#docs-list"),0<n.warning.length&&n.showWarning(),!1!==n.codeEditor&&_.defer(function(){n.initCodeEditor()}),o(n.initFileBrowser),o(window).on("beforeunload",function(){if(n.dirty)return i("The changes you made will be lost if you navigate away from this page.")}),n.docsLookUpList.on("change",function(){""===o(this).val()?n.docsLookUpButton.prop("disabled",!0):n.docsLookUpButton.prop("disabled",!1)}),o(window).on("keydown",function(e){!e.ctrlKey&&!e.metaKey||"s"!==e.key.toLowerCase()||n.instance&&n.instance.codemirror.hasFocus()||(e.preventDefault(),n.form.trigger("submit"))})},showWarning:function(){var e=n.warning.find(".file-editor-warning-message").text();o("#wpwrap").attr("aria-hidden","true"),o(document.body).addClass("modal-open").append(n.warning.detach()),n.warning.removeClass("hidden").find(".file-editor-warning-go-back").trigger("focus"),n.warningTabbables=n.warning.find("a, button"),n.warningTabbables.on("keydown",n.constrainTabbing),n.warning.on("click",".file-editor-warning-dismiss",n.dismissWarning),setTimeout(function(){wp.a11y.speak(wp.sanitize.stripTags(e.replace(/\s+/g," ")),"assertive")},1e3)},constrainTabbing:function(e){var t,i;9===e.which&&(t=n.warningTabbables.first()[0],(i=n.warningTabbables.last()[0])!==e.target||e.shiftKey?t===e.target&&e.shiftKey&&(i.focus(),e.preventDefault()):(t.focus(),e.preventDefault()))},dismissWarning:function(){wp.ajax.post("dismiss-wp-pointer",{pointer:n.themeOrPlugin+"_editor_notice"}),n.warning.remove(),o("#wpwrap").removeAttr("aria-hidden"),o("body").removeClass("modal-open")},onChange:function(){n.dirty=!0,n.removeNotice("file_saved")},submit:function(e){var t={};e.preventDefault(),o.each(n.form.serializeArray(),function(){t[this.name]=this.value}),n.instance&&(t.newcontent=n.instance.codemirror.getValue()),n.isSaving||(n.instance&&n.instance.updateErrorNotice&&n.instance.updateErrorNotice(),n.lintErrors.length?n.instance.codemirror.setCursor(n.lintErrors[0].from.line):(n.isSaving=!0,n.textarea.prop("readonly",!0),n.instance&&n.instance.codemirror.setOption("readOnly",!0),n.spinner.addClass("is-active"),e=wp.ajax.post("edit-theme-plugin-file",t),n.lastSaveNoticeCode&&n.removeNotice(n.lastSaveNoticeCode),e.done(function(e){n.lastSaveNoticeCode="file_saved",n.addNotice({code:n.lastSaveNoticeCode,type:"success",message:e.message,dismissible:!0}),n.dirty=!1}),e.fail(function(e){e=o.extend({code:"save_error",message:i("An error occurred while saving your changes. Please try again. If the problem persists, you may need to manually update the file via FTP.")},e,{type:"error",dismissible:!0});n.lastSaveNoticeCode=e.code,n.addNotice(e)}),e.always(function(){n.spinner.removeClass("is-active"),n.isSaving=!1,n.textarea.prop("readonly",!1),n.instance&&n.instance.codemirror.setOption("readOnly",!1)})))},addNotice:function(e){var t;if(e.code)return n.removeNotice(e.code),(t=o(n.noticeTemplate(e))).hide(),t.find(".notice-dismiss").on("click",function(){n.removeNotice(e.code),e.onDismiss&&e.onDismiss(e)}),wp.a11y.speak(e.message),n.noticesContainer.append(t),t.slideDown("fast"),n.noticeElements[e.code]=t;throw new Error("Missing code.")},removeNotice:function(e){return!!n.noticeElements[e]&&(n.noticeElements[e].slideUp("fast",function(){o(this).remove()}),delete n.noticeElements[e],!0)},initCodeEditor:function(){var t,e;function i(){n.form.trigger("submit")}(t=o.extend({},n.codeEditor)).onTabPrevious=function(){o("#templateside").find(":tabbable").last().trigger("focus")},t.onTabNext=function(){o("#template").find(":tabbable:not(.CodeMirror-code)").first().trigger("focus")},t.onChangeLintingErrors=function(e){0===(n.lintErrors=e).length&&n.submitButton.toggleClass("disabled",!1)},t.onUpdateErrorNotice=function(e){n.submitButton.toggleClass("disabled",0<e.length),0!==e.length?n.addNotice({code:"lint_errors",type:"error",message:r(s("There is %s error which must be fixed before you can update this file.","There are %s errors which must be fixed before you can update this file.",e.length),String(e.length)),dismissible:!1}).find("input[type=checkbox]").on("click",function(){t.onChangeLintingErrors([]),n.removeNotice("lint_errors")}):n.removeNotice("lint_errors")},(e=wp.codeEditor.initialize(o("#newcontent"),t)).codemirror.on("change",n.onChange),e.codemirror.setOption("extraKeys",{...e.codemirror.getOption("extraKeys")||{},"Ctrl-S":iLine truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
window.wp=window.wp||{},function(n){var o,a;function e(e,t){Backbone.history._hasPushState&&Backbone.Router.prototype.navigate.call(this,e,t)}(o=wp.themes=wp.themes||{}).data=_wpThemeSettings,a=o.data.l10n,o.isInstall=!!o.data.settings.isInstall,_.extend(o,{model:{},view:{},routes:{},router:{},template:wp.template}),o.Model=Backbone.Model.extend({initialize:function(){var e;this.get("slug")&&(-1!==_.indexOf(o.data.installedThemes,this.get("slug"))&&this.set({installed:!0}),o.data.activeTheme===this.get("slug"))&&this.set({active:!0}),this.set({id:this.get("slug")||this.get("id")}),this.has("sections")&&(e=this.get("sections").description,this.set({description:e}))}}),o.view.Appearance=wp.Backbone.View.extend({el:"#wpbody-content .wrap .theme-browser",window:n(window),page:0,initialize:function(e){_.bindAll(this,"scroller"),this.SearchView=e.SearchView||o.view.Search,this.window.on("scroll",_.throttle(this.scroller,300))},render:function(){this.view=new o.view.Themes({collection:this.collection,parent:this}),this.search(),this.$el.removeClass("search-loading"),this.view.render(),this.$el.empty().append(this.view.el).addClass("rendered")},searchContainer:n(".search-form"),search:function(){var e;1!==o.data.themes.length&&(e=new this.SearchView({collection:this.collection,parent:this}),(this.SearchView=e).render(),this.searchContainer.find(".search-box").append(n.parseHTML('<label for="wp-filter-search-input">'+a.search+"</label>")).append(e.el),this.searchContainer.on("submit",function(e){e.preventDefault()}))},scroller:function(){var e=this,t=this.window.scrollTop()+e.window.height(),e=e.$el.offset().top+e.$el.outerHeight(!1)-e.window.height();Math.round(.9*e)<t&&this.trigger("theme:scroll")}}),o.Collection=Backbone.Collection.extend({model:o.Model,terms:"",doSearch:function(e){this.terms!==e&&(this.terms=e,0<this.terms.length&&this.search(this.terms),""===this.terms&&(this.reset(o.data.themes),n("body").removeClass("no-results")),this.trigger("themes:update"))},search:function(t){var i,e,s,r,a;this.reset(o.data.themes,{silent:!0}),t=(t=(t=t.trim()).replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")).replace(/ /g,")(?=.*"),i=new RegExp("^(?=.*"+t+").+","i"),0===(e=this.filter(function(e){return s=e.get("name").replace(/(<([^>]+)>)/gi,""),r=e.get("description").replace(/(<([^>]+)>)/gi,""),a=e.get("author").replace(/(<([^>]+)>)/gi,""),s=_.union([s,e.get("id"),r,a,e.get("tags")]),i.test(e.get("author"))&&2<t.length&&e.set("displayAuthor",!0),i.test(s)})).length?this.trigger("query:empty"):n("body").removeClass("no-results"),this.reset(e)},paginate:function(e){var t=this;return e=e||0,t=_(t.rest(20*e)),t=_(t.first(20))},count:!1,query:function(t){var e,i,s,r=this.queries,a=this;if(this.currentQuery.request=t,e=_.find(r,function(e){return _.isEqual(e.request,t)}),(i=_.has(t,"page"))||(this.currentQuery.page=1),e||i){if(i)return this.apiCall(t,i).done(function(e){a.add(e.themes),a.trigger("query:success"),a.loadingThemes=!1}).fail(function(){a.trigger("query:fail")});0===e.themes.length?a.trigger("query:empty"):n("body").removeClass("no-results"),_.isNumber(e.total)&&(this.count=e.total),this.reset(e.themes),e.total||(this.count=this.length),this.trigger("themes:update"),this.trigger("query:success",this.count)}else this.apiCall(t).done(function(e){e.themes&&(a.reset(e.themes),s=e.info.results,r.push({themes:e.themes,request:t,total:s})),a.trigger("themes:update"),a.trigger("query:success",s),e.themes&&0===e.themes.length&&a.trigger("query:empty")}).fail(function(){a.trigger("query:fail")})},queries:[],currentQuery:{page:1,request:{}},apiCall:function(e,t){return wp.ajax.send("query-themes",{data:{request:_.extend({per_page:100},e)},beforeSend:function(){t||n("body").addClass("loading-content").removeClass("no-results")}})},loadingThemes:!1}),o.view.Theme=wp.Backbone.View.extend({className:"theme",state:"grid",html:o.template("theme"),events:{click:o.isInstall?"preview":"expand",keydown:o.isInstall?"preview":"expand",touchend:o.isInstall?"preview":"expand",keyup:"addFocus",touchmove:"preventExpand","click .theme-install":"installTheme","click .update-message":"updateTheme"},touchDrag:!1,initialize:function(){this.model.on("change",this.render,this)},render:function(){var e=this.model.toJSON();this.$el.html(this.html(e)).attr("data-slug",e.id),this.activeTheme(),this.model.get("displayAuthor")&&this.$el.addClass("display-author")},activeTheme:function(){this.model.get("active")&&this.$el.addClass("active")},addFocus:function(){var e=n(":focus").hasClass("theme")?n(":focus"):n(":focus").parents(".theme");n(".theme.focus").removeClass("focus"),e.addClass("focus")},expand:function(e){if("keydown"!==(e=e||window.event).type||13===e.which||32===e.which)return!0===this.touchDrag?this.touchDrag=!1:void(n(e.target).is(".theme-actions a")||n(e.target).is(".theme-actions a, .update-message, .button-link, .notice-dismiss")||(o.focusedTheme=this.$el,this.trigger("theme:expand",this.model.cid)))},preventExpand:function(){this.touchDrag=Line truncated
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(c,g,m){var f=c(document),h=g.i18n.__,r=g.i18n._x,p=g.i18n._n,o=g.i18n._nx,v=g.i18n.sprintf;(g=g||{}).updates={},g.updates.l10n={searchResults:"",searchResultsLabel:"",noPlugins:"",noItemsSelected:"",updating:"",pluginUpdated:"",themeUpdated:"",update:"",updateNow:"",pluginUpdateNowLabel:"",updateFailedShort:"",updateFailed:"",pluginUpdatingLabel:"",pluginUpdatedLabel:"",pluginUpdateFailedLabel:"",updatingMsg:"",updatedMsg:"",updateCancel:"",beforeunload:"",installNow:"",pluginInstallNowLabel:"",installing:"",pluginInstalled:"",themeInstalled:"",installFailedShort:"",installFailed:"",pluginInstallingLabel:"",themeInstallingLabel:"",pluginInstalledLabel:"",themeInstalledLabel:"",pluginInstallFailedLabel:"",themeInstallFailedLabel:"",installingMsg:"",installedMsg:"",importerInstalledMsg:"",aysDelete:"",aysDeleteUninstall:"",aysBulkDelete:"",aysBulkDeleteThemes:"",deleting:"",deleteFailed:"",pluginDeleted:"",themeDeleted:"",livePreview:"",activatePlugin:"",activateTheme:"",activatePluginLabel:"",activateThemeLabel:"",activateImporter:"",activateImporterLabel:"",unknownError:"",connectionError:"",nonceError:"",pluginsFound:"",noPluginsFound:"",autoUpdatesEnable:"",autoUpdatesEnabling:"",autoUpdatesEnabled:"",autoUpdatesDisable:"",autoUpdatesDisabling:"",autoUpdatesDisabled:"",autoUpdatesError:""},g.updates.l10n=window.wp.deprecateL10nObject("wp.updates.l10n",g.updates.l10n,"5.5.0"),g.updates.ajaxNonce=m.ajax_nonce,g.updates.searchTerm="",g.updates.searchMinCharacters=2,g.updates.shouldRequestFilesystemCredentials=!1,g.updates.filesystemCredentials={ftp:{host:"",username:"",password:"",connectionType:""},ssh:{publicKey:"",privateKey:""},fsNonce:"",available:!1},g.updates.ajaxLocked=!1,g.updates.adminNotice=g.template("wp-updates-admin-notice"),g.updates.queue=[],g.updates.$elToReturnFocusToFromCredentialsModal=void 0,g.updates.addAdminNotice=function(e){var t,a=c(e.selector),s=c(".wp-header-end");delete e.selector,t=g.updates.adminNotice(e),(a=a.length?a:c("#"+e.id)).length?a.replaceWith(t):s.length?s.after(t):"customize"===pagenow?c(".customize-themes-notifications").append(t):c(".wrap").find("> h1").after(t),f.trigger("wp-updates-notice-added")},g.updates.ajax=function(e,t){var a={};return g.updates.ajaxLocked?(g.updates.queue.push({action:e,data:t}),c.Deferred()):(g.updates.ajaxLocked=!0,t.success&&(a.success=t.success,delete t.success),t.error&&(a.error=t.error,delete t.error),a.data=_.extend(t,{action:e,_ajax_nonce:g.updates.ajaxNonce,_fs_nonce:g.updates.filesystemCredentials.fsNonce,username:g.updates.filesystemCredentials.ftp.username,password:g.updates.filesystemCredentials.ftp.password,hostname:g.updates.filesystemCredentials.ftp.hostname,connection_type:g.updates.filesystemCredentials.ftp.connectionType,public_key:g.updates.filesystemCredentials.ssh.publicKey,private_key:g.updates.filesystemCredentials.ssh.privateKey}),g.ajax.send(a).always(g.updates.ajaxAlways))},g.updates.ajaxAlways=function(e){e.errorCode&&"unable_to_connect_to_filesystem"===e.errorCode||(g.updates.ajaxLocked=!1,g.updates.queueChecker()),void 0!==e.debug&&window.console&&window.console.log&&_.map(e.debug,function(e){window.console.log(g.sanitize.stripTagsAndEncodeText(e))})},g.updates.refreshCount=function(){var e,t=c("#wp-admin-bar-updates"),a=c('a[href="update-core.php"] .update-plugins'),s=c('a[href="plugins.php"] .update-plugins'),n=c('a[href="themes.php"] .update-plugins');t.find(".ab-label").text(m.totals.counts.total),t.find(".updates-available-text").text(v(p("%s update available","%s updates available",m.totals.counts.total),m.totals.counts.total)),0===m.totals.counts.total&&t.find(".ab-label").parents("li").remove(),a.each(function(e,t){t.className=t.className.replace(/count-\d+/,"count-"+m.totals.counts.total)}),0<m.totals.counts.total?a.find(".update-count").text(m.totals.counts.total):a.remove(),s.each(function(e,t){t.className=t.className.replace(/count-\d+/,"count-"+m.totals.counts.plugins)}),0<m.totals.counts.total?s.find(".plugin-count").text(m.totals.counts.plugins):s.remove(),n.each(function(e,t){t.className=t.className.replace(/count-\d+/,"count-"+m.totals.counts.themes)}),0<m.totals.counts.total?n.find(".theme-count").text(m.totals.counts.themes):n.remove(),"plugins"===pagenow||"plugins-network"===pagenow?e=m.totals.counts.plugins:"themes"!==pagenow&&"themes-network"!==pagenow||(e=m.totals.counts.themes),0<e?c(".subsubsub .upgrade .count").text("("+e+")"):(c(".subsubsub .upgrade").remove(),c(".subsubsub li:last").html(function(){return c(this).children()}))},g.updates.setCardButtonStatus=function(e){var t=window.parent===window?null:window.parent;c.support.postMessage=!!window.postMessage,!1!==c.support.postMessage&&null!==t&&-1===window.parent.location.pathname.indexOf("index.php")&&t.postMessage(JSON.stringify(e),window.location.origin)},g.updates.decrementCount=function(e){m.totals.counts.total=Math.max(--m.totals.counts.total,0),"plugin"===e?m.totals.counts.plugins=Math.max(--m.totals.counts.pluginLine truncated
|
||||
@@ -0,0 +1,625 @@
|
||||
/**
|
||||
* @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,
|
||||
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false,
|
||||
ua = navigator.userAgent.toLowerCase(),
|
||||
isSafari = window.safari !== 'undefined' && typeof window.safari === 'object',
|
||||
isFirefox = ua.indexOf( 'firefox' ) !== -1;
|
||||
|
||||
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 not the install screen.
|
||||
if ( 'mailserver_pass' !== $pass1.prop('id' ) && ! $('#weblog_title').length ) {
|
||||
$( $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();
|
||||
} );
|
||||
|
||||
bindCapsLockWarning( $pass1 );
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
// Toggle between showing and hiding the password.
|
||||
$toggleButton.show().on( 'click', function () {
|
||||
if ( 'password' === $pass1.attr( 'type' ) ) {
|
||||
$pass1.attr( 'type', 'text' );
|
||||
resetToggle( false );
|
||||
} else {
|
||||
$pass1.attr( 'type', 'password' );
|
||||
resetToggle( true );
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure the password input type is set to password when the form is submitted.
|
||||
$pass1Row.closest( 'form' ).on( 'submit', function() {
|
||||
if ( $pass1.attr( 'type' ) === 'text' ) {
|
||||
$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 = $( '<div />', {
|
||||
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( '<p />');
|
||||
|
||||
// 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' );
|
||||
|
||||
bindCapsLockWarning( $pass1 );
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind Caps Lock detection to a password input field.
|
||||
*
|
||||
* @param {jQuery} $input The password input field.
|
||||
*/
|
||||
function bindCapsLockWarning( $input ) {
|
||||
var $capsWarning,
|
||||
$capsIcon,
|
||||
$capsText,
|
||||
capsLockOn = false;
|
||||
|
||||
// Skip warning on macOS Safari + Firefox (they show native indicators).
|
||||
if ( isMac && ( isSafari || isFirefox ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$capsWarning = $( '<div id="caps-warning" class="caps-warning"></div>' );
|
||||
$capsIcon = $( '<span class="caps-icon" aria-hidden="true"><svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg" fill="#3c434a" stroke="#3c434a" stroke-width="0.5"><path d="M12 5L19 15H16V19H8V15H5L12 5Z"/><rect x="8" y="21" width="8" height="1.5" rx="0.75"/></svg></span>' );
|
||||
$capsText = $( '<span>', { 'class': 'caps-warning-text', text: __( 'Caps lock is on.' ) } );
|
||||
$capsWarning.append( $capsIcon, $capsText );
|
||||
|
||||
$input.parent( 'div' ).append( $capsWarning );
|
||||
|
||||
$input.on( 'keydown', function( jqEvent ) {
|
||||
var event = jqEvent.originalEvent;
|
||||
|
||||
// Skip if key is not a printable character.
|
||||
// Key length > 1 usually means non-printable (e.g., "Enter", "Tab").
|
||||
if ( event.ctrlKey || event.metaKey || event.altKey || ! event.key || event.key.length !== 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var state = isCapsLockOn( event );
|
||||
|
||||
// React when the state changes or if caps lock is on when the user starts typing.
|
||||
if ( state !== capsLockOn ) {
|
||||
capsLockOn = state;
|
||||
|
||||
if ( capsLockOn ) {
|
||||
$capsWarning.show();
|
||||
// Don't duplicate existing screen reader Caps lock notifications.
|
||||
if ( event.key !== 'CapsLock' ) {
|
||||
wp.a11y.speak( __( 'Caps lock is on.' ), 'assertive' );
|
||||
}
|
||||
} else {
|
||||
$capsWarning.hide();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
$input.on( 'blur', function() {
|
||||
if ( ! document.hasFocus() ) {
|
||||
return;
|
||||
}
|
||||
capsLockOn = false;
|
||||
$capsWarning.hide();
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if Caps Lock is currently enabled.
|
||||
*
|
||||
* On macOS Safari and Firefox, the native warning is preferred,
|
||||
* so this function returns false to suppress custom warnings.
|
||||
*
|
||||
* @param {KeyboardEvent} e The keydown event object.
|
||||
*
|
||||
* @return {boolean} True if Caps Lock is on, false otherwise.
|
||||
*/
|
||||
function isCapsLockOn( event ) {
|
||||
return event.getModifierState( 'CapsLock' );
|
||||
}
|
||||
|
||||
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);
|
||||
$('<option />', {
|
||||
'text': val
|
||||
}).appendTo( select );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Replaces "Howdy, *" in the admin toolbar whenever the display name dropdown is updated for one's own profile.
|
||||
*/
|
||||
select.on( 'change', function() {
|
||||
if ( user_id !== current_user_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var display_name = this.value.trim() || current_name;
|
||||
|
||||
greeting.text( display_name );
|
||||
} );
|
||||
}
|
||||
|
||||
$colorpicker = $( '#color-picker' );
|
||||
$stylesheet = $( '#colors-css' );
|
||||
user_id = $( 'input#user_id' ).val();
|
||||
current_user_id = $( 'input[name="checkuser_id"]' ).val();
|
||||
|
||||
$colorpicker.on( 'click.colorpicker', '.color-option', function() {
|
||||
var colors,
|
||||
$this = $(this);
|
||||
|
||||
if ( $this.hasClass( 'selected' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this.siblings( '.selected' ).removeClass( 'selected' );
|
||||
$this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true );
|
||||
|
||||
// Set color scheme.
|
||||
if ( user_id === current_user_id ) {
|
||||
// Load the colors stylesheet.
|
||||
// The default color scheme won't have one, so we'll need to create an element.
|
||||
if ( 0 === $stylesheet.length ) {
|
||||
$stylesheet = $( '<link rel="stylesheet" />' ).appendTo( 'head' );
|
||||
}
|
||||
$stylesheet.attr( 'href', $this.children( '.css_url' ).val() );
|
||||
|
||||
// Repaint icons.
|
||||
if ( typeof wp !== 'undefined' && wp.svgPainter ) {
|
||||
try {
|
||||
colors = JSON.parse( $this.children( '.icon_colors' ).val() );
|
||||
} catch ( error ) {}
|
||||
|
||||
if ( colors ) {
|
||||
wp.svgPainter.setColors( colors );
|
||||
wp.svgPainter.paint();
|
||||
}
|
||||
}
|
||||
|
||||
// Update user option.
|
||||
$.post( ajaxurl, {
|
||||
action: 'save-user-color-scheme',
|
||||
color_scheme: $this.children( 'input[name="admin_color"]' ).val(),
|
||||
nonce: $('#color-nonce').val()
|
||||
}).done( function( response ) {
|
||||
if ( response.success ) {
|
||||
$( 'body' ).removeClass( response.data.previousScheme ).addClass( response.data.currentScheme );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
bindPasswordForm();
|
||||
bindPasswordResetLink();
|
||||
$submitButtons.on( 'click', function() {
|
||||
isSubmitting = true;
|
||||
});
|
||||
|
||||
$form = $( '#your-profile, #createuser' );
|
||||
originalFormContent = $form.serialize();
|
||||
});
|
||||
|
||||
$( '#destroy-sessions' ).on( 'click', function( e ) {
|
||||
var $this = $(this);
|
||||
|
||||
wp.ajax.post( 'destroy-sessions', {
|
||||
nonce: $( '#_wpnonce' ).val(),
|
||||
user_id: $( '#user_id' ).val()
|
||||
}).done( function( response ) {
|
||||
$this.prop( 'disabled', true );
|
||||
$this.siblings( '.notice' ).remove();
|
||||
$this.before( '<div class="notice notice-success inline" role="alert"><p>' + response.message + '</p></div>' );
|
||||
}).fail( function( response ) {
|
||||
$this.siblings( '.notice' ).remove();
|
||||
$this.before( '<div class="notice notice-error inline" role="alert"><p>' + response.message + '</p></div>' );
|
||||
});
|
||||
|
||||
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);
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(r){var s,a,t,n,i,o,p,l,d,c,u,h,w,f=!1,v=!1,m=wp.i18n.__,e=new ClipboardJS(".application-password-display .copy-button"),g=!!window.navigator.platform&&-1!==window.navigator.platform.indexOf("Mac"),b=navigator.userAgent.toLowerCase(),y="undefined"!==window.safari&&"object"==typeof window.safari,k=-1!==b.indexOf("firefox");function _(){"function"!=typeof zxcvbn?setTimeout(_,50):(!a.val()||h.hasClass("is-open")?(a.val(a.data("pw")),a.trigger("pwupdate")):T(),H(),x(),1!==parseInt(o.data("start-masked"),10)?a.attr("type","text"):o.trigger("click"),r("#pw-weak-text-label").text(m("Confirm use of weak password")),"mailserver_pass"===a.prop("id")||r("#weblog_title").length||r(a).trigger("focus"))}function C(e){o.attr({"aria-label":m(e?"Show password":"Hide password")}).find(".text").text(m(e?"Show":"Hide")).end().find(".dashicons").removeClass(e?"dashicons-hidden":"dashicons-visibility").addClass(e?"dashicons-visibility":"dashicons-hidden")}function x(){o||((o=s.find(".wp-hide-pw")).show().on("click",function(){"password"===a.attr("type")?(a.attr("type","text"),C(!1)):(a.attr("type","password"),C(!0))}),s.closest("form").on("submit",function(){"text"===a.attr("type")&&(a.attr("type","password"),C(!0))}))}function L(e,s,a){var t=r("<div />",{role:"alert"});t.addClass("notice inline"),t.addClass("notice-"+(s?"success":"error")),t.text(r(r.parseHTML(a)).text()).wrapInner("<p />"),e.prop("disabled",s),e.siblings(".notice").remove(),e.before(t)}function S(){var e;s=r(".user-pass1-wrap, .user-pass-wrap, .mailserver-pass-wrap, .reset-pass-submit"),r(".user-pass2-wrap").hide(),l=r("#submit, #wp-submit").on("click",function(){f=!1}),p=l.add(" #createusersub"),n=r(".pw-weak"),(i=n.find(".pw-checkbox")).on("change",function(){p.prop("disabled",!i.prop("checked"))}),(a=r("#pass1, #mailserver_pass")).length?(d=a.val(),1===parseInt(a.data("reveal"),10)&&_(),a.on("input pwupdate",function(){a.val()!==d&&(d=a.val(),a.removeClass("short bad good strong"),H())}),j(a)):j(a=r("#user_pass")),t=r("#pass2").on("input",function(){0<t.val().length&&(a.val(t.val()),t.val(""),d="",a.trigger("pwupdate"))}),a.is(":hidden")&&(a.prop("disabled",!0),t.prop("disabled",!0)),h=s.find(".wp-pwd"),e=s.find("button.wp-generate-pw"),x(),e.show(),e.on("click",function(){f=!0,e.not(".skip-aria-expanded").attr("aria-expanded","true"),h.show().addClass("is-open"),a.attr("disabled",!1),t.attr("disabled",!1),_(),C(!1),wp.ajax.post("generate-password").done(function(e){a.data("pw",e)})}),s.find("button.wp-cancel-pw").on("click",function(){f=!1,a.prop("disabled",!0),t.prop("disabled",!0),a.val("").trigger("pwupdate"),C(!1),h.hide().removeClass("is-open"),p.prop("disabled",!1),e.attr("aria-expanded","false")}),s.closest("form").on("submit",function(){f=!1,a.prop("disabled",!1),t.prop("disabled",!1),t.val(a.val())})}function T(){var e=r("#pass1").val();if(r("#pass-strength-result").removeClass("short bad good strong empty"),e&&""!==e.trim())switch(wp.passwordStrength.meter(e,wp.passwordStrength.userInputDisallowedList(),e)){case-1:r("#pass-strength-result").addClass("bad").html(pwsL10n.unknown);break;case 2:r("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:r("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:r("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;case 5:r("#pass-strength-result").addClass("short").html(pwsL10n.mismatch);break;default:r("#pass-strength-result").addClass("short").html(pwsL10n.short)}else r("#pass-strength-result").addClass("empty").html(" ")}function j(e){var a,s,t,n=!1;g&&(y||k)||(a=r('<div id="caps-warning" class="caps-warning"></div>'),s=r('<span class="caps-icon" aria-hidden="true"><svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg" fill="#3c434a" stroke="#3c434a" stroke-width="0.5"><path d="M12 5L19 15H16V19H8V15H5L12 5Z"/><rect x="8" y="21" width="8" height="1.5" rx="0.75"/></svg></span>'),t=r("<span>",{class:"caps-warning-text",text:m("Caps lock is on.")}),a.append(s,t),e.parent("div").append(a),e.on("keydown",function(e){var s,e=e.originalEvent;e.ctrlKey||e.metaKey||e.altKey||!e.key||1!==e.key.length||(s=e.getModifierState("CapsLock"))!==n&&((n=s)?(a.show(),"CapsLock"!==e.key&&wp.a11y.speak(m("Caps lock is on."),"assertive")):a.hide())}),e.on("blur",function(){document.hasFocus()&&(n=!1,a.hide())}))}function H(){var e=r("#pass-strength-result");e.length&&(e=e[0]).className&&(a.addClass(e.className),r(e).is(".short, .bad")?(i.prop("checked")||p.prop("disabled",!0),n.show()):(r(e).is(".empty")?(p.prop("disabled",!0),i.prop("checked",!1)):p.prop("disabled",!1),n.hide()))}e.on("success",function(e){var s=r(e.trigger),a=r(".success",s.closest(".application-password-display"));e.clearSelection(),clearTimeout(w),a.removeClass("hidden"),w=setTimeout(function(){a.addClass("hidden")},3e3),wp.a11y.speak(m("Application password has been copied to your clipboard."))}),r(function(){var e,a,t,n,i=r("#display_name"),s=i.val(),o=r("#wp-admin-bar-my-accounLine truncated
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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 );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(a){var n="undefined"!=typeof current_site_id?"&site_id="+current_site_id:"";a(function(){var i={offset:"0, -1"};"undefined"!=typeof isRtl&&isRtl&&(i.my="right top",i.at="right bottom"),a(".wp-suggest-user").each(function(){var e=a(this),t=void 0!==e.data("autocompleteType")?e.data("autocompleteType"):"add",o=void 0!==e.data("autocompleteField")?e.data("autocompleteField"):"user_login";e.autocomplete({source:ajaxurl+"?action=autocomplete-user&autocomplete_type="+t+"&autocomplete_field="+o+n,delay:500,minLength:2,position:i,open:function(){a(this).addClass("open")},close:function(){a(this).removeClass("open")}})})})}(jQuery);
|
||||
@@ -0,0 +1,763 @@
|
||||
/**
|
||||
* @output wp-admin/js/widgets.js
|
||||
*/
|
||||
|
||||
/* global ajaxurl, isRtl, wpWidgets */
|
||||
|
||||
(function($) {
|
||||
var $document = $( document );
|
||||
|
||||
window.wpWidgets = {
|
||||
/**
|
||||
* A closed Sidebar that gets a Widget dragged over it.
|
||||
*
|
||||
* @var {element|null}
|
||||
*/
|
||||
hoveredSidebar: null,
|
||||
|
||||
/**
|
||||
* Lookup of which widgets have had change events triggered.
|
||||
*
|
||||
* @var {object}
|
||||
*/
|
||||
dirtyWidgets: {},
|
||||
|
||||
init : function() {
|
||||
var rem, the_id,
|
||||
self = this,
|
||||
chooser = $('.widgets-chooser'),
|
||||
selectSidebar = chooser.find('.widgets-chooser-sidebars'),
|
||||
sidebars = $('div.widgets-sortables'),
|
||||
isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
|
||||
|
||||
// Handle the widgets containers in the right column.
|
||||
$( '#widgets-right .sidebar-name' )
|
||||
/*
|
||||
* Toggle the widgets containers when clicked and update the toggle
|
||||
* button `aria-expanded` attribute value.
|
||||
*/
|
||||
.on( 'click', function() {
|
||||
var $this = $( this ),
|
||||
$wrap = $this.closest( '.widgets-holder-wrap '),
|
||||
$toggle = $this.find( '.handlediv' );
|
||||
|
||||
if ( $wrap.hasClass( 'closed' ) ) {
|
||||
$wrap.removeClass( 'closed' );
|
||||
$toggle.attr( 'aria-expanded', 'true' );
|
||||
// Refresh the jQuery UI sortable items.
|
||||
$this.parent().sortable( 'refresh' );
|
||||
} else {
|
||||
$wrap.addClass( 'closed' );
|
||||
$toggle.attr( 'aria-expanded', 'false' );
|
||||
}
|
||||
|
||||
// Update the admin menu "sticky" state.
|
||||
$document.triggerHandler( 'wp-pin-menu' );
|
||||
})
|
||||
/*
|
||||
* Set the initial `aria-expanded` attribute value on the widgets
|
||||
* containers toggle button. The first one is expanded by default.
|
||||
*/
|
||||
.find( '.handlediv' ).each( function( index ) {
|
||||
if ( 0 === index ) {
|
||||
// jQuery equivalent of `continue` within an `each()` loop.
|
||||
return;
|
||||
}
|
||||
|
||||
$( this ).attr( 'aria-expanded', 'false' );
|
||||
});
|
||||
|
||||
// Show AYS dialog when there are unsaved widget changes.
|
||||
$( window ).on( 'beforeunload.widgets', function( event ) {
|
||||
var dirtyWidgetIds = [], unsavedWidgetsElements;
|
||||
$.each( self.dirtyWidgets, function( widgetId, dirty ) {
|
||||
if ( dirty ) {
|
||||
dirtyWidgetIds.push( widgetId );
|
||||
}
|
||||
});
|
||||
if ( 0 !== dirtyWidgetIds.length ) {
|
||||
unsavedWidgetsElements = $( '#widgets-right' ).find( '.widget' ).filter( function() {
|
||||
return -1 !== dirtyWidgetIds.indexOf( $( this ).prop( 'id' ).replace( /^widget-\d+_/, '' ) );
|
||||
});
|
||||
unsavedWidgetsElements.each( function() {
|
||||
if ( ! $( this ).hasClass( 'open' ) ) {
|
||||
$( this ).find( '.widget-title-action:first' ).trigger( 'click' );
|
||||
}
|
||||
});
|
||||
|
||||
// Bring the first unsaved widget into view and focus on the first tabbable field.
|
||||
unsavedWidgetsElements.first().each( function() {
|
||||
if ( this.scrollIntoViewIfNeeded ) {
|
||||
this.scrollIntoViewIfNeeded();
|
||||
} else {
|
||||
this.scrollIntoView();
|
||||
}
|
||||
$( this ).find( '.widget-inside :tabbable:first' ).trigger( 'focus' );
|
||||
} );
|
||||
|
||||
event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
|
||||
return event.returnValue;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle the widgets containers in the left column.
|
||||
$( '#widgets-left .sidebar-name' ).on( 'click', function() {
|
||||
var $wrap = $( this ).closest( '.widgets-holder-wrap' );
|
||||
|
||||
$wrap
|
||||
.toggleClass( 'closed' )
|
||||
.find( '.handlediv' ).attr( 'aria-expanded', ! $wrap.hasClass( 'closed' ) );
|
||||
|
||||
// Update the admin menu "sticky" state.
|
||||
$document.triggerHandler( 'wp-pin-menu' );
|
||||
});
|
||||
|
||||
$(document.body).on('click.widgets-toggle', function(e) {
|
||||
var target = $(e.target), css = {},
|
||||
widget, inside, targetWidth, widgetWidth, margin, saveButton, widgetId,
|
||||
toggleBtn = target.closest( '.widget' ).find( '.widget-top button.widget-action' );
|
||||
|
||||
if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
|
||||
widget = target.closest('div.widget');
|
||||
inside = widget.children('.widget-inside');
|
||||
targetWidth = parseInt( widget.find('input.widget-width').val(), 10 );
|
||||
widgetWidth = widget.parent().width();
|
||||
widgetId = inside.find( '.widget-id' ).val();
|
||||
|
||||
// Save button is initially disabled, but is enabled when a field is changed.
|
||||
if ( ! widget.data( 'dirty-state-initialized' ) ) {
|
||||
saveButton = inside.find( '.widget-control-save' );
|
||||
saveButton.prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
|
||||
inside.on( 'input change', function() {
|
||||
self.dirtyWidgets[ widgetId ] = true;
|
||||
widget.addClass( 'widget-dirty' );
|
||||
saveButton.prop( 'disabled', false ).val( wp.i18n.__( 'Save' ) );
|
||||
});
|
||||
widget.data( 'dirty-state-initialized', true );
|
||||
}
|
||||
|
||||
if ( inside.is(':hidden') ) {
|
||||
if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) {
|
||||
if ( widget.closest('div.widget-liquid-right').length ) {
|
||||
margin = isRTL ? 'margin-right' : 'margin-left';
|
||||
} else {
|
||||
margin = isRTL ? 'margin-left' : 'margin-right';
|
||||
}
|
||||
|
||||
css[ margin ] = widgetWidth - ( targetWidth + 30 ) + 'px';
|
||||
widget.css( css );
|
||||
}
|
||||
/*
|
||||
* Don't change the order of attributes changes and animation:
|
||||
* it's important for screen readers, see ticket #31476.
|
||||
*/
|
||||
toggleBtn.attr( 'aria-expanded', 'true' );
|
||||
inside.slideDown( 'fast', function() {
|
||||
widget.addClass( 'open' );
|
||||
});
|
||||
} else {
|
||||
/*
|
||||
* Don't change the order of attributes changes and animation:
|
||||
* it's important for screen readers, see ticket #31476.
|
||||
*/
|
||||
toggleBtn.attr( 'aria-expanded', 'false' );
|
||||
inside.slideUp( 'fast', function() {
|
||||
widget.attr( 'style', '' );
|
||||
widget.removeClass( 'open' );
|
||||
});
|
||||
}
|
||||
} else if ( target.hasClass('widget-control-save') ) {
|
||||
wpWidgets.save( target.closest('div.widget'), 0, 1, 0 );
|
||||
e.preventDefault();
|
||||
} else if ( target.hasClass('widget-control-remove') ) {
|
||||
wpWidgets.save( target.closest('div.widget'), 1, 1, 0 );
|
||||
} else if ( target.hasClass('widget-control-close') ) {
|
||||
widget = target.closest('div.widget');
|
||||
widget.removeClass( 'open' );
|
||||
toggleBtn.attr( 'aria-expanded', 'false' );
|
||||
wpWidgets.close( widget );
|
||||
} else if ( target.attr( 'id' ) === 'inactive-widgets-control-remove' ) {
|
||||
wpWidgets.removeInactiveWidgets();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
sidebars.children('.widget').each( function() {
|
||||
var $this = $(this);
|
||||
|
||||
wpWidgets.appendTitle( this );
|
||||
|
||||
if ( $this.find( 'p.widget-error' ).length ) {
|
||||
$this.find( '.widget-action' ).trigger( 'click' ).attr( 'aria-expanded', 'true' );
|
||||
}
|
||||
});
|
||||
|
||||
$('#widget-list').children('.widget').draggable({
|
||||
connectToSortable: 'div.widgets-sortables',
|
||||
handle: '> .widget-top > .widget-title',
|
||||
distance: 2,
|
||||
helper: 'clone',
|
||||
zIndex: 101,
|
||||
containment: '#wpwrap',
|
||||
refreshPositions: true,
|
||||
start: function( event, ui ) {
|
||||
var chooser = $(this).find('.widgets-chooser');
|
||||
|
||||
ui.helper.find('div.widget-description').hide();
|
||||
the_id = this.id;
|
||||
|
||||
if ( chooser.length ) {
|
||||
// Hide the chooser and move it out of the widget.
|
||||
$( '#wpbody-content' ).append( chooser.hide() );
|
||||
// Delete the cloned chooser from the drag helper.
|
||||
ui.helper.find('.widgets-chooser').remove();
|
||||
self.clearWidgetSelection();
|
||||
}
|
||||
},
|
||||
stop: function() {
|
||||
if ( rem ) {
|
||||
$(rem).hide();
|
||||
}
|
||||
|
||||
rem = '';
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Opens and closes previously closed Sidebars when Widgets are dragged over/out of them.
|
||||
*/
|
||||
sidebars.droppable( {
|
||||
tolerance: 'intersect',
|
||||
|
||||
/**
|
||||
* Open Sidebar when a Widget gets dragged over it.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @param {Object} event jQuery event object.
|
||||
*/
|
||||
over: function( event ) {
|
||||
var $wrap = $( event.target ).parent();
|
||||
|
||||
if ( wpWidgets.hoveredSidebar && ! $wrap.is( wpWidgets.hoveredSidebar ) ) {
|
||||
// Close the previous Sidebar as the Widget has been dragged onto another Sidebar.
|
||||
wpWidgets.closeSidebar( event );
|
||||
}
|
||||
|
||||
if ( $wrap.hasClass( 'closed' ) ) {
|
||||
wpWidgets.hoveredSidebar = $wrap;
|
||||
$wrap
|
||||
.removeClass( 'closed' )
|
||||
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
|
||||
}
|
||||
|
||||
$( this ).sortable( 'refresh' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Close Sidebar when the Widget gets dragged out of it.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @param {Object} event jQuery event object.
|
||||
*/
|
||||
out: function( event ) {
|
||||
if ( wpWidgets.hoveredSidebar ) {
|
||||
wpWidgets.closeSidebar( event );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
sidebars.sortable({
|
||||
placeholder: 'widget-placeholder',
|
||||
items: '> .widget',
|
||||
handle: '> .widget-top > .widget-title',
|
||||
cursor: 'move',
|
||||
distance: 2,
|
||||
containment: '#wpwrap',
|
||||
tolerance: 'pointer',
|
||||
refreshPositions: true,
|
||||
start: function( event, ui ) {
|
||||
var height, $this = $(this),
|
||||
$wrap = $this.parent(),
|
||||
inside = ui.item.children('.widget-inside');
|
||||
|
||||
if ( inside.css('display') === 'block' ) {
|
||||
ui.item.removeClass('open');
|
||||
ui.item.find( '.widget-top button.widget-action' ).attr( 'aria-expanded', 'false' );
|
||||
inside.hide();
|
||||
$(this).sortable('refreshPositions');
|
||||
}
|
||||
|
||||
if ( ! $wrap.hasClass('closed') ) {
|
||||
// Lock all open sidebars min-height when starting to drag.
|
||||
// Prevents jumping when dragging a widget from an open sidebar to a closed sidebar below.
|
||||
height = ui.item.hasClass('ui-draggable') ? $this.height() : 1 + $this.height();
|
||||
$this.css( 'min-height', height + 'px' );
|
||||
}
|
||||
},
|
||||
|
||||
stop: function( event, ui ) {
|
||||
var addNew, widgetNumber, $sidebar, $children, child, item,
|
||||
$widget = ui.item,
|
||||
id = the_id;
|
||||
|
||||
// Reset the var to hold a previously closed sidebar.
|
||||
wpWidgets.hoveredSidebar = null;
|
||||
|
||||
if ( $widget.hasClass('deleting') ) {
|
||||
wpWidgets.save( $widget, 1, 0, 1 ); // Delete widget.
|
||||
$widget.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
addNew = $widget.find('input.add_new').val();
|
||||
widgetNumber = $widget.find('input.multi_number').val();
|
||||
|
||||
$widget.attr( 'style', '' ).removeClass('ui-draggable');
|
||||
the_id = '';
|
||||
|
||||
if ( addNew ) {
|
||||
if ( 'multi' === addNew ) {
|
||||
$widget.html(
|
||||
$widget.html().replace( /<[^<>]+>/g, function( tag ) {
|
||||
return tag.replace( /__i__|%i%/g, widgetNumber );
|
||||
})
|
||||
);
|
||||
|
||||
$widget.attr( 'id', id.replace( '__i__', widgetNumber ) );
|
||||
widgetNumber++;
|
||||
|
||||
$( 'div#' + id ).find( 'input.multi_number' ).val( widgetNumber );
|
||||
} else if ( 'single' === addNew ) {
|
||||
$widget.attr( 'id', 'new-' + id );
|
||||
rem = 'div#' + id;
|
||||
}
|
||||
|
||||
wpWidgets.save( $widget, 0, 0, 1 );
|
||||
$widget.find('input.add_new').val('');
|
||||
$document.trigger( 'widget-added', [ $widget ] );
|
||||
}
|
||||
|
||||
$sidebar = $widget.parent();
|
||||
|
||||
if ( $sidebar.parent().hasClass('closed') ) {
|
||||
$sidebar.parent()
|
||||
.removeClass( 'closed' )
|
||||
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
|
||||
|
||||
$children = $sidebar.children('.widget');
|
||||
|
||||
// Make sure the dropped widget is at the top.
|
||||
if ( $children.length > 1 ) {
|
||||
child = $children.get(0);
|
||||
item = $widget.get(0);
|
||||
|
||||
if ( child.id && item.id && child.id !== item.id ) {
|
||||
$( child ).before( $widget );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( addNew ) {
|
||||
$widget.find( '.widget-action' ).trigger( 'click' );
|
||||
} else {
|
||||
wpWidgets.saveOrder( $sidebar.attr('id') );
|
||||
}
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
$(this).parent().addClass( 'widget-hover' );
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
// Remove all min-height added on "start".
|
||||
$(this).css( 'min-height', '' ).parent().removeClass( 'widget-hover' );
|
||||
},
|
||||
|
||||
receive: function( event, ui ) {
|
||||
var $sender = $( ui.sender );
|
||||
|
||||
// Don't add more widgets to orphaned sidebars.
|
||||
if ( this.id.indexOf('orphaned_widgets') > -1 ) {
|
||||
$sender.sortable('cancel');
|
||||
return;
|
||||
}
|
||||
|
||||
// If the last widget was moved out of an orphaned sidebar, close and remove it.
|
||||
if ( $sender.attr('id').indexOf('orphaned_widgets') > -1 && ! $sender.children('.widget').length ) {
|
||||
$sender.parents('.orphan-sidebar').slideUp( 400, function(){ $(this).remove(); } );
|
||||
}
|
||||
}
|
||||
}).sortable( 'option', 'connectWith', 'div.widgets-sortables' );
|
||||
|
||||
$('#available-widgets').droppable({
|
||||
tolerance: 'pointer',
|
||||
accept: function(o){
|
||||
return $(o).parent().attr('id') !== 'widget-list';
|
||||
},
|
||||
drop: function(e,ui) {
|
||||
ui.draggable.addClass('deleting');
|
||||
$('#removing-widget').hide().children('span').empty();
|
||||
},
|
||||
over: function(e,ui) {
|
||||
ui.draggable.addClass('deleting');
|
||||
$('div.widget-placeholder').hide();
|
||||
|
||||
if ( ui.draggable.hasClass('ui-sortable-helper') ) {
|
||||
$('#removing-widget').show().children('span')
|
||||
.html( ui.draggable.find( 'div.widget-title' ).children( 'h3' ).html() );
|
||||
}
|
||||
},
|
||||
out: function(e,ui) {
|
||||
ui.draggable.removeClass('deleting');
|
||||
$('div.widget-placeholder').show();
|
||||
$('#removing-widget').hide().children('span').empty();
|
||||
}
|
||||
});
|
||||
|
||||
// Area Chooser.
|
||||
$( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
|
||||
var $element = $( element ),
|
||||
name = $element.find( '.sidebar-name h2' ).text() || '',
|
||||
ariaLabel = $element.find( '.sidebar-name' ).data( 'add-to' ),
|
||||
id = $element.find( '.widgets-sortables' ).attr( 'id' ),
|
||||
li = $( '<li>' ),
|
||||
button = $( '<button>', {
|
||||
type: 'button',
|
||||
'aria-pressed': 'false',
|
||||
'class': 'widgets-chooser-button',
|
||||
'aria-label': ariaLabel
|
||||
} ).text( name.toString().trim() );
|
||||
|
||||
li.append( button );
|
||||
|
||||
if ( index === 0 ) {
|
||||
li.addClass( 'widgets-chooser-selected' );
|
||||
button.attr( 'aria-pressed', 'true' );
|
||||
}
|
||||
|
||||
selectSidebar.append( li );
|
||||
li.data( 'sidebarId', id );
|
||||
});
|
||||
|
||||
$( '#available-widgets .widget .widget-top' ).on( 'click.widgets-chooser', function() {
|
||||
var $widget = $( this ).closest( '.widget' ),
|
||||
toggleButton = $( this ).find( '.widget-action' ),
|
||||
chooserButtons = selectSidebar.find( '.widgets-chooser-button' );
|
||||
|
||||
if ( $widget.hasClass( 'widget-in-question' ) || $( '#widgets-left' ).hasClass( 'chooser' ) ) {
|
||||
toggleButton.attr( 'aria-expanded', 'false' );
|
||||
self.closeChooser();
|
||||
} else {
|
||||
// Open the chooser.
|
||||
self.clearWidgetSelection();
|
||||
$( '#widgets-left' ).addClass( 'chooser' );
|
||||
// Add CSS class and insert the chooser after the widget description.
|
||||
$widget.addClass( 'widget-in-question' ).children( '.widget-description' ).after( chooser );
|
||||
// Open the chooser with a slide down animation.
|
||||
chooser.slideDown( 300, function() {
|
||||
// Update the toggle button aria-expanded attribute after previous DOM manipulations.
|
||||
toggleButton.attr( 'aria-expanded', 'true' );
|
||||
});
|
||||
|
||||
chooserButtons.on( 'click.widgets-chooser', function() {
|
||||
selectSidebar.find( '.widgets-chooser-selected' ).removeClass( 'widgets-chooser-selected' );
|
||||
chooserButtons.attr( 'aria-pressed', 'false' );
|
||||
$( this )
|
||||
.attr( 'aria-pressed', 'true' )
|
||||
.closest( 'li' ).addClass( 'widgets-chooser-selected' );
|
||||
} );
|
||||
}
|
||||
});
|
||||
|
||||
// Add event handlers.
|
||||
chooser.on( 'click.widgets-chooser', function( event ) {
|
||||
var $target = $( event.target );
|
||||
|
||||
if ( $target.hasClass('button-primary') ) {
|
||||
self.addWidget( chooser );
|
||||
self.closeChooser();
|
||||
} else if ( $target.hasClass( 'widgets-chooser-cancel' ) ) {
|
||||
self.closeChooser();
|
||||
}
|
||||
}).on( 'keyup.widgets-chooser', function( event ) {
|
||||
if ( event.which === $.ui.keyCode.ESCAPE ) {
|
||||
self.closeChooser();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
saveOrder : function( sidebarId ) {
|
||||
var data = {
|
||||
action: 'widgets-order',
|
||||
savewidgets: $('#_wpnonce_widgets').val(),
|
||||
sidebars: []
|
||||
};
|
||||
|
||||
if ( sidebarId ) {
|
||||
$( '#' + sidebarId ).find( '.spinner:first' ).addClass( 'is-active' );
|
||||
}
|
||||
|
||||
$('div.widgets-sortables').each( function() {
|
||||
if ( $(this).sortable ) {
|
||||
data['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
|
||||
}
|
||||
});
|
||||
|
||||
$.post( ajaxurl, data, function() {
|
||||
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
|
||||
$( '.spinner' ).removeClass( 'is-active' );
|
||||
});
|
||||
},
|
||||
|
||||
save : function( widget, del, animate, order ) {
|
||||
var self = this, data, a,
|
||||
sidebarId = widget.closest( 'div.widgets-sortables' ).attr( 'id' ),
|
||||
form = widget.find( 'form' ),
|
||||
isAdd = widget.find( 'input.add_new' ).val();
|
||||
|
||||
if ( ! del && ! isAdd && form.prop( 'checkValidity' ) && ! form[0].checkValidity() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
data = form.serialize();
|
||||
|
||||
widget = $(widget);
|
||||
$( '.spinner', widget ).addClass( 'is-active' );
|
||||
|
||||
a = {
|
||||
action: 'save-widget',
|
||||
savewidgets: $('#_wpnonce_widgets').val(),
|
||||
sidebar: sidebarId
|
||||
};
|
||||
|
||||
if ( del ) {
|
||||
a.delete_widget = 1;
|
||||
}
|
||||
|
||||
data += '&' + $.param(a);
|
||||
|
||||
$.post( ajaxurl, data, function(r) {
|
||||
var id = $('input.widget-id', widget).val();
|
||||
|
||||
if ( del ) {
|
||||
if ( ! $('input.widget_number', widget).val() ) {
|
||||
$('#available-widgets').find('input.widget-id').each(function(){
|
||||
if ( $(this).val() === id ) {
|
||||
$(this).closest('div.widget').show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ( animate ) {
|
||||
order = 0;
|
||||
widget.slideUp( 'fast', function() {
|
||||
$( this ).remove();
|
||||
wpWidgets.saveOrder();
|
||||
delete self.dirtyWidgets[ id ];
|
||||
});
|
||||
} else {
|
||||
widget.remove();
|
||||
delete self.dirtyWidgets[ id ];
|
||||
|
||||
if ( sidebarId === 'wp_inactive_widgets' ) {
|
||||
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$( '.spinner' ).removeClass( 'is-active' );
|
||||
if ( r && r.length > 2 ) {
|
||||
$( 'div.widget-content', widget ).html( r );
|
||||
wpWidgets.appendTitle( widget );
|
||||
|
||||
// Re-disable the save button.
|
||||
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
|
||||
|
||||
widget.removeClass( 'widget-dirty' );
|
||||
|
||||
// Clear the dirty flag from the widget.
|
||||
delete self.dirtyWidgets[ id ];
|
||||
|
||||
$document.trigger( 'widget-updated', [ widget ] );
|
||||
|
||||
if ( sidebarId === 'wp_inactive_widgets' ) {
|
||||
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( order ) {
|
||||
wpWidgets.saveOrder();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeInactiveWidgets : function() {
|
||||
var $element = $( '.remove-inactive-widgets' ), self = this, a, data;
|
||||
|
||||
$( '.spinner', $element ).addClass( 'is-active' );
|
||||
|
||||
a = {
|
||||
action : 'delete-inactive-widgets',
|
||||
removeinactivewidgets : $( '#_wpnonce_remove_inactive_widgets' ).val()
|
||||
};
|
||||
|
||||
data = $.param( a );
|
||||
|
||||
$.post( ajaxurl, data, function() {
|
||||
$( '#wp_inactive_widgets .widget' ).each(function() {
|
||||
var $widget = $( this );
|
||||
delete self.dirtyWidgets[ $widget.find( 'input.widget-id' ).val() ];
|
||||
$widget.remove();
|
||||
});
|
||||
$( '#inactive-widgets-control-remove' ).prop( 'disabled', true );
|
||||
$( '.spinner', $element ).removeClass( 'is-active' );
|
||||
} );
|
||||
},
|
||||
|
||||
appendTitle : function(widget) {
|
||||
var title = $('input[id*="-title"]', widget).val() || '';
|
||||
|
||||
if ( title ) {
|
||||
title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
|
||||
$(widget).children('.widget-top').children('.widget-title').children()
|
||||
.children('.in-widget-title').html(title);
|
||||
|
||||
},
|
||||
|
||||
close : function(widget) {
|
||||
widget.children('.widget-inside').slideUp('fast', function() {
|
||||
widget.attr( 'style', '' )
|
||||
.find( '.widget-top button.widget-action' )
|
||||
.attr( 'aria-expanded', 'false' )
|
||||
.focus();
|
||||
});
|
||||
},
|
||||
|
||||
addWidget: function( chooser ) {
|
||||
var widget, widgetId, add, n, viewportTop, viewportBottom, sidebarBounds,
|
||||
sidebarId = chooser.find( '.widgets-chooser-selected' ).data('sidebarId'),
|
||||
sidebar = $( '#' + sidebarId );
|
||||
|
||||
widget = $('#available-widgets').find('.widget-in-question').clone();
|
||||
widgetId = widget.attr('id');
|
||||
add = widget.find( 'input.add_new' ).val();
|
||||
n = widget.find( 'input.multi_number' ).val();
|
||||
|
||||
// Remove the cloned chooser from the widget.
|
||||
widget.find('.widgets-chooser').remove();
|
||||
|
||||
if ( 'multi' === add ) {
|
||||
widget.html(
|
||||
widget.html().replace( /<[^<>]+>/g, function(m) {
|
||||
return m.replace( /__i__|%i%/g, n );
|
||||
})
|
||||
);
|
||||
|
||||
widget.attr( 'id', widgetId.replace( '__i__', n ) );
|
||||
n++;
|
||||
$( '#' + widgetId ).find('input.multi_number').val(n);
|
||||
} else if ( 'single' === add ) {
|
||||
widget.attr( 'id', 'new-' + widgetId );
|
||||
$( '#' + widgetId ).hide();
|
||||
}
|
||||
|
||||
// Open the widgets container.
|
||||
sidebar.closest( '.widgets-holder-wrap' )
|
||||
.removeClass( 'closed' )
|
||||
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
|
||||
|
||||
sidebar.append( widget );
|
||||
sidebar.sortable('refresh');
|
||||
|
||||
wpWidgets.save( widget, 0, 0, 1 );
|
||||
// No longer "new" widget.
|
||||
widget.find( 'input.add_new' ).val('');
|
||||
|
||||
$document.trigger( 'widget-added', [ widget ] );
|
||||
|
||||
/*
|
||||
* Check if any part of the sidebar is visible in the viewport. If it is, don't scroll.
|
||||
* Otherwise, scroll up to so the sidebar is in view.
|
||||
*
|
||||
* We do this by comparing the top and bottom, of the sidebar so see if they are within
|
||||
* the bounds of the viewport.
|
||||
*/
|
||||
viewportTop = $(window).scrollTop();
|
||||
viewportBottom = viewportTop + $(window).height();
|
||||
sidebarBounds = sidebar.offset();
|
||||
|
||||
sidebarBounds.bottom = sidebarBounds.top + sidebar.outerHeight();
|
||||
|
||||
if ( viewportTop > sidebarBounds.bottom || viewportBottom < sidebarBounds.top ) {
|
||||
$( 'html, body' ).animate({
|
||||
scrollTop: sidebarBounds.top - 130
|
||||
}, 200 );
|
||||
}
|
||||
|
||||
window.setTimeout( function() {
|
||||
// Cannot use a callback in the animation above as it fires twice,
|
||||
// have to queue this "by hand".
|
||||
widget.find( '.widget-title' ).trigger('click');
|
||||
// At the end of the animation, announce the widget has been added.
|
||||
window.wp.a11y.speak( wp.i18n.__( 'Widget has been added to the selected sidebar' ), 'assertive' );
|
||||
}, 250 );
|
||||
},
|
||||
|
||||
closeChooser: function() {
|
||||
var self = this,
|
||||
widgetInQuestion = $( '#available-widgets .widget-in-question' );
|
||||
|
||||
$( '.widgets-chooser' ).slideUp( 200, function() {
|
||||
$( '#wpbody-content' ).append( this );
|
||||
self.clearWidgetSelection();
|
||||
// Move focus back to the toggle button.
|
||||
widgetInQuestion.find( '.widget-action' ).attr( 'aria-expanded', 'false' ).focus();
|
||||
});
|
||||
},
|
||||
|
||||
clearWidgetSelection: function() {
|
||||
$( '#widgets-left' ).removeClass( 'chooser' );
|
||||
$( '.widget-in-question' ).removeClass( 'widget-in-question' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Closes a Sidebar that was previously closed, but opened by dragging a Widget over it.
|
||||
*
|
||||
* Used when a Widget gets dragged in/out of the Sidebar and never dropped.
|
||||
*
|
||||
* @param {Object} event jQuery event object.
|
||||
*/
|
||||
closeSidebar: function( event ) {
|
||||
this.hoveredSidebar
|
||||
.addClass( 'closed' )
|
||||
.find( '.handlediv' ).attr( 'aria-expanded', 'false' );
|
||||
|
||||
$( event.target ).css( 'min-height', '' );
|
||||
this.hoveredSidebar = null;
|
||||
}
|
||||
};
|
||||
|
||||
$( function(){ wpWidgets.init(); } );
|
||||
|
||||
})(jQuery);
|
||||
|
||||
/**
|
||||
* Removed in 5.5.0, needed for back-compatibility.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @deprecated 5.5.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
wpWidgets.l10n = wpWidgets.l10n || {
|
||||
save: '',
|
||||
saved: '',
|
||||
saveAlert: '',
|
||||
widgetAdded: ''
|
||||
};
|
||||
|
||||
wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n, '5.5.0' );
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(w){var l=w(document);window.wpWidgets={hoveredSidebar:null,dirtyWidgets:{},init:function(){var r,o,g=this,d=w(".widgets-chooser"),s=d.find(".widgets-chooser-sidebars"),e=w("div.widgets-sortables"),c=!("undefined"==typeof isRtl||!isRtl);w("#widgets-right .sidebar-name").on("click",function(){var e=w(this),i=e.closest(".widgets-holder-wrap "),t=e.find(".handlediv");i.hasClass("closed")?(i.removeClass("closed"),t.attr("aria-expanded","true"),e.parent().sortable("refresh")):(i.addClass("closed"),t.attr("aria-expanded","false")),l.triggerHandler("wp-pin-menu")}).find(".handlediv").each(function(e){0!==e&&w(this).attr("aria-expanded","false")}),w(window).on("beforeunload.widgets",function(e){var i,t=[];if(w.each(g.dirtyWidgets,function(e,i){i&&t.push(e)}),0!==t.length)return(i=w("#widgets-right").find(".widget").filter(function(){return-1!==t.indexOf(w(this).prop("id").replace(/^widget-\d+_/,""))})).each(function(){w(this).hasClass("open")||w(this).find(".widget-title-action:first").trigger("click")}),i.first().each(function(){this.scrollIntoViewIfNeeded?this.scrollIntoViewIfNeeded():this.scrollIntoView(),w(this).find(".widget-inside :tabbable:first").trigger("focus")}),e.returnValue=wp.i18n.__("The changes you made will be lost if you navigate away from this page."),e.returnValue}),w("#widgets-left .sidebar-name").on("click",function(){var e=w(this).closest(".widgets-holder-wrap");e.toggleClass("closed").find(".handlediv").attr("aria-expanded",!e.hasClass("closed")),l.triggerHandler("wp-pin-menu")}),w(document.body).on("click.widgets-toggle",function(e){var i,t,d,a,s,n,r=w(e.target),o={},l=r.closest(".widget").find(".widget-top button.widget-action");r.parents(".widget-top").length&&!r.parents("#available-widgets").length?(t=(i=r.closest("div.widget")).children(".widget-inside"),d=parseInt(i.find("input.widget-width").val(),10),a=i.parent().width(),n=t.find(".widget-id").val(),i.data("dirty-state-initialized")||((s=t.find(".widget-control-save")).prop("disabled",!0).val(wp.i18n.__("Saved")),t.on("input change",function(){g.dirtyWidgets[n]=!0,i.addClass("widget-dirty"),s.prop("disabled",!1).val(wp.i18n.__("Save"))}),i.data("dirty-state-initialized",!0)),t.is(":hidden")?(250<d&&a<d+30&&i.closest("div.widgets-sortables").length&&(o[i.closest("div.widget-liquid-right").length?c?"margin-right":"margin-left":c?"margin-left":"margin-right"]=a-(d+30)+"px",i.css(o)),l.attr("aria-expanded","true"),t.slideDown("fast",function(){i.addClass("open")})):(l.attr("aria-expanded","false"),t.slideUp("fast",function(){i.attr("style",""),i.removeClass("open")}))):r.hasClass("widget-control-save")?(wpWidgets.save(r.closest("div.widget"),0,1,0),e.preventDefault()):r.hasClass("widget-control-remove")?wpWidgets.save(r.closest("div.widget"),1,1,0):r.hasClass("widget-control-close")?((i=r.closest("div.widget")).removeClass("open"),l.attr("aria-expanded","false"),wpWidgets.close(i)):"inactive-widgets-control-remove"===r.attr("id")&&(wpWidgets.removeInactiveWidgets(),e.preventDefault())}),e.children(".widget").each(function(){var e=w(this);wpWidgets.appendTitle(this),e.find("p.widget-error").length&&e.find(".widget-action").trigger("click").attr("aria-expanded","true")}),w("#widget-list").children(".widget").draggable({connectToSortable:"div.widgets-sortables",handle:"> .widget-top > .widget-title",distance:2,helper:"clone",zIndex:101,containment:"#wpwrap",refreshPositions:!0,start:function(e,i){var t=w(this).find(".widgets-chooser");i.helper.find("div.widget-description").hide(),o=this.id,t.length&&(w("#wpbody-content").append(t.hide()),i.helper.find(".widgets-chooser").remove(),g.clearWidgetSelection())},stop:function(){r&&w(r).hide(),r=""}}),e.droppable({tolerance:"intersect",over:function(e){var i=w(e.target).parent();wpWidgets.hoveredSidebar&&!i.is(wpWidgets.hoveredSidebar)&&wpWidgets.closeSidebar(e),i.hasClass("closed")&&(wpWidgets.hoveredSidebar=i).removeClass("closed").find(".handlediv").attr("aria-expanded","true"),w(this).sortable("refresh")},out:function(e){wpWidgets.hoveredSidebar&&wpWidgets.closeSidebar(e)}}),e.sortable({placeholder:"widget-placeholder",items:"> .widget",handle:"> .widget-top > .widget-title",cursor:"move",distance:2,containment:"#wpwrap",tolerance:"pointer",refreshPositions:!0,start:function(e,i){var t=w(this),d=t.parent(),a=i.item.children(".widget-inside");"block"===a.css("display")&&(i.item.removeClass("open"),i.item.find(".widget-top button.widget-action").attr("aria-expanded","false"),a.hide(),w(this).sortable("refreshPositions")),d.hasClass("closed")||(a=i.item.hasClass("ui-draggable")?t.height():1+t.height(),t.css("min-height",a+"px"))},stop:function(e,i){var t,d,a,s,i=i.item,n=o;wpWidgets.hoveredSidebar=null,i.hasClass("deleting")?(wpWidgets.save(i,1,0,1),i.remove()):(t=i.find("input.add_new").val(),d=i.find("input.multi_number").val(),i.attr("style","").removeClass("ui-draggable"),o="",t&&("multi"===t?(i.html(i.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,d)})),i.attLine truncated
|
||||
@@ -0,0 +1,462 @@
|
||||
/**
|
||||
* @output wp-admin/js/widgets/custom-html-widgets.js
|
||||
*/
|
||||
|
||||
/* global wp */
|
||||
/* eslint consistent-this: [ "error", "control" ] */
|
||||
/* eslint no-magic-numbers: ["error", { "ignore": [0,1,-1] }] */
|
||||
|
||||
/**
|
||||
* @namespace wp.customHtmlWidget
|
||||
* @memberOf wp
|
||||
*/
|
||||
wp.customHtmlWidgets = ( function( $ ) {
|
||||
'use strict';
|
||||
|
||||
var component = {
|
||||
idBases: [ 'custom_html' ],
|
||||
codeEditorSettings: {},
|
||||
l10n: {
|
||||
errorNotice: {
|
||||
singular: '',
|
||||
plural: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
component.CustomHtmlWidgetControl = Backbone.View.extend(/** @lends wp.customHtmlWidgets.CustomHtmlWidgetControl.prototype */{
|
||||
|
||||
/**
|
||||
* View events.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
events: {},
|
||||
|
||||
/**
|
||||
* Text widget control.
|
||||
*
|
||||
* @constructs wp.customHtmlWidgets.CustomHtmlWidgetControl
|
||||
* @augments Backbone.View
|
||||
* @abstract
|
||||
*
|
||||
* @param {Object} options - Options.
|
||||
* @param {jQuery} options.el - Control field container element.
|
||||
* @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
initialize: function initialize( options ) {
|
||||
var control = this;
|
||||
|
||||
if ( ! options.el ) {
|
||||
throw new Error( 'Missing options.el' );
|
||||
}
|
||||
if ( ! options.syncContainer ) {
|
||||
throw new Error( 'Missing options.syncContainer' );
|
||||
}
|
||||
|
||||
Backbone.View.prototype.initialize.call( control, options );
|
||||
control.syncContainer = options.syncContainer;
|
||||
control.widgetIdBase = control.syncContainer.parent().find( '.id_base' ).val();
|
||||
control.widgetNumber = control.syncContainer.parent().find( '.widget_number' ).val();
|
||||
control.customizeSettingId = 'widget_' + control.widgetIdBase + '[' + String( control.widgetNumber ) + ']';
|
||||
|
||||
control.$el.addClass( 'custom-html-widget-fields' );
|
||||
control.$el.html( wp.template( 'widget-custom-html-control-fields' )( { codeEditorDisabled: component.codeEditorSettings.disabled } ) );
|
||||
|
||||
control.errorNoticeContainer = control.$el.find( '.code-editor-error-container' );
|
||||
control.currentErrorAnnotations = [];
|
||||
control.saveButton = control.syncContainer.add( control.syncContainer.parent().find( '.widget-control-actions' ) ).find( '.widget-control-save, #savewidget' );
|
||||
control.saveButton.addClass( 'custom-html-widget-save-button' ); // To facilitate style targeting.
|
||||
|
||||
control.fields = {
|
||||
title: control.$el.find( '.title' ),
|
||||
content: control.$el.find( '.content' )
|
||||
};
|
||||
|
||||
// Sync input fields to hidden sync fields which actually get sent to the server.
|
||||
_.each( control.fields, function( fieldInput, fieldName ) {
|
||||
fieldInput.on( 'input change', function updateSyncField() {
|
||||
var syncInput = control.syncContainer.find( '.sync-input.' + fieldName );
|
||||
if ( syncInput.val() !== fieldInput.val() ) {
|
||||
syncInput.val( fieldInput.val() );
|
||||
syncInput.trigger( 'change' );
|
||||
}
|
||||
});
|
||||
|
||||
// Note that syncInput cannot be re-used because it will be destroyed with each widget-updated event.
|
||||
fieldInput.val( control.syncContainer.find( '.sync-input.' + fieldName ).val() );
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Update input fields from the sync fields.
|
||||
*
|
||||
* This function is called at the widget-updated and widget-synced events.
|
||||
* A field will only be updated if it is not currently focused, to avoid
|
||||
* overwriting content that the user is entering.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
updateFields: function updateFields() {
|
||||
var control = this, syncInput;
|
||||
|
||||
if ( ! control.fields.title.is( document.activeElement ) ) {
|
||||
syncInput = control.syncContainer.find( '.sync-input.title' );
|
||||
control.fields.title.val( syncInput.val() );
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevent updating content when the editor is focused or if there are current error annotations,
|
||||
* to prevent the editor's contents from getting sanitized as soon as a user removes focus from
|
||||
* the editor. This is particularly important for users who cannot unfiltered_html.
|
||||
*/
|
||||
control.contentUpdateBypassed = control.fields.content.is( document.activeElement ) || control.editor && control.editor.codemirror.state.focused || 0 !== control.currentErrorAnnotations.length;
|
||||
if ( ! control.contentUpdateBypassed ) {
|
||||
syncInput = control.syncContainer.find( '.sync-input.content' );
|
||||
control.fields.content.val( syncInput.val() );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Show linting error notice.
|
||||
*
|
||||
* @param {Array} errorAnnotations - Error annotations.
|
||||
* @return {void}
|
||||
*/
|
||||
updateErrorNotice: function( errorAnnotations ) {
|
||||
var control = this, errorNotice, message = '', customizeSetting;
|
||||
|
||||
if ( 1 === errorAnnotations.length ) {
|
||||
message = component.l10n.errorNotice.singular.replace( '%d', '1' );
|
||||
} else if ( errorAnnotations.length > 1 ) {
|
||||
message = component.l10n.errorNotice.plural.replace( '%d', String( errorAnnotations.length ) );
|
||||
}
|
||||
|
||||
if ( control.fields.content[0].setCustomValidity ) {
|
||||
control.fields.content[0].setCustomValidity( message );
|
||||
}
|
||||
|
||||
if ( wp.customize && wp.customize.has( control.customizeSettingId ) ) {
|
||||
customizeSetting = wp.customize( control.customizeSettingId );
|
||||
customizeSetting.notifications.remove( 'htmlhint_error' );
|
||||
if ( 0 !== errorAnnotations.length ) {
|
||||
customizeSetting.notifications.add( 'htmlhint_error', new wp.customize.Notification( 'htmlhint_error', {
|
||||
message: message,
|
||||
type: 'error'
|
||||
} ) );
|
||||
}
|
||||
} else if ( 0 !== errorAnnotations.length ) {
|
||||
errorNotice = $( '<div class="inline notice notice-error notice-alt" role="alert"></div>' );
|
||||
errorNotice.append( $( '<p></p>', {
|
||||
text: message
|
||||
} ) );
|
||||
control.errorNoticeContainer.empty();
|
||||
control.errorNoticeContainer.append( errorNotice );
|
||||
control.errorNoticeContainer.slideDown( 'fast' );
|
||||
wp.a11y.speak( message );
|
||||
} else {
|
||||
control.errorNoticeContainer.slideUp( 'fast' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize editor.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
initializeEditor: function initializeEditor() {
|
||||
var control = this, settings;
|
||||
|
||||
if ( component.codeEditorSettings.disabled ) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings = _.extend( {}, component.codeEditorSettings, {
|
||||
|
||||
/**
|
||||
* Handle tabbing to the field before the editor.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
onTabPrevious: function onTabPrevious() {
|
||||
control.fields.title.focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle tabbing to the field after the editor.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
onTabNext: function onTabNext() {
|
||||
var tabbables = control.syncContainer.add( control.syncContainer.parent().find( '.widget-position, .widget-control-actions' ) ).find( ':tabbable' );
|
||||
tabbables.first().focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable save button and store linting errors for use in updateFields.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @param {Array} errorAnnotations - Error notifications.
|
||||
* @return {void}
|
||||
*/
|
||||
onChangeLintingErrors: function onChangeLintingErrors( errorAnnotations ) {
|
||||
control.currentErrorAnnotations = errorAnnotations;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update error notice.
|
||||
*
|
||||
* @ignore
|
||||
*
|
||||
* @param {Array} errorAnnotations - Error annotations.
|
||||
* @return {void}
|
||||
*/
|
||||
onUpdateErrorNotice: function onUpdateErrorNotice( errorAnnotations ) {
|
||||
control.saveButton.toggleClass( 'validation-blocked disabled', errorAnnotations.length > 0 );
|
||||
control.updateErrorNotice( errorAnnotations );
|
||||
}
|
||||
});
|
||||
|
||||
control.editor = wp.codeEditor.initialize( control.fields.content, settings );
|
||||
|
||||
// Improve the editor accessibility.
|
||||
$( control.editor.codemirror.display.lineDiv )
|
||||
.attr({
|
||||
role: 'textbox',
|
||||
'aria-multiline': 'true',
|
||||
'aria-labelledby': control.fields.content[0].id + '-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.fields.content[0].id + '-label' ).on( 'click', function() {
|
||||
control.editor.codemirror.focus();
|
||||
});
|
||||
|
||||
control.fields.content.on( 'change', function() {
|
||||
if ( this.value !== control.editor.codemirror.getValue() ) {
|
||||
control.editor.codemirror.setValue( this.value );
|
||||
}
|
||||
});
|
||||
control.editor.codemirror.on( 'change', function() {
|
||||
var value = control.editor.codemirror.getValue();
|
||||
if ( value !== control.fields.content.val() ) {
|
||||
control.fields.content.val( value ).trigger( 'change' );
|
||||
}
|
||||
});
|
||||
|
||||
// Make sure the editor gets updated if the content was updated on the server (sanitization) but not updated in the editor since it was focused.
|
||||
control.editor.codemirror.on( 'blur', function() {
|
||||
if ( control.contentUpdateBypassed ) {
|
||||
control.syncContainer.find( '.sync-input.content' ).trigger( 'change' );
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent hitting Esc from collapsing the widget control.
|
||||
if ( wp.customize ) {
|
||||
control.editor.codemirror.on( 'keydown', function onKeydown( codemirror, event ) {
|
||||
var escKeyCode = 27;
|
||||
if ( escKeyCode === event.keyCode ) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Mapping of widget ID to instances of CustomHtmlWidgetControl subclasses.
|
||||
*
|
||||
* @alias wp.customHtmlWidgets.widgetControls
|
||||
*
|
||||
* @type {Object.<string, wp.textWidgets.CustomHtmlWidgetControl>}
|
||||
*/
|
||||
component.widgetControls = {};
|
||||
|
||||
/**
|
||||
* Handle widget being added or initialized for the first time at the widget-added event.
|
||||
*
|
||||
* @alias wp.customHtmlWidgets.handleWidgetAdded
|
||||
*
|
||||
* @param {jQuery.Event} event - Event.
|
||||
* @param {jQuery} widgetContainer - Widget container element.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
|
||||
var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer;
|
||||
widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
|
||||
|
||||
idBase = widgetForm.find( '> .id_base' ).val();
|
||||
if ( -1 === component.idBases.indexOf( idBase ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent initializing already-added widgets.
|
||||
widgetId = widgetForm.find( '.widget-id' ).val();
|
||||
if ( component.widgetControls[ widgetId ] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a container element for the widget control fields.
|
||||
* This is inserted into the DOM immediately before the the .widget-content
|
||||
* element because the contents of this element are essentially "managed"
|
||||
* by PHP, where each widget update cause the entire element to be emptied
|
||||
* and replaced with the rendered output of WP_Widget::form() which is
|
||||
* sent back in Ajax request made to save/update the widget instance.
|
||||
* To prevent a "flash of replaced DOM elements and re-initialized JS
|
||||
* components", the JS template is rendered outside of the normal form
|
||||
* container.
|
||||
*/
|
||||
fieldContainer = $( '<div></div>' );
|
||||
syncContainer = widgetContainer.find( '.widget-content:first' );
|
||||
syncContainer.before( fieldContainer );
|
||||
|
||||
widgetControl = new component.CustomHtmlWidgetControl({
|
||||
el: fieldContainer,
|
||||
syncContainer: syncContainer
|
||||
});
|
||||
|
||||
component.widgetControls[ widgetId ] = widgetControl;
|
||||
|
||||
/*
|
||||
* Render the widget once the widget parent's container finishes animating,
|
||||
* as the widget-added event fires with a slideDown of the container.
|
||||
* This ensures that the textarea is visible and the editor can be initialized.
|
||||
*/
|
||||
renderWhenAnimationDone = function() {
|
||||
if ( ! ( wp.customize ? widgetContainer.parent().hasClass( 'expanded' ) : widgetContainer.hasClass( 'open' ) ) ) { // Core merge: The wp.customize condition can be eliminated with this change being in core: https://core.trac.wordpress.org/changeset/41260
|
||||
setTimeout( renderWhenAnimationDone, animatedCheckDelay );
|
||||
} else {
|
||||
widgetControl.initializeEditor();
|
||||
}
|
||||
};
|
||||
renderWhenAnimationDone();
|
||||
};
|
||||
|
||||
/**
|
||||
* Setup widget in accessibility mode.
|
||||
*
|
||||
* @alias wp.customHtmlWidgets.setupAccessibleMode
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
component.setupAccessibleMode = function setupAccessibleMode() {
|
||||
var widgetForm, idBase, widgetControl, fieldContainer, syncContainer;
|
||||
widgetForm = $( '.editwidget > form' );
|
||||
if ( 0 === widgetForm.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
idBase = widgetForm.find( '.id_base' ).val();
|
||||
if ( -1 === component.idBases.indexOf( idBase ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
fieldContainer = $( '<div></div>' );
|
||||
syncContainer = widgetForm.find( '> .widget-inside' );
|
||||
syncContainer.before( fieldContainer );
|
||||
|
||||
widgetControl = new component.CustomHtmlWidgetControl({
|
||||
el: fieldContainer,
|
||||
syncContainer: syncContainer
|
||||
});
|
||||
|
||||
widgetControl.initializeEditor();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sync widget instance data sanitized from server back onto widget model.
|
||||
*
|
||||
* This gets called via the 'widget-updated' event when saving a widget from
|
||||
* the widgets admin screen and also via the 'widget-synced' event when making
|
||||
* a change to a widget in the customizer.
|
||||
*
|
||||
* @alias wp.customHtmlWidgets.handleWidgetUpdated
|
||||
*
|
||||
* @param {jQuery.Event} event - Event.
|
||||
* @param {jQuery} widgetContainer - Widget container element.
|
||||
* @return {void}
|
||||
*/
|
||||
component.handleWidgetUpdated = function handleWidgetUpdated( event, widgetContainer ) {
|
||||
var widgetForm, widgetId, widgetControl, idBase;
|
||||
widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' );
|
||||
|
||||
idBase = widgetForm.find( '> .id_base' ).val();
|
||||
if ( -1 === component.idBases.indexOf( idBase ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
widgetId = widgetForm.find( '> .widget-id' ).val();
|
||||
widgetControl = component.widgetControls[ widgetId ];
|
||||
if ( ! widgetControl ) {
|
||||
return;
|
||||
}
|
||||
|
||||
widgetControl.updateFields();
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize functionality.
|
||||
*
|
||||
* This function exists to prevent the JS file from having to boot itself.
|
||||
* When WordPress enqueues this script, it should have an inline script
|
||||
* attached which calls wp.textWidgets.init().
|
||||
*
|
||||
* @alias wp.customHtmlWidgets.init
|
||||
*
|
||||
* @param {Object} settings - Options for code editor, exported from PHP.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
component.init = function init( settings ) {
|
||||
var $document = $( document );
|
||||
_.extend( component.codeEditorSettings, settings );
|
||||
|
||||
$document.on( 'widget-added', component.handleWidgetAdded );
|
||||
$document.on( 'widget-synced widget-updated', component.handleWidgetUpdated );
|
||||
|
||||
/*
|
||||
* Manually trigger widget-added events for media widgets on the admin
|
||||
* screen once they are expanded. The widget-added event is not triggered
|
||||
* for each pre-existing widget on the widgets admin screen like it is
|
||||
* on the customizer. Likewise, the customizer only triggers widget-added
|
||||
* when the widget is expanded to just-in-time construct the widget form
|
||||
* when it is actually going to be displayed. So the following implements
|
||||
* the same for the widgets admin screen, to invoke the widget-added
|
||||
* handler when a pre-existing media widget is expanded.
|
||||
*/
|
||||
$( function initializeExistingWidgetContainers() {
|
||||
var widgetContainers;
|
||||
if ( 'widgets' !== window.pagenow ) {
|
||||
return;
|
||||
}
|
||||
widgetContainers = $( '.widgets-holder-wrap:not(#available-widgets)' ).find( 'div.widget' );
|
||||
widgetContainers.one( 'click.toggle-widget-expanded', function toggleWidgetExpanded() {
|
||||
var widgetContainer = $( this );
|
||||
component.handleWidgetAdded( new jQuery.Event( 'widget-added' ), widgetContainer );
|
||||
});
|
||||
|
||||
// Accessibility mode.
|
||||
if ( document.readyState === 'complete' ) {
|
||||
// Page is fully loaded.
|
||||
component.setupAccessibleMode();
|
||||
} else {
|
||||
// Page is still loading.
|
||||
$( window ).on( 'load', function() {
|
||||
component.setupAccessibleMode();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return component;
|
||||
})( jQuery );
|
||||
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
wp.customHtmlWidgets=function(a){"use strict";var s={idBases:["custom_html"],codeEditorSettings:{},l10n:{errorNotice:{singular:"",plural:""}}};return s.CustomHtmlWidgetControl=Backbone.View.extend({events:{},initialize:function(e){var n=this;if(!e.el)throw new Error("Missing options.el");if(!e.syncContainer)throw new Error("Missing options.syncContainer");Backbone.View.prototype.initialize.call(n,e),n.syncContainer=e.syncContainer,n.widgetIdBase=n.syncContainer.parent().find(".id_base").val(),n.widgetNumber=n.syncContainer.parent().find(".widget_number").val(),n.customizeSettingId="widget_"+n.widgetIdBase+"["+String(n.widgetNumber)+"]",n.$el.addClass("custom-html-widget-fields"),n.$el.html(wp.template("widget-custom-html-control-fields")({codeEditorDisabled:s.codeEditorSettings.disabled})),n.errorNoticeContainer=n.$el.find(".code-editor-error-container"),n.currentErrorAnnotations=[],n.saveButton=n.syncContainer.add(n.syncContainer.parent().find(".widget-control-actions")).find(".widget-control-save, #savewidget"),n.saveButton.addClass("custom-html-widget-save-button"),n.fields={title:n.$el.find(".title"),content:n.$el.find(".content")},_.each(n.fields,function(t,i){t.on("input change",function(){var e=n.syncContainer.find(".sync-input."+i);e.val()!==t.val()&&(e.val(t.val()),e.trigger("change"))}),t.val(n.syncContainer.find(".sync-input."+i).val())})},updateFields:function(){var e,t=this;t.fields.title.is(document.activeElement)||(e=t.syncContainer.find(".sync-input.title"),t.fields.title.val(e.val())),t.contentUpdateBypassed=t.fields.content.is(document.activeElement)||t.editor&&t.editor.codemirror.state.focused||0!==t.currentErrorAnnotations.length,t.contentUpdateBypassed||(e=t.syncContainer.find(".sync-input.content"),t.fields.content.val(e.val()))},updateErrorNotice:function(e){var t,i=this,n="";1===e.length?n=s.l10n.errorNotice.singular.replace("%d","1"):1<e.length&&(n=s.l10n.errorNotice.plural.replace("%d",String(e.length))),i.fields.content[0].setCustomValidity&&i.fields.content[0].setCustomValidity(n),wp.customize&&wp.customize.has(i.customizeSettingId)?((t=wp.customize(i.customizeSettingId)).notifications.remove("htmlhint_error"),0!==e.length&&t.notifications.add("htmlhint_error",new wp.customize.Notification("htmlhint_error",{message:n,type:"error"}))):0!==e.length?((t=a('<div class="inline notice notice-error notice-alt" role="alert"></div>')).append(a("<p></p>",{text:n})),i.errorNoticeContainer.empty(),i.errorNoticeContainer.append(t),i.errorNoticeContainer.slideDown("fast"),wp.a11y.speak(n)):i.errorNoticeContainer.slideUp("fast")},initializeEditor:function(){var e,t=this;s.codeEditorSettings.disabled||(e=_.extend({},s.codeEditorSettings,{onTabPrevious:function(){t.fields.title.focus()},onTabNext:function(){t.syncContainer.add(t.syncContainer.parent().find(".widget-position, .widget-control-actions")).find(":tabbable").first().focus()},onChangeLintingErrors:function(e){t.currentErrorAnnotations=e},onUpdateErrorNotice:function(e){t.saveButton.toggleClass("validation-blocked disabled",0<e.length),t.updateErrorNotice(e)}}),t.editor=wp.codeEditor.initialize(t.fields.content,e),a(t.editor.codemirror.display.lineDiv).attr({role:"textbox","aria-multiline":"true","aria-labelledby":t.fields.content[0].id+"-label","aria-describedby":"editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"}),a("#"+t.fields.content[0].id+"-label").on("click",function(){t.editor.codemirror.focus()}),t.fields.content.on("change",function(){this.value!==t.editor.codemirror.getValue()&&t.editor.codemirror.setValue(this.value)}),t.editor.codemirror.on("change",function(){var e=t.editor.codemirror.getValue();e!==t.fields.content.val()&&t.fields.content.val(e).trigger("change")}),t.editor.codemirror.on("blur",function(){t.contentUpdateBypassed&&t.syncContainer.find(".sync-input.content").trigger("change")}),wp.customize&&t.editor.codemirror.on("keydown",function(e,t){27===t.keyCode&&t.stopPropagation()}))}}),s.widgetControls={},s.handleWidgetAdded=function(e,t){var i,n,o,d=t.find("> .widget-inside > .form, > .widget-inside > form"),r=d.find("> .id_base").val();-1===s.idBases.indexOf(r)||(r=d.find(".widget-id").val(),s.widgetControls[r])||(d=a("<div></div>"),(o=t.find(".widget-content:first")).before(d),i=new s.CustomHtmlWidgetControl({el:d,syncContainer:o}),s.widgetControls[r]=i,(n=function(){(wp.customize?t.parent().hasClass("expanded"):t.hasClass("open"))?i.initializeEditor():setTimeout(n,50)})())},s.setupAccessibleMode=function(){var e,t=a(".editwidget > form");0!==t.length&&(e=t.find(".id_base").val(),-1!==s.idBases.indexOf(e))&&(e=a("<div></div>"),(t=t.find("> .widget-inside")).before(e),new s.CustomHtmlWidgetControl({el:e,syncContainer:t}).initializeEditor())},s.handleWidgetUpdated=function(e,t){var t=t.find("> .widget-inside > .form, > .widget-inside > form"),i=t.find("> .id_base").val();-1!==s.idBases.indexOf(i)&&(i=t.find("> .widget-id").val(),t=s.widgetControls[i])Line truncated
|
||||
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* @output wp-admin/js/widgets/media-audio-widget.js
|
||||
*/
|
||||
|
||||
/* eslint consistent-this: [ "error", "control" ] */
|
||||
(function( component ) {
|
||||
'use strict';
|
||||
|
||||
var AudioWidgetModel, AudioWidgetControl, AudioDetailsMediaFrame;
|
||||
|
||||
/**
|
||||
* Custom audio details frame that removes the replace-audio state.
|
||||
*
|
||||
* @class wp.mediaWidgets.controlConstructors~AudioDetailsMediaFrame
|
||||
* @augments wp.media.view.MediaFrame.AudioDetails
|
||||
*/
|
||||
AudioDetailsMediaFrame = wp.media.view.MediaFrame.AudioDetails.extend(/** @lends wp.mediaWidgets.controlConstructors~AudioDetailsMediaFrame.prototype */{
|
||||
|
||||
/**
|
||||
* Create the default states.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
createStates: function createStates() {
|
||||
this.states.add([
|
||||
new wp.media.controller.AudioDetails({
|
||||
media: this.media
|
||||
}),
|
||||
|
||||
new wp.media.controller.MediaLibrary({
|
||||
type: 'audio',
|
||||
id: 'add-audio-source',
|
||||
title: wp.media.view.l10n.audioAddSourceTitle,
|
||||
toolbar: 'add-audio-source',
|
||||
media: this.media,
|
||||
menu: false
|
||||
})
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Audio widget model.
|
||||
*
|
||||
* See WP_Widget_Audio::enqueue_admin_scripts() for amending prototype from PHP exports.
|
||||
*
|
||||
* @class wp.mediaWidgets.modelConstructors.media_audio
|
||||
* @augments wp.mediaWidgets.MediaWidgetModel
|
||||
*/
|
||||
AudioWidgetModel = component.MediaWidgetModel.extend({});
|
||||
|
||||
/**
|
||||
* Audio widget control.
|
||||
*
|
||||
* See WP_Widget_Audio::enqueue_admin_scripts() for amending prototype from PHP exports.
|
||||
*
|
||||
* @class wp.mediaWidgets.controlConstructors.media_audio
|
||||
* @augments wp.mediaWidgets.MediaWidgetControl
|
||||
*/
|
||||
AudioWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_audio.prototype */{
|
||||
|
||||
/**
|
||||
* Show display settings.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
showDisplaySettings: false,
|
||||
|
||||
/**
|
||||
* Map model props to media frame props.
|
||||
*
|
||||
* @param {Object} modelProps - Model props.
|
||||
* @return {Object} Media frame props.
|
||||
*/
|
||||
mapModelToMediaFrameProps: function mapModelToMediaFrameProps( modelProps ) {
|
||||
var control = this, mediaFrameProps;
|
||||
mediaFrameProps = component.MediaWidgetControl.prototype.mapModelToMediaFrameProps.call( control, modelProps );
|
||||
mediaFrameProps.link = 'embed';
|
||||
return mediaFrameProps;
|
||||
},
|
||||
|
||||
/**
|
||||
* Render preview.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
renderPreview: function renderPreview() {
|
||||
var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl;
|
||||
attachmentId = control.model.get( 'attachment_id' );
|
||||
attachmentUrl = control.model.get( 'url' );
|
||||
|
||||
if ( ! attachmentId && ! attachmentUrl ) {
|
||||
return;
|
||||
}
|
||||
|
||||
previewContainer = control.$el.find( '.media-widget-preview' );
|
||||
previewTemplate = wp.template( 'wp-media-widget-audio-preview' );
|
||||
|
||||
previewContainer.html( previewTemplate({
|
||||
model: {
|
||||
attachment_id: control.model.get( 'attachment_id' ),
|
||||
src: attachmentUrl
|
||||
},
|
||||
error: control.model.get( 'error' )
|
||||
}));
|
||||
wp.mediaelement.initialize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Open the media audio-edit frame to modify the selected item.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
editMedia: function editMedia() {
|
||||
var control = this, mediaFrame, metadata, updateCallback;
|
||||
|
||||
metadata = control.mapModelToMediaFrameProps( control.model.toJSON() );
|
||||
|
||||
// Set up the media frame.
|
||||
mediaFrame = new AudioDetailsMediaFrame({
|
||||
frame: 'audio',
|
||||
state: 'audio-details',
|
||||
metadata: metadata
|
||||
});
|
||||
wp.media.frame = mediaFrame;
|
||||
mediaFrame.$el.addClass( 'media-widget' );
|
||||
|
||||
updateCallback = function( mediaFrameProps ) {
|
||||
|
||||
// Update cached attachment object to avoid having to re-fetch. This also triggers re-rendering of preview.
|
||||
control.selectedAttachment.set( mediaFrameProps );
|
||||
|
||||
control.model.set( _.extend(
|
||||
control.model.defaults(),
|
||||
control.mapMediaToModelProps( mediaFrameProps ),
|
||||
{ error: false }
|
||||
) );
|
||||
};
|
||||
|
||||
mediaFrame.state( 'audio-details' ).on( 'update', updateCallback );
|
||||
mediaFrame.state( 'replace-audio' ).on( 'replace', updateCallback );
|
||||
mediaFrame.on( 'close', function() {
|
||||
mediaFrame.detach();
|
||||
});
|
||||
|
||||
mediaFrame.open();
|
||||
}
|
||||
});
|
||||
|
||||
// Exports.
|
||||
component.controlConstructors.media_audio = AudioWidgetControl;
|
||||
component.modelConstructors.media_audio = AudioWidgetModel;
|
||||
|
||||
})( wp.mediaWidgets );
|
||||
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(t){"use strict";var a=wp.media.view.MediaFrame.AudioDetails.extend({createStates:function(){this.states.add([new wp.media.controller.AudioDetails({media:this.media}),new wp.media.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:wp.media.view.l10n.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),e=t.MediaWidgetModel.extend({}),d=t.MediaWidgetControl.extend({showDisplaySettings:!1,mapModelToMediaFrameProps:function(e){e=t.MediaWidgetControl.prototype.mapModelToMediaFrameProps.call(this,e);return e.link="embed",e},renderPreview:function(){var e,t=this,d=t.model.get("attachment_id"),a=t.model.get("url");(d||a)&&(d=t.$el.find(".media-widget-preview"),e=wp.template("wp-media-widget-audio-preview"),d.html(e({model:{attachment_id:t.model.get("attachment_id"),src:a},error:t.model.get("error")})),wp.mediaelement.initialize())},editMedia:function(){var t=this,e=t.mapModelToMediaFrameProps(t.model.toJSON()),d=new a({frame:"audio",state:"audio-details",metadata:e});(wp.media.frame=d).$el.addClass("media-widget"),e=function(e){t.selectedAttachment.set(e),t.model.set(_.extend(t.model.defaults(),t.mapMediaToModelProps(e),{error:!1}))},d.state("audio-details").on("update",e),d.state("replace-audio").on("replace",e),d.on("close",function(){d.detach()}),d.open()}});t.controlConstructors.media_audio=d,t.modelConstructors.media_audio=e}(wp.mediaWidgets);
|
||||
@@ -0,0 +1,341 @@
|
||||
/**
|
||||
* @output wp-admin/js/widgets/media-gallery-widget.js
|
||||
*/
|
||||
|
||||
/* eslint consistent-this: [ "error", "control" ] */
|
||||
(function( component ) {
|
||||
'use strict';
|
||||
|
||||
var GalleryWidgetModel, GalleryWidgetControl, GalleryDetailsMediaFrame;
|
||||
|
||||
/**
|
||||
* Custom gallery details frame.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @class wp.mediaWidgets~GalleryDetailsMediaFrame
|
||||
* @augments wp.media.view.MediaFrame.Post
|
||||
*/
|
||||
GalleryDetailsMediaFrame = wp.media.view.MediaFrame.Post.extend(/** @lends wp.mediaWidgets~GalleryDetailsMediaFrame.prototype */{
|
||||
|
||||
/**
|
||||
* Create the default states.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @return {void}
|
||||
*/
|
||||
createStates: function createStates() {
|
||||
this.states.add([
|
||||
new wp.media.controller.Library({
|
||||
id: 'gallery',
|
||||
title: wp.media.view.l10n.createGalleryTitle,
|
||||
priority: 40,
|
||||
toolbar: 'main-gallery',
|
||||
filterable: 'uploaded',
|
||||
multiple: 'add',
|
||||
editable: true,
|
||||
|
||||
library: wp.media.query( _.defaults({
|
||||
type: 'image'
|
||||
}, this.options.library ) )
|
||||
}),
|
||||
|
||||
// Gallery states.
|
||||
new wp.media.controller.GalleryEdit({
|
||||
library: this.options.selection,
|
||||
editing: this.options.editing,
|
||||
menu: 'gallery'
|
||||
}),
|
||||
|
||||
new wp.media.controller.GalleryAdd()
|
||||
]);
|
||||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* Gallery widget model.
|
||||
*
|
||||
* See WP_Widget_Gallery::enqueue_admin_scripts() for amending prototype from PHP exports.
|
||||
*
|
||||
* @since 4.9.0
|
||||
*
|
||||
* @class wp.mediaWidgets.modelConstructors.media_gallery
|
||||
* @augments wp.mediaWidgets.MediaWidgetModel
|
||||
*/
|
||||
GalleryWidgetModel = component.MediaWidgetModel.extend(/** @lends wp.mediaWidgets.modelConstructors.media_gallery.prototype */{} );
|
||||
|
||||
GalleryWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_gallery.prototype */{
|
||||
|
||||
/**
|
||||
* View events.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @type {object}
|
||||
*/
|
||||
events: _.extend( {}, component.MediaWidgetControl.prototype.events, {
|
||||
'click .media-widget-gallery-preview': 'editMedia'
|
||||
} ),
|
||||
|
||||
/**
|
||||
* Gallery widget control.
|
||||
*
|
||||
* See WP_Widget_Gallery::enqueue_admin_scripts() for amending prototype from PHP exports.
|
||||
*
|
||||
* @constructs wp.mediaWidgets.controlConstructors.media_gallery
|
||||
* @augments wp.mediaWidgets.MediaWidgetControl
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @param {Object} options - Options.
|
||||
* @param {Backbone.Model} options.model - Model.
|
||||
* @param {jQuery} options.el - Control field container element.
|
||||
* @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
|
||||
* @return {void}
|
||||
*/
|
||||
initialize: function initialize( options ) {
|
||||
var control = this;
|
||||
|
||||
component.MediaWidgetControl.prototype.initialize.call( control, options );
|
||||
|
||||
_.bindAll( control, 'updateSelectedAttachments', 'handleAttachmentDestroy' );
|
||||
control.selectedAttachments = new wp.media.model.Attachments();
|
||||
control.model.on( 'change:ids', control.updateSelectedAttachments );
|
||||
control.selectedAttachments.on( 'change', control.renderPreview );
|
||||
control.selectedAttachments.on( 'reset', control.renderPreview );
|
||||
control.updateSelectedAttachments();
|
||||
|
||||
/*
|
||||
* Refresh a Gallery widget partial when the user modifies one of the selected attachments.
|
||||
* This ensures that when an attachment's caption is updated in the media modal the Gallery
|
||||
* widget in the preview will then be refreshed to show the change. Normally doing this
|
||||
* would not be necessary because all of the state should be contained inside the changeset,
|
||||
* as everything done in the Customizer should not make a change to the site unless the
|
||||
* changeset itself is published. Attachments are a current exception to this rule.
|
||||
* For a proposal to include attachments in the customized state, see #37887.
|
||||
*/
|
||||
if ( wp.customize && wp.customize.previewer ) {
|
||||
control.selectedAttachments.on( 'change', function() {
|
||||
wp.customize.previewer.send( 'refresh-widget-partial', control.model.get( 'widget_id' ) );
|
||||
} );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the selected attachments if necessary.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @return {void}
|
||||
*/
|
||||
updateSelectedAttachments: function updateSelectedAttachments() {
|
||||
var control = this, newIds, oldIds, removedIds, addedIds, addedQuery;
|
||||
|
||||
newIds = control.model.get( 'ids' );
|
||||
oldIds = _.pluck( control.selectedAttachments.models, 'id' );
|
||||
|
||||
removedIds = _.difference( oldIds, newIds );
|
||||
_.each( removedIds, function( removedId ) {
|
||||
control.selectedAttachments.remove( control.selectedAttachments.get( removedId ) );
|
||||
});
|
||||
|
||||
addedIds = _.difference( newIds, oldIds );
|
||||
if ( addedIds.length ) {
|
||||
addedQuery = wp.media.query({
|
||||
order: 'ASC',
|
||||
orderby: 'post__in',
|
||||
perPage: -1,
|
||||
post__in: newIds,
|
||||
query: true,
|
||||
type: 'image'
|
||||
});
|
||||
addedQuery.more().done( function() {
|
||||
control.selectedAttachments.reset( addedQuery.models );
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Render preview.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @return {void}
|
||||
*/
|
||||
renderPreview: function renderPreview() {
|
||||
var control = this, previewContainer, previewTemplate, data;
|
||||
|
||||
previewContainer = control.$el.find( '.media-widget-preview' );
|
||||
previewTemplate = wp.template( 'wp-media-widget-gallery-preview' );
|
||||
|
||||
data = control.previewTemplateProps.toJSON();
|
||||
data.attachments = {};
|
||||
control.selectedAttachments.each( function( attachment ) {
|
||||
data.attachments[ attachment.id ] = attachment.toJSON();
|
||||
} );
|
||||
|
||||
previewContainer.html( previewTemplate( data ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine whether there are selected attachments.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @return {boolean} Selected.
|
||||
*/
|
||||
isSelected: function isSelected() {
|
||||
var control = this;
|
||||
|
||||
if ( control.model.get( 'error' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return control.model.get( 'ids' ).length > 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Open the media select frame to edit images.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @return {void}
|
||||
*/
|
||||
editMedia: function editMedia() {
|
||||
var control = this, selection, mediaFrame, mediaFrameProps;
|
||||
|
||||
selection = new wp.media.model.Selection( control.selectedAttachments.models, {
|
||||
multiple: true
|
||||
});
|
||||
|
||||
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
|
||||
selection.gallery = new Backbone.Model( mediaFrameProps );
|
||||
if ( mediaFrameProps.size ) {
|
||||
control.displaySettings.set( 'size', mediaFrameProps.size );
|
||||
}
|
||||
mediaFrame = new GalleryDetailsMediaFrame({
|
||||
frame: 'manage',
|
||||
text: control.l10n.add_to_widget,
|
||||
selection: selection,
|
||||
mimeType: control.mime_type,
|
||||
selectedDisplaySettings: control.displaySettings,
|
||||
showDisplaySettings: control.showDisplaySettings,
|
||||
metadata: mediaFrameProps,
|
||||
editing: true,
|
||||
multiple: true,
|
||||
state: 'gallery-edit'
|
||||
});
|
||||
wp.media.frame = mediaFrame; // See wp.media().
|
||||
|
||||
// Handle selection of a media item.
|
||||
mediaFrame.on( 'update', function onUpdate( newSelection ) {
|
||||
var state = mediaFrame.state(), resultSelection;
|
||||
|
||||
resultSelection = newSelection || state.get( 'selection' );
|
||||
if ( ! resultSelection ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy orderby_random from gallery state.
|
||||
if ( resultSelection.gallery ) {
|
||||
control.model.set( control.mapMediaToModelProps( resultSelection.gallery.toJSON() ) );
|
||||
}
|
||||
|
||||
// Directly update selectedAttachments to prevent needing to do additional request.
|
||||
control.selectedAttachments.reset( resultSelection.models );
|
||||
|
||||
// Update models in the widget instance.
|
||||
control.model.set( {
|
||||
ids: _.pluck( resultSelection.models, 'id' )
|
||||
} );
|
||||
} );
|
||||
|
||||
mediaFrame.$el.addClass( 'media-widget' );
|
||||
mediaFrame.open();
|
||||
|
||||
if ( selection ) {
|
||||
selection.on( 'destroy', control.handleAttachmentDestroy );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Open the media select frame to chose an item.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @return {void}
|
||||
*/
|
||||
selectMedia: function selectMedia() {
|
||||
var control = this, selection, mediaFrame, mediaFrameProps;
|
||||
selection = new wp.media.model.Selection( control.selectedAttachments.models, {
|
||||
multiple: true
|
||||
});
|
||||
|
||||
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
|
||||
if ( mediaFrameProps.size ) {
|
||||
control.displaySettings.set( 'size', mediaFrameProps.size );
|
||||
}
|
||||
mediaFrame = new GalleryDetailsMediaFrame({
|
||||
frame: 'select',
|
||||
text: control.l10n.add_to_widget,
|
||||
selection: selection,
|
||||
mimeType: control.mime_type,
|
||||
selectedDisplaySettings: control.displaySettings,
|
||||
showDisplaySettings: control.showDisplaySettings,
|
||||
metadata: mediaFrameProps,
|
||||
state: 'gallery'
|
||||
});
|
||||
wp.media.frame = mediaFrame; // See wp.media().
|
||||
|
||||
// Handle selection of a media item.
|
||||
mediaFrame.on( 'update', function onUpdate( newSelection ) {
|
||||
var state = mediaFrame.state(), resultSelection;
|
||||
|
||||
resultSelection = newSelection || state.get( 'selection' );
|
||||
if ( ! resultSelection ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy orderby_random from gallery state.
|
||||
if ( resultSelection.gallery ) {
|
||||
control.model.set( control.mapMediaToModelProps( resultSelection.gallery.toJSON() ) );
|
||||
}
|
||||
|
||||
// Directly update selectedAttachments to prevent needing to do additional request.
|
||||
control.selectedAttachments.reset( resultSelection.models );
|
||||
|
||||
// Update widget instance.
|
||||
control.model.set( {
|
||||
ids: _.pluck( resultSelection.models, 'id' )
|
||||
} );
|
||||
} );
|
||||
|
||||
mediaFrame.$el.addClass( 'media-widget' );
|
||||
mediaFrame.open();
|
||||
|
||||
if ( selection ) {
|
||||
selection.on( 'destroy', control.handleAttachmentDestroy );
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure focus is set inside of modal so that hitting Esc will close
|
||||
* the modal and not inadvertently cause the widget to collapse in the customizer.
|
||||
*/
|
||||
mediaFrame.$el.find( ':focusable:first' ).focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear the selected attachment when it is deleted in the media select frame.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @param {wp.media.models.Attachment} attachment - Attachment.
|
||||
* @return {void}
|
||||
*/
|
||||
handleAttachmentDestroy: function handleAttachmentDestroy( attachment ) {
|
||||
var control = this;
|
||||
control.model.set( {
|
||||
ids: _.difference(
|
||||
control.model.get( 'ids' ),
|
||||
[ attachment.id ]
|
||||
)
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
// Exports.
|
||||
component.controlConstructors.media_gallery = GalleryWidgetControl;
|
||||
component.modelConstructors.media_gallery = GalleryWidgetModel;
|
||||
|
||||
})( wp.mediaWidgets );
|
||||
@@ -0,0 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(i){"use strict";var a=wp.media.view.MediaFrame.Post.extend({createStates:function(){this.states.add([new wp.media.controller.Library({id:"gallery",title:wp.media.view.l10n.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!0,library:wp.media.query(_.defaults({type:"image"},this.options.library))}),new wp.media.controller.GalleryEdit({library:this.options.selection,editing:this.options.editing,menu:"gallery"}),new wp.media.controller.GalleryAdd])}}),e=i.MediaWidgetModel.extend({}),t=i.MediaWidgetControl.extend({events:_.extend({},i.MediaWidgetControl.prototype.events,{"click .media-widget-gallery-preview":"editMedia"}),initialize:function(e){var t=this;i.MediaWidgetControl.prototype.initialize.call(t,e),_.bindAll(t,"updateSelectedAttachments","handleAttachmentDestroy"),t.selectedAttachments=new wp.media.model.Attachments,t.model.on("change:ids",t.updateSelectedAttachments),t.selectedAttachments.on("change",t.renderPreview),t.selectedAttachments.on("reset",t.renderPreview),t.updateSelectedAttachments(),wp.customize&&wp.customize.previewer&&t.selectedAttachments.on("change",function(){wp.customize.previewer.send("refresh-widget-partial",t.model.get("widget_id"))})},updateSelectedAttachments:function(){var e,t=this,i=t.model.get("ids"),d=_.pluck(t.selectedAttachments.models,"id"),a=_.difference(d,i);_.each(a,function(e){t.selectedAttachments.remove(t.selectedAttachments.get(e))}),_.difference(i,d).length&&(e=wp.media.query({order:"ASC",orderby:"post__in",perPage:-1,post__in:i,query:!0,type:"image"})).more().done(function(){t.selectedAttachments.reset(e.models)})},renderPreview:function(){var e=this,t=e.$el.find(".media-widget-preview"),i=wp.template("wp-media-widget-gallery-preview"),d=e.previewTemplateProps.toJSON();d.attachments={},e.selectedAttachments.each(function(e){d.attachments[e.id]=e.toJSON()}),t.html(i(d))},isSelected:function(){return!this.model.get("error")&&0<this.model.get("ids").length},editMedia:function(){var i,d=this,e=new wp.media.model.Selection(d.selectedAttachments.models,{multiple:!0}),t=d.mapModelToMediaFrameProps(d.model.toJSON());e.gallery=new Backbone.Model(t),t.size&&d.displaySettings.set("size",t.size),i=new a({frame:"manage",text:d.l10n.add_to_widget,selection:e,mimeType:d.mime_type,selectedDisplaySettings:d.displaySettings,showDisplaySettings:d.showDisplaySettings,metadata:t,editing:!0,multiple:!0,state:"gallery-edit"}),(wp.media.frame=i).on("update",function(e){var t=i.state(),e=e||t.get("selection");e&&(e.gallery&&d.model.set(d.mapMediaToModelProps(e.gallery.toJSON())),d.selectedAttachments.reset(e.models),d.model.set({ids:_.pluck(e.models,"id")}))}),i.$el.addClass("media-widget"),i.open(),e&&e.on("destroy",d.handleAttachmentDestroy)},selectMedia:function(){var i,d=this,e=new wp.media.model.Selection(d.selectedAttachments.models,{multiple:!0}),t=d.mapModelToMediaFrameProps(d.model.toJSON());t.size&&d.displaySettings.set("size",t.size),i=new a({frame:"select",text:d.l10n.add_to_widget,selection:e,mimeType:d.mime_type,selectedDisplaySettings:d.displaySettings,showDisplaySettings:d.showDisplaySettings,metadata:t,state:"gallery"}),(wp.media.frame=i).on("update",function(e){var t=i.state(),e=e||t.get("selection");e&&(e.gallery&&d.model.set(d.mapMediaToModelProps(e.gallery.toJSON())),d.selectedAttachments.reset(e.models),d.model.set({ids:_.pluck(e.models,"id")}))}),i.$el.addClass("media-widget"),i.open(),e&&e.on("destroy",d.handleAttachmentDestroy),i.$el.find(":focusable:first").focus()},handleAttachmentDestroy:function(e){this.model.set({ids:_.difference(this.model.get("ids"),[e.id])})}});i.controlConstructors.media_gallery=t,i.modelConstructors.media_gallery=e}(wp.mediaWidgets);
|
||||
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* @output wp-admin/js/widgets/media-image-widget.js
|
||||
*/
|
||||
|
||||
/* eslint consistent-this: [ "error", "control" ] */
|
||||
(function( component, $ ) {
|
||||
'use strict';
|
||||
|
||||
var ImageWidgetModel, ImageWidgetControl;
|
||||
|
||||
/**
|
||||
* Image widget model.
|
||||
*
|
||||
* See WP_Widget_Media_Image::enqueue_admin_scripts() for amending prototype from PHP exports.
|
||||
*
|
||||
* @class wp.mediaWidgets.modelConstructors.media_image
|
||||
* @augments wp.mediaWidgets.MediaWidgetModel
|
||||
*/
|
||||
ImageWidgetModel = component.MediaWidgetModel.extend({});
|
||||
|
||||
/**
|
||||
* Image widget control.
|
||||
*
|
||||
* See WP_Widget_Media_Image::enqueue_admin_scripts() for amending prototype from PHP exports.
|
||||
*
|
||||
* @class wp.mediaWidgets.controlConstructors.media_audio
|
||||
* @augments wp.mediaWidgets.MediaWidgetControl
|
||||
*/
|
||||
ImageWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_image.prototype */{
|
||||
|
||||
/**
|
||||
* View events.
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
events: _.extend( {}, component.MediaWidgetControl.prototype.events, {
|
||||
'click .media-widget-preview.populated': 'editMedia'
|
||||
} ),
|
||||
|
||||
/**
|
||||
* Render preview.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
renderPreview: function renderPreview() {
|
||||
var control = this, previewContainer, previewTemplate, fieldsContainer, fieldsTemplate, linkInput;
|
||||
if ( ! control.model.get( 'attachment_id' ) && ! control.model.get( 'url' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
previewContainer = control.$el.find( '.media-widget-preview' );
|
||||
previewTemplate = wp.template( 'wp-media-widget-image-preview' );
|
||||
previewContainer.html( previewTemplate( control.previewTemplateProps.toJSON() ) );
|
||||
previewContainer.addClass( 'populated' );
|
||||
|
||||
linkInput = control.$el.find( '.link' );
|
||||
if ( ! linkInput.is( document.activeElement ) ) {
|
||||
fieldsContainer = control.$el.find( '.media-widget-fields' );
|
||||
fieldsTemplate = wp.template( 'wp-media-widget-image-fields' );
|
||||
fieldsContainer.html( fieldsTemplate( control.previewTemplateProps.toJSON() ) );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Open the media image-edit frame to modify the selected item.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
editMedia: function editMedia() {
|
||||
var control = this, mediaFrame, updateCallback, defaultSync, metadata;
|
||||
|
||||
metadata = control.mapModelToMediaFrameProps( control.model.toJSON() );
|
||||
|
||||
// Needed or else none will not be selected if linkUrl is not also empty.
|
||||
if ( 'none' === metadata.link ) {
|
||||
metadata.linkUrl = '';
|
||||
}
|
||||
|
||||
// Set up the media frame.
|
||||
mediaFrame = wp.media({
|
||||
frame: 'image',
|
||||
state: 'image-details',
|
||||
metadata: metadata
|
||||
});
|
||||
mediaFrame.$el.addClass( 'media-widget' );
|
||||
|
||||
updateCallback = function() {
|
||||
var mediaProps, linkType;
|
||||
|
||||
// Update cached attachment object to avoid having to re-fetch. This also triggers re-rendering of preview.
|
||||
mediaProps = mediaFrame.state().attributes.image.toJSON();
|
||||
linkType = mediaProps.link;
|
||||
mediaProps.link = mediaProps.linkUrl;
|
||||
control.selectedAttachment.set( mediaProps );
|
||||
control.displaySettings.set( 'link', linkType );
|
||||
|
||||
control.model.set( _.extend(
|
||||
control.mapMediaToModelProps( mediaProps ),
|
||||
{ error: false }
|
||||
) );
|
||||
};
|
||||
|
||||
mediaFrame.state( 'image-details' ).on( 'update', updateCallback );
|
||||
mediaFrame.state( 'replace-image' ).on( 'replace', updateCallback );
|
||||
|
||||
// Disable syncing of attachment changes back to server. See <https://core.trac.wordpress.org/ticket/40403>.
|
||||
defaultSync = wp.media.model.Attachment.prototype.sync;
|
||||
wp.media.model.Attachment.prototype.sync = function rejectedSync() {
|
||||
return $.Deferred().rejectWith( this ).promise();
|
||||
};
|
||||
mediaFrame.on( 'close', function onClose() {
|
||||
mediaFrame.detach();
|
||||
wp.media.model.Attachment.prototype.sync = defaultSync;
|
||||
});
|
||||
|
||||
mediaFrame.open();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get props which are merged on top of the model when an embed is chosen (as opposed to an attachment).
|
||||
*
|
||||
* @return {Object} Reset/override props.
|
||||
*/
|
||||
getEmbedResetProps: function getEmbedResetProps() {
|
||||
return _.extend(
|
||||
component.MediaWidgetControl.prototype.getEmbedResetProps.call( this ),
|
||||
{
|
||||
size: 'full',
|
||||
width: 0,
|
||||
height: 0
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the instance props from the media selection frame.
|
||||
*
|
||||
* Prevent the image_title attribute from being initially set when adding an image from the media library.
|
||||
*
|
||||
* @param {wp.media.view.MediaFrame.Select} mediaFrame - Select frame.
|
||||
* @return {Object} Props.
|
||||
*/
|
||||
getModelPropsFromMediaFrame: function getModelPropsFromMediaFrame( mediaFrame ) {
|
||||
var control = this;
|
||||
return _.omit(
|
||||
component.MediaWidgetControl.prototype.getModelPropsFromMediaFrame.call( control, mediaFrame ),
|
||||
'image_title'
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Map model props to preview template props.
|
||||
*
|
||||
* @return {Object} Preview template props.
|
||||
*/
|
||||
mapModelToPreviewTemplateProps: function mapModelToPreviewTemplateProps() {
|
||||
var control = this, previewTemplateProps, url;
|
||||
url = control.model.get( 'url' );
|
||||
previewTemplateProps = component.MediaWidgetControl.prototype.mapModelToPreviewTemplateProps.call( control );
|
||||
previewTemplateProps.currentFilename = url ? url.replace( /\?.*$/, '' ).replace( /^.+\//, '' ) : '';
|
||||
previewTemplateProps.link_url = control.model.get( 'link_url' );
|
||||
return previewTemplateProps;
|
||||
}
|
||||
});
|
||||
|
||||
// Exports.
|
||||
component.controlConstructors.media_image = ImageWidgetControl;
|
||||
component.modelConstructors.media_image = ImageWidgetModel;
|
||||
|
||||
})( wp.mediaWidgets, jQuery );
|
||||
Loaded 100 of 17470 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user