diff --git a/packages/ui/domrange.js b/packages/ui/domrange.js index a1157f864f..b957a93e43 100644 --- a/packages/ui/domrange.js +++ b/packages/ui/domrange.js @@ -907,6 +907,9 @@ DomRange.prototype.on = function (events, selector, handler) { if (! parentNode) // if we're not in the DOM, silently fail. return; + // haven't been added yet; error + if (parentNode.$_uiIsOffscreen) + throw new Error("Can't bind events before DomRange is inserted"); var eventTypes = []; events.replace(/[^ /]+/g, function (e) { diff --git a/packages/ui/domrange_tests.js b/packages/ui/domrange_tests.js index c268fb6cec..69b3869118 100644 --- a/packages/ui/domrange_tests.js +++ b/packages/ui/domrange_tests.js @@ -630,6 +630,13 @@ Tinytest.add("ui - DomRange - basic events", function (test) { } }; + var q = new DomRange; + test.throws(function () { + // can't bind events before DomRange is added to + // the DOM + q.on('click', function (evt) {}); + }); + inDocument( htmlRange("Foo"), function (r) { @@ -839,6 +846,27 @@ Tinytest.addAsync("ui - DomRange - IE TextNode GC", function (test, onComplete) }, 500); }); +Tinytest.add("ui - DomRange - events in tables", function (test) { + inDocument(htmlRange("