Comparing version 0.7.0 to 0.8.0
Changelog | ||
========= | ||
### 0.8.0 (January 11, 2017) | ||
* Add stricter types and clarify default params | ||
### 0.7.0 (January 3, 2017) | ||
@@ -5,0 +9,0 @@ |
@@ -8,9 +8,8 @@ import matches from './matches'; | ||
* @param {string} selector The CSS selector to match against. | ||
* @param {boolean} shouldCheckSelf True if the selector should test against | ||
* @param {boolean=} shouldCheckSelf True if the selector should test against | ||
* the passed element itself. | ||
* @return {Element|undefined} The matching element or undefined. | ||
*/ | ||
export default function closest(element, selector, shouldCheckSelf) { | ||
export default function closest(element, selector, shouldCheckSelf = false) { | ||
if (!(element && element.nodeType == 1 && selector)) return; | ||
const parentElements = | ||
@@ -17,0 +16,0 @@ (shouldCheckSelf ? [element] : []).concat(parents(element)); |
@@ -7,7 +7,7 @@ import closest from './closest'; | ||
* ancestor of the matching element. | ||
* @param {Node} ancestor The ancestor element to add the listener to. | ||
* @param {!Node} ancestor The ancestor element to add the listener to. | ||
* @param {string} eventType The event type to listen to. | ||
* @param {string} selector A CSS selector to match against child elements. | ||
* @param {Function} callback A function to run any time the event happens. | ||
* @param {Object} opts A configuration options object. The available options: | ||
* @param {!Function} callback A function to run any time the event happens. | ||
* @param {Object=} opts A configuration options object. The available options: | ||
* - useCapture<boolean>: If true, bind to the event capture phase. | ||
@@ -18,5 +18,3 @@ * - deep<boolean>: If true, delegate into shadow trees. | ||
export default function delegate( | ||
ancestor, eventType, selector, callback, opts) { | ||
opts = opts || {}; | ||
ancestor, eventType, selector, callback, opts = {}) { | ||
// Defines the event listener. | ||
@@ -23,0 +21,0 @@ const listener = function(event) { |
/** | ||
* Dispatches an event on the passed element. | ||
* @param {Element} element The DOM element to dispatch the event on. | ||
* @param {!Element} element The DOM element to dispatch the event on. | ||
* @param {string} eventType The type of event to dispatch. | ||
* @param {string} eventName (optional) A string name of the event constructor | ||
* @param {Object|string=} eventName A string name of the event constructor | ||
* to use. Defaults to 'Event' if nothing is passed or 'CustomEvent' if | ||
* a value is set on `initDict.detail`. | ||
* @param {Object} initDict (optional) The initialization attributes for the | ||
* a value is set on `initDict.detail`. If eventName is given an object | ||
* it is assumed to be initDict and thus reassigned. | ||
* @param {Object=} initDict The initialization attributes for the | ||
* event. A `detail` property can be used here to pass custom data. | ||
@@ -13,3 +14,4 @@ * @return {boolean} The return value of `element.dispatchEvent`, which will | ||
*/ | ||
export default function dispatch(element, eventType, eventName, initDict) { | ||
export default function dispatch( | ||
element, eventType, eventName = 'Event', initDict = {}) { | ||
let event; | ||
@@ -21,6 +23,5 @@ let isCustom; | ||
initDict = eventName; | ||
eventName = null; | ||
eventName = 'Event'; | ||
} | ||
initDict = initDict || {}; | ||
initDict.bubbles = initDict.bubbles || false; | ||
@@ -32,3 +33,3 @@ initDict.cancelable = initDict.cancelable || false; | ||
if ('detail' in initDict) isCustom = true; | ||
eventName = isCustom ? 'CustomEvent' : eventName || 'Event'; | ||
eventName = isCustom ? 'CustomEvent' : eventName; | ||
@@ -35,0 +36,0 @@ // Tries to create the event using constructors, if that doesn't work, |
@@ -40,3 +40,3 @@ const proto = window.Element.prototype; | ||
* Element.prototype.matches method across browsers. | ||
* @param {Element} element The DOM element to test. | ||
* @param {!Element} element The DOM element to test. | ||
* @param {string} selector The CSS selector to test element against. | ||
@@ -43,0 +43,0 @@ * @return {boolean} True if the selector matches. |
/** | ||
* Returns an array of a DOM element's parent elements. | ||
* @param {Element} element The DOM element whose parents to get. | ||
* @return {Array} An array of all parent elemets, or an empty array if no | ||
* @param {!Element} element The DOM element whose parents to get. | ||
* @return {!Array} An array of all parent elemets, or an empty array if no | ||
* parent elements are found. | ||
@@ -6,0 +6,0 @@ */ |
@@ -13,3 +13,3 @@ const HTTP_PORT = '80'; | ||
* @param {string} url The url to parse. | ||
* @return {Object} An object with the same properties as a `Location` | ||
* @return {!Object} An object with the same properties as a `Location` | ||
* plus the convience properties `path` and `query`. | ||
@@ -16,0 +16,0 @@ */ |
{ | ||
"name": "dom-utils", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "A small, modular DOM utilities library", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32232