|
8 | 8 | * @author Peter Sylwester |
9 | 9 | * @copyright (c)2019 Peter Sylwester |
10 | 10 | * @license MIT |
11 | | - * @version 2.2.0, 2019/09/13 |
| 11 | + * @version 2.2.2, 2019/09/16 |
12 | 12 | * @requires "HTML5", "ECMA-262 Edition 5.1" |
13 | 13 | * |
14 | 14 | * |
|
53 | 53 | }(this, (function () { |
54 | 54 | "use strict"; |
55 | 55 |
|
56 | | - var element, source, version = "2.2.1"; |
| 56 | + var element, source, version = "2.2.2"; |
57 | 57 |
|
58 | 58 | /** |
59 | 59 | * Markers are the HTML node element attributes used to designate components of the templated markup. |
|
181 | 181 | */ |
182 | 182 | var showHeritage = false; |
183 | 183 |
|
| 184 | + /** |
| 185 | + * strictStandard determines Microdata compliance. |
| 186 | + * |
| 187 | + * @public via proxy |
| 188 | + * @type {Boolean} When true, requires Microdata attributes for template. |
| 189 | + */ |
| 190 | + var strictStandard = false; |
| 191 | + |
184 | 192 |
|
185 | 193 | /* PRIVATE UTILITIES */ |
186 | 194 |
|
|
202 | 210 | }; |
203 | 211 |
|
204 | 212 | var isTemplate = function (node) { |
205 | | - return !!node && !!node.hasAttribute |
206 | | - && node.hasAttribute(MARKER.hidden) |
207 | | - && (node.hasAttribute(MARKER.repeat) || node.hasAttribute(MARKER.property) || node.hasAttribute(MARKER.binder)); |
| 213 | + return !!node && !!node.hasAttribute |
| 214 | + && node.hasAttribute(MARKER.hidden) |
| 215 | + && (node.hasAttribute(MARKER.repeat) |
| 216 | + || node.hasAttribute(MARKER.property) |
| 217 | + || node.hasAttribute(MARKER.binder)); |
208 | 218 | }; |
209 | 219 |
|
210 | 220 | var isNestedTemplate = function (node) { |
211 | 221 | return !!node && !!node.hasAttribute |
212 | | - && node.hasAttribute(MARKER.hidden) |
213 | | - && node.hasAttribute(MARKER.repeat) |
214 | | - && node.hasAttribute(MARKER.source); |
| 222 | + && node.hasAttribute(MARKER.hidden) |
| 223 | + && node.hasAttribute(MARKER.repeat) |
| 224 | + && node.hasAttribute(MARKER.source); |
215 | 225 | }; |
216 | 226 |
|
217 | 227 | var denude = function (clone) { |
|
223 | 233 |
|
224 | 234 | var findTemplate = function (node) { |
225 | 235 | var candidate; |
226 | | - if (isTemplate(node)) { |
| 236 | + if (!strictStandard) { |
| 237 | + return node; |
| 238 | + } else if (isTemplate(node)) { |
227 | 239 | return node; |
228 | 240 | } else if (!!node && !!node.querySelector) { |
229 | 241 | candidate = node.querySelector("["+MARKER.hidden+"]"); |
|
346 | 358 | } |
347 | 359 | if (!!proxy) { |
348 | 360 | if (alternates.length > 1) { |
349 | | - proxy = alternates.filter(function (alt, j, arr) { |
| 361 | + proxy = alternates.filter(function (alt, k, arr) { |
350 | 362 | if (PATTERN.address.test(alt)) { |
351 | 363 | return alt; |
352 | 364 | } else if (alt in datum) { |
|
360 | 372 | } |
361 | 373 | })[0]; |
362 | 374 | } |
363 | | - if (!!combo) { |
| 375 | + if (!!combo && Array.isArray(proxy)) { |
364 | 376 | // this is a parenthetical, e/g combineString:(foo,bar) |
365 | 377 | value = []; |
366 | 378 | proxy.forEach(function (clause) { |
|
442 | 454 | } |
443 | 455 | })[0]; |
444 | 456 | } |
445 | | - if (!!combo) { |
| 457 | + if (!!combo && Array.isArray(proxy)) { |
446 | 458 | // this is a parenthetical, e/g combineString:(foo,bar) |
447 | 459 | value = []; |
448 | 460 | proxy.forEach(function (clause) { |
|
625 | 637 |
|
626 | 638 | /* PUBLIC API */ |
627 | 639 |
|
628 | | - init: function() { |
| 640 | + init: function(config) { |
| 641 | + if (arguments.length > 0 && Object(config) === config) { |
| 642 | + if ("strictStandard" in config) { |
| 643 | + strictStandard = !!config.strictStandard; |
| 644 | + } |
| 645 | + if ("showHeritage" in config) { |
| 646 | + strictStandard = !!config.showHeritage; |
| 647 | + } |
| 648 | + } |
629 | 649 | return this; |
630 | 650 | }, |
631 | 651 |
|
|
710 | 730 | return null; |
711 | 731 | } |
712 | 732 | }, |
713 | | - |
714 | | - /** |
715 | | - * @param boo {Boolean} When true the obj.hasOwnProperty() is not enforced. |
716 | | - * @returns {Boolean} The current setting. |
717 | | - */ |
| 733 | + |
718 | 734 | getSetShowHeritage: function (boo) { |
719 | | - |
| 735 | + /** |
| 736 | + * @param boo {Boolean} When true the obj.hasOwnProperty() is not enforced. |
| 737 | + * @returns {Boolean} The current setting. |
| 738 | + */ |
720 | 739 | if (arguments.length > 0) { |
721 | 740 | showHeritage = !!boo; |
722 | 741 | } |
723 | 742 |
|
724 | 743 | return showHeritage; |
725 | 744 | }, |
| 745 | + |
| 746 | + getSetStrictStandard: function (boo) { |
| 747 | + /** |
| 748 | + * @param boo {Boolean} When true Microdata attributes are always required. |
| 749 | + * @returns {Boolean} The current setting. |
| 750 | + */ |
| 751 | + if (arguments.length > 0) { |
| 752 | + strictStandard = !!boo; |
| 753 | + } |
| 754 | + |
| 755 | + return showHeritage; |
| 756 | + }, |
726 | 757 |
|
727 | 758 | getSetSource: function (obj) { |
728 | 759 |
|
|
0 commit comments