Advertisement
fruffl

Method/Var Class

Dec 15th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 9.88 KB | None | 0 0
  1. <?PHP
  2. require_once './illi.class.hlp.php';
  3. $JS = new JS();
  4. $JS->load(array(
  5.     'javascript/jquery/jquery-1.5.1.min.js',
  6.     'javascript/jquery/jquery-ui-1.8.11.custom.min.js',
  7.     'javascript/jquery/jquery-1.5.1.ext.js'
  8. ));
  9. print $JS->render();?>
  10.  
  11. (function( $ ){
  12.     $.xtcmApp = {version: '0.0.2', vision: 'idle in roflcopter', jquery: '1.5.1', author: '~lvm', web: 'http://illi.be'};
  13.     $.xtcmApp.global =
  14.     {
  15.         /**
  16.          * not in use
  17.          * @see $.xtcmApp.initProto()
  18.          */
  19.         __SUPER__ :
  20.         {
  21.             __METHOD__ :
  22.             {
  23.                 __QUEUE__ : { initialize : function(){} },
  24.                 __REGISTRY__ : { initialize : function(){} }
  25.             },
  26.             __VARIABLE__ :
  27.             {
  28.                 __VALUE__ : { initialize : function(){} },
  29.                 __REGISTRY__ : { initialize : function(){} }
  30.             }
  31.         },
  32.         /**
  33.          * CLASS LIB
  34.          *
  35.          * @see $.xtcmApp.initProto()
  36.          */
  37.         __CLASS__ :
  38.         {
  39.             __METHOD__ :
  40.             {
  41.                 /**
  42.                  * method queue
  43.                  *
  44.                  * @param runonce bool true: terminate queue on exec
  45.                  *
  46.                  * // some stuff
  47.                  * var test11 = function(){alert('test1.1')};
  48.                  * var test12 = function(){alert('test1.2')};
  49.                  *
  50.                  * // default queue
  51.                  * var bar = new $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__();
  52.                  * bar.push(test11).push(test12)
  53.                  *  .execute()  // test1.1 test1.2
  54.                  *  .execute(); // test1.1 test1.2
  55.                  *
  56.                  * // run-once queue
  57.                  * var baz = new $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(true);
  58.                  * baz.push(test11).push(test12)
  59.                  *  .execute()  // test1.1 test1.2
  60.                  *  .execute(); // nothing
  61.                  */
  62.                 __QUEUE__ : function(runonce)
  63.                 {
  64.                     var __queue = new Array();
  65.                     var __runonce = ((runonce !== true) ? false : true);
  66.                    
  67.                     /**
  68.                      * add function to queue
  69.                      *
  70.                      * @param fn function
  71.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__();
  72.                      */
  73.                     this.push = function(fn)
  74.                     {
  75.                         __queue.push(fn);
  76.                         return this;
  77.                     }
  78.                    
  79.                     /**
  80.                      * execute queue
  81.                      *
  82.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__();
  83.                      */
  84.                     this.execute = function()
  85.                     {
  86.                         if(__queue.length === 0)
  87.                         {
  88.                             alert('No queue');
  89.                             return this;
  90.                         }
  91.                        
  92.                         if(__runonce === false)
  93.                             for(i in __queue) __queue[i]();
  94.                         else
  95.                             while(__queue.length > 0) (__queue.shift())();
  96.                            
  97.                         return this;
  98.                     }
  99.                    
  100.                     /**
  101.                      * terminate queue
  102.                      *
  103.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__();
  104.                      */
  105.                     this.reset = function()
  106.                     {
  107.                         __queue = new Array();
  108.                         return this;
  109.                     }
  110.                 },
  111.                 /**
  112.                  * method queue registry
  113.                  *
  114.                  * // some stuff
  115.                  * var test11 = function(){alert('test1.1')};
  116.                  * var test12 = function(){alert('test1.2')};
  117.                  * var test21 = function(){alert('test2.1')};
  118.                  * var test22 = function(){alert('test2.2')};
  119.                  *
  120.                  * // create registry queue
  121.                  * var foo = new $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__();
  122.                  *
  123.                  * // default queue
  124.                  * foo.register('test1').push('test1', test11).push('test1', test12)
  125.                  *  .execute('test1')   // test1.1 test1.2
  126.                  *  .execute('test1');  // test1.1 test1.2
  127.                  *
  128.                  * // run-once queue
  129.                  * foo.register('test2', true).push('test2', test11).push('test2', test12)
  130.                  *  .execute('test2')   // test1.1 test1.2
  131.                  *  .execute('test2');  // nothing
  132.                  *
  133.                  *
  134.                  * // shorthand:
  135.                  * // default queue
  136.                  * foo.get('test3').push(test21).push(test22)
  137.                  *  .execute()  // test2.1 test2.2
  138.                  *  .execute(); // test2.1 test2.2
  139.                  *
  140.                  * // run-once queue
  141.                  * foo.get('test4', true).push(test21).push(test22)
  142.                  *  .execute()  // test2.1 test2.2
  143.                  *  .execute(); // nothing
  144.                  *
  145.                  */
  146.                 __REGISTRY__ : function()
  147.                 {
  148.                     var __queue = new Object();
  149.                    
  150.                     /**
  151.                      * register queue instance
  152.                      *
  153.                      * @param name string instance-name
  154.                      * @param runonce bool
  155.                      * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__()
  156.                      * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.execute()
  157.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__();
  158.                      */
  159.                     this.register = function(name, runonce)
  160.                     {
  161.                         if(__queue[name])
  162.                             return this;
  163.                            
  164.                         __queue[name] = new $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__(runonce);
  165.                         return this;
  166.                     }
  167.                    
  168.                     /**
  169.                      * get/create queue instance
  170.                      *
  171.                      * @param name string instance-name
  172.                      * @param runonce bool
  173.                      * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__()
  174.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__();
  175.                      */
  176.                     this.get = function(name, runonce)
  177.                     {
  178.                         if(!__queue[name])
  179.                             this.register(name, runonce);
  180.                            
  181.                         return __queue[name];
  182.                     }
  183.                    
  184.                     /**
  185.                      * execute queue of instance
  186.                      *
  187.                      * @param name string instance-name
  188.                      * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.execute()
  189.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__();
  190.                      */
  191.                     this.execute = function(name)
  192.                     {
  193.                         if(!__queue[name])
  194.                             this.register(name);
  195.                            
  196.                         __queue[name].execute();
  197.                         return this;
  198.                     }
  199.                    
  200.                     /**
  201.                      * terminate queue
  202.                      *
  203.                      * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.reset()
  204.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__();
  205.                      */
  206.                     this.reset = function(name)
  207.                     {
  208.                         if(!__queue[name])
  209.                             return this;
  210.                         __queue[name].reset(); 
  211.                         return this;
  212.                     }
  213.                    
  214.                     /**
  215.                      * add function to queue of instance
  216.                      *
  217.                      * @param name string instance-name
  218.                      * @param fn function
  219.                      * @see $.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.push()
  220.                      * @return $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__();
  221.                      */
  222.                     this.push = function(name, fn)
  223.                     {
  224.                         if(!__queue[name])
  225.                             return this;
  226.                            
  227.                         __queue[name].push(fn, callback);
  228.                         return this;
  229.                     }
  230.                 }
  231.             },
  232.             __VARIABLE__ :
  233.             {
  234.                 /**
  235.                  * value for value-queue
  236.                  *
  237.                  * overwrite is allowed or not
  238.                  *
  239.                  * @param value mixed
  240.                  * @param protect bool true: can not overwrite existing value
  241.                  */
  242.                 __VALUE__ : function(value, protect)
  243.                 {
  244.                     var __value = value || null;
  245.                     var __protect = (protect === true) ? true : false;
  246.                     this.get = function(){ return __value; }
  247.                     this.set = function(value){ if(__protect === true) return this; __value = value; return this; }
  248.                 },
  249.                 /**
  250.                  * value-queue
  251.                  *
  252.                  * store vars with values
  253.                  *
  254.                  * // new value-queue
  255.                  * var foo = new $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  256.                  *
  257.                  * // var "baz"
  258.                  * foo.register('baz', 'baz: bar'); alert(foo.get('baz')); // baz: bar
  259.                  * foo.set('baz', 'baz: bar -> foo'); alert(foo.get('baz')); // baz: foo
  260.                  *
  261.                  * // protected var "foo"
  262.                  * foo.register('foo', 'foo: lol', true); alert(foo.get('foo')); // foo: lol
  263.                  * foo.set('foo', 'foo: lol -> rofl'); alert(foo.get('foo')); // foo: lol
  264.                  */
  265.                 __REGISTRY__ : function()
  266.                 {
  267.                     var __queue = new Object();
  268.                    
  269.                     /**
  270.                      * register value-instance
  271.                      *
  272.                      * @param name string instance-name
  273.                      * @param value mixed
  274.                      * @param protect bool true: can not overwrite existing value
  275.                      * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.register();
  276.                      * @return $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  277.                      */
  278.                     this.register = function(name, value, protect)
  279.                     {
  280.                         if(__queue[name])
  281.                             return this;
  282.                            
  283.                         __queue[name] = new $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__(value, protect);
  284.                         return this;
  285.                     }
  286.                    
  287.                     /**
  288.                      * get value of instance
  289.                      *
  290.                      * @param name string instance-name
  291.                      * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.get();
  292.                      * @return mixed $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.get();
  293.                      */
  294.                     this.get = function(name)
  295.                     {
  296.                         if(!__queue[name])
  297.                             return NULL;
  298.                            
  299.                         return __queue[name].get();
  300.                     }
  301.                    
  302.                     /**
  303.                      * set value of instance
  304.                      *
  305.                      * @param name string instance-name
  306.                      * @param value mixed
  307.                      * @see $.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.set();
  308.                      * @return $.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  309.                      */
  310.                     this.set = function(name, value)
  311.                     {
  312.                         if(!__queue[name])
  313.                             return this;
  314.                            
  315.                         __queue[name].set(value);
  316.                         return this;
  317.                     }
  318.                    
  319.                 }
  320.             }
  321.         }
  322.     }
  323.        
  324.     $.fn.xtcmApp = function(SETTINGS)
  325.     {
  326.        
  327.         var initProto = function()
  328.         {
  329.             $.extend($.xtcmApp.global.__CLASS__.__METHOD__.__QUEUE__.prototype,         $.xtcmApp.global.__SUPER__.__METHOD__.__QUEUE__);
  330.             $.extend($.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__.prototype,      $.xtcmApp.global.__SUPER__.__METHOD__.__REGISTRY__);
  331.             $.extend($.xtcmApp.global.__CLASS__.__VARIABLE__.__VALUE__.prototype,       $.xtcmApp.global.__SUPER__.__VARIABLE__.__VALUE__);
  332.             $.extend($.xtcmApp.global.__CLASS__.__VARIABLE__.__REGISTRY__.prototype,    $.xtcmApp.global.__SUPER__.__VARIABLE__.__REGISTRY__);
  333.         };
  334.        
  335.         var test =
  336.         {
  337.             variable : function()
  338.             {
  339.                 var test11 = function(){alert('test1.1')};
  340.                 var test12 = function(){alert('test1.2')};
  341.                 var test21 = function(){alert('test2.1')};
  342.                 var test22 = function(){alert('test2.2')};
  343.                
  344.                 var foo = new $.xtcmApp.global.__CLASS__.__METHOD__.__REGISTRY__();
  345.                 foo.get('test3').push(test11).push(test12)
  346.                     .execute()  // test2.1 test2.2
  347.                     .execute(); // test2.1 test2.2
  348.                    
  349.                 foo.get('test4', true).push(test21).push(test22)
  350.                     .execute()  // test2.1 test2.2
  351.                     .execute(); // nothing
  352.             }
  353.         };
  354.        
  355.         $.xtcmApp.initialize = function()
  356.         {
  357.             test.variable();
  358.         };
  359.        
  360.        
  361.         $.xtcmApp.initialize();
  362.     };
  363.    
  364.    
  365. })( jQuery );
  366.  
  367.  
  368. jQuery(document).ready(function($)
  369. {
  370.     $('body').xtcmApp();
  371. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement