-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn off events. #8
Open
hemanth
wants to merge
4
commits into
remy:master
Choose a base branch
from
hemanth:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,81 @@ | ||
/*globals Element:true, NodeList:true*/ | ||
$ = (function (document, $) { | ||
var element = Element.prototype, | ||
nodeList = NodeList.prototype, | ||
forEach = 'forEach', | ||
trigger = 'trigger', | ||
each = [][forEach], | ||
dummy = document.createElement(); | ||
|
||
nodeList[forEach] = each; | ||
|
||
element.on = function (event, fn) { | ||
this.addEventListener(event, fn, false); | ||
return this; | ||
}; | ||
|
||
nodeList.on = function (event, fn) { | ||
each.call(this, function (el) { | ||
el.on(event, fn); | ||
}); | ||
return this; | ||
}; | ||
|
||
element.trigger = function (type, data) { | ||
var event = document.createEvent('HTMLEvents'); | ||
event.initEvent(type, true, true); | ||
event.data = data || {}; | ||
event.eventName = type; | ||
event.target = this; | ||
this.dispatchEvent(event); | ||
return this; | ||
}; | ||
|
||
nodeList.trigger = function (event) { | ||
each.call(this, function (el) { | ||
el[trigger](event); | ||
}); | ||
return this; | ||
}; | ||
|
||
$ = function (s) { | ||
var r = document.querySelectorAll(s || '☺'), | ||
length = r.length; | ||
return length == 1 ? r[0] : !length ? nodeList : r; | ||
}; | ||
|
||
$.on = element.on.bind(dummy); | ||
$.trigger = element[trigger].bind(dummy); | ||
|
||
return $; | ||
$ = (function(document, $) { | ||
var element = Element.prototype, | ||
nodeList = NodeList.prototype, | ||
forEach = 'forEach', | ||
trigger = 'trigger', | ||
each = [][forEach], | ||
dummy = document.createElement(); | ||
|
||
nodeList[forEach] = each; | ||
|
||
element.on = function(event, fn) { | ||
if (!this.handlers) { | ||
this.handlers = [] | ||
} | ||
this.addEventListener(event, fn, false); | ||
this.handlers.push(fn); | ||
return this; | ||
}; | ||
|
||
element.off = function(event, fn) { | ||
if (!fn) { | ||
this.handlers[forEach](function(handler) { | ||
this.removeEventListener(event, handler, false); | ||
}.bind(this)); | ||
}else { | ||
this.removeEventListener(event, fn, false); | ||
} | ||
return this; | ||
}; | ||
|
||
nodeList.on = function(event, fn) { | ||
each.call(this, function(el) { | ||
el.on(event, fn); | ||
this.handlers.push(fn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicates the handlers list - as we're using |
||
}); | ||
return this; | ||
}; | ||
|
||
nodeList.off = function(event, fn) { | ||
if(!fn) { | ||
this.handlers[forEach](function(handler) { | ||
this.off(event, handler, false); | ||
}.bind(this)); | ||
}else { | ||
each.call(this, function(el) { | ||
el.off(event, fn); | ||
}); | ||
} | ||
return this; | ||
}; | ||
|
||
element.trigger = function(type, data) { | ||
var event = document.createEvent('HTMLEvents'); | ||
event.initEvent(type, true, true); | ||
event.data = data || {}; | ||
event.eventName = type; | ||
event.target = this; | ||
this.dispatchEvent(event); | ||
return this; | ||
}; | ||
|
||
nodeList.trigger = function(event) { | ||
each.call(this, function(el) { | ||
el[trigger](event); | ||
}); | ||
return this; | ||
}; | ||
|
||
$ = function(s) { | ||
var r = document.querySelectorAll(s || '☺'), | ||
length = r.length; | ||
return length == 1 ? r[0] : !length ? nodeList : r; | ||
}; | ||
|
||
$.on = element.on.bind(dummy); | ||
$.off = element.off.bind(dummy); | ||
$.trigger = element[trigger].bind(dummy); | ||
|
||
return $; | ||
})(document); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you restore the 2 white space - otherwise I see a 100% file change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remy FYI you can also view any commit without whitespace differences by appending
?w=1
to the URL. E.g. https://github.com/remy/min.js/pull/8/files?w=1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've been doing that - but integrating the change also means reversing out the white space changes - fun times :)