Projet

Général

Profil

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

root / drupal7 / sites / all / libraries / superfish-version / supposition.js @ 5a7e6170

1
/*
2
* Supposition v0.2 - an optional enhancer for Superfish jQuery menu widget - LAST UPDATE: MARCH 23rd, 2011
3
*
4
* Copyright (c) 2008 Joel Birch - based mostly on work by Jesse Klaasse and credit goes largely to him.
5
* Special thanks to Karl Swedberg for valuable input.
6
* 
7
* Dec 28th, 2010 - Modified for the Superfish project for Drupal (http://drupal.org/project/superfish)
8
*
9
* jQuery version: 1.3.x or higher.
10
*
11
* Dual licensed under the MIT and GPL licenses:
12
*         http://www.opensource.org/licenses/mit-license.php
13
*         http://www.gnu.org/licenses/gpl.html
14
*/
15

    
16
(function($){
17
  $.fn.supposition = function(){
18
    var $w = $(window), /*do this once instead of every onBeforeShow call*/
19
    _offset = function(dir) {
20
      return window[dir == 'y' ? 'pageYOffset' : 'pageXOffset']
21
      || document.documentElement && document.documentElement[dir=='y' ? 'scrollTop' : 'scrollLeft']
22
      || document.body[dir=='y' ? 'scrollTop' : 'scrollLeft'];
23
    },
24
    onHide = function(){
25
      this.css({Top:'',Right:'',Bottom:'',Left:''});
26
    },
27
    onBeforeShow = function(){
28
      this.each(function(){
29
        var $u = $(this);
30
        $u.css('display','block');
31
        var menuWidth = $u.width(),
32
        menuParentWidth = $u.closest('li').outerWidth(true),
33
        menuParentLeft = $u.closest('li').offset().left,
34
        totalRight = $w.width() + _offset('x'),
35
        menuRight = $u.offset().left + menuWidth,
36
        exactMenuWidth = (menuRight > (menuParentWidth + menuParentLeft)) ? menuWidth - (menuRight - (menuParentWidth + menuParentLeft)) : menuWidth;  
37
        if ($u.parents('.sf-js-enabled').hasClass('rtl')) {
38
          if (menuParentLeft < exactMenuWidth) {
39
            $u.css('left', menuParentWidth + 'px');
40
            $u.css('right', 'auto');
41
          }
42
        }
43
        else {
44
          if (menuRight > totalRight && menuParentLeft > menuWidth) {
45
            $u.css('right', menuParentWidth + 'px');
46
            $u.css('left', 'auto');
47
          }
48
        }
49
        var windowHeight = $w.height(),
50
        offsetTop = $u.offset().top,
51
        menuParentHeight = $u.parent().outerHeight(true),
52
        menuHeight = $u.height(),
53
        baseline = windowHeight + _offset('y');
54
        var expandUp = ((offsetTop + menuHeight > baseline) && (offsetTop > menuHeight));
55
        if (expandUp) {
56
          $u.css('bottom', menuParentHeight + 'px');
57
          $u.css('top', 'auto');
58
        }
59
        $u.css('display','none');
60
      });
61
    };
62

    
63
    return this.each(function() {
64
    var o = $.fn.superfish.o[this.serial]; /* get this menu's options */
65

    
66
    /* if callbacks already set, store them */
67
    var _onBeforeShow = o.onBeforeShow,
68
    _onHide = o.onHide;
69

    
70
    $.extend($.fn.superfish.o[this.serial],{
71
    onBeforeShow: function() {
72
    onBeforeShow.call(this); /* fire our Supposition callback */
73
    _onBeforeShow.call(this); /* fire stored callbacks */
74
    },
75
    onHide: function() {
76
    onHide.call(this); /* fire our Supposition callback */
77
    _onHide.call(this); /* fire stored callbacks */
78
    }
79
    });
80
    });
81
  };
82
})(jQuery);