Sha256: 3068725b85a3ac016bd902bfebe5331c48ed2c39add80df7631f99b1d98811e2

Contents?: true

Size: 1.75 KB

Versions: 39

Compression:

Stored size: 1.75 KB

Contents

/*!
 * eventie v1.0.6
 * event binding helper
 *   eventie.bind( elem, 'click', myFn )
 *   eventie.unbind( elem, 'click', myFn )
 * MIT license
 */

/*jshint browser: true, undef: true, unused: true */
/*global define: false, module: false */

( function( window ) {

'use strict';

var docElem = document.documentElement;

var bind = function() {};

function getIEEvent( obj ) {
  var event = window.event;
  // add event.target
  event.target = event.target || event.srcElement || obj;
  return event;
}

if ( docElem.addEventListener ) {
  bind = function( obj, type, fn ) {
    obj.addEventListener( type, fn, false );
  };
} else if ( docElem.attachEvent ) {
  bind = function( obj, type, fn ) {
    obj[ type + fn ] = fn.handleEvent ?
      function() {
        var event = getIEEvent( obj );
        fn.handleEvent.call( fn, event );
      } :
      function() {
        var event = getIEEvent( obj );
        fn.call( obj, event );
      };
    obj.attachEvent( "on" + type, obj[ type + fn ] );
  };
}

var unbind = function() {};

if ( docElem.removeEventListener ) {
  unbind = function( obj, type, fn ) {
    obj.removeEventListener( type, fn, false );
  };
} else if ( docElem.detachEvent ) {
  unbind = function( obj, type, fn ) {
    obj.detachEvent( "on" + type, obj[ type + fn ] );
    try {
      delete obj[ type + fn ];
    } catch ( err ) {
      // can't delete window object properties
      obj[ type + fn ] = undefined;
    }
  };
}

var eventie = {
  bind: bind,
  unbind: unbind
};

// ----- module definition ----- //

if ( typeof define === 'function' && define.amd ) {
  // AMD
  define( eventie );
} else if ( typeof exports === 'object' ) {
  // CommonJS
  module.exports = eventie;
} else {
  // browser global
  window.eventie = eventie;
}

})( window );

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wbase-0.3.20 lib/vendor/admin/eventie/eventie.js
wbase-0.3.19 lib/vendor/admin/eventie/eventie.js
wbase-0.3.18 lib/vendor/admin/eventie/eventie.js
wbase-0.3.17 lib/vendor/admin/eventie/eventie.js
wbase-0.3.16 lib/vendor/admin/eventie/eventie.js
wbase-0.3.15 lib/vendor/admin/eventie/eventie.js
wbase-0.3.14 lib/vendor/admin/eventie/eventie.js
wbase-0.3.13 lib/vendor/admin/eventie/eventie.js
wbase-0.3.12 lib/vendor/admin/eventie/eventie.js
wbase-0.3.11 lib/vendor/admin/eventie/eventie.js
wbase-0.3.10 lib/vendor/admin/eventie/eventie.js
wbase-0.3.9 lib/vendor/admin/eventie/eventie.js
wbase-0.3.8 lib/vendor/admin/eventie/eventie.js
wbase-0.3.7 lib/vendor/admin/eventie/eventie.js
wbase-0.3.6 lib/vendor/admin/eventie/eventie.js
wbase-0.3.5 lib/vendor/admin/eventie/eventie.js
wbase-0.3.4 lib/vendor/admin/eventie/eventie.js
wbase-0.3.3 lib/vendor/admin/eventie/eventie.js
wbase-0.3.2 lib/vendor/admin/eventie/eventie.js
wbase-0.3.1 lib/vendor/admin/eventie/eventie.js