| author | gibus |
| Mon, 10 Mar 2014 13:24:19 +0100 | |
| changeset 600 | fda73ac53450 |
| parent 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 |
|
|
|
562
92e8e5aaacde
Give maximum width for add_comment form and toc.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
34 |
var width = gLayout.getTopICommentsWidth(); |
|
92e8e5aaacde
Give maximum width for add_comment form and toc.
Simon Descarpentries <sid@sopinspace.com>
parents:
532
diff
changeset
|
35 |
width += gLayout.iCommentsRequiredThreadPadding (); // SID: use max available space as there is no indentation on that box |
| 421 | 36 |
|
37 |
var overlay = new CY.Overlay( { |
|
38 |
zIndex :3, |
|
39 |
shim :false, // until we really need it, no shim |
|
40 |
visible :false, |
|
41 |
headerContent :overlayHtml['headerContent'], |
|
42 |
bodyContent :overlayHtml['bodyContent'], |
|
| 423 | 43 |
xy :[3,30], |
| 421 | 44 |
width : width |
45 |
}); |
|
46 |
overlay.get('contentBox').addClass("c-toc") ; |
|
| 424 | 47 |
overlay.get('contentBox').set("id", "the-toc") ; |
| 421 | 48 |
|
49 |
// attach to DOM |
|
50 |
overlay.render('#leftcolumn'); |
|
51 |
|
|
|
600
fda73ac53450
Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents:
562
diff
changeset
|
52 |
CY.one("#"+gToc['tocTitleId']).set('innerHTML', gettext('Table of contents')) ; |
| 421 | 53 |
|
54 |
gToc['overlay'] = overlay ; |
|
55 |
|
|
56 |
var animationHide = null ; |
|
57 |
animationHide = new CY.Anim({ |
|
58 |
node: overlay.get('boundingBox'), |
|
59 |
duration: .3, //gPrefs['general']['animduration'], |
|
60 |
easing: CY.Easing.easeOut |
|
61 |
}); |
|
62 |
gToc['animationHide'] = animationHide ; |
|
63 |
animationHide.set('to', { opacity: 0});// height : 0 doesn't work |
|
64 |
gToc['animationHide-handle'] = animationHide.on('end', onTocHideAnimEnd, gToc); |
|
65 |
||
66 |
var animationShow = null ; |
|
67 |
animationShow = new CY.Anim({ |
|
68 |
node: overlay.get('boundingBox'), |
|
69 |
duration: .3, //gPrefs['general']['animduration'], |
|
70 |
easing: CY.Easing.easeOut |
|
71 |
}); |
|
72 |
gToc['animationShow'] = animationShow ; |
|
73 |
animationShow.set('to', { opacity: 1}); |
|
74 |
gToc['animationShow-handle'] = animationShow.on('end', onTocShowAnimEnd, gToc); |
|
|
440
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
75 |
getElementsByClassName('c-toc')[0].style.width = width + 'px'; |
| 421 | 76 |
} |
77 |
||
78 |
toggleTocFn = function() { |
|
79 |
if (isTocVisible()) |
|
80 |
hideToc(); |
|
81 |
else |
|
82 |
showToc(); |
|
83 |
} |
|
84 |
||
85 |
hideToc = function() { |
|
86 |
gToc['overlay'].hide(); |
|
87 |
} |
|
88 |
||
89 |
onTocHideAnimEnd = function() { |
|
90 |
// iComment['overlay'].blur() ; |
|
91 |
this.overlay.hide() ; |
|
92 |
gSync.resume() ; |
|
93 |
} |
|
94 |
||
95 |
onTocShowAnimEnd = function() { |
|
96 |
gSync.resume() ; |
|
97 |
} |
|
98 |
||
99 |
showToc= function () { |
|
100 |
removeFormErrMsg(gToc['tocId']) ; |
|
101 |
gIComments.hide() ; |
|
102 |
gToc['overlay'].show(); |
|
103 |
} |
|
104 |
||
105 |
isTocVisible = function () { |
|
106 |
if (gToc != null) |
|
107 |
return gToc['overlay'].get('visible') ; |
|
108 |
return false ; |
|
109 |
} |
|
110 |
||
111 |
function getElementsByTagNames(list,obj) { |
|
112 |
if (!obj) var obj = document; |
|
113 |
var tagNames = list.split(','); |
|
114 |
var resultArray = new Array(); |
|
115 |
for (var i=0;i<tagNames.length;i++) { |
|
116 |
var tags = obj.getElementsByTagName(tagNames[i]); |
|
117 |
for (var j=0;j<tags.length;j++) { |
|
118 |
resultArray.push(tags[j]); |
|
119 |
} |
|
120 |
} |
|
121 |
var testNode = resultArray[0]; |
|
122 |
if (!testNode) return []; |
|
123 |
if (testNode.sourceIndex) { |
|
124 |
resultArray.sort(function (a,b) { |
|
125 |
return a.sourceIndex - b.sourceIndex; |
|
126 |
}); |
|
127 |
} |
|
128 |
else if (testNode.compareDocumentPosition) { |
|
129 |
resultArray.sort(function (a,b) { |
|
130 |
return 3 - (a.compareDocumentPosition(b) & 6); |
|
131 |
}); |
|
132 |
} |
|
133 |
return resultArray; |
|
134 |
} |
|
|
440
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 |
/* |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
137 |
Developed by Robert Nyman, http://www.robertnyman.com |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
138 |
Code/licensing: http://code.google.com/p/getelementsbyclassname/ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
139 |
*/ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
140 |
var getElementsByClassName = function (className, tag, elm){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
141 |
if (document.getElementsByClassName) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
142 |
getElementsByClassName = function (className, tag, elm) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
143 |
elm = elm || document; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
144 |
var elements = elm.getElementsByClassName(className), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
145 |
nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
146 |
returnElements = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
147 |
current; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
148 |
for(var i=0, il=elements.length; i<il; i+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
149 |
current = elements[i]; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
150 |
if(!nodeName || nodeName.test(current.nodeName)) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
151 |
returnElements.push(current); |
|
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 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
154 |
return returnElements; |
|
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 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
157 |
else if (document.evaluate) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
158 |
getElementsByClassName = function (className, tag, elm) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
159 |
tag = tag || "*"; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
160 |
elm = elm || document; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
161 |
var classes = className.split(" "), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
162 |
classesToCheck = "", |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
163 |
xhtmlNamespace = "http://www.w3.org/1999/xhtml", |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
164 |
namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
165 |
returnElements = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
166 |
elements, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
167 |
node; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
168 |
for(var j=0, jl=classes.length; j<jl; j+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
169 |
classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]"; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
170 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
171 |
try { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
172 |
elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
173 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
174 |
catch (e) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
175 |
elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
176 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
177 |
while ((node = elements.iterateNext())) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
178 |
returnElements.push(node); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
179 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
180 |
return returnElements; |
|
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 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
183 |
else { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
184 |
getElementsByClassName = function (className, tag, elm) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
185 |
tag = tag || "*"; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
186 |
elm = elm || document; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
187 |
var classes = className.split(" "), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
188 |
classesToCheck = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
189 |
elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag), |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
190 |
current, |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
191 |
returnElements = [], |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
192 |
match; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
193 |
for(var k=0, kl=classes.length; k<kl; k+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
194 |
classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)")); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
195 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
196 |
for(var l=0, ll=elements.length; l<ll; l+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
197 |
current = elements[l]; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
198 |
match = false; |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
199 |
for(var m=0, ml=classesToCheck.length; m<ml; m+=1){ |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
200 |
match = classesToCheck[m].test(current.className); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
201 |
if (!match) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
202 |
break; |
|
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 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
205 |
if (match) { |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
206 |
returnElements.push(current); |
|
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 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
209 |
return returnElements; |
|
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 |
} |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
212 |
return getElementsByClassName(className, tag, elm); |
|
0d2d10bc47bd
Adds generic getElementsByClassName for IE compatibility.
gibus
parents:
425
diff
changeset
|
213 |
}; |