Subversion Repositories HomeAutomation

Rev

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

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