1 Replies - 1742 Views - Last Post: 19 December 2013 - 11:16 AM

#1 pravglad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-March 11

jquery issue

Posted 18 December 2013 - 11:30 PM

Posted Image


So the problem is for example if you look at the image above and under academics there are 15 submenus using keyboard tab key user goes through everything and once it reaches "all things international" with another click on Tab it should close and open students but it doesnt do that..i have posted the code also..please help



/**
 * @file
 * A Javascript file for the theme.
 *
 * In order for this Javascript to be loaded on pages, see the instructions in
 * the README.txt next to this file.
 */

// Javascript should be made compatible with libraries other than jQuery by
// wrapping it with an "anonymous closure". See:
// - http://drupal.org/node/1446420
// - http://www.adequatelygood.com/2010/3/Javascript-Module-Pattern-In-Depth
(function ($, Drupal, window, document, undefined) {

  /**
   * Make megamenus more keyboard-navigable with up, down, and esc keys.
   */
  $(document).ready(function() {
    // Capture keypresses when links are focused.
    $("a").keydown(function(e) {

        // Remove stuff left over from the previous keydown.
        $('.mega-menu__trigger').removeClass('hovered');

        // If it's inside a megamenu trigger, do our stuff.
        if ($(this).parent().hasClass('mega-menu__trigger')) {
          // If its next sibling is a megamenu wrapper, act on that.
          if ($(this).next().hasClass('mega-menu__wrapper')) {

            // Down arrow adds "hovered" class.
            if (e.which == 40) {
              $(this).parent().addClass('hovered');
              // First close any already-open megamenus.
              $('.mega-menu__wrapper').removeClass('hovered');
              // Now open the relevant megamenu.
              $(this).next().addClass('hovered');
              e.preventDefault();
            }

            // Up arrow removes the "hovered" class.
            else if (e.which == 38) {
              $(this).next().removeClass('hovered');
              e.preventDefault();
          }

        }

        // Use escape key or up arrow to close all megamenus.
        if ((e.which == 27) || (e.which == 38)) {
          $('.mega-menu__wrapper').removeClass('hovered');
          e.preventDefault();
        }
      }

      // Escape key will also work outside of megamenus to get rid of the menu.
      if (e.which == 27) {
        $('.mega-menu__wrapper').removeClass('hovered');
        e.preventDefault();
      }
    });
  });

  Drupal.behaviors.csunThemeLoad = {
    attach: function (context, settings) {
      // Use jQuery UI Accordion.
      $accordion = $('#accordion', context);
      if ($accordion.length) {
        $accordion.accordion({
          collapsible: true,
          active: false,
          heightStyle: "content"
        });
      }
      // Add tr class on even/odd in wysiwyg
      $('.field-name-field-body tr:even').addClass('even');
      $('.field-name-field-body tr:odd').addClass('odd');
      // Remove tab index for accordian
      $(".ui-accordion-header").attr("tabindex",0);
    }
  };

/*
  //keyboard accordion navigation fix
  $(document).keydown(function(event){    
    var key = event.which;                
      switch(key) {
        case 38:
          // Key up.
          $(".field.field-name-field-title-text.field-type-text.field-label-hidden.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all").attr("tabindex","0");
          break;
        case 40:
          // Key down.
          $(".field.field-name-field-title-text.field-type-text.field-label-hidden.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all").attr("tabindex","0");
          break;
        case 9:
          // Key tab.
          $(".field.field-name-field-title-text.field-type-text.field-label-hidden.ui-accordion-header.ui-helper-reset.ui-state-default.ui-corner-all").attr("tabindex","0");
          break;
        }   
  });
*/

  Drupal.behaviors.csunSlideshow = {
    attach: function(context, settings) {

      var $slideWrapper = $('.slide-wrapper', context);

      // If only one item, don't run flexslider.
      var slideshowSize = $slideWrapper.find('figure').size();

      if (slideshowSize > 1) {
        $slideWrapper
          // Setup the flexslider.
          .flexslider({
            animation: "slide",
            pauseOnHover: false, /* EZ CHANGE was true */
            pausePlay: true,  /* EZ CHANGE */
            keyboard: true
          })
          // Remove the "flexslider-off" class.
          .removeClass('flexslider-off');
        $slideWrapper
          .find('.flex-direction-nav li:first-child')
          .after('<li class="flex-control-wrapper"></li>');
        $slideWrapper
          .find('.flex-control-wrapper')
          .append($slideWrapper.find('.flex-control-nav'));
      }
    }
  };

  // Create a behavior for the dropdown nav displayed in the header.
  Drupal.behaviors.csunDropNav = {
    attach: function(context, settings) {
      // Move the drop down links to the proper containers.
      var $mobile = $('.pane-menu-block-custom-primary-mobile', context)
        .detach()
        .find('.menu-block-custom-primary-mobile');
      $('.nav-dropdown__links', context)
        .prepend($mobile);

      var $links = $('.nav-dropdown__constituency-links');
      // Move constituency links to container.
      var $secondary = $('.field-name-field-group-constituency-links', context).clone();
      if ($secondary.length) {
        $secondary
          .removeClass('field-name-field-group-constituency-links');
        $links
          .find('li')
          .append($secondary);
      }
      else {
        $links
          .empty();
      }

      // Custom logic for the myNorthridge Portal link
      if ($secondary.length) {
        $.each($('.nav-dropdown__constituency-links li'), function(){
          if ($('a', this).html() == 'MyNorthridge Portal') {
            $('a', this).attr('href', 'https://auth.csun.edu/cas/login?service=https://mynorthridge.csun.edu/psp/PANRPRD/?cmd=login&languageCd=ENG&embedform=true');
          }
        })
      }

      // Attach a click event that opens the child nav.
      var $dropdown = $('.nav-dropdown__container', context);
      $('.nav-dropdown__label', context).click(function() {
        // Find the links wrapper. Using a wrapper since there are multiple menus.
        // toggle the links open or close. Currently no animation being used.
        $dropdown.slideToggle();
        $(this).toggleClass('active expanded-open');
      });
      // Use an accordion on child nav links.
      var $accordion = $('.menu-block-custom-primary-mobile > .menu, .nav-dropdown__constituency-links', context);
      if ($accordion.length) {
        $accordion
          .find('> .menu--expanded > .menu--link')
          .addClass('accordion-trigger expandable')
          .click(function(e) {
            // Close other accordions.
            $accordion.find('.accordion-trigger').not(e.target).removeClass('expanded-open').next('ul').slideUp();
            //Toggle open/close on the <ul> after the <a>.
            $(e.target).toggleClass('expanded-open').next('ul').slideToggle();
            return false;
          });
      }
    }
  };

  // Create a behavior for the sidebar accordions.
  Drupal.behaviors.csunSidebarAccordion = {
    attach: function(context, settings) {
      var $accordion = $('.sidebar .pane-title');

      $.each($accordion, function(){
        $(this).nextAll('div').wrapAll('<div class="accordio-wrapper" />');
      })

      $accordion.click(function(e) {
        $(e.target)
          .filter('.accordion')
          .toggleClass('expanded-open')
          .next('div')
          .slideToggle();
      });

      $(window)
        .bind('orientationchange resize', function(e) {
          $accordion.removeClass('expanded-open');
          if ($(window).width() <= 950) {
            $accordion
              .addClass('accordion')
              .next('div')
              .slideUp();
          }
          else {
            $accordion
              .removeClass('accordion')
              .next('div')
              .slideDown();
          }
        })
        .trigger('resize');
    }
  };
})(jQuery, Drupal, this, this.document);



Is This A Good Question/Topic? 0
  • +

Replies To: jquery issue

#2 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,852
  • Joined: 30-April 10

Re: jquery issue

Posted 19 December 2013 - 11:16 AM

Have a look at .last(). It is useful to find the last element.
There is also a last selector :last and a last-child selector :last-child

This post has been edited by laytonsdad: 19 December 2013 - 11:20 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1