From 804cf1a7e13be92fc54f13e92077084cfa490d79 Mon Sep 17 00:00:00 2001 From: Steve James <4stevejames@gmail.com> Date: Wed, 10 Jan 2018 00:39:01 -0800 Subject: [PATCH] Improve options for header text/links and add Flip All feature This breaks out the icons to allow them to be something other than the fixed size jQuery UI icons--they could be HTML entities or Font-Awesome icons instead. Additionally, this adds support for a "flip all" feature that toggles the state of every check box in the menu. This is useful for quickly setting a lot of check-boxes in a long list. Lastly, tests have been added and modified to accommodate these changes. --- src/jquery.multiselect.js | 172 ++++++++++++++++++++++++-------------- tests/unit/options.js | 30 ++++++- 2 files changed, 134 insertions(+), 68 deletions(-) diff --git a/src/jquery.multiselect.js b/src/jquery.multiselect.js index 78e650d..7bd32d5 100644 --- a/src/jquery.multiselect.js +++ b/src/jquery.multiselect.js @@ -29,14 +29,20 @@ height: 175, minWidth: 225, classes: '', - checkAllText: 'Check all', - uncheckAllText: 'Uncheck all', - noneSelectedText: 'Select options', + openIcon: '', // Scaleable HTML Entities or Font-Awesome icons can be used here instead of the default jQuery UI icons. + closeIcon: '', + checkAllIcon: '', + uncheckAllIcon: '', + flipAllIcon: '', + checkAllText: 'Check all', // If blank or null, link not shown. + uncheckAllText: 'Uncheck all', // If blank or null, link not shown. + flipAllText: 'Flip all', // If blank or null, link not shown. showCheckAll: true, showUncheckAll: true, + showFlipAll: false, + noneSelectedText: 'Select options', selectedText: '# selected', selectedList: 0, - closeIcon: 'ui-icon-circle-close', show: null, hide: null, autoOpen: false, @@ -48,10 +54,9 @@ groupColumns: false }, - // This method determines which element to append the menu to // Uses the element provided in the options first, then looks for ui-front / dialog - // Otherwise appends to the body + // Otherwise appends to the body _getAppendEl: function() { var element = this.options.appendTo; if(element) { @@ -66,7 +71,7 @@ return element; }, - // Performs the initial creation of the widget + // Performs the initial creation of the widget _create: function() { var el = this.element; var o = this.options; @@ -82,8 +87,8 @@ // bump unique ID after assigning it to the widget instance this.multiselectID = multiselectID++; - // The button that opens the widget menu - var button = (this.button = $('')) + // The button that opens the widget menu + var button = (this.button = $('')) .addClass('ui-multiselect ui-widget ui-state-default ui-corner-all ' + o.classes) .attr({ 'title':el.attr('title'), 'tabIndex':el.attr('tabIndex'), 'id': el.attr('id') ? el.attr('id') + '_ms' : null }) .prop('aria-haspopup', true) @@ -93,28 +98,31 @@ .html(o.noneSelectedText) .appendTo(button); - // This is the menu that will hold all the options + // This is the menu that will hold all the options this.menu = $('
') .addClass('ui-multiselect-menu ui-widget ui-widget-content ui-corner-all ' + o.classes) .appendTo(this._getAppendEl()); - // Menu header to hold controls for the menu + // Menu header to hold controls for the menu this.header = $('
') .addClass('ui-widget-header ui-corner-all ui-multiselect-header ui-helper-clearfix') .appendTo(this.menu); - // Header controls, will contain the check all/uncheck all buttons - // Depending on how the options are set, this may be empty or simply plain text + // Header controls, will contain the check all/uncheck all buttons + // Depending on how the options are set, this may be empty or simply plain text this.headerLinkContainer = $('