1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-30 17:15:47 +01:00

Merge default.

--HG--
branch : mode-refactoring
This commit is contained in:
Kris Maglione
2010-10-09 16:48:11 -04:00
36 changed files with 266 additions and 157 deletions

View File

@@ -27,7 +27,7 @@ const Util = Module("Util", {
dactyl: {
__noSuchMethod__: function (meth, args) {
let win = util.activeWindow;
if(win && win.dactyl)
if (win && win.dactyl)
return win.dactyl[meth].apply(win.dactyl, args);
return null;
}
@@ -247,6 +247,10 @@ const Util = Module("Util", {
util.dump((arguments.length == 0 ? "Stack" : msg) + "\n" + stack + "\n");
},
editableInputs: set(["date", "datetime", "datetime-local", "email", "file",
"month", "number", "password", "range", "search",
"tel", "text", "time", "url", "week"]),
/**
* Converts HTML special characters in <b>str</b> to the equivalent HTML
* entities.
@@ -522,9 +526,7 @@ const Util = Module("Util", {
* @returns {nsIURI}
*/
// FIXME: createURI needed too?
newURI: function (uri) {
return services.get("io").newURI(uri, null, null);
},
newURI: function (uri, charset, base) services.get("io").newURI(uri, charset, base),
/**
* Pretty print a JavaScript object. Use HTML markup to color certain items
@@ -642,6 +644,50 @@ const Util = Module("Util", {
return color ? string : [s for each (s in string)].join("");
},
/**
* Parses the fields of a form and returns a URL/POST-data pair
* that is the equivalent of submitting the form.
*
* @param {nsINode} field One of the fields of the given form.
*/
// Nuances gleaned from browser.jar/content/browser/browser.js
parseForm: function parseForm(field) {
function encode(name, value, param) {
if (param)
value = "%s";
if (post)
return name + "=" + value;
return encodeURIComponent(name) + "=" + (param ? value : encodeURIComponent(value));
}
let form = field.form;
let doc = form.ownerDocument;
let charset = doc.charset;
let uri = util.newURI(doc.baseURI.replace(/\?.*/, ""), charset);
let url = util.newURI(form.action, charset, uri).spec;
let post = form.method.toUpperCase() == "POST";
let elems = [];
if (field instanceof Ci.nsIDOMHTMLInputElement && field.type == "submit")
elems.push(encode(field.name, field.value));
for (let [,elem] in iter(form.elements)) {
if (set.has(util.editableInputs, elem.type)
|| /^(?:hidden|textarea)$/.test(elem.type)
|| elem.checked && /^(?:checkbox|radio)$/.test(elem.type))
elems.push(encode(elem.name, elem.value, elem === field));
else if (elem instanceof Ci.nsIDOMHTMLSelectElement) {
for (let [,opt] in Iterator(elem.options))
if (opt.selected)
elems.push(encode(elem.name, opt.value));
}
}
if (post)
return [url, elems.map(encodeURIComponent).join('&'), elems];
return [url + "?" + elems.join('&'), null];
},
/**
* A generator that returns the values between <b>start</b> and <b>end</b>,
* in <b>step</b> increments.