Commit 87b6f1b0d70adbe5be08b2c5b3ac2838d039549d
1 parent
6cb8cdc86e
Exists in
master
Utilisation de H5 spéciaux plutôt que de zim-tags
Showing 1 changed file with 48 additions and 15 deletions Inline Diff
templates/html/common/wizefunc.js
1 | 1 | |||
/* Go to top of page */ | 2 | 2 | /* Go to top of page */ | |
function topFunction() { | 3 | 3 | function topFunction() { | |
document.body.scrollTop = 0; | 4 | 4 | document.body.scrollTop = 0; | |
document.documentElement.scrollTop = 0; | 5 | 5 | document.documentElement.scrollTop = 0; | |
} | 6 | 6 | } | |
7 | 7 | |||
/* open/close navigation optionally slide page */ | 8 | 8 | /* open/close navigation optionally slide page */ | |
function openNav(slide) { | 9 | 9 | function openNav(slide) { | |
if (document.getElementById("mySidenav").getAttribute("class").split(' ')[1] == "menuClosed") { | 10 | 10 | if (document.getElementById("mySidenav").getAttribute("class").split(' ')[1] == "menuClosed") { | |
document.getElementById("mySidenav").style.width = "300px"; | 11 | 11 | document.getElementById("mySidenav").style.width = "300px"; | |
if (slide==1) { | 12 | 12 | if (slide==1) { | |
document.getElementById("main").style.marginLeft = "300px"; | 13 | 13 | document.getElementById("main").style.marginLeft = "300px"; | |
} | 14 | 14 | } | |
document.getElementById("mySidenav").setAttribute("class","menu menuOpen"); | 15 | 15 | document.getElementById("mySidenav").setAttribute("class","menu menuOpen"); | |
/* Scroll to top when opening menu */ | 16 | 16 | /* Scroll to top when opening menu */ | |
topFunction(); | 17 | 17 | topFunction(); | |
} else { | 18 | 18 | } else { | |
document.getElementById("mySidenav").style.width = "0"; | 19 | 19 | document.getElementById("mySidenav").style.width = "0"; | |
if (slide==1) { | 20 | 20 | if (slide==1) { | |
document.getElementById("main").style.marginLeft = "0"; | 21 | 21 | document.getElementById("main").style.marginLeft = "0"; | |
} | 22 | 22 | } | |
document.getElementById("mySidenav").setAttribute("class","menu menuClosed"); | 23 | 23 | document.getElementById("mySidenav").setAttribute("class","menu menuClosed"); | |
} | 24 | 24 | } | |
} | 25 | 25 | } | |
26 | 26 | |||
/* when scrolling down 20 pixel display upButton */ | 27 | 27 | /* when scrolling down 20 pixel display upButton */ | |
function scrollFunction() { | 28 | 28 | function scrollFunction() { | |
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | 29 | 29 | if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | |
upButton.style.display = "block"; | 30 | 30 | upButton.style.display = "block"; | |
} else { | 31 | 31 | } else { | |
upButton.style.display = "none"; | 32 | 32 | upButton.style.display = "none"; | |
} | 33 | 33 | } | |
} | 34 | 34 | } | |
35 | 35 | |||
/* Test if the logo is present (to avoid displaying broken link icon on chrome) */ | 36 | 36 | /* Test if the logo is present (to avoid displaying broken link icon on chrome) */ | |
function testLogo() { | 37 | 37 | function testLogo() { | |
logo=document.getElementById("logoImgId"); | 38 | 38 | logo=document.getElementById("logoImgId"); | |
logodiv=document.getElementById("logoDivId"); | 39 | 39 | logodiv=document.getElementById("logoDivId"); | |
if (logo.naturalHeight == 0) { | 40 | 40 | if (logo.naturalHeight == 0) { | |
logodiv.setAttribute("style","display:none;"); | 41 | 41 | logodiv.setAttribute("style","display:none;"); | |
} | 42 | 42 | } | |
} | 43 | 43 | } | |
44 | 44 | |||
/* Convert the two first tags into info */ | 45 | 45 | /* Convert the two first tags into info */ | |
/* use tags for image/table/object attributes */ | 46 | 46 | /* use tags for image/table/object attributes */ | |
function tagToInfo() { | 47 | 47 | function tagToInfo() { | |
var tags = document.getElementsByClassName('zim-tag'); | 48 | 48 | /* All H5 tags */ | |
49 | var atags = document.getElementsByTagName('H5'); | |||
50 | /* extract configuration tags */ | |||
51 | tags=[]; | |||
52 | for (var i=0; i<atags.length;i++) { | |||
53 | var s = atags[i].innerHTML; | |||
54 | if (s.match(/^#/)) { | |||
55 | atags[i].innerHTML = s.replace('#',''); | |||
56 | tags.push(atags[i]); | |||
57 | } | |||
58 | } | |||
59 | ||||
var n = tags.length < 3 ? tags.length : 2; | 49 | 60 | var n = tags.length < 3 ? tags.length : 2; | |
for (var i=1; i <= n; i++) { | 50 | 61 | for (var i=1; i <= n; i++) { | |
62 | /* first make the tag not displayed */ | |||
63 | tags[i-1].setAttribute("style","display:none;"); | |||
var s = tags[i-1].innerHTML; | 51 | 64 | var s = tags[i-1].innerHTML; | |
s = s.replace('@',''); | 52 | |||
s = s.replace(/_/g,' '); | 53 | |||
document.getElementById("footinfo"+i).innerHTML = s; | 54 | 65 | document.getElementById("footinfo"+i).innerHTML = s; | |
} | 55 | 66 | } | |
if (tags.length > 2) { | 56 | 67 | if (tags.length > 2) { | |
/* Image tags */ | 57 | 68 | /* Image tags */ | |
for (var i=1; i <= tags.length - 2; i++) { | 58 | 69 | for (var i=1; i <= tags.length - 2; i++) { | |
var ctag = tags[i+1]; | 59 | 70 | var ctag = tags[i+1]; | |
71 | ctag.setAttribute("style","display:none;"); | |||
var s = ctag.innerHTML; | 60 | 72 | var s = ctag.innerHTML; | |
s = s.replace('@',''); | 61 | |||
/* find next img/table/zim-object */ | 62 | 73 | /* find next img/table/zim-object */ | |
ctag = findNextObject(ctag); | 63 | 74 | ctag = findNextObject(ctag); | |
64 | 75 | |||
/* either we found something either null */ | 65 | 76 | /* either we found something either null */ | |
if (ctag!=null) { | 66 | 77 | if (ctag!=null) { | |
var style = ctag.getAttribute("style"); | 67 | 78 | var style = ctag.getAttribute("style"); | |
var res; | 68 | 79 | var res; | |
style = style == null ? '' : style; | 69 | 80 | style = style == null ? '' : style; | |
if (s == "left") { | 70 | 81 | if (s == "left") { | |
style = style + "float:left; margin-left:0; margin-right:1em;"; | 71 | 82 | style = style + "float:left; margin-left:0; margin-right:1em;"; | |
} | 72 | 83 | } | |
if (s == "right") { | 73 | 84 | if (s == "right") { | |
style = style + "float:right; margin-left:1em; margin-right:0;"; | 74 | 85 | style = style + "float:right; margin-left:1em; margin-right:0;"; | |
} | 75 | 86 | } | |
if (res = s.match(/^height(.+)$/)) { | 76 | 87 | if (res = s.match(/^height(.+)$/)) { | |
style = style + "height:"+res[1]+";"; | 77 | 88 | style = style + "height:"+res[1]+";"; | |
} | 78 | 89 | } | |
if (res = s.match(/^width(.+)$/)) { | 79 | 90 | if (res = s.match(/^width(.+)$/)) { | |
style = style + "width:"+res[1]+"; height:auto;"; | 80 | 91 | style = style + "width:"+res[1]+"; height:auto;"; | |
} | 81 | 92 | } | |
if (res = s.match(/^fontsize(.+)$/)) { | 82 | 93 | if (res = s.match(/^fontsize(.+)$/)) { | |
style = style + "font-size:"+res[1]+"%;"; | 83 | 94 | style = style + "font-size:"+res[1]+"%;"; | |
} | 84 | 95 | } | |
ctag.setAttribute("style",style); | 85 | 96 | ctag.setAttribute("style",style); | |
} | 86 | 97 | } | |
87 | 98 | |||
} | 88 | 99 | } | |
89 | 100 | |||
} | 90 | 101 | } | |
} | 91 | 102 | } | |
92 | 103 | |||
function findNextObject(tag) { | 93 | 104 | function findNextObject(tag) { | |
/* try to found in current */ | 94 | 105 | /* try to found in current */ | |
var objectsTagClassArray=['IMG','','TABLE','','DIV','zim-object']; | 95 | 106 | var objectsTagClassArray=['IMG','','TABLE','','DIV','zim-object','UL','','OL','']; | |
ob = findTagInSiblings(tag,objectsTagClassArray); | 96 | 107 | ob = findTagInSiblings(tag,objectsTagClassArray); | |
if (ob == null) { | 97 | 108 | if (ob == null) { | |
ob = findTagInSiblings(tag.parentElement,objectsTagClassArray); | 98 | 109 | ob = findTagInSiblings(tag.parentElement,objectsTagClassArray); | |
} | 99 | 110 | } | |
return ob; | 100 | 111 | return ob; | |
} | 101 | 112 | } | |
102 | 113 | |||
function findTagInSiblings(tag,tagsToFind) { | 103 | 114 | function findTagInSiblings(tag,tagsToFind) { | |
var notFound = true; | 104 | 115 | var notFound = true; | |
var ctag = tag; | 105 | 116 | var ctag = tag; | |
117 | var cctag; | |||
while (notFound) { | 106 | 118 | while (notFound) { | |
ctag = ctag.nextElementSibling | 107 | 119 | ctag = ctag.nextElementSibling | |
if (ctag == null) { | 108 | 120 | if (ctag == null) { | |
notFound = false; | 109 | 121 | notFound = false; | |
break; | 110 | 122 | break; | |
} | 111 | 123 | } | |
for (var i=0 ; i < tagsToFind.length/2 ; i++) { | 112 | 124 | if (isTagInList(ctag,tagsToFind)) { | |
if (ctag.tagName == tagsToFind[i*2]) { | 113 | 125 | notFound = false; | |
/* we(ve got the tag */ | 114 | 126 | break; | |
if (tagsToFind[i*2+1]=='') { | 115 | 127 | } | |
128 | /* now search into children */ | |||
129 | if (ctag.childElementCount != 0) { | |||
130 | for (var i=0;i<ctag.childElementCount;i++) { | |||
131 | cctag=ctag.children[i]; | |||
132 | if (isTagInList(cctag,tagsToFind)) { | |||
notFound = false; | 116 | 133 | notFound = false; | |
134 | ctag=cctag; | |||
break; | 117 | 135 | break; | |
} else if (ctag.className == tagsToFind[i*2+1]) { | 118 | 136 | } | |
notFound = false; | 119 | |||
break; | 120 | |||
} | 121 | |||
} | 122 | 137 | } | |
} | 123 | 138 | } | |
} | 124 | 139 | } | |
return ctag; | 125 | 140 | return ctag; | |
} | 126 | 141 | } | |
142 | ||||
143 | function isTagInList(tag,tagsToFind) { | |||
144 | yes = false; | |||
145 | for (var i=0; i < tagsToFind.length/2 ; i++) { | |||
146 | if (tag.tagName == tagsToFind[i*2]) { | |||
147 | if (tagsToFind[i*2+1]=='') { | |||
148 | yes = true; | |||
149 | break; | |||
150 | } else if (tag.className == tagsToFind[i*2+1]) { | |||
151 | yes = true; | |||
152 | break; | |||
153 | } | |||
154 | } | |||
155 | } | |||
156 | return yes; | |||
157 | } | |||
158 |