[Pkg-mozext-commits] [itsalltext] 380/459: Moving stuff to streamline loading
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:40 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 55f484c11e42bb718c29cbfb56e3c8c9f7548214
Author: Christian Höltje <docwhat at gerf.org>
Date: Sat Aug 13 20:56:01 2011 -0400
Moving stuff to streamline loading
Monitor was initializing so early that we had to pass in
a copy of 'itsalltext'. Restructured things so it is
no longer the case.
In addition, stopped clobbering the Monitor class and
ItsAllText class. (why was I doing that?)
---
src/chrome/content/API.js | 12 +-
src/chrome/content/badeditor.xul | 2 +-
src/chrome/content/cacheobj.js | 134 +++++++++---------
src/chrome/content/itsalltext.js | 274 +++++++++++++++++++-----------------
src/chrome/content/itsalltext.xul | 24 ++--
src/chrome/content/monitor.js | 81 ++++++-----
src/chrome/content/newextension.xul | 4 +-
src/chrome/content/preferences.js | 10 +-
8 files changed, 279 insertions(+), 262 deletions(-)
diff --git a/src/chrome/content/API.js b/src/chrome/content/API.js
index 25c67e6..e3d37b3 100644
--- a/src/chrome/content/API.js
+++ b/src/chrome/content/API.js
@@ -1,4 +1,4 @@
-/*extern Components, ItsAllText, XPathResult */
+/*extern Components, itsalltext, XPathResult */
/*jslint undef: true, nomen: true, evil: false, browser: true, white: true */
/*
@@ -11,7 +11,7 @@
If "It's All Text!" isn't installed in the browser, it will fail safely.
It only generates an info message in the error console.
- You then have two choices. You can call ItsAllTextopenEditor() directly
+ You then have two choices. You can call itsalltextopenEditor() directly
via JavaScript or you can add one or two attributes to a XUL element and
it'll automatically be set up right.
@@ -40,8 +40,8 @@
</hbox>
Example calling openEditor() directly:
- if(some_condition && ItsAllText) {
- ItsAllText.openEditor('id-of-textarea', '.extension');
+ if(some_condition && itsalltext) {
+ itsalltext.openEditor('id-of-textarea', '.extension');
}
*/
@@ -72,7 +72,7 @@
*/
node.style.MozAppearance = 'none';
- cache_object = node && ItsAllText.CacheObj.get(node);
+ cache_object = node && itsalltext.CacheObj.get(node);
if (!cache_object) {
return;
}
@@ -88,7 +88,7 @@
i,
nodesIter;
/* Start watching the document, but force it. */
- ItsAllText.monitor.startPage({originalTarget: document}, true);
+ itsalltext.monitor.startPage({originalTarget: document}, true);
/* Turn on all the hidden CSS */
nodesIter = document.evaluate("//node()[@itsalltext-control]",
diff --git a/src/chrome/content/badeditor.xul b/src/chrome/content/badeditor.xul
index 1267ca3..a449ecc 100644
--- a/src/chrome/content/badeditor.xul
+++ b/src/chrome/content/badeditor.xul
@@ -5,7 +5,7 @@
<dialog
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- id="ItsAllTextBadEditor"
+ id="itsalltextBadEditor"
title="&title;"
buttonlabelaccept="&pref.label;"
ondialogaccept="return onOK();"
diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index bbabbd3..f69531e 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -1,4 +1,4 @@
-/*extern ItsAllText, Components */
+/*extern itsalltext, Components */
/*jslint undef: true, evil: false, browser: true, white: true */
/*
* It's All Text! - Easy external editing of web forms.
@@ -32,22 +32,22 @@ function CacheObj(node) {
extension;
this.uuid = Math.floor(Math.random()*2000);
- //disabled-debug -- ItsAllText.debug('CacheObject ', this.uuid, node);
+ //disabled-debug -- itsalltext.debug('CacheObject ', this.uuid, node);
for (method in this) {
if (hitch_re.test(method)) {
- //disabled-debug -- ItsAllText.debug('CacheObj ', this.uuid, 'hitching ', method, ' -> ', method.replace(hitch_re, ''));
- this[method.replace(hitch_re, '')] = ItsAllText.hitch(this, method);
+ //disabled-debug -- itsalltext.debug('CacheObj ', this.uuid, 'hitching ', method, ' -> ', method.replace(hitch_re, ''));
+ this[method.replace(hitch_re, '')] = itsalltext.hitch(this, method);
}
}
/* Gumdrop Image URL */
that.gumdrop_url = 'chrome://itsalltext/locale/gumdrop.png';
/* Gumdrop Image Width */
- that.gumdrop_width = ItsAllText.localeString('gumdrop.width');
+ that.gumdrop_width = itsalltext.localeString('gumdrop.width');
/* Gumdrop Image Height */
- that.gumdrop_height = ItsAllText.localeString('gumdrop.height');
+ that.gumdrop_height = itsalltext.localeString('gumdrop.height');
that.timestamp = 0;
that.size = 0;
@@ -70,8 +70,8 @@ function CacheObj(node) {
that.node_id ].join(':'));
// @todo [security] Add a serial to the uid hash.
- node.setUserData(ItsAllText.MYSTRING + '_UID', that.uid, null);
- ItsAllText.addToTracker(that.uid, that);
+ node.setUserData(itsalltext.MYSTRING + '_UID', that.uid, null);
+ itsalltext.addToTracker(that.uid, that);
/* Figure out where we will store the file. While the filename can
* change, the directory that the file is stored in should not!
@@ -101,7 +101,7 @@ function CacheObj(node) {
/* Set the default extension and create the nsIFile object. */
extension = node.getAttribute('itsalltext-extension');
if (typeof(extension) != 'string' || !extension.match(/^[.a-z0-9]+$/i)) {
- extension = ItsAllText.getExtensions()[0];
+ extension = itsalltext.getExtensions()[0];
}
that.setExtension(extension);
@@ -136,7 +136,7 @@ function CacheObj(node) {
* @param {Event} event The event object.
*/
that.mouseout = function (event) {
- //disabled-debug -- ItsAllText.debug("mouseout: %o", event, event.target, that.is_focused);
+ //disabled-debug -- itsalltext.debug("mouseout: %o", event, event.target, that.is_focused);
if (that.button_fade_timer) {
clearTimeout(that.button_fade_timer);
}
@@ -151,7 +151,7 @@ function CacheObj(node) {
cur = 0.7,
dest = 0,
fps = 12,
- num_frames = (ItsAllText.preferences.fade_time * fps),
+ num_frames = (itsalltext.preferences.fade_time * fps),
increment = (cur - dest) / num_frames,
wait = (1 / fps) / 1000;
if (style) {
@@ -173,13 +173,13 @@ function CacheObj(node) {
* Destroys the object, unallocating as much as possible to prevent leaks.
*/
CacheObj.prototype.destroy = function () {
- //disabled-debug -- ItsAllText.debug('destroying', this.node_id, this.uid);
+ //disabled-debug -- itsalltext.debug('destroying', this.node_id, this.uid);
var node = this.node,
doc = this.node.ownerDocument,
html = doc.getElementsByTagName('html')[0];
- //node.removeAttribute(ItsAllText.MYSTRING + '_UID');
- //html.removeAttribute(ItsAllText.MYSTRING + '_id_serial');
+ //node.removeAttribute(itsalltext.MYSTRING + '_UID');
+ //html.removeAttribute(itsalltext.MYSTRING + '_id_serial');
delete this.node;
delete this.button;
@@ -197,8 +197,8 @@ CacheObj.prototype.setExtension = function (ext) {
}
/* Create the nsIFile object */
- var file = ItsAllText.factoryFile();
- file.initWithFile(ItsAllText.getEditDir());
+ var file = itsalltext.factoryFile();
+ file.initWithFile(itsalltext.getEditDir());
file.append([this.base_filename, ext].join(''));
this.extension = ext;
@@ -216,7 +216,7 @@ CacheObj.prototype.setExtension = function (ext) {
*/
CacheObj.prototype.initFromExistingFile = function () {
var base = this.base_filename,
- fobj = ItsAllText.getEditDir(),
+ fobj = itsalltext.getEditDir(),
entries = fobj.directoryEntries,
ext = null,
tmpfiles = /(\.bak|.tmp|~)$/,
@@ -233,7 +233,7 @@ CacheObj.prototype.initFromExistingFile = function () {
try {
entry.remove(false);
} catch (e) {
- //disabled-debug -- ItsAllText.debug('unable to remove', entry, 'because:', e);
+ //disabled-debug -- itsalltext.debug('unable to remove', entry, 'because:', e);
}
}
}
@@ -256,7 +256,7 @@ CacheObj.prototype.getNodeIdentifier = function (node) {
if (!id) {
name = node.getAttribute('name');
doc = node.ownerDocument.getElementsByTagName('html')[0];
- attr = ItsAllText.MYSTRING + '_id_serial';
+ attr = itsalltext.MYSTRING + '_id_serial';
/* Get a serial that's unique to this document */
serial = doc.getUserData(attr);
@@ -265,7 +265,7 @@ CacheObj.prototype.getNodeIdentifier = function (node) {
} else {
serial = 1;
}
- id = [ItsAllText.MYSTRING, 'generated_id', name, serial].join('_');
+ id = [itsalltext.MYSTRING, 'generated_id', name, serial].join('_');
doc.setUserData(attr, serial, null);
node.setAttribute('id', id);
}
@@ -305,7 +305,7 @@ CacheObj.prototype.write = function (clobber) {
conv = Components.
classes["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
- conv.charset = ItsAllText.getCharset();
+ conv.charset = itsalltext.getCharset();
text = conv.ConvertFromUnicode(this.node.value);
foStream.write(text, text.length);
@@ -346,7 +346,7 @@ CacheObj.prototype.getStyle = function (node, attr) {
* @param {boolean} clobber Should an existing file be clobbered?
*/
CacheObj.prototype.edit = function (extension, clobber) {
- ItsAllText.debug(this.uuid, 'edit(', extension, ', ', clobber, ')', this.uid);
+ itsalltext.debug(this.uuid, 'edit(', extension, ', ', clobber, ')', this.uid);
extension = typeof(extension) === 'string'?extension:this.extension;
this.setExtension(extension);
@@ -364,7 +364,7 @@ CacheObj.prototype.edit = function (extension, clobber) {
try {
- program = ItsAllText.getEditor();
+ program = itsalltext.getEditor();
// checks
if (program === null) {
@@ -375,16 +375,16 @@ CacheObj.prototype.edit = function (extension, clobber) {
throw {name: "NS_ERROR_FILE_NOT_FOUND"};
}
- if (ItsAllText.isDarwin() &&
+ if (itsalltext.isDarwin() &&
program.isDirectory() &&
program.leafName.match(/\.app$/i)) {
// OS-X .app bundles should be run with open.
args = ['-a', program.path, filename];
- program = ItsAllText.factoryFile('/usr/bin/open');
+ program = itsalltext.factoryFile('/usr/bin/open');
} else {
/* Mac check because of
* https://bugzilla.mozilla.org/show_bug.cgi?id=322865 */
- if (!(ItsAllText.isDarwin() || program.isExecutable())) {
+ if (!(itsalltext.isDarwin() || program.isExecutable())) {
throw {name: "NS_ERROR_FILE_ACCESS_DENIED"};
}
args = [filename];
@@ -407,14 +407,14 @@ CacheObj.prototype.edit = function (extension, clobber) {
} catch (e) {
params = { out: null,
exists: program ? program.exists() : false,
- path: ItsAllText.preferences.editor,
+ path: itsalltext.preferences.editor,
exception: e.name };
window.openDialog('chrome://itsalltext/content/badeditor.xul',
null,
"chrome, titlebar, toolbar, centerscreen, modal",
params);
if (params.out !== null && params.out.do_preferences) {
- ItsAllText.openPreferences(true);
+ itsalltext.openPreferences(true);
this.edit(extension);
}
}
@@ -428,7 +428,7 @@ CacheObj.prototype.remove = function () {
try {
this.file.remove();
} catch (e) {
- //disabled-debug -- ItsAllText.debug('remove(', this.file.path, '): ', e);
+ //disabled-debug -- itsalltext.debug('remove(', this.file.path, '): ', e);
return false;
}
}
@@ -454,7 +454,7 @@ CacheObj.prototype.read = function () {
istream = Components.classes["@mozilla.org/intl/converter-input-stream;1"].
createInstance(Components.interfaces.nsIConverterInputStream);
- istream.init(fis, ItsAllText.getCharset(), 4096, DEFAULT_REPLACEMENT_CHARACTER);
+ istream.init(fis, itsalltext.getCharset(), 4096, DEFAULT_REPLACEMENT_CHARACTER);
str = {};
while (istream.readString(4096, str) !== 0) {
@@ -515,13 +515,13 @@ CacheObj.prototype.fadeStep = function (background_pallet, color_pallet, step, d
*/
CacheObj.prototype.fade = function (steps, delay) {
var color = this.getStyle(this.node, 'color'),
- color_stop = new ItsAllText.Color(color),
- color_start = new ItsAllText.Color('black'),
+ color_stop = new itsalltext.Color(color),
+ color_start = new itsalltext.Color('black'),
color_pallet = color_start.blend(color_stop, steps),
background = this.getStyle(this.node, 'background-color'),
- background_stop = new ItsAllText.Color(background),
- background_start = new ItsAllText.Color('yellow'),
+ background_stop = new itsalltext.Color(background),
+ background_start = new itsalltext.Color('yellow'),
background_pallet = background_start.blend(background_stop, steps);
setTimeout(this.fadeStep(background_pallet, color_pallet, 0, delay), delay);
};
@@ -552,9 +552,9 @@ CacheObj.prototype.update = function () {
* Capture keypresses to do the hotkey edit.
*/
CacheObj.prototype.hitched_keypress = function (event) {
- ItsAllText.debug(this.uuid, 'keypress()', event);
- var km = ItsAllText.marshalKeyEvent(event), cobj;
- if (km === ItsAllText.preferences.hotkey) {
+ itsalltext.debug(this.uuid, 'keypress()', event);
+ var km = itsalltext.marshalKeyEvent(event), cobj;
+ if (km === itsalltext.preferences.hotkey) {
cobj = CacheObj.get(event.target);
cobj.edit();
event.stopPropagation();
@@ -567,7 +567,7 @@ CacheObj.prototype.hitched_keypress = function (event) {
* @param {Object} event The event that triggered this.
*/
CacheObj.prototype.onClick = function (event) {
- //disabled-debug -- ItsAllText.debug('onClick()', event);
+ //disabled-debug -- itsalltext.debug('onClick()', event);
var cobj = CacheObj.get(event.target);
cobj.edit();
event.stopPropagation();
@@ -593,7 +593,7 @@ CacheObj.prototype.onContext = function (event) {
* sane....openPopup()
*/
var cobj = CacheObj.get(event.target),
- popup = ItsAllText.rebuildMenu(cobj.uid);
+ popup = itsalltext.rebuildMenu(cobj.uid);
popup.openPopup(cobj.button, 'end_before',
0, 0,
@@ -618,44 +618,44 @@ CacheObj.prototype.addGumDrop = function () {
nextSibling;
try {
- ItsAllText.monitor.incrementLock();
+ itsalltext.monitor.incrementLock();
if (cache_object.button !== null) {
cache_object.adjust();
- ItsAllText.monitor.decrementLock();
+ itsalltext.monitor.decrementLock();
return; /*already done*/
}
// Add the textarea mouseovers even if the button is disabled
node = cache_object.node;
- ItsAllText.debug('addGumDrop', cache_object.uuid, node);
+ itsalltext.debug('addGumDrop', cache_object.uuid, node);
if (!cache_object.is_listening) {
- 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", 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", cache_object.keypress, false);
cache_object.is_listening = true;
}
- if (ItsAllText.getDisableGumdrops()) {
- ItsAllText.monitor.decrementLock();
+ if (itsalltext.getDisableGumdrops()) {
+ itsalltext.monitor.decrementLock();
return;
}
- ItsAllText.debug('addGumDrop()', cache_object);
+ itsalltext.debug('addGumDrop()', cache_object);
doc = node.ownerDocument;
if (!node.parentNode) {
- ItsAllText.monitor.decrementLock();
+ itsalltext.monitor.decrementLock();
return;
}
- gumdrop = doc.createElementNS(ItsAllText.XHTMLNS, "img");
+ gumdrop = doc.createElementNS(itsalltext.XHTMLNS, "img");
gumdrop.setAttribute('src', this.gumdrop_url);
- if (ItsAllText.getDebug()) {
+ if (itsalltext.getDebug()) {
gumdrop.setAttribute('title', cache_object.node_id);
} else {
- gumdrop.setAttribute('title', ItsAllText.localeString('program_name'));
+ gumdrop.setAttribute('title', itsalltext.localeString('program_name'));
}
cache_object.button = gumdrop; // Store it for easy finding in the future.
@@ -671,11 +671,11 @@ CacheObj.prototype.addGumDrop = function () {
gumdrop.style.setProperty('width', this.gumdrop_width + 'px', 'important');
gumdrop.style.setProperty('height', this.gumdrop_height + 'px', 'important');
- gumdrop.setUserData(ItsAllText.MYSTRING + '_UID', cache_object.uid, null);
+ gumdrop.setUserData(itsalltext.MYSTRING + '_UID', cache_object.uid, null);
// Click event handlers
- ItsAllText.listen(gumdrop, "click", ItsAllText.hitch(cache_object, 'onClick'), false);
- ItsAllText.listen(gumdrop, "contextmenu", ItsAllText.hitch(cache_object, 'onContext'), false);
+ itsalltext.listen(gumdrop, "click", itsalltext.hitch(cache_object, 'onClick'), false);
+ itsalltext.listen(gumdrop, "contextmenu", itsalltext.hitch(cache_object, 'onContext'), false);
// Insert it into the document
parent = node.parentNode;
@@ -688,15 +688,15 @@ CacheObj.prototype.addGumDrop = function () {
}
// Add mouseovers/outs
- ItsAllText.listen(gumdrop, 'mouseover', ItsAllText.hitch(cache_object, 'mouseover'), false);
- ItsAllText.listen(gumdrop, 'mouseout', ItsAllText.hitch(cache_object, 'mouseout'), false);
+ itsalltext.listen(gumdrop, 'mouseover', itsalltext.hitch(cache_object, 'mouseover'), false);
+ itsalltext.listen(gumdrop, 'mouseout', itsalltext.hitch(cache_object, 'mouseout'), false);
cache_object.mouseout(null);
cache_object.adjust();
} catch (e) {
- ItsAllText.monitor.decrementLock();
+ itsalltext.monitor.decrementLock();
}
- ItsAllText.monitor.decrementLock();
+ itsalltext.monitor.decrementLock();
};
/**
@@ -714,7 +714,7 @@ CacheObj.prototype.adjust = function () {
coord,
pos;
- if (ItsAllText.getDisableGumdrops()) {
+ if (itsalltext.getDisableGumdrops()) {
if (gumdrop && gumdrop.style.display != 'none') {
gumdrop.style.setProperty('display', 'none', 'important');
}
@@ -743,7 +743,7 @@ CacheObj.prototype.adjust = function () {
* Position the gumdrop.
* Updates in case the DOM changes.
*/
- pos = ItsAllText.preferences.gumdrop_position;
+ pos = itsalltext.preferences.gumdrop_position;
if (pos === 'upper-right' || pos === 'lower-right') {
left = Math.max(1, el.offsetWidth - this.gumdrop_width);
} else {
@@ -758,7 +758,7 @@ CacheObj.prototype.adjust = function () {
left += el.offsetLeft;
top += el.offsetTop;
} else {
- coord = ItsAllText.getContainingBlockOffset(el, gumdrop.offsetParent);
+ coord = itsalltext.getContainingBlockOffset(el, gumdrop.offsetParent);
left += coord[0];
top += coord[1];
}
@@ -828,14 +828,14 @@ CacheObj.prototype.hashString = function (some_string) {
* @returns {String} the UID or null.
*/
CacheObj.get = function (node) {
- var str = ItsAllText.MYSTRING + "_UID",
+ var str = itsalltext.MYSTRING + "_UID",
id = null;
if (typeof(node) === 'string') {
id = node;
} else if (node && node.getUserData(str)) {
id = node.getUserData(str);
}
- return ItsAllText.getFromTracker(id);
+ return itsalltext.getFromTracker(id);
};
/**
@@ -847,7 +847,7 @@ CacheObj.get = function (node) {
*/
CacheObj.make = function (node, create_gumdrop) {
var cobj = CacheObj.get(node);
- ItsAllText.debug('CacheObj.make(',node,', ', create_gumdrop,') = ',cobj, ' : ', cobj ? cobj.uid : 'null');
+ itsalltext.debug('CacheObj.make(',node,', ', create_gumdrop,') = ',cobj, ' : ', cobj ? cobj.uid : 'null');
if (!cobj) {
cobj = new CacheObj(node);
if (create_gumdrop) {
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index c56d718..d2d7632 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -34,119 +34,6 @@ var ItsAllText = function () {
loadthings;
/**
- * A serial for tracking ids
- * @type Integer
- */
- that.serial_id = 0;
-
- /**
- * A constant, a string used for things like the preferences.
- * @type String
- */
- that.MYSTRING = 'itsalltext';
-
- /**
- * A constant, the version number. Set by the Makefile.
- * @type String
- */
- that.VERSION = '999.@@VERSION@@';
-
- /**
- * A constant, the url to the readme.
- * @type String
- */
- that.README = 'chrome://itsalltext/locale/readme.xhtml';
-
- /* The XHTML Namespace */
- that.XHTMLNS = "http://www.w3.org/1999/xhtml";
-
- /* The XUL Namespace */
- that.XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
- that.thread_id = Math.round(new Date().getTime() * Math.random());
-
- /**
- * Formats a locale string, replacing $N with the arguments in arr.
- * @param {String} name Locale property name
- * @param {Array} arr Array of strings to replace in the string.
- * @returns String
- */
- that.localeFormat = function (name, arr) {
- return this.getLocale().formatStringFromName(name, arr, arr.length);
- };
- /**
- * Returns the locale string matching name.
- * @param {String} name Locale property name
- * @returns String
- */
- that.localeString = function (name) {
- return this.getLocale().GetStringFromName(name);
- };
-
- /**
- * Create an error message from given arguments.
- * @param {Object} message One or more objects to be made into strings...
- */
- that.logString = function () {
- var args = Array.prototype.slice.apply(arguments, [0]),
- i;
- for (i = 0; i < args.length; i++) {
- try {
- args[i] = "" + args[i];
- } catch (e) {
- Components.utils.reportError(e);
- args[i] = 'toStringFailed';
- }
- }
- args.unshift(that.MYSTRING + ' [' + this.thread_id + ']:');
- return args.join(' ');
- };
-
- /**
- * This is a handy debug message. I'll remove it or disable it when
- * I release this.
- * @param {Object} message One or more objects can be passed in to display.
- */
- that.log = function () {
- const consoleService = Components.classes["@mozilla.org/consoleservice;1"];
- var message = that.logString.apply(that, arguments),
- obj = consoleService.getService(Components.interfaces.nsIConsoleService);
- try {
- // idiom: Convert arguments to an array for easy handling.
- obj.logStringMessage(message);
- } catch (e) {
- Components.utils.reportError(message);
- }
- };
-
- /**
- * Uses log iff debugging is turned on. Used for messages that need to
- * globally logged (firebug only logs locally).
- * @param {Object} message One or more objects can be passed in to display.
- */
- that.debuglog = function () {
- if (that.preferences.debug) {
- that.log.apply(that, arguments);
- }
- };
-
- /**
- * Displays debug information, if debugging is turned on.
- * Requires Firebug.
- * @param {Object} message One or more objects can be passed in to display.
- */
- that.debug = function () {
- if (that.preferences && that.preferences.debug) {
- var message = that.logString.apply(that, arguments);
- window.dump(message + '\n');
- try {
- Firebug.Console.logFormatted(arguments);
- } catch (e) {
- }
- }
- };
-
- /**
* A factory method to make an nsILocalFile object.
* @param {String} path A path to initialize the object with (optional).
* @returns {nsILocalFile}
@@ -181,18 +68,6 @@ var ItsAllText = function () {
return fobj;
};
- /* Clean the edit directory whenever we create a new window. */
- that.cleanEditDir();
-
- /* Load the various bits needed to make this work. */
- (function () {
- var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
- loader.loadSubScript('chrome://itsalltext/content/Color.js', that);
- loader.loadSubScript('chrome://itsalltext/content/monitor.js', that);
- loader.loadSubScript('chrome://itsalltext/content/cacheobj.js', that);
- that.monitor = new that.monitor(that);
- })();
-
/**
* Dictionary for storing the preferences in.
* @type Hash
@@ -667,6 +542,7 @@ var ItsAllText = function () {
// TODONOW: move to separate function
that.listen(window, 'load', function (event) {
//disabled-debug -- that.debug('!!load', event);
+
if (typeof(gBrowser) === 'undefined') {
that.monitor.registerPage(event);
} else {
@@ -698,6 +574,148 @@ var ItsAllText = function () {
that.monitor.destroy();
}, false);
+
+ /* Start your engines! */
+ this.init();
+};
+
+ItsAllText.prototype.init = function () {
+ /**
+ * A serial for tracking ids
+ * @type Integer
+ */
+ this.serial_id = 0;
+
+ /**
+ * A constant, a string used for things like the preferences.
+ * @type String
+ */
+ this.MYSTRING = 'itsalltext';
+
+ /**
+ * A constant, the version number. Set by the Makefile.
+ * @type String
+ */
+ this.VERSION = '999.@@VERSION@@';
+
+ /**
+ * A constant, the url to the readme.
+ * @type String
+ */
+ this.README = 'chrome://itsalltext/locale/readme.xhtml';
+
+ /* The XHTML Namespace */
+ this.XHTMLNS = "http://www.w3.org/1999/xhtml";
+
+ /* The XUL Namespace */
+ this.XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+
+ /* The monitor */
+ this.monitor = null;
+
+ /* For debugging */
+ this.thread_id = Math.round(new Date().getTime() * Math.random());
+
+ /* Clean the edit directory whenever we create a new window. */
+ this.cleanEditDir();
+
+ /* Load the various bits needed to make this work. */
+ this.initScripts();
+
+ /* Start the monitor */
+ var itsalltext = this;
+ setTimeout(function () {
+ itsalltext.monitor = new itsalltext.Monitor();
+ }, 1);
+}
+
+/* Load the various bits needed to make this work. */
+ItsAllText.prototype.initScripts = function() {
+ var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
+ loader.loadSubScript('chrome://itsalltext/content/Color.js', this);
+ loader.loadSubScript('chrome://itsalltext/content/monitor.js', this);
+ loader.loadSubScript('chrome://itsalltext/content/cacheobj.js', this);
+}
+
+/**
+ * Formats a locale string, replacing $N with the arguments in arr.
+ * @param {String} name Locale property name
+ * @param {Array} arr Array of strings to replace in the string.
+ * @returns String
+ */
+ItsAllText.prototype.localeFormat = function (name, arr) {
+ return this.getLocale().formatStringFromName(name, arr, arr.length);
+};
+/**
+ * Returns the locale string matching name.
+ * @param {String} name Locale property name
+ * @returns String
+ */
+ItsAllText.prototype.localeString = function (name) {
+ return this.getLocale().GetStringFromName(name);
+};
+
+/**
+ * Create an error message from given arguments.
+ * @param {Object} message One or more objects to be made into strings...
+ */
+ItsAllText.prototype.logString = function () {
+ var args = Array.prototype.slice.apply(arguments, [0]),
+ i;
+ for (i = 0; i < args.length; i++) {
+ try {
+ args[i] = "" + args[i];
+ } catch (e) {
+ Components.utils.reportError(e);
+ args[i] = 'toStringFailed';
+ }
+ }
+ args.unshift(this.MYSTRING + ' [' + this.thread_id + ']:');
+ return args.join(' ');
+};
+
+/**
+ * This is a handy debug message. I'll remove it or disable it when
+ * I release this.
+ * @param {Object} message One or more objects can be passed in to display.
+ */
+ItsAllText.prototype.log = function () {
+ const consoleService = Components.classes["@mozilla.org/consoleservice;1"];
+ var message = this.logString.apply(this, arguments),
+ obj = consoleService.getService(Components.interfaces.nsIConsoleService);
+ try {
+ // idiom: Convert arguments to an array for easy handling.
+ obj.logStringMessage(message);
+ } catch (e) {
+ Components.utils.reportError(message);
+ }
+};
+
+/**
+ * Uses log iff debugging is turned on. Used for messages that need to
+ * globally logged (firebug only logs locally).
+ * @param {Object} message One or more objects can be passed in to display.
+ */
+ItsAllText.prototype.debuglog = function () {
+ if (this.preferences.debug) {
+ this.log.apply(this, arguments);
+ }
+};
+
+/**
+ * Displays debug information, if debugging is turned on.
+ * Requires Firebug.
+ * @param {Object} message One or more objects can be passed in to display.
+ */
+ItsAllText.prototype.debug = function () {
+ if (this.preferences && this.preferences.debug) {
+ var message = this.logString.apply(this, arguments);
+ window.dump(message + '\n');
+ try {
+ Firebug.Console.logFormatted(arguments);
+ } catch (e) {
+ }
+ }
};
/**
@@ -742,7 +760,7 @@ ItsAllText.prototype.hitch = function (object, method) {
ItsAllText.prototype.listen = function (source, event, listener, opt_capture) {
opt_capture = !!opt_capture;
this.unlisten(source, event, listener, opt_capture);
- //disabled-debug -- this.debug("listen(%o, %o, -, %o)", source, event, opt_capture);
+ this.debug("listen(%o, %o, -, %o)", source, event, opt_capture);
if (source) {
source.addEventListener(event, listener, opt_capture);
}
@@ -936,10 +954,10 @@ ItsAllText.prototype.getLocale = function () {
obj = string_bundle.getService(Components.interfaces.nsIStringBundleService);
/**
* A localization bundle. Use it like so:
- * ItsAllText.locale.getStringFromName('blah');
+ * itsalltext.locale.getStringFromName('blah');
*/
return obj.createBundle("chrome://itsalltext/locale/itsalltext.properties");
};
-ItsAllText = new ItsAllText();
+var itsalltext = new ItsAllText();
diff --git a/src/chrome/content/itsalltext.xul b/src/chrome/content/itsalltext.xul
index 24d2756..e4e94b9 100644
--- a/src/chrome/content/itsalltext.xul
+++ b/src/chrome/content/itsalltext.xul
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE overlay SYSTEM "chrome://itsalltext/locale/itsalltext.dtd" >
-<overlay id="ItsAllTextOverlay"
+<overlay id="itsalltextOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://itsalltext/content/itsalltext.js" />
@@ -11,19 +11,19 @@
<menu id="itsalltext-contextmenu" label="&top.label;" accesskey="&top.key;">
<menupopup id="itsalltext-context-popup">
<menuitem label="&edit.label;"
- oncommand="ItsAllText.onEditNode(document.popupNode)"
+ oncommand="itsalltext.onEditNode(document.popupNode)"
accesskey="&edit.key;" />
<menuitem label="&newext.label;"
accesskey="&newext.key;"
- oncommand="ItsAllText.menuNewExtEdit(event);" />
+ oncommand="itsalltext.menuNewExtEdit(event);" />
<menuseparator/>
- <menuitem label=".txt" oncommand="ItsAllText.menuExtEdit(event, '.txt');"/>
+ <menuitem label=".txt" oncommand="itsalltext.menuExtEdit(event, '.txt');"/>
<menuseparator/>
<menuitem label="&readme.label;"
- oncommand="ItsAllText.openReadme();"/>
+ oncommand="itsalltext.openReadme();"/>
<menuitem label="&pref.label;"
accesskey="&pref.key;"
- oncommand="ItsAllText.openPreferences();"/>
+ oncommand="itsalltext.openPreferences();"/>
</menupopup>
</menu>
</popup>
@@ -34,15 +34,15 @@
<menupopup id="itsalltext-optionmenu">
<menuitem label="&newext.label;"
accesskey="&newext.key;"
- oncommand="ItsAllText.menuNewExtEdit(event);" />
+ oncommand="itsalltext.menuNewExtEdit(event);" />
<menuseparator/>
- <menuitem label=".txt" oncommand="ItsAllText.menuExtEdit(event,'.txt');"/>
+ <menuitem label=".txt" oncommand="itsalltext.menuExtEdit(event,'.txt');"/>
<menuseparator/>
<menuitem label="&readme.label;"
- oncommand="ItsAllText.openReadme();"/>
+ oncommand="itsalltext.openReadme();"/>
<menuitem label="&pref.label;"
accesskey="&pref.key;"
- oncommand="ItsAllText.openPreferences();"/>
+ oncommand="itsalltext.openPreferences();"/>
</menupopup>
</popupset>
</window>
@@ -55,10 +55,10 @@
insertbefore="sanitizeSeparator">
<menupopup>
<menuitem label="&readme.label;"
- oncommand="ItsAllText.openReadme();"/>
+ oncommand="itsalltext.openReadme();"/>
<menuitem label="&pref.label;"
accesskey="&pref.key;"
- oncommand="ItsAllText.openPreferences();"/>
+ oncommand="itsalltext.openPreferences();"/>
</menupopup>
</menu>
</menupopup>
diff --git a/src/chrome/content/monitor.js b/src/chrome/content/monitor.js
index dcdf23c..44c1d08 100644
--- a/src/chrome/content/monitor.js
+++ b/src/chrome/content/monitor.js
@@ -1,4 +1,4 @@
-/*extern HTMLDocument, gBrowser, ItsAllText */
+/*extern HTMLDocument, gBrowser, itsalltext */
/*jslint undef: true, evil: false, browser: true, white: true */
/*
* It's All Text! - Easy external editing of web forms.
@@ -18,28 +18,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-function monitor(iat) {
+function Monitor() {
var hitch_re = /^hitched_/,
method;
- this.iat = iat;
- //disabled-debug -- this.iat.debug('monitor');
+ itsalltext.debug('Monitor', itsalltext);
for (method in this) {
if (hitch_re.test(method)) {
- //disabled-debug -- this.iat.debug('hitching ', method, ' -> ', method.replace(hitch_re, ''));
- this[method.replace(hitch_re, '')] = this.iat.hitch(this, method);
+ //disabled-debug -- itsalltext.debug('hitching ', method, ' -> ', method.replace(hitch_re, ''));
+ this[method.replace(hitch_re, '')] = itsalltext.hitch(this, method);
}
}
}
-monitor.prototype.hitched_destroy = function () {
- delete this.iat;
+Monitor.prototype.hitched_destroy = function () {
+ delete itsalltext;
};
-monitor.prototype.hitched_restart = function () {
- var rate = this.iat.getRefresh(),
+Monitor.prototype.hitched_restart = function () {
+ var rate = itsalltext.getRefresh(),
id = this.id;
if (id) {
clearInterval(id);
@@ -51,24 +50,24 @@ monitor.prototype.hitched_restart = function () {
* Gets a page ready to be used by IAT.
* This is called as an event handler.
*/
-monitor.prototype.hitched_registerPage = function (event) {
+Monitor.prototype.hitched_registerPage = function (event) {
var doc, appContent;
if (event.originalTarget instanceof HTMLDocument) {
doc = event.originalTarget;
- //disabled-debug -- this.iat.debug('registerPage: ', doc && doc.location);
+ //disabled-debug -- itsalltext.debug('registerPage: ', doc && doc.location);
/* appContent is the browser chrome. */
appContent = document.getElementById("appcontent");
- this.iat.listen(appContent, 'DOMContentLoaded', this.startPage, true);
- this.iat.listen(document, 'unload', this.stopPage, true);
- this.iat.listen(gBrowser.tabContainer, 'TabSelect', this.watcher, true);
+ itsalltext.listen(appContent, 'DOMContentLoaded', this.startPage, true);
+ itsalltext.listen(document, 'unload', this.stopPage, true);
+ itsalltext.listen(gBrowser.tabContainer, 'TabSelect', this.watcher, true);
this.startPage({originalTarget: doc});
- //disabled-debug -- this.iat.debug('RegisterPage: END');
+ //disabled-debug -- itsalltext.debug('RegisterPage: END');
}
};
/* Finds all nodes under a doc; includes iframes and frames. */
-monitor.prototype.hitched_findnodes = function (doc) {
+Monitor.prototype.hitched_findnodes = function (doc) {
if (!doc) {
return [];
}
@@ -114,12 +113,12 @@ monitor.prototype.hitched_findnodes = function (doc) {
* This is called repeatedly and regularly to trigger updates for the
* cache objects in the page.
*/
-monitor.prototype.hitched_watcher = function (offset, init) {
+Monitor.prototype.hitched_watcher = function (offset, init) {
// If it's a special number or it's an event, then we need to init.
if (offset.type && offset.type === 'TabSelect') {
init = true;
}
- var rate = this.iat.getRefresh(),
+ var rate = itsalltext.getRefresh(),
now = Date.now(),
doc,
nodes = [],
@@ -128,7 +127,7 @@ monitor.prototype.hitched_watcher = function (offset, init) {
node;
if (!init && now - this.last_watcher_call < Math.round(rate * 0.9)) {
- //disabled-debug -- this.iat.debug('watcher(', offset, '/', (now - this.last_watcher_call), ') -- skipping catchup refresh');
+ //disabled-debug -- itsalltext.debug('watcher(', offset, '/', (now - this.last_watcher_call), ') -- skipping catchup refresh');
return;
}
this.last_watcher_call = now;
@@ -140,16 +139,16 @@ monitor.prototype.hitched_watcher = function (offset, init) {
/* If we're in a tabbed browser. */
doc = gBrowser.selectedBrowser.contentDocument;
}
- //disabled-debug -- this.iat.debug('watcher: ', offset, init, doc && doc.location);
+ //disabled-debug -- itsalltext.debug('watcher: ', offset, init, doc && doc.location);
nodes = this.findnodes(doc);
/* Now that we have the nodes, walk through and either make or
* get the cache objects and update them. */
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
if (init) {
- cobj = ItsAllText.CacheObj.make(node, this.isHTML(doc));
+ cobj = itsalltext.CacheObj.make(node, this.isHTML(doc));
} else {
- cobj = ItsAllText.CacheObj.get(node);
+ cobj = itsalltext.CacheObj.get(node);
}
if (cobj) {
cobj.update();
@@ -157,26 +156,26 @@ monitor.prototype.hitched_watcher = function (offset, init) {
}
};
-monitor.prototype._lock_count = 0;
+Monitor.prototype._lock_count = 0;
-monitor.prototype.hitched_incrementLock = function () {
+Monitor.prototype.hitched_incrementLock = function () {
this._lock_count ++;
};
-monitor.prototype.hitched_decrementLock = function () {
+Monitor.prototype.hitched_decrementLock = function () {
this._lock_count --;
};
-monitor.prototype.hitched_isLocked = function () {
+Monitor.prototype.hitched_isLocked = function () {
return this._lock_count > 0;
};
-monitor.prototype.hitched_handleSubtreeModified = function (event) {
+Monitor.prototype.hitched_handleSubtreeModified = function (event) {
var has_textareas;
if (this.isLocked()) {
return;
}
has_textareas = event.originalTarget.getElementsByTagName('textarea').length > 0;
if (has_textareas) {
- //disabled-debug -- ItsAllText.debug('handleSubtreeModified: %o', event.target);
+ //disabled-debug -- itsalltext.debug('handleSubtreeModified: %o', event.target);
try {
// Ignore events while adding the gumdrops.
this.incrementLock();
@@ -188,10 +187,10 @@ monitor.prototype.hitched_handleSubtreeModified = function (event) {
}
};
-monitor.prototype.hitched_startPage = function (event, force) {
+Monitor.prototype.hitched_startPage = function (event, force) {
var doc = event.originalTarget,
unsafeWin;
- //disabled-debug -- this.iat.debug('startPage', doc && doc.location, force);
+ //disabled-debug -- itsalltext.debug('startPage', doc && doc.location, force);
if (!(force || this.isHTML(doc))) {
this.stopPage(event);
return;
@@ -199,11 +198,11 @@ monitor.prototype.hitched_startPage = function (event, force) {
unsafeWin = doc.defaultView.wrappedJSObject;
if (unsafeWin) {
- this.iat.listen(unsafeWin, 'pagehide', this.stopPage);
+ itsalltext.listen(unsafeWin, 'pagehide', this.stopPage);
}
// Listen for the subtree being modified.
- this.iat.listen(unsafeWin, 'DOMSubtreeModified', this.handleSubtreeModified);
+ itsalltext.listen(unsafeWin, 'DOMSubtreeModified', this.handleSubtreeModified);
// Kick off a watcher now...
this.incrementLock();
@@ -214,30 +213,30 @@ monitor.prototype.hitched_startPage = function (event, force) {
this.restart();
};
-monitor.prototype.hitched_stopPage = function (event) {
+Monitor.prototype.hitched_stopPage = function (event) {
var doc = event.originalTarget,
unsafeWin;
- //disabled-debug -- this.iat.debug('stopPage', doc && doc.location);
+ //disabled-debug -- itsalltext.debug('stopPage', doc && doc.location);
unsafeWin = doc.defaultView.wrappedJSObject;
- if (unsafeWin) {
- this.iat.unlisten(unsafeWin, 'pagehide', this.stopPage);
+ if (unsafeWin && itsalltext) {
+ itsalltext.unlisten(unsafeWin, 'pagehide', this.stopPage);
}
};
-monitor.prototype.isXUL = function (doc) {
+Monitor.prototype.isXUL = function (doc) {
var contentType = doc && doc.contentType,
is_xul = (contentType == 'application/vnd.mozilla.xul+xml'),
is_my_readme;
try {
- is_my_readme = location && location.href == this.iat.README;
+ is_my_readme = location && location.href == itsalltext.README;
} catch (e) {
is_my_readme = false;
}
return is_xul && !is_my_readme;
};
-monitor.prototype.isHTML = function (doc) {
+Monitor.prototype.isHTML = function (doc) {
var contentType,
location,
is_html,
@@ -254,7 +253,7 @@ monitor.prototype.isHTML = function (doc) {
location.protocol !== 'about:' &&
location.protocol !== 'chrome:';
try {
- is_my_readme = location && location.href == this.iat.README;
+ is_my_readme = location && location.href == itsalltext.README;
/*
* Avoiding this error.... I hope.
* uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMLocation.href]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: chrome://itsalltext/chrome/itsalltext.js :: anonymous :: line 634" data: no]
diff --git a/src/chrome/content/newextension.xul b/src/chrome/content/newextension.xul
index 8b1a16a..a2c9217 100644
--- a/src/chrome/content/newextension.xul
+++ b/src/chrome/content/newextension.xul
@@ -4,11 +4,11 @@
<!DOCTYPE newextwindow SYSTEM "chrome://itsalltext/locale/newextension.dtd" >
<dialog
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- id="ItsAllTextNewExtension"
+ id="itsalltextNewExtension"
title="&title;"
ondialogaccept="return onOK();"
persist="screenX screenY width height"
- windowtype="ItsAllTextWindowType">
+ windowtype="itsalltextWindowType">
<script type="application/x-javascript" src="chrome://itsalltext/content/newextension.js"/>
<grid>
diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 93c5f44..6261a3f 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -1,4 +1,4 @@
-/*extern Components, ItsAllText */
+/*extern Components, itsalltext */
/*jslint undef: true, nomen: true, evil: false, browser: true, white: true */
// @todo [6] [pref] Better strategy for getting the default editor: EDITOR env variable or view_source.editor.path
// @todo [8] [pref] Option to make the textarea uneditable when using editor.
@@ -47,7 +47,7 @@ function pref_editor_select() {
function update_hotkey(disp) {
var str,
- km = ItsAllText.preferences.hotkey;
+ km = itsalltext.preferences.hotkey;
if (typeof(km) === 'undefined') {
setTimeout(function () {
update_hotkey(disp);
@@ -57,14 +57,14 @@ function update_hotkey(disp) {
if (km === '') {
str = '<none>';
} else {
- str = ItsAllText.keyMarshalToString(km);
+ str = itsalltext.keyMarshalToString(km);
}
document.getElementById(disp).value = str;
}
function pref_grab(disp, e) {
e.preventDefault();
- var km = ItsAllText.marshalKeyEvent(e);
+ var km = itsalltext.marshalKeyEvent(e);
const empty_re = /:0:0$/;
if (empty_re.test(km) || // Various Alt/Meta keys
km === '0:0:0:0:0:8' || // Backspace
@@ -72,7 +72,7 @@ function pref_grab(disp, e) {
km === '0:0:0:0:0:46') { // Del
km = '';
}
- ItsAllText.preferences.private_set('hotkey', km);
+ itsalltext.preferences.private_set('hotkey', km);
update_hotkey(disp);
}
--
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