| 1 | /** |
| 2 | * Schema.js |
| 3 | * |
| 4 | * Copyright, Moxiecode Systems AB |
| 5 | * Released under LGPL License. |
| 6 | * |
| 7 | * License: http://www.tinymce.com/license |
| 8 | * Contributing: http://www.tinymce.com/contributing |
| 9 | */ |
| 10 | |
| 11 | (function(tinymce) { |
| 12 | var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each; |
| 13 | |
| 14 | function split(str, delim) { |
| 15 | return str.split(delim || ','); |
| 16 | }; |
| 17 | |
| 18 | /** |
| 19 | * Unpacks the specified lookup and string data it will also parse it into an object |
| 20 | * map with sub object for it's children. This will later also include the attributes. |
| 21 | */ |
| 22 | function unpack(lookup, data) { |
| 23 | var key, elements = {}; |
| 24 | |
| 25 | function replace(value) { |
| 26 | return value.replace(/[A-Z]+/g, function(key) { |
| 27 | return replace(lookup[key]); |
| 28 | }); |
| 29 | }; |
| 30 | |
| 31 | // Unpack lookup |
| 32 | for (key in lookup) { |
| 33 | if (lookup.hasOwnProperty(key)) |
| 34 | lookup[key] = replace(lookup[key]); |
| 35 | } |
| 36 | |
| 37 | // Unpack and parse data into object map |
| 38 | replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) { |
| 39 | attributes = split(attributes, '|'); |
| 40 | |
| 41 | elements[name] = { |
| 42 | attributes : makeMap(attributes), |
| 43 | attributesOrder : attributes, |
| 44 | children : makeMap(children, '|', {'#comment' : {}}) |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | return elements; |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * Returns the HTML5 schema and caches it in the mapCache. |
| 53 | */ |
| 54 | function getHTML5() { |
| 55 | var html5 = mapCache.html5; |
| 56 | |
| 57 | if (!html5) { |
| 58 | html5 = mapCache.html5 = unpack({ |
| 59 | A : 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup', |
| 60 | B : '#|a|abbr|area|audio|b|bdo|br|button|canvas|cite|code|command|datalist|del|dfn|em|embed|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|meta|' + |
| 61 | 'meter|noscript|object|output|progress|q|ruby|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|var|video|wbr', |
| 62 | C : '#|a|abbr|area|address|article|aside|audio|b|bdo|blockquote|br|button|canvas|cite|code|command|datalist|del|details|dfn|dialog|div|dl|em|embed|fieldset|' + |
| 63 | 'figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|menu|meta|meter|nav|noscript|ol|object|output|' + |
| 64 | 'p|pre|progress|q|ruby|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|ul|var|video' |
| 65 | }, 'html[A|manifest][body|head]' + |
| 66 | 'head[A][base|command|link|meta|noscript|script|style|title]' + |
| 67 | 'title[A][#]' + |
| 68 | 'base[A|href|target][]' + |
| 69 | 'link[A|href|rel|media|type|sizes][]' + |
| 70 | 'meta[A|http-equiv|name|content|charset][]' + |
| 71 | 'style[A|type|media|scoped][#]' + |
| 72 | 'script[A|charset|type|src|defer|async][#]' + |
| 73 | 'noscript[A][C]' + |
| 74 | 'body[A][C]' + |
| 75 | 'section[A][C]' + |
| 76 | 'nav[A][C]' + |
| 77 | 'article[A][C]' + |
| 78 | 'aside[A][C]' + |
| 79 | 'h1[A][B]' + |
| 80 | 'h2[A][B]' + |
| 81 | 'h3[A][B]' + |
| 82 | 'h4[A][B]' + |
| 83 | 'h5[A][B]' + |
| 84 | 'h6[A][B]' + |
| 85 | 'hgroup[A][h1|h2|h3|h4|h5|h6]' + |
| 86 | 'header[A][C]' + |
| 87 | 'footer[A][C]' + |
| 88 | 'address[A][C]' + |
| 89 | 'p[A][B]' + |
| 90 | 'br[A][]' + |
| 91 | 'pre[A][B]' + |
| 92 | 'dialog[A][dd|dt]' + |
| 93 | 'blockquote[A|cite][C]' + |
| 94 | 'ol[A|start|reversed][li]' + |
| 95 | 'ul[A][li]' + |
| 96 | 'li[A|value][C]' + |
| 97 | 'dl[A][dd|dt]' + |
| 98 | 'dt[A][B]' + |
| 99 | 'dd[A][C]' + |
| 100 | 'a[A|href|target|ping|rel|media|type][B]' + |
| 101 | 'em[A][B]' + |
| 102 | 'strong[A][B]' + |
| 103 | 'small[A][B]' + |
| 104 | 'cite[A][B]' + |
| 105 | 'q[A|cite][B]' + |
| 106 | 'dfn[A][B]' + |
| 107 | 'abbr[A][B]' + |
| 108 | 'code[A][B]' + |
| 109 | 'var[A][B]' + |
| 110 | 'samp[A][B]' + |
| 111 | 'kbd[A][B]' + |
| 112 | 'sub[A][B]' + |
| 113 | 'sup[A][B]' + |
| 114 | 'i[A][B]' + |
| 115 | 'b[A][B]' + |
| 116 | 'mark[A][B]' + |
| 117 | 'progress[A|value|max][B]' + |
| 118 | 'meter[A|value|min|max|low|high|optimum][B]' + |
| 119 | 'time[A|datetime][B]' + |
| 120 | 'ruby[A][B|rt|rp]' + |
| 121 | 'rt[A][B]' + |
| 122 | 'rp[A][B]' + |
| 123 | 'bdo[A][B]' + |
| 124 | 'span[A][B]' + |
| 125 | 'ins[A|cite|datetime][B]' + |
| 126 | 'del[A|cite|datetime][B]' + |
| 127 | 'figure[A][C|legend|figcaption]' + |
| 128 | 'figcaption[A][C]' + |
| 129 | 'img[A|alt|src|height|width|usemap|ismap][]' + |
| 130 | 'iframe[A|name|src|height|width|sandbox|seamless][]' + |
| 131 | 'embed[A|src|height|width|type][]' + |
| 132 | 'object[A|data|type|height|width|usemap|name|form|classid][param]' + |
| 133 | 'param[A|name|value][]' + |
| 134 | 'details[A|open][C|legend]' + |
| 135 | 'command[A|type|label|icon|disabled|checked|radiogroup][]' + |
| 136 | 'menu[A|type|label][C|li]' + |
| 137 | 'legend[A][C|B]' + |
| 138 | 'div[A][C]' + |
| 139 | 'source[A|src|type|media][]' + |
| 140 | 'audio[A|src|autobuffer|autoplay|loop|controls][source]' + |
| 141 | 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster][source]' + |
| 142 | 'hr[A][]' + |
| 143 | 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' + |
| 144 | 'fieldset[A|disabled|form|name][C|legend]' + |
| 145 | 'label[A|form|for][B]' + |
| 146 | 'input[A|type|accept|alt|autocomplete|autofocus|checked|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|list|max|maxlength|min|' + |
| 147 | 'multiple|pattern|placeholder|readonly|required|size|src|step|width|files|value|name][]' + |
| 148 | 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|value|type][B]' + |
| 149 | 'select[A|autofocus|disabled|form|multiple|name|size][option|optgroup]' + |
| 150 | 'datalist[A][B|option]' + |
| 151 | 'optgroup[A|disabled|label][option]' + |
| 152 | 'option[A|disabled|selected|label|value][]' + |
| 153 | 'textarea[A|autofocus|disabled|form|maxlength|name|placeholder|readonly|required|rows|cols|wrap][]' + |
| 154 | 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' + |
| 155 | 'output[A|for|form|name][B]' + |
| 156 | 'canvas[A|width|height][]' + |
| 157 | 'map[A|name][B|C]' + |
| 158 | 'area[A|shape|coords|href|alt|target|media|rel|ping|type][]' + |
| 159 | 'mathml[A][]' + |
| 160 | 'svg[A][]' + |
| 161 | 'table[A|border][caption|colgroup|thead|tfoot|tbody|tr]' + |
| 162 | 'caption[A][C]' + |
| 163 | 'colgroup[A|span][col]' + |
| 164 | 'col[A|span][]' + |
| 165 | 'thead[A][tr]' + |
| 166 | 'tfoot[A][tr]' + |
| 167 | 'tbody[A][tr]' + |
| 168 | 'tr[A][th|td]' + |
| 169 | 'th[A|headers|rowspan|colspan|scope][B]' + |
| 170 | 'td[A|headers|rowspan|colspan][C]' + |
| 171 | 'wbr[A][]' |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | return html5; |
| 176 | }; |
| 177 | |
| 178 | /** |
| 179 | * Returns the HTML4 schema and caches it in the mapCache. |
| 180 | */ |
| 181 | function getHTML4() { |
| 182 | var html4 = mapCache.html4; |
| 183 | |
| 184 | if (!html4) { |
| 185 | // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size |
| 186 | html4 = mapCache.html4 = unpack({ |
| 187 | Z : 'H|K|N|O|P', |
| 188 | Y : 'X|form|R|Q', |
| 189 | ZG : 'E|span|width|align|char|charoff|valign', |
| 190 | X : 'p|T|div|U|W|isindex|fieldset|table', |
| 191 | ZF : 'E|align|char|charoff|valign', |
| 192 | W : 'pre|hr|blockquote|address|center|noframes', |
| 193 | ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height', |
| 194 | ZD : '[E][S]', |
| 195 | U : 'ul|ol|dl|menu|dir', |
| 196 | ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q', |
| 197 | T : 'h1|h2|h3|h4|h5|h6', |
| 198 | ZB : 'X|S|Q', |
| 199 | S : 'R|P', |
| 200 | ZA : 'a|G|J|M|O|P', |
| 201 | R : 'a|H|K|N|O', |
| 202 | Q : 'noscript|P', |
| 203 | P : 'ins|del|script', |
| 204 | O : 'input|select|textarea|label|button', |
| 205 | N : 'M|L', |
| 206 | M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym', |
| 207 | L : 'sub|sup', |
| 208 | K : 'J|I', |
| 209 | J : 'tt|i|b|u|s|strike', |
| 210 | I : 'big|small|font|basefont', |
| 211 | H : 'G|F', |
| 212 | G : 'br|span|bdo', |
| 213 | F : 'object|applet|img|map|iframe', |
| 214 | E : 'A|B|C', |
| 215 | D : 'accesskey|tabindex|onfocus|onblur', |
| 216 | C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup', |
| 217 | B : 'lang|xml:lang|dir', |
| 218 | A : 'id|class|style|title' |
| 219 | }, 'script[id|charset|type|language|src|defer|xml:space][]' + |
| 220 | 'style[B|id|type|media|title|xml:space][]' + |
| 221 | 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' + |
| 222 | 'param[id|name|value|valuetype|type][]' + |
| 223 | 'p[E|align][#|S]' + |
| 224 | 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' + |
| 225 | 'br[A|clear][]' + |
| 226 | 'span[E][#|S]' + |
| 227 | 'bdo[A|C|B][#|S]' + |
| 228 | 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' + |
| 229 | 'h1[E|align][#|S]' + |
| 230 | 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' + |
| 231 | 'map[B|C|A|name][X|form|Q|area]' + |
| 232 | 'h2[E|align][#|S]' + |
| 233 | 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' + |
| 234 | 'h3[E|align][#|S]' + |
| 235 | 'tt[E][#|S]' + |
| 236 | 'i[E][#|S]' + |
| 237 | 'b[E][#|S]' + |
| 238 | 'u[E][#|S]' + |
| 239 | 's[E][#|S]' + |
| 240 | 'strike[E][#|S]' + |
| 241 | 'big[E][#|S]' + |
| 242 | 'small[E][#|S]' + |
| 243 | 'font[A|B|size|color|face][#|S]' + |
| 244 | 'basefont[id|size|color|face][]' + |
| 245 | 'em[E][#|S]' + |
| 246 | 'strong[E][#|S]' + |
| 247 | 'dfn[E][#|S]' + |
| 248 | 'code[E][#|S]' + |
| 249 | 'q[E|cite][#|S]' + |
| 250 | 'samp[E][#|S]' + |
| 251 | 'kbd[E][#|S]' + |
| 252 | 'var[E][#|S]' + |
| 253 | 'cite[E][#|S]' + |
| 254 | 'abbr[E][#|S]' + |
| 255 | 'acronym[E][#|S]' + |
| 256 | 'sub[E][#|S]' + |
| 257 | 'sup[E][#|S]' + |
| 258 | 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' + |
| 259 | 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' + |
| 260 | 'optgroup[E|disabled|label][option]' + |
| 261 | 'option[E|selected|disabled|label|value][]' + |
| 262 | 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' + |
| 263 | 'label[E|for|accesskey|onfocus|onblur][#|S]' + |
| 264 | 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' + |
| 265 | 'h4[E|align][#|S]' + |
| 266 | 'ins[E|cite|datetime][#|Y]' + |
| 267 | 'h5[E|align][#|S]' + |
| 268 | 'del[E|cite|datetime][#|Y]' + |
| 269 | 'h6[E|align][#|S]' + |
| 270 | 'div[E|align][#|Y]' + |
| 271 | 'ul[E|type|compact][li]' + |
| 272 | 'li[E|type|value][#|Y]' + |
| 273 | 'ol[E|type|compact|start][li]' + |
| 274 | 'dl[E|compact][dt|dd]' + |
| 275 | 'dt[E][#|S]' + |
| 276 | 'dd[E][#|Y]' + |
| 277 | 'menu[E|compact][li]' + |
| 278 | 'dir[E|compact][li]' + |
| 279 | 'pre[E|width|xml:space][#|ZA]' + |
| 280 | 'hr[E|align|noshade|size|width][]' + |
| 281 | 'blockquote[E|cite][#|Y]' + |
| 282 | 'address[E][#|S|p]' + |
| 283 | 'center[E][#|Y]' + |
| 284 | 'noframes[E][#|Y]' + |
| 285 | 'isindex[A|B|prompt][]' + |
| 286 | 'fieldset[E][#|legend|Y]' + |
| 287 | 'legend[E|accesskey|align][#|S]' + |
| 288 | 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' + |
| 289 | 'caption[E|align][#|S]' + |
| 290 | 'col[ZG][]' + |
| 291 | 'colgroup[ZG][col]' + |
| 292 | 'thead[ZF][tr]' + |
| 293 | 'tr[ZF|bgcolor][th|td]' + |
| 294 | 'th[E|ZE][#|Y]' + |
| 295 | 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' + |
| 296 | 'noscript[E][#|Y]' + |
| 297 | 'td[E|ZE][#|Y]' + |
| 298 | 'tfoot[ZF][tr]' + |
| 299 | 'tbody[ZF][tr]' + |
| 300 | 'area[E|D|shape|coords|href|nohref|alt|target][]' + |
| 301 | 'base[id|href|target][]' + |
| 302 | 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]' |
| 303 | ); |
| 304 | } |
| 305 | |
| 306 | return html4; |
| 307 | }; |
| 308 | |
| 309 | /** |
| 310 | * WordPress Core |
| 311 | * |
| 312 | * Returns a schema that is the result of a deep merge between the HTML5 |
| 313 | * and HTML4 schemas. |
| 314 | */ |
| 315 | function getSaneSchema() { |
| 316 | var cachedMapCache = mapCache, |
| 317 | html5, html4; |
| 318 | |
| 319 | // Bust the mapCache so we're not dealing with the other schema objects. |
| 320 | mapCache = {}; |
| 321 | html5 = getHTML5(); |
| 322 | html4 = getHTML4(); |
| 323 | mapCache = cachedMapCache; |
| 324 | |
| 325 | |
| 326 | each( html4, function( html4settings, tag ) { |
| 327 | var html5settings = html5[ tag ], |
| 328 | difference = []; |
| 329 | |
| 330 | // Merge tags missing in HTML5 mode. |
| 331 | if ( ! html5settings ) { |
| 332 | html5[ tag ] = html4settings; |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | // Merge attributes missing from this HTML5 tag. |
| 337 | each( html4settings.attributes, function( attribute, key ) { |
| 338 | if ( ! html5settings.attributes[ key ] ) |
| 339 | html5settings.attributes[ key ] = attribute; |
| 340 | }); |
| 341 | |
| 342 | // Merge any missing attributes into the attributes order. |
| 343 | each( html4settings.attributesOrder, function( key ) { |
| 344 | if ( -1 === tinymce.inArray( html5settings.attributesOrder, key ) ) |
| 345 | difference.push( key ); |
| 346 | }); |
| 347 | |
| 348 | html5settings.attributesOrder = html5settings.attributesOrder.concat( difference ); |
| 349 | |
| 350 | // Merge children missing from this HTML5 tag. |
| 351 | each( html4settings.children, function( child, key ) { |
| 352 | if ( ! html5settings.children[ key ] ) |
| 353 | html5settings.children[ key ] = child; |
| 354 | }); |
| 355 | }); |
| 356 | |
| 357 | return html5; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Returns Nacin's HTML5 schema. |
| 362 | */ |
| 363 | function getNacinSchema() { |
| 364 | var html5 = mapCache.nacin; |
| 365 | |
| 366 | if (!html5) { |
| 367 | html5 = mapCache.nacin = unpack({ |
| 368 | A : 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup|lang|xml:lang|dir', |
| 369 | B : '#|a|abbr|area|audio|b|bdo|br|button|canvas|cite|code|command|datalist|del|dfn|em|embed|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|meta|' + |
| 370 | 'meter|noscript|object|output|progress|q|ruby|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|var|video|wbr|acronym|basefont|font|big|strike|s|u|tt|applet', |
| 371 | C : '#|a|abbr|area|address|article|aside|audio|b|bdo|blockquote|br|button|canvas|cite|code|command|datalist|del|details|dfn|dialog|div|dl|em|embed|fieldset|' + |
| 372 | 'figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|menu|meta|meter|nav|noscript|ol|object|output|' + |
| 373 | 'p|pre|progress|q|ruby|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|ul|var|video|acronym|basefont|font|big|strike|s|u|tt|applet|isindex|noframes|center|dir|wbr' |
| 374 | }, 'html[A|manifest][body|head]' + |
| 375 | 'head[A][base|command|link|meta|noscript|script|style|title]' + |
| 376 | 'title[A][#]' + |
| 377 | 'base[A|href|target][]' + |
| 378 | 'link[A|href|rel|media|type|sizes][]' + |
| 379 | 'meta[A|http-equiv|name|content|charset][]' + |
| 380 | 'style[A|type|media|scoped|xml:space][#]' + |
| 381 | 'script[A|charset|type|src|defer|async|language|xml:space][#]' + |
| 382 | 'noscript[A][C]' + |
| 383 | 'body[A|onload|onunload|background|bgcolor|text|link|vlink|alink][C]' + |
| 384 | 'section[A][C]' + |
| 385 | 'nav[A][C]' + |
| 386 | 'article[A][C]' + |
| 387 | 'aside[A][C]' + |
| 388 | 'h1[A|align][B]' + |
| 389 | 'h2[A|align][B]' + |
| 390 | 'h3[A|align][B]' + |
| 391 | 'h4[A|align][B]' + |
| 392 | 'h5[A|align][B]' + |
| 393 | 'h6[A|align][B]' + |
| 394 | 'hgroup[A][h1|h2|h3|h4|h5|h6]' + |
| 395 | 'header[A][C]' + |
| 396 | 'footer[A][C]' + |
| 397 | 'address[A][C]' + |
| 398 | 'p[A|align][B]' + |
| 399 | 'br[A|clear][]' + |
| 400 | 'pre[A|width|xml:space][B]' + |
| 401 | 'dialog[A][dd|dt]' + |
| 402 | 'blockquote[A|cite][C]' + |
| 403 | 'ol[A|start|reversed|type|compact][li]' + |
| 404 | 'ul[A|type|compact][li]' + |
| 405 | 'li[A|value|type][C]' + |
| 406 | 'dl[A|compact][dd|dt]' + |
| 407 | 'dt[A][B]' + |
| 408 | 'dd[A][C]' + |
| 409 | 'a[A|href|target|ping|rel|media|type|tabindex|onfocus|onblur|charset|name|hreflang|rev|shape|coords][B]' + |
| 410 | 'em[A][B]' + |
| 411 | 'strong[A][B]' + |
| 412 | 'small[A][B]' + |
| 413 | 'cite[A][B]' + |
| 414 | 'q[A|cite][B]' + |
| 415 | 'dfn[A][B]' + |
| 416 | 'abbr[A][B]' + |
| 417 | 'code[A][B]' + |
| 418 | 'var[A][B]' + |
| 419 | 'samp[A][B]' + |
| 420 | 'kbd[A][B]' + |
| 421 | 'sub[A][B]' + |
| 422 | 'sup[A][B]' + |
| 423 | 'i[A][B]' + |
| 424 | 'b[A][B]' + |
| 425 | 'mark[A][B]' + |
| 426 | 'progress[A|value|max][B]' + |
| 427 | 'meter[A|value|min|max|low|high|optimum][B]' + |
| 428 | 'time[A|datetime][B]' + |
| 429 | 'ruby[A][B|rt|rp]' + |
| 430 | 'rt[A][B]' + |
| 431 | 'rp[A][B]' + |
| 432 | 'bdo[A][B]' + |
| 433 | 'span[A][B]' + |
| 434 | 'ins[A|cite|datetime][C]' + |
| 435 | 'del[A|cite|datetime][C]' + |
| 436 | 'figure[A][C|legend|figcaption]' + |
| 437 | 'figcaption[A][C]' + |
| 438 | 'img[A|alt|src|height|width|usemap|ismap|name|longdesc|align|border|hspace|vspace][]' + |
| 439 | 'iframe[A|name|src|height|width|sandbox|seamless|longdesc|frameborder|marginwidth|marginheight|scrolling|align][]' + |
| 440 | 'embed[A|src|height|width|type][]' + |
| 441 | 'object[*][]' + |
| 442 | 'param[A|name|value|valuetype|type][]' + |
| 443 | 'details[A|open][C|legend]' + |
| 444 | 'command[A|type|label|icon|disabled|checked|radiogroup][]' + |
| 445 | 'menu[A|type|label|compact][C|li]' + |
| 446 | 'legend[A|align][C|B]' + |
| 447 | 'div[A|align][C]' + |
| 448 | 'source[A|src|type|media][]' + |
| 449 | 'audio[A|src|autobuffer|autoplay|loop|controls][source]' + |
| 450 | 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster][source]' + |
| 451 | 'hr[A|align|noshade|size|width][]' + |
| 452 | 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target|onsubmit|onreset|accept][C]' + |
| 453 | 'fieldset[A|disabled|form|name][C|legend]' + |
| 454 | 'label[A|form|for|onfocus|onblur][B]' + |
| 455 | 'input[A|type|accept|alt|autocomplete|autofocus|checked|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|list|max|maxlength|min|' + |
| 456 | 'multiple|pattern|placeholder|readonly|required|size|src|step|width|files|value|name|tabindex|onfocus|onblur|usemap|onselect|onchange|align][]' + |
| 457 | 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|value|type|tabindex|onfocus|onblur][C]' + |
| 458 | 'select[A|autofocus|disabled|form|multiple|name|size|tabindex|onfocus|onblur|onchange][option|optgroup]' + |
| 459 | 'datalist[A][B|option]' + |
| 460 | 'optgroup[A|disabled|label][option]' + |
| 461 | 'option[A|disabled|selected|label|value][]' + |
| 462 | 'textarea[A|autofocus|disabled|form|maxlength|name|placeholder|readonly|required|rows|cols|wrap|tabindex|onfocus|onblur|onselect|onchange][]' + |
| 463 | 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' + |
| 464 | 'output[A|for|form|name][B]' + |
| 465 | 'canvas[A|width|height][]' + |
| 466 | 'map[A|name][B|C]' + |
| 467 | 'area[A|shape|coords|href|alt|target|media|rel|ping|type|tabindex|onfocus|onblur|nohref][]' + |
| 468 | 'mathml[A][]' + |
| 469 | 'svg[A][]' + |
| 470 | 'table[A|border|summary|width|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|colgroup|thead|tfoot|tbody|tr|col]' + |
| 471 | 'caption[A|align][C]' + |
| 472 | 'colgroup[A|span|width|align|char|charoff|valign][col]' + |
| 473 | 'col[A|span|width|align|char|charoff|valign][]' + |
| 474 | 'thead[A|align|char|charoff|valign][tr]' + |
| 475 | 'tfoot[A|align|char|charoff|valign][tr]' + |
| 476 | 'tbody[A|align|char|charoff|valign][tr]' + |
| 477 | 'tr[A|align|char|charoff|valign|bgcolor][th|td]' + |
| 478 | 'th[A|headers|rowspan|colspan|scope|abbr|axis|align|char|charoff|valign|nowrap|bgcolor|width|height][C]' + |
| 479 | 'td[A|headers|rowspan|colspan|abbr|axis|scope|align|char|charoff|valign|nowrap|bgcolor|width|height][C]' + |
| 480 | 'wbr[A][]' + |
| 481 | 'applet[id|class|style|title|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][C|param]' + |
| 482 | 'tt[A][B]' + |
| 483 | 'u[A][B]' + |
| 484 | 's[A][B]' + |
| 485 | 'strike[A][B]' + |
| 486 | 'big[A][B]' + |
| 487 | 'font[id|class|style|title|lang|xml:lang|dir|size|color|face][B]' + |
| 488 | 'basefont[id|size|color|face][]' + |
| 489 | 'acronym[A][C]' + |
| 490 | 'dir[A|compact][li]' + |
| 491 | 'center[A][C]' + |
| 492 | 'noframes[A][C]' + |
| 493 | 'isindex[id|class|style|title|lang|xml:lang|dir|prompt][]' |
| 494 | ); |
| 495 | } |
| 496 | |
| 497 | return html5; |
| 498 | }; |
| 499 | |
| 500 | /** |
| 501 | * Schema validator class. |
| 502 | * |
| 503 | * @class tinymce.html.Schema |
| 504 | * @example |
| 505 | * if (tinymce.activeEditor.schema.isValidChild('p', 'span')) |
| 506 | * alert('span is valid child of p.'); |
| 507 | * |
| 508 | * if (tinymce.activeEditor.schema.getElementRule('p')) |
| 509 | * alert('P is a valid element.'); |
| 510 | * |
| 511 | * @class tinymce.html.Schema |
| 512 | * @version 3.4 |
| 513 | */ |
| 514 | |
| 515 | /** |
| 516 | * Constructs a new Schema instance. |
| 517 | * |
| 518 | * @constructor |
| 519 | * @method Schema |
| 520 | * @param {Object} settings Name/value settings object. |
| 521 | */ |
| 522 | tinymce.html.Schema = function(settings) { |
| 523 | var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems; |
| 524 | var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {}; |
| 525 | |
| 526 | // Creates an lookup table map object for the specified option or the default value |
| 527 | function createLookupTable(option, default_value, extend) { |
| 528 | var value = settings[option]; |
| 529 | |
| 530 | if (!value) { |
| 531 | // Get cached default map or make it if needed |
| 532 | value = mapCache[option]; |
| 533 | |
| 534 | if (!value) { |
| 535 | value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' ')); |
| 536 | value = tinymce.extend(value, extend); |
| 537 | |
| 538 | mapCache[option] = value; |
| 539 | } |
| 540 | } else { |
| 541 | // Create custom map |
| 542 | value = makeMap(value, ',', makeMap(value.toUpperCase(), ' ')); |
| 543 | } |
| 544 | |
| 545 | return value; |
| 546 | }; |
| 547 | |
| 548 | settings = settings || {}; |
| 549 | |
| 550 | /** |
| 551 | * WordPress core uses a sane schema in place of the default "HTML5" schema. |
| 552 | */ |
| 553 | schemaItems = settings.schema == "html5" ? getSaneSchema() : getHTML4(); |
| 554 | |
| 555 | // Koop |
| 556 | window.schema = { |
| 557 | html4: getHTML4(), |
| 558 | html5: getHTML5(), |
| 559 | nacin: getNacinSchema(), |
| 560 | sane: getSaneSchema() |
| 561 | }; |
| 562 | |
| 563 | (function( schema ){ |
| 564 | var sane = schema.sane, |
| 565 | nacin = schema.nacin, |
| 566 | tags, settings; |
| 567 | |
| 568 | tags = _.isEqual( _.keys( sane ), _.keys( nacin ) ); |
| 569 | console.log( 'same tags?', tags ); |
| 570 | |
| 571 | _.each( sane, function( saneopts, tag ) { |
| 572 | var nacinopts = nacin[ tag ], |
| 573 | sAttributes = _.keys( saneopts.attributes ), |
| 574 | nAttributes = _.keys( nacinopts.attributes ), |
| 575 | sAttributesOrder = saneopts.attributesOrder, |
| 576 | nAttributesOrder = nacinopts.attributesOrder, |
| 577 | sChildren = _.keys( saneopts.children ), |
| 578 | nChildren = _.keys( nacinopts.children ); |
| 579 | |
| 580 | console.log( tag, 'attributes differences -- ' |
| 581 | ,'sane only', _.difference( sAttributes, nAttributes ) |
| 582 | // ,'nacin only', _.difference( nAttributes, sAttributes ) |
| 583 | ); |
| 584 | // console.log( tag, 'attributesOrder differences -- ' |
| 585 | // // ,'sane only', _.difference( sAttributesOrder, nAttributesOrder ) |
| 586 | // ,'nacin only', _.difference( nAttributesOrder, sAttributesOrder ) |
| 587 | // ); |
| 588 | console.log( tag, 'children differences -- ' |
| 589 | ,'sane only', _.difference( sChildren, nChildren ) |
| 590 | // ,'nacin only', _.difference( nChildren, sChildren ) |
| 591 | ); |
| 592 | }); |
| 593 | }( window.schema )); |
| 594 | // Koop |
| 595 | |
| 596 | // Allow all elements and attributes if verify_html is set to false |
| 597 | if (settings.verify_html === false) |
| 598 | settings.valid_elements = '*[*]'; |
| 599 | |
| 600 | // Build styles list |
| 601 | if (settings.valid_styles) { |
| 602 | validStyles = {}; |
| 603 | |
| 604 | // Convert styles into a rule list |
| 605 | each(settings.valid_styles, function(value, key) { |
| 606 | validStyles[key] = tinymce.explode(value); |
| 607 | }); |
| 608 | } |
| 609 | |
| 610 | // Setup map objects |
| 611 | whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea'); |
| 612 | selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr'); |
| 613 | shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr'); |
| 614 | boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls'); |
| 615 | nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap); |
| 616 | textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' + |
| 617 | 'blockquote center dir fieldset header footer article section hgroup aside nav figure'); |
| 618 | blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + |
| 619 | 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option datalist select optgroup', textBlockElementsMap); |
| 620 | |
| 621 | // Converts a wildcard expression string to a regexp for example *a will become /.*a/. |
| 622 | function patternToRegExp(str) { |
| 623 | return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$'); |
| 624 | }; |
| 625 | |
| 626 | // Parses the specified valid_elements string and adds to the current rules |
| 627 | // This function is a bit hard to read since it's heavily optimized for speed |
| 628 | function addValidElements(valid_elements) { |
| 629 | var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, |
| 630 | prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value, |
| 631 | elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/, |
| 632 | attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/, |
| 633 | hasPatternsRegExp = /[*?+]/; |
| 634 | |
| 635 | if (valid_elements) { |
| 636 | // Split valid elements into an array with rules |
| 637 | valid_elements = split(valid_elements); |
| 638 | |
| 639 | if (elements['@']) { |
| 640 | globalAttributes = elements['@'].attributes; |
| 641 | globalAttributesOrder = elements['@'].attributesOrder; |
| 642 | } |
| 643 | |
| 644 | // Loop all rules |
| 645 | for (ei = 0, el = valid_elements.length; ei < el; ei++) { |
| 646 | // Parse element rule |
| 647 | matches = elementRuleRegExp.exec(valid_elements[ei]); |
| 648 | if (matches) { |
| 649 | // Setup local names for matches |
| 650 | prefix = matches[1]; |
| 651 | elementName = matches[2]; |
| 652 | outputName = matches[3]; |
| 653 | attrData = matches[4]; |
| 654 | |
| 655 | // Create new attributes and attributesOrder |
| 656 | attributes = {}; |
| 657 | attributesOrder = []; |
| 658 | |
| 659 | // Create the new element |
| 660 | element = { |
| 661 | attributes : attributes, |
| 662 | attributesOrder : attributesOrder |
| 663 | }; |
| 664 | |
| 665 | // Padd empty elements prefix |
| 666 | if (prefix === '#') |
| 667 | element.paddEmpty = true; |
| 668 | |
| 669 | // Remove empty elements prefix |
| 670 | if (prefix === '-') |
| 671 | element.removeEmpty = true; |
| 672 | |
| 673 | // Copy attributes from global rule into current rule |
| 674 | if (globalAttributes) { |
| 675 | for (key in globalAttributes) |
| 676 | attributes[key] = globalAttributes[key]; |
| 677 | |
| 678 | attributesOrder.push.apply(attributesOrder, globalAttributesOrder); |
| 679 | } |
| 680 | |
| 681 | // Attributes defined |
| 682 | if (attrData) { |
| 683 | attrData = split(attrData, '|'); |
| 684 | for (ai = 0, al = attrData.length; ai < al; ai++) { |
| 685 | matches = attrRuleRegExp.exec(attrData[ai]); |
| 686 | if (matches) { |
| 687 | attr = {}; |
| 688 | attrType = matches[1]; |
| 689 | attrName = matches[2].replace(/::/g, ':'); |
| 690 | prefix = matches[3]; |
| 691 | value = matches[4]; |
| 692 | |
| 693 | // Required |
| 694 | if (attrType === '!') { |
| 695 | element.attributesRequired = element.attributesRequired || []; |
| 696 | element.attributesRequired.push(attrName); |
| 697 | attr.required = true; |
| 698 | } |
| 699 | |
| 700 | // Denied from global |
| 701 | if (attrType === '-') { |
| 702 | delete attributes[attrName]; |
| 703 | attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1); |
| 704 | continue; |
| 705 | } |
| 706 | |
| 707 | // Default value |
| 708 | if (prefix) { |
| 709 | // Default value |
| 710 | if (prefix === '=') { |
| 711 | element.attributesDefault = element.attributesDefault || []; |
| 712 | element.attributesDefault.push({name: attrName, value: value}); |
| 713 | attr.defaultValue = value; |
| 714 | } |
| 715 | |
| 716 | // Forced value |
| 717 | if (prefix === ':') { |
| 718 | element.attributesForced = element.attributesForced || []; |
| 719 | element.attributesForced.push({name: attrName, value: value}); |
| 720 | attr.forcedValue = value; |
| 721 | } |
| 722 | |
| 723 | // Required values |
| 724 | if (prefix === '<') |
| 725 | attr.validValues = makeMap(value, '?'); |
| 726 | } |
| 727 | |
| 728 | // Check for attribute patterns |
| 729 | if (hasPatternsRegExp.test(attrName)) { |
| 730 | element.attributePatterns = element.attributePatterns || []; |
| 731 | attr.pattern = patternToRegExp(attrName); |
| 732 | element.attributePatterns.push(attr); |
| 733 | } else { |
| 734 | // Add attribute to order list if it doesn't already exist |
| 735 | if (!attributes[attrName]) |
| 736 | attributesOrder.push(attrName); |
| 737 | |
| 738 | attributes[attrName] = attr; |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | // Global rule, store away these for later usage |
| 745 | if (!globalAttributes && elementName == '@') { |
| 746 | globalAttributes = attributes; |
| 747 | globalAttributesOrder = attributesOrder; |
| 748 | } |
| 749 | |
| 750 | // Handle substitute elements such as b/strong |
| 751 | if (outputName) { |
| 752 | element.outputName = elementName; |
| 753 | elements[outputName] = element; |
| 754 | } |
| 755 | |
| 756 | // Add pattern or exact element |
| 757 | if (hasPatternsRegExp.test(elementName)) { |
| 758 | element.pattern = patternToRegExp(elementName); |
| 759 | patternElements.push(element); |
| 760 | } else |
| 761 | elements[elementName] = element; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | }; |
| 766 | |
| 767 | function setValidElements(valid_elements) { |
| 768 | elements = {}; |
| 769 | patternElements = []; |
| 770 | |
| 771 | addValidElements(valid_elements); |
| 772 | |
| 773 | each(schemaItems, function(element, name) { |
| 774 | children[name] = element.children; |
| 775 | }); |
| 776 | }; |
| 777 | |
| 778 | // Adds custom non HTML elements to the schema |
| 779 | function addCustomElements(custom_elements) { |
| 780 | var customElementRegExp = /^(~)?(.+)$/; |
| 781 | |
| 782 | if (custom_elements) { |
| 783 | each(split(custom_elements), function(rule) { |
| 784 | var matches = customElementRegExp.exec(rule), |
| 785 | inline = matches[1] === '~', |
| 786 | cloneName = inline ? 'span' : 'div', |
| 787 | name = matches[2]; |
| 788 | |
| 789 | children[name] = children[cloneName]; |
| 790 | customElementsMap[name] = cloneName; |
| 791 | |
| 792 | // If it's not marked as inline then add it to valid block elements |
| 793 | if (!inline) { |
| 794 | blockElementsMap[name.toUpperCase()] = {}; |
| 795 | blockElementsMap[name] = {}; |
| 796 | } |
| 797 | |
| 798 | // Add elements clone if needed |
| 799 | if (!elements[name]) { |
| 800 | elements[name] = elements[cloneName]; |
| 801 | } |
| 802 | |
| 803 | // Add custom elements at span/div positions |
| 804 | each(children, function(element, child) { |
| 805 | if (element[cloneName]) |
| 806 | element[name] = element[cloneName]; |
| 807 | }); |
| 808 | }); |
| 809 | } |
| 810 | }; |
| 811 | |
| 812 | // Adds valid children to the schema object |
| 813 | function addValidChildren(valid_children) { |
| 814 | var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/; |
| 815 | |
| 816 | if (valid_children) { |
| 817 | each(split(valid_children), function(rule) { |
| 818 | var matches = childRuleRegExp.exec(rule), parent, prefix; |
| 819 | |
| 820 | if (matches) { |
| 821 | prefix = matches[1]; |
| 822 | |
| 823 | // Add/remove items from default |
| 824 | if (prefix) |
| 825 | parent = children[matches[2]]; |
| 826 | else |
| 827 | parent = children[matches[2]] = {'#comment' : {}}; |
| 828 | |
| 829 | parent = children[matches[2]]; |
| 830 | |
| 831 | each(split(matches[3], '|'), function(child) { |
| 832 | if (prefix === '-') |
| 833 | delete parent[child]; |
| 834 | else |
| 835 | parent[child] = {}; |
| 836 | }); |
| 837 | } |
| 838 | }); |
| 839 | } |
| 840 | }; |
| 841 | |
| 842 | function getElementRule(name) { |
| 843 | var element = elements[name], i; |
| 844 | |
| 845 | // Exact match found |
| 846 | if (element) |
| 847 | return element; |
| 848 | |
| 849 | // No exact match then try the patterns |
| 850 | i = patternElements.length; |
| 851 | while (i--) { |
| 852 | element = patternElements[i]; |
| 853 | |
| 854 | if (element.pattern.test(name)) |
| 855 | return element; |
| 856 | } |
| 857 | }; |
| 858 | |
| 859 | if (!settings.valid_elements) { |
| 860 | // No valid elements defined then clone the elements from the schema spec |
| 861 | each(schemaItems, function(element, name) { |
| 862 | elements[name] = { |
| 863 | attributes : element.attributes, |
| 864 | attributesOrder : element.attributesOrder |
| 865 | }; |
| 866 | |
| 867 | children[name] = element.children; |
| 868 | }); |
| 869 | |
| 870 | // Switch these on HTML4 |
| 871 | if (settings.schema != "html5") { |
| 872 | each(split('strong/b,em/i'), function(item) { |
| 873 | item = split(item, '/'); |
| 874 | elements[item[1]].outputName = item[0]; |
| 875 | }); |
| 876 | } |
| 877 | |
| 878 | // Add default alt attribute for images |
| 879 | elements.img.attributesDefault = [{name: 'alt', value: ''}]; |
| 880 | |
| 881 | // Remove these if they are empty by default |
| 882 | each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) { |
| 883 | if (elements[name]) { |
| 884 | elements[name].removeEmpty = true; |
| 885 | } |
| 886 | }); |
| 887 | |
| 888 | // Padd these by default |
| 889 | each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) { |
| 890 | elements[name].paddEmpty = true; |
| 891 | }); |
| 892 | } else |
| 893 | setValidElements(settings.valid_elements); |
| 894 | |
| 895 | addCustomElements(settings.custom_elements); |
| 896 | addValidChildren(settings.valid_children); |
| 897 | addValidElements(settings.extended_valid_elements); |
| 898 | |
| 899 | // Todo: Remove this when we fix list handling to be valid |
| 900 | addValidChildren('+ol[ul|ol],+ul[ul|ol]'); |
| 901 | |
| 902 | // Delete invalid elements |
| 903 | if (settings.invalid_elements) { |
| 904 | tinymce.each(tinymce.explode(settings.invalid_elements), function(item) { |
| 905 | if (elements[item]) |
| 906 | delete elements[item]; |
| 907 | }); |
| 908 | } |
| 909 | |
| 910 | // If the user didn't allow span only allow internal spans |
| 911 | if (!getElementRule('span')) |
| 912 | addValidElements('span[!data-mce-type|*]'); |
| 913 | |
| 914 | /** |
| 915 | * Name/value map object with valid parents and children to those parents. |
| 916 | * |
| 917 | * @example |
| 918 | * children = { |
| 919 | * div:{p:{}, h1:{}} |
| 920 | * }; |
| 921 | * @field children |
| 922 | * @type {Object} |
| 923 | */ |
| 924 | self.children = children; |
| 925 | |
| 926 | /** |
| 927 | * Name/value map object with valid styles for each element. |
| 928 | * |
| 929 | * @field styles |
| 930 | * @type {Object} |
| 931 | */ |
| 932 | self.styles = validStyles; |
| 933 | |
| 934 | /** |
| 935 | * Returns a map with boolean attributes. |
| 936 | * |
| 937 | * @method getBoolAttrs |
| 938 | * @return {Object} Name/value lookup map for boolean attributes. |
| 939 | */ |
| 940 | self.getBoolAttrs = function() { |
| 941 | return boolAttrMap; |
| 942 | }; |
| 943 | |
| 944 | /** |
| 945 | * Returns a map with block elements. |
| 946 | * |
| 947 | * @method getBlockElements |
| 948 | * @return {Object} Name/value lookup map for block elements. |
| 949 | */ |
| 950 | self.getBlockElements = function() { |
| 951 | return blockElementsMap; |
| 952 | }; |
| 953 | |
| 954 | /** |
| 955 | * Returns a map with text block elements. Such as: p,h1-h6,div,address |
| 956 | * |
| 957 | * @method getTextBlockElements |
| 958 | * @return {Object} Name/value lookup map for block elements. |
| 959 | */ |
| 960 | self.getTextBlockElements = function() { |
| 961 | return textBlockElementsMap; |
| 962 | }; |
| 963 | |
| 964 | /** |
| 965 | * Returns a map with short ended elements such as BR or IMG. |
| 966 | * |
| 967 | * @method getShortEndedElements |
| 968 | * @return {Object} Name/value lookup map for short ended elements. |
| 969 | */ |
| 970 | self.getShortEndedElements = function() { |
| 971 | return shortEndedElementsMap; |
| 972 | }; |
| 973 | |
| 974 | /** |
| 975 | * Returns a map with self closing tags such as <li>. |
| 976 | * |
| 977 | * @method getSelfClosingElements |
| 978 | * @return {Object} Name/value lookup map for self closing tags elements. |
| 979 | */ |
| 980 | self.getSelfClosingElements = function() { |
| 981 | return selfClosingElementsMap; |
| 982 | }; |
| 983 | |
| 984 | /** |
| 985 | * Returns a map with elements that should be treated as contents regardless if it has text |
| 986 | * content in them or not such as TD, VIDEO or IMG. |
| 987 | * |
| 988 | * @method getNonEmptyElements |
| 989 | * @return {Object} Name/value lookup map for non empty elements. |
| 990 | */ |
| 991 | self.getNonEmptyElements = function() { |
| 992 | return nonEmptyElementsMap; |
| 993 | }; |
| 994 | |
| 995 | /** |
| 996 | * Returns a map with elements where white space is to be preserved like PRE or SCRIPT. |
| 997 | * |
| 998 | * @method getWhiteSpaceElements |
| 999 | * @return {Object} Name/value lookup map for white space elements. |
| 1000 | */ |
| 1001 | self.getWhiteSpaceElements = function() { |
| 1002 | return whiteSpaceElementsMap; |
| 1003 | }; |
| 1004 | |
| 1005 | /** |
| 1006 | * Returns true/false if the specified element and it's child is valid or not |
| 1007 | * according to the schema. |
| 1008 | * |
| 1009 | * @method isValidChild |
| 1010 | * @param {String} name Element name to check for. |
| 1011 | * @param {String} child Element child to verify. |
| 1012 | * @return {Boolean} True/false if the element is a valid child of the specified parent. |
| 1013 | */ |
| 1014 | self.isValidChild = function(name, child) { |
| 1015 | var parent = children[name]; |
| 1016 | |
| 1017 | return !!(parent && parent[child]); |
| 1018 | }; |
| 1019 | |
| 1020 | /** |
| 1021 | * Returns true/false if the specified element name and optional attribute is |
| 1022 | * valid according to the schema. |
| 1023 | * |
| 1024 | * @method isValid |
| 1025 | * @param {String} name Name of element to check. |
| 1026 | * @param {String} attr Optional attribute name to check for. |
| 1027 | * @return {Boolean} True/false if the element and attribute is valid. |
| 1028 | */ |
| 1029 | self.isValid = function(name, attr) { |
| 1030 | var attrPatterns, i, rule = getElementRule(name); |
| 1031 | |
| 1032 | // Check if it's a valid element |
| 1033 | if (rule) { |
| 1034 | if (attr) { |
| 1035 | // Check if attribute name exists |
| 1036 | if (rule.attributes[attr]) { |
| 1037 | return true; |
| 1038 | } |
| 1039 | |
| 1040 | // Check if attribute matches a regexp pattern |
| 1041 | attrPatterns = rule.attributePatterns; |
| 1042 | if (attrPatterns) { |
| 1043 | i = attrPatterns.length; |
| 1044 | while (i--) { |
| 1045 | if (attrPatterns[i].pattern.test(name)) { |
| 1046 | return true; |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | } else { |
| 1051 | return true; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | // No match |
| 1056 | return false; |
| 1057 | }; |
| 1058 | |
| 1059 | /** |
| 1060 | * Returns true/false if the specified element is valid or not |
| 1061 | * according to the schema. |
| 1062 | * |
| 1063 | * @method getElementRule |
| 1064 | * @param {String} name Element name to check for. |
| 1065 | * @return {Object} Element object or undefined if the element isn't valid. |
| 1066 | */ |
| 1067 | self.getElementRule = getElementRule; |
| 1068 | |
| 1069 | /** |
| 1070 | * Returns an map object of all custom elements. |
| 1071 | * |
| 1072 | * @method getCustomElements |
| 1073 | * @return {Object} Name/value map object of all custom elements. |
| 1074 | */ |
| 1075 | self.getCustomElements = function() { |
| 1076 | return customElementsMap; |
| 1077 | }; |
| 1078 | |
| 1079 | /** |
| 1080 | * Parses a valid elements string and adds it to the schema. The valid elements format is for example "element[attr=default|otherattr]". |
| 1081 | * Existing rules will be replaced with the ones specified, so this extends the schema. |
| 1082 | * |
| 1083 | * @method addValidElements |
| 1084 | * @param {String} valid_elements String in the valid elements format to be parsed. |
| 1085 | */ |
| 1086 | self.addValidElements = addValidElements; |
| 1087 | |
| 1088 | /** |
| 1089 | * Parses a valid elements string and sets it to the schema. The valid elements format is for example "element[attr=default|otherattr]". |
| 1090 | * Existing rules will be replaced with the ones specified, so this extends the schema. |
| 1091 | * |
| 1092 | * @method setValidElements |
| 1093 | * @param {String} valid_elements String in the valid elements format to be parsed. |
| 1094 | */ |
| 1095 | self.setValidElements = setValidElements; |
| 1096 | |
| 1097 | /** |
| 1098 | * Adds custom non HTML elements to the schema. |
| 1099 | * |
| 1100 | * @method addCustomElements |
| 1101 | * @param {String} custom_elements Comma separated list of custom elements to add. |
| 1102 | */ |
| 1103 | self.addCustomElements = addCustomElements; |
| 1104 | |
| 1105 | /** |
| 1106 | * Parses a valid children string and adds them to the schema structure. The valid children format is for example: "element[child1|child2]". |
| 1107 | * |
| 1108 | * @method addValidChildren |
| 1109 | * @param {String} valid_children Valid children elements string to parse |
| 1110 | */ |
| 1111 | self.addValidChildren = addValidChildren; |
| 1112 | |
| 1113 | self.elements = elements; |
| 1114 | }; |
| 1115 | })(tinymce); |