Skip to content

Commit

Permalink
Improved searching in j-Directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Oct 6, 2020
1 parent c75b52e commit ba24158
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion j-Directory/component.js
Expand Up @@ -5,8 +5,9 @@ COMPONENT('directory', 'minwidth:200', function(self, config, cls) {
var is = false, selectedindex = 0, resultscount = 0;
var templateE = '{{ name | encode | ui_directory_helper }}';
var templateR = '{{ name | raw }}';
var template = '<li data-index="{{ $.index }}" data-search="{{ name }}" {{ if selected }} class="current selected{{ if classname }} {{ classname }}{{ fi }}"{{ else if classname }} class="{{ classname }}"{{ fi }}>{0}</li>';
var template = '<li data-index="{{ $.index }}" data-search="{{ $.search }}" {{ if selected }} class="current selected{{ if classname }} {{ classname }}{{ fi }}"{{ else if classname }} class="{{ classname }}"{{ fi }}>{0}</li>';
var templateraw = template.format(templateR);
var regstrip = /(&nbsp;|<([^>]+)>)/ig;
var parentclass;

template = template.format(templateE);
Expand Down Expand Up @@ -282,12 +283,14 @@ COMPONENT('directory', 'minwidth:200', function(self, config, cls) {
var builder = [];
var indexer = {};
var item;
var key = (self.opt.search == true ? self.opt.key : (self.opt.search || self.opt.key)) || 'name';

for (var i = 0; i < items.length; i++) {
item = items[i];
if (self.opt.exclude && self.opt.exclude(item))
continue;
indexer.index = i;
indexer.search = item[key] ? item[key].replace(regstrip, '') : '';
resultscount++;
builder.push(self.opt.ta(item, indexer));
}
Expand Down Expand Up @@ -416,7 +419,9 @@ COMPONENT('directory', 'minwidth:200', function(self, config, cls) {

if (!opt.ajax) {
var indexer = {};
var key = (opt.search == true ? opt.key : (opt.search || opt.key)) || 'name';
for (var i = 0; i < items.length; i++) {

item = items[i];

if (typeof(item) === 'string')
Expand All @@ -433,6 +438,7 @@ COMPONENT('directory', 'minwidth:200', function(self, config, cls) {
item.selected = false;

indexer.index = i;
indexer.search = item[key] ? item[key].replace(regstrip, '') : '';
builder.push(opt.ta(item, indexer));
}

Expand Down
2 changes: 1 addition & 1 deletion j-Directory/component.json
@@ -1,6 +1,6 @@
{
"datecreated": "2019-01-26T12:36:00.000Z",
"dateupdated": "2020-10-02T11:49:00.000Z",
"dateupdated": "2020-10-06T10:11:00.000Z",
"name": "j-Directory",
"tags": [
"dropdown",
Expand Down
2 changes: 1 addition & 1 deletion j-Directory/readme.md
Expand Up @@ -27,7 +27,7 @@ Method: `component.show(options)`
- `options.empty` {String} optional, adds empty field
- `options.exclude` {Function} optional, can exclude items and must return a boolean `function(item) { return item.id !== 100 }`
- `options.close` {Function} optional, can determine closing of panel
- `options.search` {Boolean} optional, can hide search field (default: `true`)
- `options.search` {Boolean/String} optional, can hide search field (default: `true`) or `{String}` (key name) can map a value for searching
- `options.selected` {Object} optional, can contain a selected value (default: `undefined`)
- `options.align` {String} optional, `left` (default), `right` or `center`
- `options.position` {String} optional, `top` (default), `bottom`
Expand Down

0 comments on commit ba24158

Please sign in to comment.