Projet

Général

Profil

Paste
Télécharger (2,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / Superfish-for-Drupal-1.x / sftouchscreen.js @ 4da4932d

1
/*
2
 * sf-Touchscreen v1.2b - Provides touchscreen compatibility for the jQuery Superfish plugin.
3
 *
4
 * Developer's note:
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

    
15
(function($){
16
  $.fn.sftouchscreen = function(options){
17
    options = $.extend({
18
      mode: 'inactive',
19
      breakpoint: 768,
20
      useragent: ''
21
    }, options);
22

    
23
    function activate(menu){
24
      // Select hyperlinks from parent menu items.
25
      menu.find('li > ul').closest('li').children('a').each(function(){
26
        var item = $(this);
27
        // No .toggle() here as it's not possible to reset it.
28
        item.click(function(event){
29
          // Already clicked? proceed to the URL.
30
          if (item.hasClass('sf-clicked')){
31
            window.location = item.attr('href');
32
          }
33
          // Prevent it otherwise.
34
          else {
35
            event.preventDefault();
36
            item.addClass('sf-clicked');
37
          }
38
        }).closest('li').mouseleave(function(){
39
          // Reset everything.
40
          item.removeClass('sf-clicked');
41
        });
42
      });
43
    }
44
    // Return original object to support chaining.
45
    return this.each(function(){
46
      var menu = $(this),
47
      mode = options.mode;
48
      // The rest is crystal clear, isn't it? :)
49
      switch (mode){
50
        case 'always_active' :
51
          activate(menu);
52
        break;
53
        case 'window_width' :
54
          if ($(window).width() < options.breakpoint){
55
            activate(menu);
56
          }
57
          var timer;
58
          $(window).resize(function(){
59
            clearTimeout(timer);
60
            timer = setTimeout(function(){
61
              if ($(window).width() < options.breakpoint){
62
                activate(menu);
63
              }
64
            }, 100);
65
          });
66
        break;
67
        case 'useragent_custom' :
68
          if (options.useragent != ''){
69
            var ua = RegExp(options.useragent, 'i');
70
            if (navigator.userAgent.match(ua)){
71
              activate(menu);
72
            }
73
          }
74
        break;
75
        case 'useragent_predefined' :
76
          if (navigator.userAgent.match(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i)){
77
            activate(menu);
78
          }
79
        break;
80
      }
81
    });
82
  };
83
})(jQuery);