JavaScript manipulation

Nao

  • Dadman with a boy
  • Posts: 16,078
JavaScript manipulation
« on May 6th, 2011, 05:13 PM »
Feature: JavaScript manipulation
Developer: Nao
Target: modders, themers, users, geeks
Status: 100% (complete.)
Comment:

Wedge makes life easier for JavaScript developers. First of all, you can put inline events into your markup (even better, you can use < > & without escaping them), they'll be delayed automatically to the end, and grouped together. That is, even if you call onclick="return something();" on several elements, that event will be stored only once in the HTML. This helps separate presentation from code.
You may also use jQuery inside your events. Also, Wedge allows you to add JS code simply by calling the add_js() function, and JS files with add_js_file(). Conversion of existing code in templates is made easier by the fact that commas are accepted within the add_js() calls, e.g. add_js('alert("', $txt['hello'], '");').
And because all code is postponed to the end of the page, you don't have to run anything in a DOMContentLoaded/DOMReady event, because the DOM is effectively built and ready to use by the time your code is run.
If you don't need jQuery or need your code to be executed before everything else, call add_js_inline(). The full DOM is still available at this point, but no jQuery, and no common Wedge functions. If you desperately want to run your code to be run in the middle of the DOM, don't bother with our functions and just use a script tag. We won't judge you.