| author | gibus |
| Wed, 11 Sep 2013 23:13:01 +0200 | |
| changeset 532 | 0bad3613f59d |
| parent 525 | 89ef5ed3c48b |
| child 562 | 92e8e5aaacde |
| permissions | -rw-r--r-- |
| 421 | 1 |
gToc = null ; |
2 |
||
3 |
instanciateToc = function() { |
|
4 |
gToc = { |
|
5 |
'tocId':CY.guid(), |
|
6 |
'tocTitleId':CY.guid(), |
|
| 422 | 7 |
'closeBtnId':CY.guid(), |
8 |
'empty': false |
|
| 421 | 9 |
} ; |
10 |
|
|
11 |
var overlayHtml = {}; |
|
12 |
overlayHtml['headerContent'] = '<div id="' + gToc['tocId'] + '"><h3 id="' + gToc['tocTitleId'] + '"></h3>'; |
|
13 |
||
14 |
var toBeTOCced = getElementsByTagNames('h2,h3,h4,h5,h6', document.getElementById('maincontainer')); |
|
15 |
|
|
16 |
var content = document.createElement('div'); |
|
| 422 | 17 |
if (toBeTOCced.length >= 2) { |
18 |
for (var i=0;i<toBeTOCced.length;i++) { |
|
19 |
var tmp = document.createElement('a'); |
|
|
469
08d57b273596
When building toc, delete <a> elements, including when written in uppercase (<A>).
gibus
parents:
440
diff
changeset
|
20 |
tmp.innerHTML = toBeTOCced[i].innerHTML.replace(/<\/?a[^>]*>/ig,''); |
| 422 | 21 |
tmp.className = 'page indent' + toBeTOCced[i].nodeName; |
22 |
content.appendChild(tmp); |
|
23 |
var headerId = toBeTOCced[i].id || 'link' + i; |
|
24 |
tmp.href = '#' + headerId; |
|
25 |
toBeTOCced[i].id = headerId; |
|
26 |
} |
|
27 |
} |
|
28 |
else { |
|
29 |
content.innerHTML = ''; |
|
30 |
gToc['empty'] = true; |
|
31 |
} |
|
| 421 | 32 |
overlayHtml['bodyContent'] = content.innerHTML; |
33 |
|
|
34 |
var width = gLayout.getTopICommentsWidth() ; |
|
35 |
|
|
36 |
var overlay = new CY.Overlay( { |
|
37 |
zIndex :3, |
|
38 |
shim :false, // until we really need it, no shim |
|
39 |
visible :false, |
|
40 |
headerContent :overlayHtml['headerContent'], |
|
41 |
bodyContent :overlayHtml['bodyContent'], |
|
| 423 | 42 |
xy :[3,30], |
| 421 | 43 |
width : width |
44 |
}); |
|
45 |
overlay.get('contentBox').addClass("c-toc") ; |
|
| 424 | 46 |
overlay.get('contentBox').set("id", "the-toc") ; |
| 421 | 47 |
|
48 |
// attach to DOM |
|
49 |
overlay.render('#leftcolumn'); |
|
50 |
|
|
|
532
0bad3613f59d
Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents:
525
diff
changeset
|
51 |
CY.get("#"+gToc['tocTitleId']).set('innerHTML', gettext('Table of contents')) ; |
| 421 | 52 |
|
53 |
gToc['overlay'] = overlay ; |
|
54 |
|
|
55 |
var animationHide = null ; |
|
56 |
animationHide = new CY.Anim({ |
|
57 |
node: overlay.get('boundingBox'), |
|
58 |
duration: .3, //gPrefs['general']['animduration'], |
|
59 |
easing: CY.Easing.easeOut |
|
60 |
}); |
|
61 |
gToc['animationHide'] = animationHide ; |
|
62 |
animationHide.set('to', { opacity: 0});// height : 0 doesn't work |
|
63 |
gToc['animationHide-handle'] = animationHide.on('end', onTocHideAnimEnd, gToc); |
|
64 |
||
65 |
var animationShow = null ; |
|
66 |
animationShow = new CY.Anim({ |
|
67 |
node: overlay.get('boundingBox'), |
|
68 |
duration: .3, //gPrefs['general']['animduration'], |
|
69 |
easing: CY.Easing.easeOut |
|
70 |
}); |
|
71 |
gToc['animationShow'] = animationShow ; |
|
72 |
animationShow.set('to', { opacity: 1}); |
|
73 |
gToc['animationShow-handle'] = animationShow.on('end', onTocShowAnimEnd, gToc); |
|
|
440
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
74 |
getElementsByClassName('c-toc')[0].style.width = width + 'px'; |
| 421 | 75 |
} |
76 |
||
77 |
toggleTocFn = function() { |
|
78 |
if (isTocVisible()) |
|
79 |
hideToc(); |
|
80 |
else |
|
81 |
showToc(); |
|
82 |
} |
|
83 |
||
84 |
hideToc = function() { |
|
85 |
gToc['overlay'].hide(); |
|
86 |
} |
|
87 |
||
88 |
onTocHideAnimEnd = function() { |
|
89 |
// iComment['overlay'].blur() ; |
|
90 |
this.overlay.hide() ; |
|
91 |
gSync.resume() ; |
|
92 |
} |
|
93 |
||
94 |
onTocShowAnimEnd = function() { |
|
95 |
gSync.resume() ; |
|
96 |
} |
|
97 |
||
98 |
showToc= function () { |
|
99 |
removeFormErrMsg(gToc['tocId']) ; |
|
100 |
gIComments.hide() ; |
|
101 |
gToc['overlay'].show(); |
|
102 |
} |
|
103 |
||
104 |
isTocVisible = function () { |
|
105 |
if (gToc != null) |
|
106 |
return gToc['overlay'].get('visible') ; |
|
107 |
return false ; |
|
108 |
} |
|
109 |
||
110 |
function getElementsByTagNames(list,obj) { |
|
111 |
if (!obj) var obj = document; |
|
112 |
var tagNames = list.split(','); |
|
113 |
var resultArray = new Array(); |
|
114 |
for (var i=0;i<tagNames.length;i++) { |
|
115 |
var tags = obj.getElementsByTagName(tagNames[i]); |
|
116 |
for (var j=0;j<tags.length;j++) { |
|
117 |
resultArray.push(tags[j]); |
|
118 |
} |
|
119 |
} |
|
120 |
var testNode = resultArray[0]; |
|
121 |
if (!testNode) return []; |
|
122 |
if (testNode.sourceIndex) { |
|
123 |
resultArray.sort(function (a,b) { |
|
124 |
return a.sourceIndex - b.sourceIndex; |
|
125 |
}); |
|
126 |
} |
|
127 |
else if (testNode.compareDocumentPosition) { |
|
128 |
resultArray.sort(function (a,b) { |
|
129 |
return 3 - (a.compareDocumentPosition(b) & 6); |
|
130 |
}); |
|
131 |
} |
|
132 |
return resultArray; |
|
133 |
} |
|
|
440
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
134 |
|
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
135 |
/* |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
136 |
Developed by Robert Nyman, http://www.robertnyman.com |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
137 |
Code/licensing: http://code.google.com/p/getelementsbyclassname/ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
138 |
*/ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
139 |
var getElementsByClassName = function (className, tag, elm){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
140 |
if (document.getElementsByClassName) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
141 |
getElementsByClassName = function (className, tag, elm) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
142 |
elm = elm || document; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
143 |
var elements = elm.getElementsByClassName(className), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
144 |
nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
145 |
returnElements = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
146 |
current; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
147 |
for(var i=0, il=elements.length; i<il; i+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
148 |
current = elements[i]; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
149 |
if(!nodeName || nodeName.test(current.nodeName)) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
150 |
returnElements.push(current); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
151 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
152 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
153 |
return returnElements; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
154 |
}; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
155 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
156 |
else if (document.evaluate) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
157 |
getElementsByClassName = function (className, tag, elm) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
158 |
tag = tag || "*"; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
159 |
elm = elm || document; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
160 |
var classes = className.split(" "), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
161 |
classesToCheck = "", |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
162 |
xhtmlNamespace = "http://www.w3.org/1999/xhtml", |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
163 |
namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
164 |
returnElements = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
165 |
elements, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
166 |
node; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
167 |
for(var j=0, jl=classes.length; j<jl; j+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
168 |
classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]"; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
169 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
170 |
try { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
171 |
elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
172 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
173 |
catch (e) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
174 |
elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
175 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
176 |
while ((node = elements.iterateNext())) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
177 |
returnElements.push(node); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
178 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
179 |
return returnElements; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
180 |
}; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
181 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
182 |
else { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
183 |
getElementsByClassName = function (className, tag, elm) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
184 |
tag = tag || "*"; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
185 |
elm = elm || document; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
186 |
var classes = className.split(" "), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
187 |
classesToCheck = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
188 |
elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
189 |
current, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
190 |
returnElements = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
191 |
match; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
192 |
for(var k=0, kl=classes.length; k<kl; k+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
193 |
classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)")); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
194 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
195 |
for(var l=0, ll=elements.length; l<ll; l+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
196 |
current = elements[l]; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
197 |
match = false; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
198 |
for(var m=0, ml=classesToCheck.length; m<ml; m+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
199 |
match = classesToCheck[m].test(current.className); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
200 |
if (!match) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
201 |
break; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
202 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
203 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
204 |
if (match) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
205 |
returnElements.push(current); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
206 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
207 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
208 |
return returnElements; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
209 |
}; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
210 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
211 |
return getElementsByClassName(className, tag, elm); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
212 |
}; |