Commit 4fd76e81a25db67c6c0c110d0b24073fe66287fd

Authored by William Daniau
1 parent 87b6f1b0d7
Exists in master

Prise en compte du fait qu'il n'y a pas forcément de nextSibling

Showing 1 changed file with 36 additions and 10 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
/* use tags for image/table/object attributes */ 46 46 function tagToInfo(s5=false) {
function tagToInfo() { 47 47 /* All H4 tags */
/* All H5 tags */ 48 48 var atags = document.getElementsByTagName('H4');
var atags = document.getElementsByTagName('H5'); 49
/* extract configuration tags */ 50 49 /* extract configuration tags */
tags=[]; 51 50 tags=[];
for (var i=0; i<atags.length;i++) { 52 51 for (var i=0; i<atags.length;i++) {
var s = atags[i].innerHTML; 53 52 var s = atags[i].innerHTML;
if (s.match(/^#/)) { 54 53 if (s.match(/^#/)) {
atags[i].innerHTML = s.replace('#',''); 55 54 atags[i].innerHTML = s.replace('#','');
tags.push(atags[i]); 56 55 tags.push(atags[i]);
} 57 56 }
} 58 57 }
59 58
var n = tags.length < 3 ? tags.length : 2; 60 59 var n = tags.length < 3 ? tags.length : 2;
for (var i=1; i <= n; i++) { 61 60 for (var i=1; i <= n; i++) {
/* first make the tag not displayed */ 62 61 /* first make the tag not displayed */
tags[i-1].setAttribute("style","display:none;"); 63 62 tags[i-1].setAttribute("style","display:none;");
var s = tags[i-1].innerHTML; 64 63 /* If next sibling is a <br> make it display:none too */
document.getElementById("footinfo"+i).innerHTML = s; 65 64 if (tags[i-1].nextElementSibling && tags[i-1].nextElementSibling.tagName == 'BR') {
65 tags[i-1].nextElementSibling.setAttribute("style","display:none;");
66 }
67 if (s5) {
68 var s = tags[i-1].innerHTML;
69 document.getElementById("footinfo"+i).innerHTML = s;
70 }
} 66 71 }
if (tags.length > 2) { 67 72 }
73
74 /* Convert the two first tags into info */
75 /* use tags for image/table/object attributes */
76 function tagToStyle() {
77 /* All H5 tags */
78 var atags = document.getElementsByTagName('H5');
79 /* extract configuration tags */
80 tags=[];
81 for (var i=0; i<atags.length;i++) {
82 var s = atags[i].innerHTML;
83 if (s.match(/^#/)) {
84 atags[i].innerHTML = s.replace('#','');
85 tags.push(atags[i]);
86 }
87 }
88
89 if (tags.length > 0) {
/* Image tags */ 68 90 /* Image tags */
for (var i=1; i <= tags.length - 2; i++) { 69 91 for (var i=0; i < tags.length; i++) {
var ctag = tags[i+1]; 70 92 var ctag = tags[i];
ctag.setAttribute("style","display:none;"); 71 93 ctag.setAttribute("style","display:none;");
94 /* If next sibling is a <br> make it display:none too */
95 if (ctag.nextElementSibling && ctag.nextElementSibling.tagName == 'BR') {
96 ctag.nextElementSibling.setAttribute("style","display:none;");
97 }
var s = ctag.innerHTML; 72 98 var s = ctag.innerHTML;
/* find next img/table/zim-object */ 73 99 /* find next img/table/zim-object */
ctag = findNextObject(ctag); 74 100 ctag = findNextObject(ctag);
75 101
/* either we found something either null */ 76 102 /* either we found something either null */
if (ctag!=null) { 77 103 if (ctag!=null) {
var style = ctag.getAttribute("style"); 78 104 var style = ctag.getAttribute("style");
var res; 79 105 var res;
style = style == null ? '' : style; 80 106 style = style == null ? '' : style;
if (s == "left") { 81 107 if (s == "left") {
style = style + "float:left; margin-left:0; margin-right:1em;"; 82 108 style = style + "float:left; margin-left:0; margin-right:1em;";
} 83 109 }
if (s == "right") { 84 110 if (s == "right") {
style = style + "float:right; margin-left:1em; margin-right:0;"; 85 111 style = style + "float:right; margin-left:1em; margin-right:0;";
} 86 112 }
if (res = s.match(/^height(.+)$/)) { 87 113 if (res = s.match(/^height(.+)$/)) {
style = style + "height:"+res[1]+";"; 88 114 style = style + "height:"+res[1]+";";
} 89 115 }
if (res = s.match(/^width(.+)$/)) { 90 116 if (res = s.match(/^width(.+)$/)) {
style = style + "width:"+res[1]+"; height:auto;"; 91 117 style = style + "width:"+res[1]+"; height:auto;";
} 92 118 }
if (res = s.match(/^fontsize(.+)$/)) { 93 119 if (res = s.match(/^fontsize(.+)$/)) {
style = style + "font-size:"+res[1]+"%;"; 94 120 style = style + "font-size:"+res[1]+"%;";
} 95 121 }
ctag.setAttribute("style",style); 96 122 ctag.setAttribute("style",style);
} 97 123 }
98 124
} 99 125 }
100 126
} 101 127 }
} 102 128 }
103 129
function findNextObject(tag) { 104 130 function findNextObject(tag) {
/* try to found in current */ 105 131 /* try to found in current */
var objectsTagClassArray=['IMG','','TABLE','','DIV','zim-object','UL','','OL','']; 106 132 var objectsTagClassArray=['IMG','','TABLE','','DIV','zim-object','UL','','OL',''];
ob = findTagInSiblings(tag,objectsTagClassArray); 107 133 ob = findTagInSiblings(tag,objectsTagClassArray);
if (ob == null) { 108 134 if (ob == null) {
ob = findTagInSiblings(tag.parentElement,objectsTagClassArray); 109 135 ob = findTagInSiblings(tag.parentElement,objectsTagClassArray);
} 110 136 }
return ob; 111 137 return ob;
} 112 138 }
113 139
function findTagInSiblings(tag,tagsToFind) { 114 140 function findTagInSiblings(tag,tagsToFind) {
var notFound = true; 115 141 var notFound = true;
var ctag = tag; 116 142 var ctag = tag;
var cctag; 117 143 var cctag;
while (notFound) { 118 144 while (notFound) {
ctag = ctag.nextElementSibling 119 145 ctag = ctag.nextElementSibling
if (ctag == null) { 120 146 if (ctag == null) {
notFound = false; 121 147 notFound = false;
break; 122 148 break;
} 123 149 }
if (isTagInList(ctag,tagsToFind)) { 124 150 if (isTagInList(ctag,tagsToFind)) {
notFound = false; 125 151 notFound = false;
break; 126 152 break;
} 127 153 }
/* now search into children */ 128 154 /* now search into children */
if (ctag.childElementCount != 0) { 129 155 if (ctag.childElementCount != 0) {
for (var i=0;i<ctag.childElementCount;i++) { 130 156 for (var i=0;i<ctag.childElementCount;i++) {
cctag=ctag.children[i]; 131 157 cctag=ctag.children[i];
if (isTagInList(cctag,tagsToFind)) { 132 158 if (isTagInList(cctag,tagsToFind)) {
notFound = false; 133 159 notFound = false;
ctag=cctag; 134 160 ctag=cctag;
break; 135 161 break;
} 136 162 }
} 137 163 }
} 138 164 }
} 139 165 }
return ctag; 140 166 return ctag;
} 141 167 }
142 168
function isTagInList(tag,tagsToFind) { 143 169 function isTagInList(tag,tagsToFind) {
yes = false; 144 170 yes = false;
for (var i=0; i < tagsToFind.length/2 ; i++) { 145 171 for (var i=0; i < tagsToFind.length/2 ; i++) {
if (tag.tagName == tagsToFind[i*2]) { 146 172 if (tag.tagName == tagsToFind[i*2]) {
if (tagsToFind[i*2+1]=='') { 147 173 if (tagsToFind[i*2+1]=='') {
yes = true; 148 174 yes = true;
break; 149 175 break;
} else if (tag.className == tagsToFind[i*2+1]) { 150 176 } else if (tag.className == tagsToFind[i*2+1]) {
yes = true; 151 177 yes = true;
break; 152 178 break;
} 153 179 }
} 154 180 }