mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-23 03:27:02 +09:00
* fix: label modern dialog apply/clear with the page button text; show Rows on the bar
The dialog apply button was hardcoded 'Search', which mismatched the page's submit label (e.g. 'Go') and collided with pages that have a filter field named Search (clog). It now uses the configured go/clear button display text. Also route the 'rows' field to the modern bar alongside timespan/refresh so the per-page Rows selector stays visible.
* feature: always label the row-count selector 'Rows'
emit_field() forces the 'rows' field friendly_name to Rows regardless of page-specific naming (Devices, Trees, ...), in both legacy and modern filters. Refresh already renders on the modern bar via field_is_bar.
* feature: order modern bar selectors (Rows, Refresh) and separate them from the buttons
Rows renders first and Refresh second on the modern filter bar, and a vertical separator now divides the selectors (Layouts, Rows, Refresh) from the layout action buttons.
* changelog: 8191.feature fragment for modern filter bar polish
* jQuery 4: replace removed $.isFunction in bundled plugins
jQuery 4.0 removed $.isFunction. contextMenu, colorpicker and timepicker are hand-vendored orphans fixed in place; tablesorter is npm-managed, so it is also rewritten at sync time in build/sync-js.mjs so a rebuild reproduces the fix (no-ops once the upstream fix is released and the pin is bumped).
* Render the Thumbnails and Business Hours graph filter checkboxes as Cacti toggles
* fix: address review — update modern JS docblock and strengthen bar/label tests
Rewrite the create_modern_javascript docblock to describe the page-configured apply/clear labels (and document the change/clear callback params). Extend FilterLayoutsTest to assert the selector|button separator, the applied Rows-then-Refresh ordering, and both go/clear label lookups, and that the hardcoded Search dialog label is gone.
* Filter bar polish: toggle-style filter checkboxes and flicker-free layout buttons
Render the shared filter_checkbox field as a Cacti toggle switch (.checkboxSwitch/.checkboxSlider) so every page's filter checkboxes match the rest of the UI, and start the layout Rename/Delete/Save As buttons hidden so layoutUpdateButtons() reveals them only when applicable instead of flashing visible on load.
* Modern filter: move the timespan selector onto its own second filter line
Timespan controls were rendered inline on the single modern filter bar. Route method=timespan fields into a separate group and emit them as a second filterTable row so the bar isn't overcrowded, matching the legacy multi-row layout. Applies to every modern filter with a timespan (the graph view pages).
* Modern filter: keep toggle checkboxes on the bar with a visible label and tooltip
filter_checkbox fields now count as bar fields so the Thumbnails/Business Hours toggles sit on the single bar instead of the Edit dialog. Their label used .checkboxLabel (display:none by design for forms), which hid the text; switch to .checkboxLabelWanted and always set a title tooltip from the field's title/friendly_name so each toggle is self-describing.
* Modern filter: toggles back in the dialog, restrict auto-apply to bar fields, drop dialog Clear
- Move filter_checkbox toggles back into the Edit dialog (field_is_bar no longer claims them) and render them as a form row: friendly name in the label column, toggle in the value column.
- In modern mode only bar selectors (Rows, Refresh) and the Layout selector auto-trigger a filter change; dialog field changes/clicks no longer call applyFilter (gate changeChain/clickChain on !use_modern_filter() || field_is_bar). Legacy keeps auto-applying on change (text inputs still excluded).
- Remove the Clear button from the modern Edit dialog and the now-unused clearLabel; update the dialog-labels test accordingly.
* Fix filter toggle vertical alignment across themes
The generic .filterTable .filterColumn label { vertical-align: -10% } nudge (meant for text labels) out-specified .checkboxSwitch and dragged the toggle switch down, which also pulled the adjacent label baseline low in the Edit dialog and misaligned the toggle on the legacy filter bar. Add a higher-specificity label.checkboxSwitch { vertical-align: middle } in every theme carrying the rule (midwinter has no such rule).
* Hide the filter search glyph in the modern Edit dialog
Theme main.js appends a ti-search glyph after #rfilter, positioned for a table cell; in the modern Edit dialog #rfilter sits in a wide div (no td), so the glyph wraps below the field. Skip the injection when #rfilter is inside .cactiFilterEditTable (modern dialog); legacy, which has no such ancestor, keeps the glyph.
* jQuery 4: full removed-API sweep of bundled plugins
Replace every jQuery-4-removed helper across the vendored plugins: \$.trim -> String.prototype.trim, \$.isArray -> Array.isArray, \$.proxy -> Function.prototype.bind, \$.parseJSON -> JSON.parse, \$.type -> typeof/\$.isPlainObject, \$.isWindow -> native window check (plus the earlier \$.isFunction). Orphans (colorpicker, timepicker, multiselect, multiselect.filter, tableDnD) are fixed in place; the npm-managed tablesorter core+widgets are rewritten at sync time in build/sync-js.mjs so a rebuild reproduces the fix.
* Modern filter dialog: non-modal, Apply gated on save, Save keeps dialog open
- Rename the dialog apply action to Apply and disable it until the (new or changed) filter is saved (layoutDirty tracking); Close just closes without applying.
- Save no longer reloads the page: it reflects the saved layout in the selector and re-enables Apply, keeping the dialog open.
- Dialogs are now modal: false.
- Switch the layout selector change from a full document.location reload to an AJAX loadUrl().
- Vertically center the modern bar cells so the barSep separator lines up between the buttons.
* Modern filter: add layout to the filter's session variable structure
Register layout (FILTER_VALIDATE_INT, default 0) in sanitize_filter_variables() alongside page so the selected layout is validated and stored in the filter's session object and persists across page views.
* Modern filter: Graph Template amalgam on line 2, timespan on line 3
Tag the Graph Template + Source/Order/CF/Measure group ('bar' => true on graph_template_id and the html_graph_order_filter_array() metrics) so create_modern_filter renders it as its own second filter line on Graph View and Tree View, pushing the timespan to the third line. These bar fields also auto-trigger the filter so the Template->Source->Order callback chain works on the main bar.
* Fix graph_template_id multi-select: allow comma lists, type get_host_graph_list correctly
get_host_graph_list() immediately transforms graph_template_id via html_transform_graph_template_ids() (handles cg_/dq_ prefixes and comma lists), so its parameter is a string, not an int -- correct the type hint and docblock. Also widen the preview and listview graph_template_id validation regexp to accept a comma-separated list like 'cg_118,cg_106,cg_119', matching the tree filter.
* Modern filter: hide the whole cell for hidden layout buttons to even out bar separator spacing
The Rename/Delete/Save As buttons hid only the <button>, leaving their table-cell (with padding) in the bar, so the separator after them was pushed away from Edit. Put the display:none on the .filterColumnButton cell and toggle the cell in layoutUpdateButtons so hidden buttons take no space and the separators sit evenly between the visible buttons.
* Remove legacy .drop-callback/makeCallbacks() autocomplete widget
The Device dropdown and other form_callback() lookups now always use the
ajax-backed select2 selectmenu. Drop the old makeCallbacks() jQuery-UI
autocomplete entirely and have form_callback() render the select2-callback
<select> by default, keeping the plain full-list <select> only when the
'autocomplete' config option is enabled.
* Carry selected layout through the modern dialog Apply action
The layout_save callback already returns the new layout id (and url), and
layoutDialogSave() selects it in #filter_layout. The dialog Apply button,
however, ran the plain filter apply (applyFilter()) which rebuilds the URL
from the field values and omits filter_layout, so the page reloaded as
(New Filter). Apply now navigates to the selected layout's data-url (which
includes filter_layout=<id>) when a layout is selected, falling back to the
normal filter apply when none is.
* Fix Filter Layouts manage page table and use jQuery UI dialogs for delete/rename
The management table was opened with html_start_box(\ = true), emitting a
<div> instead of a <table>, so the header and rows rendered unstyled and
run-together. Switch it to table mode.
Replace the generic confirm()-based delete with a CDEF-style jQuery UI
confirmation dialog loaded over ajax, and add a Rename action that opens a
matching jQuery UI dialog with a name field. Both post to the existing
layout_delete/layout_rename handlers on confirm.
* Use jQuery UI dialogs for filter-bar layout rename/delete; drop rename from manage page
The filter bar (modern and legacy) was still using native prompt()/confirm()
for the layout Rename and Delete actions - convert both to jQuery UI dialogs
(a name-entry dialog for rename, a confirm dialog for delete).
On the Filter Layouts management page, remove the rename action entirely and
instead link the layout name to its page (with filter_layout set) as an edit
link; keep the Delete confirmation dialog and Publish action.
* Rework Layouts manage page: preset filter bar + actions dropdown; rename to Layouts
Model layouts.php on the preset pages (CDEFs, etc.): add the standard
CactiTableFilter search bar in the legacy look, a sortable list with a
checkbox column, a pager, and a draw_actions_dropdown with Delete, Make
Global (publish), and Make Local (reassign to the current user). The
unimpressive per-row action icons and ajax dialogs are replaced by the
checkbox/confirmation flow. Make Global/Make Local are admin-only.
Treat layouts.php as a filter_layouts preset page so its own filter bar
does not offer the layout dropdown. Rename the page title and Console
Presets menu entry from 'Filters'/'Filter Layouts' to 'Layouts'.
* Show friendly page name in the Layouts list Page column
Map the stored page basename to the Console navigation title (e.g. host.php
=> Devices) via a layouts_page_name() lookup against \, falling
back to the raw basename. The Page column is now nosort since the displayed
label no longer matches the sortable database value.
* Fix filter search TypeError: use filter_options key in default search field
sanitize_filter_variables() reads a field's callback options from the
'filter_options' key, but the default search field in create_default() stored
them under 'options', so the key never reached validate_store_request_vars().
That left FILTER_CALLBACK with no callback and raised 'filter_var(): Option
must be a valid callback' whenever a table filter was searched.
* Address PR scan findings: tablesorter useless conditional + layouts SQL
- jquery.tablesorter.js: drop the redundant 'str &&' guard inside the
already-truthy 'str ?' branch of the digit and currency parsers (CodeQL
useless-conditional). Add a matching sync-js transform rule so a rebuild
from upstream keeps the simplification.
- layouts.php: fully parameterize the management list queries with bound
'?' parameters for the search term and user id, and build the LIMIT from
explicit (int) page/rows, so no request variable reaches the SQL string
(Semgrep cacti-request-var-in-sql).
* Address PR review: colorpicker trim, tablesorter JSON guard, bar separator, i18n
- jquery.colorpicker.js: _setAltField() iterated index <= properties.length, so
the last pass read properties[undefined]; \$.trim(undefined) was '' but native
.trim() throws. Iterate with < so no TypeError.
- jquery.tablesorter.widgets.js: the retrieveValue feature-check still tested the
removed \$.parseJSON; under jQuery 4 it was always falsy so saved widget state
never loaded. Test native window.JSON.parse instead, and add a matching
build/sync-js.mjs transform rule so a rebuild keeps the guard.
- html_filter.php: the Layouts selector is always rendered, so emit the
selector-to-button separator unconditionally (graph preview routes fields to
the amalgam/timespan lines, leaving the bar line without it before).
- changelog/i18n: reword 8191.feature to describe the Apply (save-gated) dialog
action, and add the new layouts.php/html_filter.php msgids to cacti.pot.
* Add tablesorter transform coverage to the sync-js test
Feed a fixture containing every removed jQuery 4 utility (\$.isFunction,
\$.trim, \$.type ===string/object, \$.isWindow, \$.isArray, \$.parseJSON calls
and the bare if (\$.parseJSON) guard) plus the CodeQL str && simplification
through syncAssets, and assert the synced tablesorter output contains the
native equivalents and none of the removed APIs. Previously the transform ran
against a generic stub, so an incomplete rewrite could pass unnoticed.
* Apply php-cs-fixer: comment style, alignment, and single-quote strings
Run through the project php-cs-fixer config (the mandatory pre-PR check):
line comments for the input-validation banners, aligned assignment, and
single-quoted strings where no interpolation is used. No behaviour change.
* Render the filter Go action as a refresh glyph button (modern + legacy)
Replace the 'Go' text submit with a compact 'ti ti-refresh' glyph button
titled 'Refresh page' for every page filter:
- emit_field() forces the glyph/title on any 'go' submit, so both the shared
default and pages that define their own 'go' get it on the legacy filter.
- The modern bar (which has no form) gets a JS-wired #layout_refresh glyph
button right of Edit that loadUrl()s the selected layout url (carrying
filter_layout) or the page change callback.
Add the 'Refresh page' msgid to cacti.pot and note it in 8191.feature.
* Add a Tabler .icon-rotate spin class and use it for refreshing icons
Tabler ships only the icon webfont, with no fa-spin equivalent, so spinning
reload icons stopped animating (e.g. the Troubleshooting > Data Sources
auto-refresh indicator). Define .icon-rotate in every theme (reusing the
globally loaded fa-spin keyframes) and apply it:
- the modern filter refresh button spins while it loads,
- the realtime graph drill-down loader switches from fa-spin to icon-rotate,
- the data_debug auto-refresh indicators spin again.
* tests: sync FilterLayouts assertions with the reworded separator comment and dw.addClass
The source scan expected the old 'Separate the selectors' comment and a chained
.dialog('widget').addClass() form; update to the current reworded comment and
the 'var dw' + dw.addClass('cactiFilterDialog') the dialog now uses.
* Glyph-ify the timespan Refresh/Clear and the generic Clear action
Replace the timespan 'Refresh' text button with a spinning ti ti-refresh glyph
and 'Clear' with a ti ti-eraser glyph (also fixing a stray double </span>), and
make the generic filter Clear a ti ti-eraser glyph button across legacy and
modern via emit_field (button case now honours a 'glyph' key). The timespan
refresh icon spins (icon-rotate) while it reloads.
* Glyph-ify filter Import/Export, layout, and modern-bar action buttons
Force ti-table-import / ti-table-export glyphs for any filter button named import/export (centralized in emit_field like go/clear), so page-defined Import/Export buttons and the modern bar's always-visible action strip render consistent Tabler glyphs. Add a glyph parameter to layout_button() and glyph the Edit/Rename/Delete/Save As/Save/New/Publish buttons across the modern bar and legacy layouts row.
* Use table-import/table-export glyphs for cactiTableButton Import/Export icons
The filter header Export/Import icons injected into cactiTableButton used generic chevron-down/chevron-up glyphs; switch them to ti ti-table-export / ti ti-table-import to match the rest of the glyph theme.
* Glyph-ify the Save Filter Defaults button on the filter bar
The has_save 'Save' action rendered as a text button on the modern bar (and legacy filter); force a ti ti-device-floppy glyph via emit_field like go/clear/import/export so it matches the rest of the glyph theme.
* Regenerate tree-view graphs when applying a saved filter layout
The modern layout selector loaded a layout's saved data-url (action=tree) directly, so on the Graph Tree view it pulled the tree shell instead of regenerating graphs. Route the layout-url loads (selector change, refresh button, and dialog Apply) through correctUrlParameters() so action=tree becomes action=tree_content and graphs reload into #main, matching applyGraphFilter(). No-op on non-tree pages.
* Keep timespan controls working after ajax reloads and tip custom date fields
On the Graph Preview page the predefined_timespan change and tsrefresh/tsclear/shift click handlers were bound directly inside the filter's inline ready script, so an ajax content reload that replaced the timespan controls dropped the bindings (a full page refresh restored them). Bind them with namespaced event delegation on document so they survive content replacement and never double-bind. Add tooltips to the custom start/end date inputs telling the user to click Refresh to apply the range, plus POT entries and a changelog note.
* Record layouts.php static redirect in the sink inventory baseline
The sink and architectural hotspot guard flagged inventory drift: layouts.php's static header('Location: layouts.php') redirect (no request input) was never added to the tracked baseline. Refresh the baseline via tests/security/build_sink_inventory.sh to record it.
* Fix layout Save-As dialog state and use cacti_redirect in layouts.php
Address review findings: (1) use cacti_redirect('layouts.php') instead of a raw header()+exit so the standard redirect checks run (and drop the now-unneeded sink-inventory entry); (2) reset the dialog's force-new flag after the first successful save so later saves update the created layout instead of creating duplicates; (3) preserve an existing dirty state when reopening the Edit dialog so pending edits are not silently discarded by Apply.
* Drop stale layout msgids from the translation template
Remove the Filter Layouts, Published to all users, Publish to all users, and No Filter Layouts Found msgids that this PR replaced (now Layouts, Make Global, Make Local, No Layouts Found); all four are absent from PHP. Keeps the surgically-maintained POT in sync with the shipped strings.
---------
Co-authored-by: TheWitness <TheWitness@users.noreply.github.com>
289 lines
10 KiB
JavaScript
289 lines
10 KiB
JavaScript
/* jshint forin:true, noarg:true, noempty:true, eqeqeq:true, boss:true, undef:true, curly:true, browser:true, jquery:true */
|
|
/*
|
|
* jQuery MultiSelect UI Widget Filtering Plugin 3.0.0
|
|
* Copyright (c) 2012 Eric Hynds
|
|
*
|
|
* http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
|
|
*
|
|
* Depends:
|
|
* - jQuery UI MultiSelect widget
|
|
*
|
|
* Dual licensed under the MIT and GPL licenses:
|
|
* http://www.opensource.org/licenses/mit-license.php
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
*
|
|
*/
|
|
(function($) {
|
|
var rEscape = /[\-\[\]{}()*+?.,\\\^$|#\s]/g;
|
|
|
|
// "{{term}}" is a placeholder below for where the search term
|
|
// would be inserted in the resulting regular expression.
|
|
var filterRules = {
|
|
contains: '{{term}}',
|
|
beginsWith: '^{{term}}',
|
|
endsWith: '{{term}}$',
|
|
exactMatch: '^{{term}}$',
|
|
containsNumber: '\d',
|
|
isNumeric: '^\d+$',
|
|
isNonNumeric: '^\D+$',
|
|
};
|
|
|
|
var headerSelector = '.ui-multiselect-header';
|
|
var hasFilterClass = 'ui-multiselect-hasfilter';
|
|
var filterClass = 'ui-multiselect-filter';
|
|
var optgroupClass = 'ui-multiselect-optgroup';
|
|
var groupLabelClass = 'ui-multiselect-grouplabel';
|
|
var hiddenClass = 'ui-multiselect-excluded';
|
|
var searchClass = 'ui-state-default ui-corner-all';
|
|
|
|
/**
|
|
* This comes courtesy of underscore.js
|
|
* @param {function} func to debounce
|
|
* @param {number} wait period
|
|
* @param {bool} immediate perform once immediately
|
|
* @return {function} input function with a debounce period
|
|
*/
|
|
function debounce(func, wait, immediate) {
|
|
var timeout;
|
|
return function() {
|
|
var context = this; var args = arguments; // eslint-disable-line prefer-rest-params
|
|
var later = function() {
|
|
timeout = null;
|
|
if (!immediate) {
|
|
func.apply(context, args);
|
|
}
|
|
};
|
|
var callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) {
|
|
func.apply(context, args);
|
|
}
|
|
};
|
|
}
|
|
|
|
$.widget('ech.multiselectfilter', {
|
|
options: {
|
|
label: 'Filter:', // (string) The label to show with the input
|
|
placeholder: 'Enter keywords', // (string) The placeholder text to show in the input
|
|
filterRule: 'contains', // (string) Either a named filter rule from above or a regular expression containing {{term}} as a placeholder
|
|
searchGroups: false, // (true | false) If true, search option group labels and show an entire group on a match.
|
|
autoReset: false, // (true | false) If true, clear the filter each time the widget menu is closed.
|
|
width: null, // (number) Override default width set in css file (px). null will inherit
|
|
debounceMS: 250, // (number) Number of milleseconds to wait between running the search handler.
|
|
},
|
|
|
|
/**
|
|
* Performs widget creation
|
|
* Widget API has already set this.element and this.options for us
|
|
* - Find the multiselect widget.
|
|
* - Create the filter input
|
|
* - Set up event handlers
|
|
* - Insert in header
|
|
* - Create text cache
|
|
* - Override toggleState
|
|
*/
|
|
_create: function() {
|
|
var opts = this.options;
|
|
var $element = this.element;
|
|
|
|
// get the multiselect instance
|
|
this.instance = $element.data('ech-multiselect');
|
|
|
|
// store header; add filter class so the close/check all/uncheck all links can be positioned correctly
|
|
this.$header = this.instance.$menu.find(headerSelector).addClass(hasFilterClass);
|
|
|
|
// wrapper $element
|
|
this.$input = $(document.createElement('input'))
|
|
.attr({
|
|
placeholder: opts.placeholder,
|
|
type: 'search',
|
|
})
|
|
.css({width: (typeof opts.width === 'string')
|
|
? this.instance._parse2px(opts.width, this.$header).px + 'px'
|
|
: (/\d/.test(opts.width) ? opts.width + 'px' : null),
|
|
})
|
|
.addClass(searchClass);
|
|
this._bindInputEvents();
|
|
// automatically reset the widget on close?
|
|
if (this.options.autoReset) {
|
|
$element.on('multiselectbeforeclose', this._reset.bind(this));
|
|
}
|
|
|
|
var $label = $(document.createElement('label')).text(opts.label).append(this.$input).addClass('ui-multiselect-filter-label');
|
|
this.$wrapper = $(document.createElement('div'))
|
|
.addClass(filterClass)
|
|
.append($label)
|
|
.prependTo(this.$header);
|
|
|
|
// If menu already opened, have to reset menu height since
|
|
// addition of the filter input changes the header height calc.
|
|
if (!!this.instance._isOpen) {
|
|
this.instance._setMenuHeight(true);
|
|
}
|
|
|
|
// cache input values for searching
|
|
this.updateCache();
|
|
|
|
// Change the normal _toggleChecked fxn behavior so that when checkAll/uncheckAll
|
|
// is fired, only the currently displayed filtered inputs are checked if filter entered.
|
|
var instance = this.instance;
|
|
var filter = this.$input[0];
|
|
instance._oldToggleChecked = instance._toggleChecked;
|
|
instance._toggleChecked = function(flag, group) {
|
|
instance._oldToggleChecked(flag, group, !!filter.value);
|
|
};
|
|
},
|
|
|
|
/**
|
|
* Binds keyboard events to the input
|
|
* This is where special behavior like ALT-R for reset is bound
|
|
*/
|
|
_bindInputEvents: function() {
|
|
this.$input.on({
|
|
keydown: function(e) {
|
|
// prevent the enter key from submitting the form / closing the widget
|
|
if (e.which === 13) {
|
|
e.preventDefault();
|
|
} else if (e.which === 27) {
|
|
$element.multiselect('close');
|
|
e.preventDefault();
|
|
} else if (e.which === 9 && e.shiftKey) {
|
|
$element.multiselect('close');
|
|
e.preventDefault();
|
|
} else if (e.altKey) {
|
|
switch (e.which) {
|
|
case 82:
|
|
e.preventDefault();
|
|
$(this).val('').trigger('input', '');
|
|
break;
|
|
case 65:
|
|
$element.multiselect('checkAll');
|
|
break;
|
|
case 85:
|
|
$element.multiselect('uncheckAll');
|
|
break;
|
|
case 70:
|
|
$element.multiselect('flipAll');
|
|
break;
|
|
case 76:
|
|
$element.multiselect('instance').$labels.first().trigger('mouseenter');
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
input: debounce(this._handler, this.options.debounceMS).bind(this),
|
|
search: this._handler.bind(this),
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Handles searches as text is entered in the filter box.
|
|
* Uses a text cache to speed up searching.
|
|
* Debouncing is done to limit how often this is ran.
|
|
* Alternate filter rules can be used.
|
|
* Option group labels may be searched, also.
|
|
* @param {event} e event object from original event.
|
|
*/
|
|
_handler: function(e) {
|
|
var term = this.$input[0].value.toLowerCase().replace(/^\s+|\s+$/g, '');
|
|
var filterRule = this.options.filterRule || 'contains';
|
|
var regex = new RegExp( ( filterRules[filterRule] || filterRule ).replace('{{term}}', term.replace(rEscape, '\\$&')), 'i');
|
|
var searchGroups = !!this.options.searchGroups;
|
|
var $checkboxes = this.instance.$checkboxes;
|
|
var cache = this.cache; // Cached text() object
|
|
|
|
this.$rows.toggleClass(hiddenClass, !!term);
|
|
|
|
var filteredInputs = $checkboxes.children().map(function(x) {
|
|
var elem = this;
|
|
var $groupItems = $(elem);
|
|
var groupShown = false;
|
|
|
|
// Account for optgroups
|
|
// If we are searching in option group labels and we match an optgroup label,
|
|
// then show all its children and return all its inputs also.
|
|
if (elem.classList.contains(optgroupClass)) {
|
|
var $groupItems = $groupItems.find('li');
|
|
if (searchGroups && regex.test( cache[x] ) ) {
|
|
elem.classList.remove(hiddenClass);
|
|
$groupItems.removeClass(hiddenClass);
|
|
return $groupItems.find('input').get();
|
|
}
|
|
}
|
|
|
|
return $groupItems.map(function(y) {
|
|
if ( regex.test( cache[x + '.' + y] ) ) {
|
|
// Show the opt group heading if needed
|
|
if (!groupShown) {
|
|
elem.classList.remove(hiddenClass);
|
|
groupShown = true;
|
|
}
|
|
this.classList.remove(hiddenClass);
|
|
return this.getElementsByTagName('input')[0];
|
|
}
|
|
return null;
|
|
});
|
|
});
|
|
if (term) {
|
|
this._trigger('filter', e, filteredInputs);
|
|
}
|
|
if (!this.instance.options.listbox && this.instance._isOpen) {
|
|
this.instance._setMenuHeight(true);
|
|
this.instance.position();
|
|
}
|
|
return;
|
|
},
|
|
|
|
_reset: function() {
|
|
this.$input.val('');
|
|
var event = document.createEvent('Event');
|
|
event.initEvent('reset', true, true);
|
|
this.$input.get(0).dispatchEvent(event);
|
|
this._handler(event);
|
|
},
|
|
|
|
/**
|
|
* Creates a text cache object from the widget options' text.
|
|
* @param {Boolean} alsoRefresh causes the displayed search results to refresh.
|
|
*/
|
|
updateCache: function(alsoRefresh) {
|
|
var cache = {}; // keys are like 0, 0.1, 1, 1.0, 1.1 etc.
|
|
this.instance.$checkboxes.children().each(function(x) {
|
|
var $element = $(this);
|
|
// Account for optgroups
|
|
if (this.classList.contains(optgroupClass)) {
|
|
// Single number keys are the option labels
|
|
cache[x] = this.getElementsByClassName(groupLabelClass)[0].textContent;
|
|
$element = $element.find('li');
|
|
}
|
|
$element.each(function(y) {
|
|
cache[x + '.' + y] = this.textContent;
|
|
});
|
|
});
|
|
this.cache = cache;
|
|
this.$rows = this.instance.$checkboxes.find('li');
|
|
if (!!alsoRefresh) {
|
|
this._handler();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* @return {object} Returns the input wrapper div
|
|
*/
|
|
widget: function() {
|
|
return this.$wrapper;
|
|
},
|
|
|
|
/**
|
|
* Destroys this widget
|
|
*/
|
|
destroy: function() {
|
|
$.Widget.prototype.destroy.call(this);
|
|
this.$input.val('').trigger('keyup').off('keydown input search');
|
|
this.instance.$menu.find(headerSelector).removeClass(hasFilterClass);
|
|
this.$wrapper.remove();
|
|
},
|
|
});
|
|
})(jQuery);
|