|
1 | 1 | $(function () { |
2 | 2 |
|
3 | | - var current = 'all'; |
4 | | - function doSwitch (which) { |
5 | | - if (which == current) return; |
6 | | - current = which; |
| 3 | + var $allPluginsLinkElement = $('#all'); |
| 4 | + var current = $('#all'); |
| 5 | + var $pluginElement = $('.plug_list_scratch'); |
| 6 | + var $allPlugins = $('#plugins article'); |
| 7 | + function doSwitch ($linkElement) { |
| 8 | + if ($linkElement[0] == current) return; |
| 9 | + current = $linkElement[0]; |
7 | 10 |
|
8 | 11 | $('html,body').animate({ |
9 | 12 | scrollTop: 0 |
10 | 13 | }); |
11 | 14 |
|
12 | | - var $plugins = $('.plug_list.' + which + ' article'); |
13 | | - $('#ptags > .tag').removeClass('active'); |
14 | | - $('#ptags > .tag > #' + which).parent('.tag').addClass('active'); |
15 | | - $('.plug_list_scratch') |
16 | | - .quicksand($plugins, { |
17 | | - attribute: 'id' |
| 15 | + var $plugins; |
| 16 | + |
| 17 | + $('#ptags > .tag.active').removeClass('active'); |
| 18 | + $allPlugins.removeClass('hidden'); |
| 19 | + if ($linkElement[0] === $allPluginsLinkElement[0]) { |
| 20 | + $plugins = $(); |
| 21 | + } else { |
| 22 | + var keywords = $linkElement.data('keywords'); |
| 23 | + $plugins = $allPlugins.filter(function (index, element) { |
| 24 | + elementKeywords = $(element).data('keywords'); |
| 25 | + if (!elementKeywords || !elementKeywords.length) return true; |
| 26 | + for (var i in keywords) { |
| 27 | + if (elementKeywords.indexOf(keywords[i]) !== -1) { |
| 28 | + return false; |
| 29 | + } |
| 30 | + } |
| 31 | + return true; |
18 | 32 | }); |
| 33 | + } |
| 34 | + $plugins.addClass('hidden'); |
| 35 | + $linkElement.parent('.tag').addClass('active'); |
19 | 36 | } |
20 | 37 |
|
21 | | - $('body.plugins #ptags > .tag > .which').click(function (e) { |
22 | | - e.preventDefault(); |
23 | | - var which = $(this).attr('id'); |
24 | | - doSwitch(which); |
| 38 | + $('#ptags').on('click', '.tag > .which', function (event) { |
| 39 | + event.preventDefault(); |
| 40 | + doSwitch($(this)); |
25 | 41 | }); |
26 | 42 |
|
27 | | - $('body.plugins #ptags > .tag > span.reset').click(function (e) { |
28 | | - e.preventDefault(); |
| 43 | + $('#ptags').on('click', '.tag > span.reset', function (event) { |
| 44 | + event.preventDefault(); |
29 | 45 | console.log('reset'); |
30 | | - doSwitch('all'); |
| 46 | + doSwitch($allPluginsLinkElement); |
31 | 47 | }); |
32 | 48 |
|
33 | 49 | }); |
0 commit comments