/
gui.polypage.jquery.js
60 lines (50 loc) · 1.6 KB
/
gui.polypage.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
48
49
50
51
52
53
54
55
56
57
58
59
60
// ==========================
// = PolyPage GUI Extension =
// ==========================
(function($) {
$.polypage.extension('GUI',
{
containerID: 'pp_options',
label: "Page States:"
},
{
init: function(){
this.bindEvents();
this.redraw();
},
bindEvents: function() {
var nb = this;
this.scope.bind('pp_gui_forceRedraw', function() { nb.redraw() });
this.polypageScope.bind('pp_stateChange', function() { nb.redraw()});
},
redraw: function(){
this.scope.trigger('pp_gui_redrawBegin', this);
this.undraw();
if(!this.needsOptionBar()) return;
this.draw();
this.scope.trigger('pp_gui_redrawComplete', this);
},
draw: function(){
this.scope.append('<div id="'+this.options.containerID+'"><p>'+this.options.label+'</p><ul></ul></div>');
var states = this.states();
for(var index in states) {
var state = states[index];
var humanStateName = state.name.replace(this.separator(),' ');
var className = state.value ? 'on' : 'off'
$('#pp_options ul').append('<li><a href="#pp_toggle_'+state.name+'" id="pp_state_toggle_'+state.name+'" class="'+className+'">'+humanStateName+'</a></li>');
}
},
undraw: function(){
this.scope.find('#'+this.options.containerID).remove();
},
needsOptionBar: function(){
return this.polypage.hasElements();
},
states: function(){
return this.polypage.alphabeticalStates();
},
separator: function(){
return this.polypage.options.separator;
}
});
})(jQuery);