...
Code Block |
---|
// Example Widget function(ns/*, data, utils*/){ // Create Widget short name for local reference exWdgt = {}; // Use closures for private code var testFunc(); // Add all widget code to widget namespace. exWdgt.WidgetModel = can.Model({...}); exWdgt.WidgetControl = can.Control({...}); // Add an initialization function if the widget should be initialized externally exWdgt.initWidget = function(/*params*/){...}; // Make sure to add widget namespace to ns namespace ns.ExampleWidget = exWdgt; // Pass in external values that will be used by this code }( // ns should always be included, be first and be the specific namespace to which the resulting objects and functions from this file will be added. raft.widgets, // ns raft.data, // data raft.utils // utils )); $(document).ready(function()){ // Code to run when document is finished loading } |
Utilities
Helper Functions
Code Block |
---|
$.isDefined(obj) // Returns true if object is not undefined and not null
String.isString(obj) // Returns true if object is a string literal or String object
String.isEmpty(obj) // Returns true if object is a zero-length string
String.isNonEmpty(obj) // Returns true if object is a non-zero-length string
Number.isNumber(obj) // Returns true if object is a primitive number or a Number object
|
Dynamic Loader Functions
requireScript(): Loads the specified script, synchronously by default. If the file has already been loaded it will not be loaded again and a comment will be logged to that effect. The return value is a promise.
Code Block |
---|
raft.utils.requireScript(path).always(...).then(...);
|
requireCSS(): Adds a tag to the document.head element which loads the specified CSS file.
Code Block |
---|
raft.utils.requiresCSS(path);
|
Misc:
- Always include both params when calling can.Model()
...