diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-17 18:03:54 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-17 18:03:54 +0200 |
commit | 620ca44cfa360d6e100215619acab8ae1eb10f34 (patch) | |
tree | 22f427b0d6167b3f4bf8656449cb398e023415bb | |
parent | 11effccf63dd2f50db54583a4047bcd13247e1a4 (diff) | |
parent | 21374b14830837fe525046c1a77a4b61f31df6fa (diff) | |
download | bugzilla-triage-620ca44cfa360d6e100215619acab8ae1eb10f34.tar.gz |
Merge OOPtesting branch
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | lib/persistent-page-mod.js | 56 | ||||
-rw-r--r-- | tests/test-util.js | 5 |
3 files changed, 64 insertions, 2 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..365283f --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: install + +install: + rsync -avz jsons/RH_Data-packages.json \ + /home/matej/Dokumenty/website/ceplovi.cz/matej/progs/data/
\ No newline at end of file diff --git a/lib/persistent-page-mod.js b/lib/persistent-page-mod.js new file mode 100644 index 0000000..5c00a8f --- /dev/null +++ b/lib/persistent-page-mod.js @@ -0,0 +1,56 @@ +var timer = require("timer"); + +function PersistentPageMod(window, callback) { + memory.track(this); + this.window = window; + this.callback = callback; + this.window.addEventListener("unload", this, false); + this.window.addEventListener("DOMSubtreeModified", this, false); + this.doMod(); + require("unload-2").ensure(this); +} + +PersistentPageMod.prototype = { + REPLACE_DELAY: 100, + doMod: function doMod() { + try { + this.callback.call(undefined, this.window); + } catch (e) { + console.exception(e); + } + this.timerID = null; + }, + handleEvent: function handleEvent(event) { + switch (event.type) { + case "unload": + if (event.target == this.window.document) + this.unload(); + break; + case "DOMSubtreeModified": + if (this.timerID == null) { + // Wait a bit to do the replacing. Otherwise, we just get called + // tons of times in a tiny period and end up hanging the browser + // for a while. + var self = this; + this.timerID = timer.setTimeout(function() self.doMod(), + this.REPLACE_DELAY); + } + break; + } + }, + unload: function unload() { + if (this.timerID != null) { + timer.clearTimeout(this.timerID); + this.timerID = null; + } + this.window.removeEventListener("DOMSubtreeModified", this, false); + this.window.removeEventListener("unload", this, false); + } +}; + +require("errors").catchAndLogProps(PersistentPageMod.prototype, + "handleEvent"); + +var register = exports.register = function register(window, callback) { + new PersistentPageMod(window, callback); +}; diff --git a/tests/test-util.js b/tests/test-util.js index 98bd435..6292e84 100644 --- a/tests/test-util.js +++ b/tests/test-util.js @@ -41,7 +41,7 @@ exports.ensureHeir = function (test) { // http://en.wikipedia.org/wiki/Deirdre :) fedlimid = new Father("mac Daill"); naoise = new Son("Usnech", "Deirdre"); - + test.assertEqual(fedlimid.getFamily(), "mac Daill", "checking creation of new simple object"); @@ -185,7 +185,8 @@ exports.ensureLoadText = function (test) { // var url = "http://matej.ceplovi.cz/progs/data/pushkin.txt", text = ""; // test.waitUntilDone(); // util.loadText(url, function (txt) { -// //test.assertEqual(txt, pushkinTestString); +// console.log(txt); +// test.assertEqual(txt, pushkinTestString); // test.done(); // }); // }; |