Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#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

     
    597597                                        continue;
    598598                                }
    599599
     600                                if (node.getAttribute("stopParser") == "true") {
     601                                        node = node.nextSibling;
     602                                        continue;
     603                                }
     604
    600605                                if(scripts && node.nodeName.toLowerCase() == "script"){
    601606                                        // Save <script type="dojo/..."> for parent, then continue to next sibling
    602607                                        type = node.getAttribute("type");

Change History (3)

comment:1 Changed 3 years ago by bill

Resolution: invalid
Status: newclosed

stopParser is a property, not an attribute, so you need to call myDiv.stopParser = true.

comment:2 Changed 3 years ago by Michael Schall

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 3 years ago by bill

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.

Note: See TracTickets for help on using tickets.