sftouchscreen.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * sf-Touchscreen v1.0b - Provides touchscreen compatibility for the jQuery Superfish plugin. - LAST UPDATE: MARCH 23rd, 2011
  3. *
  4. * Developer's notes:
  5. * Built as a part of the Superfish project for Drupal (http://drupal.org/project/superfish)
  6. * Found any bug? have any cool ideas? contact me right away! http://drupal.org/user/619294/contact
  7. *
  8. * jQuery version: 1.3.x or higher.
  9. *
  10. * Dual licensed under the MIT and GPL licenses:
  11. * http://www.opensource.org/licenses/mit-license.php
  12. * http://www.gnu.org/licenses/gpl.html
  13. */
  14. (function($){
  15. $.fn.sftouchscreen = function() {
  16. // Return original object to support chaining.
  17. return this.each( function() {
  18. // Select hyperlinks from parent menu items.
  19. $(this).find('li > ul').closest('li').children('a').each( function() {
  20. var $item = $(this);
  21. // No .toggle() here as it's not possible to reset it.
  22. $item.click( function(event){
  23. // Already clicked? proceed to the URI.
  24. if ($item.hasClass('sf-clicked')) {
  25. var $uri = $item.attr('href');
  26. window.location = $uri;
  27. }
  28. else {
  29. event.preventDefault();
  30. $item.addClass('sf-clicked');
  31. }
  32. }).closest('li').mouseleave( function(){
  33. // So, we reset everything.
  34. $item.removeClass('sf-clicked');
  35. });
  36. });
  37. });
  38. };
  39. })(jQuery);