1this.swetrackfilter = { 2 3 create: function(self, onupdate_f){ 4 5 var __onupdate = null; 6 7 var __get_selected_categories = function(){ 8 var selected_cats = []; 9 10 Array.prototype.forEach.call(document.querySelectorAll('.track-category-checkbox'), function(checkbox, i){ 11 if(swebase.dom.is_checkbox(checkbox)){ 12 if(checkbox.checked === true){ 13 if(checkbox.hasAttribute('data-category')){ 14 var cat = checkbox.getAttribute('data-category'); 15 16 if(selected_cats.indexOf(cat) === -1){ 17 selected_cats.push(cat); 18 } 19 } 20 } 21 } 22 }); 23 return selected_cats; 24 }; 25 26 var __show_all = function(){ 27 Array.prototype.forEach.call(document.querySelectorAll('.track'), function(track_node, i){ 28 track_node.setAttribute('data-visible', '1'); 29 }); 30 return self; 31 }; 32 33 self.update = function(){ 34 var selected_cats = __get_selected_categories(); 35 36 if(selected_cats.length > 0){ 37 Array.prototype.forEach.call(document.querySelectorAll('.track'), function(track_node, i){ 38 var track_cats = []; 39 40 if(track_node.hasAttribute('data-categories')){ 41 track_cats = swebase.string.split_ws(track_node.getAttribute('data-categories')); 42 43 var intersection = selected_cats.filter(function(_cat){ 44 return (track_cats.indexOf(_cat) !== -1); 45 }); 46 if(intersection.length > 0){ 47 track_node.setAttribute('data-visible', '1'); 48 49 } else { 50 track_node.setAttribute('data-visible', ''); 51 } 52 } 53 }); 54 55 } else { 56 __show_all(); 57 } 58 if(typeof __onupdate === 'function'){ 59 __onupdate(); 60 } 61 return self; 62 }; 63 64 // ========================================================================= 65 66 var __is_window_global = function(ns){ 67 for(var name in window) { 68 if(name === ns){ 69 return true; 70 } 71 } 72 return false; 73 }; 74 75 var __check = function(){ 76 var required = ['swebase']; 77 var not_found = []; 78 79 for(var i = 0; i < required.length; ++i){ 80 if(!__is_window_global(required[i])){ 81 not_found.push(required[i]); 82 } 83 } 84 if(not_found.length > 0){ 85 throw '[swetrackfilter.js] NAMESPACES NOT FOUND: '+not_found.join(', '); 86 } 87 return self; 88 }; 89 90 // =========================================================================== 91 92 __check(); 93 94 Array.prototype.forEach.call(document.querySelectorAll('.track-category-checkbox'), function(checkbox, i){ 95 if(swebase.dom.is_checkbox(checkbox)){ 96 checkbox.addEventListener('change', function(changeEvent){ 97 self.update(); 98 }); 99 } 100 }); 101 __onupdate = onupdate_f; 102 return self; 103 } 104};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.