forked from rmurphey/jqfundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportlet.js
55 lines (42 loc) · 1.27 KB
/
portlet.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
(function($){
$.fn.portlet = function(opts) {
opts = $.extend({}, $.fn.portlet.defaults, opts || {});
return this.each(function(){
var content = $(this),
visible = 1,
portlet = $('<div/>', {
"class" : "portlet"
}),
buttons = $('<ul/>', {
"class" : "buttons"
}),
openClose = $('<li/>', {
"class" : "open-close",
text : opts.openCloseText[visible]
}).appendTo(buttons),
openCloseAll = $('<li/>', {
"class" : "open-close-all",
text : opts.openCloseAllText[visible]
}).appendTo(buttons),
title = $('<h1/>', {
"class" : "title",
text : opts.title
});
function toggleVisible(){
visible = visible ? 0 : 1;
openClose.text(opts.openCloseText[visible]);
content[visible ? 'show' : 'hide']();
}
content.wrap(portlet);
content.before(buttons.before(title));
openClose.click(toggleVisible);
openCloseAll.click(function() { $(document).trigger('togglePortlet'); });
$(document).bind('togglePortlet', toggleVisible);
});
};
$.fn.portlet.defaults = {
title : 'Portlet',
openCloseText : [ 'Open', 'Close' ],
openCloseAllText : [ 'Open All', 'Close All' ]
};
}(jQuery));