toloframework
Version: 
Javascript/HTML/CSS compiler for Firefox OS or nodewebkit apps using modules in the nodejs style.
93 lines (86 loc) • 3.17 kB
JavaScript
/**********************************************************************
 require( 'require' )
 -----------------------------------------------------------------------
 @example
 var Path = require("node://path");  // Only in NodeJS/NW.js environment.
 var Button = require("tfw.button");
 **********************************************************************/
var require = function() {
    var modules = {};
    var definitions = {};
    var nodejs_require = typeof window.require === 'function' ? window.require : null;
    var f = function(id, body) {
        if( id.substr( 0, 7 ) == 'node://' ) {
            // Calling for a NodeJS module.
            if( !nodejs_require ) {
                throw Error( "[require] NodeJS is not available to load module `" + id + "`!" );
            }
            return nodejs_require( id.substr( 7 ) );
        }
        if( typeof body === 'function' ) {
            definitions[id] = body;
            return;
        }
        var mod;
        body = definitions[id];
        if (typeof body === 'undefined') {
            var err = new Error("Required module is missing: " + id);   
            console.error(err.stack);
            throw err;
        }
        mod = modules[id];
        if (typeof mod === 'undefined') {
            mod = {exports: {}};
            var exports = mod.exports;
            body(exports, mod);
            modules[id] = mod.exports;
            mod = mod.exports;
            //console.log("Module initialized: " + id);
        }
        return mod;
    };
    return f;
}();
function addListener(e,l) {
    if (window.addEventListener) {
        window.addEventListener(e,l,false);
    } else {
        window.attachEvent('on' + e, l);
    }
};
addListener(
    'DOMContentLoaded',
    function() {
        document.body.parentNode.$data = {};
        // Attach controllers.
        var W = require('x-widget');
        W('wdg.label30', 'wdg.label', {"value": "label"})
        W('wdg.label31', 'wdg.label', {"value": "false"})
        W('wdg.label32', 'wdg.label', {"value": "true"})
        W('lbl', 'wdg.label', {
            value: "label",
            wide: "false",
            visible: "true"})
        W('wdg.label33', 'wdg.label', {
            value: "label",
            wide: "false",
            visible: "true"})
        W('txtValue', 'wdg.text', {
            label: "value",
            value: "value",
            wide: "true"})
        W('chkWide', 'wdg.checkbox', {
            text: "wide",
            value: "false",
            wide: "true"})
        W('chkVisible', 'wdg.checkbox', {
            text: "visible",
            value: "true",
            wide: "true"})
        W.bind('wdg.label30',{"value":{"B":["txtValue","value"]}});
        W.bind('wdg.label31',{"value":{"B":["chkWide","value"]}});
        W.bind('wdg.label32',{"value":{"B":["chkVisible","value"]}});
        W.bind('lbl',{"value":{"B":["txtValue","value"]},"wide":{"B":["chkWide","value"]},"visible":{"B":["chkVisible","value"]}});
        W.bind('wdg.label33',{"value":{"B":["txtValue","value"]},"wide":{"B":["chkWide","value"]},"visible":{"B":["chkVisible","value"]}});
    }
);