Yaffs site version 1.1
[yaffs-website] / web / libraries / superfish / sfsmallscreen.js
similarity index 95%
rename from vendor/mehrpadin/superfish/sfsmallscreen.js
rename to web/libraries/superfish/sfsmallscreen.js
index 7a2d1981cbcff201c0e0df5ddf9e3c854a34a280..9765fedc9b7844595a5c5c5f7981610c00146475 100644 (file)
@@ -71,7 +71,7 @@
       return refined;
     }
 
-    // Creating <option> elements out of t
+    // Creating <option> elements out of the menu.
     function toSelect(menu, level){
       var
       items = '',
@@ -81,7 +81,7 @@
         for (var b = 0; b < parent.length; b++){
           var
           item = parent.eq(b),
-          path = item.is('a') ? item.attr('href') : '',
+          path = (item.is('a') && !!item.attr('href')) ? item.attr('href') : '',
           // Class names modification.
           itemClone = item.clone(),
           classes = (options.hyperlinkClasses) ? ((options.excludeClass_hyperlink && itemClone.hasClass(options.excludeClass_hyperlink)) ? itemClone.removeClass(options.excludeClass_hyperlink).attr('class') : itemClone.attr('class')) : '',
           if (options.addSelected && item.hasClass('active')){
             classes += ' active';
           }
+          classes = (classes) ? ' class="' + classes + '"' : '';
           // <option> has to be disabled if the item is not a link.
-          disable = item.is('span') || item.attr('href')=='#' ? ' disabled="disabled"' : '',
+          disable = (path == '') || (path == '#') ? ' disabled="disabled"' : '',
           // Crystal clear.
           subIndicator = 1 < level ? Array(level).join('-') + ' ' : '';
           // Preparing the <option> element.
-          items += '<option value="' + path + '" class="' + classes + '"' + disable + '>' + subIndicator + $.trim(item.text()) +'</option>',
+          items += '<option value="' + path + '"' + classes + disable + '>' + subIndicator + $.trim(item.text()) +'</option>',
           childUL = list.find('> ul');
           // Using the function for the sub-menu of this item.
           for (var u = 0; u < childUL.length; u++){
             $(this).removeAttr('style').removeClass('sfHover').attr('id', $(this).attr('id') + '-accordion');
           });
           // Doing the same and making sure all the sub-menus are off-screen (hidden).
-          accordion.find('ul').removeAttr('style').not('.sf-hidden').addClass('sf-hidden');
+          accordion.children('ul').removeAttr('style').not('.sf-hidden').addClass('sf-hidden');
           // Creating the accordion toggle switch.
           var toggle = '<div class="sf-accordion-toggle ' + styleClass + '"><a href="#" id="' + toggleID + '"><span>' + options.title + '</span></a></div>';
 
               // If the accordion is already expanded:
               // Hiding its expanded sub-menus and then the accordion itself as well.
               accordionElement.add(accordionElement.find('li.sf-expanded')).removeClass('sf-expanded')
-              .end().find('ul').hide()
+              .end().children('ul').hide()
               // This is a bit tricky, it's the same trick that has been in use in the main plugin for some time.
               // Basically we'll add a class that keeps the sub-menu off-screen and still visible,
               // and make it invisible and removing the class one moment before showing or hiding it.
           // Creating the <option> elements.
           var newMenu = toSelect(refinedMenu, 1),
           // Creating the <select> element and assigning an ID and class name.
-          selectList = $('<select class="' + classes + '" id="' + menuID + '-select"/>')
+          selectList = $('<select' + classes + ' id="' + menuID + '-select"/>')
           // Attaching the title and the items to the <select> element.
           .html('<option>' + options.title + '</option>' + newMenu)
           // Attaching an event then.
       if (options.type == 'accordion'){
         $(id + '-toggle').parent('div').remove();
       }
-      // Crystal clear!
-      $(id).show();
+      // Remove inline CSS display property; less clear than simply using .show(), but respects stylesheet
+      $(id).css('display', '');
     }
 
     // Return original object to support chaining.