Subversion Repositories HomeAutomation

Rev

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