1/** 2 * @copyright Copyright (C) 2012 Cedric KEIFLIN alias ced1870 3 * https://www.joomlack.fr 4 * Module Accordeon CK 5 * @license GNU/GPL 6 * */ 7 8(function($) { 9 10 //define the defaults for the plugin and how to call it 11 var Accordeonmenuck = function (container, options) { 12 //set default options 13 var defaults = { 14 eventtype: 'click', 15 fadetransition: false, // pas encore implemente 16 transition: 'linear', 17 duree: 500, 18 imageplus: 'modules/mod_accordeonmenuck/assets/plus.png', 19 imageminus: 'modules/mod_accordeonmenuck/assets/minus.png', 20 // menuID : 'accordeonck', 21 defaultopenedid: '0', 22 showactive: true, 23 activeeffect: true, 24 showcounter: false, 25 closeothers: true 26 }; 27 28 if (!(this instanceof Accordeonmenuck)) return new Accordeonmenuck(container, options); 29 var accordeonmenucks = window.accordeonmenucks || []; 30 if (accordeonmenucks.indexOf(container) > -1) return; 31 accordeonmenucks.push(container); 32 window.accordeonmenucks = accordeonmenucks; 33 34 //call in the default otions 35 var options = $.extend(defaults, options); 36 var menu = $(container); 37 var menuwrap = menu.parent(); 38 39 //act upon the element that is passed into the design 40 return menu.each(function(options) { 41 if (! menu.attr('accordeonck_done')) { 42 menu.attr('accordeonck_done', '1'); 43 accordeonmenuInit(); 44 } 45 }); 46 47 function accordeonmenuInit() { 48 $(".parent > ul", menu).hide(); 49 if (options.showactive && !options.activeeffect) { 50 $(".parent.active > ul", menu).show().parent().addClass("open"); 51 $(".parent.active > img.toggler", menu).attr('src', options.imageminus); 52 } else if (options.showactive && options.activeeffect) { 53 togglemenu($(".parent.active > .toggler", menu)); 54 } 55 if (options.defaultopenedid && !$(".active.parent", menu).length) { 56 $(".item-"+options.defaultopenedid+" > ul", menu).show().parent().addClass("open"); 57 $(".item-"+options.defaultopenedid+" > img.toggler", menu).attr('src', options.imageminus); 58 } 59 if (options.eventtype == 'click') { 60 $("li.parent > .toggler", menu).click(function() { 61 togglemenu($(this)); 62 }); 63 } else { 64 $("li.parent > .toggler", menu).mouseenter(function() { 65 togglemenu($(this)); 66 }); 67 } 68 if (options.showcounter == true) { 69 if ($('.accordeonck-counter', menu).length) return; 70 $('li.accordeonck.parent', menu).each(function() { 71 // if ($('li.accordeonck', $(this)).length) { 72 var counter = '<span class="badge accordeonck-counter">' + ($('a.accordeonck', $(this)).length - 1) + '</span>'; 73 $(this).find('> .accordeonck_outer > a.accordeonck').append(counter); 74 // } 75 }); 76 } 77 // accessibility 78 $("li.parent > .toggler", menu).on('keydown', function(event) { 79 // 32 = space bar, 13 = enter, 40 = arrow down, 38 = arrow up 80// console.log(event.which); 81 if (event.which === 32 || event.which === 13 || event.which === 40 || event.which === 38) { 82 togglemenu($(this)); 83 } 84 }); 85 initSearch() 86 } 87 88 function togglemenu(link) { 89 ck_content = link.parent(); 90 if (!link.parent().hasClass("open")) { 91 if (options.closeothers != false) { 92 $(".parent > ul", ck_content.parent()).slideUp({ 93 duration: options.duree, 94 easing: options.transition, 95 complete: function() { 96 $(".parent", ck_content.parent()).removeClass("open"); 97 $(".parent > img.toggler", ck_content.parent()).attr('src', options.imageplus); 98 if (link.get(0).tagName.toLowerCase() == 'img') 99 link.attr('src', options.imageplus); 100 } 101 }); 102 } 103 link.nextAll("ul").slideDown({ 104 duration: options.duree, 105 easing: options.transition, 106 complete: function() { 107 link.parent().addClass("open"); 108 if (link.get(0).tagName.toLowerCase() == 'img') 109 link.attr('src', options.imageminus); 110 } 111 }); 112 } else { 113 link.nextAll("ul").slideUp({ 114 duration: options.duree, 115 easing: options.transition, 116 complete: function() { 117 link.parent().removeClass("open"); 118 if (link.get(0).tagName.toLowerCase() == 'img') 119 link.attr('src', options.imageplus); 120 } 121 }); 122 } 123 } 124 125 function initSearch() { 126 let searchContainer = $('.accordeonck-search', menuwrap);
127 if (! searchContainer.length) return; 128 129 menu.append('<div class="accordeonck-results"></div>'); 130 131 var searchInput = searchContainer.find('input'); 132 searchInput.on('keyup', function() { 133 doSearch(this.value); 134 }); 135 searchContainer.find('button').on('click', function() { 136 searchInput.val(''); 137 resetSearch(); 138 }); 139 $(window).on('keydown', function(event) { 140 if (event.which === 27) { 141 searchInput.val(''); 142 resetSearch(); 143 } 144 }) 145 menuwrap.find('.accordeonck-search-reset').on('click', function() { 146 searchInput.val(''); 147 resetSearch() 148 }) 149 } 150 151 function doSearch(txt) { 152 if (! txt) { 153 resetSearch(); 154 return; 155 } 156 menu.find('> li').hide(); 157 let resultContainer = $('.accordeonck-results', menuwrap); 158 resultContainer.empty().show(); 159 160 let items = new Array(); 161 [].slice.call(menu[0].querySelectorAll("a.accordeonck")) 162 .filter(a => a.textContent.toLowerCase().match(txt.toLowerCase())) 163 .forEach(function(a) { items.push(a); }); 164 165 items.forEach(function(el) { 166 resultContainer.append('<li class="accordeonck level1 accordeonck-result"><span class="accordeonck_outer">' + el.outerHTML + '</span></li>'); 167 }) 168 169 menuwrap.find('.accordeonck-search-reset').show(); 170 } 171 172 function resetSearch() { 173 $('.accordeonck-results', menuwrap).empty().hide(); 174 menu.find('> li').show(); 175 menuwrap.find('.accordeonck-search-reset').hide(); 176 } 177 }; 178 window.Accordeonmenuck = Accordeonmenuck; 179})(jQuery);
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.