diff --git a/packages/jquery/plugins/jquery.select2.selectAll.js b/packages/jquery/plugins/jquery.select2.selectAll.js new file mode 100644 index 000000000..f53f0c684 --- /dev/null +++ b/packages/jquery/plugins/jquery.select2.selectAll.js @@ -0,0 +1,92 @@ +/** + * jquery.select2.selectAll.js + * + * A Select2 extension that adds "Select All" and "Unselect All" functionality to Select2 dropdowns. + * + * @description + * This extension creates a custom adapter for Select2 that adds "Select All" and "Unselect All" + * buttons to the dropdown of multi-select Select2 instances. These buttons allow users to quickly + * select or unselect all options in the dropdown. + * + * @usage + * 1. Include this file after loading jQuery and Select2. + * 2. Initialize Select2 with the custom adapter: + * $('#your-select-element').select2({ + * dropdownAdapter: $.fn.select2.amd.require('select2/selectAllAdapter') + * }); + * + * @dependencies + * - jQuery (https://jquery.com) + * - Select2 (https://select2.org) + * + * @source + * This script is based on the code from: + * https://jsfiddle.net/beaver71/tjvjytp3/ + * Modified and packaged as a reusable extension. + * The original code was written for Select2 version 4.0.5. When adapting it for the latest version + * (4.1.0-rc.0), some modifications were necessary due to changes in Select2's internal structure + * and API. The custom adapter code has been updated to be compatible with version 4.1.0-rc.0, + * addressing issues that arose from differences in how Select2 handles custom adapters in the + * newer version. These changes ensure that the "Select All" and "Unselect All" functionality + * works correctly with the latest Select2 release while maintaining backwards compatibility + * where possible. + */ + +(function ($) { + 'use strict'; + + $.fn.select2.amd.define('select2/selectAllAdapter', [ + 'select2/utils', + 'select2/dropdown', + 'select2/dropdown/attachBody' + ], function (Utils, Dropdown, AttachBody) { + + function SelectAll() { } + SelectAll.prototype.render = function (decorated) { + var self = this, + $rendered = decorated.call(this), + $selectAll = $( + '' + ), + $unselectAll = $( + '' + ), + $btnContainer = $('