Subversion Repositories HomeAutomation

Rev

Rev 1619 | Rev 1644 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. var global_legacy = false;
  3.  
  4. LoadScript("common/json.js");
  5.  
  6. function Start(legacy)
  7. {
  8.     global_legacy = legacy;
  9.    
  10.     LoadScript("common/alias.js");
  11.     LoadScript("common/irrecord.js");
  12.    
  13.     if (global_legacy)
  14.     {
  15.         LoadScript("legacy/System/Base.js");
  16.         LoadScript("legacy/System/Startup.js");
  17.         LoadScript("legacy/Autostart.js");
  18.        
  19.         autostart();
  20.     }
  21.     else
  22.     {
  23.         LoadScript("user/autostart.js");
  24.     }
  25. }
  26.  
  27. function Extend(descendant, parent)
  28. {
  29.     var s_constructor = parent.toString();
  30.     var a_match = s_constructor.match(/\s*function (.*)\(/);
  31.    
  32.     if (a_match != null)
  33.     {
  34.         descendant.prototype[a_match[1]] = parent;
  35.     }
  36.    
  37.     for (var m in parent.prototype)
  38.     {
  39.         descendant.prototype[m] = parent.prototype[m];
  40.     }
  41. }
  42.  
  43. function ArrayContains(array, item)
  44. {
  45.     for (var n in array)
  46.     {
  47.         if (array[n] == item)
  48.         {
  49.             return true;
  50.         }
  51.     }
  52.    
  53.     return false;
  54. }
  55.  
  56. String.prototype.ltrim = function(charlist)
  57. {
  58.     charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
  59.     var re = new RegExp('^[' + charlist + ']+', 'g');
  60.     return this.replace(re, '');
  61. }
  62.  
  63. String.prototype.rtrim = function(charlist)
  64. {
  65.     charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
  66.     var re = new RegExp('[' + charlist + ']+$', 'g');
  67.     return this.replace(re, '');
  68. }
  69.  
  70. String.prototype.trim = function(charlist)
  71. {
  72.     var str = this.ltrim(charlist);
  73.     return str.rtrim(charlist);
  74. }
  75.  
  76. function EventBase()
  77. {
  78.     this.callbacks_ = new Array();
  79. }
  80.  
  81. EventBase.prototype.callbacks_ = null;
  82.  
  83. EventBase.prototype.Bind = function(event_name, callback)
  84. {
  85.     if (typeof this.callbacks_[event_name] == 'undefined')
  86.     {
  87.         this.callbacks_[event_name] = new Array();
  88.     }
  89.    
  90.     this.callbacks_[event_name].push(callback);
  91. }
  92.  
  93. EventBase.prototype.Trigger = function(event_name)
  94. {
  95.     if (typeof this.callbacks_[event_name] != 'undefined')
  96.     {
  97.         for (var n = 0; n < this.callbacks_[event_name].length; n++)
  98.         {
  99.             this.callbacks_[event_name][n].apply(null, Array.prototype.slice.call(arguments, 0));
  100.         }
  101.     }
  102. }
  103.