-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.filter.js
55 lines (53 loc) · 1.48 KB
/
jquery.filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* jQuery Filter Plugin 1.0
* www.sam-benne.co.uk
* Copyright 2012, Sam Bennett
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
;(function($){
var settings = null;
var methods = {
init: function(options) {
settings = $.extend( {
animationspeed: 250,
id: 'filter',
onCreate: null,
onDestroy: null,
onStop: null
}, options);
return this.each(function(e){
methods.create();
});
},
destroy: function() {
if(typeof settings.onDestroy === "function") settings.onDestroy.call();
},
create: function() {
$(document).on('click', '#' + settings.id + ' [data-tag]', function(e) {
e.preventDefault();
var tag = $(this).data('tag');
var regex = new RegExp(tag, "i")
$('[data-tags]').each(function(k, v) {
if($(v).data('tags').match(regex) === null) $(v).fadeOut(settings.animationspeed);
else $(v).fadeIn(settings.animationspeed);
});
});
if(typeof settings.onCreate === "function") settings.onCreate.call();
},
stop: function() {
if(typeof settings.onStop === "function") settings.onStop.call();
},
update: function(content) {
}
};
$.fn.filter = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.filter');
}
};
})(jQuery);