bootstrap-list-filter
Advanced tools
Comparing version 0.2.1 to 0.2.2
/* | ||
* bootstrap-list-filter v0.2.1 - 2015-07-24 | ||
* bootstrap-list-filter v0.2.2 - 2015-09-21 | ||
* | ||
@@ -17,2 +17,2 @@ * Copyright 2015 Stefano Cudini | ||
*/ | ||
!function(a){a.fn.btsListFilter=function(b,c){"use strict";function d(a,b){return a.replace(/\{ *([\w_]+) *\}/g,function(a,c){return b[c]||""})}function e(a,b){var c;return b=b||300,function(){var d=this,e=arguments;clearTimeout(c),c=setTimeout(function(){a.apply(d,Array.prototype.slice.call(e))},b)}}var f,g=this,h=a(this),i=a(b),j=h;return c=a.extend({delay:300,minLength:1,initial:!0,casesensitive:!1,eventKey:"keyup",resetOnBlur:!0,sourceData:null,sourceTmpl:'<a class="list-group-item" href="#"><span>{title}</span></a>',sourceNode:function(a){return d(c.sourceTmpl,a)},emptyNode:function(a){return'<a class="list-group-item well" href="#"><span>No Results</span></a>'},itemClassTmp:"bts-dynamic-item",itemEl:".list-group-item",itemChild:null,itemFilter:function(b,d){d=d&&d.replace(new RegExp("[({[^.$*+?\\]})]","g"),"");var e=a(b).text(),f=c.initial?"^":"",g=new RegExp(f+d,c.casesensitive?"":"i");return g.test(e)}},c),i.on(c.eventKey,e(function(b){var d=a(this).val();c.itemEl&&(j=h.find(c.itemEl)),c.itemChild&&(j=j.find(c.itemChild));var e=j.filter(function(){return c.itemFilter.call(g,this,d)}),i=j.not(e);c.itemChild&&(e=e.parents(c.itemEl),i=i.parents(c.itemEl).hide()),""!==d&&d.length>=c.minLength?(e.show(),i.hide(),"function"===a.type(c.sourceData)?(e.hide(),i.hide(),f&&(a.isFunction(f.abort)?f.abort():a.isFunction(f.stop)&&f.stop()),f=c.sourceData.call(g,d,function(b){if(f=null,e.hide(),i.hide(),h.find("."+c.itemClassTmp).remove(),b&&0!==b.length)for(var d in b)a(c.sourceNode.call(g,b[d])).addClass(c.itemClassTmp).appendTo(h);else a(c.emptyNode.call(g)).addClass(c.itemClassTmp).appendTo(h)})):(h.find("."+c.itemClassTmp).remove(),0===e.length&&a(c.emptyNode.call(g)).addClass(c.itemClassTmp).appendTo(h))):(e.show(),i.show(),h.find("."+c.itemClassTmp).remove())},c.delay)),c.resetOnBlur&&i.on("blur",function(b){a(this).val("").trigger(c.eventKey)}),h}}(jQuery); | ||
!function(a){a.fn.btsListFilter=function(b,c){"use strict";function d(a,b){return a.replace(/\{ *([\w_]+) *\}/g,function(a,c){return b[c]||""})}function e(a,b){var c;return b=b||300,function(){var d=this,e=arguments;clearTimeout(c),c=setTimeout(function(){a.apply(d,Array.prototype.slice.call(e))},b)}}var f,g,h=this,i=a(this),j=a(b),k=i;return c=a.extend({delay:300,minLength:1,initial:!0,casesensitive:!1,eventKey:"keyup",resetOnBlur:!0,sourceData:null,sourceTmpl:'<a class="list-group-item" href="#"><span>{title}</span></a>',sourceNode:function(a){return d(c.sourceTmpl,a)},emptyNode:function(a){return'<a class="list-group-item well" href="#"><span>No Results</span></a>'},itemClassTmp:"bts-dynamic-item",itemEl:".list-group-item",itemChild:null,itemFilter:function(b,d){d=d&&d.replace(new RegExp("[({[^.$*+?\\]})]","g"),"");var e=a(b).text(),f=c.initial?"^":"",g=new RegExp(f+d,c.casesensitive?"":"i");return g.test(e)},cancelNode:function(){return'<span class="btn glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>'}},c),h.reset=function(){j.val("").trigger(c.eventKey)},a.isFunction(c.cancelNode)&&(f=a(c.cancelNode.call(h)),j.after(f),j.parents(".form-group").addClass("has-feedback"),j.prev().is(".control-label")||f.css({top:0}),f.on("click",h.reset)),j.on(c.eventKey,e(function(b){var d=a(this).val();c.itemEl&&(k=i.find(c.itemEl)),c.itemChild&&(k=k.find(c.itemChild));var e=k.filter(function(){return c.itemFilter.call(h,this,d)}),f=k.not(e);c.itemChild&&(e=e.parents(c.itemEl),f=f.parents(c.itemEl).hide()),""!==d&&d.length>=c.minLength?(e.show(),f.hide(),"function"===a.type(c.sourceData)?(e.hide(),f.hide(),g&&(a.isFunction(g.abort)?g.abort():a.isFunction(g.stop)&&g.stop()),g=c.sourceData.call(h,d,function(b){if(g=null,e.hide(),f.hide(),i.find("."+c.itemClassTmp).remove(),b&&0!==b.length)for(var d in b)a(c.sourceNode.call(h,b[d])).addClass(c.itemClassTmp).appendTo(i);else a(c.emptyNode.call(h)).addClass(c.itemClassTmp).appendTo(i)})):(i.find("."+c.itemClassTmp).remove(),0===e.length&&a(c.emptyNode.call(h)).addClass(c.itemClassTmp).appendTo(i))):(e.show(),f.show(),i.find("."+c.itemClassTmp).remove())},c.delay)),c.resetOnBlur&&j.on("blur",function(a){h.reset()}),i}}(jQuery); |
@@ -7,5 +7,6 @@ | ||
var searchlist = this, | ||
var self = this, | ||
searchlist$ = $(this), | ||
inputEl$ = $(inputEl), | ||
cancelEl$, | ||
items$ = searchlist$, | ||
@@ -15,20 +16,2 @@ callData, | ||
function tmpl(str, data) { | ||
return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { | ||
return data[key] || ''; | ||
}); | ||
} | ||
function debouncer(func, timeout) { | ||
var timeoutID; | ||
timeout = timeout || 300; | ||
return function () { | ||
var scope = this , args = arguments; | ||
clearTimeout( timeoutID ); | ||
timeoutID = setTimeout( function () { | ||
func.apply( scope , Array.prototype.slice.call( args ) ); | ||
}, timeout); | ||
}; | ||
} | ||
opts = $.extend({ | ||
@@ -61,7 +44,43 @@ delay: 300, | ||
return regSearch.test( text ); | ||
}, | ||
cancelNode: function() { | ||
return '<span class="btn glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>'; | ||
} | ||
}, opts); | ||
}, opts); | ||
function tmpl(str, data) { | ||
return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { | ||
return data[key] || ''; | ||
}); | ||
} | ||
function debouncer(func, timeout) { | ||
var timeoutID; | ||
timeout = timeout || 300; | ||
return function () { | ||
var scope = this , args = arguments; | ||
clearTimeout( timeoutID ); | ||
timeoutID = setTimeout( function () { | ||
func.apply( scope , Array.prototype.slice.call( args ) ); | ||
}, timeout); | ||
}; | ||
} | ||
self.reset = function() { | ||
inputEl$.val('').trigger(opts.eventKey); | ||
}; | ||
if($.isFunction(opts.cancelNode)) { | ||
cancelEl$ = $(opts.cancelNode.call(self)); | ||
inputEl$.after( cancelEl$ ); | ||
inputEl$.parents('.form-group').addClass('has-feedback'); | ||
if(!inputEl$.prev().is('.control-label')) | ||
cancelEl$.css({top: 0}) | ||
cancelEl$.on('click', self.reset); | ||
} | ||
inputEl$.on(opts.eventKey, debouncer(function(e) { | ||
@@ -78,3 +97,3 @@ | ||
var contains = items$.filter(function(){ | ||
return opts.itemFilter.call(searchlist, this, val); | ||
return opts.itemFilter.call(self, this, val); | ||
}), | ||
@@ -106,3 +125,3 @@ containsNot = items$.not(contains); | ||
callReq = opts.sourceData.call(searchlist, val, function(data) { | ||
callReq = opts.sourceData.call(self, val, function(data) { | ||
callReq = null; | ||
@@ -115,6 +134,6 @@ contains.hide(); | ||
if(!data || data.length===0) | ||
$( opts.emptyNode.call(searchlist) ).addClass(opts.itemClassTmp).appendTo(searchlist$); | ||
$( opts.emptyNode.call(self) ).addClass(opts.itemClassTmp).appendTo(searchlist$); | ||
else | ||
for(var i in data) | ||
$( opts.sourceNode.call(searchlist, data[i]) ).addClass(opts.itemClassTmp).appendTo(searchlist$); | ||
$( opts.sourceNode.call(self, data[i]) ).addClass(opts.itemClassTmp).appendTo(searchlist$); | ||
}); | ||
@@ -126,3 +145,3 @@ } | ||
if(contains.length===0) | ||
$( opts.emptyNode.call(searchlist) ).addClass(opts.itemClassTmp).appendTo(searchlist$); | ||
$( opts.emptyNode.call(self) ).addClass(opts.itemClassTmp).appendTo(searchlist$); | ||
} | ||
@@ -141,3 +160,3 @@ | ||
inputEl$.on('blur', function(e) { | ||
$(this).val('').trigger(opts.eventKey); | ||
self.reset(); | ||
}); | ||
@@ -144,0 +163,0 @@ |
{ | ||
"name": "bootstrap-list-filter", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"main": "bootstrap-list-filter.min.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/stefanocudini/bootstrap-list-filter", |
Package.describe({ | ||
version: "0.2.1", | ||
version: "0.2.2", | ||
name: "bootstrap-list-filter", | ||
@@ -4,0 +4,0 @@ summary: "bootstrap-list-filter" |
{ | ||
"name": "bootstrap-list-filter", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Search widget to filter Bootstrap lists", | ||
@@ -26,3 +26,3 @@ "main": "bootstrap-list-filter.src.js", | ||
"peerDependencies": { | ||
"bootstrap": "^3.4.5" | ||
"bootstrap": "^3.3.5" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
@@ -21,2 +21,3 @@ Bootstrap List Filter | ||
* search text in case sensitive | ||
* search text in initial position or full | ||
@@ -68,2 +69,2 @@ **Demo online:** | ||
* itemChild *sub item selector (default: .list-group-item)*, | ||
* itemFilter *function for filter results(receive: text, item)* | ||
* itemFilter *function for filter results(receive: text, item)* |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
93448
19
362
69