/* * sf-Smallscreen v1.2b - Provides small-screen compatibility for the jQuery Superfish plugin. * * Developer's note: * Built as a part of the Superfish project for Drupal (http://drupal.org/project/superfish) * Found any bug? have any cool ideas? contact me right away! http://drupal.org/user/619294/contact * * jQuery version: 1.3.x or higher. * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ (function($){ $.fn.sfsmallscreen = function(options){ options = $.extend({ mode: 'inactive', type: 'accordion', breakpoint: 768, breakpointUnit: 'px', useragent: '', title: '', addSelected: false, menuClasses: false, hyperlinkClasses: false, excludeClass_menu: '', excludeClass_hyperlink: '', includeClass_menu: '', includeClass_hyperlink: '', accordionButton: 1, expandText: 'Expand', collapseText: 'Collapse' }, options); // We need to clean up the menu from anything unnecessary. function refine(menu){ var refined = menu.clone(), // Things that should not be in the small-screen menus. rm = refined.find('span.sf-sub-indicator, span.sf-description'), // This is a helper class for those who need to add extra markup that shouldn't exist // in the small-screen versions. rh = refined.find('.sf-smallscreen-remove'), // Mega-menus has to be removed too. mm = refined.find('ul.sf-megamenu'); for (var a = 0; a < rh.length; a++){ rh.eq(a).replaceWith(rh.eq(a).html()); } for (var b = 0; b < rm.length; b++){ rm.eq(b).remove(); } if (mm.length > 0){ mm.removeClass('sf-megamenu'); var ol = refined.find('div.sf-megamenu-column > ol'); for (var o = 0; o < ol.length; o++){ ol.eq(o).replaceWith(''); } var elements = ['div.sf-megamenu-column','.sf-megamenu-wrapper > ol','li.sf-megamenu-wrapper']; for (var i = 0; i < elements.length; i++){ obj = refined.find(elements[i]); for (var t = 0; t < obj.length; t++){ obj.eq(t).replaceWith(obj.eq(t).html()); } } refined.find('.sf-megamenu-column').removeClass('sf-megamenu-column'); } refined.add(refined.find('*')).css({width:''}); return refined; } // Creating ', childUL = list.find('> ul'); // Using the function for the sub-menu of this item. for (var u = 0; u < childUL.length; u++){ items += toSelect(childUL.eq(u), level + 1); } } } return items; } // Create the new version, hide the original. function convert(menu){ var menuID = menu.attr('id'), // Creating a refined version of the menu. refinedMenu = refine(menu); // Currently the plugin provides two reactions to small screens. // Converting the menu to a element does not exist already. if ($('#' + menuID + '-select').length == 0){ // Creating the ' + newMenu) // Attaching an event then. .change(function(){ // Except for the first option that is the menu title and not a real menu item. if ($('option:selected', this).index()){ window.location = selectList.val(); } }); // Applying the addSelected option to it. if (options.addSelected){ selectList.find('.active').attr('selected', !0); } // Finally inserting the