fruffl

Untitled

Jan 31st, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 27.98 KB | None | 0 0
  1.  
  2. plat4m.bootstrap(function()
  3. {
  4.     var     JS      = tri4m.lib.loader.Javascript,
  5.         JSLoader    = tri4m.lib.loader.Queue,
  6.         Bootstrap   = new JSLoader({ success : tri4m.compstrap  });
  7.    
  8.     Bootstrap.push(new JS({ src : JQUERY_SRC, success : Bootstrap.next }));
  9.    
  10.     setTimeout
  11.     (
  12.         function()
  13.         {
  14.             typeof jQuery === 'undefined'
  15.                 ? Bootstrap.start()
  16.                 : tri4m.compstrap();
  17.         },
  18.         JQUERY_INIT_TIME
  19.     );
  20. });
  21.  
  22.  
  23. tri4m.extend
  24. (
  25.     {
  26.         lib :
  27.         {
  28.             exception :
  29.             {
  30.                 Throwable : function(name)
  31.                 {
  32.                     var name = name;
  33.                    
  34.                     var constructor = function(message)
  35.                     {
  36.                         //Error.apply(this, arguments);
  37.                         if(this == window) return new arguments.callee(message, level);
  38.                        
  39.                         this.message    = message || '';
  40.                         this.name   = name + '.Exception';
  41.                     };
  42.                    
  43.                     constructor.name = name || 'tri4m.lib.exception.Throwable';
  44.                     constructor.prototype.toString = Error.prototype.toString;
  45.                    
  46.                     return constructor;
  47.                 }
  48.             },
  49.             loader :
  50.             {
  51.                 /**
  52.                  * @param string src
  53.                  * @param object lfo        the expected object
  54.                  * @param function onload
  55.                  * @param function callback
  56.                  */
  57.                 Javascript : function(options)
  58.                 {
  59.                     this.name = 'tri4m.lib.loader.Javascript';
  60.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  61.                    
  62.                     var tried   = false;
  63.                     var avail   = false;
  64.                    
  65.                     var __settings = tri4m.extend(
  66.                     {
  67.                         src     : null,
  68.                         lfo     : null,
  69.                         success     : null
  70.                     }, options);
  71.                    
  72.                     this.load = function()
  73.                     {
  74.                         if(true === tried)
  75.                             return this;
  76.                            
  77.                         tried = true;
  78.                            
  79.                         if(null === __settings.src)
  80.                             throw new this.Exception('src is null.');
  81.                        
  82.                         /* NullReferenceError....
  83.                         if(typeof __settings.lfo !== 'undefined' && __settings.lfo !== null)
  84.                         {
  85.                             tri4m.log('lfo is avail: ' + tri4m.objectToString(__settings.lfo));
  86.                            
  87.                             avail = true;
  88.                             __settings.callback(this);
  89.                             return this;
  90.                         }
  91.                        
  92.                         */
  93.                        
  94.                         tri4m.log('Load script ' + __settings.src);
  95.                        
  96.                         try
  97.                         {
  98.                             var head = document.getElementsByTagName('head')[0],
  99.                                 script = document.createElement('script');
  100.                        
  101.                             script.setAttribute('src', __settings.src);
  102.                             script.setAttribute('type', 'text/javascript');
  103.                             script.setAttribute('charset', 'utf-8');
  104.                            
  105.                             script.onload = script.onreadstatechange = function()
  106.                             {
  107.                                 if(!this.readyState
  108.                                 || this.readyState == 'loaded'
  109.                                 || this.readyState == 'complete')
  110.                                 {
  111.                                     script.onload = script.onreadystatechange = null;
  112.                                    
  113.                                     if(tri4m.isFunction(__settings.success))
  114.                                         __settings.success(__settings);
  115.                                        
  116.                                 }
  117.                             };
  118.                        
  119.                             head.insertBefore(script, head.firstChild);
  120.                            
  121.                         }
  122.                         catch(e)
  123.                         {
  124.                             throw new this.Exception('Unable to append javasript ' + __settings.src)
  125.                         }
  126.                        
  127.                        
  128.                         return this;
  129.                     }
  130.                 },
  131.                 /**
  132.                  * @param string src
  133.                  * @param object lfo        the expected object
  134.                  * @param function onload
  135.                  * @param function callback
  136.                  */
  137.                 Stylesheet : function(options)
  138.                 {
  139.                     this.name = 'tri4m.lib.loader.Stylesheet';
  140.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  141.                    
  142.                     var tried   = false;
  143.                     var avail   = false;
  144.                    
  145.                     var __settings = tri4m.extend(
  146.                     {
  147.                         src     : null,
  148.                         lfo     : null,
  149.                         success     : null
  150.                     }, options);
  151.                    
  152.                     this.load = function()
  153.                     {
  154.                         if(true === tried)
  155.                             return this;
  156.                            
  157.                         tried = true;
  158.                            
  159.                         if(null === __settings.src)
  160.                             throw new this.Exception('src is null.');
  161.                        
  162.                         /* NullReferenceError....
  163.                         if(typeof __settings.lfo !== 'undefined' && __settings.lfo !== null)
  164.                         {
  165.                             tri4m.log('lfo is avail: ' + tri4m.objectToString(__settings.lfo));
  166.                            
  167.                             avail = true;
  168.                             __settings.callback(this);
  169.                             return this;
  170.                         }
  171.                        
  172.                         */
  173.                        
  174.                         tri4m.log('Load script ' + __settings.src);
  175.                        
  176.                         try
  177.                         {
  178.                             var head = document.getElementsByTagName('head')[0],
  179.                                 script = document.createElement('link');
  180.                        
  181.                             script.setAttribute('src', __settings.src);
  182.                             script.setAttribute('type', 'text/css');
  183.                             script.setAttribute('media', 'all');
  184.                            
  185.                             script.onload = script.onreadstatechange = function()
  186.                             {
  187.                                 if(!this.readyState
  188.                                 || this.readyState == 'loaded'
  189.                                 || this.readyState == 'complete')
  190.                                 {
  191.                                     script.onload = script.onreadystatechange = null;
  192.                                    
  193.                                     if(tri4m.isFunction(__settings.success))
  194.                                         __settings.success(__settings);
  195.                                        
  196.                                 }
  197.                             };
  198.                        
  199.                             head.insertBefore(script, head.firstChild);
  200.                            
  201.                         }
  202.                         catch(e)
  203.                         {
  204.                             throw new this.Exception('Unable to append stylesheet ' + __settings.src)
  205.                         }
  206.                        
  207.                        
  208.                         return this;
  209.                     }
  210.                 },
  211.                 /**
  212.                  * Queue-Loader based on Automation-Player
  213.                  *
  214.                  *
  215.                  * var Loader = new tri4m.lib.loader.Queue('Javascript');
  216.                  *
  217.                  * var myComplete = function() { Loader.next(); alert('whohoo'); }
  218.                  *
  219.                  * Loader.push(new tri4m.lib.loader.Javascript({src : 'swfobject.js', success : Loader.next}))
  220.                  * Loader.push(new tri4m.lib.loader.Javascript({src : 'whoohooo.js', success : myComplete }));
  221.                  * Loader.push(new tri4m.lib.loader.Javascript({src : 'another.js', success : Loader.next }));
  222.                  * Loader.start();
  223.                  *
  224.                  *
  225.                  * jQuery is ready before we init our plugins:
  226.                  * plat4m.bootstrap(function()
  227.                  * {
  228.                  *  var JS = tri4m.lib.loader.Javascript, JSLoader = tri4m.lib.loader.Queue,
  229.                  *      Compstrap = new JSLoader,
  230.                  *      Bootstrap = new JSLoader({ success: Compstrap.start });
  231.                  *  
  232.                  *  Bootstrap.push(new JS({ src : 'http://localfrost/wp-content/plugins/tri4m/jquery.js', success : Bootstrap.next }));
  233.                  *  Compstrap.push(new JS({ src : 'http://localfrost/wp-content/plugins/tri4m/tri4mQtLoader/js/tri4m.QtLoader.js' }));
  234.                  *  
  235.                  *  setTimeout
  236.                  *  (
  237.                  *      function()
  238.                  *      {
  239.                  *          typeof jQuery === 'undefined'
  240.                  *              ? Bootstrap.start()
  241.                  *              : Compstrap.start();
  242.                  *      } , 200
  243.                  *  );
  244.                  * });
  245.                  *
  246.                  * @note calling Loader.next() in File-callback is required
  247.                  * @see ri4m.lib.automation.Player
  248.                  */
  249.                 Queue : function(options)
  250.                 {
  251.                     var __methods = new tri4m.lib.method.Hook,
  252.                         __player = new tri4m.lib.automation.Player(options);
  253.                    
  254.                     /**
  255.                      * @param tri4m.lib.loader.File File
  256.                      */
  257.                     this.push = function(File)
  258.                     {
  259.                         __methods.push(File.load);
  260.                         return this;
  261.                     }
  262.                    
  263.                     /**
  264.                      * start
  265.                      */
  266.                     this.start = function()
  267.                     {  
  268.                         __player.setup(__methods).play();
  269.                         return this;
  270.                     }
  271.                    
  272.                     /**
  273.                      * next
  274.                      */
  275.                     this.next = function()
  276.                     {
  277.                         __player.next();
  278.                         return this;
  279.                     }
  280.                 }
  281.             },
  282.             property :
  283.             {
  284.                 /**
  285.                  * value for value-queue
  286.                  *
  287.                  * overwrite is allowed or not
  288.                  *
  289.                  * @param value mixed
  290.                  * @param protect bool true: can not overwrite existing value
  291.                  */
  292.                 Value : function(value, protect)
  293.                 {
  294.                     this.name = 'tri4m.lib.property.Value';
  295.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  296.                    
  297.                     var __value = value || null;
  298.                     var __protect = (protect === true) ? true : false;
  299.                    
  300.                     /**
  301.                      * get value
  302.                      * @return mixed
  303.                      */
  304.                     this.get = function()
  305.                     {
  306.                         return __value;
  307.                     };
  308.                    
  309.                     /**
  310.                      * set value
  311.                      *
  312.                      * this has no effect, if __protect is true
  313.                      * @return tri4m.lib.property.Value
  314.                      */
  315.                     this.set = function(value)
  316.                     {
  317.                         if(__protect === true)
  318.                             throw new this.Exception(value + ' is protected', 3);
  319.                        
  320.                         __value = value;
  321.                         return this;
  322.                     };
  323.                    
  324.                     /**
  325.                      * get variable as object
  326.                      *
  327.                      * @return object
  328.                      */
  329.                     this.toObject = function()
  330.                     {
  331.                         return {
  332.                             value   : __value,
  333.                             protect : __protect
  334.                         };
  335.                     };
  336.                 },
  337.                 /**
  338.                  * value registry
  339.                  *
  340.                  * store vars with values
  341.                  *
  342.                  * // new value-queue
  343.                  * var foo = new tri4m.lib.property.Registry();
  344.                  *
  345.                  * // var "baz"
  346.                  * foo.register('baz', 'baz: bar'); log.t100(foo.get('baz')); // baz: bar
  347.                  * foo.set('baz', 'baz: bar -> foo'); log.t100(foo.get('baz')); // baz: foo
  348.                  *
  349.                  * // protected var "foo"
  350.                  * foo.register('foo', 'foo: lol', true); log.t100(foo.get('foo')); // foo: lol
  351.                  * foo.set('foo', 'foo: lol -> rofl'); log.t100(foo.get('foo')); // foo: lol
  352.                  */
  353.                 Registry : function()
  354.                 {
  355.                     this.name = 'tri4m.lib.property.Registry';
  356.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  357.                    
  358.                     var __data = {};
  359.                    
  360.                     /**
  361.                      * register value-instance
  362.                      *
  363.                      * @param name string instance-name
  364.                      * @param value mixed
  365.                      * @param protect bool true: can not overwrite existing value
  366.                      * @see tri4m.lib.property.Value()
  367.                      * @return tri4m.lib.property.Registry
  368.                      */
  369.                     this.register = function(name, value, protect)
  370.                     {
  371.                         if(this.isset(name) === true)
  372.                             throw new this.Exception('Unable to register existing property ' +  name, 3);
  373.                        
  374.                         __data[name] = new tri4m.lib.property.Value(value, protect);
  375.  
  376.                         return this;
  377.                     };
  378.                    
  379.                     /**
  380.                      * unregister value-instance
  381.                      *
  382.                      * @param name string instance-name
  383.                      * @return tri4m.lib.property.Registry
  384.                      */
  385.                     this.unregister = function(name)
  386.                     {
  387.                         if(this.isset(name) === false)
  388.                             return this;
  389.                        
  390.                         delete _data[name]
  391.  
  392.                         return this;
  393.                     };
  394.  
  395.                     /**
  396.                      * isset instance
  397.                      *
  398.                      * @param name string instance-name
  399.                      * @return bool
  400.                      */
  401.                     this.isset = function(name)
  402.                     {
  403.                         return (!__data[name]) ? false : true;
  404.                     };
  405.  
  406.                     /**
  407.                      * get value of instance
  408.                      *
  409.                      * @param name string instance-name
  410.                      * @see tri4m.lib.property.Value.get()
  411.                      * @return tri4m.lib.property.Value || null
  412.                      */
  413.                     this.get = function(name)
  414.                     {
  415.                         return ((this.isset(name) === true) ? __data[name].get() : null);
  416.                     };
  417.  
  418.                     /**
  419.                      * set value of instance
  420.                      *
  421.                      * you must register your variable at first!
  422.                      * you can not use this registry as garbage dump!
  423.                      *
  424.                      * @param name string instance-name
  425.                      * @param value mixed
  426.                      * @see tri4m.lib.property.Value.set()
  427.                      * @return tri4m.lib.property.Registry
  428.                      */
  429.                     this.set = function(name, value)
  430.                     {
  431.                         if(false === this.isset(name))
  432.                             throw new this.Exception('Unable to update value for ' +  name + ': not found', 3);
  433.                        
  434.                         try{ __data[name].set(value); }
  435.                         catch(e){ throw new this.Exception('Unable update value for ' +  name, 3); }
  436.                        
  437.                         return this;
  438.                     };
  439.  
  440.                     /**
  441.                      * get queue as object
  442.                      *
  443.                      * @return tri4m.lib.property.Registry  as propertyName:propertyValue object
  444.                      */
  445.                     this.toObject = function()
  446.                     {
  447.                         var q = {};
  448.                         for(i in __data)
  449.                             q[i] = __data[i].toObject();
  450.                         return q;
  451.                     };
  452.  
  453.                     /**
  454.                      * get queue as value object
  455.                      *
  456.                      * @return tri4m.lib.property.Registry.__data as propertyValue object
  457.                      */
  458.                     this.toValueObject = function()
  459.                     {
  460.                         var q = {};
  461.                         for(i in __data)
  462.                             q[i] = __data[i].toObject().value;
  463.                         return q;
  464.                     };
  465.  
  466.                     /**
  467.                      * get queue as property object
  468.                      *
  469.                      * @return tri4m.lib.property.Registry.__data as propertyName object
  470.                      */
  471.                     this.toPropertyObject = function()
  472.                     {
  473.                         var q = {};
  474.                         var k = 0;
  475.                         for(i in __data)
  476.                         {
  477.                             q[k] = i;
  478.                             k++;
  479.                         }
  480.                         return q;
  481.                     };
  482.                 }
  483.             },
  484.             method :
  485.             {
  486.                 /**
  487.                  * method FIFO
  488.                  *
  489.                  * @param runonce bool true: terminate queue on exec
  490.                  *
  491.                  * // some stuff
  492.                  * var test11 = function(){log.t100('test1.1')};
  493.                  * var test12 = function(){log.t100('test1.2')};
  494.                  *
  495.                  * // default queue
  496.                  * var bar = new tri4m.lib.method.Hook;
  497.                  * bar.push(test11).push(test12)
  498.                  *  .execute()  // test1.1 test1.2
  499.                  *  .execute(); // test1.1 test1.2
  500.                  *
  501.                  * // run-once queue
  502.                  * var baz = new tri4m.lib.method.Hook(true);
  503.                  * baz.push(test11).push(test12)
  504.                  *  .execute()  // test1.1 test1.2
  505.                  *  .execute(); // nothing
  506.                  */
  507.                 Hook : function(runonce)
  508.                 {
  509.                     this.name = 'tri4m.lib.method.Hook';
  510.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  511.                    
  512.                     var __hook = [];
  513.                     var __runonce = (runonce !== true) ? false : true;
  514.  
  515.                     /**
  516.                      * add function to queue
  517.                      *
  518.                      * @param fn function
  519.                      * @return tri4m.lib.method.Hook
  520.                      */
  521.                     this.push = function(fn)
  522.                     {
  523.                         __hook.push(fn);
  524.                         return this;
  525.                     };
  526.  
  527.                     /**
  528.                      * execute queue
  529.                      *
  530.                      * @return tri4m.lib.method.Hook
  531.                      */
  532.                     this.execute = function()
  533.                     {
  534.                         if(__hook.length === 0)
  535.                             return this;
  536.  
  537.                         if(__runonce === false)
  538.                             for(i in __hook) __hook[i]();
  539.                         else
  540.                             while(__hook.length > 0) (__hook.shift())();
  541.  
  542.                         return this;
  543.                     };
  544.  
  545.                     /**
  546.                      * terminate queue
  547.                      *
  548.                      * @return tri4m.lib.method.Hook
  549.                      */
  550.                     this.reset = function()
  551.                     {
  552.                         __hook = [];
  553.                         return this;
  554.                     };
  555.  
  556.                     /**
  557.                      * get queue as array
  558.                      *
  559.                      * @return tri4m.lib.method.Hook.__hook... imho as copy
  560.                      */
  561.                     this.toArray = function()
  562.                     {
  563.                         var a = __hook;
  564.                         return a;
  565.                     };
  566.                 },
  567.                 /**
  568.                  * method hook registry
  569.                  *
  570.                  * // some stuff
  571.                  * var test11 = function(){log.t100('test1.1')};
  572.                  * var test12 = function(){log.t100('test1.2')};
  573.                  * var test21 = function(){log.t100('test2.1')};
  574.                  * var test22 = function(){log.t100('test2.2')};
  575.                  *
  576.                  * // create registry queue
  577.                  * var foo = new tri4m.lib.method.Registry();
  578.                  *
  579.                  * // default queue
  580.                  * foo.register('test1').push('test1', test11).push('test1', test12)
  581.                  *  .execute('test1')   // test1.1 test1.2
  582.                  *  .execute('test1');  // test1.1 test1.2
  583.                  *
  584.                  * // run-once queue
  585.                  * foo.register('test2', true).push('test2', test11).push('test2', test12)
  586.                  *  .execute('test2')   // test2.1 test2.2
  587.                  *  .execute('test2');  // nothing
  588.                  *
  589.                  *
  590.                  * // shorthand:
  591.                  * // default queue
  592.                  * foo.get('test3').push(test21).push(test22)
  593.                  *  .execute()  // test2.1 test2.2
  594.                  *  .execute(); // test2.1 test2.2
  595.                  *
  596.                  * // run-once queue
  597.                  * foo.get('test4', true).push(test21).push(test22)
  598.                  *  .execute()  // test2.1 test2.2
  599.                  *  .execute(); // nothing
  600.                  */
  601.                 Registry : function()
  602.                 {
  603.                     this.name = 'tri4m.lib.method.Registry';
  604.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  605.                    
  606.                     var __hook = new tri4m.lib.property.Registry();
  607.  
  608.                     /**
  609.                      * register queue instance
  610.                      *
  611.                      * @param name string instance-name
  612.                      * @param runonce bool
  613.                      * @see tri4m.lib.method.Hook()
  614.                      * @see tri4m.lib.property.Registry.register()
  615.                      * @return tri4m.lib.method.Registry
  616.                      */
  617.                     this.register = function(name, runonce)
  618.                     {
  619.                         __hook.register(name, new tri4m.lib.method.Hook(runonce), true);
  620.                         return this;
  621.                     };
  622.  
  623.                     /**
  624.                      * isset instance
  625.                      *
  626.                      * @param name string instance-name
  627.                      * @see tri4m.lib.property.Registry.isset()
  628.                      * @return bool tri4m.lib.property.Registry.isset()
  629.                      */
  630.                     this.isset = function(name)
  631.                     {
  632.                         return __hook.isset(name);
  633.                     };
  634.  
  635.                     /**
  636.                      * get/create queue instance
  637.                      *
  638.                      * @param name string instance-name
  639.                      * @param runonce bool
  640.                      * @see tri4m.lib.method.Hook
  641.                      * @return tri4m.lib.method.Hook
  642.                      */
  643.                     this.get = function(name, runonce)
  644.                     {
  645.                         //log.t100(__hook.get(name).className());
  646.                         if(this.isset(name) === false)
  647.                             this.register(name, runonce);
  648.                         return __hook.get(name);
  649.                     };
  650.  
  651.                     /**
  652.                      * execute queue of instance
  653.                      *
  654.                      * @param name string instance-name
  655.                      * @see tri4m.lib.method.Hook.execute()
  656.                      * @return tri4m.lib.method.Registry
  657.                      */
  658.                     this.execute = function(name)
  659.                     {
  660.                         if(this.isset(name) === true)
  661.                             this.get(name).execute();
  662.                         return this;
  663.                     };
  664.  
  665.                     /**
  666.                      * terminate queue
  667.                      *
  668.                      * @see tri4m.lib.method.Hook.reset()
  669.                      * @return tri4m.lib.method.Registry
  670.                      */
  671.                     this.reset = function(name)
  672.                     {
  673.                         if(this.isset(name) === true)
  674.                             this.get(name).reset();
  675.                         return this;
  676.                     };
  677.  
  678.                     /**
  679.                      * add function to queue of instance
  680.                      *
  681.                      * @param name string instance-name
  682.                      * @param fn function
  683.                      * @see tri4m.lib.method.Hook.push()
  684.                      * @return tri4m.lib.method.Registry
  685.                      */
  686.                     this.push = function(name, fn)
  687.                     {
  688.                         if(this.isset(name) === true)
  689.                             this.get(name).push(fn);
  690.                         return this;
  691.                     };
  692.  
  693.                     /**
  694.                      * get queue as object
  695.                      *
  696.                      * @return tri4m.lib.property.Registry.__hook as copy
  697.                      */
  698.                     this.toObject = function()
  699.                     {
  700.                         return __hook.toObject();
  701.                     };
  702.  
  703.                     /**
  704.                      * get queue as object
  705.                      *
  706.                      * @return tri4m.lib.property.Registry.__hook as copy
  707.                      */
  708.                     this.getHook = function()
  709.                     {
  710.                         var q = __hook;
  711.                         return q;
  712.                     };
  713.                 }
  714.             },
  715.             automation :
  716.             {
  717.                 /**
  718.                  * animation playlist player
  719.                  *
  720.                  * split methods from tri4m.lib.method.Hook
  721.                  * to partials
  722.                  *
  723.                  * @example tri4m.lib.loader.Queue
  724.                  *
  725.                  *
  726.                  * step 1:
  727.                  *  create your methods:
  728.                  *
  729.                  * ...
  730.                  * Env :
  731.                  * {
  732.                  *  Playlists : null,
  733.                  *  Animation :
  734.                  *  {
  735.                  *      test10 : function(){
  736.                  *          log.t100('test10');
  737.                  *          tri4m('ul.list li').css({height: 5});
  738.                  *          tri4m.Env.Playlists.next('intro');
  739.                  *      },
  740.                  *      test11 : function(){
  741.                  *          log.t100('test11');
  742.                  *          tri4m('ul.list li').animate({height: 140}, 2200, function()
  743.                  *          {
  744.                  *              log.t100('test11 anim callback');
  745.                  *              tri4m.Env.Playlists.next('intro');
  746.                  *          });
  747.                  *      },
  748.                  *      test12 : function(){
  749.                  *          log.t100('test12');
  750.                  *          tri4m('ul.list li').css({width: 10});
  751.                  *          tri4m.Env.Playlists.next('intro');
  752.                  *      },
  753.                  *      test13 : function(){
  754.                  *          log.t100('test13');
  755.                  *          tri4m('ul.list li').animate({width: 140}, 2200);
  756.                  *          tri4m.Env.Playlists.next('intro');
  757.                  *      }
  758.                  *  }
  759.                  * },
  760.                  * ...
  761.                  *
  762.                  *
  763.                  * step 2:
  764.                  *  init the animation registry and register
  765.                  *  the methods into sections, e.g. "intro" or "button-hover"
  766.                  *
  767.                  * ...
  768.                  * test : function()
  769.                  * {
  770.                  *  tri4m.Env.Playlists =
  771.                  *      new tri4m.lib.automation.Registry();
  772.                  *
  773.                  *  tri4m.Env.Playlists.register('intro')
  774.                  *      .push(tri4m.Env.Animation.test10)
  775.                  *      .push(tri4m.Env.Animation.test11)
  776.                  *      .push(tri4m.Env.Animation.test12)
  777.                  *      .push(tri4m.Env.Animation.test13)
  778.                  *  ;
  779.                  *  tri4m.Env.Playlists.play('intro');
  780.                  * },
  781.                  * ...
  782.                  *
  783.                  *
  784.                  * @todo    lock, pause, start, stop not really implemented
  785.                  */
  786.                 Player : function(options)
  787.                 {
  788.                     this.name = 'tri4m.lib.automation.Player';
  789.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  790.                    
  791.                    
  792.                     var __settings = tri4m.extend(
  793.                     {
  794.                         onPlayStart : tri4m.noop,
  795.                         onPlayNext  : tri4m.noop,
  796.                         onPlayPause : tri4m.noop,
  797.                         onPlayStop  : tri4m.noop,
  798.                         success : tri4m.noop
  799.                     }, options);
  800.                    
  801.                     /**
  802.                      * method registry queue
  803.                      */
  804.                     var __registry = null;
  805.  
  806.                     /**
  807.                      * __isPlaying bool status quo
  808.                      */
  809.                     var __isPlaying = false;
  810.  
  811.                     /**
  812.                      * translated registry as func-callback-object
  813.                      */
  814.                     var __playlist = [];
  815.  
  816.                     /**
  817.                      * working-copy of __playlist
  818.                      */
  819.                     var __playqueue = [];
  820.  
  821.                     /**
  822.                      * counter
  823.                      */
  824.                     var __playedTimes = 0;
  825.  
  826.                     /**
  827.                      * install method queue
  828.                      *
  829.                      * @param registry tri4m.lib.method.Hook
  830.                      * @return tri4m.lib.automation.Player
  831.                      */
  832.                     this.setup = function(registry)
  833.                     {
  834.                         if(__registry !== null)
  835.                             return this;
  836.  
  837.                         __registry = registry;
  838.  
  839.                         var methods = __registry.toArray();
  840.  
  841.                         for(var i = 0; i < methods.length; i++)
  842.                         {
  843.                             var fn = methods[i];
  844.  
  845.                             if(typeof fn !== 'function')
  846.                                 continue;
  847.  
  848.                             var cb = function(){};
  849.                            
  850.                             if((next = methods[i+1]))
  851.                             {
  852.                                 if(typeof next !== 'function')
  853.                                     continue;
  854.  
  855.                                 cb = next;
  856.                             }
  857.  
  858.                             var item = {
  859.                                 method: fn,
  860.                                 callback :
  861.                                 {
  862.                                     method : cb
  863.                                 }
  864.                             };
  865.                            
  866.                             __playlist.push(item);
  867.                         }
  868.                        
  869.                         return this;
  870.                     };
  871.  
  872.                     /**
  873.                      * init playing
  874.                      *
  875.                      * @return tri4m.lib.automation.Player
  876.                      */
  877.                     this.play = function()
  878.                     {
  879.                         if(true === this.isPlaying())
  880.                             return false;
  881.  
  882.                         if(__playqueue.length === 0)
  883.                         {
  884.                             __playedTimes++;
  885.                             __settings.onPlayStart();
  886.                         }
  887.                            
  888.                        
  889.                         __isPlaying = true;
  890.                         __playqueue = __playlist;
  891.                        
  892.  
  893.                         this.next();
  894.                         return this;
  895.                     };
  896.  
  897.                     /**
  898.                      * play next method
  899.                      *
  900.                      * test11 : function(){
  901.                      *  log.t100('test11');
  902.                      *  tri4m('ul.list li').animate({height: 140}, 2200, function()
  903.                      *  {
  904.                      *      log.t100('test11 anim callback');
  905.                      *      tri4m.Env.Playlists.next('intro');
  906.                      *  });
  907.                      * },
  908.                      *
  909.                      * @return tri4m.lib.automation.Player
  910.                      */
  911.                     this.next = function()
  912.                     {
  913.                         if(null === __playqueue)
  914.                             return this;
  915.  
  916.                         var next = null;
  917.  
  918.                         if(__playqueue.length > 0)
  919.                             next = __playqueue.shift();
  920.  
  921.                         if(!next)
  922.                         {
  923.                             this.stop();
  924.                             __settings.success();
  925.                             return this;
  926.                         }
  927.  
  928.                         __settings.onPlayNext();
  929.                         next.method();
  930.  
  931.                         return this;
  932.                     };
  933.  
  934.                     /**
  935.                      * pause
  936.                      *
  937.                      * @return tri4m.lib.automation.Player
  938.                      */
  939.                     this.pause = function()
  940.                     {
  941.                         __isPlaying = false;
  942.                         __settings.onPlayPause();
  943.                         return this;
  944.                     };
  945.  
  946.                     /**
  947.                      * stop/abort playing and delete working copy
  948.                      *
  949.                      * @return tri4m.lib.automation.Player
  950.                      */
  951.                     this.stop = function()
  952.                     {
  953.                         __playqueue = [];
  954.                         __isPlaying = false;
  955.                         __settings.onPlayStop();
  956.                         return this;
  957.                     };
  958.  
  959.                     /**
  960.                      * is playing status
  961.                      *
  962.                      * @return bool status quo
  963.                      */
  964.                     this.isPlaying = function()
  965.                     {
  966.                         return __isPlaying;
  967.                     };
  968.                 },
  969.                 /**
  970.                  * playlist class
  971.                  *
  972.                  * holds a methodhook (playlist) and the player
  973.                  *
  974.                  */
  975.                 Playlist : function()
  976.                 {
  977.                     this.name = 'tri4m.lib.automation.Playlist';
  978.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  979.                    
  980.                     /**
  981.                      * method queue/playlist
  982.                      */
  983.                     var __playlist  = new tri4m.lib.method.Hook();
  984.  
  985.                     /**
  986.                      * player
  987.                      */
  988.                     var __player    = new tri4m.lib.automation.Player();
  989.  
  990.                     /**
  991.                      * push method to __playlist
  992.                      *
  993.                      * @param function
  994.                      * @return tri4m.lib.automation.Playlist
  995.                      */
  996.                     this.push = function(fn)
  997.                     {
  998.                         __playlist.push(fn);
  999.                         return this;
  1000.                     };
  1001.  
  1002.                     /**
  1003.                      * initialize player and start playing
  1004.                      *
  1005.                      * @return tri4m.lib.automation.Playlist
  1006.                      */
  1007.                     this.play = function()
  1008.                     {
  1009.                         __player.setup(__playlist).play();
  1010.                         return this;
  1011.                     };
  1012.  
  1013.                     /**
  1014.                      * play next frame
  1015.                      *
  1016.                      * this is the callback-caller
  1017.                      *
  1018.                      * test11 : function(){
  1019.                      *  log.t100('test11');
  1020.                      *  tri4m('ul.list li').animate({height: 140}, 2200, function()
  1021.                      *  {
  1022.                      *      log.t100('test11 anim callback');
  1023.                      *      tri4m.Env.Playlists.next('intro');
  1024.                      *  });
  1025.                      * },
  1026.                      *
  1027.                      *
  1028.                      * @return tri4m.lib.automation.Playlist
  1029.                      */
  1030.                     this.next = function()
  1031.                     {
  1032.                         __player.next();
  1033.                         return this;
  1034.                     };
  1035.                 },
  1036.                 /**
  1037.                  * playlist/player registry
  1038.                  *
  1039.                  * store animation-queues by event-name
  1040.                  *
  1041.                  */
  1042.                 Registry : function()
  1043.                 {
  1044.                     this.name = 'tri4m.lib.automation.Registry';
  1045.                     this.Exception = new tri4m.lib.exception.Throwable(this.name);
  1046.                    
  1047.                     var __queue = new tri4m.lib.property.Registry();
  1048.  
  1049.                     /**
  1050.                      * craete a new playlist-instance
  1051.                      *
  1052.                      * @param string instance name
  1053.                      * @return tri4m.lib.automation.Playlist
  1054.                      */
  1055.                     this.register = function(name)
  1056.                     {
  1057.                         __queue.register(name, new tri4m.lib.automation.Playlist(), true);
  1058.                         return __queue.get(name);
  1059.                     };
  1060.  
  1061.                     /**
  1062.                      * get playlist-instance
  1063.                      *
  1064.                      * @param string instance name
  1065.                      * @return tri4m.lib.automation.Playlist
  1066.                      */
  1067.                     this.get = function(name)
  1068.                     {
  1069.                         return __queue.get(name);
  1070.                     };
  1071.                    
  1072.                     /**
  1073.                      * play a playlist-instance
  1074.                      *
  1075.                      * @param string instance name
  1076.                      * @return tri4m.lib.automation.Registry
  1077.                      */
  1078.                     this.play = function(name)
  1079.                     {
  1080.                         __queue.get(name).play();
  1081.                         return this;
  1082.                     };
  1083.                    
  1084.                     /**
  1085.                      * play next callback
  1086.                      *
  1087.                      * @param string instance name
  1088.                      * @return tri4m.lib.automation.Registry
  1089.                      */
  1090.                     this.next = function(name)
  1091.                     {
  1092.                         __queue.get(name).next();
  1093.                         return this;
  1094.                     };
  1095.                 }
  1096.             }
  1097.         }
  1098.     }
  1099. );
  1100.  
  1101. tri4m.extend
  1102. (
  1103.     {
  1104.         append :
  1105.         {
  1106.             /**
  1107.              * head:
  1108.              *
  1109.              * (function(tri4m, undefined)
  1110.              * {
  1111.              *  tri4m(function()
  1112.              *  {
  1113.              *      tri4m.append([
  1114.              *          'plugin.js',
  1115.              *          'another.js'
  1116.              *      ],
  1117.              *      {
  1118.              *          success : function()
  1119.              *          {
  1120.              *              tri4m.log('-- init my plugin');
  1121.              *          }
  1122.              *      });
  1123.              *  });
  1124.              * })(tri4m);
  1125.              */
  1126.             Javascript : function(src, options, hold)
  1127.             {
  1128.                 var __settings = tri4m.extend
  1129.                 (
  1130.                     {
  1131.                         success : tri4m.noop
  1132.                     },
  1133.                     options
  1134.                 );
  1135.                
  1136.                 if(typeof stack === 'undefined')
  1137.                      stack = new tri4m.lib.loader.Queue({ success : __settings.success });
  1138.                
  1139.                 if(typeof src !== 'string')
  1140.                 {
  1141.                     var i = 0, l = src.length;
  1142.                    
  1143.                     for(var name in src)
  1144.                     {
  1145.                         i++;
  1146.                         tri4m.append.Javascript(src[name], {}, i !== l)
  1147.                     }
  1148.                        
  1149.                     return tri4m.com;
  1150.                 }
  1151.                
  1152.                 if(typeof cache === 'undefined')
  1153.                     cache = [];
  1154.                
  1155.                 for(var i in cache)
  1156.                     if(src === cache[i])
  1157.                         return tri4m.com;
  1158.                
  1159.                 cache.push(src);   
  1160.                
  1161.                 tri4m.log('append script ' + src);
  1162.                
  1163.                      
  1164.                 var cur = stack;
  1165.                
  1166.                 stack.push(new tri4m.lib.loader.Javascript(
  1167.                 {
  1168.                     //src : src + '?' + Math.random(0, 100000000),
  1169.                     src : src,
  1170.                     success : cur.next
  1171.                    
  1172.                 }));
  1173.                
  1174.                 if(!hold || hold !== true)
  1175.                     stack.start();
  1176.                    
  1177.                 return tri4m;
  1178.             },
  1179.             Stylesheet : function(src, options, hold)
  1180.             {
  1181.                 var __settings = tri4m.extend
  1182.                 (
  1183.                     {
  1184.                         success : tri4m.noop
  1185.                     },
  1186.                     options
  1187.                 );
  1188.                
  1189.                 if(typeof stack === 'undefined')
  1190.                      stack = new tri4m.lib.loader.Queue({ success : __settings.success });
  1191.                
  1192.                 if(typeof src !== 'string')
  1193.                 {
  1194.                     var i = 0, l = src.length;
  1195.                    
  1196.                     for(var name in src)
  1197.                     {
  1198.                         i++;
  1199.                         tri4m.append.Stylesheet(src[name], {}, i !== l)
  1200.                     }
  1201.                        
  1202.                     return tri4m.com;
  1203.                 }
  1204.                
  1205.                 if(typeof cache === 'undefined')
  1206.                     cache = [];
  1207.                
  1208.                 for(var i in cache)
  1209.                     if(src === cache[i])
  1210.                         return tri4m.com;
  1211.                
  1212.                 cache.push(src);   
  1213.                
  1214.                 tri4m.log('append script ' + src);
  1215.                
  1216.                      
  1217.                 var cur = stack;
  1218.                
  1219.                 stack.push(new tri4m.lib.loader.Stylesheet(
  1220.                 {
  1221.                     //src : src + '?' + Math.random(0, 100000000),
  1222.                     src : src,
  1223.                     success : cur.next
  1224.                 }));
  1225.                
  1226.                 if(!hold || hold !== true)
  1227.                     stack.start();
  1228.                    
  1229.                 return tri4m;
  1230.             }
  1231.         }
Add Comment
Please, Sign In to add comment