Skip to content

Commit

Permalink
Docs; Code style updates; Update to version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rniemeyer committed Jan 3, 2015
1 parent 0187f55 commit f7e326d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ There are a couple of cases where this technique might be necessary:

Note: when attaching a handler using the binding, you will need to manage the value of `this` as you would when using the normal `click` and `event` bindings. So, in this case you would have to take care of it in our view model or bind against it like `$parent.removeItem.bind($parent)`.

##Control Bubbling
Normally, when an event is handled, the plugin will prevent further bubbling of the event. In a scenario that you do want an event to continue bubbling, you can add an additional binding per event name to allow bubbling.

```html
<div data-bind="delegatedHandler: ['click', 'mouseover'], delegatedClickBubble: true">
...
</div>
```

In this caase, the `delegatedClickBubble` additional binding will signal the plugin that when it handles a `click` event it should allow the event to continue bubbling. For even greater control, the handler could then access the event argument (2nd arg) and choose to prevent bubbling on a case-by-case basis.

##TODO

* Improve example
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knockout-delegatedEvents",
"version": "0.4.0",
"version": "0.5.0",
"main": "build/knockout-delegatedEvents.min.js",
"ignore": [
"examples",
Expand Down
7 changes: 4 additions & 3 deletions build/knockout-delegatedEvents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// knockout-delegatedEvents 0.4.0 | (c) 2014 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
// knockout-delegatedEvents 0.5.0 | (c) 2015 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
;(function(factory) {
//CommonJS
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
Expand Down Expand Up @@ -98,8 +98,9 @@
}

//prevent bubbling if not enabled
if(bubble !== true) {
if (bubble !== true) {
event.cancelBubble = true;

if (typeof event.stopPropagation === "function") {
event.stopPropagation();
}
Expand Down Expand Up @@ -146,7 +147,7 @@

ko.utils.arrayForEach(events, function(event) {
//check if the associated "delegated<EventName>Bubble" is true (optionally allows bubbling)
var bubble = allBindings.get( createBindingName(event + 'Bubble') ) === true;
var bubble = allBindings.get(createBindingName(event + "Bubble")) === true;

createDelegatedBinding(event);
ko.utils.registerEventHandler(element, event, createDelegatedHandler(event, element, bubble));
Expand Down
2 changes: 1 addition & 1 deletion build/knockout-delegatedEvents.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knockout-delegatedEvents",
"version": "0.4.0",
"version": "0.5.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "0.x.x",
Expand Down
5 changes: 3 additions & 2 deletions src/knockout-delegatedEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@
}

//prevent bubbling if not enabled
if(bubble !== true) {
if (bubble !== true) {
event.cancelBubble = true;

if (typeof event.stopPropagation === "function") {
event.stopPropagation();
}
Expand Down Expand Up @@ -145,7 +146,7 @@

ko.utils.arrayForEach(events, function(event) {
//check if the associated "delegated<EventName>Bubble" is true (optionally allows bubbling)
var bubble = allBindings.get( createBindingName(event + 'Bubble') ) === true;
var bubble = allBindings.get(createBindingName(event + "Bubble")) === true;

createDelegatedBinding(event);
ko.utils.registerEventHandler(element, event, createDelegatedHandler(event, element, bubble));
Expand Down

0 comments on commit f7e326d

Please sign in to comment.