Maybe the best way to do this, but currently I have a well-encapsulated JavaScript object that can have some custom options. I include an HTML snippet on the page (through Dreamweaver snippets), and on the page my JS file is loaded, which goes through the DOM and identifies any of these code snippets as specific functionality, and goes ahead and installs this functionality.
Thatβs all, until I want to add more than one object to the page and configure them. The important point here is that you can add as many objects to the page as you want with my current setting - because they are common at this point and do not have an id attribute.
Now I want to configure these objects, so I thought: "How about an external file containing configuration settings that these objects check and apply if a configuration object is found." This works well too, but the configuration data is now a bit "deleted". I guess it will annoy my other colleagues in the end, this is just one more thing to remember.
So, to my question, I am happy to insert these code blocks, which will still run the self-tooling of objects when the page loads. But what I would like to try also inserts a script block that contains configuration settings. I need a tool for this inserted code block, knowing that its parent is the context for the configuration.
Code example:
<div class="snippet"> <_contents of this 'snippet'_/> <script type="text/javascript"> new Snippet().init({ rootElement: REFERENCE_TO_THIS_SCRIPT_TAGS_PARENT_NODE, configOptionA: true, configOptionB: false }); </script> </div>
Note. <div class="snippet"> does not have an 'id' attribute because I want more than one of them to be deleted per page.
Other solutions are welcome if they adhere to my limitations!
unobtrusive-javascript dynamic configuration
danjah Jun 16 '10 at 22:28 2010-06-16 22:28
source share