]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/bookmarkcache.jsm
Import r6976 from upstream hg supporting Firefox up to 25.*
[dactyl.git] / common / modules / bookmarkcache.jsm
index 55328a1fe3aa8dfe4c8db978fd437aac7bfcad08..031618941e915c2e2d6121f7cad5344085be185a 100644 (file)
@@ -1,14 +1,13 @@
-// Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail>
+// Copyright ©2008-2013 Kris Maglione <maglione.k at Gmail>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
 
-Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("bookmarkcache", {
     exports: ["Bookmark", "BookmarkCache", "Keyword", "bookmarkcache"],
     require: ["services", "util"]
-}, this);
+});
 
 this.lazyRequire("storage", ["storage"]);
 
@@ -28,7 +27,7 @@ update(Bookmark.prototype, {
     get extra() [
         ["keyword", this.keyword,         "Keyword"],
         ["tags",    this.tags.join(", "), "Tag"]
-    ].filter(function (item) item[1]),
+    ].filter(item => item[1]),
 
     get uri() newURI(this.url),
     set uri(uri) {
@@ -42,7 +41,19 @@ update(Bookmark.prototype, {
         if (!this.charset || this.charset === "UTF-8")
             return encodeURIComponent(str);
         let conv = services.CharsetConv(this.charset);
-        return escape(conv.ConvertFromUnicode(str) + conv.Finish());
+        return escape(conv.ConvertFromUnicode(str) + conv.Finish()).replace(/\+/g, encodeURIComponent);
+    },
+
+    get folder() {
+        let res = [];
+        res.toString = function () this.join("/");
+
+        let id = this.id, parent, title;
+        while ((id    = services.bookmarks.getFolderIdForItem(id)) &&
+               (title = services.bookmarks.getItemTitle(id)))
+            res.push(title);
+
+        return res.reverse();
     }
 })
 Bookmark.prototype.members.uri = Bookmark.prototype.members.url;
@@ -79,7 +90,7 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
     keywords: Class.Memoize(function () array.toObject([[b.keyword, b] for (b in this) if (b.keyword)])),
 
     rootFolders: ["toolbarFolder", "bookmarksMenuFolder", "unfiledBookmarksFolder"]
-        .map(function (s) services.bookmarks[s]),
+        .map(s => services.bookmarks[s]),
 
     _deleteBookmark: function deleteBookmark(id) {
         let result = this.bookmarks[id] || null;
@@ -94,8 +105,8 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
         let uri = newURI(node.uri);
         let keyword = services.bookmarks.getKeywordForBookmark(node.itemId);
 
-        let tags = tags in node ? (node.tags ? node.tags.split(/, /g) : [])
-                                : services.tagging.getTagsForURI(uri, {}) || [];
+        let tags = "tags" in node ? (node.tags ? node.tags.split(/, /g) : [])
+                                  : services.tagging.getTagsForURI(uri, {}) || [];
 
         let post = BookmarkCache.getAnnotation(node.itemId, this.POST);
         let charset = BookmarkCache.getAnnotation(node.itemId, this.CHARSET);
@@ -172,7 +183,11 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
         let query = services.history.getNewQuery();
         let options = services.history.getNewQueryOptions();
         options.queryType = options.QUERY_TYPE_BOOKMARKS;
-        options.excludeItemIfParentHasAnnotation = "livemark/feedURI";
+        try {
+            // https://bugzil.la/702639
+            options.excludeItemIfParentHasAnnotation = "livemark/feedURI";
+        }
+        catch (e) {}
 
         let { root } = services.history.executeQuery(query, options);
         root.containerOpen = true;
@@ -247,4 +262,4 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
 
 endModule();
 
-// vim: set fdm=marker sw=4 sts=4 et ft=javascript:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: