[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/prototype-1.4.0/src/ -> base.js (source)

   1  var Class = {
   2    create: function() {
   3      return function() { 
   4        this.initialize.apply(this, arguments);
   5      }
   6    }
   7  }
   8  
   9  var Abstract = new Object();
  10  
  11  Object.extend = function(destination, source) {
  12    for (property in source) {
  13      destination[property] = source[property];
  14    }
  15    return destination;
  16  }
  17  
  18  Object.inspect = function(object) {
  19    try {
  20      if (object == undefined) return 'undefined';
  21      if (object == null) return 'null';
  22      return object.inspect ? object.inspect() : object.toString();
  23    } catch (e) {
  24      if (e instanceof RangeError) return '...';
  25      throw e;
  26    }
  27  }
  28  
  29  Function.prototype.bind = function() {
  30    var __method = this, args = $A(arguments), object = args.shift();
  31    return function() {
  32      return __method.apply(object, args.concat($A(arguments)));
  33    }
  34  }
  35  
  36  Function.prototype.bindAsEventListener = function(object) {
  37    var __method = this;
  38    return function(event) {
  39      return __method.call(object, event || window.event);
  40    }
  41  }
  42  
  43  Object.extend(Number.prototype, {
  44    toColorPart: function() {
  45      var digits = this.toString(16);
  46      if (this < 16) return '0' + digits;
  47      return digits;
  48    },
  49  
  50    succ: function() {
  51      return this + 1;
  52    },
  53    
  54    times: function(iterator) {
  55      $R(0, this, true).each(iterator);
  56      return this;
  57    }
  58  });
  59  
  60  var Try = {
  61    these: function() {
  62      var returnValue;
  63  
  64      for (var i = 0; i < arguments.length; i++) {
  65        var lambda = arguments[i];
  66        try {
  67          returnValue = lambda();
  68          break;
  69        } catch (e) {}
  70      }
  71  
  72      return returnValue;
  73    }
  74  }
  75  
  76  /*--------------------------------------------------------------------------*/
  77  
  78  var PeriodicalExecuter = Class.create();
  79  PeriodicalExecuter.prototype = {
  80    initialize: function(callback, frequency) {
  81      this.callback = callback;
  82      this.frequency = frequency;
  83      this.currentlyExecuting = false;
  84  
  85      this.registerCallback();
  86    },
  87  
  88    registerCallback: function() {
  89      setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  90    },
  91  
  92    onTimerEvent: function() {
  93      if (!this.currentlyExecuting) {
  94        try { 
  95          this.currentlyExecuting = true;
  96          this.callback(); 
  97        } finally { 
  98          this.currentlyExecuting = false;
  99        }
 100      }
 101    }
 102  }
 103  
 104  /*--------------------------------------------------------------------------*/
 105  
 106  function $() {
 107    var elements = new Array();
 108  
 109    for (var i = 0; i < arguments.length; i++) {
 110      var element = arguments[i];
 111      if (typeof element == 'string')
 112        element = document.getElementById(element);
 113  
 114      if (arguments.length == 1) 
 115        return element;
 116  
 117      elements.push(element);
 118    }
 119  
 120    return elements;
 121  }


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7