Permalink
Browse files

Merge branch 'master' of git@github.com:sstephenson/prototype

Conflicts:
	CHANGELOG
  • Loading branch information...
2 parents c9d6c3e + 354e2f8 commit df67da14b3a793fb0aeb01c089bbfd4ccb022bc6 @savetheclocktower savetheclocktower committed May 7, 2010
Showing with 113 additions and 7 deletions.
  1. +1 −1 .gitmodules
  2. +2 −0 CHANGELOG
  3. +4 −2 Rakefile
  4. +2 −3 src/dom/event.js
  5. +99 −0 test/unit/event_handler_test.js
  6. +4 −0 test/unit/fixtures/event_handler.html
  7. +1 −1 vendor/pdoc
View
@@ -20,4 +20,4 @@
url = git://github.com/jeresig/sizzle.git
[submodule "vendor/slick/repository"]
path = vendor/slick/repository
- url = http://github.com/mootools/slick.git
+ url = git://github.com/mootools/slick.git
View
@@ -1,5 +1,7 @@
* Add `Element.purge` for cleaning up event listeners and element storage keys on elements that will be removed from the page. Make `Element.update` perform similar cleanup automatically. (Andrew Dupont, Tobie Langel)
+* The second argument to Event.Handler callbacks is the target element when no selector is present, or the matching element when a selector is present. Callbacks are always bound to the original element. (sam)
+
* Fix issue where `Element.Layout#get` would fail to interpret negative pixel values. (Sebastien Gruhier, Andrew Dupont)
* Fix bugs in layout.js. Add tests for `Element.Layout#toCSS`, `#toObject`, and `#toHash`. (RStankov, Andrew Dupont)
View
@@ -74,8 +74,10 @@ module PrototypeHelper
:index_page => 'README.markdown',
:syntax_highlighter => syntax_highlighter,
:markdown_parser => :bluecloth,
- :repository_url => "http://github.com/sstephenson/prototype/blob/#{current_head}/",
- :pretty_urls => true,
+ :src_code_href => proc { |file, line|
+ "http://github.com/sstephenson/prototype/blob/#{current_head}/#{file}#LID#{line}"
+ },
+ :pretty_urls => false,
:bust_cache => false,
:name => 'Prototype JavaScript Framework',
:short_name => 'Prototype',
View
@@ -912,9 +912,8 @@
},
handleEvent: function(event) {
- var element = this.selector ? event.findElement(this.selector) :
- this.element;
- if (element) this.callback.call(element, event, element);
+ var element = event.findElement(this.selector);
+ if (element) this.callback.call(this.element, event, element);
}
});
@@ -0,0 +1,99 @@
+new Test.Unit.Runner((function() {
+ function handle(selector, callback) {
+ if (!callback) {
+ callback = selector;
+ selector = false;
+ }
+ return new Event.Handler("container", "test:event", selector, callback);
+ }
+
+ return {
+ testHandlersDoNothingIfStartHasNotBeenCalled: function() {
+ var fired = false;
+ this.handler = handle(function() { fired = true });
+
+ $("container").fire("test:event");
+ this.assert(!fired);
+ },
+
+ testHandlersAreFiredWhenStartIsCalled: function() {
+ var fired = false;
+ this.handler = handle(function() { fired = true });
+
+ this.handler.start();
+ this.assert(!fired);
+ $("container").fire("test:event");
+ this.assert(fired);
+ },
+
+ testHandlersDoNotFireAfterStartingAndThenStopping: function() {
+ var fired = 0;
+ this.handler = handle(function() { fired++ });
+
+ this.handler.start();
+ this.assertEqual(0, fired);
+ $("container").fire("test:event");
+ this.assertEqual(1, fired);
+ this.handler.stop();
+ $("container").fire("test:event");
+ this.assertEqual(1, fired);
+ },
+
+ testHandlersWithoutSelectorsPassTheTargetElementToCallbacks: function() {
+ var span = $("container").down("span");
+ this.handler = handle(function(event, element) {
+ this.assertEqual(span, element);
+ }.bind(this));
+
+ this.handler.start();
+ span.fire("test:event");
+ },
+
+ testHandlersWithSelectorsPassTheMatchedElementToCallbacks: function() {
+ var link = $("container").down("a"), span = link.down("span");
+ this.handler = handle("a", function(event, element) {
+ this.assertEqual(link, element);
+ }.bind(this));
+
+ this.handler.start();
+ span.fire("test:event");
+ },
+
+ testHandlersWithSelectorsDoNotCallTheCallbackIfNoMatchingElementIsFound: function() {
+ var paragraph = $("container").down("p", 1), fired = false;
+ this.handler = handle("a", function(event, element) { fired = true });
+
+ this.handler.start();
+ paragraph.fire("test:event");
+ this.assert(!fired);
+ },
+
+ testHandlerCallbacksAreBoundToTheOriginalElement: function() {
+ var span = $("container").down("span"), element;
+ this.handler = handle(function() { element = this });
+
+ this.handler.start();
+ span.fire("test:event");
+ this.assertEqual($("container"), element);
+ },
+
+ testCallingStartMultipleTimesDoesNotInstallMultipleObservers: function() {
+ var fired = 0;
+ this.handler = handle(function() { fired++ });
+
+ this.handler.start();
+ this.handler.start();
+ $("container").fire("test:event");
+ this.assertEqual(1, fired);
+ },
+
+ teardown: function() {
+ try {
+ this.handler.stop();
+ } catch (e) {
+ } finally {
+ delete this.handler;
+ }
+ }
+ }
+})());
@@ -0,0 +1,4 @@
+<div id="container" style="display: none">
+ <p>Here's <a href="#"><span>a link</span></a>.</p>
+ <p>And here's another paragraph.</p>
+</div>

0 comments on commit df67da1

Please sign in to comment.