Inspiration from Paul Irish's concept and idea, Markup-based unobtrusive comprehensive DOM-ready execution.
Dynamically execute JS code based on your body tag's id and class. All your page code can be included as one or many files. All you do is register each snippet with autoExec, and it handles the rest for you!
This project used to require jQuery, now it is library agnostic! If you
are using jQuery, it will automatically bind to the document.ready
event
for you. (unless you set AUTOEXEC.ready
to false
) Otherwise, just
use the AUTOEXEC.run()
method inside your own code.
Property | Type | Default | Comments |
---|---|---|---|
debug | boolean | false | Determines whether or not to output to the console. (there is already a wrapper to make sure this doesn't break IE) |
ready | boolean | true | If true, automatically binds to the jQuery ready event. (if jQuery is found) |
element | HTMLElement | document.body | The element to use when determining what to execute from the registry. (still uses id and class attributes) |
Registers a page-specific handler
Name | Type | Comments |
---|---|---|
id | string | The string id used to match the page to a #id |
fn | function | Code snippet to be executed. There are no arguments, and no context. (except window of course) |
Registers a handler for a page behavior
Name | Type | Comments |
---|---|---|
id | string | The string id used to match the page to a #id |
fn | function | Code snippet to be executed. There are no arguments, and no context. (except window of course) |
Low-level registration method (registerPage and registerBehavior are preferred)
Name | Type | Comments |
---|---|---|
type | string | "page" or "behavior" accepted |
id | string | The string id used to match the page/behavior to a #id or .class |
fn | function | Code snippet to be executed. There are no arguments, and no context. (except window of course) |
Registers an ignore rule. (only applies to behaviors) All ignore rules are built into an array, and all rules are tested against every behavior before they are executed.
If you choose to use a regular expression, please note that you'll need to
use ^
and $
in order to match the entire string. Otherwise, you could be
matching against substrings instead, producing undesired results.
Name | Type | Comments |
---|---|---|
rule | string|regexp | If a string, looks for an exact match. If a regexp, runs regexp.test. |
Runs through the element #id and .class, executing items from the registry as needed.
If you are using no library, or a library other than jQuery, use this method within your window.load, domready, etc. event.