-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaf.pathmenu.js
executable file
·68 lines (59 loc) · 2.11 KB
/
af.pathmenu.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
/**
* af.pathmenu.js
* @author Ian Maffett
* @copyright Ian Maffett
* @desc App Framework plugin for creating path style menu's.
Your HTML needs to be a <ul> with <li> as the items (up to 5)
<ul id='pathmenu'>
<li><a href='#'>Like</a></li>
<li><a href='#'>+1</a></li>
<li><a href='#'>Tweet</a></li>
<li><a href='#'>Email</a></li>
<li><a href='#'>♥</a></li>
</ul>
* Then you simply call $("#pathmenu").pathmenu(opts) to enable it
*
* opts
btnclass - button class for the popup links
menubtnclass - class for the menu button
button - text to show in the button
*/
(function($){
$.fn.pathmenu=function(opts){
if(this.length===0) return;
new pathmenu(this[0],opts);
return this;
};
var pathmenu=function(el,opts){
this.container=$(el);
opts.btnclass=opts.btnclass||"pathbtn";
opts.menubtnclass=opts.menubtnclass||"pathmenubutton";
opts.button=opts.button||"!";
var self=this;
//subscribe for the destroy event to prevent memory leaks
this.container.bind('destroy', function(){
self.container.off("click");
});
//Add the button class to the <li's>
this.container.find("li").addClass(opts.btnclass);
//Add the actual button
this.container.addClass("pathcircle");
this.container.append("<li class='"+opts.menubtnclass+"'><div><a>"+opts.button+"</a></div></li>");
//Handle clicking the links
this.container.on("click","."+opts.btnclass,function(){
//Wait 50ms to close
setTimeout(function(){
self.container.find("."+opts.btnclass).removeClass("open");
self.container.find("."+opts.menubtnclass).removeClass("open");
},50);
});
//Toggle clicking the menu
this.container.find("."+opts.menubtnclass).bind("click",function(){
var btns=self.container.find("."+opts.btnclass);
if(btns.hasClass("open"))
btns.removeClass("open"),$(this).removeClass("open");
else
btns.addClass("open"),$(this).addClass("open");
});
};
})(af)