Comparing version 1.10.0 to 1.11.0
{ | ||
"name": "fastsearch", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"homepage": "https://github.com/dbrekalo/fastsearch", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -15,2 +15,3 @@ (function(factory) { | ||
instanceNum = 0, | ||
eventStringRE = /\w\b/g, | ||
keyMap = { | ||
@@ -56,3 +57,3 @@ 13: 'enter', | ||
return events.replace(/\w\b/g, function(match) { | ||
return events.replace(eventStringRE, function(match) { | ||
return match + eventNamespace; | ||
@@ -270,2 +271,6 @@ }); | ||
if (this.options.flipOnBottom) { | ||
this.checkDropdownPosition(); | ||
} | ||
this.$resultsCont = this.$resultsCont || $('<div>').addClass(this.options.resultsContClass).appendTo(this.$el); | ||
@@ -288,3 +293,3 @@ | ||
if (this.options.focusFirstItem && this.$resultItems.length) { | ||
if (this.options.focusFirstItem && this.$resultItems && this.$resultItems.length) { | ||
this.navigateItem('down'); | ||
@@ -297,2 +302,12 @@ } | ||
checkDropdownPosition: function() { | ||
var flipOnBottom = this.options.flipOnBottom; | ||
var offset = typeof flipOnBottom === 'boolean' && flipOnBottom ? 400 : flipOnBottom; | ||
var isFlipped = this.$input.offset().top + offset > $document.height(); | ||
this.$el.toggleClass(this.options.resultsFlippedClass, isFlipped); | ||
}, | ||
documentCancelEvents: function(setup, onCancel) { | ||
@@ -501,2 +516,3 @@ | ||
resultsOpenedClass: 'fsr_opened', | ||
resultsFlippedClass: 'fsr_flipped', | ||
groupClass: 'fs_group', | ||
@@ -515,2 +531,3 @@ itemClass: 'fs_result_item', | ||
focusFirstItem: false, | ||
flipOnBottom: false, | ||
@@ -517,0 +534,0 @@ responseFormat: { // Adjust where plugin looks for data in your JSON server response |
@@ -1,1 +0,1 @@ | ||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){function b(a,b){this.init.apply(this,arguments)}var c=a(window.document),d=0,e={13:"enter",27:"escape",40:"downArrow",38:"upArrow"};return a.extend(b.prototype,{init:function(c,e){e=this.options=a.extend(!0,{},b.defaults,e),this.$input=a(c),this.$el=e.wrapSelector instanceof a?e.wrapSelector:this.$input.closest(e.wrapSelector),b.pickTo(e,this.$el.data(),["url","onItemSelect","noResultsText","inputIdName","apiInputName"]),e.url=e.url||this.$el.attr("action"),this.ens=".fastsearch"+ ++d,this.itemSelector=b.selectorFromClass(e.itemClass),this.focusedItemSelector=b.selectorFromClass(e.focusedItemClass),this.events()},namespaceEvents:function(a){var b=this.ens;return a.replace(/\w\b/g,function(a){return a+b})},events:function(){var b=this,c=this.options;this.$input.on(this.namespaceEvents("keyup focus click"),function(a){"enter"!==e[a.keyCode]&&b.handleTyping()}).on(this.namespaceEvents("keydown"),function(a){if("enter"===e[a.keyCode]&&c.preventSubmit&&a.preventDefault(),b.hasResults&&b.resultsOpened)switch(e[a.keyCode]){case"downArrow":a.preventDefault(),b.navigateItem("down");break;case"upArrow":a.preventDefault(),b.navigateItem("up");break;case"enter":b.onEnter(a)}}),this.$el.on(this.namespaceEvents("click"),this.itemSelector,function(c){c.preventDefault(),b.handleItemSelect(a(this))}),c.mouseEvents&&this.$el.on(this.namespaceEvents("mouseleave"),this.itemSelector,function(b){a(this).removeClass(c.focusedItemClass)}).on(this.namespaceEvents("mouseenter"),this.itemSelector,function(d){b.$resultItems.removeClass(c.focusedItemClass),a(this).addClass(c.focusedItemClass)})},handleTyping:function(){var b=a.trim(this.$input.val()),c=this;b.length<this.options.minQueryLength?this.hideResults():b===this.query?this.showResults():(clearTimeout(this.keyupTimeout),this.keyupTimeout=setTimeout(function(){c.$el.addClass(c.options.loadingClass),c.query=b,c.getResults(function(a){c.showResults(c.storeResponse(a).generateResults(a))})},this.options.typeTimeout))},getResults:function(b){var c=this,d=this.options,e=this.$el.find("input, textarea, select").serializeArray();d.apiInputName&&e.push({name:d.apiInputName,value:this.$input.val()}),a.get(d.url,e,function(a){b(d.parseResponse?d.parseResponse.call(c,a,c):a)})},storeResponse:function(a){return this.responseData=a,this.hasResults=0!==a.length,this},generateResults:function(b){var c=a("<div>"),d=this.options;return d.template?a(d.template(b,this)):(0===b.length?c.html('<p class="'+d.noResultsClass+'">'+("function"==typeof d.noResultsText?d.noResultsText.call(this):d.noResultsText)+"</p>"):"html"===this.options.responseType?c.html(b):this["generate"+(b[0][d.responseFormat.groupItems]?"GroupedResults":"SimpleResults")](b,c),c.children())},generateSimpleResults:function(b,c){var d=this;this.itemModels=b,a.each(b,function(a,b){c.append(d.generateItem(b))})},generateGroupedResults:function(b,c){var d=this,e=this.options,f=e.responseFormat;this.itemModels=[],a.each(b,function(b,g){var h=a('<div class="'+e.groupClass+'">').appendTo(c);g[f.groupCaption]&&h.append('<h3 class="'+e.groupTitleClass+'">'+g[f.groupCaption]+"</h3>"),a.each(g.items,function(a,b){d.itemModels.push(b),h.append(d.generateItem(b))}),e.onGroupCreate&&e.onGroupCreate.call(d,h,g,d)})},generateItem:function(b){var c=this.options,d=c.responseFormat,e=b[d.url],f=b[d.html]||b[d.label],g=a("<"+(e?"a":"span")+">").html(f).addClass(c.itemClass);return e&&g.attr("href",e),c.onItemCreate&&c.onItemCreate.call(this,g,b,this),g},showResults:function(b){!b&&this.resultsOpened||(this.$el.removeClass(this.options.loadingClass).addClass(this.options.resultsOpenedClass),this.$resultsCont=this.$resultsCont||a("<div>").addClass(this.options.resultsContClass).appendTo(this.$el),b&&(this.$resultsCont.html(b),this.$resultItems=this.$resultsCont.find(this.itemSelector),this.options.onResultsCreate&&this.options.onResultsCreate.call(this,this.$resultsCont,this.responseData,this)),this.resultsOpened||(this.documentCancelEvents("on"),this.$input.trigger("openingResults")),this.options.focusFirstItem&&this.$resultItems.length&&this.navigateItem("down"),this.resultsOpened=!0)},documentCancelEvents:function(b,d){var f=this;return"off"===b&&this.closeEventsSetuped?(c.off(this.ens),void(this.closeEventsSetuped=!1)):void("on"!==b||this.closeEventsSetuped||(c.on(this.namespaceEvents("click keyup"),function(b){("escape"===e[b.keyCode]||!a(b.target).is(f.$el)&&!a.contains(f.$el.get(0),b.target)&&a.contains(document.documentElement,b.target))&&(d?d.call(f):f.hideResults())}),this.closeEventsSetuped=!0))},navigateItem:function(a){var b=this.$resultItems.filter(this.focusedItemSelector),c=this.$resultItems.length-1;if(0===b.length)return void this.$resultItems.eq("up"===a?c:0).addClass(this.options.focusedItemClass);var d=this.$resultItems.index(b),e="up"===a?d-1:d+1;e>c&&(e=0),e<0&&(e=c),b.removeClass(this.options.focusedItemClass),this.$resultItems.eq(e).addClass(this.options.focusedItemClass)},navigateDown:function(){this.navigateItem("down")},navigateUp:function(){this.navigateItem("up")},onEnter:function(a){var b=this.$resultItems.filter(this.focusedItemSelector);b.length&&(a.preventDefault(),this.handleItemSelect(b))},handleItemSelect:function(a){var b=this.options.onItemSelect,c=this.itemModels.length?this.itemModels[this.$resultItems.index(a)]:{};this.$input.trigger("itemSelected"),"fillInput"===b?this.fillInput(c):"follow"===b?window.location.href=a.attr("href"):"function"==typeof b&&b.call(this,a,c,this)},fillInput:function(b){var c=this.options,d=c.responseFormat;if(this.query=b[d.label],this.$input.val(b[d.label]).trigger("change"),c.fillInputId&&b.id){if(!this.$inputId){var e=c.inputIdName||this.$input.attr("name")+"_id";this.$inputId=this.$el.find('input[name="'+e+'"]'),this.$inputId.length||(this.$inputId=a('<input type="hidden" name="'+e+'" />').appendTo(this.$el))}this.$inputId.val(b.id).trigger("change")}this.hideResults()},hideResults:function(){return this.resultsOpened&&(this.resultsOpened=!1,this.$el.removeClass(this.options.resultsOpenedClass),this.$input.trigger("closingResults"),this.documentCancelEvents("off")),this},clear:function(){return this.hideResults(),this.$input.val("").trigger("change"),this},destroy:function(){c.off(this.ens),this.$input.off(this.ens),this.$el.off(this.ens).removeClass(this.options.resultsOpenedClass).removeClass(this.options.loadingClass),this.$resultsCont&&(this.$resultsCont.remove(),delete this.$resultsCont),delete this.$el.data().fastsearch}}),a.extend(b,{pickTo:function(b,c,d){return a.each(d,function(a,d){b[d]=c&&c[d]||b[d]}),b},selectorFromClass:function(a){return"."+a.replace(/\s/g,".")}}),b.defaults={wrapSelector:"form",url:null,responseType:"JSON",preventSubmit:!1,resultsContClass:"fs_results",resultsOpenedClass:"fsr_opened",groupClass:"fs_group",itemClass:"fs_result_item",groupTitleClass:"fs_group_title",loadingClass:"loading",noResultsClass:"fs_no_results",focusedItemClass:"focused",typeTimeout:140,minQueryLength:2,template:null,mouseEvents:!("ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0),focusFirstItem:!1,responseFormat:{url:"url",html:"html",label:"label",groupCaption:"caption",groupItems:"items"},fillInputId:!0,inputIdName:null,apiInputName:null,noResultsText:"No results found",onItemSelect:"follow",parseResponse:null,onResultsCreate:null,onGroupCreate:null,onItemCreate:null},a.fastsearch=b,a.fn.fastsearch=function(c){return this.each(function(){a.data(this,"fastsearch")||a.data(this,"fastsearch",new b(this,c))})},a}); | ||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){function b(a,b){this.init.apply(this,arguments)}var c=a(window.document),d=0,e=/\w\b/g,f={13:"enter",27:"escape",40:"downArrow",38:"upArrow"};return a.extend(b.prototype,{init:function(c,e){e=this.options=a.extend(!0,{},b.defaults,e),this.$input=a(c),this.$el=e.wrapSelector instanceof a?e.wrapSelector:this.$input.closest(e.wrapSelector),b.pickTo(e,this.$el.data(),["url","onItemSelect","noResultsText","inputIdName","apiInputName"]),e.url=e.url||this.$el.attr("action"),this.ens=".fastsearch"+ ++d,this.itemSelector=b.selectorFromClass(e.itemClass),this.focusedItemSelector=b.selectorFromClass(e.focusedItemClass),this.events()},namespaceEvents:function(a){var b=this.ens;return a.replace(e,function(a){return a+b})},events:function(){var b=this,c=this.options;this.$input.on(this.namespaceEvents("keyup focus click"),function(a){"enter"!==f[a.keyCode]&&b.handleTyping()}).on(this.namespaceEvents("keydown"),function(a){if("enter"===f[a.keyCode]&&c.preventSubmit&&a.preventDefault(),b.hasResults&&b.resultsOpened)switch(f[a.keyCode]){case"downArrow":a.preventDefault(),b.navigateItem("down");break;case"upArrow":a.preventDefault(),b.navigateItem("up");break;case"enter":b.onEnter(a)}}),this.$el.on(this.namespaceEvents("click"),this.itemSelector,function(c){c.preventDefault(),b.handleItemSelect(a(this))}),c.mouseEvents&&this.$el.on(this.namespaceEvents("mouseleave"),this.itemSelector,function(b){a(this).removeClass(c.focusedItemClass)}).on(this.namespaceEvents("mouseenter"),this.itemSelector,function(d){b.$resultItems.removeClass(c.focusedItemClass),a(this).addClass(c.focusedItemClass)})},handleTyping:function(){var b=a.trim(this.$input.val()),c=this;b.length<this.options.minQueryLength?this.hideResults():b===this.query?this.showResults():(clearTimeout(this.keyupTimeout),this.keyupTimeout=setTimeout(function(){c.$el.addClass(c.options.loadingClass),c.query=b,c.getResults(function(a){c.showResults(c.storeResponse(a).generateResults(a))})},this.options.typeTimeout))},getResults:function(b){var c=this,d=this.options,e=this.$el.find("input, textarea, select").serializeArray();d.apiInputName&&e.push({name:d.apiInputName,value:this.$input.val()}),a.get(d.url,e,function(a){b(d.parseResponse?d.parseResponse.call(c,a,c):a)})},storeResponse:function(a){return this.responseData=a,this.hasResults=0!==a.length,this},generateResults:function(b){var c=a("<div>"),d=this.options;return d.template?a(d.template(b,this)):(0===b.length?c.html('<p class="'+d.noResultsClass+'">'+("function"==typeof d.noResultsText?d.noResultsText.call(this):d.noResultsText)+"</p>"):"html"===this.options.responseType?c.html(b):this["generate"+(b[0][d.responseFormat.groupItems]?"GroupedResults":"SimpleResults")](b,c),c.children())},generateSimpleResults:function(b,c){var d=this;this.itemModels=b,a.each(b,function(a,b){c.append(d.generateItem(b))})},generateGroupedResults:function(b,c){var d=this,e=this.options,f=e.responseFormat;this.itemModels=[],a.each(b,function(b,g){var h=a('<div class="'+e.groupClass+'">').appendTo(c);g[f.groupCaption]&&h.append('<h3 class="'+e.groupTitleClass+'">'+g[f.groupCaption]+"</h3>"),a.each(g.items,function(a,b){d.itemModels.push(b),h.append(d.generateItem(b))}),e.onGroupCreate&&e.onGroupCreate.call(d,h,g,d)})},generateItem:function(b){var c=this.options,d=c.responseFormat,e=b[d.url],f=b[d.html]||b[d.label],g=a("<"+(e?"a":"span")+">").html(f).addClass(c.itemClass);return e&&g.attr("href",e),c.onItemCreate&&c.onItemCreate.call(this,g,b,this),g},showResults:function(b){!b&&this.resultsOpened||(this.$el.removeClass(this.options.loadingClass).addClass(this.options.resultsOpenedClass),this.options.flipOnBottom&&this.checkDropdownPosition(),this.$resultsCont=this.$resultsCont||a("<div>").addClass(this.options.resultsContClass).appendTo(this.$el),b&&(this.$resultsCont.html(b),this.$resultItems=this.$resultsCont.find(this.itemSelector),this.options.onResultsCreate&&this.options.onResultsCreate.call(this,this.$resultsCont,this.responseData,this)),this.resultsOpened||(this.documentCancelEvents("on"),this.$input.trigger("openingResults")),this.options.focusFirstItem&&this.$resultItems&&this.$resultItems.length&&this.navigateItem("down"),this.resultsOpened=!0)},checkDropdownPosition:function(){var a=this.options.flipOnBottom,b="boolean"==typeof a&&a?400:a,d=this.$input.offset().top+b>c.height();this.$el.toggleClass(this.options.resultsFlippedClass,d)},documentCancelEvents:function(b,d){var e=this;return"off"===b&&this.closeEventsSetuped?(c.off(this.ens),void(this.closeEventsSetuped=!1)):void("on"!==b||this.closeEventsSetuped||(c.on(this.namespaceEvents("click keyup"),function(b){("escape"===f[b.keyCode]||!a(b.target).is(e.$el)&&!a.contains(e.$el.get(0),b.target)&&a.contains(document.documentElement,b.target))&&(d?d.call(e):e.hideResults())}),this.closeEventsSetuped=!0))},navigateItem:function(a){var b=this.$resultItems.filter(this.focusedItemSelector),c=this.$resultItems.length-1;if(0===b.length)return void this.$resultItems.eq("up"===a?c:0).addClass(this.options.focusedItemClass);var d=this.$resultItems.index(b),e="up"===a?d-1:d+1;e>c&&(e=0),e<0&&(e=c),b.removeClass(this.options.focusedItemClass),this.$resultItems.eq(e).addClass(this.options.focusedItemClass)},navigateDown:function(){this.navigateItem("down")},navigateUp:function(){this.navigateItem("up")},onEnter:function(a){var b=this.$resultItems.filter(this.focusedItemSelector);b.length&&(a.preventDefault(),this.handleItemSelect(b))},handleItemSelect:function(a){var b=this.options.onItemSelect,c=this.itemModels.length?this.itemModels[this.$resultItems.index(a)]:{};this.$input.trigger("itemSelected"),"fillInput"===b?this.fillInput(c):"follow"===b?window.location.href=a.attr("href"):"function"==typeof b&&b.call(this,a,c,this)},fillInput:function(b){var c=this.options,d=c.responseFormat;if(this.query=b[d.label],this.$input.val(b[d.label]).trigger("change"),c.fillInputId&&b.id){if(!this.$inputId){var e=c.inputIdName||this.$input.attr("name")+"_id";this.$inputId=this.$el.find('input[name="'+e+'"]'),this.$inputId.length||(this.$inputId=a('<input type="hidden" name="'+e+'" />').appendTo(this.$el))}this.$inputId.val(b.id).trigger("change")}this.hideResults()},hideResults:function(){return this.resultsOpened&&(this.resultsOpened=!1,this.$el.removeClass(this.options.resultsOpenedClass),this.$input.trigger("closingResults"),this.documentCancelEvents("off")),this},clear:function(){return this.hideResults(),this.$input.val("").trigger("change"),this},destroy:function(){c.off(this.ens),this.$input.off(this.ens),this.$el.off(this.ens).removeClass(this.options.resultsOpenedClass).removeClass(this.options.loadingClass),this.$resultsCont&&(this.$resultsCont.remove(),delete this.$resultsCont),delete this.$el.data().fastsearch}}),a.extend(b,{pickTo:function(b,c,d){return a.each(d,function(a,d){b[d]=c&&c[d]||b[d]}),b},selectorFromClass:function(a){return"."+a.replace(/\s/g,".")}}),b.defaults={wrapSelector:"form",url:null,responseType:"JSON",preventSubmit:!1,resultsContClass:"fs_results",resultsOpenedClass:"fsr_opened",resultsFlippedClass:"fsr_flipped",groupClass:"fs_group",itemClass:"fs_result_item",groupTitleClass:"fs_group_title",loadingClass:"loading",noResultsClass:"fs_no_results",focusedItemClass:"focused",typeTimeout:140,minQueryLength:2,template:null,mouseEvents:!("ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0),focusFirstItem:!1,flipOnBottom:!1,responseFormat:{url:"url",html:"html",label:"label",groupCaption:"caption",groupItems:"items"},fillInputId:!0,inputIdName:null,apiInputName:null,noResultsText:"No results found",onItemSelect:"follow",parseResponse:null,onResultsCreate:null,onGroupCreate:null,onItemCreate:null},a.fastsearch=b,a.fn.fastsearch=function(c){return this.each(function(){a.data(this,"fastsearch")||a.data(this,"fastsearch",new b(this,c))})},a}); |
{ | ||
"name": "fastsearch", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"main": "src/fastsearch.js", | ||
@@ -5,0 +5,0 @@ "description": "Lightweight fast search / autocomplete plugin based on jQuery", |
@@ -15,2 +15,3 @@ (function(factory) { | ||
instanceNum = 0, | ||
eventStringRE = /\w\b/g, | ||
keyMap = { | ||
@@ -56,3 +57,3 @@ 13: 'enter', | ||
return events.replace(/\w\b/g, function(match) { | ||
return events.replace(eventStringRE, function(match) { | ||
return match + eventNamespace; | ||
@@ -270,2 +271,6 @@ }); | ||
if (this.options.flipOnBottom) { | ||
this.checkDropdownPosition(); | ||
} | ||
this.$resultsCont = this.$resultsCont || $('<div>').addClass(this.options.resultsContClass).appendTo(this.$el); | ||
@@ -288,3 +293,3 @@ | ||
if (this.options.focusFirstItem && this.$resultItems.length) { | ||
if (this.options.focusFirstItem && this.$resultItems && this.$resultItems.length) { | ||
this.navigateItem('down'); | ||
@@ -297,2 +302,12 @@ } | ||
checkDropdownPosition: function() { | ||
var flipOnBottom = this.options.flipOnBottom; | ||
var offset = typeof flipOnBottom === 'boolean' && flipOnBottom ? 400 : flipOnBottom; | ||
var isFlipped = this.$input.offset().top + offset > $document.height(); | ||
this.$el.toggleClass(this.options.resultsFlippedClass, isFlipped); | ||
}, | ||
documentCancelEvents: function(setup, onCancel) { | ||
@@ -501,2 +516,3 @@ | ||
resultsOpenedClass: 'fsr_opened', | ||
resultsFlippedClass: 'fsr_flipped', | ||
groupClass: 'fs_group', | ||
@@ -515,2 +531,3 @@ itemClass: 'fs_result_item', | ||
focusFirstItem: false, | ||
flipOnBottom: false, | ||
@@ -517,0 +534,0 @@ responseFormat: { // Adjust where plugin looks for data in your JSON server response |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55368
773