Skip to content

drothman/autoexec.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

JavaScript Automatic Execution

Inspiration from Paul Irish's concept and idea, Markup-based unobtrusive comprehensive DOM-ready execution.

What?

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.

Configuration

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)

API Documentation

registerPage (id, fn)

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)

registerBehavior (id, fn)

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)

register (type, id, fn)

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)

registerIgnore (rule)

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.

run ()

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.

About

Automatically execute JS code depending upon document.body #id and .class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published