1var WA = WA || {}; 2 3WA.ResponsiveMenu = function(areaSelector) { 4 this.area_ = $(areaSelector); 5 this.openedMenu_ = null; 6 this.openedMenuEl_ = null; 7}; 8 9/** 10 * @private 11 */ 12WA.ResponsiveMenu.prototype.area_ = null; 13 14/** 15 * @private 16 */ 17WA.ResponsiveMenu.prototype.originalEshopMenu_ = null; 18 19/** 20 * @private 21 */ 22WA.ResponsiveMenu.prototype.originalArticleMenu_ = null; 23 24/** 25 * @private 26 */ 27WA.ResponsiveMenu.prototype.articleData_ = []; 28 29/** 30 * @private 31 */ 32WA.ResponsiveMenu.prototype.eshopData_ = []; 33 34/** 35 * @private 36 */ 37WA.ResponsiveMenu.prototype.articleArea_ = null; 38 39/** 40 * @private 41 */ 42WA.ResponsiveMenu.prototype.eshopArea_ = null; 43 44/** 45 * @private 46 */ 47WA.ResponsiveMenu.prototype.history_ = { eshop: [], article: [] }; 48 49/** 50 * @private 51 * @returns {array} 52 */ 53WA.ResponsiveMenu.prototype.getHistory_ = function() { 54 return this.history_[this.openedMenu_]; 55}; 56 57/** 58 * @private 59 * @returns {Object} 60 */ 61WA.ResponsiveMenu.prototype.historyPop_ = function() { 62 return this.getHistory_().pop(); 63}; 64 65/** 66 * @private 67 * @param {object} object 68 */ 69WA.ResponsiveMenu.prototype.historyPush_ = function(object) { 70 this.getHistory_().push({ 71 href: object.attr('href'), 72 text: object.text(), 73 node: object.get(0), 74 parentNode: object.parent().get(0) 75 }); 76}; 77 78/** 79 * @private 80 * @returns {int} 81 */ 82WA.ResponsiveMenu.prototype.historyCount_ = function() { 83 return this.getHistory_().length; 84}; 85 86/** 87 * @private 88 * @param {int} steps 89 * @returns {Object} 90 */ 91WA.ResponsiveMenu.prototype.historyGetStepBack_ = function(steps) { 92 return this.getHistory_()[this.historyCount_() - steps] 93}; 94 95/** 96 * @param {String} selector 97 */ 98WA.ResponsiveMenu.prototype.setEshopSelector = function(selector) { 99 this.originalEshopMenu_ = $(selector); 100}; 101 102/** 103 * @param {String} selector 104 */ 105WA.ResponsiveMenu.prototype.setArticleSelector = function(selector) { 106 this.originalArticleMenu_ = $(selector); 107}; 108 109/** 110 * @param {String} selector 111 */ 112WA.ResponsiveMenu.prototype.render = function() { 113 this.eshopData_ = this.getEshopData_(); 114 this.articleData_ = this.getArticleData_(); 115 this.insertDataToDocument_(); 116 if(this.originalEshopMenu_.hasClass('masonry_enabled')){ 117 this.runMasonry_(); 118 } 119}; 120 121/** 122 * @private 123 */ 124WA.ResponsiveMenu.prototype.getEshopData_ = function() { 125 var isClicableMenu = this.originalEshopMenu_.attr('class') == 'menu-typ-1'; 126 var eshopMenuRoot = this.originalEshopMenu_.find('.root-eshop-menu'); 127 return this.getEshopMenuChildren_(eshopMenuRoot, isClicableMenu); 128}; 129 130/** 131 * @private 132 * @param {Object} parentNode jQuery object 133 * @param {Boolean} isClicableMenu 134 */ 135WA.ResponsiveMenu.prototype.getEshopMenuChildren_ = function(parentNode, isClicableMenu) { 136 var listLi = parentNode 137 .children('li') 138 .filter(function() { 139 return !/home-button/.test(this.className); 140 }) 141 .filter(":not(.item-extra)"); 142 var this_ = this; 143 var data = []; 144 $.each(listLi, function(key, value) { 145 var li = $(value); 146 var idMenu = this_.getEshopIdMenu_(li.attr('class'), true); 147 var anchor = li.children('a'); 148 var match = /level-(\d+)/.exec(parentNode[0].className); 149 var level = match ? parseInt(match[1]) : false; 150 if(!anchor.length) { 151 if(level) { 152 anchor = li.find("a.item-link.level-" + level); 153 } else { 154 anchor = li.find("a.item-link").eq(0); 155 } 156 } 157 var href = anchor.attr('href'); 158 var children = []; 159 var text = anchor.text().trim(); 160 var isDir = false; 161 162 if (li.children('.eshop-submenu').is('ul')) { 163 children = this_.getEshopMenuChildren_(li.children('.eshop-submenu'), isClicableMenu); 164 isDir = true; 165 } else { 166 if(level) 167 { 168 children = this_.getEshopMenuChildren_(li.find(".eshop-submenu.menu-level-" + (level + 1)), isClicableMenu); 169 } else { 170 children = this_.getEshopMenuChildren_(li.find(".eshop-sbumenu").eq(0), isClicableMenu); 171 } 172 isDir = !!children.length; 173 } 174 if(isClicableMenu && li.next('.eshop-submenu').is('ul')) { 175 children = this_.getEshopMenuChildren_(li.next('.eshop-submenu'), isClicableMenu); 176 isDir = true; 177 } 178 179 var isSeparator = false;
180 var separatorResult = new RegExp("category-menu-sep-([0-9]+)").exec(li.attr('class')); 181 if (separatorResult !== null) { 182 isSeparator = true; 183 text = li.text(); 184 } 185 186 data[key] = { 187 idMenu: parseInt(idMenu), 188 isSeparator: isSeparator, 189 isDir: isDir, 190 href: href, 191 text: text, 192 originalClasses: li.attr('class'), 193 children: children 194 }; 195 }); 196 return data; 197}; 198 199/** 200 * @private 201 * @param {string} classes 202 * @return {Number} 203 */ 204WA.ResponsiveMenu.prototype.getEshopIdMenu_ = function(classes, isSubmenu) { 205 206 var regexString = "category-menu-([0-9]+)"; 207 if (isSubmenu === true) { 208 regexString = "category-submenu-([0-9]+)"; 209 } 210 var pattern = new RegExp(regexString); 211 var result = pattern.exec(classes); 212 if (result === null) { 213 return 0; 214 } 215 return result[1]; 216}; 217 218/** 219 * @private 220 */ 221WA.ResponsiveMenu.prototype.getArticleData_ = function() { 222 var data = []; 223 var this_ = this; 224 var length = this.originalArticleMenu_.children('ul').length; 225 if(length) { 226 $.each(this.originalArticleMenu_.children('ul'), function(key, value) { 227 var fakeFirstLevel = $(value); 228 if (length > 1) 229 { 230 data[key] = this_.getArticleMenuChildren_(fakeFirstLevel); 231 } 232 else 233 { 234 data = this_.getArticleMenuChildren_(fakeFirstLevel); 235 } 236 }); 237 } else { 238 data = this.getArticleMenuChildren_(this.originalArticleMenu_.find(".root-article-menu")); 239 } 240 if(BS.Design.is_new_menu_tmpl(BS.Design.template.name)) 241 { 242 data = this.getArticleMenuChildren_($('#new_template_row li[class^="eshop-menu-"]')) 243 } 244 return data; 245}; 246 247/** 248 * @private 249 * @param {Object} parentNode jQuery object 250 */ 251WA.ResponsiveMenu.prototype.getArticleMenuChildren_ = function(parentNode, isSubmenu) { 252 var listLi = parentNode.children('li'); 253 if(BS.Design.is_new_menu_tmpl(BS.Design.template.name) && !isSubmenu) 254 { 255 listLi = parentNode; 256 } 257 var data = []; 258 var this_ = this; 259 $.each(listLi, function(key, value) { 260 var li = $(value); 261 var idMenu = this_.getArticleIdMenu_(li.attr('class'), isSubmenu); 262 var anchor = li.children('a'); 263 var children = []; 264 var href = anchor.attr('href'); 265 var isDir = false; 266 if (li.children('ul').is('ul')) { 267 children = this_.getArticleMenuChildren_(li.children('ul'), true); 268 isDir = true; 269 } 270 271 data[key] = { 272 idMenu: idMenu, 273 isSeparator: false, 274 isDir: isDir, 275 href: href, 276 text: anchor.text().trim(), 277 originalClasses: li.attr('class'), 278 children: children 279 }; 280 }); 281 return data; 282}; 283 284 285/** 286 * @private 287 * @param {string} classes 288 * @return {Number} 289 */ 290WA.ResponsiveMenu.prototype.getArticleIdMenu_ = function(classes, isSubmenu) { 291 292 var regexString = "eshop-menu-([0-9]+)"; 293 if (isSubmenu === true) { 294 regexString = "eshop-submenu-([0-9]+)"; 295 } 296 var pattern = new RegExp(regexString); 297 var result = pattern.exec(classes); 298 if (result === null) { 299 return 0; 300 } 301 return result[1]; 302}; 303 304/** 305 * @private 306 */ 307WA.ResponsiveMenu.prototype.insertDataToDocument_ = function() { 308 this.createMenuWrappers_(); 309 this.area_.append(this.eshopArea_); 310 this.area_.append(this.articleArea_); 311 this.registerEvents_(); 312}; 313 314/** 315 * @private 316 */ 317WA.ResponsiveMenu.prototype.createMenuWrappers_ = function() { 318 this.articleArea_ = $('<div/>').addClass('responsive-menu-button article-menu-button').text(responsive_articlemenu_name) 319 .append($('<div/>').addClass('mobile-menu-content').css('display', 'none') 320 .append(this.renderMenuTree_(this.articleData_))); 321 322 if(typeof responsive_eshopmenu_name != 'undefined') { 323 this.eshopArea_ = $('<div/>').addClass('responsive-menu-button eshop-menu-button').text(responsive_eshopmenu_name) 324 .append($('<div/>').addClass('mobile-menu-content').css('display', 'none') 325 .append(this.renderMenuTree_(this.eshopData_))); 326 } else { 327 this.eshopArea_ = $('<div/>'); 328 } 329 330 this.articleArea_.append(('<div class="fixed-parent-node"><span class="direct-link-text"></span><a href=""></a></div>')); 331 this.eshopArea_.append(('<div class="fixed-parent-node"><span class="direct-link-text"></span><a href=""></a></div>')); 332}; 333 334WA.ResponsiveMenu.prototype.renderMenuTree_ = function(data) { 335 var branche = $('<ul/>'); 336 var this_ = this; 337 338 $.each(data, function(key, itemData) { 339 var realData = itemData[0]; 340 if (typeof itemData[0] == "undefined") { 341 realData = itemData; 342 } 343 var li = $('<li/>').attr('class', realData.originalClasses); 344 if (!realData.isDir) { 345 li.addClass('direct-link'); 346 } else { 347 li.addClass('is-directory'); 348 } 349 if (realData.isSeparator) { 350 li.addClass('is-separator'); 351 li.text(realData.text); 352 } 353 354 if (typeof realData.href != "undefined") { 355 var anchor = $('<a/>').attr('href', realData.href).text(realData.text); 356 li.append(anchor) 357 } 358 359 if (realData.children.length) { 360 var children = this_.renderMenuTree_(realData.children); 361 li.append(children); 362 } 363 364 branche.append(li); 365 }); 366 return branche; 367}; 368 369WA.ResponsiveMenu.prototype.registerEvents_ = function() { 370 var this_ = this; 371 this_.articleArea_.on('click', function(event) { 372 this_.openedMenu_ = "article";
373 this_.displayMenu_($(event.currentTarget)); 374 }); 375 this_.eshopArea_.on('click', function(event) { 376 this_.openedMenu_ = "eshop"; 377 this_.displayMenu_($(event.currentTarget)); 378 }); 379 $('.mobile-menu-content li.is-directory > a').on('click', function(event) { 380 var mobileMenuContent = this_.openedMenuEl_.find(".mobile-menu-content").eq(0); 381 var mobileMenuContentUl = mobileMenuContent.find("ul"); 382 mobileMenuContentUl 383 .removeClass("visible") 384 .removeAttr("style"); 385 mobileMenuContent.next('.fixed-parent-node').removeClass('root'); 386 var subCategory = $(event.currentTarget).next('ul'); 387 subCategory.addClass('visible'); 388 subCategory.parents('ul').css('zIndex', 20); 389 this_.changeFixedParent_($(event.currentTarget)); 390 this_.historyPush_($(event.currentTarget)); 391 event.preventDefault(); 392 event.stopPropagation(); 393 }); 394 $('.mobile-menu-content li.direct-link > a').on('click', function(event) { 395 event.stopPropagation(); 396 }); 397 $('.fixed-parent-node .direct-link-text').on('click', function(event){ 398 var previousCategory = this_.historyGetStepBack_(2); 399 var mobileMenuContent = this_.openedMenuEl_.find(".mobile-menu-content").eq(0); 400 var mobileMenuContentUl = mobileMenuContent.find("ul"); 401 if(typeof previousCategory != "undefined") { 402 this_.changeFixedParent_($(previousCategory.node)); 403 mobileMenuContentUl.removeClass("visible"); 404 $(previousCategory.parentNode).children('ul').addClass('visible'); 405 } else { 406 mobileMenuContentUl.removeClass("visible"); 407 var fixedParentNode = this_.openedMenuEl_.find(".fixed-parent-node").eq(0); 408 fixedParentNode.addClass("root"); 409 fixedParentNode.find(".direct-link-text").text(""); 410 fixedParentNode.find("a").attr("href", "").text("").removeClass("active"); 411 } 412 this_.historyPop_(); 413 event.preventDefault(); 414 event.stopPropagation(); 415 }); 416}; 417 418/** 419 * @param {Object} parentNode jQuery object 420 */ 421WA.ResponsiveMenu.prototype.displayMenu_ = function(parentNode) { 422 this.openedMenuEl_ = parentNode; 423 var content = parentNode.children('.mobile-menu-content'); 424 if (content.css('display') === 'block') { 425 content.css('display', 'none'); 426 content.next('.fixed-parent-node').removeClass('root'); 427 content.next('.fixed-parent-node').removeClass('visible'); 428 } else { 429 content.css('display', 'block'); 430 var addClass = "visible"; 431 if(this.historyCount_() === 0) { 432 addClass += " root"; 433 } 434 content.next('.fixed-parent-node').addClass(addClass); 435 } 436}; 437 438/** 439 * @private 440 * @param {Object} actualLi jQuery object 441 */ 442WA.ResponsiveMenu.prototype.changeFixedParent_ = function(actualLi) { 443 444 var menuContent= actualLi.closest('.mobile-menu-content'); 445 var fixedParent = menuContent.next('.fixed-parent-node'); 446 var text = actualLi.text().trim(); 447 var href = actualLi.attr('href'); 448 //odstraneni nezadoucich znaku [sipka = \xbb (\u00bb)] 449 text = text.replace(/\xbb$/, ""); 450 fixedParent.children('.direct-link-text').text(text); 451 actualLi.children('a').removeClass('active'); 452 if(href !== '#' && href !== '') { 453 fixedParent.children('a').attr('href', href).addClass('active'); 454 } 455 fixedParent.addClass('visible'); 456}; 457 458/** 459 * @private 460 */ 461WA.ResponsiveMenu.prototype.runMasonry_ = function() { 462 var $container = $('.masonry_enabled .root-eshop-menu > li > ul.level-2'); 463 $container.masonry({ 464 columnWidth: 200, 465 itemSelector: '.masonry_item' 466 }); 467};
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.