//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";
defineModule("bookmarkcache", {
exports: ["Bookmark", "BookmarkCache", "Keyword", "bookmarkcache"],
defineModule("bookmarkcache", {
exports: ["Bookmark", "BookmarkCache", "Keyword", "bookmarkcache"],
- require: ["services", "storage", "util"]
-}, this);
+ require: ["services", "util"]
+});
+
+this.lazyRequire("storage", ["storage"]);
+
+function newURI(url, charset, base) {
+ try {
+ return services.io.newURI(url, charset, base);
+ }
+ catch (e) {
+ throw Error(e);
+ }
+}
var Bookmark = Struct("url", "title", "icon", "post", "keyword", "tags", "charset", "id");
var Keyword = Struct("keyword", "title", "icon", "url");
var Bookmark = Struct("url", "title", "icon", "post", "keyword", "tags", "charset", "id");
var Keyword = Struct("keyword", "title", "icon", "url");
get extra() [
["keyword", this.keyword, "Keyword"],
["tags", this.tags.join(", "), "Tag"]
get extra() [
["keyword", this.keyword, "Keyword"],
["tags", this.tags.join(", "), "Tag"]
- get uri() util.newURI(this.url),
+ get uri() newURI(this.url),
+ set uri(uri) {
+ let tags = this.tags;
+ this.tags = null;
+ services.bookmarks.changeBookmarkURI(this.id, uri);
+ this.tags = tags;
+ },
encodeURIComponent: function _encodeURIComponent(str) {
if (!this.charset || this.charset === "UTF-8")
return encodeURIComponent(str);
let conv = services.CharsetConv(this.charset);
encodeURIComponent: function _encodeURIComponent(str) {
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.setter("url", function (val) {
- let tags = this.tags;
- this.tags = null;
- services.bookmarks.changeBookmarkURI(this.id, val);
- this.tags = tags;
-});
+Bookmark.setter("url", function (val) { this.uri = isString(val) ? newURI(val) : val; });
Bookmark.setter("title", function (val) { services.bookmarks.setItemTitle(this.id, val); });
Bookmark.setter("post", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.POST, val); });
Bookmark.setter("charset", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.CHARSET, val); });
Bookmark.setter("title", function (val) { services.bookmarks.setItemTitle(this.id, val); });
Bookmark.setter("post", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.POST, val); });
Bookmark.setter("charset", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.CHARSET, val); });
- keywords: Class.memoize(function () array.toObject([[b.keyword, b] for (b in this) if (b.keyword)])),
+ keywords: Class.Memoize(function () array.toObject([[b.keyword, b] for (b in this) if (b.keyword)])),
- let tags = 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);
return Bookmark(node.uri, node.title, node.icon && node.icon.spec, post, keyword, tags, charset, node.itemId);
let post = BookmarkCache.getAnnotation(node.itemId, this.POST);
let charset = BookmarkCache.getAnnotation(node.itemId, this.CHARSET);
return Bookmark(node.uri, node.title, node.icon && node.icon.spec, post, keyword, tags, charset, node.itemId);
for (let id in values(ids))
if (id in this.bookmarks)
return this.bookmarks[id];
for (let id in values(ids))
if (id in this.bookmarks)
return this.bookmarks[id];
- while (folders.length > 0) {
- query.setFolders(folders, 1);
- folders.shift();
- let result = services.history.executeQuery(query, options);
- let folder = result.root;
- folder.containerOpen = true;
+ options.queryType = options.QUERY_TYPE_BOOKMARKS;
+ try {
+ // https://bugzil.la/702639
+ options.excludeItemIfParentHasAnnotation = "livemark/feedURI";
+ }
+ catch (e) {}
- for (let i = 0; i < folder.childCount; i++) {
- let node = folder.getChild(i);
- if (node.type == node.RESULT_TYPE_FOLDER) // folder
- folders.push(node.itemId);
- else if (node.type == node.RESULT_TYPE_URI) // bookmark
+ for (let i = 0; i < root.childCount; i++) {
+ let node = root.getChild(i);
+ if (node.type == node.RESULT_TYPE_URI) // bookmark
getAnnotation: function getAnnotation(item, anno)
services.annotation.itemHasAnnotation(item, anno) ?
services.annotation.getItemAnnotation(item, anno) : null,
getAnnotation: function getAnnotation(item, anno)
services.annotation.itemHasAnnotation(item, anno) ?
services.annotation.getItemAnnotation(item, anno) : null,