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