08-27-周三_17-09-29
This commit is contained in:
22
node_modules/good-listener/.editorconfig
generated
vendored
Normal file
22
node_modules/good-listener/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
# Change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package.json,bower.json}]
|
||||
indent_size = 2
|
1
node_modules/good-listener/.npmignore
generated
vendored
Normal file
1
node_modules/good-listener/.npmignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
3
node_modules/good-listener/.travis.yml
generated
vendored
Normal file
3
node_modules/good-listener/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
11
node_modules/good-listener/bower.json
generated
vendored
Normal file
11
node_modules/good-listener/bower.json
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "good-listener",
|
||||
"description": "A more versatile way of adding & removing event listeners",
|
||||
"version": "1.2.1",
|
||||
"license": "MIT",
|
||||
"main": "dist/good-listener.js",
|
||||
"keywords": [
|
||||
"event",
|
||||
"listener"
|
||||
]
|
||||
}
|
25
node_modules/good-listener/demo/destroy.html
generated
vendored
Normal file
25
node_modules/good-listener/demo/destroy.html
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Destroy</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Write some markup -->
|
||||
<button class="target">Click me</button>
|
||||
<button class="target">Click me</button>
|
||||
<button class="target">Click me</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/good-listener.js"></script>
|
||||
|
||||
<!-- 3. Remove listener by calling the destroy function -->
|
||||
<script>
|
||||
var listener = listen('.target', 'click', function(e) {
|
||||
console.info(e);
|
||||
});
|
||||
|
||||
listener.destroy();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
30
node_modules/good-listener/demo/multiple.html
generated
vendored
Normal file
30
node_modules/good-listener/demo/multiple.html
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Selector</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Write some markup -->
|
||||
<button data-a>Click me</button>
|
||||
<button data-a>Click me</button>
|
||||
<button data-a>Click me</button>
|
||||
<button data-b>Click me</button>
|
||||
<button data-b>Click me</button>
|
||||
<button data-b>Click me</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/good-listener.js"></script>
|
||||
|
||||
<!-- 3. Add listener by passing a string selector -->
|
||||
<script>
|
||||
listen('[data-a]', 'click', function(e) {
|
||||
console.info(e);
|
||||
});
|
||||
|
||||
listen('[data-b]', 'click', function(e) {
|
||||
console.info(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
23
node_modules/good-listener/demo/node.html
generated
vendored
Normal file
23
node_modules/good-listener/demo/node.html
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Node</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Write some markup -->
|
||||
<button id="target">Click me</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/good-listener.js"></script>
|
||||
|
||||
<!-- 3. Add listener by passing a HTML element -->
|
||||
<script>
|
||||
var target = document.getElementById('target');
|
||||
|
||||
listen(target, 'click', function(e) {
|
||||
console.info(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
25
node_modules/good-listener/demo/nodelist.html
generated
vendored
Normal file
25
node_modules/good-listener/demo/nodelist.html
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>NodeList</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Write some markup -->
|
||||
<button>Click me</button>
|
||||
<button>Click me</button>
|
||||
<button>Click me</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/good-listener.js"></script>
|
||||
|
||||
<!-- 3. Add listener by passing a list of HTML elements -->
|
||||
<script>
|
||||
var targets = document.querySelectorAll('button');
|
||||
|
||||
listen(targets, 'click', function(e) {
|
||||
console.info(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
23
node_modules/good-listener/demo/selector.html
generated
vendored
Normal file
23
node_modules/good-listener/demo/selector.html
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Selector</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Write some markup -->
|
||||
<button class="target">Click me</button>
|
||||
<button class="target">Click me</button>
|
||||
<button class="target">Click me</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/good-listener.js"></script>
|
||||
|
||||
<!-- 3. Add listener by passing a string selector -->
|
||||
<script>
|
||||
listen('.target', 'click', function(e) {
|
||||
console.info(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
228
node_modules/good-listener/dist/good-listener.js
generated
vendored
Normal file
228
node_modules/good-listener/dist/good-listener.js
generated
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.listen = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
var DOCUMENT_NODE_TYPE = 9;
|
||||
|
||||
/**
|
||||
* A polyfill for Element.matches()
|
||||
*/
|
||||
if (typeof Element !== 'undefined' && !Element.prototype.matches) {
|
||||
var proto = Element.prototype;
|
||||
|
||||
proto.matches = proto.matchesSelector ||
|
||||
proto.mozMatchesSelector ||
|
||||
proto.msMatchesSelector ||
|
||||
proto.oMatchesSelector ||
|
||||
proto.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the closest parent that matches a selector.
|
||||
*
|
||||
* @param {Element} element
|
||||
* @param {String} selector
|
||||
* @return {Function}
|
||||
*/
|
||||
function closest (element, selector) {
|
||||
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
|
||||
if (element.matches(selector)) return element;
|
||||
element = element.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = closest;
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
var closest = require('./closest');
|
||||
|
||||
/**
|
||||
* Delegates event to a selector.
|
||||
*
|
||||
* @param {Element} element
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @param {Boolean} useCapture
|
||||
* @return {Object}
|
||||
*/
|
||||
function delegate(element, selector, type, callback, useCapture) {
|
||||
var listenerFn = listener.apply(this, arguments);
|
||||
|
||||
element.addEventListener(type, listenerFn, useCapture);
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
element.removeEventListener(type, listenerFn, useCapture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds closest match and invokes callback.
|
||||
*
|
||||
* @param {Element} element
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Function}
|
||||
*/
|
||||
function listener(element, selector, type, callback) {
|
||||
return function(e) {
|
||||
e.delegateTarget = closest(e.target, selector);
|
||||
|
||||
if (e.delegateTarget) {
|
||||
callback.call(element, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = delegate;
|
||||
|
||||
},{"./closest":1}],3:[function(require,module,exports){
|
||||
/**
|
||||
* Check if argument is a HTML element.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.node = function(value) {
|
||||
return value !== undefined
|
||||
&& value instanceof HTMLElement
|
||||
&& value.nodeType === 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a list of HTML elements.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.nodeList = function(value) {
|
||||
var type = Object.prototype.toString.call(value);
|
||||
|
||||
return value !== undefined
|
||||
&& (type === '[object NodeList]' || type === '[object HTMLCollection]')
|
||||
&& ('length' in value)
|
||||
&& (value.length === 0 || exports.node(value[0]));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a string.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.string = function(value) {
|
||||
return typeof value === 'string'
|
||||
|| value instanceof String;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a function.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.fn = function(value) {
|
||||
var type = Object.prototype.toString.call(value);
|
||||
|
||||
return type === '[object Function]';
|
||||
};
|
||||
|
||||
},{}],4:[function(require,module,exports){
|
||||
var is = require('./is');
|
||||
var delegate = require('delegate');
|
||||
|
||||
/**
|
||||
* Validates all params and calls the right
|
||||
* listener function based on its target type.
|
||||
*
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} target
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listen(target, type, callback) {
|
||||
if (!target && !type && !callback) {
|
||||
throw new Error('Missing required arguments');
|
||||
}
|
||||
|
||||
if (!is.string(type)) {
|
||||
throw new TypeError('Second argument must be a String');
|
||||
}
|
||||
|
||||
if (!is.fn(callback)) {
|
||||
throw new TypeError('Third argument must be a Function');
|
||||
}
|
||||
|
||||
if (is.node(target)) {
|
||||
return listenNode(target, type, callback);
|
||||
}
|
||||
else if (is.nodeList(target)) {
|
||||
return listenNodeList(target, type, callback);
|
||||
}
|
||||
else if (is.string(target)) {
|
||||
return listenSelector(target, type, callback);
|
||||
}
|
||||
else {
|
||||
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event listener to a HTML element
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {HTMLElement} node
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenNode(node, type, callback) {
|
||||
node.addEventListener(type, callback);
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
node.removeEventListener(type, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener to a list of HTML elements
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {NodeList|HTMLCollection} nodeList
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenNodeList(nodeList, type, callback) {
|
||||
Array.prototype.forEach.call(nodeList, function(node) {
|
||||
node.addEventListener(type, callback);
|
||||
});
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
Array.prototype.forEach.call(nodeList, function(node) {
|
||||
node.removeEventListener(type, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener to a selector
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenSelector(selector, type, callback) {
|
||||
return delegate(document.body, selector, type, callback);
|
||||
}
|
||||
|
||||
module.exports = listen;
|
||||
|
||||
},{"./is":3,"delegate":2}]},{},[4])(4)
|
||||
});
|
24
node_modules/good-listener/karma.conf.js
generated
vendored
Normal file
24
node_modules/good-listener/karma.conf.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
module.exports = function(karma) {
|
||||
karma.set({
|
||||
plugins: ['karma-browserify', 'karma-chai', 'karma-sinon', 'karma-mocha', 'karma-phantomjs-launcher'],
|
||||
|
||||
frameworks: ['browserify', 'chai', 'sinon', 'mocha'],
|
||||
|
||||
files: [
|
||||
'src/**/*.js',
|
||||
'test/**/*.js',
|
||||
'./node_modules/phantomjs-polyfill/bind-polyfill.js'
|
||||
],
|
||||
|
||||
preprocessors: {
|
||||
'src/**/*.js' : ['browserify'],
|
||||
'test/**/*.js': ['browserify']
|
||||
},
|
||||
|
||||
browserify: {
|
||||
debug: true
|
||||
},
|
||||
|
||||
browsers: ['PhantomJS']
|
||||
});
|
||||
}
|
101
node_modules/good-listener/package.json
generated
vendored
Normal file
101
node_modules/good-listener/package.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "good-listener",
|
||||
"raw": "good-listener@^1.2.2",
|
||||
"rawSpec": "^1.2.2",
|
||||
"scope": null,
|
||||
"spec": ">=1.2.2 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\clipboard"
|
||||
]
|
||||
],
|
||||
"_from": "good-listener@>=1.2.2 <2.0.0",
|
||||
"_id": "good-listener@1.2.2",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/good-listener",
|
||||
"_nodeVersion": "7.5.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-18-east.internal.npmjs.com",
|
||||
"tmp": "tmp/good-listener-1.2.2.tgz_1488304564488_0.39132829662412405"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "zno.rocha@gmail.com",
|
||||
"name": "zenorocha"
|
||||
},
|
||||
"_npmVersion": "4.1.2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "good-listener",
|
||||
"raw": "good-listener@^1.2.2",
|
||||
"rawSpec": "^1.2.2",
|
||||
"scope": null,
|
||||
"spec": ">=1.2.2 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/clipboard"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz",
|
||||
"_shasum": "d53b30cdf9313dffb7dc9a0d477096aa6d145c50",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "good-listener@^1.2.2",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\clipboard",
|
||||
"bugs": {
|
||||
"url": "https://github.com/zenorocha/good-listener/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"delegate": "^3.1.2"
|
||||
},
|
||||
"description": "A more versatile way of adding & removing event listeners",
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.0",
|
||||
"chai": "^3.5.0",
|
||||
"karma": "^1.3.0",
|
||||
"karma-browserify": "^5.0.1",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-mocha": "^1.2.0",
|
||||
"karma-phantomjs-launcher": "^1.0.0",
|
||||
"karma-sinon": "^1.0.4",
|
||||
"mocha": "^3.1.2",
|
||||
"phantomjs-polyfill": "0.0.2",
|
||||
"phantomjs-prebuilt": "^2.1.3",
|
||||
"simulant": "^0.2.2",
|
||||
"sinon": "^1.17.3",
|
||||
"watchify": "^3.7.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "d53b30cdf9313dffb7dc9a0d477096aa6d145c50",
|
||||
"tarball": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz"
|
||||
},
|
||||
"gitHead": "74ff6376e7f0b7c5c8d7e4b228fcbf9189f0d21d",
|
||||
"homepage": "https://github.com/zenorocha/good-listener#readme",
|
||||
"keywords": [
|
||||
"event",
|
||||
"listener"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "src/listen.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "zno.rocha@gmail.com",
|
||||
"name": "zenorocha"
|
||||
}
|
||||
],
|
||||
"name": "good-listener",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zenorocha/good-listener.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "browserify src/listen.js -s listen -o dist/good-listener.js",
|
||||
"test": "karma start --single-run"
|
||||
},
|
||||
"version": "1.2.2"
|
||||
}
|
91
node_modules/good-listener/readme.md
generated
vendored
Normal file
91
node_modules/good-listener/readme.md
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
# good-listener
|
||||
|
||||
[](https://travis-ci.org/zenorocha/good-listener)
|
||||
|
||||
> A more versatile way of adding & removing event listeners.
|
||||
|
||||

|
||||
|
||||
## Install
|
||||
|
||||
You can get it on npm.
|
||||
|
||||
```
|
||||
npm install good-listener --save
|
||||
```
|
||||
|
||||
Or bower, too.
|
||||
|
||||
```
|
||||
bower install good-listener --save
|
||||
```
|
||||
|
||||
If you're not into package management, just [download a ZIP](https://github.com/zenorocha/good-listener/archive/master.zip) file.
|
||||
|
||||
## Setup
|
||||
|
||||
###### Node (Browserify)
|
||||
|
||||
```js
|
||||
var listen = require('good-listener');
|
||||
```
|
||||
|
||||
###### Browser (Standalone)
|
||||
|
||||
```html
|
||||
<script src="dist/good-listener.js"></script>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Add an event listener
|
||||
|
||||
By passing a string selector [(see full demo)](https://github.com/zenorocha/good-listener/blob/master/demo/selector.html).
|
||||
|
||||
```js
|
||||
listen('.btn', 'click', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
```
|
||||
|
||||
Or by passing a HTML element [(see full demo)](https://github.com/zenorocha/good-listener/blob/master/demo/node.html).
|
||||
|
||||
```js
|
||||
var logo = document.getElementById('logo');
|
||||
|
||||
listen(logo, 'click', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
```
|
||||
|
||||
Or by passing a list of HTML elements [(see full demo)](https://github.com/zenorocha/good-listener/blob/master/demo/nodelist.html).
|
||||
|
||||
```js
|
||||
var anchors = document.querySelectorAll('a');
|
||||
|
||||
listen(anchors, 'click', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
```
|
||||
|
||||
### Remove an event listener
|
||||
|
||||
By calling the `destroy` function that returned from previous operation [(see full demo)](https://github.com/zenorocha/good-listener/blob/master/demo/destroy.html).
|
||||
|
||||
```js
|
||||
var listener = listen('.btn', 'click', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
listener.destroy();
|
||||
```
|
||||
|
||||
## Browser Support
|
||||
|
||||
| <img src="https://clipboardjs.com/assets/images/chrome.png" width="48px" height="48px" alt="Chrome logo"> | <img src="https://clipboardjs.com/assets/images/edge.png" width="48px" height="48px" alt="Edge logo"> | <img src="https://clipboardjs.com/assets/images/firefox.png" width="48px" height="48px" alt="Firefox logo"> | <img src="https://clipboardjs.com/assets/images/ie.png" width="48px" height="48px" alt="Internet Explorer logo"> | <img src="https://clipboardjs.com/assets/images/opera.png" width="48px" height="48px" alt="Opera logo"> | <img src="https://clipboardjs.com/assets/images/safari.png" width="48px" height="48px" alt="Safari logo"> |
|
||||
|:---:|:---:|:---:|:---:|:---:|:---:|
|
||||
| Latest ✔ | Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | Latest ✔ |
|
||||
|
||||
## License
|
||||
|
||||
[MIT License](http://zenorocha.mit-license.org/) © Zeno Rocha
|
49
node_modules/good-listener/src/is.js
generated
vendored
Normal file
49
node_modules/good-listener/src/is.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Check if argument is a HTML element.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.node = function(value) {
|
||||
return value !== undefined
|
||||
&& value instanceof HTMLElement
|
||||
&& value.nodeType === 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a list of HTML elements.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.nodeList = function(value) {
|
||||
var type = Object.prototype.toString.call(value);
|
||||
|
||||
return value !== undefined
|
||||
&& (type === '[object NodeList]' || type === '[object HTMLCollection]')
|
||||
&& ('length' in value)
|
||||
&& (value.length === 0 || exports.node(value[0]));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a string.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.string = function(value) {
|
||||
return typeof value === 'string'
|
||||
|| value instanceof String;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a function.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.fn = function(value) {
|
||||
var type = Object.prototype.toString.call(value);
|
||||
|
||||
return type === '[object Function]';
|
||||
};
|
95
node_modules/good-listener/src/listen.js
generated
vendored
Normal file
95
node_modules/good-listener/src/listen.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
var is = require('./is');
|
||||
var delegate = require('delegate');
|
||||
|
||||
/**
|
||||
* Validates all params and calls the right
|
||||
* listener function based on its target type.
|
||||
*
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} target
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listen(target, type, callback) {
|
||||
if (!target && !type && !callback) {
|
||||
throw new Error('Missing required arguments');
|
||||
}
|
||||
|
||||
if (!is.string(type)) {
|
||||
throw new TypeError('Second argument must be a String');
|
||||
}
|
||||
|
||||
if (!is.fn(callback)) {
|
||||
throw new TypeError('Third argument must be a Function');
|
||||
}
|
||||
|
||||
if (is.node(target)) {
|
||||
return listenNode(target, type, callback);
|
||||
}
|
||||
else if (is.nodeList(target)) {
|
||||
return listenNodeList(target, type, callback);
|
||||
}
|
||||
else if (is.string(target)) {
|
||||
return listenSelector(target, type, callback);
|
||||
}
|
||||
else {
|
||||
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event listener to a HTML element
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {HTMLElement} node
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenNode(node, type, callback) {
|
||||
node.addEventListener(type, callback);
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
node.removeEventListener(type, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener to a list of HTML elements
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {NodeList|HTMLCollection} nodeList
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenNodeList(nodeList, type, callback) {
|
||||
Array.prototype.forEach.call(nodeList, function(node) {
|
||||
node.addEventListener(type, callback);
|
||||
});
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
Array.prototype.forEach.call(nodeList, function(node) {
|
||||
node.removeEventListener(type, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener to a selector
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenSelector(selector, type, callback) {
|
||||
return delegate(document.body, selector, type, callback);
|
||||
}
|
||||
|
||||
module.exports = listen;
|
111
node_modules/good-listener/test/is.js
generated
vendored
Normal file
111
node_modules/good-listener/test/is.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
var is = require('../src/is');
|
||||
|
||||
describe('is', function() {
|
||||
before(function() {
|
||||
global.node = document.createElement('div');
|
||||
global.node.setAttribute('id', 'foo');
|
||||
global.node.setAttribute('class', 'foo');
|
||||
document.body.appendChild(global.node);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('is.node', function() {
|
||||
it('should be considered as node', function() {
|
||||
assert.ok(is.node(document.getElementById('foo')));
|
||||
assert.ok(is.node(document.getElementsByTagName('div')[0]));
|
||||
assert.ok(is.node(document.getElementsByClassName('foo')[0]));
|
||||
assert.ok(is.node(document.querySelector('.foo')));
|
||||
});
|
||||
|
||||
it('should not be considered as node', function() {
|
||||
assert.notOk(is.node(undefined));
|
||||
assert.notOk(is.node(null));
|
||||
assert.notOk(is.node(false));
|
||||
assert.notOk(is.node(true));
|
||||
assert.notOk(is.node(function () {}));
|
||||
assert.notOk(is.node([]));
|
||||
assert.notOk(is.node({}));
|
||||
assert.notOk(is.node(/a/g));
|
||||
assert.notOk(is.node(new RegExp('a', 'g')));
|
||||
assert.notOk(is.node(new Date()));
|
||||
assert.notOk(is.node(42));
|
||||
assert.notOk(is.node(NaN));
|
||||
assert.notOk(is.node(Infinity));
|
||||
assert.notOk(is.node(new Number(42)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('is.nodeList', function() {
|
||||
it('should be considered as nodeList', function() {
|
||||
assert.ok(is.nodeList(document.getElementsByTagName('div')));
|
||||
assert.ok(is.nodeList(document.getElementsByClassName('foo')));
|
||||
assert.ok(is.nodeList(document.querySelectorAll('.foo')));
|
||||
});
|
||||
|
||||
it('should not be considered as nodeList', function() {
|
||||
assert.notOk(is.nodeList(undefined));
|
||||
assert.notOk(is.nodeList(null));
|
||||
assert.notOk(is.nodeList(false));
|
||||
assert.notOk(is.nodeList(true));
|
||||
assert.notOk(is.nodeList(function () {}));
|
||||
assert.notOk(is.nodeList([]));
|
||||
assert.notOk(is.nodeList({}));
|
||||
assert.notOk(is.nodeList(/a/g));
|
||||
assert.notOk(is.nodeList(new RegExp('a', 'g')));
|
||||
assert.notOk(is.nodeList(new Date()));
|
||||
assert.notOk(is.nodeList(42));
|
||||
assert.notOk(is.nodeList(NaN));
|
||||
assert.notOk(is.nodeList(Infinity));
|
||||
assert.notOk(is.nodeList(new Number(42)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('is.string', function() {
|
||||
it('should be considered as string', function() {
|
||||
assert.ok(is.string('abc'));
|
||||
assert.ok(is.string(new String('abc')));
|
||||
});
|
||||
|
||||
it('should not be considered as string', function() {
|
||||
assert.notOk(is.string(undefined));
|
||||
assert.notOk(is.string(null));
|
||||
assert.notOk(is.string(false));
|
||||
assert.notOk(is.string(true));
|
||||
assert.notOk(is.string(function () {}));
|
||||
assert.notOk(is.string([]));
|
||||
assert.notOk(is.string({}));
|
||||
assert.notOk(is.string(/a/g));
|
||||
assert.notOk(is.string(new RegExp('a', 'g')));
|
||||
assert.notOk(is.string(new Date()));
|
||||
assert.notOk(is.string(42));
|
||||
assert.notOk(is.string(NaN));
|
||||
assert.notOk(is.string(Infinity));
|
||||
assert.notOk(is.string(new Number(42)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('is.fn', function() {
|
||||
it('should be considered as function', function() {
|
||||
assert.ok(is.fn(function () {}));
|
||||
});
|
||||
|
||||
it('should not be considered as function', function() {
|
||||
assert.notOk(is.fn(undefined));
|
||||
assert.notOk(is.fn(null));
|
||||
assert.notOk(is.fn(false));
|
||||
assert.notOk(is.fn(true));
|
||||
assert.notOk(is.fn([]));
|
||||
assert.notOk(is.fn({}));
|
||||
assert.notOk(is.fn(/a/g));
|
||||
assert.notOk(is.fn(new RegExp('a', 'g')));
|
||||
assert.notOk(is.fn(new Date()));
|
||||
assert.notOk(is.fn(42));
|
||||
assert.notOk(is.fn(NaN));
|
||||
assert.notOk(is.fn(Infinity));
|
||||
assert.notOk(is.fn(new Number(42)));
|
||||
});
|
||||
});
|
||||
});
|
135
node_modules/good-listener/test/listen.js
generated
vendored
Normal file
135
node_modules/good-listener/test/listen.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
var listen = require('../src/listen');
|
||||
var simulant = require('simulant');
|
||||
|
||||
describe('good-listener', function() {
|
||||
before(function() {
|
||||
global.node = document.createElement('div');
|
||||
global.node.setAttribute('id', 'foo');
|
||||
global.node.setAttribute('class', 'foo');
|
||||
document.body.appendChild(global.node);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('listen', function() {
|
||||
it('should throw an error since arguments were not passed', function(done) {
|
||||
try {
|
||||
listen();
|
||||
}
|
||||
catch(error) {
|
||||
assert.equal(error.message, 'Missing required arguments');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error since "target" was invalid', function(done) {
|
||||
try {
|
||||
listen(null, 'click', function() {});
|
||||
}
|
||||
catch(error) {
|
||||
assert.equal(error.message, 'First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error since "type" was invalid', function(done) {
|
||||
try {
|
||||
listen('.btn', false, function() {});
|
||||
}
|
||||
catch(error) {
|
||||
assert.equal(error.message, 'Second argument must be a String');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error since "callback" was invalid', function(done) {
|
||||
try {
|
||||
listen('.btn', 'click', []);
|
||||
}
|
||||
catch(error) {
|
||||
assert.equal(error.message, 'Third argument must be a Function');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('listenNode', function() {
|
||||
before(function() {
|
||||
global.target = document.querySelector('#foo');
|
||||
global.spy = sinon.spy(global.target, 'removeEventListener');
|
||||
});
|
||||
|
||||
after(function() {
|
||||
global.spy.restore();
|
||||
});
|
||||
|
||||
it('should add an event listener', function(done) {
|
||||
listen(global.target, 'click', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
simulant.fire(global.target, simulant('click'));
|
||||
});
|
||||
|
||||
it('should remove an event listener', function() {
|
||||
var listener = listen(global.target, 'click', function() {});
|
||||
|
||||
listener.destroy();
|
||||
assert.ok(global.spy.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
describe('listenNodeList', function() {
|
||||
before(function() {
|
||||
global.targets = document.querySelectorAll('.foo');
|
||||
global.spy = sinon.spy(global.targets[0], 'removeEventListener');
|
||||
});
|
||||
|
||||
after(function() {
|
||||
global.spy.restore();
|
||||
});
|
||||
|
||||
it('should add an event listener', function(done) {
|
||||
listen(global.targets, 'click', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
simulant.fire(global.targets[0], simulant('click'));
|
||||
});
|
||||
|
||||
it('should remove an event listener', function() {
|
||||
var listener = listen(global.targets, 'click', function() {});
|
||||
|
||||
listener.destroy();
|
||||
assert.ok(global.spy.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
describe('listenSelector', function() {
|
||||
before(function() {
|
||||
global.target = document.querySelector('.foo');
|
||||
global.spy = sinon.spy(document.body, 'removeEventListener');
|
||||
});
|
||||
|
||||
after(function() {
|
||||
global.spy.restore();
|
||||
});
|
||||
|
||||
it('should add an event listener', function(done) {
|
||||
listen('.foo', 'click', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
simulant.fire(global.target, simulant('click'));
|
||||
});
|
||||
|
||||
it('should remove an event listener', function() {
|
||||
var listener = listen('.foo', 'click', function() {});
|
||||
|
||||
listener.destroy();
|
||||
assert.ok(global.spy.calledOnce);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user