toloframework
Version:
Javascript/HTML/CSS compiler for Firefox OS or nodewebkit apps using modules in the nodejs style.
81 lines (73 loc) • 16.3 kB
JavaScript
/**********************************************************************
require( 'require' )
-----------------------------------------------------------------------
@example
var Path = require("node://path"); // Only in NodeJS/NW.js environment.
var Button = require("tfw.button");
**********************************************************************/
window.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(f, mod, exports);
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.
APP = require('test');
setTimeout(function (){if(typeof APP.start==='function')APP.start()});
}
);
require("$",function(r,o,n){n.config={name:'"toloframework"',description:'"Javascript/HTML/CSS compiler for Firefox OS or nodewebkit apps using modules in the nodejs style."',author:'"Tolokoban"',version:'"0.42.13"',major:"0",minor:"42",revision:"13",date:"2018-01-31T20:40:30.000Z",consts:{}};var e=null;n.lang=function(r){return void 0===r&&(window.localStorage&&(r=window.localStorage.getItem("Language")),r||(r=window.navigator.language)||(r=window.navigator.browserLanguage)||(r="fr"),r=r.substr(0,2).toLowerCase()),e=r,window.localStorage&&window.localStorage.setItem("Language",r),r},n.intl=function(r,o){var e,t,a,i,g,l,s,u=r[n.lang()],c=o[0];for(s in r)break;if(!s)return c;if(!u&&!(u=r[s]))return c;if(e=u[c],e||(u=r[s],e=u[c]),!e)return c;if(o.length>1){for(t="",g=0,a=0;a<e.length;a++)i=e.charAt(a),"$"===i?(t+=e.substring(g,a),a++,l=e.charCodeAt(a)-48,l<0||l>=o.length?t+="$"+e.charAt(a):t+=o[l],g=a+1):"\\"===i&&(t+=e.substring(g,a),a++,t+=e.charAt(a),g=a+1);t+=e.substr(g),e=t}return e}});
//# sourceMappingURL=$.js.map
require("test",function(n,t,e){function i(n){return n.length}var r=function(){function t(){return i(e,arguments)}var e={en:{},fr:{}},i=n("$").intl;return t.all=e,t}(),o=n("tfw.binding.property-manager"),l=n("tfw.binding.list"),s=n("tfw.binding.link");e.start=function(){var n={};o(n).create("list",{init:new l([])});var t={};o(t).create("size",{init:0}),new s({debug:"<LINK>",A:{obj:n,name:"list"},B:{obj:t,name:"size",converter:i}}),console.log("AAA"),n.list.push(6),console.log("BBB"),n.list.push(3),console.log("CCC")},t.exports._=r});
//# sourceMappingURL=test.js.map
require("tfw.binding.link",function(e,n,t){function r(e,n,t,r){var o=this,a=[];return e[r].forEach(function(r,c){if(r.open){g(r.obj);e[t].forEach(function(t,f){if("string"==typeof t.name&&"string"==typeof r.name&&t.obj===r.obj&&t.name===r.name)return console.error("It is forbidden to bind a property on itself! ("+f+" -> "+c+")"),void console.info("[tfw.binding.link] args=",e);var s=g(t.obj),u=i.bind(o,t,r,n);s.on(t.name,u),a.push({pm:s,name:t.name,slot:u})})}}),a}function o(e,n){this.destroy=function(){e.forEach(function(e){e.pm.off(e.name,e.slot)}),n.forEach(function(e){e.pm.off(e.name,e.slot)})}}function i(e,n,t,r,o,i,a){if(Array.isArray(a)||(a=[]),this.debug&&console.log("Link "+this.name+": ",{src:e,dst:n,id:t,value:r,propertyName:o,container:i,wave:a}),s(t,a))return void(this.debug&&console.log("...has been BLOCKED by the wave! ",a));var c=this,f=g(e.obj),y=g(n.obj);if(r=d(r,e,n),r=l(r,n,f),r=m(r,e,n),u(r,e,n))return void(this.debug&&console.log("...has been FILTERED!"));r=h(r,e,n),r=b(r,e,n),"number"==typeof n.delay?(this.debug&&console.log("...has been DELAYED for "+n.delay+" ms!"),clearTimeout(n._id),n._id=setTimeout(function(){c.debug&&(console.log("Link "+c.name+" (after "+n.delay+" ms): ",{src:e,dst:n,id:t,value:r,propertyName:o,wave:a}),console.log("...try to change a value. ",{target:y,propertyName:n.name,value:r,wave:a})),y.change(n.name,r,a)},n.delay)):(this.debug&&console.log("...try to change a value. ",{target:y,propertyName:n.name,value:r,wave:a}),y.change(n.name,r,a))}function a(e){try{void 0===e.name&&(e.name=e.debug),"string"!=typeof e.name&&(e.name="Link#"+this.id),void 0===e&&f("Missing mandatory argument!"),void 0===e.A&&f("Missing `args.A`!"),Array.isArray(e.A)||(e.A=[e.A]),void 0===e.B&&f("Missing `args.B`!"),Array.isArray(e.B)||(e.B=[e.B]);var n;for(n=0;n<e.A.length;n++)c(e.A[n],n);for(n=0;n<e.B.length;n++)c(e.B[n],n);this.name=e.name,this.debug=e.debug}catch(n){console.error("checkArgs( "+e+" )"),f(n,"checkArgs( <args> )")}}function c(e,n){try{if(e.action){if("function"!=typeof e.action)throw"Attribute `["+n+"].action` must be a function!";if(void 0!==e.obj)throw"["+n+"].action cannot be defined in the same time of ["+n+"].obj! They are exclusive attributes.";if(void 0!==e.name)throw"["+n+"].action cannot be defined in the same time of ["+n+"].name! They are exclusive attributes.";var t={};g(t).create("<action>",{set:e.action}),e.obj=t,e.name="<action>"}else if(void 0===e.obj&&f("Missing `["+n+"].obj`!"),void 0===e.name&&(e.name="*"),!g.isLinkable(e.obj,e.name))throw"`"+e.name+"` is not a linkable attribute.\nValid linkable attributes are: "+g.getAllAttributesNames(e.obj).join(", ")+".";void 0===e.open&&(e.open=!0)}catch(t){console.error("checkpod(",e,", ",n,")"),f(t,"checkpod( <pod>, "+n+")")}}function f(e,n){throw n=void 0===n?"":"::"+n,e+"\n[tfw.binding.link"+n+"]"}function s(e,n){if(Array.isArray(n)){if(!(n.indexOf(e)<0))return!0;n.push(e)}return!1}function u(e,n,t){if("function"==typeof t.filter)try{if(!t.filter(e))return!0}catch(e){console.error(e),f("Error in filter of link "+g(n.obj)+"."+n.name+" -> "+g(t.obj)+"."+t.name+"!")}return!1}function l(e,n,t){return"string"==typeof n.switch?t.get(n.switch):Array.isArray(n.switch)?n.switch.map(function(e){return t.get(e)}):e}function m(e,n,t){if("function"==typeof t.converter)try{return t.converter(e)}catch(e){console.error(e),f("Error in converter of link "+g(n.obj)+"."+n.name+" -> "+g(t.obj)+"."+t.name+"!")}return e}function h(e,n,t){if(!t.format)return e;try{if(!Array.isArray(t.format))throw"Must be an array with two elements!";var r=t.format[0];if("function"!=typeof r)throw"First element of the array must be a function!";var o=t.format[1];if("string"!=typeof o)throw"Second element of the array must be a string!";return r(o,e)}catch(e){console.error(e),f("Error in format of link "+g(n.obj)+"."+n.name+" -> "+g(t.obj)+"."+t.name+"!\n"+e)}}function b(e,n,t){if(e&&"function"==typeof e.map&&"function"==typeof t.map)try{return e.map(t.map)}catch(e){console.error(e),f("Error in map of link "+g(n.obj)+"."+n.name+" -> "+g(t.obj)+"."+t.name+"!")}return e}function d(e,n,t){if(void 0===t.value)return e;if("function"==typeof t.value)try{return t.value(n.name)}catch(e){console.error(e),f("Error in value("+n.name+") of link "+g(n.obj)+"."+n.name+" -> "+g(t.obj)+"."+t.name+"!")}return t.value}var y=function(){function n(){return r(t,arguments)}var t={en:{},fr:{}},r=e("$").intl;return n.all=t,n}(),g=e("tfw.binding.property-manager"),v=0,p=function(e){try{var n=v++;a.call(this,e);var t=r.call(this,e,n,"A","B"),i=r.call(this,e,n,"B","A");o.call(this,t,i)}catch(n){console.error("new Link( "+e+" )"),f(n,"new Link( <args> ) "+(this.name||""))}};n.exports=p,n.exports._=y});
//# sourceMappingURL=tfw.binding.link.js.map
require("tfw.binding.property-manager",function(t,e,r){function n(t){Object.defineProperty(this,"id",{value:g++,writable:!1,configurable:!1,enumerable:!0}),this.name=this.id,this._props={},this._container=t}function i(t,e){var r=this,n={value:void 0,event:new d,filter:v(e.filter),converter:v(e.converter),delay:p(e.delay),action:null,alwaysFired:!!e.alwaysFired,manager:this,name:t,timeout:0};return n.get=o(n,e),n.set=a(n,e,r,t),this._props[t]=n,void 0!==e.init&&n.set(e.init),Object.defineProperty(this._container,t,{get:n.get.bind(n),set:r.change.bind(r,t),enumerable:!0,configurable:!1}),n}function o(t,e){return"function"==typeof e.get?function(r){var n=e.get(r);return u(t,n),n}:function(e){return t.value}}function a(t,e,r,n){return"function"==typeof e.cast?"function"==typeof e.set?function(n){f(t,t.get());var i=e.cast(n,r);u(t,t.value),e.set(i)}:function(n){f(t,t.get()),t.value=e.cast(n,r),u(t,t.value)}:"function"==typeof e.set?e.set:function(e){f(t,t.get()),t.value=e,u(t,t.value)}}function u(t,e){if(void 0!==e&&null!==e&&!0===e.isContentChangeAware){var r=e[m];Array.isArray(r)?-1===r.indexOf(t)&&r.push(t):r=[t],e[m]=r}}function f(t,e){if(void 0!==e&&null!==e&&!0===e.isContentChangeAware){var r=e[m];if(Array.isArray(r)){var n=r.indexOf(t);-1!==n&&r.splice(n,1)}}}function c(t,e){t.delay?(clearTimeout(t.timeout),t.timeout=setTimeout(e,t.delay)):e()}function s(t,e){throw e=void 0===e?"":"::"+e,Error("[tfw.binding.property-manager"+e+"] "+t)}function p(t){return"number"!=typeof t?0:isNaN(t)?0:Math.max(0,Math.floor(t))}function v(t){if("function"==typeof t)return t}function y(t,e){return t!==e}var l=function(){function e(){return n(r,arguments)}var r={en:{},fr:{}},n=t("$").intl;return e.all=r,e}(),d=t("tfw.event"),g=0,h="__tfw.property-manager__",m="__tfw.binding.property-manager__";n.prototype.set=function(t,e){this.create(t).set(e)},n.prototype.get=function(t){return this.create(t).get()},n.prototype.propertyId=function(t){return this.create(t).id},n.prototype.fire=function(t,e){var r=this.create(t);r.event.fire(r.get(),t,this._container,e)},n.prototype.change=function(t,e,r){void 0===r&&(r=[]);var n=this.create(t),i=n.converter;"function"==typeof i&&(e=i(e));var o=n.get();if(n.alwaysFired||y(e,o)){n.set(e);var a=this;c(n,function(){a.fire(t,r)})}},n.prototype.converter=function(t,e){var r=this.create(t);if("function"==typeof e)r.converter=e;else if(void 0!==e)throw Error("[tfw.binding.property-manager::converter] `converter` must be of type function or undefined!");return r.converter},n.prototype.delay=function(t,e){var r=this.create(t);if(e=parseFloat(e),isNaN(e))return r.delay;r.delay=e},n.prototype.on=function(t,e){this.create(t).event.add(e)},n.prototype.off=function(t,e){this.create(t).event.remove(e)},e.exports=function(t){void 0===t&&s("Argument `container` is mandatory!");var e=t[h];return e||(e=new n(t),t[h]=e),e},e.exports.isLinkable=function(t,e){return void 0!==t[h]&&("string"!=typeof e||void 0!==t[h]._props[e])},e.exports.getAllAttributesNames=function(t){return void 0===t[h]?[]:Object.keys(t[h]._props)},e.exports.getProperties=function(t){var e=t[m];return Array.isArray(e)?e:null},n.prototype.create=function(t,e){"string"!=typeof t&&s("propertyName must be a string!");var r=this._props[t];return r||(void 0===e&&(e={}),r=i.call(this,t,e)),r},n.prototype.createAction=function(t,e){return void 0===e&&(e={}),e.alwaysFired=!0,this.create(t,e)},e.exports._=l});
//# sourceMappingURL=tfw.binding.property-manager.js.map
require("tfw.event",function(t,r,i){var n=function(){function r(){return n(i,arguments)}var i={en:{},fr:{}},n=t("$").intl;return r.all=i,r}(),e=function(){this._list=[]};e.prototype.add=function(t){if("function"!=typeof t)return!1;this.remove(t);for(var r=0;r<this._list.length;r++)if(t===this._list)return!1;return this._list.push(t),!0},e.prototype.remove=function(t){if("function"!=typeof t)return!1;for(var r=0;r<this._list.length;r++){if(t===this._list)return this._list.splice(r,1),!0}return!1},e.prototype.clear=function(){this._list=[]},e.prototype.fire=function(){var t,r,i=Array.prototype.slice.call(arguments);for(t=0;t<this._list.length;t++)if(r=this._list[t],!1===r.apply(r,i))return!1;return!0},r.exports=e,r.exports._=n});
//# sourceMappingURL=tfw.event.js.map
require("tfw.binding.list",function(r,t,e){function i(r,t){if(r.length<2)return!0;for(var e,i=r[0],n=1;n<r.length;n++){if(e=r[n],t(i,e)>0)return!1;i=e}return!0}function n(r){return!!r&&"number"==typeof r[u]}function o(r,t,e){Object.defineProperty(r,t,{value:e,writable:!1,configurable:!1,enumerable:!0})}var s=function(){function t(){return i(e,arguments)}var e={en:{},fr:{}},i=r("$").intl;return t.all=e,t}(),a=r("tfw.binding.property-manager"),f=r("tfw.listeners"),u="__tfw.binding.list__",h=1,p=function(r){o(this,u,h++),o(this,"_listeners",new f),o(this,"_links",[]),o(this,"isContentChangeAware",!0),Array.isArray(r)?o(this,"_array",r):n(r)?(o(this,"_array",r._array),this.link(r)):o(this,"_array",[r])};t.exports=p,p.isList=n,p.prototype.fire=function(r,t,e){var i=this[u];Array.isArray(e)?-1===e.indexOf(i)&&e.push(i):e=[i],this._listeners.fire(r,t,e),this._links.forEach(function(i){e.indexOf(i[u])>-1||i.fire(r,t,e)});var n=a.getProperties(this);Array.isArray(n)&&n.forEach(function(r){r.manager.fire(r.name)})},p.prototype.addListener=function(r){this._listeners.add(r)},p.prototype.removeListener=function(r){this._listeners.remove(r)},p.prototype.link=function(r){if(!n(r))throw console.error("Argument: ",r),Error("[tfw.binding.list.link] Argument must be a tfw.binding.list object!");-1===this._links.indexOf(r)&&(this._links.push(r),r.link(this))},p.prototype.unlink=function(r){var t=this._links.indexOf(r);-1!==t&&(this._links.splice(t,1),r.unlink(this))},p.prototype.get=function(r){return this._array[r]},p.prototype.put=function(r,t){var e=this._array[r];return e!==t&&(this._array[r]=t,this.fire("put",{index:r,oldValue:e,newValue:t}),!0)},p.prototype.remove=function(r){var t=this._array.indexOf(r);return-1!==t&&(this._array.splice(t,1),this.fire("remove",{elem:r,index:t}),!0)},p.prototype.removeAt=function(r){var t=this._array[r];return this._array.splice(r,1),this.fire("remove",{elem:t,index:r}),!0},p.prototype.mapInPlace=function(r){var t=this;return this._Array.forEach(function(e,i){var n=r(e);t.put(i,n)}),this};var l=function(r,t){return r==t?0:r<t?-1:1};p.prototype.sort=function(r){return"function"!=typeof r&&(r=l),i(this._array,r)?this:(this._array.sort(r),this.fire("sort",r),this)},["push","pop","shift","unshift","splice","reverse"].forEach(function(r){p.prototype[r]=function(){var t=Array.prototype.slice.call(arguments),e=Array.prototype[r].apply(this._array,t);return this.fire(r,t),e}}),["slice","forEach","filter","map","reduce","indexOf","lastIndexOf"].forEach(function(r){p.prototype[r]=function(){var t=Array.prototype.slice.call(arguments);return Array.prototype[r].apply(this._array,t)}}),Object.defineProperty(p.prototype,"length",{get:function(){return this._array.length},set:function(r){this._array.length=r,this.fire("length",r)},configurable:!1,enumerable:!0}),t.exports._=s});
//# sourceMappingURL=tfw.binding.list.js.map
require("tfw.listeners",function(t,r,i){var n=function(){function r(){return n(i,arguments)}var i={en:{}},n=t("$").intl;return r.all=i,r}(),e=function(){this._list=[]};e.prototype.add=function(t,r){if("function"!=typeof t)return!1;this.remove(t);for(var i=0;i<this._list.length;i++)if(t===this._list[i])return!1;return this._list.push([t,r]),!0},e.prototype.remove=function(t,r){if("function"!=typeof t)return!1;for(var i=0;i<this._list.length;i++){var n=this._list[i];if(t===n[0]&&r===n[1])return this._list.splice(i,1),!0}return!1},e.prototype.clear=function(){this._list=[]},e.prototype.fire=function(){var t,r,i,n,e=Array.prototype.slice.call(arguments);for(t=0;t<this._list.length;t++)if(n=this._list[t],r=n[0],i=n[1],!1===r.apply(i,e))return!1;return!0},r.exports=e,r.exports._=n});
//# sourceMappingURL=tfw.listeners.js.map