From 22c1661fe56726ee7ed976030854731ef783ed8d Mon Sep 17 00:00:00 2001 From: maxwroc Date: Fri, 23 Aug 2019 13:21:15 +0100 Subject: [PATCH 1/2] Wildcard search --- README.md | 2 + dist/jquery.hideseek-mod.js | 23 +- dist/jquery.hideseek-mod.min.js | 6 +- dist/jquery.hideseek-mod.min.js.map | 2 +- docs/index.html | 53 ++- docs/javascripts/initializers.js | 4 + .../javascripts/vendor/jquery.hideseek-mod.js | 356 ++++++++++++++++++ .../vendor/jquery.hideseek-mod.min.js | 49 --- docs/stylesheets/styles.css | 5 + hideseek-mod.jquery.json | 2 +- jquery.hideseek-mod.js | 23 +- package.json | 2 +- utils/build.js | 3 +- 13 files changed, 458 insertions(+), 72 deletions(-) create mode 100644 docs/javascripts/vendor/jquery.hideseek-mod.js delete mode 100644 docs/javascripts/vendor/jquery.hideseek-mod.min.js diff --git a/README.md b/README.md index dd1312a..558a2ff 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ Served using: * [Prince.gr][5] ## Changelog +### v0.8.4 +* Wildcard search (use '*' in queries) ### v0.8.3 * Fix: Improved query change handling * Generating map file diff --git a/dist/jquery.hideseek-mod.js b/dist/jquery.hideseek-mod.js index 8c96581..379e6dd 100644 --- a/dist/jquery.hideseek-mod.js +++ b/dist/jquery.hideseek-mod.js @@ -4,7 +4,7 @@ * @copyright Copyright 2015, Dimitris Krestos * @license Apache License, Version 2.0 (http://www.opensource.org/licenses/apache2.0.php) * @link http://vdw.staytuned.gr - * @version v0.8.3 + * @version v0.8.4 * * Dependencies are include in minified versions at the bottom: * 1. Highlight v4 by Johann Burkard @@ -47,6 +47,7 @@ hidden_mode: false, min_chars: 1, throttle: 0, + wildcards: false }; var options = $.extend(defaults, options); @@ -58,7 +59,7 @@ $this.opts = []; $this.state = {}; - $.map(['list', 'nodata', 'attribute', 'matches', 'highlight', 'ignore', 'headers', 'navigation', 'ignore_accents', 'hidden_mode', 'min_chars', 'throttle'], function (val, i) { + $.map(['list', 'nodata', 'attribute', 'matches', 'highlight', 'ignore', 'headers', 'navigation', 'ignore_accents', 'hidden_mode', 'min_chars', 'throttle', 'wildcards'], function (val, i) { $this.opts[val] = $this.data(val) || options[val]; }); @@ -88,6 +89,19 @@ if (shouldHandleQueryChange($this, q)) { + var isQueryFound = function (text) { + return text.indexOf(q) != -1; + } + + if ($this.opts.wildcards && q.indexOf('*') !== -1 && q.length > 1) { + // convert query to regexp by escaping and replacing '*' + var regExpString = (q[0] == '*' ? '' : '\\b') + q.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '\\w*') + (q[q.length - 1] == '*' ? '' : '\\b'); + var pattern = new RegExp(regExpString); + isQueryFound = function (text) { + return pattern.test(text); + } + } + $list.children($this.opts.ignore.trim() ? ':not(' + $this.opts.ignore + ')' : '').removeClass('selected').each(function () { var data = getNormalizedText( @@ -96,7 +110,7 @@ : $(this).text() ); - var treaty = data.indexOf(q) == -1 || q === ($this.opts.hidden_mode ? '' : false) + var treaty = !isQueryFound(data) || q === ($this.opts.hidden_mode ? '' : false) if (treaty) { @@ -104,6 +118,9 @@ } else { + // TODO consider removing in the future + // matches is a map - when key matches query then the text is tested against value + // both keys and values from the map/matches object are treated as RegExp patterns if ($this.opts.matches && q.match(new RegExp(Object.keys($this.opts.matches)[0])) !== null) { if (data.match(new RegExp(Object.values($this.opts.matches)[0])) !== null) { diff --git a/dist/jquery.hideseek-mod.min.js b/dist/jquery.hideseek-mod.min.js index 6dab82e..570d44c 100644 --- a/dist/jquery.hideseek-mod.min.js +++ b/dist/jquery.hideseek-mod.min.js @@ -4,7 +4,7 @@ * @copyright Copyright 2015, Dimitris Krestos * @license Apache License, Version 2.0 (http://www.opensource.org/licenses/apache2.0.php) * @link http://vdw.staytuned.gr - * @version v0.8.3 + * @version v0.8.4 * * Dependencies are include in minified versions at the bottom: * 1. Highlight v4 by Johann Burkard @@ -29,7 +29,7 @@ * * or any similar structure... */ -!function(c,t){"use strict";c.fn.hideseek=function(i){i=c.extend({list:".hideseek-data",nodata:"",attribute:"text",matches:!1,highlight:!1,ignore:"",headers:"",navigation:!1,ignore_accents:!1,hidden_mode:!1,min_chars:1,throttle:0},i);return this.each(function(){var h=c(this);h.opts=[],h.state={},c.map(["list","nodata","attribute","matches","highlight","ignore","headers","navigation","ignore_accents","hidden_mode","min_chars","throttle"],function(e,t){h.opts[e]=h.data(e)||i[e]}),h.opts.headers&&(h.opts.ignore+=h.opts.ignore?", "+h.opts.headers:h.opts.headers);var l=function(e){return e=e.toLowerCase(),h.opts.ignore_accents?t.removeAccents(e):e},d=c(h.opts.list);h.opts.navigation&&h.attr("autocomplete","off"),h.opts.hidden_mode&&d.children().hide(),h.keyup(function(t,i){if(!i||"number"!=typeof i||i<=0)return t;var s=0;return function(){var e=arguments;clearTimeout(s),s=setTimeout(function(){t.apply(null,e)},i)}}(function(e){var t,i,s,n,a=l(h.val());function o(e){h.opts.highlight?e.removeHighlight().highlight(a,h.opts.ignore_accents).show():e.show()}function r(e){return e.children(".selected:visible")}h.opts.min_chars&&a.length * @link http://johannburkard.de */ -function($,hideseek){$.fn.highlight=function(e,l){return this.length&&e&&e.length?this.each(function(){!function e(t,i){var s=0;if(3==t.nodeType){var n=(l?hideseek.removeAccents(t.data):t.data).toUpperCase().indexOf(i);if(0<=n){var a=document.createElement("span");a.className="highlight";var o=t.splitText(n),r=(o.splitText(i.length),o.cloneNode(!0));a.appendChild(r),o.parentNode.replaceChild(a,o),s=1}}else if(1==t.nodeType&&t.childNodes&&!/(script|style)/i.test(t.tagName))for(var h=0;hPlease note: It is extended version of HideSeek plugin!
-

Default usage

+

Default usage

 $('#search-1').hideseek();
 
@@ -99,7 +99,7 @@

Default usage

-

Highlight

+

Highlight

 $('#search-highlight').hideseek({
   highlight: true
@@ -126,7 +126,7 @@ 

Highlight

-

No results message

+

No results message

 $('#search-nodata').hideseek({
   nodata: 'No results found'
@@ -155,7 +155,7 @@ 

No results message