|
35 | 35 |
|
36 | 36 | // We need to clean up the menu from anything unnecessary. |
37 | 37 | function refine(menu){ |
38 | | - var |
39 | | - refined = menu.clone(), |
| 38 | + var refined = menu.clone(); |
40 | 39 | // Things that should not be in the small-screen menus. |
41 | | - rm = refined.find('span.sf-sub-indicator'), |
| 40 | + var rm = refined.find('span.sf-sub-indicator'); |
42 | 41 | // This is a helper class for those who need to add extra markup that shouldn't exist |
43 | 42 | // in the small-screen versions. |
44 | | - rh = refined.find('.sf-smallscreen-remove'), |
| 43 | + var rh = refined.find('.sf-smallscreen-remove'); |
45 | 44 | // Mega-menus has to be removed too. |
46 | | - mm = refined.find('ul.sf-multicolumn'); |
| 45 | + var mm = refined.find('ul.sf-multicolumn'); |
47 | 46 | for (var a = 0; a < rh.length; a++){ |
48 | 47 | rh.eq(a).replaceWith(rh.eq(a).html()); |
49 | 48 | } |
|
73 | 72 |
|
74 | 73 | // Creating <option> elements out of the menu. |
75 | 74 | function toSelect(menu, level){ |
76 | | - var |
77 | | - items = '', |
78 | | - childLI = $(menu).children('li'); |
| 75 | + var items = ''; |
| 76 | + var childLI = $(menu).children('li'); |
79 | 77 | for (var a = 0; a < childLI.length; a++){ |
80 | 78 | var list = childLI.eq(a), parent = list.children('a, span'); |
81 | 79 | for (var b = 0; b < parent.length; b++){ |
|
109 | 107 |
|
110 | 108 | // Create the new version, hide the original. |
111 | 109 | function convert(menu){ |
112 | | - var menuID = menu.attr('id'), |
| 110 | + var menuID = menu.attr('id'); |
113 | 111 | // Creating a refined version of the menu. |
114 | | - refinedMenu = refine(menu); |
| 112 | + var refinedMenu = refine(menu); |
115 | 113 | // Currently the plugin provides two reactions to small screens. |
116 | 114 | // Converting the menu to a <select> element, and converting to an accordion version of the menu. |
117 | 115 | if (options.type == 'accordion'){ |
118 | | - var |
119 | | - toggleID = menuID + '-toggle', |
120 | | - accordionID = menuID + '-accordion'; |
| 116 | + var toggleID = menuID + '-toggle'; |
| 117 | + var accordionID = menuID + '-accordion'; |
121 | 118 | // Making sure the accordion does not exist. |
122 | 119 | if ($('#' + accordionID).length == 0){ |
123 | | - var |
124 | 120 | // Getting the style class. |
125 | | - styleClass = menu.attr('class').split(' ').filter(function(item){ |
| 121 | + var styleClass = menu.attr('class').split(' ').filter(function(item){ |
126 | 122 | return item.indexOf('sf-style-') > -1 ? item : ''; |
127 | | - }), |
| 123 | + }); |
128 | 124 | // Creating the accordion. |
129 | | - accordion = $(refinedMenu).attr('id', accordionID); |
| 125 | + var accordion = $(refinedMenu).attr('id', accordionID); |
130 | 126 | // Removing unnecessary classes. |
131 | 127 | accordion.removeClass('sf-horizontal sf-vertical sf-navbar sf-shadow sf-js-enabled'); |
132 | 128 | // Adding necessary classes. |
|
155 | 151 | // Inserting the according and hiding the original menu. |
156 | 152 | menu.before(toggle).before(accordion).hide(); |
157 | 153 |
|
158 | | - var |
159 | | - accordionElement = $('#' + accordionID), |
| 154 | + var accordionElement = $('#' + accordionID); |
160 | 155 | // Deciding what should be used as accordion buttons. |
161 | | - buttonElement = (options.accordionButton < 2) ? 'a.menuparent,span.nolink.menuparent' : 'a.sf-accordion-button', |
162 | | - button = accordionElement.find(buttonElement); |
| 156 | + var buttonElement = (options.accordionButton < 2) ? 'a.menuparent,span.nolink.menuparent' : 'a.sf-accordion-button'; |
| 157 | + var button = accordionElement.find(buttonElement); |
163 | 158 |
|
164 | 159 | // Attaching a click event to the toggle switch. |
165 | 160 | $('#' + toggleID).on('click', function(e){ |
|
244 | 239 | // Class names modification. |
245 | 240 | menuClone = menu.clone(), classes = (options.menuClasses) ? ((options.excludeClass_menu && menuClone.hasClass(options.excludeClass_menu)) ? menuClone.removeClass(options.excludeClass_menu).attr('class') : menuClone.attr('class')) : '', |
246 | 241 | classes = (options.includeClass_menu && !menuClone.hasClass(options.includeClass_menu)) ? ((options.menuClasses) ? menuClone.addClass(options.includeClass_menu).attr('class') : options.includeClass_menu) : classes, |
247 | | - classes = (classes) ? ' class="' + classes + '"' : ''; |
| 242 | + classes = classes ? ' class="' + classes + '"' : ''; |
248 | 243 |
|
249 | 244 | // Making sure the <select> element does not exist already. |
250 | 245 | if ($('#' + menuID + '-select').length == 0){ |
251 | 246 | // Creating the <option> elements. |
252 | | - var newMenu = toSelect(refinedMenu, 1), |
| 247 | + var newMenu = toSelect(refinedMenu, 1); |
253 | 248 | // Creating the <select> element and assigning an ID and class name. |
254 | | - selectList = $('<select ' + classes + ' id="' + menuID + '-select"/>') |
| 249 | + var selectList = $('<select ' + classes + ' id="' + menuID + '-select"/>') |
255 | 250 | // Attaching the title and the items to the <select> element. |
256 | 251 | .html('<option>' + options.title + '</option>' + newMenu) |
257 | 252 | // Attaching an event then. |
|
273 | 268 |
|
274 | 269 | // Turn everything back to normal. |
275 | 270 | function turnBack(menu){ |
276 | | - var |
277 | | - id = '#' + menu.attr('id'); |
| 271 | + var id = '#' + menu.attr('id'); |
278 | 272 | // Removing the small screen version. |
279 | 273 | $(id + '-' + options.type).remove(); |
280 | 274 | // Removing the accordion toggle switch as well. |
|
288 | 282 | // Return original object to support chaining. |
289 | 283 | // Although this is unnecessary because of the way the module uses these plugins. |
290 | 284 | for (var s = 0; s < this.length; s++){ |
291 | | - var |
292 | | - menu = $(this).eq(s), |
293 | | - mode = options.mode; |
| 285 | + var menu = $(this).eq(s); |
| 286 | + var mode = options.mode; |
294 | 287 | // The rest is crystal clear, isn't it? :) |
295 | 288 | if (menu.children('li').length == 0){ |
296 | 289 | // Skip empty menu which will not be visible and don't want to suddenly make it visible. |
|
0 commit comments