forked from wheresmehat/CodeRun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasidebar.jquery.js
47 lines (42 loc) · 1.27 KB
/
asidebar.jquery.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
function injectAsidebar(jQuery) {
jQuery.fn.asidebar = function asidebar(status) {
switch (status) {
case "open":
var that = this;
// fade in backdrop
if ($(".aside-backdrop").length === 0) {
$("body").append("<div class='aside-backdrop'></div>");
}
$(".aside-backdrop").addClass("in");
function close() {
$(that).asidebar.apply(that, ["close"]);
}
// slide in asidebar
$(this).addClass("in");
$(this).find("[data-dismiss=aside], [data-dismiss=asidebar]").on('click', close);
$(".aside-backdrop").on('click', close);
break;
case "close":
// fade in backdrop
if ($(".aside-backdrop.in").length > 0) {
$(".aside-backdrop").removeClass("in");
}
// slide in asidebar
$(this).removeClass("in");
break;
case "toggle":
if($(this).attr("class").split(' ').indexOf('in') > -1) {
$(this).asidebar("close");
} else {
$(this).asidebar("open");
}
break;
}
}
}
// support browser and node
if (typeof jQuery !== "undefined") {
injectAsidebar(jQuery);
} else if (typeof module !== "undefined" && module.exports) {
module.exports = injectAsidebar;
}