arielsalminen / TinyNav.js

Responsive navigation plugin that weighs just 443 bytes
http://tinynav.viljamis.com/
635 stars 207 forks source link

Limit the depth and use active class is broken #39

Open ghost opened 11 years ago

ghost commented 11 years ago

The current implementation select the active option using the :eq() selection. But this doesnt work with the lasted feature specific depth.

Here is my modification:

    // Build options
    var options = '';

    $nav
      .addClass('l_' + namespace_i)
      .find('a')
      .each(function () {
        if($(this).parents('ul, ol').length < settings.depth + 1 || settings.depth == 0){
          options += '<option value="' + $(this).attr('href') + '"';
          if (!settings.header) {
            if ($(this).parent().hasClass(settings.active)) {
                options += ' selected="selected"';
            }
          }
          options += '>';
          var j;
          for (j = 0; j < $(this).parents('ul, ol').length - 1; j++) {
            options += '- ';
          }
          options += $(this).text() + '</option>';
        }
      });

    // Append options into a select
    $select.append(options);

    // Select the active item
    /*if (!settings.header) {
      $select
        .find(':eq(' + $(l_namespace_i + ' li').index($(l_namespace_i + ' li.' + settings.active)) + ')')
        .attr('selected', true);
    }*/
LRotherfield commented 11 years ago

I have updated the select active method https://github.com/LRotherfield/TinyNav.js/commit/c17e979b716da824a80cd0a0a3c4f9845de139bc it feels a little convoluted considering its added another 20% of the entire file size so if you can rewrite it in a nicer way please do