fruffl

tri4m Bootloader

Jan 31st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 63.50 KB | None | 0 0
  1. (function(window, undefined)
  2. {
  3.     var plat4m, bootstrapList, compstrapList,
  4.     document    = window.document,
  5.     location    = window.location,
  6.     navigator   = window.navigator,
  7.         _tri4m  = window.tri4m,
  8.         tri4m   = function(selector, context) { return new tri4m.shell.init(selector, context, plat4m); },
  9.     ECMA_push   = Array.prototype.push,
  10.     ECMA_slice  = Array.prototype.slice,
  11.     ECMA_indexOf    = Array.prototype.indexOf,
  12.     ECMA_toString   = Object.prototype.toString,
  13.     ECMA_hasOwn = Object.prototype.hasOwnProperty,
  14.     ECMA_trim   = String.prototype.trim,
  15.     ECMA_classType  = {},
  16.     DOMContentLoaded = function()
  17.     {
  18.         if(document.addEventListener)
  19.         {
  20.             document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
  21.             tri4m.bootstrap();
  22.         }
  23.         else if(document.readyState === "complete")
  24.         {
  25.             document.detachEvent("onreadystatechange", DOMContentLoaded);
  26.             tri4m.bootstrap();
  27.         }
  28.     };
  29.    
  30.     var REGEX_V_MS_PREFIX   = /^-ms-/;
  31.     var REGEX_D_DASH_ALPHA  = /-([\da-z])/gi;
  32.     var REGEX_C_NOT_WHITE   = /\S/;
  33.     var REGEX_C_SPACE   = /\s+/;
  34.    
  35.     var JQUERY_SRC      = 'http://code.jquery.com/jquery-latest.min.js';
  36.     var JQUERY_INIT_TIME    = 500; // idle for jQuery === undefined
  37.  
  38. tri4m.shell = tri4m.prototype =
  39. {
  40.     constructor: tri4m,
  41.     init: function(selector, context, plat4m)
  42.     {
  43.         if(!selector)
  44.             return this;
  45.            
  46.         if(selector.nodeType)
  47.         {
  48.             this.context = this[0] = selector;
  49.             this.length = 1;
  50.             return this;
  51.         }
  52.        
  53.         if(typeof selector === "string")
  54.         {
  55.             tri4m.log('no jQuery - no selector support! (request: ' + selector + ')', 3);
  56.             return this;
  57.         }
  58.         else if(tri4m.isFunction(selector))
  59.         {
  60.             return plat4m.compstrap(selector);
  61.         }
  62.  
  63.         if(typeof selector.selector !== 'undefined')
  64.         {
  65.             this.selector = selector.selector;
  66.             this.context  = selector.context;
  67.         }
  68.  
  69.         return tri4m.makeArray(selector, this);
  70.     },
  71.     selector: "",
  72.     build: "1.8.3",
  73.     minor: "1.8.2",
  74.     major: "1.8.3",
  75.     length: 0,
  76.     size: function()
  77.     {
  78.         return this.length;
  79.     },
  80.     toArray: function()
  81.     {
  82.         return ECMA_slice.call(this);
  83.     },
  84.     get: function(num)
  85.     {
  86.         return num == null
  87.             ? this.toArray()
  88.             : (num < 0 ? this[this.length + num] : this[num]);
  89.     },
  90.     pushStack: function(elems, name, selector)
  91.     {
  92.         var ret = tri4m.merge(this.constructor(), elems);
  93.        
  94.         ret.prevObject = this;
  95.         ret.context    = this.context;
  96.  
  97.         if(name === "find")
  98.         {
  99.             ret.selector = this.selector + (this.selector ? " " : "") + selector;
  100.         }
  101.         else if(name)
  102.         {
  103.             ret.selector = this.selector + "." + name + "(" + selector + ")";
  104.         }
  105.        
  106.         return ret;
  107.     },
  108.     each: function(callback, args)
  109.     {
  110.         return tri4m.each(this, callback, args);
  111.     },
  112.     bootstrap: function(fn)
  113.     {
  114.         tri4m.bootstrap.promise().done(fn);
  115.         return this;
  116.     },
  117.     compstrap: function(fn)
  118.     {
  119.         tri4m.compstrap.promise().done(fn);
  120.         return this;
  121.     },
  122.     eq: function(i)
  123.     {
  124.         i = +i;
  125.         return i === -1
  126.             ? this.slice(i)
  127.             : this.slice(i, i + 1);
  128.     },
  129.     first: function()
  130.     {
  131.         return this.eq(0);
  132.     },
  133.     last: function()
  134.     {
  135.         return this.eq(-1);
  136.     },
  137.     slice: function()
  138.     {
  139.         return this.pushStack
  140.         (
  141.             ECMA_slice.apply(this, arguments),
  142.             "slice",
  143.             ECMA_slice.call(arguments).join(",")
  144.         );
  145.     },
  146.     map: function(callback)
  147.     {
  148.         return this.pushStack
  149.         (
  150.             tri4m.map
  151.             (
  152.                 this,
  153.                 function(elem, i)
  154.                 {
  155.                     return callback.call(elem, i, elem);
  156.                 }
  157.             )
  158.         );
  159.     },
  160.     end: function()
  161.     {
  162.         return this.prevObject || this.constructor(null);
  163.     },
  164.     push: ECMA_push,
  165.     sort: [].sort,
  166.     splice: [].splice
  167. };
  168.  
  169. tri4m.shell.init.prototype = tri4m.shell;
  170.  
  171.  
  172. tri4m.extend = tri4m.shell.extend = function()
  173. {
  174.     var opt, name, des, ref, refIsArray, clone, tar = arguments[0] || {}, i = 1, length = arguments.length, rec = false;
  175.  
  176.     if(typeof tar === "boolean")
  177.     {
  178.         rec = tar;
  179.         tar = arguments[1] || {};
  180.         i = 2;
  181.     }
  182.        
  183.     if(typeof tar !== "object"
  184.     && !tri4m.isFunction(tar))
  185.         tar = {};
  186.        
  187.     if(length === i)
  188.     {
  189.         tar = this;
  190.         --i;
  191.     }
  192.  
  193.     for(; i < length; i++)
  194.     {
  195.         if((opt = arguments[i]) == null)
  196.             continue;
  197.        
  198.         for(name in opt)
  199.         {
  200.             des = tar[name];
  201.             ref = opt[name];
  202.            
  203.             if(tar === ref)
  204.                 continue;
  205.  
  206.             if(rec
  207.             && ref
  208.             && (tri4m.isPlainObject(ref) || (refIsArray = tri4m.isArray(ref))))
  209.             {
  210.                 if(refIsArray)
  211.                 {
  212.                     refIsArray = false;
  213.                     clone = des && tri4m.isArray(des) ? des : [];
  214.  
  215.                 }
  216.                 else
  217.                 {
  218.                     clone = des && tri4m.isPlainObject(des) ? des : {};
  219.                 }
  220.  
  221.                 tar[name] = tri4m.extend(rec, clone, ref);
  222.                
  223.                 continue;
  224.             }
  225.            
  226.             if(ref === undefined)
  227.                 continue;
  228.                
  229.             tar[name] = ref;
  230.         }
  231.     }
  232.    
  233.     return tar;
  234. };
  235.  
  236. tri4m.extend(
  237. {
  238.     isBootstrapped: false,
  239.     isCompstrapped: false,
  240.     bootstrapWait: 1,
  241.     compstrapWait: 1,
  242.     holdBoot: function(hold)
  243.     {
  244.         if(hold)
  245.         {
  246.             tri4m.bootstrapWait++;
  247.         }
  248.         else
  249.         {
  250.             tri4m.bootstrap(true);
  251.         }
  252.     },
  253.     bootstrap: function(wait)
  254.     {
  255.         if(wait === true ? --tri4m.bootstrapWait : tri4m.isBootstrapped)
  256.             return;
  257.            
  258.         if(!document.body)
  259.             return setTimeout(tri4m.bootstrap, 1);
  260.  
  261.         tri4m.isBootstrapped = true;
  262.        
  263.         if(wait !== true
  264.         && --tri4m.bootstrapWait > 0)
  265.             return;
  266.        
  267.         bootstrapList.resolveWith(document, [tri4m]);
  268.  
  269.         tri4m.log('-- Bootstrap complete');
  270.     },
  271.     compstrap: function(wait)
  272.     {
  273.         if(wait === true ? --tri4m.compstrapWait : tri4m.isCompstrapped)
  274.             return;
  275.            
  276.         if(!document.body)
  277.             return setTimeout(tri4m.compstrap, 1);
  278.  
  279.         tri4m.isCompstrapped = true;
  280.        
  281.         if(wait !== true
  282.         && --tri4m.compstrapWait > 0)
  283.             return;
  284.        
  285.         compstrapList.resolveWith(document, [tri4m]);
  286.        
  287.         tri4m.log('-- Compstrap complete');
  288.     },
  289.     log : function(sText, sType, _bTimestamp)
  290.     {
  291.         var debugMode = true, useConsole = true,
  292.              c = null, d = ['log', 'info', 'warn', 'error'], sType = sType || 0, n = d[sType];
  293.                        
  294.         if(typeof l == 'undefined')
  295.             l = 0;
  296.    
  297.         if(false === debugMode)
  298.             return this;
  299.        
  300.        
  301.         if(null === c)
  302.             c = (typeof console !== 'undefined' && typeof console.log !== 'undefined');
  303.        
  304.  
  305.         if(typeof(_bTimestamp) !== 'undefined' && _bTimestamp)
  306.             sText = sText + ' | ' + new Date().getTime();
  307.  
  308.         sText = 'tri4m: ' + sText;
  309.         sType = d[sType];
  310.        
  311.         l++;
  312.        
  313.         if(c && useConsole)
  314.         {
  315.             if(typeof console[sType] === 'undefined')
  316.                 sType = d[sType];
  317.            
  318.             if(typeof console[sType] !== 'undefined')
  319.             {
  320.                 console[sType](sText);
  321.             }
  322.             else
  323.             {
  324.                 console.log(sText);
  325.             }
  326.         }
  327.        
  328.         return this;
  329.     },
  330.     isFunction: function(obj)
  331.     {
  332.         return tri4m.type(obj) === "function";
  333.     },
  334.     isArray: Array.isArray || function(obj)
  335.     {
  336.         return tri4m.type(obj) === "array";
  337.     },
  338.     isWindow: function(obj)
  339.     {
  340.         return obj != null && obj == obj.window;
  341.     },
  342.     isNumeric: function(obj)
  343.     {
  344.         return !isNaN(parseFloat(obj)) && isFinite(obj);
  345.     },
  346.     type: function(obj)
  347.     {
  348.         return obj == null ?
  349.             String(obj) :
  350.             ECMA_classType[ECMA_toString.call(obj)] || "object";
  351.     },
  352.     isPlainObject: function(obj)
  353.     {
  354.         if(!obj || tri4m.type(obj) !== "object" || obj.nodeType || tri4m.isWindow(obj))
  355.             return false;
  356.  
  357.         try {
  358.             if(obj.constructor
  359.             && !ECMA_hasOwn.call(obj, "constructor")
  360.             && !ECMA_hasOwn.call(obj.constructor.prototype, "isPrototypeOf"))
  361.                 return false;
  362.         }
  363.         catch(e)
  364.         {
  365.             return false;
  366.         }
  367.  
  368.         var key;
  369.         for(key in obj) {}
  370.  
  371.         return key === undefined || ECMA_hasOwn.call(obj, key);
  372.     },
  373.     isEmptyObject: function(obj)
  374.     {
  375.         var name;
  376.         for(name in obj)
  377.             return false;
  378.        
  379.         return true;
  380.     },
  381.     stringToFlag: function(options, type)
  382.     {
  383.         var object = {};
  384.        
  385.         var type = (type
  386.                 && type === true
  387.                 || type === false
  388.                 || type === null
  389.                 || type === 0
  390.                 || type === 1
  391.                 || type === 2)
  392.                     ? type
  393.                     : true;
  394.        
  395.         tri4m.each
  396.         (
  397.             options.split(REGEX_C_SPACE),
  398.             function(i, flag)
  399.             {
  400.                 i++;
  401.                 if(type === 0)
  402.                 {
  403.                     object[flag] = i - 1;
  404.                     return;
  405.                 }
  406.                
  407.                 if(type === 1)
  408.                 {
  409.                     object[flag] = i;
  410.                     return;
  411.                 }
  412.                
  413.                 if(type === 2)
  414.                 {
  415.                     object[flag] = Math.pow(2, i);
  416.                     return;
  417.                 }
  418.                
  419.                 object[flag] = type;
  420.             }
  421.         );
  422.        
  423.         return object;
  424.     },
  425.     objectToString : function(object, includeFunctions, fullPrintFunctions, tbl)
  426.     {
  427.         var incFunctions = includeFunctions || false, prntFunctions = fullPrintFunctions || false, tbl = tbl || false;
  428.        
  429.         var type = function(p, t, l)
  430.         {
  431.             var l = l || 0, s = tri4m.stringRepeat('    ', l), n = "\n" + s, d = n + '@prop ' + p + ': ', r;
  432.            
  433.             var space   = n;
  434.             var type    = '[property] ';
  435.             var name    = p;
  436.             var value   = t;
  437.             var scalar  = true;
  438.            
  439.             switch(true)
  440.             {
  441.                 case(typeof t === "undefined"):
  442.                     value = "undefined";
  443.                     break;
  444.                 case(t === null):
  445.                     value = "null";
  446.                     break;
  447.                 case(typeof t === "boolean"):
  448.                     value = (t === true) ? "true" : 'false';
  449.                     type = "[boolean]";
  450.                     break;
  451.                 case(t === NaN):
  452.                     value = "NaN" ;
  453.                     break;
  454.                 case(tri4m.isFunction(t)):
  455.                     internal = t.toString().match(/\[native code\]/g);
  456.                     type = "[function"+ ((internal !== null) ? "[internal: " + t.constructor.name + "]" : "") + "]";
  457.                     value = (true === prntFunctions) ? t.toString() : null;
  458.                     break;
  459.                 case(tri4m.isArray(t) && t.length === 0):
  460.                     type = "[array]";
  461.                     value = "[]";
  462.                     break;
  463.                 case(tri4m.isArray(t)):
  464.                     var b = parse(t, (l + 1)).join("");
  465.                     type = "[array]";
  466.                     value = n + " [" + b + n + "], ";
  467.                     scalar = false;
  468.                     break;
  469.                 case (typeof t === "object" && tri4m.isEmptyObject(t)):
  470.                     type = "[object]";
  471.                     value = "[]";
  472.                     break;
  473.                 case (typeof t === "object"):
  474.                     var b = parse(t, (l + 1)).join(s);
  475.                     type = "[object]";
  476.                     value = "[" + b + n +"], ";
  477.                     scalar = false;
  478.                     break;
  479.                 case (typeof t === "string"):
  480.                     type = "[string]";
  481.                     value = "'" + t.toString() + "', ";
  482.                     break;
  483.                 default:
  484.                     type = "[" + (typeof t) + "]";
  485.                     value = t.toString();
  486.                     break;
  487.             }
  488.            
  489.             return { space : space, type : type, name : name, value : value, scalar : scalar };
  490.         };
  491.        
  492.         var parse = function(o, l)
  493.         {
  494.             var a = [], b = [], l = l || 1, tl = 0, nl = 0;
  495.            
  496.             for(var p in o)
  497.             {
  498.                 if(typeof o.hasOwnProperty !== 'function')
  499.                     continue;
  500.                    
  501.                 if(!o.hasOwnProperty(p))
  502.                     continue;
  503.                
  504.                 var t = o[p];
  505.                
  506.                 if(false === incFunctions
  507.                 && tri4m.isFunction(t))
  508.                     continue;
  509.                
  510.                 a[a.length] = type(p, t, l);
  511.             }
  512.            
  513.             for(var i in a)
  514.             {
  515.                 var atl = a[i].type.length, anl = a[i].name.length;
  516.                
  517.                 if(atl > tl)
  518.                     tl = atl;
  519.                    
  520.                 if(anl > nl)
  521.                     nl = anl;
  522.             }
  523.            
  524.             for(var i in a)
  525.             {
  526.                 var t = a[i], n = t.name, p = t.type, v = t.value;
  527.                
  528.                 if(true === t.scalar && true === tbl)
  529.                 {
  530.                     n = tri4m.stringPadRight(t.name, " ", nl);
  531.                     p = tri4m.stringPadRight(t.type, " ", tl)
  532.                 }
  533.                
  534.                 v =  (null === v) ? "" : ": " + v;
  535.                
  536.                 b[b.length] = t.space + p + " " + n + v;
  537.             }
  538.            
  539.             return b;
  540.         };
  541.        
  542.         var r = parse(object).join("");
  543.         r = (r !== '') ? r + "\n" : 'null';
  544.            
  545.         return "{{{!:" + r + ":!EOF}}}\n";
  546.     },
  547.     rand: function(numericScope)
  548.     {
  549.         if(!numericScope)
  550.             var numericScope = Math.floor(Math.random());
  551.        
  552.         return Math.floor(Math.random() * numericScope);
  553.     },
  554.     sprintf: function(str)
  555.     {
  556.         for(var i = 1, len = arguments.length; i < len; ++i)
  557.             str = str.replace("{" + (i - 1) + "}", arguments[i]);
  558.        
  559.         return str;
  560.     },
  561.     sizeOf : function(subject)
  562.     {
  563.         if(tri4m.isArray(subject))
  564.             return subject.length;
  565.            
  566.         if(typeof subject === 'undefined') return;
  567.         if(typeof subject === null) return;
  568.        
  569.         var c = 0;
  570.         for(var i in subject) c++;
  571.         return c;
  572.     },
  573.     sleep : function(subject, time, callback)
  574.     {
  575.         var i = subject;
  576.        
  577.         i.queue(function()
  578.         {
  579.             setTimeout(function()
  580.             {
  581.                 i.dequeue();
  582.                 if(callback) callback();
  583.                 return subject;
  584.             }, time);
  585.         });
  586.        
  587.         return subject;
  588.     },
  589.     stringFindNumber: function(string)
  590.     {
  591.         string = string.replace(/[^0-9]/gi, '');
  592.         if(!string || isNaN(string)) string = 0;
  593.         return string;
  594.     },
  595.     stringPadLeft: function(string, chr, width)
  596.     {
  597.         var result = string, length = width - result.toString().length, i = length - 1;
  598.            
  599.         if(width > 0 && i >= 0)
  600.             do result = chr + result;
  601.             while(i--);
  602.        
  603.         return result;
  604.     },
  605.     stringPadRight: function(string, chr, width)
  606.     {
  607.         var result = string, length = width - result.toString().length, i = length - 1;
  608.            
  609.         if(width > 0 && i >= 0)
  610.             do result = result + chr;
  611.             while(i--);
  612.        
  613.         return result;
  614.     },
  615.     stringRepeat: function(string, width)
  616.     {
  617.         var result = '';
  618.         for(var i = 0; i < width; i++)
  619.             result += string;
  620.        
  621.         return result;
  622.     },
  623.     stringToWrite : function(str, depth, width, chr)
  624.     {
  625.         var width = width || 8, depth = depth || 0, chr = chr || ' ';
  626.         return tri4m.stringRepeat(chr, depth * width) + str + "\n";
  627.     },
  628.     trimChar: function(string, chr)
  629.     {
  630.         if(string.substr(0, 1) === chr)
  631.             string = string.substr(1, (string.length - 1));
  632.         if(string.substr((string.length - 1), string.length) === chr)
  633.             string = string.substr(0, (string.length - 1));
  634.         return string;
  635.     },
  636.     trimCharsRight: function(string, charlist)
  637.     {
  638.         charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([\[\]\(\)\.\?\/\*\{\}\+\tri4m\^\:])/g, '\\tri4m1');
  639.         return (string + '').replace(new RegExp('[' + charlist + ']+tri4m', 'g') , '');
  640.     },
  641.     zeroFill: function(number, width, includeDecimal)
  642.     {
  643.         if(typeof includeDecimal == 'undefined')
  644.             includeDecimal = false;
  645.        
  646.         var result = parseFloat(number), negative = false, length = width - result.toString().length, i = length - 1;
  647.        
  648.         if(result < 0)
  649.         {
  650.             result = Math.abs(result);
  651.             negative = true;
  652.             length++;
  653.             i = length - 1;
  654.         }
  655.        
  656.         if(width > 0)
  657.         {
  658.             if(result.toString().indexOf('.') > 0)
  659.             {
  660.                 if(!includeDecimal)
  661.                     length += result.toString().split('.')[1].length;
  662.                 length++;
  663.                 i = length - 1;
  664.             }
  665.            
  666.             if(i >= 0)
  667.                 do result = '0' + result;
  668.                 while (i--);
  669.         }
  670.        
  671.         return (true === negative)
  672.             ? '-' + result
  673.             : result;
  674.     },
  675.     rgb2hex : function(dec)
  676.     {
  677.         var n = parseInt(dec), c = 'ABCDEF', b = n / 16, r = n % 16; b = b-(r/16);
  678.         b = ((b >= 0) && (b <= 9)) ? b : c.charAt(b - 10);    
  679.         return ((r >= 0) && (r <= 9)) ? b + '' + r : b + '' + c.charAt(r - 10);
  680.     },
  681.     dec2hex : function(d)
  682.     {
  683.         return Number(d).toString(16).toUpperCase();
  684.     },
  685.     dec2hexCode : function(dec, length)
  686.     {
  687.         if(!length) var length = 8;
  688.         return '0x' + tri4m.stringPadLeft(tri4m.dec2hex(dec), '0', length);
  689.     },
  690.     error: function(msg)
  691.     {
  692.         throw new Error(msg);
  693.     },
  694.     noop: function() {},
  695.     globalEval: function(data) {
  696.         if(data
  697.         && ECMA_rnotwhite.test(data))
  698.             (window.execScript || function(data) { window["eval"].call(window, data); })(data);
  699.     },
  700.     camelCase: function(string) {
  701.         return string.replace(REGEX_V_MS_PREFIX, "ms-").replace(REGEX_D_DASH_ALPHA, fcamelCase);
  702.     },
  703.     nodeName: function(elem, name) {
  704.         return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  705.     },
  706.     each: function(obj, callback, args)
  707.     {
  708.         var name, i = 0, length = obj.length, isObj = length === undefined || tri4m.isFunction(obj);
  709.  
  710.         if(args)
  711.         {
  712.             if(isObj)
  713.             {
  714.                 for(name in obj)
  715.                     if(callback.apply(obj[name], args) === false)
  716.                         break;
  717.             }
  718.             else
  719.             {
  720.                 for(; i < length;)
  721.                     if(callback.apply(obj[i++], args) === false)
  722.                         break;
  723.             }
  724.         }
  725.         else
  726.         {
  727.             if(isObj)
  728.             {
  729.                 for(name in obj)
  730.                     if(callback.call(obj[name], name, obj[name]) === false)
  731.                         break;
  732.             }
  733.             else
  734.             {
  735.                 for(; i < length;)
  736.                     if(callback.call(obj[i], i, obj[i++]) === false)
  737.                         break;
  738.             }
  739.         }
  740.  
  741.         return obj;
  742.     },
  743.     trim: function(text)
  744.     {
  745.         if(ECMA_trim
  746.         && !ECMA_trim.call("\uFEFF\xA0"))
  747.         {
  748.             return (function(text)
  749.             {
  750.                 return text == null
  751.                     ? ""
  752.                     : ECMA_trim.call(text);
  753.             })(text);
  754.         }
  755.         else
  756.         {
  757.             return (function(text)
  758.             {
  759.                 return text == null
  760.                 ? ""
  761.                 : (text + "").replace(rtrim, "");
  762.             })(text);
  763.         }
  764.     },
  765.     makeArray: function(arr, results)
  766.     {
  767.         var type, ret = results || [];
  768.  
  769.         if(arr == null)
  770.             return ret;
  771.            
  772.         type = tri4m.type(arr);
  773.  
  774.         if(arr.length == null
  775.         || type === "string"
  776.         || type === "function"
  777.         || type === "regexp"
  778.         || tri4m.isWindow(arr))
  779.         {
  780.             ECMA_push.call(ret, arr);
  781.         }
  782.         else
  783.         {
  784.             tri4m.merge(ret, arr);
  785.         }
  786.  
  787.         return ret;
  788.     },
  789.     inArray: function(elem, arr, i) {
  790.         var len;
  791.  
  792.         if(arr)
  793.         {
  794.             if(ECMA_indexOf)
  795.                 return ECMA_indexOf.call(arr, elem, i);
  796.    
  797.             len = arr.length;
  798.             i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
  799.            
  800.             for(; i < len; i++)
  801.                 if(i in arr
  802.                 && arr[i] === elem)
  803.                     return i;
  804.         }
  805.  
  806.         return -1;
  807.     },
  808.     merge: function(first, second)
  809.     {
  810.         var l = second.length, i = first.length, j = 0;
  811.  
  812.         if(typeof l === "number")
  813.         {
  814.             for(; j < l; j++)
  815.                 first[i++] = second[j];
  816.         }
  817.         else
  818.         {
  819.             while(second[j] !== undefined)
  820.                 first[i++] = second[j++];
  821.         }
  822.  
  823.         first.length = i;
  824.  
  825.         return first;
  826.     },
  827.     grep: function(elems, callback, inv)
  828.     {
  829.         var retVal, ret = [], i = 0, length = elems.length;
  830.        
  831.         inv = !!inv;
  832.  
  833.         for(; i < length; i++)
  834.         {
  835.             retVal = !!callback(elems[i], i);
  836.             if(inv !== retVal)
  837.                 ret.push(elems[i]);
  838.         }
  839.  
  840.         return ret;
  841.     },
  842.     map: function(elems, callback, arg)
  843.     {
  844.         var value, key, ret = [], i = 0, length = elems.length,
  845.         isArray = elems instanceof tri4m
  846.                 || length !== undefined
  847.                     && typeof length === "number"
  848.                     && ((length > 0 && elems[0] && elems[length -1])
  849.                         || length === 0
  850.                         || tri4m.isArray(elems));
  851.  
  852.         if(isArray)
  853.         {
  854.             for(; i < length; i++)
  855.             {
  856.                 value = callback(elems[i], i, arg);
  857.  
  858.                 if(value != null)
  859.                     ret[ret.length] = value;
  860.             }
  861.         }
  862.         else
  863.         {
  864.             for(key in elems)
  865.             {
  866.                 value = callback(elems[key], key, arg);
  867.                
  868.                 if(value != null)
  869.                     ret[ret.length] = value;
  870.             }
  871.         }
  872.  
  873.         return ret.concat.apply([], ret);
  874.     },
  875.     guid: 1,
  876.     proxy: function(fn, context)
  877.     {
  878.         var tmp, args, proxy;
  879.  
  880.         if(typeof context === "string")
  881.         {
  882.             tmp = fn[context];
  883.             context = fn;
  884.             fn = tmp;
  885.         }
  886.  
  887.         if(!tri4m.isFunction(fn))
  888.             return undefined;
  889.  
  890.         args = ECMA_slice.call(arguments, 2);
  891.         proxy = function()
  892.         {
  893.             return fn.apply(context, args.concat(ECMA_slice.call(arguments)));
  894.         };
  895.        
  896.         proxy.guid = fn.guid = fn.guid || tri4m.guid++;
  897.  
  898.         return proxy;
  899.     },
  900.     access: function(elems, fn, key, value, chainable, emptyGet, pass)
  901.     {
  902.         var exec, bulk = key == null, i = 0, length = elems.length;
  903.        
  904.         if(key
  905.         && typeof key === "object")
  906.         {
  907.             for(i in key)
  908.                 tri4m.access(elems, fn, i, key[i], 1, emptyGet, value);
  909.            
  910.             chainable = 1;
  911.         }
  912.         else if(value !== undefined)
  913.         {
  914.             exec = pass === undefined && tri4m.isFunction(value);
  915.  
  916.             if(bulk)
  917.             {
  918.                 if(exec)
  919.                 {
  920.                     exec = fn;
  921.                    
  922.                     fn = function(elem, key, value)
  923.                     {
  924.                         return exec.call(tri4m(elem), value);
  925.                     };
  926.                 }
  927.                 else
  928.                 {
  929.                     fn.call(elems, value);
  930.                     fn = null;
  931.                 }
  932.             }
  933.  
  934.             if(fn)
  935.                 for(; i < length; i++)
  936.                     fn(elems[i], key, exec ? value.call(elems[i], i, fn(elems[i], key)) : value, pass);
  937.  
  938.             chainable = 1;
  939.         }
  940.  
  941.         return chainable
  942.             ? elems
  943.             : bulk
  944.                 ? fn.call(elems)
  945.                 : length
  946.                     ? fn(elems[0], key)
  947.                     : emptyGet;
  948.     },
  949.     now: function()
  950.     {
  951.         return (new Date()).getTime();
  952.     },
  953.     loadScript: function(src, callback)
  954.     {
  955.         var head = document.getElementsByTagName('head')[0],
  956.             script = document.createElement('script');
  957.             done = false;
  958.        
  959.         script.setAttribute('src', src);
  960.         script.setAttribute('type', 'text/javascript');
  961.         script.setAttribute('charset', 'utf-8');
  962.        
  963.         script.onload = script.onreadstatechange = function()
  964.         {
  965.             if(!done
  966.             && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete'))
  967.             {
  968.                 done = true;
  969.                 script.onload = script.onreadystatechange = null;
  970.                 if(callback)
  971.                 {
  972.                     callback();
  973.                 }
  974.             }
  975.         };
  976.        
  977.         head.insertBefore(script, head.firstChild);
  978.     },
  979.     toRegister :
  980.     {
  981.         expr :
  982.         {
  983.             ':' : {}
  984.         }
  985.     }
  986. });
  987.  
  988.        
  989. tri4m.bootstrap.promise = function(obj)
  990. {
  991.     if(!bootstrapList)
  992.     {
  993.         bootstrapList = tri4m.Deferred();
  994.        
  995.         if(document.readyState === "complete")
  996.         {
  997.             setTimeout(tri4m.bootstrap, 1);
  998.         }
  999.         else if(document.addEventListener)
  1000.         {
  1001.             document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
  1002.             window.addEventListener("load", tri4m.bootstrap, false);
  1003.         }
  1004.         else
  1005.         {
  1006.             document.attachEvent("onreadystatechange", DOMContentLoaded);
  1007.             window.attachEvent("onload", tri4m.bootstrap);
  1008.             var top = false;
  1009.  
  1010.             try
  1011.             {
  1012.                 top = window.frameElement == null && document.documentElement;
  1013.             }
  1014.             catch(e)
  1015.             {
  1016.             }
  1017.  
  1018.             if(top && top.doScroll)
  1019.             {
  1020.                 (function doScrollCheck()
  1021.                 {
  1022.                     if(!tri4m.isBootstrapped)
  1023.                     {
  1024.                         try
  1025.                         {
  1026.                             top.doScroll("left");
  1027.                         }
  1028.                         catch(e)
  1029.                         {
  1030.                             return setTimeout(doScrollCheck, 50);
  1031.                         }
  1032.  
  1033.                         tri4m.bootstrap();
  1034.                     }
  1035.                 })();
  1036.             }
  1037.         }
  1038.     }
  1039.    
  1040.     return bootstrapList.promise(obj);
  1041. };
  1042.  
  1043. tri4m.compstrap.promise = function(obj)
  1044. {
  1045.     if(!compstrapList)
  1046.         compstrapList = tri4m.Deferred();
  1047.    
  1048.     return compstrapList.promise(obj);
  1049. };
  1050.  
  1051. tri4m.each
  1052. (
  1053.     "Boolean Number String Function Array Date RegExp Object".split(" "),
  1054.     function(i, name)
  1055.     {
  1056.         ECMA_classType["[object " + name + "]"] = name.toLowerCase();
  1057.     }
  1058. );
  1059.  
  1060. plat4m = tri4m(document);
  1061.  
  1062.  
  1063. var optionsCache = {};
  1064. var createOptions = function(options)
  1065. {
  1066.     var object = optionsCache[options] = {};
  1067.     tri4m.each
  1068.     (
  1069.         options.split(REGEX_C_SPACE),
  1070.         function(_, flag)
  1071.         {
  1072.             object[flag] = true;
  1073.         }
  1074.     );
  1075.    
  1076.     return object;
  1077. };
  1078.  
  1079. tri4m.Callbacks = function(options)
  1080. {
  1081.     options = typeof options === "string"
  1082.         ? (optionsCache[options] || createOptions(options))
  1083.         : tri4m.extend({}, options);
  1084.  
  1085.     var memory,
  1086.         fired,
  1087.         firing,
  1088.         firingStart,
  1089.         firingLength,
  1090.         firingIndex,
  1091.         list        = [],
  1092.         stack       = !options.once && [],
  1093.         fire = function(data)
  1094.         {
  1095.             memory      = options.memory && data;
  1096.             fired       = true;
  1097.             firingIndex = firingStart || 0;
  1098.             firingStart = 0;
  1099.             firingLength    = list.length;
  1100.             firing      = true;
  1101.            
  1102.             for(; list && firingIndex < firingLength; firingIndex++)
  1103.             {
  1104.                 if(list[firingIndex].apply(data[0], data[1]) === false
  1105.                 && options.stopOnFalse)
  1106.                 {
  1107.                     memory = false;
  1108.                     break;
  1109.                 }
  1110.             }
  1111.            
  1112.             firing = false;
  1113.            
  1114.             if(list)
  1115.             {
  1116.                 if(stack)
  1117.                 {
  1118.                     if(stack.length)
  1119.                         fire(stack.shift());
  1120.                 }
  1121.                 else if(memory)
  1122.                 {
  1123.                     list = [];
  1124.                 }
  1125.                 else
  1126.                 {
  1127.                     self.disable();
  1128.                 }
  1129.             }
  1130.         },
  1131.         self = {
  1132.             add : function()
  1133.             {
  1134.                 if(list)
  1135.                 {
  1136.                     var start = list.length;
  1137.                    
  1138.                     (function add(args)
  1139.                     {
  1140.                         tri4m.each(args, function(_, arg)
  1141.                         {
  1142.                             var type = tri4m.type(arg);
  1143.                            
  1144.                             if(type === "function")
  1145.                             {
  1146.                                 if(!options.unique
  1147.                                 || !self.has(arg))
  1148.                                     list.push(arg);
  1149.                             }
  1150.                             else if(arg
  1151.                             && arg.length
  1152.                             && type !== "string")
  1153.                             {
  1154.                                 add(arg);
  1155.                             }
  1156.                         });
  1157.                     })(arguments);
  1158.                    
  1159.                     if(firing)
  1160.                     {
  1161.                         firingLength = list.length;
  1162.                     }
  1163.                     else if(memory)
  1164.                     {
  1165.                         firingStart = start;
  1166.                         fire(memory);
  1167.                     }
  1168.                 }
  1169.                
  1170.                 return this;
  1171.             },
  1172.             remove: function()
  1173.             {
  1174.                 if(list)
  1175.                 {
  1176.                     tri4m.each
  1177.                     (
  1178.                         arguments,
  1179.                        
  1180.                         function(_, arg)
  1181.                         {
  1182.                             var index;
  1183.                            
  1184.                             while((index = tri4m.inArray(arg, list, index)) > -1)
  1185.                             {
  1186.                                 list.splice(index, 1);
  1187.                                 if(firing)
  1188.                                 {
  1189.                                     if(index <= firingLength)
  1190.                                         firingLength--;
  1191.                                        
  1192.                                     if(index <= firingIndex)
  1193.                                         firingIndex--;
  1194.                                 }
  1195.                             }
  1196.                         }
  1197.                     );
  1198.                 }
  1199.                
  1200.                 return this;
  1201.             },
  1202.             has: function(fn)
  1203.             {
  1204.                 return tri4m.inArray(fn, list) > -1;
  1205.             },
  1206.             empty: function()
  1207.             {
  1208.                 list = [];
  1209.                 return this;
  1210.             },
  1211.             disable: function()
  1212.             {
  1213.                 list = stack = memory = undefined;
  1214.                 return this;
  1215.             },
  1216.             disabled: function()
  1217.             {
  1218.                 return !list;
  1219.             },
  1220.             lock: function()
  1221.             {
  1222.                 stack = undefined;
  1223.                 if(!memory)
  1224.                     self.disable();
  1225.                
  1226.                 return this;
  1227.             },
  1228.             locked: function()
  1229.             {
  1230.                 return !stack;
  1231.             },
  1232.             fireWith: function(context, args)
  1233.             {
  1234.                 args = args || [];
  1235.                 args = [context, args.slice ? args.slice() : args];
  1236.                
  1237.                 if(list
  1238.                 && (!fired || stack))
  1239.                 {
  1240.                     if(firing)
  1241.                     {
  1242.                         stack.push(args);
  1243.                     }
  1244.                     else
  1245.                     {
  1246.                         fire(args);
  1247.                     }
  1248.                 }
  1249.                
  1250.                 return this;
  1251.             },
  1252.             fire: function()
  1253.             {
  1254.                 self.fireWith(this, arguments);
  1255.                 return this;
  1256.             },
  1257.             fired: function()
  1258.             {
  1259.                 return !!fired;
  1260.             }
  1261.         };
  1262.  
  1263.     return self;
  1264. };
  1265.  
  1266. tri4m.extend(
  1267. {
  1268.     Deferred: function(func)
  1269.     {
  1270.         var     tuples =
  1271.             [   /* action, add listener, listener list, final state */
  1272.                 ["resolve", "done",     tri4m.Callbacks("once memory"), "resolved"],
  1273.                 ["reject",  "fail",     tri4m.Callbacks("once memory"), "rejected"],
  1274.                 ["notify",  "progress", tri4m.Callbacks("memory")]
  1275.             ],
  1276.             state = "pending",
  1277.             promise =
  1278.             {
  1279.                 state: function()
  1280.                 {
  1281.                     return state;
  1282.                 },
  1283.                 always: function()
  1284.                 {
  1285.                     deferred.done(arguments).fail(arguments);
  1286.                     return this;
  1287.                 },
  1288.                 then: function(/* fnDone, fnFail, fnProgress */)
  1289.                 {
  1290.                     var fns = arguments;
  1291.                     return tri4m.Deferred(function(newDefer)
  1292.                     {
  1293.                         tri4m.each(tuples, function(i, tuple)
  1294.                         {
  1295.                             var action = tuple[0],
  1296.                                 fn = fns[i];
  1297.                            
  1298.                             deferred[tuple[1]](tri4m.isFunction(fn)
  1299.                                 ? function()
  1300.                                 {
  1301.                                     var returned = fn.apply(this, arguments);
  1302.                                     if(returned && tri4m.isFunction(returned.promise))
  1303.                                     {
  1304.                                         returned.promise()
  1305.                                             .done(newDefer.resolve)
  1306.                                             .fail(newDefer.reject)
  1307.                                             .progress(newDefer.notify);
  1308.                                     }
  1309.                                     else
  1310.                                     {
  1311.                                         newDefer[action + "With"](this === deferred
  1312.                                             ? newDefer
  1313.                                             : this, [returned]);
  1314.                                     }
  1315.                                 }
  1316.                                 : newDefer[action]
  1317.                             );
  1318.                         });
  1319.                        
  1320.                         fns = null;
  1321.                        
  1322.                     }).promise();
  1323.                 },
  1324.                 promise: function(obj)
  1325.                 {
  1326.                     return obj != null
  1327.                         ? tri4m.extend(obj, promise)
  1328.                         : promise;
  1329.                 }
  1330.             },
  1331.             deferred = {};
  1332.  
  1333.         promise.pipe = promise.then;
  1334.        
  1335.         tri4m.each(tuples, function(i, tuple)
  1336.         {
  1337.             var list = tuple[2], stateString = tuple[3];
  1338.             promise[tuple[1]] = list.add;
  1339.            
  1340.             if(stateString)
  1341.             {
  1342.                 list.add
  1343.                 (
  1344.                     function()
  1345.                     {
  1346.                         state = stateString;
  1347.                     },
  1348.                     tuples[i ^ 1][2].disable,
  1349.                     tuples[2][2].lock
  1350.                 );
  1351.             }
  1352.  
  1353.             deferred[tuple[0]] = list.fire;
  1354.             deferred[tuple[0] + "With"] = list.fireWith;
  1355.         });
  1356.  
  1357.         promise.promise(deferred);
  1358.  
  1359.         if(func)
  1360.             func.call(deferred, deferred);
  1361.  
  1362.         return deferred;
  1363.     },
  1364.     when: function(subordinate /* , ..., subordinateN */)
  1365.     {
  1366.         var     i       = 0,
  1367.             resolveValues   = core_slice.call(arguments),
  1368.             length      = resolveValues.length,
  1369.             remaining   = length !== 1 || (subordinate && tri4m.isFunction(subordinate.promise)) ? length : 0,
  1370.             deferred    = remaining === 1 ? subordinate : tri4m.Deferred(),
  1371.             updateFunc = function(i, contexts, values)
  1372.             {
  1373.                 return function(value)
  1374.                 {
  1375.                     contexts[i] = this;
  1376.                     values[i]   = arguments.length > 1 ? core_slice.call(arguments) : value;
  1377.                    
  1378.                     if(values === progressValues)
  1379.                     {
  1380.                         deferred.notifyWith(contexts, values);
  1381.                     }
  1382.                     else if(!(--remaining))
  1383.                     {
  1384.                         deferred.resolveWith(contexts, values);
  1385.                     }
  1386.                 };
  1387.             },
  1388.             progressValues, progressContexts, resolveContexts;
  1389.  
  1390.         if(length > 1)
  1391.         {
  1392.             progressValues      = new Array(length);
  1393.             progressContexts    = new Array(length);
  1394.             resolveContexts     = new Array(length);
  1395.            
  1396.             for(; i < length; i++)
  1397.             {
  1398.                 if(resolveValues[i]
  1399.                 && tri4m.isFunction(resolveValues[i].promise))
  1400.                 {
  1401.                     resolveValues[i].promise()
  1402.                         .done(updateFunc(i, resolveContexts, resolveValues))
  1403.                         .fail(deferred.reject)
  1404.                         .progress(updateFunc(i, progressContexts, progressValues));
  1405.                 }
  1406.                 else
  1407.                 {
  1408.                     --remaining;
  1409.                 }
  1410.             }
  1411.         }
  1412.        
  1413.         if(!remaining)
  1414.             deferred.resolveWith(resolveContexts, resolveValues);
  1415.  
  1416.         return deferred.promise();
  1417.     }
  1418. });
  1419.  
  1420. tri4m.extend
  1421. (
  1422.     {
  1423.         lib :
  1424.         {
  1425.             exception :
  1426.             {
  1427.                 Throwable : function(name)
  1428.                 {
  1429.                     var name = name;
  1430.                    
  1431.                     var constructor = function(message)
  1432.                     {
  1433.                         //Error.apply(this, arguments);
  1434.                         if(this == window) return new arguments.callee(message, level);
  1435.                        
  1436.                         this.message    = message || '';
  1437.                         this.name   = name + '.Exception';
  1438.                     };
  1439.                    
  1440.                     constructor.name = name || 'tri4m.lib.exception.Throwable';
  1441.                     constructor.prototype.toString = Error.prototype.toString;
  1442.                    
  1443.                     return constructor;
  1444.                 }
  1445.             },
  1446.             loader :
  1447.             {
  1448.                 /**
  1449.                  * @param string src
  1450.                  * @param object lfo        the expected object
  1451.                  * @param function onload
  1452.                  * @param function callback
  1453.                  */
  1454.                 Javascript : function(options)
  1455.                 {
  1456.                     this.name = 'tri4m.lib.loader.Javascript';
  1457.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  1458.                    
  1459.                     var tried   = false;
  1460.                     var avail   = false;
  1461.                    
  1462.                     var __settings = tri4m.extend(
  1463.                     {
  1464.                         src     : null,
  1465.                         lfo     : null,
  1466.                         success     : null
  1467.                     }, options);
  1468.                    
  1469.                     this.load = function()
  1470.                     {
  1471.                         if(true === tried)
  1472.                             return this;
  1473.                            
  1474.                         tried = true;
  1475.                            
  1476.                         if(null === __settings.src)
  1477.                             throw new this.Exception('src is null.');
  1478.                        
  1479.                         /* NullReferenceError....
  1480.                         if(typeof __settings.lfo !== 'undefined' && __settings.lfo !== null)
  1481.                         {
  1482.                             tri4m.log('lfo is avail: ' + tri4m.objectToString(__settings.lfo));
  1483.                            
  1484.                             avail = true;
  1485.                             __settings.callback(this);
  1486.                             return this;
  1487.                         }
  1488.                        
  1489.                         */
  1490.                        
  1491.                         tri4m.log('Load script ' + __settings.src);
  1492.                        
  1493.                         try
  1494.                         {
  1495.                             var head = document.getElementsByTagName('head')[0],
  1496.                                 script = document.createElement('script');
  1497.                        
  1498.                             script.setAttribute('src', __settings.src);
  1499.                             script.setAttribute('type', 'text/javascript');
  1500.                             script.setAttribute('charset', 'utf-8');
  1501.                            
  1502.                             script.onload = script.onreadstatechange = function()
  1503.                             {
  1504.                                 if(!this.readyState
  1505.                                 || this.readyState == 'loaded'
  1506.                                 || this.readyState == 'complete')
  1507.                                 {
  1508.                                     script.onload = script.onreadystatechange = null;
  1509.                                    
  1510.                                     if(tri4m.isFunction(__settings.success))
  1511.                                         __settings.success(__settings);
  1512.                                        
  1513.                                 }
  1514.                             };
  1515.                        
  1516.                             head.insertBefore(script, head.firstChild);
  1517.                            
  1518.                         }
  1519.                         catch(e)
  1520.                         {
  1521.                             throw new this.Exception('Unable to append javasript ' + __settings.src)
  1522.                         }
  1523.                        
  1524.                        
  1525.                         return this;
  1526.                     }
  1527.                 },
  1528.                 /**
  1529.                  * @param string src
  1530.                  * @param object lfo        the expected object
  1531.                  * @param function onload
  1532.                  * @param function callback
  1533.                  */
  1534.                 Stylesheet : function(options)
  1535.                 {
  1536.                     this.name = 'tri4m.lib.loader.Stylesheet';
  1537.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  1538.                    
  1539.                     var tried   = false;
  1540.                     var avail   = false;
  1541.                    
  1542.                     var __settings = tri4m.extend(
  1543.                     {
  1544.                         src     : null,
  1545.                         lfo     : null,
  1546.                         success     : null
  1547.                     }, options);
  1548.                    
  1549.                     this.load = function()
  1550.                     {
  1551.                         if(true === tried)
  1552.                             return this;
  1553.                            
  1554.                         tried = true;
  1555.                            
  1556.                         if(null === __settings.src)
  1557.                             throw new this.Exception('src is null.');
  1558.                        
  1559.                         /* NullReferenceError....
  1560.                         if(typeof __settings.lfo !== 'undefined' && __settings.lfo !== null)
  1561.                         {
  1562.                             tri4m.log('lfo is avail: ' + tri4m.objectToString(__settings.lfo));
  1563.                            
  1564.                             avail = true;
  1565.                             __settings.callback(this);
  1566.                             return this;
  1567.                         }
  1568.                        
  1569.                         */
  1570.                        
  1571.                         tri4m.log('Load script ' + __settings.src);
  1572.                        
  1573.                         try
  1574.                         {
  1575.                             var head = document.getElementsByTagName('head')[0],
  1576.                                 script = document.createElement('link');
  1577.                        
  1578.                             script.setAttribute('src', __settings.src);
  1579.                             script.setAttribute('type', 'text/css');
  1580.                             script.setAttribute('media', 'all');
  1581.                            
  1582.                             script.onload = script.onreadstatechange = function()
  1583.                             {
  1584.                                 if(!this.readyState
  1585.                                 || this.readyState == 'loaded'
  1586.                                 || this.readyState == 'complete')
  1587.                                 {
  1588.                                     script.onload = script.onreadystatechange = null;
  1589.                                    
  1590.                                     if(tri4m.isFunction(__settings.success))
  1591.                                         __settings.success(__settings);
  1592.                                        
  1593.                                 }
  1594.                             };
  1595.                        
  1596.                             head.insertBefore(script, head.firstChild);
  1597.                            
  1598.                         }
  1599.                         catch(e)
  1600.                         {
  1601.                             throw new this.Exception('Unable to append stylesheet ' + __settings.src)
  1602.                         }
  1603.                        
  1604.                        
  1605.                         return this;
  1606.                     }
  1607.                 },
  1608.                 /**
  1609.                  * Queue-Loader based on Automation-Player
  1610.                  *
  1611.                  *
  1612.                  * var Loader = new tri4m.lib.loader.Queue('Javascript');
  1613.                  *
  1614.                  * var myComplete = function() { Loader.next(); alert('whohoo'); }
  1615.                  *
  1616.                  * Loader.push(new tri4m.lib.loader.Javascript({src : 'swfobject.js', success : Loader.next}))
  1617.                  * Loader.push(new tri4m.lib.loader.Javascript({src : 'whoohooo.js', success : myComplete }));
  1618.                  * Loader.push(new tri4m.lib.loader.Javascript({src : 'another.js', success : Loader.next }));
  1619.                  * Loader.start();
  1620.                  *
  1621.                  *
  1622.                  * jQuery is ready before we init our plugins:
  1623.                  * plat4m.bootstrap(function()
  1624.                  * {
  1625.                  *  var JS = tri4m.lib.loader.Javascript, JSLoader = tri4m.lib.loader.Queue,
  1626.                  *      Compstrap = new JSLoader,
  1627.                  *      Bootstrap = new JSLoader({ success: Compstrap.start });
  1628.                  *  
  1629.                  *  Bootstrap.push(new JS({ src : 'http://localfrost/wp-content/plugins/tri4m/jquery.js', success : Bootstrap.next }));
  1630.                  *  Compstrap.push(new JS({ src : 'http://localfrost/wp-content/plugins/tri4m/tri4mQtLoader/js/tri4m.QtLoader.js' }));
  1631.                  *  
  1632.                  *  setTimeout
  1633.                  *  (
  1634.                  *      function()
  1635.                  *      {
  1636.                  *          typeof jQuery === 'undefined'
  1637.                  *              ? Bootstrap.start()
  1638.                  *              : Compstrap.start();
  1639.                  *      } , 200
  1640.                  *  );
  1641.                  * });
  1642.                  *
  1643.                  * @note calling Loader.next() in File-callback is required
  1644.                  * @see ri4m.lib.automation.Player
  1645.                  */
  1646.                 Queue : function(options)
  1647.                 {
  1648.                     var __methods = new tri4m.lib.method.Hook,
  1649.                         __player = new tri4m.lib.automation.Player(options);
  1650.                    
  1651.                     /**
  1652.                      * @param tri4m.lib.loader.File File
  1653.                      */
  1654.                     this.push = function(File)
  1655.                     {
  1656.                         __methods.push(File.load);
  1657.                         return this;
  1658.                     }
  1659.                    
  1660.                     /**
  1661.                      * start
  1662.                      */
  1663.                     this.start = function()
  1664.                     {  
  1665.                         __player.setup(__methods).play();
  1666.                         return this;
  1667.                     }
  1668.                    
  1669.                     /**
  1670.                      * next
  1671.                      */
  1672.                     this.next = function()
  1673.                     {
  1674.                         __player.next();
  1675.                         return this;
  1676.                     }
  1677.                 }
  1678.             },
  1679.             property :
  1680.             {
  1681.                 /**
  1682.                  * value for value-queue
  1683.                  *
  1684.                  * overwrite is allowed or not
  1685.                  *
  1686.                  * @param value mixed
  1687.                  * @param protect bool true: can not overwrite existing value
  1688.                  */
  1689.                 Value : function(value, protect)
  1690.                 {
  1691.                     this.name = 'tri4m.lib.property.Value';
  1692.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  1693.                    
  1694.                     var __value = value || null;
  1695.                     var __protect = (protect === true) ? true : false;
  1696.                    
  1697.                     /**
  1698.                      * get value
  1699.                      * @return mixed
  1700.                      */
  1701.                     this.get = function()
  1702.                     {
  1703.                         return __value;
  1704.                     };
  1705.                    
  1706.                     /**
  1707.                      * set value
  1708.                      *
  1709.                      * this has no effect, if __protect is true
  1710.                      * @return tri4m.lib.property.Value
  1711.                      */
  1712.                     this.set = function(value)
  1713.                     {
  1714.                         if(__protect === true)
  1715.                             throw new this.Exception(value + ' is protected', 3);
  1716.                        
  1717.                         __value = value;
  1718.                         return this;
  1719.                     };
  1720.                    
  1721.                     /**
  1722.                      * get variable as object
  1723.                      *
  1724.                      * @return object
  1725.                      */
  1726.                     this.toObject = function()
  1727.                     {
  1728.                         return {
  1729.                             value   : __value,
  1730.                             protect : __protect
  1731.                         };
  1732.                     };
  1733.                 },
  1734.                 /**
  1735.                  * value registry
  1736.                  *
  1737.                  * store vars with values
  1738.                  *
  1739.                  * // new value-queue
  1740.                  * var foo = new tri4m.lib.property.Registry();
  1741.                  *
  1742.                  * // var "baz"
  1743.                  * foo.register('baz', 'baz: bar'); log.t100(foo.get('baz')); // baz: bar
  1744.                  * foo.set('baz', 'baz: bar -> foo'); log.t100(foo.get('baz')); // baz: foo
  1745.                  *
  1746.                  * // protected var "foo"
  1747.                  * foo.register('foo', 'foo: lol', true); log.t100(foo.get('foo')); // foo: lol
  1748.                  * foo.set('foo', 'foo: lol -> rofl'); log.t100(foo.get('foo')); // foo: lol
  1749.                  */
  1750.                 Registry : function()
  1751.                 {
  1752.                     this.name = 'tri4m.lib.property.Registry';
  1753.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  1754.                    
  1755.                     var __data = {};
  1756.                    
  1757.                     /**
  1758.                      * register value-instance
  1759.                      *
  1760.                      * @param name string instance-name
  1761.                      * @param value mixed
  1762.                      * @param protect bool true: can not overwrite existing value
  1763.                      * @see tri4m.lib.property.Value()
  1764.                      * @return tri4m.lib.property.Registry
  1765.                      */
  1766.                     this.register = function(name, value, protect)
  1767.                     {
  1768.                         if(this.isset(name) === true)
  1769.                             throw new this.Exception('Unable to register existing property ' +  name, 3);
  1770.                        
  1771.                         __data[name] = new tri4m.lib.property.Value(value, protect);
  1772.  
  1773.                         return this;
  1774.                     };
  1775.                    
  1776.                     /**
  1777.                      * unregister value-instance
  1778.                      *
  1779.                      * @param name string instance-name
  1780.                      * @return tri4m.lib.property.Registry
  1781.                      */
  1782.                     this.unregister = function(name)
  1783.                     {
  1784.                         if(this.isset(name) === false)
  1785.                             return this;
  1786.                        
  1787.                         delete _data[name]
  1788.  
  1789.                         return this;
  1790.                     };
  1791.  
  1792.                     /**
  1793.                      * isset instance
  1794.                      *
  1795.                      * @param name string instance-name
  1796.                      * @return bool
  1797.                      */
  1798.                     this.isset = function(name)
  1799.                     {
  1800.                         return (!__data[name]) ? false : true;
  1801.                     };
  1802.  
  1803.                     /**
  1804.                      * get value of instance
  1805.                      *
  1806.                      * @param name string instance-name
  1807.                      * @see tri4m.lib.property.Value.get()
  1808.                      * @return tri4m.lib.property.Value || null
  1809.                      */
  1810.                     this.get = function(name)
  1811.                     {
  1812.                         return ((this.isset(name) === true) ? __data[name].get() : null);
  1813.                     };
  1814.  
  1815.                     /**
  1816.                      * set value of instance
  1817.                      *
  1818.                      * you must register your variable at first!
  1819.                      * you can not use this registry as garbage dump!
  1820.                      *
  1821.                      * @param name string instance-name
  1822.                      * @param value mixed
  1823.                      * @see tri4m.lib.property.Value.set()
  1824.                      * @return tri4m.lib.property.Registry
  1825.                      */
  1826.                     this.set = function(name, value)
  1827.                     {
  1828.                         if(false === this.isset(name))
  1829.                             throw new this.Exception('Unable to update value for ' +  name + ': not found', 3);
  1830.                        
  1831.                         try{ __data[name].set(value); }
  1832.                         catch(e){ throw new this.Exception('Unable update value for ' +  name, 3); }
  1833.                        
  1834.                         return this;
  1835.                     };
  1836.  
  1837.                     /**
  1838.                      * get queue as object
  1839.                      *
  1840.                      * @return tri4m.lib.property.Registry  as propertyName:propertyValue object
  1841.                      */
  1842.                     this.toObject = function()
  1843.                     {
  1844.                         var q = {};
  1845.                         for(i in __data)
  1846.                             q[i] = __data[i].toObject();
  1847.                         return q;
  1848.                     };
  1849.  
  1850.                     /**
  1851.                      * get queue as value object
  1852.                      *
  1853.                      * @return tri4m.lib.property.Registry.__data as propertyValue object
  1854.                      */
  1855.                     this.toValueObject = function()
  1856.                     {
  1857.                         var q = {};
  1858.                         for(i in __data)
  1859.                             q[i] = __data[i].toObject().value;
  1860.                         return q;
  1861.                     };
  1862.  
  1863.                     /**
  1864.                      * get queue as property object
  1865.                      *
  1866.                      * @return tri4m.lib.property.Registry.__data as propertyName object
  1867.                      */
  1868.                     this.toPropertyObject = function()
  1869.                     {
  1870.                         var q = {};
  1871.                         var k = 0;
  1872.                         for(i in __data)
  1873.                         {
  1874.                             q[k] = i;
  1875.                             k++;
  1876.                         }
  1877.                         return q;
  1878.                     };
  1879.                 }
  1880.             },
  1881.             method :
  1882.             {
  1883.                 /**
  1884.                  * method FIFO
  1885.                  *
  1886.                  * @param runonce bool true: terminate queue on exec
  1887.                  *
  1888.                  * // some stuff
  1889.                  * var test11 = function(){log.t100('test1.1')};
  1890.                  * var test12 = function(){log.t100('test1.2')};
  1891.                  *
  1892.                  * // default queue
  1893.                  * var bar = new tri4m.lib.method.Hook;
  1894.                  * bar.push(test11).push(test12)
  1895.                  *  .execute()  // test1.1 test1.2
  1896.                  *  .execute(); // test1.1 test1.2
  1897.                  *
  1898.                  * // run-once queue
  1899.                  * var baz = new tri4m.lib.method.Hook(true);
  1900.                  * baz.push(test11).push(test12)
  1901.                  *  .execute()  // test1.1 test1.2
  1902.                  *  .execute(); // nothing
  1903.                  */
  1904.                 Hook : function(runonce)
  1905.                 {
  1906.                     this.name = 'tri4m.lib.method.Hook';
  1907.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  1908.                    
  1909.                     var __hook = [];
  1910.                     var __runonce = (runonce !== true) ? false : true;
  1911.  
  1912.                     /**
  1913.                      * add function to queue
  1914.                      *
  1915.                      * @param fn function
  1916.                      * @return tri4m.lib.method.Hook
  1917.                      */
  1918.                     this.push = function(fn)
  1919.                     {
  1920.                         __hook.push(fn);
  1921.                         return this;
  1922.                     };
  1923.  
  1924.                     /**
  1925.                      * execute queue
  1926.                      *
  1927.                      * @return tri4m.lib.method.Hook
  1928.                      */
  1929.                     this.execute = function()
  1930.                     {
  1931.                         if(__hook.length === 0)
  1932.                             return this;
  1933.  
  1934.                         if(__runonce === false)
  1935.                             for(i in __hook) __hook[i]();
  1936.                         else
  1937.                             while(__hook.length > 0) (__hook.shift())();
  1938.  
  1939.                         return this;
  1940.                     };
  1941.  
  1942.                     /**
  1943.                      * terminate queue
  1944.                      *
  1945.                      * @return tri4m.lib.method.Hook
  1946.                      */
  1947.                     this.reset = function()
  1948.                     {
  1949.                         __hook = [];
  1950.                         return this;
  1951.                     };
  1952.  
  1953.                     /**
  1954.                      * get queue as array
  1955.                      *
  1956.                      * @return tri4m.lib.method.Hook.__hook... imho as copy
  1957.                      */
  1958.                     this.toArray = function()
  1959.                     {
  1960.                         var a = __hook;
  1961.                         return a;
  1962.                     };
  1963.                 },
  1964.                 /**
  1965.                  * method hook registry
  1966.                  *
  1967.                  * // some stuff
  1968.                  * var test11 = function(){log.t100('test1.1')};
  1969.                  * var test12 = function(){log.t100('test1.2')};
  1970.                  * var test21 = function(){log.t100('test2.1')};
  1971.                  * var test22 = function(){log.t100('test2.2')};
  1972.                  *
  1973.                  * // create registry queue
  1974.                  * var foo = new tri4m.lib.method.Registry();
  1975.                  *
  1976.                  * // default queue
  1977.                  * foo.register('test1').push('test1', test11).push('test1', test12)
  1978.                  *  .execute('test1')   // test1.1 test1.2
  1979.                  *  .execute('test1');  // test1.1 test1.2
  1980.                  *
  1981.                  * // run-once queue
  1982.                  * foo.register('test2', true).push('test2', test11).push('test2', test12)
  1983.                  *  .execute('test2')   // test2.1 test2.2
  1984.                  *  .execute('test2');  // nothing
  1985.                  *
  1986.                  *
  1987.                  * // shorthand:
  1988.                  * // default queue
  1989.                  * foo.get('test3').push(test21).push(test22)
  1990.                  *  .execute()  // test2.1 test2.2
  1991.                  *  .execute(); // test2.1 test2.2
  1992.                  *
  1993.                  * // run-once queue
  1994.                  * foo.get('test4', true).push(test21).push(test22)
  1995.                  *  .execute()  // test2.1 test2.2
  1996.                  *  .execute(); // nothing
  1997.                  */
  1998.                 Registry : function()
  1999.                 {
  2000.                     this.name = 'tri4m.lib.method.Registry';
  2001.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  2002.                    
  2003.                     var __hook = new tri4m.lib.property.Registry();
  2004.  
  2005.                     /**
  2006.                      * register queue instance
  2007.                      *
  2008.                      * @param name string instance-name
  2009.                      * @param runonce bool
  2010.                      * @see tri4m.lib.method.Hook()
  2011.                      * @see tri4m.lib.property.Registry.register()
  2012.                      * @return tri4m.lib.method.Registry
  2013.                      */
  2014.                     this.register = function(name, runonce)
  2015.                     {
  2016.                         __hook.register(name, new tri4m.lib.method.Hook(runonce), true);
  2017.                         return this;
  2018.                     };
  2019.  
  2020.                     /**
  2021.                      * isset instance
  2022.                      *
  2023.                      * @param name string instance-name
  2024.                      * @see tri4m.lib.property.Registry.isset()
  2025.                      * @return bool tri4m.lib.property.Registry.isset()
  2026.                      */
  2027.                     this.isset = function(name)
  2028.                     {
  2029.                         return __hook.isset(name);
  2030.                     };
  2031.  
  2032.                     /**
  2033.                      * get/create queue instance
  2034.                      *
  2035.                      * @param name string instance-name
  2036.                      * @param runonce bool
  2037.                      * @see tri4m.lib.method.Hook
  2038.                      * @return tri4m.lib.method.Hook
  2039.                      */
  2040.                     this.get = function(name, runonce)
  2041.                     {
  2042.                         //log.t100(__hook.get(name).className());
  2043.                         if(this.isset(name) === false)
  2044.                             this.register(name, runonce);
  2045.                         return __hook.get(name);
  2046.                     };
  2047.  
  2048.                     /**
  2049.                      * execute queue of instance
  2050.                      *
  2051.                      * @param name string instance-name
  2052.                      * @see tri4m.lib.method.Hook.execute()
  2053.                      * @return tri4m.lib.method.Registry
  2054.                      */
  2055.                     this.execute = function(name)
  2056.                     {
  2057.                         if(this.isset(name) === true)
  2058.                             this.get(name).execute();
  2059.                         return this;
  2060.                     };
  2061.  
  2062.                     /**
  2063.                      * terminate queue
  2064.                      *
  2065.                      * @see tri4m.lib.method.Hook.reset()
  2066.                      * @return tri4m.lib.method.Registry
  2067.                      */
  2068.                     this.reset = function(name)
  2069.                     {
  2070.                         if(this.isset(name) === true)
  2071.                             this.get(name).reset();
  2072.                         return this;
  2073.                     };
  2074.  
  2075.                     /**
  2076.                      * add function to queue of instance
  2077.                      *
  2078.                      * @param name string instance-name
  2079.                      * @param fn function
  2080.                      * @see tri4m.lib.method.Hook.push()
  2081.                      * @return tri4m.lib.method.Registry
  2082.                      */
  2083.                     this.push = function(name, fn)
  2084.                     {
  2085.                         if(this.isset(name) === true)
  2086.                             this.get(name).push(fn);
  2087.                         return this;
  2088.                     };
  2089.  
  2090.                     /**
  2091.                      * get queue as object
  2092.                      *
  2093.                      * @return tri4m.lib.property.Registry.__hook as copy
  2094.                      */
  2095.                     this.toObject = function()
  2096.                     {
  2097.                         return __hook.toObject();
  2098.                     };
  2099.  
  2100.                     /**
  2101.                      * get queue as object
  2102.                      *
  2103.                      * @return tri4m.lib.property.Registry.__hook as copy
  2104.                      */
  2105.                     this.getHook = function()
  2106.                     {
  2107.                         var q = __hook;
  2108.                         return q;
  2109.                     };
  2110.                 }
  2111.             },
  2112.             automation :
  2113.             {
  2114.                 /**
  2115.                  * animation playlist player
  2116.                  *
  2117.                  * split methods from tri4m.lib.method.Hook
  2118.                  * to partials
  2119.                  *
  2120.                  * @example tri4m.lib.loader.Queue
  2121.                  *
  2122.                  *
  2123.                  * step 1:
  2124.                  *  create your methods:
  2125.                  *
  2126.                  * ...
  2127.                  * Env :
  2128.                  * {
  2129.                  *  Playlists : null,
  2130.                  *  Animation :
  2131.                  *  {
  2132.                  *      test10 : function(){
  2133.                  *          log.t100('test10');
  2134.                  *          tri4m('ul.list li').css({height: 5});
  2135.                  *          tri4m.Env.Playlists.next('intro');
  2136.                  *      },
  2137.                  *      test11 : function(){
  2138.                  *          log.t100('test11');
  2139.                  *          tri4m('ul.list li').animate({height: 140}, 2200, function()
  2140.                  *          {
  2141.                  *              log.t100('test11 anim callback');
  2142.                  *              tri4m.Env.Playlists.next('intro');
  2143.                  *          });
  2144.                  *      },
  2145.                  *      test12 : function(){
  2146.                  *          log.t100('test12');
  2147.                  *          tri4m('ul.list li').css({width: 10});
  2148.                  *          tri4m.Env.Playlists.next('intro');
  2149.                  *      },
  2150.                  *      test13 : function(){
  2151.                  *          log.t100('test13');
  2152.                  *          tri4m('ul.list li').animate({width: 140}, 2200);
  2153.                  *          tri4m.Env.Playlists.next('intro');
  2154.                  *      }
  2155.                  *  }
  2156.                  * },
  2157.                  * ...
  2158.                  *
  2159.                  *
  2160.                  * step 2:
  2161.                  *  init the animation registry and register
  2162.                  *  the methods into sections, e.g. "intro" or "button-hover"
  2163.                  *
  2164.                  * ...
  2165.                  * test : function()
  2166.                  * {
  2167.                  *  tri4m.Env.Playlists =
  2168.                  *      new tri4m.lib.automation.Registry();
  2169.                  *
  2170.                  *  tri4m.Env.Playlists.register('intro')
  2171.                  *      .push(tri4m.Env.Animation.test10)
  2172.                  *      .push(tri4m.Env.Animation.test11)
  2173.                  *      .push(tri4m.Env.Animation.test12)
  2174.                  *      .push(tri4m.Env.Animation.test13)
  2175.                  *  ;
  2176.                  *  tri4m.Env.Playlists.play('intro');
  2177.                  * },
  2178.                  * ...
  2179.                  *
  2180.                  *
  2181.                  * @todo    lock, pause, start, stop not really implemented
  2182.                  */
  2183.                 Player : function(options)
  2184.                 {
  2185.                     this.name = 'tri4m.lib.automation.Player';
  2186.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  2187.                    
  2188.                    
  2189.                     var __settings = tri4m.extend(
  2190.                     {
  2191.                         onPlayStart : tri4m.noop,
  2192.                         onPlayNext  : tri4m.noop,
  2193.                         onPlayPause : tri4m.noop,
  2194.                         onPlayStop  : tri4m.noop,
  2195.                         success : tri4m.noop
  2196.                     }, options);
  2197.                    
  2198.                     /**
  2199.                      * method registry queue
  2200.                      */
  2201.                     var __registry = null;
  2202.  
  2203.                     /**
  2204.                      * __isPlaying bool status quo
  2205.                      */
  2206.                     var __isPlaying = false;
  2207.  
  2208.                     /**
  2209.                      * translated registry as func-callback-object
  2210.                      */
  2211.                     var __playlist = [];
  2212.  
  2213.                     /**
  2214.                      * working-copy of __playlist
  2215.                      */
  2216.                     var __playqueue = [];
  2217.  
  2218.                     /**
  2219.                      * counter
  2220.                      */
  2221.                     var __playedTimes = 0;
  2222.  
  2223.                     /**
  2224.                      * install method queue
  2225.                      *
  2226.                      * @param registry tri4m.lib.method.Hook
  2227.                      * @return tri4m.lib.automation.Player
  2228.                      */
  2229.                     this.setup = function(registry)
  2230.                     {
  2231.                         if(__registry !== null)
  2232.                             return this;
  2233.  
  2234.                         __registry = registry;
  2235.  
  2236.                         var methods = __registry.toArray();
  2237.  
  2238.                         for(var i = 0; i < methods.length; i++)
  2239.                         {
  2240.                             var fn = methods[i];
  2241.  
  2242.                             if(typeof fn !== 'function')
  2243.                                 continue;
  2244.  
  2245.                             var cb = function(){};
  2246.                            
  2247.                             if((next = methods[i+1]))
  2248.                             {
  2249.                                 if(typeof next !== 'function')
  2250.                                     continue;
  2251.  
  2252.                                 cb = next;
  2253.                             }
  2254.  
  2255.                             var item = {
  2256.                                 method: fn,
  2257.                                 callback :
  2258.                                 {
  2259.                                     method : cb
  2260.                                 }
  2261.                             };
  2262.                            
  2263.                             __playlist.push(item);
  2264.                         }
  2265.                        
  2266.                         return this;
  2267.                     };
  2268.  
  2269.                     /**
  2270.                      * init playing
  2271.                      *
  2272.                      * @return tri4m.lib.automation.Player
  2273.                      */
  2274.                     this.play = function()
  2275.                     {
  2276.                         if(true === this.isPlaying())
  2277.                             return false;
  2278.  
  2279.                         if(__playqueue.length === 0)
  2280.                         {
  2281.                             __playedTimes++;
  2282.                             __settings.onPlayStart();
  2283.                         }
  2284.                            
  2285.                        
  2286.                         __isPlaying = true;
  2287.                         __playqueue = __playlist;
  2288.                        
  2289.  
  2290.                         this.next();
  2291.                         return this;
  2292.                     };
  2293.  
  2294.                     /**
  2295.                      * play next method
  2296.                      *
  2297.                      * test11 : function(){
  2298.                      *  log.t100('test11');
  2299.                      *  tri4m('ul.list li').animate({height: 140}, 2200, function()
  2300.                      *  {
  2301.                      *      log.t100('test11 anim callback');
  2302.                      *      tri4m.Env.Playlists.next('intro');
  2303.                      *  });
  2304.                      * },
  2305.                      *
  2306.                      * @return tri4m.lib.automation.Player
  2307.                      */
  2308.                     this.next = function()
  2309.                     {
  2310.                         if(null === __playqueue)
  2311.                             return this;
  2312.  
  2313.                         var next = null;
  2314.  
  2315.                         if(__playqueue.length > 0)
  2316.                             next = __playqueue.shift();
  2317.  
  2318.                         if(!next)
  2319.                         {
  2320.                             this.stop();
  2321.                             __settings.success();
  2322.                             return this;
  2323.                         }
  2324.  
  2325.                         __settings.onPlayNext();
  2326.                         next.method();
  2327.  
  2328.                         return this;
  2329.                     };
  2330.  
  2331.                     /**
  2332.                      * pause
  2333.                      *
  2334.                      * @return tri4m.lib.automation.Player
  2335.                      */
  2336.                     this.pause = function()
  2337.                     {
  2338.                         __isPlaying = false;
  2339.                         __settings.onPlayPause();
  2340.                         return this;
  2341.                     };
  2342.  
  2343.                     /**
  2344.                      * stop/abort playing and delete working copy
  2345.                      *
  2346.                      * @return tri4m.lib.automation.Player
  2347.                      */
  2348.                     this.stop = function()
  2349.                     {
  2350.                         __playqueue = [];
  2351.                         __isPlaying = false;
  2352.                         __settings.onPlayStop();
  2353.                         return this;
  2354.                     };
  2355.  
  2356.                     /**
  2357.                      * is playing status
  2358.                      *
  2359.                      * @return bool status quo
  2360.                      */
  2361.                     this.isPlaying = function()
  2362.                     {
  2363.                         return __isPlaying;
  2364.                     };
  2365.                 },
  2366.                 /**
  2367.                  * playlist class
  2368.                  *
  2369.                  * holds a methodhook (playlist) and the player
  2370.                  *
  2371.                  */
  2372.                 Playlist : function()
  2373.                 {
  2374.                     this.name = 'tri4m.lib.automation.Playlist';
  2375.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  2376.                    
  2377.                     /**
  2378.                      * method queue/playlist
  2379.                      */
  2380.                     var __playlist  = new tri4m.lib.method.Hook();
  2381.  
  2382.                     /**
  2383.                      * player
  2384.                      */
  2385.                     var __player    = new tri4m.lib.automation.Player();
  2386.  
  2387.                     /**
  2388.                      * push method to __playlist
  2389.                      *
  2390.                      * @param function
  2391.                      * @return tri4m.lib.automation.Playlist
  2392.                      */
  2393.                     this.push = function(fn)
  2394.                     {
  2395.                         __playlist.push(fn);
  2396.                         return this;
  2397.                     };
  2398.  
  2399.                     /**
  2400.                      * initialize player and start playing
  2401.                      *
  2402.                      * @return tri4m.lib.automation.Playlist
  2403.                      */
  2404.                     this.play = function()
  2405.                     {
  2406.                         __player.setup(__playlist).play();
  2407.                         return this;
  2408.                     };
  2409.  
  2410.                     /**
  2411.                      * play next frame
  2412.                      *
  2413.                      * this is the callback-caller
  2414.                      *
  2415.                      * test11 : function(){
  2416.                      *  log.t100('test11');
  2417.                      *  tri4m('ul.list li').animate({height: 140}, 2200, function()
  2418.                      *  {
  2419.                      *      log.t100('test11 anim callback');
  2420.                      *      tri4m.Env.Playlists.next('intro');
  2421.                      *  });
  2422.                      * },
  2423.                      *
  2424.                      *
  2425.                      * @return tri4m.lib.automation.Playlist
  2426.                      */
  2427.                     this.next = function()
  2428.                     {
  2429.                         __player.next();
  2430.                         return this;
  2431.                     };
  2432.                 },
  2433.                 /**
  2434.                  * playlist/player registry
  2435.                  *
  2436.                  * store animation-queues by event-name
  2437.                  *
  2438.                  */
  2439.                 Registry : function()
  2440.                 {
  2441.                     this.name = 'tri4m.lib.automation.Registry';
  2442.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  2443.                    
  2444.                     var __queue = new tri4m.lib.property.Registry();
  2445.  
  2446.                     /**
  2447.                      * craete a new playlist-instance
  2448.                      *
  2449.                      * @param string instance name
  2450.                      * @return tri4m.lib.automation.Playlist
  2451.                      */
  2452.                     this.register = function(name)
  2453.                     {
  2454.                         __queue.register(name, new tri4m.lib.automation.Playlist(), true);
  2455.                         return __queue.get(name);
  2456.                     };
  2457.  
  2458.                     /**
  2459.                      * get playlist-instance
  2460.                      *
  2461.                      * @param string instance name
  2462.                      * @return tri4m.lib.automation.Playlist
  2463.                      */
  2464.                     this.get = function(name)
  2465.                     {
  2466.                         return __queue.get(name);
  2467.                     };
  2468.                    
  2469.                     /**
  2470.                      * play a playlist-instance
  2471.                      *
  2472.                      * @param string instance name
  2473.                      * @return tri4m.lib.automation.Registry
  2474.                      */
  2475.                     this.play = function(name)
  2476.                     {
  2477.                         __queue.get(name).play();
  2478.                         return this;
  2479.                     };
  2480.                    
  2481.                     /**
  2482.                      * play next callback
  2483.                      *
  2484.                      * @param string instance name
  2485.                      * @return tri4m.lib.automation.Registry
  2486.                      */
  2487.                     this.next = function(name)
  2488.                     {
  2489.                         __queue.get(name).next();
  2490.                         return this;
  2491.                     };
  2492.                 }
  2493.             }
  2494.         }
  2495.     }
  2496. );
  2497.  
  2498. tri4m.extend
  2499. (
  2500.     {
  2501.         append :
  2502.         {
  2503.             /**
  2504.              * head:
  2505.              *
  2506.              * (function(tri4m, undefined)
  2507.              * {
  2508.              *  tri4m(function()
  2509.              *  {
  2510.              *      tri4m.append([
  2511.              *          'plugin.js',
  2512.              *          'another.js'
  2513.              *      ],
  2514.              *      {
  2515.              *          success : function()
  2516.              *          {
  2517.              *              tri4m.log('-- init my plugin');
  2518.              *          }
  2519.              *      });
  2520.              *  });
  2521.              * })(tri4m);
  2522.              */
  2523.             Javascript : function(src, options, hold)
  2524.             {
  2525.                 var __settings = tri4m.extend
  2526.                 (
  2527.                     {
  2528.                         success : tri4m.noop
  2529.                     },
  2530.                     options
  2531.                 );
  2532.                
  2533.                 if(typeof stack === 'undefined')
  2534.                      stack = new tri4m.lib.loader.Queue({ success : __settings.success });
  2535.                
  2536.                 if(typeof src !== 'string')
  2537.                 {
  2538.                     var i = 0, l = src.length;
  2539.                    
  2540.                     for(var name in src)
  2541.                     {
  2542.                         i++;
  2543.                         tri4m.append.Javascript(src[name], {}, i !== l)
  2544.                     }
  2545.                        
  2546.                     return tri4m.com;
  2547.                 }
  2548.                
  2549.                 if(typeof cache === 'undefined')
  2550.                     cache = [];
  2551.                
  2552.                 for(var i in cache)
  2553.                     if(src === cache[i])
  2554.                         return tri4m.com;
  2555.                
  2556.                 cache.push(src);   
  2557.                
  2558.                 tri4m.log('append script ' + src);
  2559.                
  2560.                      
  2561.                 var cur = stack;
  2562.                
  2563.                 stack.push(new tri4m.lib.loader.Javascript(
  2564.                 {
  2565.                     //src : src + '?' + Math.random(0, 100000000),
  2566.                     src : src,
  2567.                     success : cur.next
  2568.                    
  2569.                 }));
  2570.                
  2571.                 if(!hold || hold !== true)
  2572.                     stack.start();
  2573.                    
  2574.                 return tri4m;
  2575.             },
  2576.             Stylesheet : function(src, options, hold)
  2577.             {
  2578.                 var __settings = tri4m.extend
  2579.                 (
  2580.                     {
  2581.                         success : tri4m.noop
  2582.                     },
  2583.                     options
  2584.                 );
  2585.                
  2586.                 if(typeof stack === 'undefined')
  2587.                      stack = new tri4m.lib.loader.Queue({ success : __settings.success });
  2588.                
  2589.                 if(typeof src !== 'string')
  2590.                 {
  2591.                     var i = 0, l = src.length;
  2592.                    
  2593.                     for(var name in src)
  2594.                     {
  2595.                         i++;
  2596.                         tri4m.append.Stylesheet(src[name], {}, i !== l)
  2597.                     }
  2598.                        
  2599.                     return tri4m.com;
  2600.                 }
  2601.                
  2602.                 if(typeof cache === 'undefined')
  2603.                     cache = [];
  2604.                
  2605.                 for(var i in cache)
  2606.                     if(src === cache[i])
  2607.                         return tri4m.com;
  2608.                
  2609.                 cache.push(src);   
  2610.                
  2611.                 tri4m.log('append script ' + src);
  2612.                
  2613.                      
  2614.                 var cur = stack;
  2615.                
  2616.                 stack.push(new tri4m.lib.loader.Stylesheet(
  2617.                 {
  2618.                     //src : src + '?' + Math.random(0, 100000000),
  2619.                     src : src,
  2620.                     success : cur.next
  2621.                 }));
  2622.                
  2623.                 if(!hold || hold !== true)
  2624.                     stack.start();
  2625.                    
  2626.                 return tri4m;
  2627.             }
  2628.         }
  2629.     }
  2630. );
  2631.  
  2632. tri4m.com = function(name, base, prototype)
  2633. {
  2634.     var     fullName,
  2635.         existingConstructor,
  2636.         constructor,
  2637.         basePrototype,
  2638.         namespace = name.split(".")[0];
  2639.  
  2640.     name        = name.split(".")[1];
  2641.     fullName    = 'tri4m-' + namespace + "-" + name;
  2642.    
  2643.  
  2644.     if(!prototype)
  2645.     {
  2646.         prototype   = base;
  2647.         base        = tri4m.__Com;
  2648.     }
  2649.    
  2650.     tri4m.toRegister.expr[':'][fullName] = function(elem)
  2651.     {
  2652.         return !!jQuery.data(elem, fullName);
  2653.     };
  2654.  
  2655.     tri4m[namespace]    = tri4m[namespace] || {};
  2656.     existingConstructor = tri4m[namespace][name];
  2657.    
  2658.     constructor = tri4m[namespace][name] = function(options, element)
  2659.     {
  2660.         if(!this._create__Com)
  2661.             return new constructor(options, element);
  2662.  
  2663.         if(arguments.length)
  2664.             this._create__Com(options, element);
  2665.     };
  2666.    
  2667.     tri4m.extend(constructor, existingConstructor,
  2668.     {
  2669.         version: prototype.version,
  2670.         _proto: tri4m.extend({}, prototype),
  2671.         _childConstructors: []
  2672.     });
  2673.  
  2674.     basePrototype       = new base();
  2675.     basePrototype.options   = tri4m.com.extend({}, basePrototype.options);
  2676.    
  2677.     tri4m.each(prototype, function(prop, value)
  2678.     {
  2679.         if(tri4m.isFunction(value)) {
  2680.             prototype[prop] = (function()
  2681.             {
  2682.                 var     _super = function()
  2683.                     {
  2684.                         return base.prototype[prop].apply(this, arguments);
  2685.                     },
  2686.                     _superApply = function(args)
  2687.                     {
  2688.                         return base.prototype[prop].apply(this, args);
  2689.                     };
  2690.                    
  2691.                 return function()
  2692.                 {
  2693.                     var __super     = this._super,
  2694.                         __superApply    = this._superApply,
  2695.                         returnValue;
  2696.  
  2697.                     this._super     = _super;
  2698.                     this._superApply    = _superApply;
  2699.                     returnValue         = value.apply(this, arguments);
  2700.                     this._super     = __super;
  2701.                     this._superApply    = __superApply;
  2702.  
  2703.                     return returnValue;
  2704.                 };
  2705.             })();
  2706.         }
  2707.     });
  2708.    
  2709.     constructor.prototype = tri4m.com.extend
  2710.     (
  2711.         basePrototype,
  2712.         {
  2713.             comEventPrefix: name
  2714.         },
  2715.         prototype,
  2716.         {
  2717.             constructor:    constructor,
  2718.             namespace:  namespace,
  2719.             comName:    name,
  2720.             comBaseClass:   fullName,
  2721.             comFullName:    fullName
  2722.         }
  2723.     );
  2724.  
  2725.     if(existingConstructor)
  2726.     {
  2727.         tri4m.each(existingConstructor._childConstructors, function(i, child)
  2728.         {
  2729.             var childPrototype = child.prototype;
  2730.             tri4m.com(childPrototype.namespace + "." + childPrototype.comName, constructor, child._proto);
  2731.         });
  2732.        
  2733.         delete existingConstructor._childConstructors;
  2734.     }
  2735.     else
  2736.     {
  2737.         base._childConstructors.push(constructor);
  2738.     }
  2739.  
  2740.     tri4m.com.bridge(name, constructor);
  2741. };
  2742.  
  2743. tri4m.com.extend = function(target)
  2744. {
  2745.     var     input       = ECMA_slice.call(arguments, 1),
  2746.         inputIndex  = 0,
  2747.         inputLength = input.length,
  2748.         key,
  2749.         value;
  2750.        
  2751.     for(  ; inputIndex < inputLength; inputIndex++)
  2752.     {
  2753.         for(key in input[inputIndex])
  2754.         {
  2755.             value = input[inputIndex][key];
  2756.            
  2757.             if(input[inputIndex].hasOwnProperty(key) && value !== undefined)
  2758.             {
  2759.                 target[key] = tri4m.isPlainObject(value)
  2760.                     ? tri4m.com.extend({}, target[key], value)
  2761.                     : value;
  2762.             }
  2763.         }
  2764.     }
  2765.    
  2766.     return target;
  2767. };
  2768.  
  2769. tri4m.com.bridge = function(name, object)
  2770. {
  2771.     var fullName = object.prototype.comFullName;
  2772.     tri4m.shell[name] = function(options)
  2773.     {
  2774.         var isMethodCall    = typeof options === "string",
  2775.             args        = ECMA_slice.call(arguments, 1),
  2776.             returnValue = this;
  2777.  
  2778.         options = !isMethodCall && args.length
  2779.             ? tri4m.com.extend.apply(null, [options].concat(args))
  2780.             : options;
  2781.  
  2782.         if(isMethodCall)
  2783.         {
  2784.             this.each(function()
  2785.             {
  2786.                 var methodValue, instance = jQuery.data(this, fullName);
  2787.                
  2788.                 if(!instance)
  2789.                     return tri4m.log("cannot call methods on " + name + " prior to initialization; " + "attempted to call method '" + options + "'", 3);
  2790.                
  2791.                 if(!tri4m.isFunction(instance[options]) || options.charAt(0) === "_")
  2792.                     return tri4m.log("no such method '" + options + "' for " + name + " com instance", 3);
  2793.                
  2794.                
  2795.                 methodValue = instance[options].apply(instance, args);
  2796.                
  2797.                
  2798.                 if(methodValue !== instance
  2799.                 && methodValue !== undefined)
  2800.                 {
  2801.                     returnValue = methodValue && methodValue.jquery
  2802.                         ? returnValue.pushStack(methodValue.get())
  2803.                         : methodValue;
  2804.                        
  2805.                     return false;
  2806.                 }
  2807.             });
  2808.         }
  2809.         else
  2810.         {
  2811.             this.each(function()
  2812.             {
  2813.                 var instance = tri4m.data(this, fullName);
  2814.                
  2815.                 if(instance)
  2816.                 {
  2817.                     instance.option(options || {})._init();
  2818.                 }
  2819.                 else
  2820.                 {
  2821.                     new object(options, this);
  2822.                 }
  2823.             });
  2824.         }
  2825.  
  2826.         return returnValue;
  2827.     };
  2828. };
  2829.  
  2830. var uuid            = 0;
  2831. tri4m.__Com         = function(options, element) {};
  2832. tri4m.__Com._childConstructors  = [];
  2833.  
  2834. tri4m.__Com.prototype =
  2835. {
  2836.     comName: "component",
  2837.     defaultElement: "<div>",
  2838.     options:
  2839.     {
  2840.         disabled: false,
  2841.  
  2842.         // callbacks
  2843.         create: null
  2844.     },
  2845.     _create__Com: function(options, element)
  2846.     {
  2847.         element         = jQuery(element || this.defaultElement || this)[0];
  2848.         this.element        = jQuery(element);
  2849.         this.uuid       = uuid++;
  2850.         this.eventNamespace = "." + this.comName + this.uuid;
  2851.         this.options        = tri4m.com.extend
  2852.                     (
  2853.                         {},
  2854.                         this.options,
  2855.                         this._getCreateOptions(),
  2856.                         options
  2857.                     );
  2858.        
  2859.         if(element !== this)
  2860.         {
  2861.             jQuery.data(element, this.comName, this);
  2862.             jQuery.data(element, this.comFullName, this);
  2863.         }
  2864.        
  2865.         this.element.addClass(this.comFullName);
  2866.  
  2867.         this._create();
  2868.         this._init();
  2869.     },
  2870.     _getCreateOptions:  tri4m.noop,
  2871.     _getCreateEventData:    tri4m.noop,
  2872.     _init:          tri4m.noop,
  2873.     _log: function(message, level)
  2874.     {
  2875.         if(typeof this.options.debug === 'undefined')
  2876.             return;
  2877.            
  2878.         if(this.options.debug !== true)
  2879.             return;
  2880.            
  2881.         tri4m.log(this.comName + ': ' + message, level);
  2882.     },
  2883.     com: function()
  2884.     {
  2885.         return this.element;
  2886.     },
  2887.     keyCode: {
  2888.         ALT: 18,
  2889.         BACKSPACE: 8,
  2890.         CAPS_LOCK: 20,
  2891.         COMMA: 188,
  2892.         COMMAND: 91,
  2893.         COMMAND_LEFT: 91, // COMMAND
  2894.         COMMAND_RIGHT: 93,
  2895.         CONTROL: 17,
  2896.         DELETE: 46,
  2897.         DOWN: 40,
  2898.         END: 35,
  2899.         ENTER: 13,
  2900.         ESCAPE: 27,
  2901.         HOME: 36,
  2902.         INSERT: 45,
  2903.         LEFT: 37,
  2904.         MENU: 93, // COMMAND_RIGHT
  2905.         NUMPAD_ADD: 107,
  2906.         NUMPAD_DECIMAL: 110,
  2907.         NUMPAD_DIVIDE: 111,
  2908.         NUMPAD_ENTER: 108,
  2909.         NUMPAD_MULTIPLY: 106,
  2910.         NUMPAD_SUBTRACT: 109,
  2911.         PAGE_DOWN: 34,
  2912.         PAGE_UP: 33,
  2913.         PERIOD: 190,
  2914.         RIGHT: 39,
  2915.         SHIFT: 16,
  2916.         SPACE: 32,
  2917.         TAB: 9,
  2918.         UP: 38,
  2919.         WINDOWS: 91 // COMMAND
  2920.     },
  2921.     option: function(key, value)
  2922.     {
  2923.         var options = key, parts, curOption, i;
  2924.  
  2925.         if(arguments.length === 0)
  2926.             return tri4m.com.extend({}, this.options);
  2927.  
  2928.         if(typeof key === "string")
  2929.         {
  2930.             // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  2931.             options = {};
  2932.             parts   = key.split(".");
  2933.             key = parts.shift();
  2934.            
  2935.             if(parts.length)
  2936.             {
  2937.                 curOption = options[key] = tri4m.com.extend({}, this.options[key]);
  2938.                
  2939.                 for(i = 0; i < parts.length - 1; i++)
  2940.                 {
  2941.                     curOption[parts[i]] = curOption[parts[i]] || {};
  2942.                     curOption       = curOption[parts[i]];
  2943.                 }
  2944.                
  2945.                 key = parts.pop();
  2946.                
  2947.                 if(value === undefined)
  2948.                     return curOption[key] === undefined
  2949.                         ? null
  2950.                         : curOption[key];
  2951.                
  2952.                 curOption[key] = value;
  2953.             }
  2954.             else
  2955.             {
  2956.                 if(value === undefined)
  2957.                     return this.options[key] === undefined ? null : this.options[key];
  2958.                
  2959.                 options[key] = value;
  2960.             }
  2961.         }
  2962.  
  2963.         this._setOptions(options);
  2964.  
  2965.         return this;
  2966.     },
  2967.     _setOptions: function(options)
  2968.     {
  2969.         var key;
  2970.  
  2971.         for (key in options)
  2972.             this._setOption(key, options[key]);
  2973.  
  2974.         return this;
  2975.     },
  2976.     _setOption: function(key, value)
  2977.     {
  2978.         this.options[key] = value;
  2979.  
  2980.         if(key === "disabled")
  2981.         {
  2982.             this.com()
  2983.                 .toggleClass(this.comFullName + "-disabled ui-state-disabled", !!value)
  2984.                 .attr("aria-disabled", value);
  2985.         }
  2986.  
  2987.         return this;
  2988.     }
  2989. };
  2990.  
  2991. tri4m.com("__postInit.__Com",
  2992. {
  2993.     _create__Com: function()
  2994.     {
  2995.         tri4m.__Com.prototype._create__Com.apply(this, arguments);
  2996.         this._init();
  2997.     },
  2998. });
  2999.  
  3000. plat4m.bootstrap(function()
  3001. {
  3002.     var     JS      = tri4m.lib.loader.Javascript,
  3003.         JSLoader    = tri4m.lib.loader.Queue,
  3004.         Bootstrap   = new JSLoader({ success : tri4m.compstrap  });
  3005.    
  3006.     Bootstrap.push(new JS({ src : JQUERY_SRC, success : Bootstrap.next }));
  3007.    
  3008.     setTimeout
  3009.     (
  3010.         function()
  3011.         {
  3012.             typeof jQuery === 'undefined'
  3013.                 ? Bootstrap.start()
  3014.                 : tri4m.compstrap();
  3015.         },
  3016.         JQUERY_INIT_TIME
  3017.     );
  3018. });
  3019.  
  3020. window.tri4m = tri4m;
  3021. })(window);
Add Comment
Please, Sign In to add comment