| author | gibus |
| Mon, 14 May 2012 10:15:01 +0200 | |
| changeset 425 | d70552fc1a66 |
| parent 424 | 2f9108930e47 |
| child 440 | 0d2d10bc47bd |
| 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'); |
|
| 424 | 20 |
tmp.innerHTML = toBeTOCced[i].innerHTML.replace(/<\/?a[^>]*>/g,''); |
| 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 |
|
|
51 |
CY.get("#"+gToc['tocTitleId']).set('innerHTML', gettext('Table of contents')) ; |
|
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); |
|
|
425
d70552fc1a66
Fix some javascript error with IE8 (getElementsByClassName() is unknown).
gibus
parents:
424
diff
changeset
|
74 |
if (typeof document.getElementsByClassName!='function') { |
|
d70552fc1a66
Fix some javascript error with IE8 (getElementsByClassName() is unknown).
gibus
parents:
424
diff
changeset
|
75 |
document.querySelectorAll('.c-toc')[0].style.width = width + 'px'; |
|
d70552fc1a66
Fix some javascript error with IE8 (getElementsByClassName() is unknown).
gibus
parents:
424
diff
changeset
|
76 |
} |
|
d70552fc1a66
Fix some javascript error with IE8 (getElementsByClassName() is unknown).
gibus
parents:
424
diff
changeset
|
77 |
else { |
|
d70552fc1a66
Fix some javascript error with IE8 (getElementsByClassName() is unknown).
gibus
parents:
424
diff
changeset
|
78 |
document.getElementsByClassName('c-toc')[0].style.width = width + 'px'; |
|
d70552fc1a66
Fix some javascript error with IE8 (getElementsByClassName() is unknown).
gibus
parents:
424
diff
changeset
|
79 |
} |
| 421 | 80 |
} |
81 |
||
82 |
toggleTocFn = function() { |
|
83 |
if (isTocVisible()) |
|
84 |
hideToc(); |
|
85 |
else |
|
86 |
showToc(); |
|
87 |
} |
|
88 |
||
89 |
hideToc = function() { |
|
90 |
gToc['overlay'].hide(); |
|
91 |
} |
|
92 |
||
93 |
onTocHideAnimEnd = function() { |
|
94 |
// iComment['overlay'].blur() ; |
|
95 |
this.overlay.hide() ; |
|
96 |
gSync.resume() ; |
|
97 |
} |
|
98 |
||
99 |
onTocShowAnimEnd = function() { |
|
100 |
gSync.resume() ; |
|
101 |
} |
|
102 |
||
103 |
showToc= function () { |
|
104 |
removeFormErrMsg(gToc['tocId']) ; |
|
105 |
gIComments.hide() ; |
|
106 |
gToc['overlay'].show(); |
|
107 |
} |
|
108 |
||
109 |
isTocVisible = function () { |
|
110 |
if (gToc != null) |
|
111 |
return gToc['overlay'].get('visible') ; |
|
112 |
return false ; |
|
113 |
} |
|
114 |
||
115 |
function getElementsByTagNames(list,obj) { |
|
116 |
if (!obj) var obj = document; |
|
117 |
var tagNames = list.split(','); |
|
118 |
var resultArray = new Array(); |
|
119 |
for (var i=0;i<tagNames.length;i++) { |
|
120 |
var tags = obj.getElementsByTagName(tagNames[i]); |
|
121 |
for (var j=0;j<tags.length;j++) { |
|
122 |
resultArray.push(tags[j]); |
|
123 |
} |
|
124 |
} |
|
125 |
var testNode = resultArray[0]; |
|
126 |
if (!testNode) return []; |
|
127 |
if (testNode.sourceIndex) { |
|
128 |
resultArray.sort(function (a,b) { |
|
129 |
return a.sourceIndex - b.sourceIndex; |
|
130 |
}); |
|
131 |
} |
|
132 |
else if (testNode.compareDocumentPosition) { |
|
133 |
resultArray.sort(function (a,b) { |
|
134 |
return 3 - (a.compareDocumentPosition(b) & 6); |
|
135 |
}); |
|
136 |
} |
|
137 |
return resultArray; |
|
138 |
} |