1/** 2 * @copyright Copyright (C) 2012 Cedric KEIFLIN alias ced1870 3 * http://www.joomlack.fr 4 * Module Maximenu CK 5 * @license GNU/GPL 6 * */ 7 8(function($) { 9 $.fn.MobileMaxiMenu = function(options) { 10 var defaults = { 11 useimages: false, 12 container: 'body', 13 showdesc: false, 14 showlogo: true, 15 usemodules: false, 16 menuid: '', 17 titletag: 'h3', 18 displaytype: 'flat' 19 }; 20 21 var opts = $.extend(defaults, options); 22 var menu = this; 23 24 return menu.each(function(options) { 25 if ($('#'+opts.menuid+'-mobile').length) 26 return; 27 if (menu.prev(opts.titletag)) 28 menu.prev(opts.titletag).addClass('hidemenumobileck'); 29 updatelevel(menu); 30 mobilemaximenuinit(); 31 if (opts.displaytype == 'accordion') 32 mobilemaximenuSetAccordeon(); 33 34 function mobilemaximenuinit() { 35 var activeitem, logoitem; 36 if ($('.maxipushdownck', menu).length) { 37 var menuitems = $(sortmenu(menu)); 38 } else { 39 var menuitems = $('ul.maximenuck li', menu); 40 } 41 //$(document.body).append('<div id="'+opts.menuid+'-mobile" class="mobilemaximenuck"></div>'); 42 if (opts.container == 'body') { 43 $(document.body).append('<div id="'+opts.menuid+'-mobile" class="mobilemaximenuck"></div>'); 44 } else { 45 menu.after($('<div id="'+opts.menuid+'-mobile" class="mobilemaximenuck"></div>')); 46 } 47 mobilemenu = $('#'+opts.menuid+'-mobile'); 48 mobilemenuHTML = '<div class="topbar"><span class="mobilemaximenucktitle">' + CKTEXT_PLG_MAXIMENUCK_MENU + '</span><span class="mobilemaximenuckclose"></span></div>'; 49 menuitems.each(function(i, itemtmp) { 50 itemtmp = $(itemtmp); 51 if (itemanchor = validateitem(itemtmp) 52 ) { 53 mobilemenuHTML += '<div class="mobilemaximenuckitem">'; 54 // itemanchor = $('> a.maximenuck', itemtmp).length ? $('> a.maximenuck', itemtmp).clone() : $('> span.separator', itemtmp).clone(); 55 if (!opts.showdesc) { 56 if ($('span.descck', itemanchor).length) 57 $('span.descck', itemanchor).remove(); 58 } 59 itemhref = itemanchor.attr('href') ? ' href="' + itemanchor.attr('href') + '"' : ''; 60 if (opts.useimages && ($('> * > img', itemtmp).length || $('> * > * > img', itemtmp).length)) { 61 datatocopy = itemanchor.html(); 62 mobilemenuHTML +='<div class="' + itemtmp.attr('class') + '"><a ' + itemhref + '>' + datatocopy + '</a></div>'; 63 } else if (opts.usemodules && $('> div.maximenuck_mod', itemtmp).length) { 64 datatocopy = $('> div.maximenuck_mod', itemtmp).html(); 65 mobilemenuHTML +='<div class="' + itemtmp.attr('class') + '">' + datatocopy + '</div>'; 66 } else { 67 datatocopy = $('> span.titreck', itemanchor).html(); 68 mobilemenuHTML +='<div class="' + itemtmp.attr('class') + '"><a ' + itemhref + '>' + datatocopy + '</a></div>'; 69 } 70 71 itemlevel = $(itemtmp).attr('data-level'); 72 j = i; 73 while (menuitems[j+1] && !validateitem(menuitems[j+1]) && j < 1000) { 74 j++; 75 } 76 if (menuitems[j+1] && validateitem(menuitems[j+1])) { 77 itemleveldiff = $(menuitems[i]).attr('data-level') - $(menuitems[j+1]).attr('data-level'); 78 if (itemleveldiff < 0) { 79 mobilemenuHTML += '<div class="mobilemaximenucksubmenu">'; 80 } 81 else if (itemleveldiff > 0) { 82 mobilemenuHTML += '</div>'; 83 mobilemenuHTML += mobilemaximenu_strrepeat('</div>', itemleveldiff); 84 } else { 85 mobilemenuHTML += '</div>'; 86 } 87 } else { 88 mobilemenuHTML += mobilemaximenu_strrepeat('</div>', itemlevel); 89 } 90 91 if (itemtmp.hasClass('current')) 92 activeitem = itemtmp.clone(); 93 if (!opts.showdesc) { 94 if ($('span.descck', $(activeitem)).length) 95 $('span.descck', $(activeitem)).remove(); 96 } 97 } //else if ($(itemtmp).hasClass('maximenucklogo')) { 98 //logoitem = $(itemtmp).clone(); 99 //} 100 }); 101 102 mobilemenu.append(mobilemenuHTML); 103 104 mobilemenu.css({ 105 'position': 'absolute', 106 'z-index': '100000', 107 'top': '0', 108 'left': '0', 109 'display': 'none' 110 }); 111 if (activeitem) { 112 if (opts.useimages) { 113 activeitemtext = activeitem.find('a.maximenuck').html(); 114 } else { 115 activeitemtext = activeitem.find('span.titreck').html(); 116 } 117 if (!activeitemtext || activeitemtext == 'undefined') activeitemtext = CKTEXT_PLG_MAXIMENUCK_MENU; 118 } else { 119 activeitemtext = CKTEXT_PLG_MAXIMENUCK_MENU; 120 } 121 if ($('.maximenucklogo', menu).length && opts.showlogo) { 122 logoitem = $('.maximenucklogo', menu).clone(); 123 $('.topbar', mobilemenu).after('<div class="' + $(logoitem).attr('class') + '">'+$(logoitem).html()+'<div style="clear:both;"></div></div>') 124 } 125 var position = (opts.container == 'body') ? 'absolute' : 'static'; 126 var mobilebutton = '<div id="'+opts.menuid+'-mobilebarmenuck" class="mobilebarmenuck" style="position:' + position + '"><span class="mobilebarmenutitleck">' + activeitemtext + '</span>' 127 + '<div class="mobilebuttonmenuck"></div>' 128 + '</div>'; 129 130 if (opts.container == 'body') { 131 $(document.body).append(mobilebutton); 132 } else { 133 menu.after(mobilebutton); 134 mobilemenu.css('position', 'static'); 135 } 136 $('.mobilebuttonmenuck', $('#'+opts.menuid+'-mobilebarmenuck')).click(function() { 137 $('.mobilemaximenuck').fadeOut(); 138 $('#'+opts.menuid+'-mobile').fadeIn(); 139 if (opts.container != 'body') $('#'+opts.menuid+'-mobilebarmenuck').css('display','none'); 140 }); 141 $('.mobilemaximenuckclose', mobilemenu).click(function() { 142 $('#'+opts.menuid+'-mobile').fadeOut(); 143 if (opts.container != 'body') $('#'+opts.menuid+'-mobilebarmenuck').css('display',''); 144 }); 145 } 146 147 function mobilemaximenuSetAccordeon() { 148 mobilemenu = $('#'+opts.menuid+'-mobile'); 149 $('.mobilemaximenucksubmenu', mobilemenu).hide(); 150 $('.mobilemaximenucksubmenu', mobilemenu).each(function(i, submenu) { 151 submenu = $(submenu); 152 itemparent = submenu.prev('.maximenuck'); 153 if ($('+ .mobilemaximenucksubmenu > div.mobilemaximenuckitem', itemparent).length) 154 $(itemparent).append('<div class="mobilemaximenutogglericon" />'); 155 }); 156 $('.mobilemaximenutogglericon', mobilemenu).click(function() { 157 itemparentsubmenu = $(this).parent().next('.mobilemaximenucksubmenu'); 158 if (itemparentsubmenu.css('display') == 'none') { 159 itemparentsubmenu.css('display', 'block'); 160 $(this).parent().addClass('open'); 161 } else { 162 itemparentsubmenu.css('display', 'none'); 163 $(this).parent().removeClass('open'); 164 } 165 }); 166 } 167 168 function updatelevel(menu) { 169 $('div.maximenuck_mod', menu).each(function(i, module) { 170 module = $(module); 171 liparentlevel = module.parent('li.maximenuckmodule').attr('data-level'); 172 $('li.maximenuck', module).each(function(j, li) { 173 li = $(li); 174 lilevel = parseInt(li.attr('data-level')) + parseInt(liparentlevel)-1; 175 li.attr('data-level', lilevel).addClass('level'+lilevel); 176 }); 177 }); 178 } 179 180 function validateitem(itemtmp) { 181 if (!itemtmp || $(itemtmp).hasClass('nomobileck')) 182 return false;
183// if (($('> a.maximenuck', itemtmp).length || $('> span.separator', itemtmp).length || $('> * > a.maximenuck', itemtmp).length || $('> * > span.separator', itemtmp).length) 184// && ($('> a.maximenuck > span.titreck', itemtmp).length || $('> span.separator > span.titreck', itemtmp).length || opts.useimages) 185// || ($('> div.maximenuck_mod', itemtmp).length && opts.usemodules) 186// && !itemtmp.hasClass('nomobileck') 187// ) 188// if ($('> * > img', itemtmp).length && opts.useimages) { 189// return $('> *', itemtmp).clone(); 190 if ($('> * > img', itemtmp).length && !opts.useimages && !$('> * > span.titreck', itemtmp).length) { 191 return false 192 } 193 if ($('> a.maximenuck', itemtmp).length) return $('> a.maximenuck', itemtmp).clone(); 194 if ($('> span.separator', itemtmp).length) return $('> span.separator', itemtmp).clone(); 195 if ($('> * > a.maximenuck', itemtmp).length) return $('> * > a.maximenuck', itemtmp).clone(); 196 if ($('> * > span.separator', itemtmp).length) return $('> * > span.separator', itemtmp).clone(); 197 if ($('> div.maximenuck_mod', itemtmp).length && opts.usemodules) return $('> div.maximenuck_mod', itemtmp).clone(); 198 199// if ($('> * > * > img', itemtmp).length && opts.useimages) return $('> * > *', itemtmp).clone(); 200// return $('> a.maximenuck', itemtmp).length ? $('> a.maximenuck', itemtmp).clone() : $('> span.separator', itemtmp).clone(); 201 return false; 202 } 203 204 function mobilemaximenu_strrepeat(string, count) { 205 if (count < 1) return ''; 206 while (count > 0) { 207 string += string; 208 count--; 209 } 210 return string; 211 } 212 213 function sortmenu(menu) { 214 var items = new Array(); 215 mainitems = $('ul.maximenuck > li.maximenuck.level1', menu); 216 j = 0; 217 mainitems.each(function(ii, mainitem) { 218 items.push(mainitem); 219 if ($(mainitem).hasClass('parent')) { 220 subitemcontainer = $('.maxipushdownck > .floatck', menu).eq(j); 221 subitems = $('li.maximenuck', subitemcontainer); 222 subitems.each(function(k, subitem) { 223 items.push(subitem); 224 }); 225 j++; 226 } 227 }); 228 return items; 229 } 230 }); 231 } 232})(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.