comparison Blast output page example_files/toggle.js @ 0:bad241dc701f

add example input blast xml and output html page
author Jan Kanis <jan.code@jankanis.nl>
date Tue, 06 May 2014 17:05:58 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bad241dc701f
1
2 Toggle = function(node) {
3 this.init(node);
4 }
5
6 /**
7 * @class Creates a new Toggle class with "node" as src
8 * @return Reutrns a new toggle instance
9 */
10 Toggle.prototype = {
11
12 init: function(node) {
13
14 // Subclass instance?
15 if (typeof(arguments[0]) == 'undefined') return;
16
17 var oThis = this;
18 this.node = node;
19
20 // Initialize "showing" variable based on presence of "showing" or
21 // "hiding" class. If neither, then showing. Be sure class is
22 // set to reflect variable value
23 node.showing =
24 utils.hasClass(node, "showing") || !utils.hasClass(node, "hiding");
25 utils.addClass(node, node.showing ? "showing" : "hiding");
26
27 // Set notifier for node
28 utils.addEvent(node, "click", function(e) {
29 e = e || window.event;
30 utils.preventDefault(e);
31
32 var theNode = utils.getTargetObj(e);
33
34 // Send message to global notifier, if one exists
35 if (typeof(Notifier) != 'undefined') {
36 var notifier = Notifier.getInstance();
37 // Notify before change
38 notifier.Notify(oThis, "change:" + theNode.id, !this.showing);
39 }
40
41 // Hide or show based on current state
42 if (this.showing) {
43 oThis.hide();
44 } else {
45 oThis.show();
46 }
47
48 }, false);
49
50 utils.addEvent(node, "selectstart", function(e) { utils.preventDefault(e); }, true);
51 utils.addEvent(node, "drag", function(e) { utils.preventDefault(e); }, true);
52
53 // Cache "this" for ID lookup
54 if (!node.id) {
55 node.id = utils.createNewId();
56 }
57 var m = Toggle.getSrcs();
58 m[node.id] = this;
59 },
60
61 // Hide targets, and set self to hiding.
62 hide: function() {
63 var oThis = this;
64
65 oThis.setHiding();
66 if (oThis.listeners) {
67 forEach(oThis.listeners, function(l) {
68 oThis.hideTarget(l);
69 });
70 }
71 },
72
73 // Show targets, and set self to showing.
74 show: function() {
75 var oThis = this;
76
77 oThis.setShowing();
78 if (oThis.listeners) {
79 forEach(oThis.listeners, function(l) {
80 oThis.showTarget(l);
81 });
82 }
83 },
84
85 // Set own presentation to "showing"
86 setShowing: function() {
87 utils.addClass(this.node, "showing");
88 utils.removeClass(this.node, "hiding");
89 this.node.showing = true;
90 },
91
92 // Set own presentation to "hiding"
93 setHiding: function() {
94 utils.addClass(this.node, "hiding");
95 utils.removeClass(this.node, "showing");
96 this.node.showing = false;
97 },
98
99 // Show a target
100 showTarget: function(l) {
101 utils.addClass(l, "shown");
102 utils.removeClass(l, "hidden");
103 },
104
105 // Hide a target
106 hideTarget: function(l) {
107 utils.addClass(l, "hidden");
108 utils.removeClass(l, "shown");
109 },
110
111 // Add a target to this toggle.
112 add: function(target) {
113 if (!this.listeners) {
114 this.listeners = new Array();
115 }
116 this.listeners[this.listeners.length] = target;
117
118 if (utils.hasClass(target, "hidden")) {
119 this.setHiding();
120 this.node.showing = false;
121 } else {
122 this.setShowing();
123 this.node.showing = true;
124 }
125 }
126 }
127
128 // Show/hide a "target" (a node controlled by the node with the given ID)
129 Toggle.addTarget = function(srcid, target) {
130 var tn = Toggle.findOrMake(srcid);
131 tn.add(target);
132 }
133
134 // Assoc array of srcs indexed by their ids
135 Toggle.getSrcs = function() {
136 if (!Toggle.srcs) {
137 Toggle.srcs = new Object();
138 }
139 return Toggle.srcs;
140 }
141
142 // Find or make toggle for given id
143 Toggle.findOrMake = function(srcid) {
144 var ts = Toggle.getSrcs();
145 var tn = ts[srcid];
146 if (!tn) {
147 tn = new Toggle($(srcid));
148 }
149 return tn;
150 }
151
152 // This dispatches the call to Toggle.onload, which may be
153 // overridden by instances (subclasses)
154 Toggle._onload = function() {
155 Toggle.onload();
156 }
157
158 // A toggle source node controls other nodes that reference it by id using
159 // their toggle= attribute. A node may be both a toggle source and destination.
160 Toggle.onload = function() {
161 //alert("toggle start");
162 if(utils.hasClass(document.body,"noToggleCheck")) return;
163
164 shnodes = jQuery("[toggle]");
165 // Now hook up dst nodes
166 forEach(shnodes, function(node) {
167 // Link toggle node to its source
168 var srcid = node.getAttribute("toggle");
169 Toggle.addTarget(srcid, node);
170 });
171 //alert("toggle 2 end");
172 }
173
174 utils.addEvent(window, 'load', Toggle._onload, false);