Script

Simple APIs to interact with the DOM and organize your logic

Functions

Wee brings a unique approach to referencing functions. Wherever you can provide a callback you can also use a ‘controllerName:methodName’ string. You can also always use a standard generic function or function reference.

Wee.fn.make('controllerName', {
    methodName: function() {
        // Method logic
    }
});

Wee.screen.map({
    size: 3,
    callback: 'controllerName:methodName'
});

Since the string method isn’t supported in JavaScript natively if you ever need to use the format outside of a supported context you can use the $exec method.

Wee.$exec('controllerName:methodName');

When needing to execute multiple methods you can use an array format. You can also mix method options in the array.

Wee.routes.map({
    $any: [
        'controllerName:methodName',
        'controllerName:secondMethodName',
        function() {
            // Callback logic
        }
    ]
});

Globals

  • Wee._body = document.body
  • Wee._doc = document
  • Wee._html = document.documentElement
  • Wee._legacy = true if IE8 or below
  • Wee._slice = [].slice
  • Wee._win = window

Selection

Wee accepts any browser-supported selection queries. Internally Wee parses the selection string to invoke the most efficient native selection method and returns an array of matching nodes.

Examples

$('#id');
$('.class');
$('#id .class');
$('.class1, .class2');
$('.parent > .child');

References

References are a distinctive approach to referencing DOM elements from your script. They bring added benefit of being cached when the page loads so they offer superior performance to standard selectors. Refs are more distinct than js- classes. Anywhere in Wee where you can pass a standard selector you can also pass a 'ref:name' string.

<div data-ref="element"></div>
$('ref:element');

If multiple refs are set with the same name they are pushed into an array an can be targeted with a single ref selection. You can also set multiple ref values separated with spaces.

<div data-ref="element"></div>
<div data-ref="element element2"></div>
$('ref:element').on('click', function() {
    // Method logic
});

$('ref:element2').on('click', function() {
    // Method logic
});

Note

If you add elements to the page dynamically you can call the Wee.$setRef() method.

Callbacks

Options for callback functions

Functions passed in as parameters to any Wee API method are evaluated in the same fashion. Usually, an options object will be provided for these Wee API methods that take a callback function that can have the following properties:

Variable Type Default Description Required
args array - Arguments to be passed into value if value is function
scope object - Scope assigned to value if value is a function