can-event-dom-radiochange
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,3 +5,2 @@ 'use strict'; | ||
var domEvents = require('can-dom-events'); | ||
var oldEvents = require('can-util/dom/events/events'); | ||
var definition = require('./can-event-dom-radiochange'); | ||
@@ -14,20 +13,2 @@ var compat = require('./compat'); | ||
// Fix oldEvent calls to match new syntax | ||
function newifyOldEvents (oldEvents) { | ||
return { | ||
addEventListener: function (target) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return oldEvents.addEventListener.apply(target, args); | ||
}, | ||
removeEventListener: function (target) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return oldEvents.removeEventListener.apply(target, args); | ||
}, | ||
dispatch: function (target) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return oldEvents.dispatch.apply(target, args); | ||
}, | ||
}; | ||
} | ||
var compatWithNew = { | ||
@@ -44,13 +25,2 @@ name: 'compat with can-dom-events', | ||
var compatWithOld = { | ||
name: 'compat with can-util/dom/events', | ||
domEvents: newifyOldEvents(oldEvents), | ||
setup: function () { | ||
this.removeEvent = compat(oldEvents); | ||
}, | ||
teardown: function () { | ||
this.removeEvent(); | ||
} | ||
}; | ||
var rawNewDomEvents = { | ||
@@ -68,3 +38,2 @@ name: 'plain with can-dom-events', | ||
var suites = [ | ||
compatWithOld, | ||
compatWithNew, | ||
@@ -71,0 +40,0 @@ rawNewDomEvents |
'use strict'; | ||
var events = require('can-util/dom/events/events'); | ||
var domData = require('can-util/dom/data/data'); | ||
var getDocument = require('can-util/dom/document/document'); | ||
var domData = require('can-dom-data-state'); | ||
var getDocument = require('can-globals/document/document'); | ||
var domEvents = require('can-dom-events'); | ||
var CIDMap = require('can-util/js/cid-map/cid-map'); | ||
var CIDMap = require('can-cid/map/map'); | ||
@@ -65,3 +64,3 @@ function getRoot (el) { | ||
function attachRootListener (root, eventName) { | ||
function attachRootListener (root, eventName, events) { | ||
var listenerName = getListenerName(eventName); | ||
@@ -78,7 +77,7 @@ var listener = domData.get.call(root, listenerName); | ||
}; | ||
events.addEventListener.call(root, 'change', newListener); | ||
events.addEventListener(root, 'change', newListener); | ||
domData.set.call(root, listenerName, newListener); | ||
} | ||
function detachRootListener (root, eventName) { | ||
function detachRootListener (root, eventName, events) { | ||
var listenerName = getListenerName(eventName); | ||
@@ -93,7 +92,7 @@ var listener = domData.get.call(root, listenerName); | ||
} | ||
events.removeEventListener.call(root, 'change', listener); | ||
events.removeEventListener(root, 'change', listener); | ||
domData.clean.call(root, listenerName); | ||
} | ||
function addListener (eventName, el) { | ||
function addListener (eventName, el, events) { | ||
if (!isRadioInput(el)) { | ||
@@ -104,9 +103,9 @@ throw new Error('Listeners for ' + eventName + ' must be radio inputs'); | ||
getRegistry(root, eventName).set(el, el); | ||
attachRootListener(root, eventName); | ||
attachRootListener(root, eventName, events); | ||
} | ||
function removeListener (eventName, el) { | ||
function removeListener (eventName, el, events) { | ||
var root = getRoot(el); | ||
getRegistry(root, eventName).delete(el); | ||
detachRootListener(root, eventName); | ||
detachRootListener(root, eventName, events); | ||
} | ||
@@ -117,2 +116,3 @@ | ||
* @parent can-infrastructure | ||
* @package ./package.json | ||
* | ||
@@ -127,16 +127,14 @@ * A custom event for listening to changes of inputs with type "radio", | ||
* ```js | ||
* var events = require("can-util/dom/events/events"); | ||
* var radioChange = require("can-util/dom/events/radiochange/radiochange"); | ||
* events.addCustomEvent(radioChange); | ||
* var domEvents = require('can-dom-events'); | ||
* var radioChange = require('can-event-dom-radiochange'); | ||
* domEvents.addEvent(radioChange); | ||
* | ||
* var el = document.createElement("div"); | ||
* var target = document.createElement('input'); | ||
* | ||
* function radiochangeHandler() { | ||
* console.log("radiochange event fired"); | ||
* function handler () { | ||
* console.log('radiochange event fired'); | ||
* } | ||
* | ||
* events.addEventListener.call(el, "radiochange", radiochangeHandler, false); | ||
* events.removeEventListener.call(el, "radiochange", radiochangeHandler); | ||
* | ||
* events.removeCustomEvent(radioChange); | ||
* domEvents.addEventListener(target, 'radiochange', handler); | ||
* domEvents.removeEventListener(target, 'radiochange', handler); | ||
* ``` | ||
@@ -148,3 +146,3 @@ */ | ||
addEventListener: function (target, eventName, handler) { | ||
addListener(eventName, target); | ||
addListener(eventName, target, this); | ||
target.addEventListener(eventName, handler); | ||
@@ -154,5 +152,5 @@ }, | ||
removeEventListener: function (target, eventName, handler) { | ||
removeListener(eventName, target); | ||
removeListener(eventName, target, this); | ||
target.removeEventListener(eventName, handler); | ||
} | ||
}; |
{ | ||
"name": "can-event-dom-radiochange", | ||
"description": "Custom radiochange event", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": { | ||
@@ -14,4 +14,6 @@ "name": "Chris Andrejewski", | ||
"dependencies": { | ||
"can-cid": "^1.1.0", | ||
"can-dom-data-state": "^0.1.1", | ||
"can-dom-events": "^1.0.2", | ||
"can-util": "^3.8.4" | ||
"can-globals": "^0.1.0" | ||
}, | ||
@@ -18,0 +20,0 @@ "devDependencies": { |
# can-event-dom-radiochange | ||
[![Build Status](https://travis-ci.org/canjs/can-event-dom-radiochange.svg?branch=master)](https://travis-ci.org/canjs/can-event-dom-radiochange) | ||
[![Join the chat at https://gitter.im/canjs/canjs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/canjs/canjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/canjs/can-event-dom-radiochange/blob/master/LICENSE) | ||
[![npm version](https://badge.fury.io/js/can-event-dom-radiochange.svg)](https://www.npmjs.com/package/can-event-dom-radiochange) | ||
[![Travis build status](https://travis-ci.org/canjs/can-event-dom-radiochange.svg?branch=master)](https://travis-ci.org/canjs/can-event-dom-radiochange) | ||
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/canjs/can-event-dom-radiochange?branch=master&svg=true)](https://ci.appveyor.com/project/matthewp/can-event-dom-radiochange) | ||
[![Coverage status](https://coveralls.io/repos/github/canjs/can-event-dom-radiochange/badge.svg?branch=master)](https://coveralls.io/github/canjs/can-event-dom-radiochange?branch=master) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/canjs/can-event-dom-radiochange.svg)](https://greenkeeper.io/) | ||
A custom event for listening to changes of inputs with type "radio", which fires when a conflicting radio input changes. A "conflicting" radio button has the same "name" attribute and exists within in the same form, or lack thereof. This event coordinates state bound to whether a radio is checked. The "change" event does not fire for deselected radios. By using this event instead, deselected radios receive notification. | ||
## Usage | ||
## Documentation | ||
### ES6 use | ||
Read the [can-event-dom-radiochange API docs on CanJS.com](https://canjs.com/doc/can-event-dom-radiochange.html). | ||
With StealJS, you can import this module directly in an auto-rendered template: | ||
## Changelog | ||
```js | ||
import radioChange from 'can-event-dom-radiochange'; | ||
import domEvents from 'can-util/dom/events'; | ||
domEvents.addCustomEvent(radioChange); | ||
``` | ||
See the [latest releases on GitHub](https://github.com/canjs/can-event-dom-radiochange/releases). | ||
### CommonJS use | ||
## Contributing | ||
Use `require` to load `can-event-dom-radiochange` and everything else | ||
needed to create a template that uses `can-event-dom-radiochange`: | ||
The [contribution guide](https://github.com/canjs/can-event-dom-radiochange/blob/master/CONTRIBUTING.md) has information on getting help, reporting bugs, developing locally, and more. | ||
```js | ||
var radioChange = require("can-event-dom-radiochange"); | ||
var domEvents = require('can-util/dom/events'); | ||
domEvents.addCustomEvent(radioChange); | ||
``` | ||
## License | ||
### Standalone use | ||
[MIT](https://github.com/canjs/can-event-dom-radiochange/blob/master/LICENSE) | ||
Load the `global` version of the plugin: | ||
```html | ||
<script src='./node_modules/can-event-dom-radiochange/dist/global/can-event-dom-radiochange.js'></script> | ||
``` |
16911
4
226
29
+ Addedcan-cid@^1.1.0
+ Addedcan-dom-data-state@^0.1.1
+ Addedcan-globals@^0.1.0
+ Addedcan-dom-data-state@0.1.1(transitive)
+ Addedcan-globals@0.1.0(transitive)
- Removedcan-util@^3.8.4
- Removedcan-ajax@1.4.1(transitive)
- Removedcan-assign@1.3.3(transitive)
- Removedcan-deparam@1.2.3(transitive)
- Removedcan-dom-data-state@0.2.0(transitive)
- Removedcan-event-dom-enter@1.0.4(transitive)
- Removedcan-event-dom-radiochange@1.0.5(transitive)
- Removedcan-globals@1.2.2(transitive)
- Removedcan-param@1.2.0(transitive)
- Removedcan-parse-uri@1.2.2(transitive)
- Removedcan-types@1.4.0(transitive)
- Removedcan-util@3.14.0(transitive)