[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/scripts/ -> events.js (source)

   1  /**
   2   * The event functions are no longer in use and a mere wrapper around
   3   * jQuery's event handlers.
   4   *
   5   * @deprecated
   6   */
   7  function addEvent(element, type, handler) {
   8      DEPRECATED('Use jQuery.bind() instead.');
   9      jQuery(element).bind(type,{},handler);
  10  }
  11  
  12  function removeEvent(element, type, handler) {
  13      DEPRECATED('Use jQuery.unbind() instead.');
  14      jQuery(element).unbind(type,handler);
  15  }
  16  
  17  function addInitEvent(func) {
  18      DEPRECATED('Use jQuery(<function>) instead');
  19      jQuery(func);
  20  }
  21  
  22  /**
  23   * Bind variables to a function call creating a closure
  24   *
  25   * Use this to circumvent variable scope problems when creating closures
  26   * inside a loop
  27   *
  28   * @author  Adrian Lang <lang@cosmocode.de>
  29   * @fixme   Is there a jQuery equivalent? Otherwise move to somewhere else
  30   * @link    http://www.cosmocode.de/en/blog/gohr/2009-10/15-javascript-fixing-the-closure-scope-in-loops
  31   * @param   functionref fnc - the function to be called
  32   * @param   mixed - any arguments to be passed to the function
  33   * @returns functionref
  34   */
  35  function bind(fnc/*, ... */) {
  36      var Aps = Array.prototype.slice;
  37      // Store passed arguments in this scope.
  38      // Since arguments is no Array nor has an own slice method,
  39      // we have to apply the slice method from the Array.prototype
  40      var static_args = Aps.call(arguments, 1);
  41  
  42      // Return a function evaluating the passed function with the
  43      // given args and optional arguments passed on invocation.
  44      return function (/* ... */) {
  45          // Same here, but we use Array.prototype.slice solely for
  46          // converting arguments to an Array.
  47          return fnc.apply(this,
  48                           static_args.concat(Aps.call(arguments, 0)));
  49      };
  50  }


Generated: Thu Aug 18 03:00:04 2011 Cross-referenced by PHPXref 0.7
WikiForumIRCBugsGitXRefTranslate