mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-12 06:35:47 +01:00
Merge default.
--HG-- branch : mode-refactoring
This commit is contained in:
@@ -98,10 +98,10 @@ function defineModule(name, params) {
|
||||
module.NAME = name;
|
||||
module.EXPORTED_SYMBOLS = params.exports || [];
|
||||
defineModule.loadLog.push("defineModule " + name);
|
||||
for(let [, mod] in Iterator(params.require || []))
|
||||
for (let [, mod] in Iterator(params.require || []))
|
||||
require(module, mod);
|
||||
|
||||
for(let [, mod] in Iterator(params.use || []))
|
||||
for (let [, mod] in Iterator(params.use || []))
|
||||
if (loaded.hasOwnProperty(mod))
|
||||
require(module, mod, "use");
|
||||
else {
|
||||
@@ -142,7 +142,7 @@ defineModule.time = function time(major, minor, func, self) {
|
||||
|
||||
function endModule() {
|
||||
defineModule.loadLog.push("endModule " + currentModule.NAME);
|
||||
for(let [, mod] in Iterator(use[currentModule.NAME] || []))
|
||||
for (let [, mod] in Iterator(use[currentModule.NAME] || []))
|
||||
require(mod, currentModule.NAME, "use");
|
||||
loaded[currentModule.NAME] = 1;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ function debuggerProperties(obj) {
|
||||
* @returns {Generator}
|
||||
*/
|
||||
function prototype(obj)
|
||||
obj.__proto__ || Object.getPrototypeOf(obj) ||
|
||||
obj.__proto__ || Object.getPrototypeOf(obj) ||
|
||||
XPCNativeWrapper.unwrap(obj).__proto__ ||
|
||||
Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj));
|
||||
function properties(obj, prototypes, debugger_) {
|
||||
@@ -373,7 +373,7 @@ set.remove = function (set, key) {
|
||||
* @returns {Generator}
|
||||
*/
|
||||
function iter(obj) {
|
||||
if (ctypes && obj instanceof ctypes.CData) {
|
||||
if (ctypes && ctypes.CData && obj instanceof ctypes.CData) {
|
||||
while (obj.constructor instanceof ctypes.PointerType)
|
||||
obj = obj.contents;
|
||||
if (obj.constructor instanceof ctypes.ArrayType)
|
||||
@@ -1128,7 +1128,7 @@ const array = Class("array", Array, {
|
||||
*/
|
||||
zip: function zip(ary1, ary2) {
|
||||
let res = [];
|
||||
for(let [i, item] in Iterator(ary1))
|
||||
for (let [i, item] in Iterator(ary1))
|
||||
res.push([item, i in ary2 ? ary2[i] : ""]);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ defineModule("bookmarkcache", {
|
||||
require: ["services", "storage", "util"]
|
||||
});
|
||||
|
||||
|
||||
const Bookmark = Struct("url", "title", "icon", "keyword", "tags", "id");
|
||||
const Bookmark = Struct("url", "title", "icon", "post", "keyword", "tags", "id");
|
||||
const Keyword = Struct("keyword", "title", "icon", "url");
|
||||
Bookmark.defaultValue("icon", function () BookmarkCache.getFavicon(this.url));
|
||||
Bookmark.prototype.__defineGetter__("extra", function () [
|
||||
@@ -19,12 +18,15 @@ Bookmark.prototype.__defineGetter__("extra", function () [
|
||||
["tags", this.tags.join(", "), "Tag"]
|
||||
].filter(function (item) item[1]));
|
||||
|
||||
const bookmarks = services.get("bookmarks");
|
||||
const history = services.get("history");
|
||||
const tagging = services.get("tagging");
|
||||
const name = "bookmark-cache";
|
||||
const annotation = services.get("annotation");
|
||||
const bookmarks = services.get("bookmarks");
|
||||
const history = services.get("history");
|
||||
const tagging = services.get("tagging");
|
||||
const name = "bookmark-cache";
|
||||
|
||||
const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
||||
POST: "bookmarkProperties/POSTData",
|
||||
|
||||
init: function init() {
|
||||
bookmarks.addObserver(this, false);
|
||||
},
|
||||
@@ -33,17 +35,14 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
|
||||
get bookmarks() Class.replaceProperty(this, "bookmarks", this.load()),
|
||||
|
||||
get keywords() array.toObject([[b.keyword, b] for (b in this) if (b.keyword)]),
|
||||
|
||||
rootFolders: ["toolbarFolder", "bookmarksMenuFolder", "unfiledBookmarksFolder"]
|
||||
.map(function (s) bookmarks[s]),
|
||||
|
||||
_deleteBookmark: function deleteBookmark(id) {
|
||||
let length = this.bookmarks.length;
|
||||
let result;
|
||||
this.bookmarks = this.bookmarks.filter(function (item) {
|
||||
if (item.id == id)
|
||||
result = item;
|
||||
return item.id != id;
|
||||
});
|
||||
let result = this.bookmarks[item.id] || null;
|
||||
delete this.bookmarks[id];
|
||||
return result;
|
||||
},
|
||||
|
||||
@@ -53,7 +52,8 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
let uri = util.newURI(node.uri);
|
||||
let keyword = bookmarks.getKeywordForBookmark(node.itemId);
|
||||
let tags = tagging.getTagsForURI(uri, {}) || [];
|
||||
return Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId);
|
||||
let post = BookmarkCache.getAnnotation(node.itemId, this.POST);
|
||||
return Bookmark(node.uri, node.title, node.icon && node.icon.spec, post, keyword, tags, node.itemId);
|
||||
},
|
||||
|
||||
readBookmark: function readBookmark(id) {
|
||||
@@ -84,11 +84,9 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
return this.rootFolders.indexOf(root) >= 0;
|
||||
},
|
||||
|
||||
get keywords() [Keyword(k.keyword, k.title, k.icon, k.url) for ([, k] in Iterator(this.bookmarks)) if (k.keyword)],
|
||||
|
||||
// Should be made thread safe.
|
||||
load: function load() {
|
||||
let bookmarks = [];
|
||||
let bookmarks = {};
|
||||
|
||||
let folders = this.rootFolders.slice();
|
||||
let query = history.getNewQuery();
|
||||
@@ -106,7 +104,7 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
if (node.type == node.RESULT_TYPE_FOLDER) // folder
|
||||
folders.push(node.itemId);
|
||||
else if (node.type == node.RESULT_TYPE_URI) // bookmark
|
||||
bookmarks.push(this._loadBookmark(node));
|
||||
bookmarks[node.itemId] = this._loadBookmark(node);
|
||||
}
|
||||
|
||||
// close a container after using it!
|
||||
@@ -120,7 +118,7 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
if (bookmarks.getItemType(itemId) == bookmarks.TYPE_BOOKMARK) {
|
||||
if (this.isBookmark(itemId)) {
|
||||
let bmark = this._loadBookmark(this.readBookmark(itemId));
|
||||
this.bookmarks.push(bmark);
|
||||
this.bookmarks[bmark.id] = bmark;
|
||||
storage.fireEvent(name, "add", bmark);
|
||||
}
|
||||
}
|
||||
@@ -132,8 +130,12 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
},
|
||||
onItemChanged: function onItemChanged(itemId, property, isAnnotation, value) {
|
||||
if (isAnnotation)
|
||||
return;
|
||||
let bookmark = bookmarkcache.bookmarks.filter(function (item) item.id == itemId)[0];
|
||||
if (property === this.POST)
|
||||
[property, value] = ["post", BookmarkCache.getAnnotation(itemId, this.POST)];
|
||||
else
|
||||
return;
|
||||
|
||||
let bookmark = this.bookmarks[itemId];
|
||||
if (bookmark) {
|
||||
if (property == "tags")
|
||||
value = tagging.getTagsForURI(util.newURI(bookmark.url), {});
|
||||
@@ -144,6 +146,9 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
}
|
||||
}
|
||||
}, {
|
||||
getAnnotation: function getAnnotation(item, anno)
|
||||
annotation.itemHasAnnotation(item, anno) ?
|
||||
annotation.getItemAnnotation(item, anno) : null,
|
||||
getFavicon: function getFavicon(uri) {
|
||||
try {
|
||||
return service.get("favicon").getFaviconImageForPage(util.newURI(uri)).spec;
|
||||
|
||||
@@ -18,6 +18,7 @@ const Services = Module("Services", {
|
||||
this.classes = {};
|
||||
this.services = {};
|
||||
|
||||
this.add("annotation", "@mozilla.org/browser/annotation-service;1", Ci.nsIAnnotationService);
|
||||
this.add("appStartup", "@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup);
|
||||
this.add("autoCompleteSearch", "@mozilla.org/autocomplete/search;1?name=history", Ci.nsIAutoCompleteSearch);
|
||||
this.add("bookmarks", "@mozilla.org/browser/nav-bookmarks-service;1", Ci.nsINavBookmarksService);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user