-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlayform.js
104 lines (88 loc) · 3.42 KB
/
overlayform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(function($){
var elements,
methods = {
init : function(){
elements = this;
return this.each(function(){
var $this = $(this),
data = $this.data('overlayform');
if (!data){ //If the plugin hasn't been initialized yet
$this.overlayForm('bind');
$(this).data('overlayform', {
target : $this
});
}
});
},
bind: function(){
var target = this,
bubbleObject;
target.bind('overlay.fill',function(){
$(this).data('overlayform').content = $.fn.formBubble.bubbleObject;
});
target.bind('overlay.open',function(){
var overlayContent = ($(this).data('overlayform')) ? $(this).data('overlayform').content : false,
overlayVisible = (overlayContent) ? $.contains(document, overlayContent[0]) : false,
rightSpace = $(window).width() - (target.offset().left + target.width()),
leftSpace = target.offset().left,
align = (leftSpace > rightSpace) ? 'left' : 'right',
targetWidth = target.width();
if (overlayVisible){ //close bubble if 2nd click
$.fn.formBubble.close(overlayContent);
return false;
}
targetWidth = (align==='right' && targetWidth > 0) ? targetWidth * -1 : targetWidth + 14;
if (elements.length) elements.removeClass('above-form-bubble');
target
.formBubble({
alignment: {
bubble: align
},
graphics: {
close: false,
pointer: false
},
offset: {
x: targetWidth,
y: 3
},
animation: {
slide: false,
speed: 0
},
callbacks : {
onOpen: function(){ },
onClose: function(){
target.removeClass('above-form-bubble');
}
}
})
.addClass('above-form-bubble')
.trigger('overlay.fill');
return false;
});
},
destroy : function(){
return this.each(function(){
var $this = $(this),
data = $this.data('overlayform');
//unbind overlayform events
$this.unbind('.open');
$this.unbind('.fill');
//remove overlayform data
$this.removeData('overlayform');
//remove overlayform DOM element
if (data && data.content) data.content.remove();
});
}
};
$.fn.overlayForm = function(method){
if (methods[method]){
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ){
return methods.init.apply( this, arguments );
}else{
$.error( 'Method ' + method + ' does not exist on $.overlayform' );
}
};
})(jQuery);