From aca67690f1cc3a86bbdf8df1e3d16f40e20b7045 Mon Sep 17 00:00:00 2001 From: William Daniau Date: Thu, 17 Oct 2019 17:34:28 +0200 Subject: [PATCH] Ajout de configuration par tags dans Wize_S5 --- templates/html/common/wizefunc.js | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/templates/html/common/wizefunc.js b/templates/html/common/wizefunc.js index ab8d565..afde500 100644 --- a/templates/html/common/wizefunc.js +++ b/templates/html/common/wizefunc.js @@ -43,6 +43,7 @@ } /* Convert the two first tags into info */ + /* use tags for image/table/object attributes */ function tagToInfo() { var tags = document.getElementsByClassName('zim-tag'); var n = tags.length < 3 ? tags.length : 2; @@ -52,4 +53,74 @@ s = s.replace(/_/g,' '); document.getElementById("footinfo"+i).innerHTML = s; } + if (tags.length > 2) { + /* Image tags */ + for (var i=1; i <= tags.length - 2; i++) { + var ctag = tags[i+1]; + var s = ctag.innerHTML; + s = s.replace('@',''); + /* find next img/table/zim-object */ + ctag = findNextObject(ctag); + + /* either we found something either null */ + if (ctag!=null) { + var style = ctag.getAttribute("style"); + var res; + style = style == null ? '' : style; + if (s == "left") { + style = style + "float:left; margin-left:0; margin-right:1em;"; + } + if (s == "right") { + style = style + "float:right; margin-left:1em; margin-right:0;"; + } + if (res = s.match(/^height(.+)$/)) { + style = style + "height:"+res[1]+";"; + } + if (res = s.match(/^width(.+)$/)) { + style = style + "width:"+res[1]+"; height:auto;"; + } + if (res = s.match(/^fontsize(.+)$/)) { + style = style + "font-size:"+res[1]+"%;"; + } + ctag.setAttribute("style",style); + } + + } + + } + } + + function findNextObject(tag) { + /* try to found in current */ + var objectsTagClassArray=['IMG','','TABLE','','DIV','zim-object']; + ob = findTagInSiblings(tag,objectsTagClassArray); + if (ob == null) { + ob = findTagInSiblings(tag.parentElement,objectsTagClassArray); + } + return ob; + } + + function findTagInSiblings(tag,tagsToFind) { + var notFound = true; + var ctag = tag; + while (notFound) { + ctag = ctag.nextElementSibling + if (ctag == null) { + notFound = false; + break; + } + for (var i=0 ; i < tagsToFind.length/2 ; i++) { + if (ctag.tagName == tagsToFind[i*2]) { + /* we(ve got the tag */ + if (tagsToFind[i*2+1]=='') { + notFound = false; + break; + } else if (ctag.className == tagsToFind[i*2+1]) { + notFound = false; + break; + } + } + } + } + return ctag; } -- 2.16.4