-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.garagedoor.js
executable file
·99 lines (81 loc) · 2.33 KB
/
jquery.garagedoor.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
/*
* jQuery GarageDoor Plugin
*
* portions influenced by: http://www.learningjquery.com/2007/10/a-plugin-development-pattern
*/
(function($) {
$.fn.GarageDoor = function(options) {
var opts = $.extend({}, $.fn.GarageDoor.defaults, options);
return this.each(function() {
$this = $(this);
// manipulate
$this.css('position', 'relative');
wrapElement($this);
createClone($this, opts);
// create animations
bindRaise($this, opts);
bindLower($this, opts);
// bind custom events
if(opts.onRaise) $('#' + $this.attr("id") + "_wrap").bind("mouseenter", opts.onRaise);
if(opts.onLower) $('#' + $this.attr("id") + "_wrap").bind("mouseleave", opts.onLower);
});
};
function wrapElement(elem) {
var wrap = document.createElement("div");
wrap = $(wrap);
wrap.attr("id", elem.attr("id") + "_wrap")
wrap.css("width", elem.width());
wrap.css("height", elem.height());
wrap.css('overflow', 'hidden');
elem.wrap(wrap);
};
function createClone(elem, opts) {
var clone = elem.clone();
elem.after(clone.attr("id", elem.attr("id") + "_clone").css("position", "relative")).after("<br/>");
if(opts.alterClone) {
opts.alterClone.call(this, clone);
} else {
$.fn.GarageDoor.alterClone(clone);
}
};
function bindRaise(elem, opts) {
$('#' + elem.attr("id") + "_wrap").bind("mouseenter", function(){
if(opts.raiseDelegate) {
opts.raiseDelegate.call(this, function(){open(elem, opts)});
} else {
open(elem, opts);
}
});
};
function bindLower(elem, opts) {
$('#' + elem.attr("id") + "_wrap").bind("mouseleave", function(){
if(opts.lowerDelegate) {
opts.lowerDelegate.call(this, function(){close(elem, opts)});
} else {
close(elem, opts);
}
});
};
function open(elem, opts) {
elem.animate({
top: (- elem.height())
}, opts.raiseSpeed);
$('#' + elem.attr("id") + "_clone").animate({
top: (- elem.height())
}, opts.lowerSpeed);
}
function close(elem, opts) {
elem.animate({
top: (0)
}, opts.raiseSpeed);
$('#' + elem.attr("id") + "_clone").animate({
top: (0)
}, opts.lowerSpeed);
}
$.fn.GarageDoor.alterClone = function(elem) {
};
$.fn.GarageDoor.defaults = {
raiseSpeed: 200,
lowerSpeed: 200
};
})(jQuery);