[Pkg-mozext-commits] [itsalltext] 290/459: interim checkpoint
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:30 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository itsalltext.
commit 6a8e0333426b4512fa1ac1b526bebfe3327d5ae5
Author: docwhat at gerf.org <docwhat at gerf.org>
Date: Mon Nov 5 14:45:27 2007 -0500
interim checkpoint
---
Makefile | 4 +-
src/chrome/content/cacheobj.js | 29 ++++---
src/chrome/content/itsalltext.js | 160 ++++++++++++++++++++++++++++-----------
3 files changed, 137 insertions(+), 56 deletions(-)
diff --git a/Makefile b/Makefile
index 2cd1326..24bfca0 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ ZIP := zip
PROJNICK := itsalltext
PROJNAME := "It's All Text!"
ICONFILE := src/chrome/content/icon.png
-VERSION := 0.8.2
+VERSION := 0.8.2.2
# NOTE: do not create files or directories in here that have
@@ -158,7 +158,7 @@ showlint: lint
narf: .narf-stamp
.narf-stamp:
- $(Q)grep -nri 'narf' [a-z0-9]* ; test $$? = 1
+ $(Q)grep -nri 'narf' [a-z0-9]* ; test $$? = 1 || :
$(Q)touch $@
##
diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index 355a1d0..a4e1d37 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -152,7 +152,7 @@ function CacheObj(node) {
* Destroys the object, unallocating as much as possible to prevent leaks.
*/
CacheObj.prototype.destroy = function() {
- ItsAllText.debug('destroying', this.node_id, this);
+ ItsAllText.debug('destroying', this.node_id, this.uid);
var node = this.node;
var doc = this.node.ownerDocument;
var html = doc.getElementsByTagName('html')[0];
@@ -566,11 +566,16 @@ CacheObj.prototype.addGumDrop = function() {
// Add the textarea mouseovers even if the button is disabled
var node = cache_object.node;
- node.addEventListener( "mouseover", cache_object.mouseover, false);
- node.addEventListener( "mouseout", cache_object.mouseout, false);
- node.addEventListener( "focus", cache_object.mouseover, false);
- node.addEventListener( "blur", cache_object.mouseout, false);
- node.addEventListener( "keypress", cache_object.keypress, false);
+ ItsAllText.listen(node, "mouseover", ItsAllText.hitch(cache_object, "mouseover"), false);
+ ItsAllText.listen(node, "mouseout", ItsAllText.hitch(cache_object, "mouseout"), false);
+ ItsAllText.listen(node, "focus", ItsAllText.hitch(cache_object, "mouseover"), false);
+ ItsAllText.listen(node, "blur", ItsAllText.hitch(cache_object, "mouseout"), false);
+ ItsAllText.listen(node, "keypress", ItsAllText.hitch(cache_object, "keypress"), false);
+// narf node.addEventListener( "mouseover", cache_object.mouseover, false);
+// narf node.addEventListener( "mouseout", cache_object.mouseout, false);
+// narf node.addEventListener( "focus", cache_object.mouseover, false);
+// narf node.addEventListener( "blur", cache_object.mouseout, false);
+// narf node.addEventListener( "keypress", cache_object.keypress, false);
if (ItsAllText.getDisableGumdrops()) {
return;
}
@@ -604,8 +609,10 @@ CacheObj.prototype.addGumDrop = function() {
gumdrop.setAttribute(ItsAllText.MYSTRING+'_UID', cache_object.uid);
// Click event handlers
- gumdrop.addEventListener("click", cache_object.onClick, false);
- gumdrop.addEventListener("contextmenu", cache_object.onContext, false);
+ ItsAllText.listen(gumdrop, "click", ItsAllText.hitch(cache_object, 'onClick'), false);
+ ItsAllText.listen(gumdrop, "contextmenu", ItsAllText.hitch(cache_object, 'onContext'), false);
+// narf gumdrop.addEventListener("click", cache_object.onClick, false);
+// narf gumdrop.addEventListener("contextmenu", cache_object.onContext, false);
// Insert it into the document
var parent = node.parentNode;
@@ -618,8 +625,10 @@ CacheObj.prototype.addGumDrop = function() {
}
// Add mouseovers/outs
- gumdrop.addEventListener("mouseover", cache_object.mouseover, false);
- gumdrop.addEventListener("mouseout", cache_object.mouseout, false);
+ ItsAllText.listen(gumdrop, 'mouseover', ItsAllText.hitch(cache_object, 'mouseover'), false);
+ ItsAllText.listen(gumdrop, 'mouseout', ItsAllText.hitch(cache_object, 'mouseout'), false);
+// narf gumdrop.addEventListener("mouseover", cache_object.mouseover, false);
+// narf gumdrop.addEventListener("mouseout", cache_object.mouseout, false);
cache_object.mouseout(null);
cache_object.adjust();
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 1809f8e..2e9a1d7 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -38,6 +38,12 @@ var ItsAllText = function() {
that.tracker = {};
/**
+ * A serial for tracking ids
+ * @type Integer
+ */
+ that.serial_id = 0;
+
+ /**
* A constant, a string used for things like the preferences.
* @type String
*/
@@ -132,9 +138,11 @@ var ItsAllText = function() {
*/
that.debug = function() {
if (that.preferences && that.preferences.debug) {
- try { Firebug.Console.logFormatted(arguments); }
- catch(e) {
- that.log.apply(that,arguments);
+ try {
+ Firebug.Console.logFormatted(arguments);
+ var message = that.logString.apply(that, arguments);
+ window.dump(message+'\n');
+ } catch(e) {
}
}
};
@@ -476,7 +484,7 @@ var ItsAllText = function() {
}
}
}
- that.debuglog('tracker count:', count);
+ that.debug('tracker count:', count);
};
/**
@@ -667,12 +675,21 @@ Line 0
is_usable = false;
}
if (!(is_usable || is_my_readme)) {
- that.debuglog('watch(): ignoring -- ',
- location, contentType);
+ that.debug('watch(): ignoring -- ', location, contentType);
return;
}
}
+ var documents = that.monitor.documents;
+ var i;
+ for(i in documents) {
+ if (documents[i] === doc) {
+ // Found it, don't watch it twice.
+ that.debug('narf: double watch: ' + doc.location + '\n');
+ return;
+ }
+ }
+ that.debug('watch()ing: ' + doc.location + '\n');
that.refreshDocument(doc);
that.monitor.documents.push(doc);
},
@@ -686,20 +703,18 @@ Line 0
var now = Date.now();
if (now - monitor.last_now < Math.round(rate * 0.9)) {
- that.debuglog('monitor.watcher(',offset,') -- skipping catchup refresh');
+ that.debug('monitor.watcher(',offset,') -- skipping catchup refresh');
return;
}
monitor.last_now = now;
/* Walk the documents looking for changes */
var documents = monitor.documents;
- //that.debuglog('monitor.watcher(',offset,'): ', documents.length);
var i, doc;
for(i in documents) {
if (documents.hasOwnProperty(i)) {
doc = documents[i];
if (doc.location) {
- //that.debuglog('refreshing', doc.location);
that.refreshDocument(doc);
}
}
@@ -714,7 +729,7 @@ Line 0
var i;
for(i in documents) {
if (documents[i] === doc) {
- that.debug('unwatching', doc);
+ that.debug('unwatching', doc && doc.location);
delete documents[i];
}
}
@@ -728,16 +743,6 @@ Line 0
};
/**
- * Callback whenever the DOM content in a window or tab is loaded.
- * @param {Object} event An event passed in.
- */
- that.onDOMContentLoad = function(event) {
- var doc = event.originalTarget;
- that.monitor.watch(doc);
- return;
- };
-
- /**
* Open the editor for a selected node.
* @param {Object} node The textarea to get.
*/
@@ -794,13 +799,70 @@ Line 0
// Do the startup when things are loaded.
- window.addEventListener("load", function(event){that.pageload(event);}, true);
+ that.listen(window, 'load', that.hitch(that, 'pageload'));
+ //narf window.addEventListener("load", that.pageload, true);
// Do the startup when things are unloaded.
- window.addEventListener("unload", function(event){that.pageunload(event);}, true);
+ //narf window.addEventListener("unload", function(event){that.pageunload(event);}, true);
+ that.listen(window, 'unload', that.hitch(that, 'pageunload'));
};
/**
+ * This wraps the call to object.method to ensure that 'this' is correct.
+ * This is borrowed from GreaseMonkey (though the concept has been around)
+ * @method hitch
+ * @param {Object} object
+ * @param {String} method The method on object to call
+ * @returns {Function} A wrapped call to object.method() which passes the arguments.
+ */
+ItsAllText.prototype.hitch = function(object, method) {
+ if (!object[method]) {
+ throw "method '" + method + "' does not exist on object '" + object + "'";
+ }
+
+ var staticArgs = Array.prototype.splice.call(arguments, 2, arguments.length);
+
+ return function() {
+ // make a copy of staticArgs (don't modify it because it gets reused for
+ // every invocation).
+ var args = staticArgs.concat();
+
+ // add all the new arguments
+ for (var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+
+ // invoke the original function with the correct this object and
+ // the combined list of static and dynamic arguments.
+ return object[method].apply(object, args);
+ };
+}
+
+/**
+ * @method listen
+ * @param source {HTMLElement} The element to listen for events on.
+ * @param event {String} The name of the event to listen for.
+ * @param listener {Function} The function to run when the event is triggered.
+ * @param opt_capture {Boolean} Should the event be captured?
+ */
+ItsAllText.prototype.listen = function (source, event, listener, opt_capture) {
+ Components.lookupMethod(source, "addEventListener")(
+ event, listener, opt_capture);
+}
+
+/**
+ * @method unlisten
+ * @param source {HTMLElement} The element with the event
+ * @param event {String} The name of the event.
+ * @param listener {Function} The function that was to be run when the event is triggered.
+ * @param opt_capture {Boolean} Should the event be captured?
+ */
+ItsAllText.prototype.unlisten = function (source, event, listener, opt_capture) {
+ Components.lookupMethod(source, "removeEventListener")(
+ event, listener, opt_capture);
+}
+
+/**
* Convert an event into a key fingerprint, aka keyprint.
* @param {Event} event
* @returns {String} keyprint
@@ -894,15 +956,17 @@ ItsAllText.prototype.menuNewExtEdit = function(event) {
* @param {string} ext
* @param {boolean} clobber
*/
-ItsAllText.prototype.menuExtEdit = function(event, ext, clobber) {
- var that = this;
- var uid = that.private_current_uid;
+ItsAllText.prototype.menuExtEdit = function(ext, clobber, event) {
+ var uid = this.private_current_uid;
+ for (var i=0; i < arguments.length; i++) {
+ this.debug('narf '+i+': '+arguments[i]+'\n');
+ }
if (ext !== null) {
ext = typeof(ext) === 'string'?ext:event.target.getAttribute('label');
}
- ItsAllText.debug('menuExtEdit:',uid, ext, clobber);
- var cobj = that.getCacheObj(uid);
- that.monitor.watch(cobj.node.ownerDocument);
+ this.debug('menuExtEdit:',uid, ext, clobber);
+ var cobj = this.getCacheObj(uid);
+ this.monitor.watch(cobj.node.ownerDocument);
cobj.edit(ext, clobber);
};
@@ -950,7 +1014,7 @@ ItsAllText.prototype.rebuildMenu = function(uid, menu_id, is_disabled) {
if (cobj.edit_count <= 0 && cobj.file && cobj.file.exists()) {
node = document.createElementNS(that.XULNS, 'menuitem');
node.setAttribute('label', that.localeFormat('edit_existing', [cobj.extension]));
- node.addEventListener('command', function(event){return that.menuExtEdit(event, null, false);}, false);
+ that.listen(node, 'command', that.hitch(that, 'menuExtEdit', null, false), false);
node.setAttribute('disabled', is_disabled?'true':'false');
menu.insertBefore(node, magic_stop_node);
}
@@ -961,7 +1025,8 @@ ItsAllText.prototype.rebuildMenu = function(uid, menu_id, is_disabled) {
node.setAttribute('label', that.localeFormat('edit_ext', [exts[i]]));
(function() {
var ext=exts[i];
- node.addEventListener('command', function(event){return that.menuExtEdit(event, ext);}, false);
+ that.listen(node, 'command', that.hitch(that, 'menuExtEdit', ext, true), false);
+ //narf node.addEventListener('command', function(event){return that.menuExtEdit(event, ext);}, false);
})();
node.setAttribute('disabled', is_disabled?'true':'false');
menu.insertBefore(node, magic_stop_node);
@@ -983,15 +1048,27 @@ ItsAllText.prototype.getLocale = function() {
};
/**
+ * An event to watch a document.
+ * @method watchDocument
+ */
+ItsAllText.prototype.watchDocument = function (event) {
+ var doc = event.originalTarget;
+ // This setTimeout is like a yield() --
+ // it put it at the end of the thread stack.
+ setTimeout(this.hitch(this.monitor, 'watch', doc), 1);
+};
+
+/**
* Initialize the module. Should be called once, when a window is loaded.
* @private
*/
ItsAllText.prototype.pageload = function(event) {
var doc = event.originalTarget;
+ this.debug('narfy0 load ' + doc.nodeName + '\n');
if (!doc || doc.nodeName != "#document") {
return;
}
- this.debug("pageload(): A page has been loaded:",doc);
+ this.debug("pageload(): A page has been loaded:",doc && doc.location);
// Start watching the preferences.
this.preference_observer.register();
@@ -999,24 +1076,19 @@ ItsAllText.prototype.pageload = function(event) {
// Start the monitor
this.monitor.restart();
+ // Schedule a watch when the content is loaded.
var appcontent = document.getElementById("appcontent"); // The Browser
if (appcontent) {
- // Normal web-page.
- appcontent.addEventListener("DOMContentLoaded", this.onDOMContentLoad,
- true);
- /* This is a fallback. It seems that sometimes I get here
- * AFTER the DOMContentLoaded event has fired. :-( Better late
- * than never, I guess.
- */
- setTimeout(function() {ItsAllText.onDOMContentLoad({originalTarget: event.originalTarget});}, 5000);
- } else {
- this.onDOMContentLoad(event);
+ this.debug('narfy1 load ' + doc.location + '\n');
+ this.listen(appcontent, 'load', this.hitch(this, 'watchDocument'), true);
+ //narf appcontent.addEventListener("load", This.watchDocument, true);
}
+
// Attach the context menu, if we can.
var contentAreaContextMenu = doc.getElementById("contentAreaContextMenu");
if (contentAreaContextMenu) {
- contentAreaContextMenu.addEventListener("popupshowing",
- this.onContextMenu, false);
+ this.listen(contentAreaContextMenu, 'popupshowing', this.hitch(this, 'onContextMenu'), false);
+ //narf contentAreaContextMenu.addEventListener("popupshowing",this.onContextMenu, false);
}
};
@@ -1029,7 +1101,7 @@ ItsAllText.prototype.pageunload = function(event) {
/* We don't check for the doc type because we want to
* be sure everything is unloaded.
*/
- this.debug("pageunload(): A page has been unloaded", doc);
+ this.debug("pageunload(): A page has been unloaded", doc && doc.location);
this.monitor.unwatch(doc);
this.preference_observer.unregister();
this.cleanCacheObjs();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git
More information about the Pkg-mozext-commits
mailing list