Commit aca67690f1cc3a86bbdf8df1e3d16f40e20b7045
1 parent
0d8dc7302c
Exists in
master
Ajout de configuration par tags dans Wize_S5
Showing 1 changed file with 71 additions and 0 deletions Side-by-side Diff
templates/html/common/wizefunc.js
... | ... | @@ -43,6 +43,7 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | /* Convert the two first tags into info */ |
46 | + /* use tags for image/table/object attributes */ | |
46 | 47 | function tagToInfo() { |
47 | 48 | var tags = document.getElementsByClassName('zim-tag'); |
48 | 49 | var n = tags.length < 3 ? tags.length : 2; |
... | ... | @@ -52,5 +53,75 @@ |
52 | 53 | s = s.replace(/_/g,' '); |
53 | 54 | document.getElementById("footinfo"+i).innerHTML = s; |
54 | 55 | } |
56 | + if (tags.length > 2) { | |
57 | + /* Image tags */ | |
58 | + for (var i=1; i <= tags.length - 2; i++) { | |
59 | + var ctag = tags[i+1]; | |
60 | + var s = ctag.innerHTML; | |
61 | + s = s.replace('@',''); | |
62 | + /* find next img/table/zim-object */ | |
63 | + ctag = findNextObject(ctag); | |
64 | + | |
65 | + /* either we found something either null */ | |
66 | + if (ctag!=null) { | |
67 | + var style = ctag.getAttribute("style"); | |
68 | + var res; | |
69 | + style = style == null ? '' : style; | |
70 | + if (s == "left") { | |
71 | + style = style + "float:left; margin-left:0; margin-right:1em;"; | |
72 | + } | |
73 | + if (s == "right") { | |
74 | + style = style + "float:right; margin-left:1em; margin-right:0;"; | |
75 | + } | |
76 | + if (res = s.match(/^height(.+)$/)) { | |
77 | + style = style + "height:"+res[1]+";"; | |
78 | + } | |
79 | + if (res = s.match(/^width(.+)$/)) { | |
80 | + style = style + "width:"+res[1]+"; height:auto;"; | |
81 | + } | |
82 | + if (res = s.match(/^fontsize(.+)$/)) { | |
83 | + style = style + "font-size:"+res[1]+"%;"; | |
84 | + } | |
85 | + ctag.setAttribute("style",style); | |
86 | + } | |
87 | + | |
88 | + } | |
89 | + | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + function findNextObject(tag) { | |
94 | + /* try to found in current */ | |
95 | + var objectsTagClassArray=['IMG','','TABLE','','DIV','zim-object']; | |
96 | + ob = findTagInSiblings(tag,objectsTagClassArray); | |
97 | + if (ob == null) { | |
98 | + ob = findTagInSiblings(tag.parentElement,objectsTagClassArray); | |
99 | + } | |
100 | + return ob; | |
101 | + } | |
102 | + | |
103 | + function findTagInSiblings(tag,tagsToFind) { | |
104 | + var notFound = true; | |
105 | + var ctag = tag; | |
106 | + while (notFound) { | |
107 | + ctag = ctag.nextElementSibling | |
108 | + if (ctag == null) { | |
109 | + notFound = false; | |
110 | + break; | |
111 | + } | |
112 | + for (var i=0 ; i < tagsToFind.length/2 ; i++) { | |
113 | + if (ctag.tagName == tagsToFind[i*2]) { | |
114 | + /* we(ve got the tag */ | |
115 | + if (tagsToFind[i*2+1]=='') { | |
116 | + notFound = false; | |
117 | + break; | |
118 | + } else if (ctag.className == tagsToFind[i*2+1]) { | |
119 | + notFound = false; | |
120 | + break; | |
121 | + } | |
122 | + } | |
123 | + } | |
124 | + } | |
125 | + return ctag; | |
55 | 126 | } |