wip
This commit is contained in:
@@ -1615,6 +1615,7 @@
|
||||
} else {
|
||||
expand = function() {
|
||||
section._animateChangeExpanded( function() {
|
||||
backBtn.attr( 'tabindex', '0' );
|
||||
backBtn.trigger( 'focus' );
|
||||
content.css( 'top', '' );
|
||||
container.scrollTop( 0 );
|
||||
@@ -1660,7 +1661,7 @@
|
||||
}
|
||||
}
|
||||
section._animateChangeExpanded( function() {
|
||||
|
||||
backBtn.attr( 'tabindex', '-1' );
|
||||
sectionTitle.trigger( 'focus' );
|
||||
content.css( 'top', '' );
|
||||
|
||||
@@ -2714,6 +2715,7 @@
|
||||
} else {
|
||||
expand = function() {
|
||||
section._animateChangeExpanded( function() {
|
||||
backBtn.attr( 'tabindex', '0' );
|
||||
backBtn.trigger( 'focus' );
|
||||
content.css( 'top', '' );
|
||||
container.scrollTop( 0 );
|
||||
@@ -2744,7 +2746,7 @@
|
||||
}
|
||||
}
|
||||
section._animateChangeExpanded( function() {
|
||||
|
||||
backBtn.attr( 'tabindex', '-1' );
|
||||
sectionTitle.trigger( 'focus' );
|
||||
content.css( 'top', '' );
|
||||
|
||||
@@ -2964,6 +2966,7 @@
|
||||
} );
|
||||
} else {
|
||||
panel._animateChangeExpanded( function() {
|
||||
backBtn.attr( 'tabindex', '0' );
|
||||
backBtn.trigger( 'focus' );
|
||||
accordionSection.css( 'top', '' );
|
||||
container.scrollTop( 0 );
|
||||
@@ -4063,7 +4066,7 @@
|
||||
* @return {void}
|
||||
*/
|
||||
addNewPage: function () {
|
||||
var control = this, promise, toggle, container, input, title, select;
|
||||
var control = this, promise, toggle, container, input, inputError, title, select;
|
||||
|
||||
if ( 'dropdown-pages' !== control.params.type || ! control.params.allow_addition || ! api.Menus ) {
|
||||
return;
|
||||
@@ -4072,15 +4075,23 @@
|
||||
toggle = control.container.find( '.add-new-toggle' );
|
||||
container = control.container.find( '.new-content-item-wrapper' );
|
||||
input = control.container.find( '.create-item-input' );
|
||||
inputError = control.container.find('.create-item-error');
|
||||
title = input.val();
|
||||
select = control.container.find( 'select' );
|
||||
|
||||
if ( ! title ) {
|
||||
input.addClass( 'invalid' );
|
||||
container.addClass( 'form-invalid' );
|
||||
input.attr('aria-invalid', 'true');
|
||||
input.attr('aria-describedby', inputError.attr('id'));
|
||||
inputError.slideDown( 'fast' );
|
||||
wp.a11y.speak( inputError.text() );
|
||||
return;
|
||||
}
|
||||
|
||||
input.removeClass( 'invalid' );
|
||||
container.removeClass( 'form-invalid' );
|
||||
input.attr('aria-invalid', 'false');
|
||||
input.removeAttr('aria-describedby');
|
||||
inputError.hide();
|
||||
input.attr( 'disabled', 'disabled' );
|
||||
|
||||
// The menus functions add the page, publish when appropriate,
|
||||
@@ -4715,10 +4726,19 @@
|
||||
* @param {Object} attachment
|
||||
*/
|
||||
setImageFromAttachment: function( attachment ) {
|
||||
var control = this;
|
||||
this.params.attachment = attachment;
|
||||
|
||||
// Set the Customizer setting; the callback takes care of rendering.
|
||||
this.setting( attachment.id );
|
||||
|
||||
// Set focus to the first relevant button after the icon.
|
||||
_.defer( function() {
|
||||
var firstButton = control.container.find( '.actions .button' ).first();
|
||||
if ( firstButton.length ) {
|
||||
firstButton.focus();
|
||||
}
|
||||
} );
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4801,7 +4821,8 @@
|
||||
* @param {Object} attachment
|
||||
*/
|
||||
setImageFromAttachment: function( attachment ) {
|
||||
var sizes = [ 'site_icon-32', 'thumbnail', 'full' ], link,
|
||||
var control = this,
|
||||
sizes = [ 'site_icon-32', 'thumbnail', 'full' ], link,
|
||||
icon;
|
||||
|
||||
_.each( sizes, function( size ) {
|
||||
@@ -4822,6 +4843,14 @@
|
||||
// Update the icon in-browser.
|
||||
link = $( 'link[rel="icon"][sizes="32x32"]' );
|
||||
link.attr( 'href', icon.url );
|
||||
|
||||
// Set focus to the first relevant button after the icon.
|
||||
_.defer( function() {
|
||||
var firstButton = control.container.find( '.actions .button' ).first();
|
||||
if ( firstButton.length ) {
|
||||
firstButton.focus();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -667,6 +667,7 @@
|
||||
itemType = dataContainer.data( 'type' ),
|
||||
itemObject = dataContainer.data( 'object' ),
|
||||
itemTypeLabel = dataContainer.data( 'type_label' ),
|
||||
inputError = container.find('.create-item-error'),
|
||||
promise;
|
||||
|
||||
if ( ! this.currentMenuControl ) {
|
||||
@@ -677,13 +678,18 @@
|
||||
if ( 'post_type' !== itemType ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( '' === itemName.val().trim() ) {
|
||||
itemName.addClass( 'invalid' );
|
||||
itemName.focus();
|
||||
container.addClass( 'form-invalid' );
|
||||
itemName.attr('aria-invalid', 'true');
|
||||
itemName.attr('aria-describedby', inputError.attr('id'));
|
||||
inputError.slideDown( 'fast' );
|
||||
wp.a11y.speak( inputError.text() );
|
||||
return;
|
||||
} else {
|
||||
itemName.removeClass( 'invalid' );
|
||||
container.removeClass( 'form-invalid' );
|
||||
itemName.attr('aria-invalid', 'false');
|
||||
itemName.removeAttr('aria-describedby');
|
||||
inputError.hide();
|
||||
container.find( '.accordion-section-title' ).addClass( 'loading' );
|
||||
}
|
||||
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -1273,7 +1273,7 @@ window.wp = window.wp || {};
|
||||
|
||||
var $addMediaButton = $( '<button type="button" class="button insert-media add_media">' );
|
||||
|
||||
$addMediaButton.append( '<span class="wp-media-buttons-icon"></span>' );
|
||||
$addMediaButton.append( '<span class="wp-media-buttons-icon" aria-hidden="true"></span>' );
|
||||
$addMediaButton.append( document.createTextNode( ' ' + buttonText ) );
|
||||
$addMediaButton.data( 'editor', id );
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+20
-6
@@ -1406,14 +1406,25 @@
|
||||
|
||||
updateQuickSearchResults : function(input) {
|
||||
var panel, params,
|
||||
minSearchLength = 2,
|
||||
q = input.val();
|
||||
minSearchLength = 1,
|
||||
q = input.val(),
|
||||
pageSearchChecklist = $( '#page-search-checklist' );
|
||||
|
||||
/*
|
||||
* Minimum characters for a search. Also avoid a new Ajax search when
|
||||
* the pressed key (e.g. arrows) doesn't change the searched term.
|
||||
* Avoid a new Ajax search when the pressed key (e.g. arrows)
|
||||
* doesn't change the searched term.
|
||||
*/
|
||||
if ( q.length < minSearchLength || api.lastSearch == q ) {
|
||||
if ( api.lastSearch == q ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset results when search is less than or equal to
|
||||
* minimum characters for searched term.
|
||||
*/
|
||||
if ( q.length <= minSearchLength ) {
|
||||
pageSearchChecklist.empty();
|
||||
wp.a11y.speak( wp.i18n.__( 'Search results cleared' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1770,12 +1781,14 @@
|
||||
$item;
|
||||
|
||||
if( ! $items.length ) {
|
||||
let noResults = wp.i18n.__( 'No results found.' );
|
||||
const li = $( '<li>' );
|
||||
const p = $( '<p>', { text: wp.i18n.__( 'No results found.' ) } );
|
||||
const p = $( '<p>', { text: noResults } );
|
||||
li.append( p );
|
||||
$('.categorychecklist', panel).empty().append( li );
|
||||
$( '.spinner', panel ).removeClass( 'is-active' );
|
||||
wrapper.addClass( 'has-no-menu-item' );
|
||||
wp.a11y.speak( noResults, 'assertive' );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1802,6 +1815,7 @@
|
||||
});
|
||||
|
||||
$('.categorychecklist', panel).html( $items );
|
||||
wp.a11y.speak( wp.i18n.sprintf( wp.i18n.__( '%d Search Results Found' ), $items.length ), 'assertive' );
|
||||
$( '.spinner', panel ).removeClass( 'is-active' );
|
||||
wrapper.removeClass( 'has-no-menu-item' );
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+40
-7
@@ -31,6 +31,12 @@ jQuery( function($) {
|
||||
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.
|
||||
@@ -40,8 +46,20 @@ jQuery( function($) {
|
||||
* @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(); });
|
||||
|
||||
/**
|
||||
@@ -53,23 +71,38 @@ jQuery( function($) {
|
||||
*/
|
||||
$('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 ) {
|
||||
$('#ajax-response').empty().append('<div class="notice notice-error"><p>' + wp.i18n.__( 'Sorry, you are not allowed to do that.' ) + '</p></div>');
|
||||
tr.children().css('backgroundColor', '');
|
||||
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 {
|
||||
$('#ajax-response').empty().append('<div class="notice notice-error"><p>' + wp.i18n.__( 'An error occurred while processing your request. Please try again later.' ) + '</p></div>');
|
||||
tr.children().css('backgroundColor', '');
|
||||
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' );
|
||||
});
|
||||
|
||||
tr.children().css('backgroundColor', '#f33');
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
jQuery(function(o){var s=!1;o("#the-list").on("click",".delete-tag",function(){var t,e=o(this),n=e.parents("tr"),r=!0;return(r="undefined"!=showNotice?showNotice.warn():r)&&(t=e.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag"),o.post(ajaxurl,t,function(e){"1"==e?(o("#ajax-response").empty(),n.fadeOut("normal",function(){n.remove()}),o('select#parent option[value="'+t.match(/tag_ID=(\d+)/)[1]+'"]').remove(),o("a.tag-link-"+t.match(/tag_ID=(\d+)/)[1]).remove()):("-1"==e?o("#ajax-response").empty().append('<div class="notice notice-error"><p>'+wp.i18n.__("Sorry, you are not allowed to do that.")+"</p></div>"):o("#ajax-response").empty().append('<div class="notice notice-error"><p>'+wp.i18n.__("An error occurred while processing your request. Please try again later.")+"</p></div>"),n.children().css("backgroundColor",""))}),n.children().css("backgroundColor","#f33")),!1}),o("#edittag").on("click",".delete",function(e){if("undefined"==typeof showNotice)return!0;showNotice.warn()||e.preventDefault()}),o("#submit").on("click",function(){var a=o(this).parents("form");return s||(s=!0,a.find(".submit .spinner").addClass("is-active"),o.post(ajaxurl,o("#addtag").serialize(),function(e){var t,n,r;if(s=!1,a.find(".submit .spinner").removeClass("is-active"),o("#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<o("#tag-"+e).length?o(".tags #tag-"+e).after(t.responses[0].supplemental.noparents):o(".tags").prepend(t.responses[0].supplemental.parents),o(".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>")}o('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible',a).val("")}})),!1})});
|
||||
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})});
|
||||
+12
-1
@@ -1011,6 +1011,12 @@ themes.view.Preview = themes.view.Details.extend({
|
||||
this.undelegateEvents();
|
||||
this.close();
|
||||
}
|
||||
|
||||
// Return if Ctrl + Shift or Shift key pressed
|
||||
if ( event.shiftKey || ( event.ctrlKey && event.shiftKey ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The right arrow key, next theme.
|
||||
if ( event.keyCode === 39 ) {
|
||||
_.once( this.nextTheme() );
|
||||
@@ -1115,6 +1121,11 @@ themes.view.Themes = wp.Backbone.View.extend({
|
||||
return;
|
||||
}
|
||||
|
||||
// Return if Ctrl + Shift or Shift key pressed
|
||||
if ( event.shiftKey || ( event.ctrlKey && event.shiftKey ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pressing the right arrow key fires a theme:next event.
|
||||
if ( event.keyCode === 39 ) {
|
||||
self.overlay.nextTheme();
|
||||
@@ -1210,7 +1221,7 @@ themes.view.Themes = wp.Backbone.View.extend({
|
||||
|
||||
// 'Add new theme' element shown at the end of the grid.
|
||||
if ( ! themes.isInstall && themes.data.settings.canInstall ) {
|
||||
this.$el.append( '<div class="theme add-new-theme"><a href="' + themes.data.settings.installURI + '"><div class="theme-screenshot"><span></span></div><h2 class="theme-name">' + l10n.addNew + '</h2></a></div>' );
|
||||
this.$el.append( '<div class="theme add-new-theme"><a href="' + themes.data.settings.installURI + '"><div class="theme-screenshot"><span aria-hidden="true"></span></div><h2 class="theme-name">' + l10n.addNew + '</h2></a></div>' );
|
||||
}
|
||||
|
||||
this.parent.page++;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -965,7 +965,7 @@
|
||||
wp.a11y.speak( __( 'Plugin dependencies check completed successfully.' ) );
|
||||
$document.trigger( 'wp-check-plugin-dependencies-success', response );
|
||||
|
||||
if ( 'plugins-network' === pagenow ) {
|
||||
if ( 'plugins-network' === pagenow || 'plugin-install-network' === pagenow ) {
|
||||
buttonText = _x( 'Network Activate', 'plugin' );
|
||||
ariaLabel = sprintf(
|
||||
/* translators: %s: Plugin name. */
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -20,7 +20,11 @@
|
||||
$form,
|
||||
originalFormContent,
|
||||
$passwordWrapper,
|
||||
successTimeout;
|
||||
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' ) {
|
||||
@@ -56,8 +60,8 @@
|
||||
// Once zxcvbn loads, passwords strength is known.
|
||||
$( '#pw-weak-text-label' ).text( __( 'Confirm use of weak password' ) );
|
||||
|
||||
// Focus the password field.
|
||||
if ( 'mailserver_pass' !== $pass1.prop('id' ) ) {
|
||||
// Focus the password field if not the install screen.
|
||||
if ( 'mailserver_pass' !== $pass1.prop('id' ) && ! $('#weblog_title').length ) {
|
||||
$( $pass1 ).trigger( 'focus' );
|
||||
}
|
||||
}
|
||||
@@ -80,6 +84,8 @@
|
||||
$pass1.removeClass( 'short bad good strong' );
|
||||
showOrHideWeakPasswordCheckbox();
|
||||
} );
|
||||
|
||||
bindCapsLockWarning( $pass1 );
|
||||
}
|
||||
|
||||
function resetToggle( show ) {
|
||||
@@ -101,6 +107,8 @@
|
||||
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' );
|
||||
@@ -110,6 +118,14 @@
|
||||
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 );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,6 +219,8 @@
|
||||
} else {
|
||||
// Password field for the login form.
|
||||
$pass1 = $( '#user_pass' );
|
||||
|
||||
bindCapsLockWarning( $pass1 );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -322,6 +340,79 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user