-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#104 closed: "Change users grid to a simpler list"
- Loading branch information
Showing
5 changed files
with
122 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
(function($) { | ||
/** Plugin Main Function */ | ||
$.fn.livefilter = function(action, opts) { | ||
if (typeof action === "undefined") { | ||
action = "init"; | ||
} | ||
if (typeof action === "object") { | ||
opts = action; | ||
action = "init"; | ||
} | ||
if (action === "init") { | ||
opts = $.extend({}, $.fn.livefilter.defaults, opts); | ||
$(this).data("lf-data", opts); | ||
$(this).unbind(".livefilter").bind("keyup.livefilter", $.fn.livefilter.onKey(opts)); | ||
} else if (action === "destroy") { | ||
opts = $(this).data("lf-data"); | ||
$(opts.selector).filter("." + opts.hiddenClass)[opts.showFn](); | ||
$(this).unbind(".livefilter"); | ||
} | ||
return $(this); | ||
}; | ||
|
||
/** keyup event action */ | ||
$.fn.livefilter.onKey = function(opts) { | ||
var rv = function() { | ||
var v = $(this).val(); | ||
if (v) { | ||
$(opts.selector).filter(":icontains(" + v + ")")[opts.showFn]().removeClass(opts.hiddenClass).end().filter(":not(:icontains(" + v + "))")[opts.hideFn]().addClass(opts.hiddenClass); | ||
} else { | ||
$(opts.selector).removeClass(opts.hiddenClass)[opts.showFn](); | ||
} | ||
}; | ||
if (opts.debounce) { | ||
rv = $.fn.livefilter.debounce(rv, opts.debounce); | ||
} | ||
return rv; | ||
}; | ||
|
||
/** Delay execution of too frequent tasks*/ | ||
$.fn.livefilter.debounce = function(func, threshold) { | ||
var timeout; | ||
return function debounced() { | ||
var obj = this, args = arguments; | ||
function delayed() { | ||
func.apply(obj, args); | ||
timeout = null; | ||
} | ||
if (timeout) clearTimeout(timeout); | ||
timeout = setTimeout(delayed, threshold || 100); | ||
}; | ||
}; | ||
|
||
/** Case insensitive :contains jQuery pseudo selector */ | ||
$.expr[":"].icontains = function(obj, index, meta, stack) { | ||
return (obj.textContent || obj.innerText || jQuery(obj).text() || "").toLowerCase().indexOf(meta[3].toLowerCase()) >= 0; | ||
}; | ||
|
||
/** Plugin global defaults */ | ||
$.fn.livefilter.defaults = { | ||
selector: "tbody tr", | ||
debounce: 500, | ||
|
||
hiddenClass: "lf-hidden", | ||
showFn: "show", | ||
hideFn: "hide" | ||
}; | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters