Enqueue selectWoo

This commit is contained in:
claudiulodro 2017-06-26 11:50:08 -07:00
parent 1fb11d0be7
commit ee9c762bdc
14 changed files with 336 additions and 234 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,7 @@
padding: 6px;
user-select: none;
-webkit-user-select: none; }
.select2-results__option[aria-selected] {
.select2-results__option[data-selected] {
cursor: pointer; }
.select2-container--open .select2-dropdown {
@ -264,7 +264,7 @@
.select2-container--default .select2-results__option[aria-disabled=true] {
color: #999; }
.select2-container--default .select2-results__option[aria-selected=true] {
.select2-container--default .select2-results__option[data-selected=true] {
background-color: #ddd; }
.select2-container--default .select2-results__option .select2-results__option {
@ -287,7 +287,7 @@
margin-left: -5em;
padding-left: 6em; }
.select2-container--default .select2-results__option--highlighted[aria-selected] {
.select2-container--default .select2-results__option--highlighted[data-selected] {
background-color: #0073aa;
color: white; }
@ -463,7 +463,7 @@
.select2-container--classic .select2-results__option[aria-disabled=true] {
color: grey; }
.select2-container--classic .select2-results__option--highlighted[aria-selected] {
.select2-container--classic .select2-results__option--highlighted[data-selected] {
background-color: #3875d7;
color: white; }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,27 +1,41 @@
/*!
* Select2 4.0.3
* https://select2.github.io
* SelectWoo 5.0.0
* https://github.com/woocommerce/selectWoo
*
* Released under the MIT license
* https://github.com/select2/select2/blob/master/LICENSE.md
* https://github.com/woocommerce/selectWoo/blob/master/LICENSE.md
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
factory(require('jquery'));
module.exports = function (root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function (jQuery) {
} (function (jQuery) {
// This is needed so we can catch the AMD loader configuration and use it
// The inner file should be wrapped (by `banner.start.js`) in a function that
// returns the AMD loader references.
var S2 =
(function () {
var S2 =(function () {
// Restore the Select2 AMD loader so it can be used
// Needed mostly in the language files, where the loader is not inserted
if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
@ -30,13 +44,11 @@
var S2;(function () { if (!S2 || !S2.requirejs) {
if (!S2) { S2 = {}; } else { require = S2; }
/**
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
* @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
* Released under MIT license, http://github.com/requirejs/almond/LICENSE
*/
//Going sloppy to avoid 'use strict' string cost, but strict practices should
//be followed.
/*jslint sloppy: true */
/*global setTimeout: false */
var requirejs, require, define;
@ -64,60 +76,58 @@ var requirejs, require, define;
*/
function normalize(name, baseName) {
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
foundI, foundStarMap, starI, i, j, part,
foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
baseParts = baseName && baseName.split("/"),
map = config.map,
starMap = (map && map['*']) || {};
//Adjust any relative paths.
if (name && name.charAt(0) === ".") {
//If have a base name, try to normalize against it,
//otherwise, assume it is a top-level require that will
//be relative to baseUrl in the end.
if (baseName) {
name = name.split('/');
lastIndex = name.length - 1;
if (name) {
name = name.split('/');
lastIndex = name.length - 1;
// Node .js allowance:
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
// If wanting node ID compatibility, strip .js from end
// of IDs. Have to do this here, and not in nameToUrl
// because node allows either .js or non .js to map
// to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
//Lop off the last part of baseParts, so that . matches the
//"directory" and not name of the baseName's module. For instance,
//baseName of "one/two/three", maps to "one/two/three.js", but we
//want the directory, "one/two" for this normalization.
name = baseParts.slice(0, baseParts.length - 1).concat(name);
// Starts with a '.' so need the baseName
if (name[0].charAt(0) === '.' && baseParts) {
//Convert baseName to array, and lop off the last part,
//so that . matches that 'directory' and not name of the baseName's
//module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
name = normalizedBaseParts.concat(name);
}
//start trimDots
for (i = 0; i < name.length; i += 1) {
part = name[i];
if (part === ".") {
name.splice(i, 1);
i -= 1;
} else if (part === "..") {
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
//End of the line. Keep at least one non-dot
//path segment at the front so it can be mapped
//correctly to disk. Otherwise, there is likely
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
break;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
//start trimDots
for (i = 0; i < name.length; i++) {
part = name[i];
if (part === '.') {
name.splice(i, 1);
i -= 1;
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
continue;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
}
//end trimDots
name = name.join("/");
} else if (name.indexOf('./') === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
}
//end trimDots
name = name.join('/');
}
//Apply map config if available.
@ -230,32 +240,39 @@ var requirejs, require, define;
return [prefix, name];
}
//Creates a parts array for a relName where first part is plugin ID,
//second part is resource ID. Assumes relName has already been normalized.
function makeRelParts(relName) {
return relName ? splitPrefix(relName) : [];
}
/**
* Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin
* too, as an optimization.
*/
makeMap = function (name, relName) {
makeMap = function (name, relParts) {
var plugin,
parts = splitPrefix(name),
prefix = parts[0];
prefix = parts[0],
relResourceName = relParts[1];
name = parts[1];
if (prefix) {
prefix = normalize(prefix, relName);
prefix = normalize(prefix, relResourceName);
plugin = callDep(prefix);
}
//Normalize according
if (prefix) {
if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName));
name = plugin.normalize(name, makeNormalize(relResourceName));
} else {
name = normalize(name, relName);
name = normalize(name, relResourceName);
}
} else {
name = normalize(name, relName);
name = normalize(name, relResourceName);
parts = splitPrefix(name);
prefix = parts[0];
name = parts[1];
@ -302,13 +319,14 @@ var requirejs, require, define;
};
main = function (name, deps, callback, relName) {
var cjsModule, depName, ret, map, i,
var cjsModule, depName, ret, map, i, relParts,
args = [],
callbackType = typeof callback,
usingExports;
//Use name if no relName
relName = relName || name;
relParts = makeRelParts(relName);
//Call the callback to define the module, if necessary.
if (callbackType === 'undefined' || callbackType === 'function') {
@ -317,7 +335,7 @@ var requirejs, require, define;
//Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName);
map = makeMap(deps[i], relParts);
depName = map.f;
//Fast path CommonJS standard dependencies.
@ -373,7 +391,7 @@ var requirejs, require, define;
//deps arg is the module name, and second arg (if passed)
//is just the relName.
//Normalize module name, if it contains . or ..
return callDep(makeMap(deps, callback).f);
return callDep(makeMap(deps, makeRelParts(callback)).f);
} else if (!deps.splice) {
//deps is a config object, not an array.
config = deps;
@ -773,7 +791,7 @@ S2.define('select2/results',[
Results.prototype.render = function () {
var $results = $(
'<ul class="select2-results__options" role="tree"></ul>'
'<ul class="select2-results__options" role="listbox"></ul>'
);
if (this.options.get('multiple')) {
@ -796,7 +814,7 @@ S2.define('select2/results',[
this.hideLoading();
var $message = $(
'<li role="treeitem" aria-live="assertive"' +
'<li role="alert" aria-live="assertive"' +
' class="select2-results__option"></li>'
);
@ -858,9 +876,9 @@ S2.define('select2/results',[
Results.prototype.highlightFirstItem = function () {
var $options = this.$results
.find('.select2-results__option[aria-selected]');
.find('.select2-results__option[data-selected]');
var $selected = $options.filter('[aria-selected=true]');
var $selected = $options.filter('[data-selected=true]');
// Check if there are any selected options
if ($selected.length > 0) {
@ -884,7 +902,7 @@ S2.define('select2/results',[
});
var $options = self.$results
.find('.select2-results__option[aria-selected]');
.find('.select2-results__option[data-selected]');
$options.each(function () {
var $option = $(this);
@ -896,9 +914,9 @@ S2.define('select2/results',[
if ((item.element != null && item.element.selected) ||
(item.element == null && $.inArray(id, selectedIds) > -1)) {
$option.attr('aria-selected', 'true');
$option.attr('data-selected', 'true');
} else {
$option.attr('aria-selected', 'false');
$option.attr('data-selected', 'false');
}
});
@ -930,17 +948,17 @@ S2.define('select2/results',[
option.className = 'select2-results__option';
var attrs = {
'role': 'treeitem',
'aria-selected': 'false'
'role': 'option',
'data-selected': 'false'
};
if (data.disabled) {
delete attrs['aria-selected'];
delete attrs['data-selected'];
attrs['aria-disabled'] = 'true';
}
if (data.id == null) {
delete attrs['aria-selected'];
delete attrs['data-selected'];
}
if (data._resultId != null) {
@ -952,9 +970,8 @@ S2.define('select2/results',[
}
if (data.children) {
attrs.role = 'group';
attrs['aria-label'] = data.text;
delete attrs['aria-selected'];
delete attrs['data-selected'];
}
for (var attr in attrs) {
@ -1082,7 +1099,7 @@ S2.define('select2/results',[
var data = $highlighted.data('data');
if ($highlighted.attr('aria-selected') == 'true') {
if ($highlighted.attr('data-selected') == 'true') {
self.trigger('close', {});
} else {
self.trigger('select', {
@ -1094,7 +1111,7 @@ S2.define('select2/results',[
container.on('results:previous', function () {
var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]');
var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted);
@ -1128,7 +1145,7 @@ S2.define('select2/results',[
container.on('results:next', function () {
var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]');
var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted);
@ -1156,7 +1173,8 @@ S2.define('select2/results',[
});
container.on('results:focus', function (params) {
params.element.addClass('select2-results__option--highlighted');
params.element.addClass('select2-results__option--highlighted').attr('aria-selected', 'true');
self.$results.attr('aria-activedescendant', params.element.attr('id'));
});
container.on('results:message', function (params) {
@ -1188,13 +1206,13 @@ S2.define('select2/results',[
});
}
this.$results.on('mouseup', '.select2-results__option[aria-selected]',
this.$results.on('mouseup', '.select2-results__option[data-selected]',
function (evt) {
var $this = $(this);
var data = $this.data('data');
if ($this.attr('aria-selected') === 'true') {
if ($this.attr('data-selected') === 'true') {
if (self.options.get('multiple')) {
self.trigger('unselect', {
originalEvent: evt,
@ -1213,12 +1231,13 @@ S2.define('select2/results',[
});
});
this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
this.$results.on('mouseenter', '.select2-results__option[data-selected]',
function (evt) {
var data = $(this).data('data');
self.getHighlightedResults()
.removeClass('select2-results__option--highlighted');
.removeClass('select2-results__option--highlighted')
.attr('aria-selected', 'false');
self.trigger('results:focus', {
data: data,
@ -1245,7 +1264,7 @@ S2.define('select2/results',[
return;
}
var $options = this.$results.find('[aria-selected]');
var $options = this.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted);
@ -1349,6 +1368,7 @@ S2.define('select2/selection/base',[
var id = container.id + '-container';
var resultsId = container.id + '-results';
var searchHidden = this.options.get('minimumResultsForSearch') === Infinity;
this.container = container;
@ -1369,7 +1389,9 @@ S2.define('select2/selection/base',[
});
container.on('results:focus', function (params) {
self.$selection.attr('aria-activedescendant', params.data._resultId);
if (searchHidden) {
self.$selection.attr('aria-activedescendant', params.data._resultId);
}
});
container.on('selection:update', function (params) {
@ -1379,7 +1401,9 @@ S2.define('select2/selection/base',[
container.on('open', function () {
// When the dropdown is open, aria-expanded="true"
self.$selection.attr('aria-expanded', 'true');
self.$selection.attr('aria-owns', resultsId);
if (searchHidden) {
self.$selection.attr('aria-owns', resultsId);
}
self._attachCloseHandler(container);
});
@ -1390,7 +1414,11 @@ S2.define('select2/selection/base',[
self.$selection.removeAttr('aria-activedescendant');
self.$selection.removeAttr('aria-owns');
self.$selection.focus();
// This needs to be delayed as the active element is the body when the
// key is pressed.
window.setTimeout(function () {
self.$selection.focus();
}, 1);
self._detachCloseHandler(container);
});
@ -1500,7 +1528,10 @@ S2.define('select2/selection/single',[
var id = container.id + '-container';
this.$selection.find('.select2-selection__rendered').attr('id', id);
this.$selection.find('.select2-selection__rendered')
.attr('id', id)
.attr('role', 'textbox')
.attr('aria-readonly', 'true');
this.$selection.attr('aria-labelledby', id);
this.$selection.on('mousedown', function (evt) {
@ -1518,6 +1549,13 @@ S2.define('select2/selection/single',[
// User focuses on the container
});
this.$selection.on('keydown', function (evt) {
// If user starts typing an alphanumeric key on the keyboard, open if not opened.
if (!container.isOpen() && evt.which >= 48 && evt.which <= 90) {
container.open();
}
});
this.$selection.on('blur', function (evt) {
// User exits the container
});
@ -1854,16 +1892,19 @@ S2.define('select2/selection/search',[
Search.prototype.bind = function (decorated, container, $container) {
var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container);
container.on('open', function () {
self.$search.attr('aria-owns', resultsId);
self.$search.trigger('focus');
});
container.on('close', function () {
self.$search.val('');
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.trigger('focus');
});
@ -1882,7 +1923,7 @@ S2.define('select2/selection/search',[
});
container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.id);
self.$search.attr('aria-activedescendant', params.data._resultId);
});
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
@ -3191,7 +3232,7 @@ S2.define('select2/data/select',[
}
}
if (data.id) {
if (data.id !== undefined) {
option.value = data.id;
}
@ -3550,7 +3591,10 @@ S2.define('select2/data/tags',[
}, true)
);
var checkText = option.text === params.term;
var optionText = (option.text || '').toUpperCase();
var paramsTerm = (params.term || '').toUpperCase();
var checkText = optionText === paramsTerm;
if (checkText || checkChildren) {
if (child) {
@ -3887,9 +3931,9 @@ S2.define('select2/dropdown/search',[
var $search = $(
'<span class="select2-search select2-search--dropdown">' +
'<input class="select2-search__field" type="search" tabindex="-1"' +
'<input class="select2-search__field" type="text" tabindex="-1"' +
' autocomplete="off" autocorrect="off" autocapitalize="off"' +
' spellcheck="false" role="textbox" />' +
' spellcheck="false" role="combobox" aria-autocomplete="list" />' +
'</span>'
);
@ -3903,6 +3947,7 @@ S2.define('select2/dropdown/search',[
Search.prototype.bind = function (decorated, container, $container) {
var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container);
@ -3926,7 +3971,7 @@ S2.define('select2/dropdown/search',[
container.on('open', function () {
self.$search.attr('tabindex', 0);
self.$search.attr('aria-owns', resultsId);
self.$search.focus();
window.setTimeout(function () {
@ -3936,7 +3981,8 @@ S2.define('select2/dropdown/search',[
container.on('close', function () {
self.$search.attr('tabindex', -1);
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.val('');
});
@ -3957,6 +4003,10 @@ S2.define('select2/dropdown/search',[
}
}
});
container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.data._resultId);
});
};
Search.prototype.handleSearch = function (evt) {
@ -4098,7 +4148,7 @@ S2.define('select2/dropdown/infiniteScroll',[
var $option = $(
'<li ' +
'class="select2-results__option select2-results__option--load-more"' +
'role="treeitem" aria-disabled="true"></li>'
'role="option" aria-disabled="true"></li>'
);
var message = this.options.get('translations').get('loadingMore');
@ -6364,11 +6414,11 @@ S2.define('jquery.select2',[
'./select2/core',
'./select2/defaults'
], function ($, _, Select2, Defaults) {
if ($.fn.select2 == null) {
if ($.fn.selectWoo == null) {
// All methods that should return the element
var thisMethods = ['open', 'close', 'destroy'];
$.fn.select2 = function (options) {
$.fn.selectWoo = function (options) {
options = options || {};
if (typeof options === 'object') {
@ -6408,10 +6458,17 @@ S2.define('jquery.select2',[
};
}
if ($.fn.select2.defaults == null) {
$.fn.select2.defaults = Defaults;
if ($.fn.select2 != null && $.fn.select2.defaults != null) {
$.fn.selectWoo.defaults = $.fn.select2.defaults;
}
if ($.fn.selectWoo.defaults == null) {
$.fn.selectWoo.defaults = Defaults;
}
// Also register selectWoo under select2 if select2 is not already present.
$.fn.select2 = $.fn.select2 || $.fn.selectWoo;
return Select2;
});
@ -6430,6 +6487,7 @@ S2.define('jquery.select2',[
// This allows Select2 to use the internal loader outside of this file, such
// as in the language files.
jQuery.fn.select2.amd = S2;
jQuery.fn.selectWoo.amd = S2;
// Return the Select2 instance for anyone who is importing it.
return select2;

File diff suppressed because one or more lines are too long

View File

@ -1,27 +1,41 @@
/*!
* Select2 4.0.3
* https://select2.github.io
* SelectWoo 5.0.0
* https://github.com/woocommerce/selectWoo
*
* Released under the MIT license
* https://github.com/select2/select2/blob/master/LICENSE.md
* https://github.com/woocommerce/selectWoo/blob/master/LICENSE.md
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
factory(require('jquery'));
module.exports = function (root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function (jQuery) {
} (function (jQuery) {
// This is needed so we can catch the AMD loader configuration and use it
// The inner file should be wrapped (by `banner.start.js`) in a function that
// returns the AMD loader references.
var S2 =
(function () {
var S2 =(function () {
// Restore the Select2 AMD loader so it can be used
// Needed mostly in the language files, where the loader is not inserted
if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
@ -30,13 +44,11 @@
var S2;(function () { if (!S2 || !S2.requirejs) {
if (!S2) { S2 = {}; } else { require = S2; }
/**
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
* @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
* Released under MIT license, http://github.com/requirejs/almond/LICENSE
*/
//Going sloppy to avoid 'use strict' string cost, but strict practices should
//be followed.
/*jslint sloppy: true */
/*global setTimeout: false */
var requirejs, require, define;
@ -64,60 +76,58 @@ var requirejs, require, define;
*/
function normalize(name, baseName) {
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
foundI, foundStarMap, starI, i, j, part,
foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
baseParts = baseName && baseName.split("/"),
map = config.map,
starMap = (map && map['*']) || {};
//Adjust any relative paths.
if (name && name.charAt(0) === ".") {
//If have a base name, try to normalize against it,
//otherwise, assume it is a top-level require that will
//be relative to baseUrl in the end.
if (baseName) {
name = name.split('/');
lastIndex = name.length - 1;
if (name) {
name = name.split('/');
lastIndex = name.length - 1;
// Node .js allowance:
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
// If wanting node ID compatibility, strip .js from end
// of IDs. Have to do this here, and not in nameToUrl
// because node allows either .js or non .js to map
// to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
//Lop off the last part of baseParts, so that . matches the
//"directory" and not name of the baseName's module. For instance,
//baseName of "one/two/three", maps to "one/two/three.js", but we
//want the directory, "one/two" for this normalization.
name = baseParts.slice(0, baseParts.length - 1).concat(name);
// Starts with a '.' so need the baseName
if (name[0].charAt(0) === '.' && baseParts) {
//Convert baseName to array, and lop off the last part,
//so that . matches that 'directory' and not name of the baseName's
//module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
name = normalizedBaseParts.concat(name);
}
//start trimDots
for (i = 0; i < name.length; i += 1) {
part = name[i];
if (part === ".") {
name.splice(i, 1);
i -= 1;
} else if (part === "..") {
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
//End of the line. Keep at least one non-dot
//path segment at the front so it can be mapped
//correctly to disk. Otherwise, there is likely
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
break;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
//start trimDots
for (i = 0; i < name.length; i++) {
part = name[i];
if (part === '.') {
name.splice(i, 1);
i -= 1;
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
continue;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
}
//end trimDots
name = name.join("/");
} else if (name.indexOf('./') === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
}
//end trimDots
name = name.join('/');
}
//Apply map config if available.
@ -230,32 +240,39 @@ var requirejs, require, define;
return [prefix, name];
}
//Creates a parts array for a relName where first part is plugin ID,
//second part is resource ID. Assumes relName has already been normalized.
function makeRelParts(relName) {
return relName ? splitPrefix(relName) : [];
}
/**
* Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin
* too, as an optimization.
*/
makeMap = function (name, relName) {
makeMap = function (name, relParts) {
var plugin,
parts = splitPrefix(name),
prefix = parts[0];
prefix = parts[0],
relResourceName = relParts[1];
name = parts[1];
if (prefix) {
prefix = normalize(prefix, relName);
prefix = normalize(prefix, relResourceName);
plugin = callDep(prefix);
}
//Normalize according
if (prefix) {
if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName));
name = plugin.normalize(name, makeNormalize(relResourceName));
} else {
name = normalize(name, relName);
name = normalize(name, relResourceName);
}
} else {
name = normalize(name, relName);
name = normalize(name, relResourceName);
parts = splitPrefix(name);
prefix = parts[0];
name = parts[1];
@ -302,13 +319,14 @@ var requirejs, require, define;
};
main = function (name, deps, callback, relName) {
var cjsModule, depName, ret, map, i,
var cjsModule, depName, ret, map, i, relParts,
args = [],
callbackType = typeof callback,
usingExports;
//Use name if no relName
relName = relName || name;
relParts = makeRelParts(relName);
//Call the callback to define the module, if necessary.
if (callbackType === 'undefined' || callbackType === 'function') {
@ -317,7 +335,7 @@ var requirejs, require, define;
//Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName);
map = makeMap(deps[i], relParts);
depName = map.f;
//Fast path CommonJS standard dependencies.
@ -373,7 +391,7 @@ var requirejs, require, define;
//deps arg is the module name, and second arg (if passed)
//is just the relName.
//Normalize module name, if it contains . or ..
return callDep(makeMap(deps, callback).f);
return callDep(makeMap(deps, makeRelParts(callback)).f);
} else if (!deps.splice) {
//deps is a config object, not an array.
config = deps;
@ -773,7 +791,7 @@ S2.define('select2/results',[
Results.prototype.render = function () {
var $results = $(
'<ul class="select2-results__options" role="tree"></ul>'
'<ul class="select2-results__options" role="listbox"></ul>'
);
if (this.options.get('multiple')) {
@ -796,7 +814,7 @@ S2.define('select2/results',[
this.hideLoading();
var $message = $(
'<li role="treeitem" aria-live="assertive"' +
'<li role="alert" aria-live="assertive"' +
' class="select2-results__option"></li>'
);
@ -858,9 +876,9 @@ S2.define('select2/results',[
Results.prototype.highlightFirstItem = function () {
var $options = this.$results
.find('.select2-results__option[aria-selected]');
.find('.select2-results__option[data-selected]');
var $selected = $options.filter('[aria-selected=true]');
var $selected = $options.filter('[data-selected=true]');
// Check if there are any selected options
if ($selected.length > 0) {
@ -884,7 +902,7 @@ S2.define('select2/results',[
});
var $options = self.$results
.find('.select2-results__option[aria-selected]');
.find('.select2-results__option[data-selected]');
$options.each(function () {
var $option = $(this);
@ -896,9 +914,9 @@ S2.define('select2/results',[
if ((item.element != null && item.element.selected) ||
(item.element == null && $.inArray(id, selectedIds) > -1)) {
$option.attr('aria-selected', 'true');
$option.attr('data-selected', 'true');
} else {
$option.attr('aria-selected', 'false');
$option.attr('data-selected', 'false');
}
});
@ -930,17 +948,17 @@ S2.define('select2/results',[
option.className = 'select2-results__option';
var attrs = {
'role': 'treeitem',
'aria-selected': 'false'
'role': 'option',
'data-selected': 'false'
};
if (data.disabled) {
delete attrs['aria-selected'];
delete attrs['data-selected'];
attrs['aria-disabled'] = 'true';
}
if (data.id == null) {
delete attrs['aria-selected'];
delete attrs['data-selected'];
}
if (data._resultId != null) {
@ -952,9 +970,8 @@ S2.define('select2/results',[
}
if (data.children) {
attrs.role = 'group';
attrs['aria-label'] = data.text;
delete attrs['aria-selected'];
delete attrs['data-selected'];
}
for (var attr in attrs) {
@ -1082,7 +1099,7 @@ S2.define('select2/results',[
var data = $highlighted.data('data');
if ($highlighted.attr('aria-selected') == 'true') {
if ($highlighted.attr('data-selected') == 'true') {
self.trigger('close', {});
} else {
self.trigger('select', {
@ -1094,7 +1111,7 @@ S2.define('select2/results',[
container.on('results:previous', function () {
var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]');
var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted);
@ -1128,7 +1145,7 @@ S2.define('select2/results',[
container.on('results:next', function () {
var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]');
var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted);
@ -1156,7 +1173,8 @@ S2.define('select2/results',[
});
container.on('results:focus', function (params) {
params.element.addClass('select2-results__option--highlighted');
params.element.addClass('select2-results__option--highlighted').attr('aria-selected', 'true');
self.$results.attr('aria-activedescendant', params.element.attr('id'));
});
container.on('results:message', function (params) {
@ -1188,13 +1206,13 @@ S2.define('select2/results',[
});
}
this.$results.on('mouseup', '.select2-results__option[aria-selected]',
this.$results.on('mouseup', '.select2-results__option[data-selected]',
function (evt) {
var $this = $(this);
var data = $this.data('data');
if ($this.attr('aria-selected') === 'true') {
if ($this.attr('data-selected') === 'true') {
if (self.options.get('multiple')) {
self.trigger('unselect', {
originalEvent: evt,
@ -1213,12 +1231,13 @@ S2.define('select2/results',[
});
});
this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
this.$results.on('mouseenter', '.select2-results__option[data-selected]',
function (evt) {
var data = $(this).data('data');
self.getHighlightedResults()
.removeClass('select2-results__option--highlighted');
.removeClass('select2-results__option--highlighted')
.attr('aria-selected', 'false');
self.trigger('results:focus', {
data: data,
@ -1245,7 +1264,7 @@ S2.define('select2/results',[
return;
}
var $options = this.$results.find('[aria-selected]');
var $options = this.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted);
@ -1349,6 +1368,7 @@ S2.define('select2/selection/base',[
var id = container.id + '-container';
var resultsId = container.id + '-results';
var searchHidden = this.options.get('minimumResultsForSearch') === Infinity;
this.container = container;
@ -1369,7 +1389,9 @@ S2.define('select2/selection/base',[
});
container.on('results:focus', function (params) {
self.$selection.attr('aria-activedescendant', params.data._resultId);
if (searchHidden) {
self.$selection.attr('aria-activedescendant', params.data._resultId);
}
});
container.on('selection:update', function (params) {
@ -1379,7 +1401,9 @@ S2.define('select2/selection/base',[
container.on('open', function () {
// When the dropdown is open, aria-expanded="true"
self.$selection.attr('aria-expanded', 'true');
self.$selection.attr('aria-owns', resultsId);
if (searchHidden) {
self.$selection.attr('aria-owns', resultsId);
}
self._attachCloseHandler(container);
});
@ -1390,7 +1414,11 @@ S2.define('select2/selection/base',[
self.$selection.removeAttr('aria-activedescendant');
self.$selection.removeAttr('aria-owns');
self.$selection.focus();
// This needs to be delayed as the active element is the body when the
// key is pressed.
window.setTimeout(function () {
self.$selection.focus();
}, 1);
self._detachCloseHandler(container);
});
@ -1500,7 +1528,10 @@ S2.define('select2/selection/single',[
var id = container.id + '-container';
this.$selection.find('.select2-selection__rendered').attr('id', id);
this.$selection.find('.select2-selection__rendered')
.attr('id', id)
.attr('role', 'textbox')
.attr('aria-readonly', 'true');
this.$selection.attr('aria-labelledby', id);
this.$selection.on('mousedown', function (evt) {
@ -1518,6 +1549,13 @@ S2.define('select2/selection/single',[
// User focuses on the container
});
this.$selection.on('keydown', function (evt) {
// If user starts typing an alphanumeric key on the keyboard, open if not opened.
if (!container.isOpen() && evt.which >= 48 && evt.which <= 90) {
container.open();
}
});
this.$selection.on('blur', function (evt) {
// User exits the container
});
@ -1854,16 +1892,19 @@ S2.define('select2/selection/search',[
Search.prototype.bind = function (decorated, container, $container) {
var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container);
container.on('open', function () {
self.$search.attr('aria-owns', resultsId);
self.$search.trigger('focus');
});
container.on('close', function () {
self.$search.val('');
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.trigger('focus');
});
@ -1882,7 +1923,7 @@ S2.define('select2/selection/search',[
});
container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.id);
self.$search.attr('aria-activedescendant', params.data._resultId);
});
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
@ -3191,7 +3232,7 @@ S2.define('select2/data/select',[
}
}
if (data.id) {
if (data.id !== undefined) {
option.value = data.id;
}
@ -3550,7 +3591,10 @@ S2.define('select2/data/tags',[
}, true)
);
var checkText = option.text === params.term;
var optionText = (option.text || '').toUpperCase();
var paramsTerm = (params.term || '').toUpperCase();
var checkText = optionText === paramsTerm;
if (checkText || checkChildren) {
if (child) {
@ -3887,9 +3931,9 @@ S2.define('select2/dropdown/search',[
var $search = $(
'<span class="select2-search select2-search--dropdown">' +
'<input class="select2-search__field" type="search" tabindex="-1"' +
'<input class="select2-search__field" type="text" tabindex="-1"' +
' autocomplete="off" autocorrect="off" autocapitalize="off"' +
' spellcheck="false" role="textbox" />' +
' spellcheck="false" role="combobox" aria-autocomplete="list" />' +
'</span>'
);
@ -3903,6 +3947,7 @@ S2.define('select2/dropdown/search',[
Search.prototype.bind = function (decorated, container, $container) {
var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container);
@ -3926,7 +3971,7 @@ S2.define('select2/dropdown/search',[
container.on('open', function () {
self.$search.attr('tabindex', 0);
self.$search.attr('aria-owns', resultsId);
self.$search.focus();
window.setTimeout(function () {
@ -3936,7 +3981,8 @@ S2.define('select2/dropdown/search',[
container.on('close', function () {
self.$search.attr('tabindex', -1);
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.val('');
});
@ -3957,6 +4003,10 @@ S2.define('select2/dropdown/search',[
}
}
});
container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.data._resultId);
});
};
Search.prototype.handleSearch = function (evt) {
@ -4098,7 +4148,7 @@ S2.define('select2/dropdown/infiniteScroll',[
var $option = $(
'<li ' +
'class="select2-results__option select2-results__option--load-more"' +
'role="treeitem" aria-disabled="true"></li>'
'role="option" aria-disabled="true"></li>'
);
var message = this.options.get('translations').get('loadingMore');
@ -5653,11 +5703,11 @@ S2.define('jquery.select2',[
'./select2/core',
'./select2/defaults'
], function ($, _, Select2, Defaults) {
if ($.fn.select2 == null) {
if ($.fn.selectWoo == null) {
// All methods that should return the element
var thisMethods = ['open', 'close', 'destroy'];
$.fn.select2 = function (options) {
$.fn.selectWoo = function (options) {
options = options || {};
if (typeof options === 'object') {
@ -5697,10 +5747,17 @@ S2.define('jquery.select2',[
};
}
if ($.fn.select2.defaults == null) {
$.fn.select2.defaults = Defaults;
if ($.fn.select2 != null && $.fn.select2.defaults != null) {
$.fn.selectWoo.defaults = $.fn.select2.defaults;
}
if ($.fn.selectWoo.defaults == null) {
$.fn.selectWoo.defaults = Defaults;
}
// Also register selectWoo under select2 if select2 is not already present.
$.fn.select2 = $.fn.select2 || $.fn.selectWoo;
return Select2;
});
@ -5719,6 +5776,7 @@ S2.define('jquery.select2',[
// This allows Select2 to use the internal loader outside of this file, such
// as in the language files.
jQuery.fn.select2.amd = S2;
jQuery.fn.selectWoo.amd = S2;
// Return the Select2 instance for anyone who is importing it.
return select2;

1
assets/js/selectWoo/selectWoo.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -111,7 +111,7 @@ class WC_Admin_Assets {
wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION );
wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION );
wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION );
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '5.0.0' );
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'select2' ), WC_VERSION );
wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array(
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),

View File

@ -227,9 +227,9 @@ class WC_Frontend_Scripts {
'version' => WC_VERSION,
),
'select2' => array(
'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),
'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '4.0.3',
'version' => '5.0.0',
),
'wc-address-i18n' => array(
'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),