1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
(function($){
|
17
|
$.fn.supposition = function(){
|
18
|
var $w = $(window),
|
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({bottom:''});
|
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
|
menuParentShadow = ($u.closest('.sf-menu').hasClass('sf-shadow') && $u.css('padding-bottom').length > 0) ? parseInt($u.css('padding-bottom').slice(0,-2)) : 0,
|
52
|
menuParentHeight = ($u.closest('.sf-menu').hasClass('sf-vertical')) ? '-' + menuParentShadow : $u.parent().outerHeight(true) - menuParentShadow,
|
53
|
menuHeight = $u.height(),
|
54
|
baseline = windowHeight + _offset('y');
|
55
|
var expandUp = ((offsetTop + menuHeight > baseline) && (offsetTop > menuHeight));
|
56
|
if (expandUp) {
|
57
|
$u.css('bottom', menuParentHeight + 'px');
|
58
|
$u.css('top', 'auto');
|
59
|
}
|
60
|
$u.css('display','none');
|
61
|
});
|
62
|
};
|
63
|
|
64
|
return this.each(function() {
|
65
|
var o = $.fn.superfish.o[this.serial];
|
66
|
|
67
|
|
68
|
var _onBeforeShow = o.onBeforeShow,
|
69
|
_onHide = o.onHide;
|
70
|
|
71
|
$.extend($.fn.superfish.o[this.serial],{
|
72
|
onBeforeShow: function() {
|
73
|
onBeforeShow.call(this);
|
74
|
_onBeforeShow.call(this);
|
75
|
},
|
76
|
onHide: function() {
|
77
|
onHide.call(this);
|
78
|
_onHide.call(this);
|
79
|
}
|
80
|
});
|
81
|
});
|
82
|
};
|
83
|
})(jQuery);
|