All Downloads are FREE. Search and download functionalities are using the official Maven repository.

polyfills.Event.meta.json Maven / Gradle / Ivy

The newest version!
{"aliases":["default-3.3","default-3.4","default-3.5","default-3.6","default"],"browsers":{"firefox":"6 - 10","ie":"6 - 11","ie_mob":"10","opera":"10 - 11.5","safari":"4 - 7","firefox_mob":"6 - 10"},"dependencies":["Window","Document","Element","Object.defineProperty"],"docs":"https://developer.mozilla.org/en/docs/Web/API/Event","notes":["Where necessary, also adds the [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) methods `addEventListener`, `removeEventListener` and `dispatchEvent`."],"detectSource":"(function(global) {\n\n\tif (!('Event' in global)) return false;\n\tif (typeof global.Event === 'function') return true;\n\n\ttry {\n\n\t\t// In IE 9-11, the Event object exists but cannot be instantiated\n\t\tnew Event('click');\n\t\treturn true;\n\t} catch(e) {\n\t\treturn false;\n\t}\n}(this))","testSource":"","baseDir":"Event","hasTests":true,"testsSource":"/* eslint-env mocha, browser*/\n/* global proclaim, it */\n\n// Safari fails this test.  However, no-one would ever do this\n// as it would just create an event that can never be dispatched/listened for\n// it doesn't cause any problem\nit.skip('should throw exception when instantiated with no parameters', function() {\n\tproclaim.throws(function() {\n\t\tnew Event();\n\t});\n});\n\nit('should have correct default properties', function() {\n\tvar testEvent = new Event('click');\n\tproclaim.equal(testEvent.type, 'click');\n\tproclaim.equal(testEvent.bubbles, false);\n\tproclaim.equal(testEvent.cancelable, false);\n});\n\nit('should modify default properties if optional EventInit parameter is passed', function() {\n\tvar testEvent = new Event('test', {\n\t\tbubbles: true,\n\t\tcancelable: true\n\t});\n\n\tproclaim.equal(testEvent.type, 'test');\n\tproclaim.equal(testEvent.bubbles, true);\n\tproclaim.equal(testEvent.cancelable, true);\n});\n\nit('should be able to fire an event that can be listened to', function(done) {\n\tvar testEvent = new Event('test', {\n\t\tbubbles: true,\n\t\tcancelable: true\n\t});\n\n\tvar testEl = document.createElement('div');\n\ttestEl.addEventListener('test', function(ev) {\n\t\tproclaim.equal(ev.type, 'test');\n\t\tproclaim.equal(ev.bubbles, true);\n\t\tproclaim.equal(ev.cancelable, true);\n\t\tdone();\n\t});\n\ttestEl.dispatchEvent(testEvent);\n});\n\nit('should bubble the event', function(done) {\n\tvar testEvent = new Event('test', {\n\t\tbubbles: true,\n\t\tcancelable: true\n\t});\n\n\tvar testEl = document.createElement('div');\n\tdocument.body.appendChild(testEl);\n\tdocument.body.addEventListener('test', function(ev) {\n\t\tproclaim.equal(ev.type, 'test');\n\t\tproclaim.equal(ev.bubbles, true);\n\t\tproclaim.equal(ev.cancelable, true);\n\t\tdone();\n\t});\n\ttestEl.dispatchEvent(testEvent);\n});\n\nit('should not trigger an event handler once removed', function() {\n\tvar testEvent = new Event('test', {\n\t\tbubbles: true,\n\t\tcancelable: true\n\t});\n\tvar listener = function() {\n\t\tthrow new Error('listener was fired, but should have been removed');\n\t};\n\n\tvar testEl = document.createElement('div');\n\ttestEl.addEventListener('test', listener);\n\ttestEl.removeEventListener('test', listener);\n\ttestEl.dispatchEvent(testEvent);\n});\n\nit('should trigger an event handler once added, removed, and added again', function () {\n\t// NOTE: The event must be a real DOM event or the\n\t// dispatchEvent polyfill will catch the fireEvent\n\t// error, simulate firing the event by running the\n\t// event listeners.\n\tvar fired = false;\n\tvar listener = function() {\n\t\tfired = true;\n\t\tdocument.removeEventListener('click', listener);\n\t};\n\n\tdocument.addEventListener('click', listener);\n\tdocument.removeEventListener('click', listener);\n\tdocument.addEventListener('click', listener);\n\t// click the document\n\tdocument.dispatchEvent(new Event('click'));\n\tproclaim.equal(fired, true);\n});\n\nit('should have the correct target when using delegation', function () {\n\tvar fired = false;\n\tvar el = document.body.firstChild;\n\tvar listener = function(e) {\n\t\tif (e.target === el) fired = true;\n\t\tdocument.removeEventListener('click', listener);\n\t};\n\n\tdocument.addEventListener('click', listener);\n\tel.dispatchEvent(new Event('click', {\n\t\tbubbles: true\n\t}));\n\tproclaim.equal(fired, true);\n});\n\nit('should successfully call window.addEventListener or throw exception', function() {\n\n\tvar eventsToTest = [\n\t\t'click',\n\t\t'dblclick',\n\t\t'keyup',\n\t\t'keypress',\n\t\t'keydown',\n\t\t'mousedown',\n\t\t'mouseup',\n\t\t'mousemove',\n\t\t'mouseover',\n\t\t'mouseenter',\n\t\t'mouseleave',\n\t\t'mouseout',\n\t\t'storage',\n\t\t'storagecommit',\n\t\t'textinput'\n\t];\n\n\tvar threwLast;\n\tvar threw;\n\tvar listener = function() {};\n\tfor(var i = 0; i < eventsToTest.length; i++) {\n\t\tvar eventType = eventsToTest[i];\n\t\ttry {\n\t\t\twindow.addEventListener(eventType, listener);\n\t\t\tthrew = false;\n\t\t} catch(ignore) {\n\t\t\tthrew = true;\n\t\t}\n\n\t\tif (typeof (threwLast) != 'undefined') {\n\t\t\tproclaim.equal(threw, threwLast);\n\t\t}\n\t\tthrewLast = threw;\n\t}\n});\n\nit('subclasses should be instances of Event if the UA implements DOM3', function () {\n\tvar a = document.createElement('a');\n\ta.addEventListener('click', function(ev) {\n\n\t\t// Supported in IE9+\n\t\tif ('MouseEvent' in window) {\n\t\t\tproclaim.isInstanceOf(ev, Event);\n\t\t}\n\t});\n\tdocument.body.appendChild(a);\n\ta.click();\n})"}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy