#18822 closed defect (invalid)
parser does not always honor stopParser
Reported by: | Michael Schall | Owned by: | bill |
---|---|---|---|
Priority: | undecided | Milestone: | tbd |
Component: | Parser | Version: | 1.11.0 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Is there a way to stop dojo's parser from "looking inside" a dom structure? it seems that stopParser would be the tool to do that, but it does not work in all cases.
I have a plunkr created that shows my issue: http://plnkr.co/edit/axwk9pFi6Ytvg0RFJIPN?p=preview
Button 1 is correctly parsed and turned into a dijit button, but I need a way to have Button 2 ignored similar to the "broken on purpose" Button 3.
I can resolve the issue by modifying parser.js and adding another check that continues on any node with stopParser present...
-
parser.js
597 597 continue; 598 598 } 599 599 600 if (node.getAttribute("stopParser") == "true") { 601 node = node.nextSibling; 602 continue; 603 } 604 600 605 if(scripts && node.nodeName.toLowerCase() == "script"){ 601 606 // Save <script type="dojo/..."> for parent, then continue to next sibling 602 607 type = node.getAttribute("type");
Change History (3)
comment:1 Changed 5 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 5 years ago by
Thanks for the direction... Your suggestion works great.
It seems like both could work, why require a property when an attribute could be added to the node? Performance optimization? This way I have to traverse the dom tree before parsing for my exclusions rather than just having an attribute as part of the html.
For others finding this ticket, I solved it with the following code. The first block sets the stopParser
on the html containers I do not want parsed at load time before the second block runs to call parser.parse
to create the dijits.
require(["dojo/query", "dojo/domReady!"], function(query) { query(".templateNodes").forEach(function(node) { node.stopParser = true; }); }); window.ui = {}; require(["dojo/parser", "dojo/ready", "dijit/registry", "dojo/_base/array"], function(parser, ready, registry, array) { ready(100, function() { parser.parse().then(function() { array.forEach(registry.toArray(), function(instance) { ui[instance.id] = instance; }); }).otherwise(function(e) { alert("Error parsing document: " + e.message); }); }); });
comment:3 Changed 5 years ago by
There was no grand plan. For dijit's use case a property worked fine (probably marginally better than an attribute). Like you said, the parser could be enhanced to support both.
stopParser
is a property, not an attribute, so you need to callmyDiv.stopParser = true
.