pax_global_header00006660000000000000000000000064126726310320014514gustar00rootroot0000000000000052 comment=5b838a23410b9ed0eb1b74bc3a266c1af204b8f2 yaeti-0.0.6/000077500000000000000000000000001267263103200126325ustar00rootroot00000000000000yaeti-0.0.6/.gitignore000066400000000000000000000000171267263103200146200ustar00rootroot00000000000000/node_modules/ yaeti-0.0.6/.jscsrc000066400000000000000000000001761267263103200141260ustar00rootroot00000000000000{ "preset": "crockford", "validateIndentation": "\t", "disallowKeywords": ["with"], "disallowDanglingUnderscores": null } yaeti-0.0.6/.jshintrc000066400000000000000000000007001267263103200144540ustar00rootroot00000000000000{ "bitwise": false, "curly": true, "eqeqeq": true, "forin": true, "freeze": true, "latedef": "function", "noarg": true, "nonbsp": true, "nonew": true, "plusplus": false, "undef": true, "unused": true, "strict": false, "maxparams": 6, "maxdepth": 4, "maxstatements": false, "maxlen": 200, "browser": true, "browserify": true, "devel": true, "jquery": false, "mocha": true, "node": false, "shelljs": false, "worker": false } yaeti-0.0.6/LICENSE000066400000000000000000000021171267263103200136400ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Iñaki Baz Castillo, Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. yaeti-0.0.6/README.md000066400000000000000000000036651267263103200141230ustar00rootroot00000000000000# yaeti Yet Another [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) Implementation. The library exposes both the [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) interface and the [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) interface. ## Installation ```bash $ npm install yaeti --save ``` ## Usage ```javascript var yaeti = require('yaeti'); // Custom class we want to make an EventTarget. function Foo() { // Make Foo an EventTarget. yaeti.EventTarget.call(this); } // Create an instance. var foo = new Foo(); function listener1() { console.log('listener1'); } function listener2() { console.log('listener2'); } foo.addEventListener('bar', listener1); foo.addEventListener('bar', listener2); foo.removeEventListener('bar', listener1); var event = new yaeti.Event('bar'); foo.dispatchEvent(event); // Output: // => "listener2" ``` ## API #### `yaeti.EventTarget` interface Implementation of the [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) interface. * Make a custom class inherit from `EventTarget`: ```javascript function Foo() { yaeti.EventTarget.call(this); } ``` * Make an existing object an `EventTarget`: ```javascript yaeti.EventTarget.call(obj); ``` The interface implements the `addEventListener`, `removeEventListener` and `dispatchEvent` methods as defined by the W3C. ##### `listeners` read-only property Returns an object whose keys are configured event types (String) and whose values are an array of listeners (functions) for those event types. #### `yaeti.Event` interface Implementation of the [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) interface. *NOTE:* Just useful in Node (the browser already exposes the native `Event` interface). ```javascript var event = new yaeti.Event('bar'); ``` ## Author [Iñaki Baz Castillo](https://github.com/ibc) ## License [MIT](./LICENSE) yaeti-0.0.6/gulpfile.js000066400000000000000000000010631267263103200147770ustar00rootroot00000000000000var /** * Dependencies. */ gulp = require('gulp'), jscs = require('gulp-jscs'), jshint = require('gulp-jshint'), stylish = require('gulp-jscs-stylish'); gulp.task('lint', function () { var src = ['gulpfile.js', 'index.js', 'lib/**/*.js']; return gulp.src(src) .pipe(jshint('.jshintrc')) // Enforce good practics. .pipe(jscs('.jscsrc')) // Enforce style guide. .pipe(stylish.combineWithHintResults()) .pipe(jshint.reporter('jshint-stylish', {verbose: true})) .pipe(jshint.reporter('fail')); }); gulp.task('default', gulp.task('lint')); yaeti-0.0.6/index.js000066400000000000000000000001511267263103200142740ustar00rootroot00000000000000module.exports = { EventTarget : require('./lib/EventTarget'), Event : require('./lib/Event') }; yaeti-0.0.6/lib/000077500000000000000000000000001267263103200134005ustar00rootroot00000000000000yaeti-0.0.6/lib/Event.browser.js000066400000000000000000000001321267263103200164750ustar00rootroot00000000000000/** * In browsers export the native Event interface. */ module.exports = global.Event; yaeti-0.0.6/lib/Event.js000066400000000000000000000003231267263103200150150ustar00rootroot00000000000000/** * Expose the Event class. */ module.exports = _Event; function _Event(type) { this.type = type; this.isTrusted = false; // Set a flag indicating this is not a DOM Event object this._yaeti = true; } yaeti-0.0.6/lib/EventTarget.js000066400000000000000000000043671267263103200162000ustar00rootroot00000000000000/** * Expose the _EventTarget class. */ module.exports = _EventTarget; function _EventTarget() { // Do nothing if called for a native EventTarget object.. if (typeof this.addEventListener === 'function') { return; } this._listeners = {}; this.addEventListener = _addEventListener; this.removeEventListener = _removeEventListener; this.dispatchEvent = _dispatchEvent; } Object.defineProperties(_EventTarget.prototype, { listeners: { get: function () { return this._listeners; } } }); function _addEventListener(type, newListener) { var listenersType, i, listener; if (!type || !newListener) { return; } listenersType = this._listeners[type]; if (listenersType === undefined) { this._listeners[type] = listenersType = []; } for (i = 0; !!(listener = listenersType[i]); i++) { if (listener === newListener) { return; } } listenersType.push(newListener); } function _removeEventListener(type, oldListener) { var listenersType, i, listener; if (!type || !oldListener) { return; } listenersType = this._listeners[type]; if (listenersType === undefined) { return; } for (i = 0; !!(listener = listenersType[i]); i++) { if (listener === oldListener) { listenersType.splice(i, 1); break; } } if (listenersType.length === 0) { delete this._listeners[type]; } } function _dispatchEvent(event) { var type, listenersType, dummyListener, stopImmediatePropagation = false, i, listener; if (!event || typeof event.type !== 'string') { throw new Error('`event` must have a valid `type` property'); } // Do some stuff to emulate DOM Event behavior (just if this is not a // DOM Event object) if (event._yaeti) { event.target = this; event.cancelable = true; } // Attempt to override the stopImmediatePropagation() method try { event.stopImmediatePropagation = function () { stopImmediatePropagation = true; }; } catch (error) {} type = event.type; listenersType = (this._listeners[type] || []); dummyListener = this['on' + type]; if (typeof dummyListener === 'function') { dummyListener.call(this, event); } for (i = 0; !!(listener = listenersType[i]); i++) { if (stopImmediatePropagation) { break; } listener.call(this, event); } return !event.defaultPrevented; } yaeti-0.0.6/package.json000066400000000000000000000011341267263103200151170ustar00rootroot00000000000000{ "name": "yaeti", "version": "0.0.6", "description": "Yet Another EventTarget Implementation", "author": "Iñaki Baz Castillo ", "license": "MIT", "main": "index.js", "browser": { "./lib/Event.js": "./lib/Event.browser.js" }, "repository": { "type": "git", "url": "https://github.com/ibc/yaeti.git" }, "devDependencies": { "gulp": "git+https://github.com/gulpjs/gulp.git#4.0", "gulp-jscs": "^1.6.0", "gulp-jscs-stylish": "^1.1.0", "gulp-jshint": "^1.11.2", "jshint-stylish": "~1.0.2" }, "engines": { "node": ">=0.10.32" } }