Mercurial > projects > booket
annotate booket.js @ 23:69552aee9993
Use custom expander instead of details element
Use a custom expander instead of a details element which is not (yet)
universally supported.
author | Guido Berhoerster <guido+booket@berhoerster.name> |
---|---|
date | Sun, 05 Oct 2014 19:46:32 +0200 |
parents | b19db583b5f8 |
children | 6cf1ec2e8955 |
rev | line source |
---|---|
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1 /* |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2014 Guido Berhoerster <guido+booket@berhoerster.name> |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
3 * |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
11 * |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
14 * |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
22 */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
23 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
24 (function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
25 'use strict'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
26 |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
27 var BOOKMARKLET_URI = |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
28 'javascript:(function() {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
29 '\'use strict\';' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
30 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
31 'function displayBookmarkData(bookmarkData) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
32 'window.alert(\'Copy the following data and paste it into \' +' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
33 '\'Booket:\\n\\n\' + JSON.stringify(bookmarkData));' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
34 '}' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
35 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
36 'var bookmarkData = {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
37 '\'url\': document.URL,' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
38 '\'title\': document.title,' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
39 '\'favicon\': undefined' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
40 '};' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
41 'var faviconLinkElement;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
42 'var faviconUrls = [];' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
43 'var aElement;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
44 'var canvasElement;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
45 'var canvasCtx;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
46 'var imgElement;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
47 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
48 'aElement = document.createElement(\'a\');' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
49 'aElement.href = document.URL;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
50 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
51 'faviconUrls.push(aElement.protocol + \'//\' + aElement.host + ' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
52 '\'/favicon.ico\');' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
53 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
54 'faviconLinkElement = document.querySelector(' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
55 '\'link[rel~=\\\'icon\\\']\');' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
56 'if (faviconLinkElement !== null) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
57 'faviconUrls.push(faviconLinkElement.href);' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
58 '}' + |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
59 '' + |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
60 'canvasElement = document.createElement(\'canvas\');' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
61 'canvasCtx = canvasElement.getContext(\'2d\');' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
62 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
63 'imgElement = new Image();' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
64 'imgElement.addEventListener(\'load\', function(e) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
65 'var faviconUrl;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
66 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
67 'canvasElement.width = 16;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
68 'canvasElement.height = 16;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
69 'canvasCtx.clearRect(0, 0, 16, 16);' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
70 'try {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
71 'canvasCtx.drawImage(this, 0, 0, 16, 16);' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
72 'bookmarkData.favicon = canvasElement.toDataURL();' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
73 '} catch (exception) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
74 'faviconUrl = faviconUrls.pop();' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
75 '}' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
76 'if (bookmarkData.favicon !== undefined || ' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
77 'faviconUrl === undefined) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
78 'displayBookmarkData(bookmarkData);' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
79 '} else {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
80 'imgElement.src = faviconUrl;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
81 '}' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
82 '});' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
83 'imgElement.addEventListener(\'error\', function(e) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
84 'var faviconUrl;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
85 '' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
86 'faviconUrl = faviconUrls.pop();' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
87 'if (faviconUrl !== undefined) {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
88 'imgElement.src = faviconUrl;' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
89 '} else {' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
90 'displayBookmarkData(bookmarkData);' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
91 '}' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
92 '});' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
93 'imgElement.src = faviconUrls.pop();' + |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
94 '})();'; |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
95 |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
96 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
97 /* |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
98 * utility stuff |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
99 */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
100 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
101 function isNumber(number) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
102 return (Object.prototype.toString.call(number) === '[object Number]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
103 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
104 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
105 function isString(number) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
106 return (Object.prototype.toString.call(number) === '[object String]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
107 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
108 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
109 function arrayEqual(array1, array2) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
110 if (!Array.isArray(array1)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
111 throw new TypeError(typeof array1 + ' is not an array'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
112 } else if (!Array.isArray(array2)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
113 throw new TypeError(typeof array2 + ' is not an array'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
114 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
115 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
116 if (array1.length !== array2.length) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
117 return false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
118 } else if (array1.length === 0 && array2.length === 0) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
119 return true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
120 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
121 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
122 return array1.slice().sort().every(function (value, i) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
123 return value === array2[i]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
124 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
125 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
126 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
127 function parseHash(url) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
128 var hashData; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
129 var pos; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
130 var hash; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
131 var hashParts; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
132 var key; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
133 var value; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
134 var i; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
135 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
136 hashData = new StringMap(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
137 pos = url.indexOf('#'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
138 hash = (pos > -1) ? url.substr(pos + 1) : ''; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
139 // hash parts are seperated by a ';' |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
140 hashParts = hash.split(';'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
141 for (i = 0; i < hashParts.length; i++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
142 // key and value pairs are seperated by a '=', an empty value will |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
143 // cause the key to be ignored |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
144 pos = hashParts[i].indexOf('='); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
145 if (pos > -1) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
146 key = decodeURIComponent(hashParts[i].substr(0, pos)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
147 value = decodeURIComponent(hashParts[i].substr(pos + 1)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
148 hashData.set(key, value); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
149 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
150 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
151 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
152 return hashData; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
153 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
154 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
155 function serializeHash(url, hashData) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
156 var hashParts = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
157 var pos; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
158 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
159 pos = url.indexOf('#'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
160 if (pos > -1) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
161 url = url.substr(0, pos); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
162 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
163 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
164 hashData.forEach(function (value, key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
165 if (value !== '') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
166 hashParts.push(encodeURIComponent(key) + '=' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
167 encodeURIComponent(value)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
168 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
169 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
170 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
171 // only append a '#' if there are any hash parts |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
172 return url + (hashParts.length > 0 ? '#' + hashParts.join(';') : ''); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
173 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
174 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
175 function getAncestorElementDatasetItem(node, item) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
176 while ((node = node.parentNode) !== null) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
177 if (node.dataset && node.dataset[item] !== undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
178 return node.dataset[item]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
179 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
180 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
181 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
182 return undefined; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
183 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
184 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
185 // for use with Node.querySelector() and Node.querySelectorAll() |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
186 function createDatasetSelector(name, value) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
187 return '[data-' + name + '="' + value.replace(/["\\]/g, '\\$&') + '"]'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
188 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
189 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
190 function extend(targetObject, sourceObject) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
191 var propertyName; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
192 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
193 for (propertyName in sourceObject.prototype) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
194 if (!Object.prototype.hasOwnProperty.call(targetObject.prototype, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
195 propertyName)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
196 targetObject.prototype[propertyName] = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
197 sourceObject.prototype[propertyName]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
198 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
199 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
200 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
201 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
202 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
203 var ObservableMixin = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
204 this._eventsObservers = {}; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
205 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
206 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
207 ObservableMixin.prototype.addObserver = function (eventName, observer) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
208 var i; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
209 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
210 if (!Object.prototype.hasOwnProperty.call(this._eventsObservers, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
211 eventName)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
212 this._eventsObservers[eventName] = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
213 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
214 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
215 // prevent observers for an event from being called more than once |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
216 for (i = 0; i < this._eventsObservers[eventName].length; i++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
217 if (this._eventsObservers[eventName][i] === observer) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
218 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
219 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
220 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
221 this._eventsObservers[eventName].push(observer); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
222 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
223 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
224 ObservableMixin.prototype.deleteObserver = function (eventName, observer) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
225 var i = 0; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
226 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
227 if (!Object.prototype.hasOwnProperty.call(this._eventsObservers, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
228 eventName)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
229 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
230 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
231 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
232 while (i < this._eventsObservers[eventName].length) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
233 if (this._eventsObservers[eventName][i] === observer) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
234 this._eventsObservers[eventName].splice(i, 1); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
235 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
236 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
237 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
238 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
239 ObservableMixin.prototype.notify = function (eventName) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
240 var origArguments; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
241 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
242 if (!Object.prototype.hasOwnProperty.call(this._eventsObservers, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
243 eventName)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
244 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
245 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
246 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
247 origArguments = Array.prototype.slice.call(arguments, 1); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
248 this._eventsObservers[eventName].forEach(function (observer, i) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
249 // call the observer function and pass on any additional arguments |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
250 observer.apply(undefined, origArguments); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
251 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
252 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
253 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
254 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
255 var StringMap = function (iter) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
256 this._stringMap = Object.create(null); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
257 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
258 if (iter !== undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
259 if (Array.isArray(iter)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
260 iter.forEach(function (pair) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
261 if (Array.isArray(pair)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
262 this.set(pair[0], pair[1]); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
263 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
264 throw new TypeError(typeof pair + ' is not an array'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
265 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
266 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
267 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
268 throw new TypeError(typeof iter + ' is not iterable'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
269 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
270 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
271 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
272 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
273 Object.defineProperty(StringMap.prototype, 'size', { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
274 get: function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
275 var size = 0; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
276 var key; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
277 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
278 for (key in this._stringMap) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
279 if (key.charAt(0) === '@') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
280 size++; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
281 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
282 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
283 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
284 return size; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
285 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
286 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
287 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
288 StringMap.prototype.set = function (key, value) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
289 this._stringMap['@' + key] = value; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
290 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
291 return this; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
292 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
293 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
294 StringMap.prototype.get = function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
295 return this._stringMap['@' + key]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
296 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
297 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
298 StringMap.prototype.has = function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
299 return (('@' + key) in this._stringMap); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
300 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
301 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
302 StringMap.prototype.delete = function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
303 if (this.has(key)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
304 delete this._stringMap['@' + key]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
305 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
306 return true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
307 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
308 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
309 return false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
310 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
311 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
312 StringMap.prototype.forEach = function (callbackFn, thisArg) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
313 Object.keys(this._stringMap).forEach(function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
314 if (key.charAt(0) === '@') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
315 key = key.substr(1); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
316 callbackFn.call(thisArg, this.get(key), key, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
317 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
318 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
319 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
320 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
321 StringMap.prototype.keys = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
322 return Object.keys(this._stringMap).map(function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
323 return key.substr(1); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
324 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
325 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
326 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
327 StringMap.prototype.toJSON = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
328 return this._stringMap; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
329 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
330 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
331 StringMap.prototype.toString = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
332 return Object.prototype.toString.call(this._stringMap); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
333 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
334 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
335 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
336 var StringSet = function (iter) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
337 this._stringArray = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
338 this._stringMap = new StringMap(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
339 if (iter !== undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
340 if (Array.isArray(iter) || iter instanceof StringSet) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
341 iter.forEach(function (string) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
342 this.add(string); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
343 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
344 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
345 throw new TypeError(typeof iter + ' is not iterable'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
346 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
347 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
348 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
349 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
350 Object.defineProperty(StringSet.prototype, 'size', { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
351 get: function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
352 return this._stringArray.length; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
353 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
354 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
355 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
356 StringSet.prototype.has = function (string) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
357 return this._stringMap.has(string); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
358 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
359 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
360 StringSet.prototype.add = function (string) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
361 if (!this.has(string)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
362 this._stringMap.set(string, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
363 this._stringArray.push(string); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
364 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
365 return this; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
366 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
367 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
368 StringSet.prototype.delete = function (string) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
369 if (this.has(string)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
370 this._stringMap.delete(string); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
371 this._stringArray.splice(this._stringArray.indexOf(string), 1); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
372 return true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
373 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
374 return false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
375 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
376 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
377 StringSet.prototype.forEach = function (callbackFn, thisArg) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
378 this._stringArray.forEach(function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
379 callbackFn.call(thisArg, key, key, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
380 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
381 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
382 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
383 StringSet.prototype.keys = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
384 return this._stringArray.slice(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
385 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
386 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
387 StringSet.prototype.values = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
388 return this._stringArray.slice(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
389 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
390 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
391 StringSet.prototype.clear = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
392 this._stringMap = new StringMap(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
393 this._stringArray = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
394 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
395 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
396 StringSet.prototype.toJSON = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
397 return this._stringArray; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
398 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
399 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
400 StringSet.prototype.toString = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
401 return this._stringArray.toString(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
402 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
403 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
404 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
405 /* |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
406 * model |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
407 */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
408 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
409 var Bookmark = function (url, title, favicon, tags, ctime, mtime) { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
410 var parsedTime; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
411 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
412 if (!isString(url)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
413 throw new TypeError(typeof url + ' is not a string'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
414 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
415 this.url = url; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
416 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
417 this.title = (isString(title) && title !== '') ? title : url; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
418 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
419 if (isString(favicon) && favicon.match(/^data:image\/png;base64,/)) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
420 this.favicon = favicon; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
421 } else { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
422 this.favicon = undefined; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
423 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
424 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
425 if (Array.isArray(tags)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
426 // remove duplicates, non-string or empty tags and tags containing |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
427 // commas |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
428 this.tags = new StringSet(tags.filter(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
429 return (isString(tag) && tag !== '' && tag.indexOf(',') === -1); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
430 }).sort()); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
431 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
432 this.tags = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
433 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
434 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
435 if (isNumber(ctime) || isString(ctime)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
436 parsedTime = new Date(ctime); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
437 this.ctime = !isNaN(parsedTime.getTime()) ? parsedTime : new Date(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
438 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
439 this.ctime = new Date(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
440 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
441 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
442 if (isNumber(mtime) || isString(mtime)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
443 parsedTime = new Date(mtime); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
444 // modification time must be greater than creation time |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
445 this.mtime = (!isNaN(parsedTime.getTime()) || |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
446 parsedTime >= this.ctime) ? parsedTime : new Date(this.ctime); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
447 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
448 this.mtime = new Date(this.ctime); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
449 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
450 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
451 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
452 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
453 var BookmarkModel = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
454 ObservableMixin.call(this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
455 |
18
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
456 this._unsavedChanges = false; |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
457 this.loadFileReader = null; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
458 this.importFileReader= null; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
459 this._bookmarks = new StringMap(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
460 this._tagCount = new StringMap(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
461 this._filterTags = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
462 this._searchTerm = ''; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
463 this._filteredBookmarks = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
464 this._searchedBookmarks = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
465 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
466 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
467 extend(BookmarkModel, ObservableMixin); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
468 |
18
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
469 Object.defineProperty(BookmarkModel.prototype, 'unsavedChanges', { |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
470 set: function (value) { |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
471 if (this._unsavedChanges !== value) { |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
472 this._unsavedChanges = value; |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
473 this.notify('unsaved-changes-changed', value) |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
474 } |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
475 }, |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
476 get: function () { |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
477 return this._unsavedChanges; |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
478 } |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
479 }); |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
480 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
481 BookmarkModel.prototype.add = function (bookmarks) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
482 var addedBookmarkUrls = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
483 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
484 // argument can be a single bookmark or a list of bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
485 if (!Array.isArray(bookmarks)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
486 bookmarks = [bookmarks]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
487 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
488 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
489 bookmarks.forEach(function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
490 // delete any existing bookmark for the given URL before adding the new |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
491 // one in order to update views |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
492 this.delete(bookmark.url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
493 this._bookmarks.set(bookmark.url, bookmark); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
494 addedBookmarkUrls.add(bookmark.url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
495 this.unsavedChanges = true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
496 this.notify('bookmark-added', bookmark); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
497 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
498 // update tag count |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
499 bookmark.tags.forEach(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
500 var tagCount; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
501 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
502 if (this._tagCount.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
503 tagCount = this._tagCount.get(tag) + 1; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
504 this._tagCount.set(tag, tagCount); |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
505 this.notify('tag-count-changed', tag, this._tagCount); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
506 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
507 this._tagCount.set(tag, 1); |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
508 this.notify('tag-added', tag, this._tagCount); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
509 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
510 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
511 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
512 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
513 // apply tag filter and search added bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
514 this.updateFilteredSearchedBookmarks(addedBookmarkUrls); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
515 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
516 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
517 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
518 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
519 BookmarkModel.prototype.has = function (url) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
520 return this._bookmarks.has(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
521 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
522 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
523 BookmarkModel.prototype.get = function (url) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
524 return this._bookmarks.get(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
525 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
526 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
527 BookmarkModel.prototype.delete = function (urls) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
528 var needUpdateFilterTags = false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
529 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
530 // argument can be a single bookmark or a list of bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
531 if (!Array.isArray(urls)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
532 urls = [urls]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
533 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
534 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
535 urls.forEach(function (url) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
536 var bookmark; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
537 var tagCount; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
538 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
539 if (this._bookmarks.has(url)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
540 bookmark = this._bookmarks.get(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
541 this._bookmarks.delete(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
542 this.unsavedChanges = true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
543 this.notify('bookmark-deleted', bookmark.url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
544 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
545 // update tag count |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
546 bookmark.tags.forEach(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
547 if (this._tagCount.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
548 tagCount = this._tagCount.get(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
549 if (tagCount > 1) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
550 tagCount--; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
551 this._tagCount.set(tag, tagCount); |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
552 this.notify('tag-count-changed', tag, this._tagCount); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
553 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
554 this._tagCount.delete(tag); |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
555 this.notify('tag-deleted', tag, this._tagCount); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
556 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
557 if (this._filterTags.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
558 this._filterTags.delete(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
559 needUpdateFilterTags = true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
560 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
561 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
562 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
563 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
564 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
565 // update filtered and searched bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
566 if (this._filteredBookmarks.has(url)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
567 this._filteredBookmarks.delete(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
568 if (this._searchedBookmarks.has(url)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
569 this._searchedBookmarks.delete(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
570 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
571 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
572 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
573 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
574 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
575 if (needUpdateFilterTags) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
576 this.updateFilteredSearchedBookmarks(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
577 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
578 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
579 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
580 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
581 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
582 BookmarkModel.prototype.forEach = function (callbackFn, thisArg) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
583 this._bookmarks.keys().forEach(function (key) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
584 callbackFn.call(thisArg, this._bookmarks.get(key), key, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
585 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
586 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
587 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
588 BookmarkModel.prototype.hasTag = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
589 return this._tagCount.has(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
590 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
591 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
592 BookmarkModel.prototype.getTagCount = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
593 return (this._tagCount.has(tag)) ? this._tagCount.get(tag) : undefined; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
594 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
595 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
596 BookmarkModel.prototype.updateSearchedBookmarks = function (urlsSubset) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
597 var searchUrls; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
598 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
599 // additive search if urlsSubset is given |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
600 if (urlsSubset !== undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
601 searchUrls = urlsSubset; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
602 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
603 this._searchedBookmarks = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
604 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
605 searchUrls = this._filteredBookmarks.values(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
606 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
607 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
608 // search for the search term in title and URL |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
609 searchUrls.forEach(function (url) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
610 var bookmark; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
611 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
612 bookmark = this.get(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
613 if (this._searchTerm === '' || |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
614 bookmark.title.indexOf(this._searchTerm) !== -1 || |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
615 bookmark.url.indexOf(this._searchTerm) !== -1) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
616 this._searchedBookmarks.add(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
617 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
618 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
619 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
620 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
621 BookmarkModel.prototype.updateFilteredSearchedBookmarks = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
622 function (urlsSubset) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
623 var filterUrls; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
624 var searchUrls; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
625 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
626 // additive filtering if urlsSubset is given |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
627 if (urlsSubset !== undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
628 filterUrls = urlsSubset; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
629 searchUrls = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
630 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
631 this._filteredBookmarks = new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
632 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
633 filterUrls = this._bookmarks.keys(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
634 searchUrls = undefined; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
635 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
636 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
637 // apply tag filter |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
638 filterUrls.forEach(function (url) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
639 var bookmark; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
640 var matchingTagCount = 0; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
641 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
642 bookmark = this.get(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
643 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
644 bookmark.tags.forEach(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
645 if (this._filterTags.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
646 matchingTagCount++; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
647 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
648 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
649 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
650 if (matchingTagCount === this._filterTags.size) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
651 this._filteredBookmarks.add(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
652 if (urlsSubset !== undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
653 searchUrls.push(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
654 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
655 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
656 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
657 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
658 // search the filter results |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
659 this.updateSearchedBookmarks(searchUrls); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
660 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
661 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
662 BookmarkModel.prototype.toggleFilterTag = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
663 if (this._filterTags.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
664 this._filterTags.delete(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
665 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
666 this._filterTags.add(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
667 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
668 this.updateFilteredSearchedBookmarks(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
669 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
670 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
671 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
672 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
673 BookmarkModel.prototype.setFilterTags = function (filterTags) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
674 if (!arrayEqual(filterTags.values(), this._filterTags.values())) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
675 this._filterTags = new StringSet(filterTags); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
676 this.updateFilteredSearchedBookmarks(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
677 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
678 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
679 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
680 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
681 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
682 BookmarkModel.prototype.setSearchTerm = function (searchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
683 if (searchTerm !== this._searchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
684 this._searchTerm = searchTerm; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
685 this.updateSearchedBookmarks(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
686 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
687 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
688 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
689 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
690 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
691 BookmarkModel.prototype.setFilterTagsSearchTerm = function (filterTags, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
692 searchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
693 if (!arrayEqual(filterTags.values(), this._filterTags.values())) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
694 this._filterTags = new StringSet(filterTags); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
695 this._searchTerm = searchTerm; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
696 this.updateFilteredSearchedBookmarks(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
697 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
698 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
699 } else if (searchTerm !== this._searchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
700 this._searchTerm = searchTerm; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
701 this.updateSearchedBookmarks(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
702 this.notify('filter-tags-search-changed', this._searchedBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
703 this._filterTags, this._searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
704 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
705 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
706 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
707 BookmarkModel.prototype.parseLoadedBookmarks = function (data) { |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
708 var wasEmpty = !this._bookmarks.size; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
709 var parsedData; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
710 var bookmarks = []; |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
711 var bookmark; |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
712 var oldBookmark; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
713 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
714 try { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
715 parsedData = JSON.parse(data); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
716 } catch (e) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
717 this.notify('load-file-error', e.message); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
718 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
719 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
720 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
721 if (!Array.isArray(parsedData.bookmarks)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
722 this.notify('parse-file-error', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
723 'This file does not contain bookmarks.'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
724 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
725 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
726 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
727 // create a temporary list of valid bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
728 parsedData.bookmarks.forEach(function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
729 if (isString(bookmark.url) && bookmark.url !== '') { |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
730 bookmark = new Bookmark(bookmark.url, bookmark.title, |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
731 bookmark.favicon, bookmark.tags, bookmark.ctime, bookmark.mtime) |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
732 oldBookmark = this.get(bookmark.url); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
733 if (oldBookmark === undefined || |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
734 oldBookmark.mtime < bookmark.mtime) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
735 bookmarks.push(bookmark); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
736 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
737 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
738 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
739 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
740 // add each bookmark to the model ordered by the last modification time |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
741 this.add(bookmarks.sort(function (bookmark1, bookmark2) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
742 return bookmark1.ctime - bookmark2.ctime; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
743 })); |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
744 if (wasEmpty) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
745 // if there were no bookmarks before there cannot be any unsaved changes |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
746 this.unsavedChanges = false; |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
747 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
748 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
749 |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
750 BookmarkModel.prototype.parseImportedBookmarks = function (data) { |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
751 var wasEmpty = (this._bookmarks.size > 0); |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
752 var bookmarkDoc; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
753 var bookmarkElements; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
754 var i; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
755 var url; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
756 var title; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
757 var favicon; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
758 var tags; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
759 var ctime; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
760 var mtime; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
761 var bookmarks = []; |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
762 var bookmark; |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
763 var oldBookmark; |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
764 |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
765 bookmarkDoc = document.implementation.createHTMLDocument(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
766 bookmarkDoc.open(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
767 bookmarkDoc.write(data); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
768 bookmarkDoc.close(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
769 |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
770 // create a temporary list of valid bookmarks |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
771 bookmarkElements = bookmarkDoc.querySelectorAll('dt > a[href]'); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
772 for (i = 0; i < bookmarkElements.length; i++) { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
773 url = bookmarkElements[i].href; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
774 if (url !== '') { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
775 title = bookmarkElements[i].textContent; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
776 favicon = bookmarkElements[i].getAttribute('icon'); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
777 tags = ((tags = bookmarkElements[i].getAttribute('tags')) !== |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
778 null) ? tags.split(',') : []; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
779 ctime = !isNaN(ctime = |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
780 parseInt(bookmarkElements[i].getAttribute('add_date'), 10)) ? |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
781 ctime * 1000 : undefined; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
782 mtime = !isNaN(mtime = |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
783 parseInt(bookmarkElements[i].getAttribute('last_modified'), |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
784 10)) ? mtime * 1000 : undefined; |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
785 bookmark = new Bookmark(url, title, favicon, tags, ctime, mtime); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
786 oldBookmark = this.get(bookmark.url); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
787 if (oldBookmark === undefined || |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
788 oldBookmark.mtime < bookmark.mtime) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
789 bookmarks.push(bookmark); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
790 } |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
791 } |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
792 } |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
793 |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
794 // add each bookmark to the model ordered by the last modification time |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
795 this.add(bookmarks.sort(function (bookmark1, bookmark2) { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
796 return bookmark1.ctime - bookmark2.ctime; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
797 })); |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
798 if (!wasEmpty) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
799 // if there were no bookmarks before there cannot be any unsaved changes |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
800 this.unsavedChanges = false; |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
801 } |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
802 }; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
803 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
804 BookmarkModel.prototype.loadFile = function (bookmarkFile, merge) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
805 if (!merge) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
806 // delete all existing bookmarks first |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
807 this.delete(this._bookmarks.keys()); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
808 this.unsavedChanges = false; |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
809 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
810 |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
811 this.loadFileReader = new FileReader(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
812 this.loadFileReader.addEventListener('error', this); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
813 this.loadFileReader.addEventListener('load', this); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
814 this.loadFileReader.readAsText(bookmarkFile); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
815 }; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
816 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
817 BookmarkModel.prototype.importFile = function (bookmarkFile, merge) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
818 if (!merge) { |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
819 // delete all existing bookmarks first |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
820 this.delete(this._bookmarks.keys()); |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
821 this.unsavedChanges = false; |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
822 } |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
823 |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
824 this.importFileReader = new FileReader(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
825 this.importFileReader.addEventListener('error', this); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
826 this.importFileReader.addEventListener('load', this); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
827 this.importFileReader.readAsText(bookmarkFile); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
828 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
829 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
830 BookmarkModel.prototype.saveFile = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
831 var jsonBlob; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
832 var bookmarkData = { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
833 'bookmarks': [] |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
834 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
835 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
836 this._bookmarks.forEach(function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
837 bookmarkData.bookmarks.push(bookmark); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
838 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
839 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
840 jsonBlob = new Blob([JSON.stringify(bookmarkData)], {type: |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
841 'application/json'}); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
842 this.notify('save-file', jsonBlob); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
843 this.unsavedChanges = false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
844 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
845 |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
846 BookmarkModel.prototype.exportFile = function () { |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
847 var htmlBlob; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
848 var bookmarkDoc; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
849 var commentNode; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
850 var metaElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
851 var titleElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
852 var headingElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
853 var bookmarkListElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
854 var bookmarkLinkElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
855 var bookmarkElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
856 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
857 bookmarkDoc = document.implementation.createHTMLDocument(); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
858 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
859 // construct Netscape bookmarks format within body |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
860 commentNode = bookmarkDoc.createComment('This is an automatically ' + |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
861 'generated file.\nIt will be read and overwritten.\nDO NOT EDIT!'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
862 bookmarkDoc.body.appendChild(commentNode); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
863 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
864 metaElement = bookmarkDoc.createElement('meta'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
865 metaElement.setAttribute('http-equiv', 'Content-Type'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
866 metaElement.setAttribute('content', 'text/html; charset=UTF-8'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
867 bookmarkDoc.body.appendChild(metaElement); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
868 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
869 titleElement = bookmarkDoc.createElement('title'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
870 titleElement.textContent = 'Bookmarks'; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
871 bookmarkDoc.body.appendChild(titleElement); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
872 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
873 headingElement = bookmarkDoc.createElement('h1'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
874 headingElement.textContent = 'Bookmarks'; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
875 bookmarkDoc.body.appendChild(headingElement); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
876 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
877 bookmarkListElement = bookmarkDoc.createElement('dl'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
878 bookmarkDoc.body.appendChild(bookmarkListElement); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
879 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
880 this._bookmarks.forEach(function (bookmark) { |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
881 bookmarkElement = bookmarkDoc.createElement('dt'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
882 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
883 bookmarkLinkElement = bookmarkDoc.createElement('a'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
884 bookmarkLinkElement.href = bookmark.url; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
885 bookmarkLinkElement.textContent = bookmark.title; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
886 bookmarkLinkElement.setAttribute('icon', bookmark.favicon); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
887 bookmarkLinkElement.setAttribute('tags', |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
888 bookmark.tags.values().join(',')); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
889 bookmarkLinkElement.setAttribute('add_date', |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
890 Math.round(bookmark.ctime.getTime() / 1000)); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
891 bookmarkLinkElement.setAttribute('last_modified', |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
892 Math.round(bookmark.mtime.getTime() / 1000)); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
893 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
894 bookmarkElement.appendChild(bookmarkLinkElement); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
895 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
896 bookmarkListElement.appendChild(bookmarkElement); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
897 bookmarkListElement.appendChild(bookmarkDoc.createElement('dd')); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
898 }, this); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
899 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
900 htmlBlob = new Blob(['<!DOCTYPE NETSCAPE-Bookmark-file-1>\n' + |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
901 bookmarkDoc.body.innerHTML], {type: 'text/html'}); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
902 this.notify('export-file', htmlBlob); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
903 }; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
904 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
905 BookmarkModel.prototype.handleEvent = function (e) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
906 if (e.type === 'load') { |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
907 if (e.target === this.loadFileReader) { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
908 this.parseLoadedBookmarks(e.target.result); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
909 this.loadFileReader = null; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
910 } else if (e.target === this.importFileReader) { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
911 this.parseImportedBookmarks(e.target.result); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
912 this.importFileReader = null; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
913 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
914 } else if (e.type === 'error') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
915 this.notify('load-file-error', e.target.error.message); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
916 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
917 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
918 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
919 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
920 /* |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
921 * view |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
922 */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
923 |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
924 var KeyboardShortcutsView = function () { |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
925 document.addEventListener('keydown', this); |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
926 document.addEventListener('keyup', this); |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
927 |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
928 this.shortcutKeysOverlayElement = |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
929 document.querySelector('#keyboard-shortcuts'); |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
930 }; |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
931 |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
932 KeyboardShortcutsView.prototype.handleEvent = function (e) { |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
933 var elements; |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
934 var i; |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
935 |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
936 // keyboard shortcut hints are visible when the Alt key is pressed and |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
937 // hidden again when the Alt key is released or another key is pressed |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
938 if (this.shortcutKeysOverlayElement.dataset.overlayVisible !== undefined && |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
939 (e.type === 'keyup' || e.type === 'keydown')) { |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
940 delete this.shortcutKeysOverlayElement.dataset.overlayVisible; |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
941 } else if (e.type === 'keydown' && e.keyCode === 18) { |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
942 this.shortcutKeysOverlayElement.dataset.overlayVisible = ''; |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
943 } |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
944 }; |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
945 |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
946 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
947 var TagView = function () { |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
948 var tagsElement; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
949 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
950 ObservableMixin.call(this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
951 |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
952 tagsElement = document.querySelector('#tags'); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
953 tagsElement.addEventListener('click', this); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
954 |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
955 this.tagListElement = tagsElement.querySelector('ul.tag-list'); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
956 |
5
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
957 this.tagDatalistElement = document.querySelector('#tag-datalist'); |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
958 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
959 this.tagTemplate = document.querySelector('#tag-template'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
960 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
961 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
962 extend(TagView, ObservableMixin); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
963 |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
964 TagView.prototype.onTagAdded = function (tag, tagCount) { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
965 var newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
966 var tagElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
967 var setTagButton; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
968 var toggleTagButton; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
969 var tagElements; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
970 var i; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
971 var referenceTag = ''; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
972 var referenceNode; |
5
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
973 var tagOptionElement; |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
974 var i; |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
975 var isInDatalist = false; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
976 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
977 // create new tag element from template |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
978 newNode = document.importNode(this.tagTemplate.content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
979 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
980 tagElement = newNode.querySelector('li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
981 tagElement.dataset.tag = tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
982 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
983 setTagButton = tagElement.querySelector('button[name="set-tag"]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
984 setTagButton.textContent = tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
985 setTagButton.title = 'Set filter to "' + tag + '"'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
986 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
987 toggleTagButton = tagElement.querySelector('button[name="toggle-tag"]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
988 toggleTagButton.textContent = '+'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
989 toggleTagButton.title = 'Add "' + tag + '" to filter'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
990 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
991 // maintain alphabetical order when inserting the tag element |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
992 tagElements = this.tagListElement.querySelectorAll('li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
993 for (i = 0; i < tagElements.length; i ++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
994 if (tagElements[i].dataset.tag > referenceTag && |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
995 tagElements[i].dataset.tag < tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
996 referenceTag = tagElements[i].dataset.tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
997 referenceNode = tagElements[i]; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
998 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
999 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1000 this.tagListElement.insertBefore(newNode, (referenceNode !== undefined) ? |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1001 referenceNode.nextSibling : this.tagListElement.firstChild); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1002 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1003 // initialize tag count |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1004 this.onTagCountChanged(tag, tagCount); |
5
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1005 |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1006 // add to datalist |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1007 for (i = 0; i < this.tagDatalistElement.options.length; i++) { |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1008 if (this.tagDatalistElement.options[i].value == tag) { |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1009 isInDatalist = true; |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1010 break; |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1011 } |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1012 } |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1013 if (!isInDatalist) { |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1014 tagOptionElement = document.createElement('option'); |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1015 tagOptionElement.value = tag; |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1016 this.tagDatalistElement.appendChild(tagOptionElement); |
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1017 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1018 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1019 |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1020 TagView.prototype.updateTagCloud = function (tagCount) { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1021 var tagElements; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1022 var i; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1023 var j; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1024 var tagCountMax = 1; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1025 |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1026 tagCount.forEach(function (count) { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1027 if (count > tagCountMax) { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1028 tagCountMax = count; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1029 } |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1030 }, this); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1031 |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1032 tagElements = this.tagListElement.querySelectorAll('ul.tag-list > li'); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1033 for (i = 0; i < tagElements.length; i++) { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1034 for (j = 1; j <= 10; j++) { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1035 tagElements[i].classList.remove('tag-frequency-' + j); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1036 } |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1037 tagElements[i].classList.add('tag-frequency-' + |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1038 (Math.floor(tagCount.get(tagElements[i].dataset.tag) / |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1039 (tagCountMax / 9)) + 1)); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1040 } |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1041 }; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1042 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1043 TagView.prototype.onTagCountChanged = function (tag, tagCount) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1044 this.tagListElement.querySelector('li' + createDatasetSelector('tag', tag) + |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1045 ' .tag-count').textContent = '(' + tagCount.get(tag) + ')'; |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1046 this.updateTagCloud(tagCount); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1047 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1048 |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1049 TagView.prototype.onTagDeleted = function (tag, tagCount) { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1050 var tagElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1051 |
5
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1052 // remove from tag list |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1053 tagElement = this.tagListElement.querySelector('li' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1054 createDatasetSelector('tag', tag)); |
5
39c95b9826d2
Add autocompletion for tags
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
3
diff
changeset
|
1055 tagElement.parentNode.removeChild(tagElement); |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1056 |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1057 this.updateTagCloud(tagCount); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1058 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1059 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1060 TagView.prototype.onFilterTagsSearchChanged = function (filteredBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1061 newFilterTags, newSearchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1062 var tagElements; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1063 var i; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1064 var tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1065 var toggleTagButton; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1066 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1067 tagElements = this.tagListElement.querySelectorAll('li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1068 for (i = 0; i < tagElements.length; i++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1069 tag = tagElements[i].dataset.tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1070 toggleTagButton = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1071 tagElements[i].querySelector('button[name="toggle-tag"]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1072 if (newFilterTags.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1073 tagElements[i].classList.add('active-filter-tag'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1074 toggleTagButton.textContent = '\u2212'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1075 toggleTagButton.title = 'Remove "' + tag + '" from filter'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1076 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1077 tagElements[i].classList.remove('active-filter-tag'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1078 toggleTagButton.textContent = '+'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1079 toggleTagButton.title = 'Add "' + tag + '" to filter'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1080 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1081 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1082 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1083 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1084 TagView.prototype.handleEvent = function (e) { |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1085 if (e.type === 'click') { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1086 if (e.target.name === 'set-tag' || |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1087 e.target.name === 'toggle-tag') { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1088 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1089 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1090 this.notify(e.target.name, getAncestorElementDatasetItem(e.target, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1091 'tag')); |
12
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1092 } else if (e.target.name === 'show-tag-cloud') { |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1093 this.tagListElement.classList.toggle('tag-cloud', e.target.checked); |
948048e40fab
Add option for displaying tag list as a tag cloud
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
11
diff
changeset
|
1094 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1095 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1096 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1097 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1098 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1099 var ActionsView = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1100 var saveFormElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1101 var loadFormElement; |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1102 var importFormElement; |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1103 var exportFormElement; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1104 var newNode; |
16
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1105 var i; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1106 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1107 ObservableMixin.call(this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1108 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1109 this.tagInputTemplate = document.querySelector('#tag-input-template'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1110 saveFormElement = document.querySelector('form#save-form'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1111 saveFormElement.addEventListener('submit', this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1112 |
18
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1113 this.unsavedChangesElement = |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1114 saveFormElement.querySelector('.unsaved-changes-message'); |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1115 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1116 this.saveLinkElement = saveFormElement.querySelector('a#save-link'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1117 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1118 loadFormElement = document.querySelector('form#load-form'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1119 loadFormElement.addEventListener('submit', this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1120 |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1121 importFormElement = document.querySelector('form#import-form'); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1122 importFormElement.addEventListener('submit', this); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1123 |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1124 exportFormElement = document.querySelector('form#export-form'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1125 exportFormElement.addEventListener('submit', this); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1126 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1127 // create new editor form from template |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1128 newNode = document.importNode( |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1129 document.querySelector('#bookmark-editor-template').content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1130 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1131 this.editorFormElement = newNode.querySelector('form.bookmark-editor-form'); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1132 this.editorFormElement.querySelector('legend').textContent = 'Add Bookmark'; |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1133 this.editorFormElement.querySelector('label').accessKey = 'a'; |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1134 this.editorFormElement.addEventListener('input', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1135 this.editorFormElement.addEventListener('click', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1136 this.editorFormElement.addEventListener('submit', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1137 this.editorFormElement.addEventListener('reset', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1138 |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1139 this.faviconImageElement = |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1140 this.editorFormElement.querySelector('img.bookmark-favicon'); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1141 this.faviconImageElement.addEventListener('load', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1142 this.faviconImageElement.addEventListener('error', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1143 |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1144 this.missingFaviconUri = this.faviconImageElement.src; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1145 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1146 this.editTagListElement = |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1147 this.editorFormElement.querySelector('ul.tag-input-list'); |
16
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1148 // add four tag input elements for convenience |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1149 for (i = 0; i < 4; i++) { |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1150 this.editTagListElement.appendChild(this.createTagInputElement('')); |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1151 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1152 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1153 saveFormElement.parentNode.insertBefore(newNode, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1154 saveFormElement.nextSibling); |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1155 |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1156 document.querySelector('a#bookmarklet-link').href = BOOKMARKLET_URI; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1157 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1158 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1159 extend(ActionsView, ObservableMixin); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1160 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1161 ActionsView.prototype.createTagInputElement = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1162 var newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1163 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1164 newNode = document.importNode(this.tagInputTemplate.content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1165 newNode.querySelector('input[name="tag"]').value = tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1166 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1167 return newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1168 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1169 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1170 ActionsView.prototype.handleEvent = function (e) { |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1171 var bookmarkletData; |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1172 var parsedData; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1173 var tags = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1174 var i; |
16
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1175 var tagInputElements; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1176 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1177 switch (e.type) { |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1178 case 'error': |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1179 if (e.target.classList.contains('bookmark-favicon')) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1180 if (e.target.src !== this.missingFaviconUri) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1181 e.target.src = this.missingFaviconUri; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1182 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1183 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1184 break; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1185 case 'load': |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1186 if (e.target.classList.contains('bookmark-favicon')) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1187 this.editorFormElement.favicon.value = |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1188 (e.target.src !== this.missingFaviconUri) ? e.target.src : ''; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1189 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1190 break; |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1191 case 'input': |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1192 if (e.target.name === 'bookmarklet-import') { |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1193 // get rid of any preceding text |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1194 bookmarkletData = e.target.value.replace(/^[^{]*/, ''); |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1195 |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1196 try { |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1197 parsedData = JSON.parse(bookmarkletData); |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1198 } catch (exception) { |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1199 return; |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1200 } |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1201 |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1202 if (isString(parsedData.url) && parsedData.url !== '') { |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1203 e.target.form.elements.url.value = parsedData.url; |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1204 } |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1205 if (isString(parsedData.title) && parsedData.title !== '') { |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1206 e.target.form.elements.title.value = parsedData.title; |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1207 } |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1208 if (isString(parsedData.favicon) && |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1209 parsedData.favicon.match(/^data:image\/png;base64,/)) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1210 this.faviconImageElement.src = parsedData.favicon; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1211 } |
6
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1212 } |
e9ad4c625b7a
Add bookmarklet for bookmarking
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
5
diff
changeset
|
1213 break; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1214 case 'click': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1215 if (e.target.name === 'more-tags') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1216 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1217 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1218 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1219 this.editTagListElement.appendChild(this.createTagInputElement('')); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1220 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1221 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1222 case 'submit': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1223 if (e.target.id === 'save-form') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1224 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1225 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1226 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1227 this.notify('save-file'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1228 } else if (e.target.id === 'load-form') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1229 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1230 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1231 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1232 this.notify('load-file', e.target.file.files[0], |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1233 e.target.merge.checked); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1234 e.target.reset(); |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1235 } else if (e.target.id === 'import-form') { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1236 e.preventDefault(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1237 e.target.blur(); |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1238 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1239 this.notify('import-file', e.target.file.files[0], |
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1240 e.target.merge.checked); |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1241 e.target.reset(); |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1242 } else if (e.target.id === 'export-form') { |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1243 e.preventDefault(); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1244 e.target.blur(); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1245 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1246 this.notify('export-file'); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1247 } else if (e.target.classList.contains('bookmark-editor-form')) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1248 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1249 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1250 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1251 if (e.target.tag.length) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1252 for (i = 0; i < e.target.tag.length; i++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1253 tags.push(e.target.tag[i].value.trim()); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1254 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1255 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1256 tags.push(e.target.tag.value.trim()); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1257 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1258 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1259 this.notify('save-bookmark', e.target.url.value, |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1260 e.target.title.value, e.target.favicon.value, tags); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1261 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1262 e.target.reset(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1263 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1264 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1265 case 'reset': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1266 if (e.target.classList.contains('bookmark-editor-form')) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1267 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1268 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1269 e.target.querySelector('img.bookmark-favicon').src = |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1270 this.missingFaviconUri; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1271 |
16
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1272 // remove all but the first four tag input elements |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1273 tagInputElements = |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1274 this.editTagListElement.querySelectorAll('li:nth-child(n+5)'); |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1275 for (i = 0; i < tagInputElements.length; i++) { |
64272f2105da
Show four tag input elements by default
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
12
diff
changeset
|
1276 this.editTagListElement.removeChild(tagInputElements[i]); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1277 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1278 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1279 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1280 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1281 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1282 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1283 ActionsView.prototype.onSaveFile = function (jsonBlob) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1284 this.saveLinkElement.href = URL.createObjectURL(jsonBlob); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1285 this.saveLinkElement.click(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1286 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1287 |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1288 ActionsView.prototype.onExportFile = function (htmlBlob) { |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1289 var exportLinkElement; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1290 |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1291 exportLinkElement = document.querySelector('a#export-link'); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1292 exportLinkElement.href = URL.createObjectURL(htmlBlob); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1293 exportLinkElement.click(); |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1294 }; |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1295 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1296 ActionsView.prototype.confirmLoadFile = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1297 return window.confirm('There are unsaved changes to your bookmarks.\n' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1298 'Proceed loading the bookmark file?'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1299 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1300 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1301 ActionsView.prototype.onLoadFileError = function (message) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1302 window.alert('Failed to load bookmark file:\n' + message); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1303 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1304 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1305 ActionsView.prototype.onParseFileError = function (message) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1306 window.alert('Failed to parse bookmark file:\n' + message); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1307 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1308 |
18
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1309 ActionsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) { |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1310 this.unsavedChangesElement.hidden = !unsavedChanges; |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1311 }; |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1312 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1313 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1314 var BookmarkView = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1315 var searchFormElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1316 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1317 ObservableMixin.call(this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1318 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1319 this.bookmarkTemplate = document.querySelector('#bookmark-template'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1320 this.bookmarkTagTemplate = document.querySelector('#bookmark-tag-template'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1321 this.bookmarkEditorTemplate = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1322 document.querySelector('#bookmark-editor-template'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1323 this.tagInputTemplate = document.querySelector('#tag-input-template'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1324 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1325 this.bookmarkListElement = document.querySelector('ul#bookmark-list'); |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1326 this.bookmarkListElement.addEventListener('input', this); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1327 this.bookmarkListElement.addEventListener('click', this); |
23
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1328 this.bookmarkListElement.addEventListener('keydown', this); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1329 this.bookmarkListElement.addEventListener('submit', this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1330 this.bookmarkListElement.addEventListener('reset', this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1331 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1332 searchFormElement = document.querySelector('#search-form'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1333 searchFormElement.addEventListener('submit', this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1334 searchFormElement.addEventListener('reset', this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1335 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1336 this.searchTermInputElement = searchFormElement['search-term']; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1337 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1338 this.bookmarkMessageElement = document.querySelector('#bookmark-message'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1339 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1340 this.missingFaviconUri = ''; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1341 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1342 this.updateBookmarkMessage(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1343 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1344 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1345 extend(BookmarkView, ObservableMixin); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1346 |
23
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1347 BookmarkView.prototype.getAncestorClass = function (node, className) { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1348 while ((node = node.parentNode) !== null && |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1349 (!node.classList || !node.classList.contains(className))); |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1350 |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1351 return node; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1352 }; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1353 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1354 BookmarkView.prototype.handleEvent = function (e) { |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1355 var bookmarkletData; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1356 var parsedData; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1357 var i; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1358 var tags = []; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1359 var node; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1360 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1361 switch (e.type) { |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1362 case 'error': |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1363 if (e.target.classList.contains('bookmark-favicon')) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1364 if (e.target.src !== this.missingFaviconUri) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1365 e.target.src = this.missingFaviconUri; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1366 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1367 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1368 break; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1369 case 'load': |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1370 if (e.target.classList.contains('bookmark-favicon')) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1371 node = e.target; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1372 while ((node = node.parentNode) !== null) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1373 if (node.classList.contains('bookmark-editor-form')) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1374 node.favicon.value = |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1375 (e.target.src !== this.missingFaviconUri) ? |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1376 e.target.src : ''; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1377 break; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1378 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1379 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1380 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1381 break; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1382 case 'input': |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1383 if (e.target.name === 'bookmarklet-import') { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1384 // get rid of any preceding text |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1385 bookmarkletData = e.target.value.replace(/^[^{]*/, ''); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1386 |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1387 try { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1388 parsedData = JSON.parse(bookmarkletData); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1389 } catch (exception) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1390 return; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1391 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1392 |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1393 if (isString(parsedData.url) && parsedData.url !== '') { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1394 e.target.form.elements.url.value = parsedData.url; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1395 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1396 if (isString(parsedData.title) && parsedData.title !== '') { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1397 e.target.form.elements.title.value = parsedData.title; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1398 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1399 if (isString(parsedData.favicon) && |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1400 parsedData.favicon.match(/^data:image\/png;base64,/)) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1401 e.target.form.querySelector('img.bookmark-favicon').src = |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1402 parsedData.favicon; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1403 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1404 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1405 break; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1406 case 'click': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1407 switch (e.target.name) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1408 case 'edit-bookmark': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1409 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1410 // fallthrough |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1411 case 'delete-bookmark': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1412 this.notify(e.target.name, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1413 getAncestorElementDatasetItem(e.target, 'bookmarkUrl')); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1414 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1415 case 'more-tags': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1416 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1417 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1418 e.target.form.querySelector('ul.tag-input-list').appendChild( |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1419 this.createTagInputElement('')); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1420 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1421 case 'set-tag': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1422 case 'toggle-tag': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1423 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1424 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1425 this.notify(e.target.name, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1426 getAncestorElementDatasetItem(e.target, 'tag')); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1427 break; |
23
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1428 default: |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1429 if ((node = this.getAncestorClass(e.target, 'expander')) !== null) { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1430 if (node.dataset.expanderOpen !== undefined) { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1431 delete node.dataset.expanderOpen; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1432 } else { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1433 node.dataset.expanderOpen = ''; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1434 } |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1435 } |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1436 break; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1437 } |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1438 break; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1439 case 'keydown': |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1440 if (e.keyCode === 32 && |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1441 (node = this.getAncestorClass(e.target, 'expander')) !== null) { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1442 if (node.dataset.expanderOpen !== undefined) { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1443 delete node.dataset.expanderOpen; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1444 } else { |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1445 node.dataset.expanderOpen = ''; |
69552aee9993
Use custom expander instead of details element
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
22
diff
changeset
|
1446 } |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1447 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1448 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1449 case 'submit': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1450 if (e.target.classList.contains('bookmark-editor-form')) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1451 // save bookmark-editor-form form contents |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1452 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1453 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1454 if (e.target.tag.length) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1455 for (i = 0; i < e.target.tag.length; i++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1456 tags.push(e.target.tag[i].value.trim()); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1457 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1458 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1459 tags.push(e.target.tag.value.trim()); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1460 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1461 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1462 this.notify('save-bookmark', e.target.url.value, |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1463 e.target.title.value, e.target.favicon.value, tags, |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1464 e.target['original-url'].value); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1465 } else if (e.target.id === 'search-form') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1466 // search |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1467 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1468 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1469 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1470 this.notify('search', e.target['search-term'].value); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1471 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1472 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1473 case 'reset': |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1474 if (e.target.classList.contains('bookmark-editor-form')) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1475 // cancel bookmark-editor-form form |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1476 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1477 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1478 // re-enable edit button |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1479 this.bookmarkListElement.querySelector('li' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1480 createDatasetSelector('bookmark-url', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1481 e.target['original-url'].value) + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1482 ' button[name="edit-bookmark"]').disabled = false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1483 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1484 e.target.parentNode.removeChild(e.target); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1485 } else if (e.target.id === 'search-form') { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1486 // clear search |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1487 e.preventDefault(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1488 e.target.blur(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1489 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1490 this.notify('search', ''); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1491 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1492 break; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1493 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1494 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1495 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1496 BookmarkView.prototype.updateBookmarkMessage = function () { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1497 this.bookmarkMessageElement.textContent = 'Showing ' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1498 this.bookmarkListElement.querySelectorAll('ul#bookmark-list > ' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1499 'li:not([hidden])').length + ' of ' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1500 this.bookmarkListElement.querySelectorAll('ul#bookmark-list > ' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1501 'li').length + ' bookmarks.'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1502 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1503 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1504 BookmarkView.prototype.onBookmarkAdded = function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1505 var newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1506 var bookmarkElement; |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1507 var faviconElement; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1508 var linkElement; |
3
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1509 var hostnameElement; |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1510 var urlElement; |
2
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1511 var ctimeElement; |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1512 var mtimeElement; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1513 var tagListElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1514 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1515 newNode = document.importNode(this.bookmarkTemplate.content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1516 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1517 bookmarkElement = newNode.querySelector('li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1518 bookmarkElement.dataset.bookmarkUrl = bookmark.url; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1519 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1520 faviconElement = bookmarkElement.querySelector('img.bookmark-favicon'); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1521 faviconElement.src = (bookmark.favicon) ? bookmark.favicon : |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1522 this.missingFaviconUri; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1523 faviconElement.alt = ''; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1524 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1525 linkElement = bookmarkElement.querySelector('a.bookmark-link'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1526 linkElement.textContent = linkElement.title = bookmark.title; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1527 linkElement.href = bookmark.url; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1528 |
3
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1529 hostnameElement = bookmarkElement.querySelector('.bookmark-hostname'); |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1530 hostnameElement.textContent = (linkElement.hostname !== '') ? |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1531 '[' + linkElement.hostname + ']' : ''; |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1532 |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1533 urlElement = bookmarkElement.querySelector('.bookmark-url'); |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1534 urlElement.textContent = bookmark.url; |
4786df0aec03
Display URL and hostname
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
2
diff
changeset
|
1535 |
2
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1536 ctimeElement = bookmarkElement.querySelector('.ctime'); |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1537 ctimeElement.dateTime = bookmark.ctime.toISOString(); |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1538 ctimeElement.textContent = bookmark.ctime.toString(); |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1539 |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1540 mtimeElement = bookmarkElement.querySelector('.mtime'); |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1541 mtimeElement.dateTime = bookmark.mtime.toISOString(); |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1542 mtimeElement.textContent = bookmark.mtime.toString(); |
82c50265c8dc
Display creation and modification time
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
0
diff
changeset
|
1543 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1544 tagListElement = bookmarkElement.querySelector('ul.tag-list'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1545 bookmark.tags.forEach(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1546 var newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1547 var tagElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1548 var setTagButton; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1549 var toggleTagButton; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1550 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1551 newNode = document.importNode(this.bookmarkTagTemplate.content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1552 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1553 tagElement = newNode.querySelector('li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1554 tagElement.dataset.tag = tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1555 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1556 setTagButton = newNode.querySelector('button[name="set-tag"]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1557 setTagButton.textContent = tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1558 setTagButton.title = 'Set filter to "' + tag + '"'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1559 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1560 toggleTagButton = newNode.querySelector('button[name="toggle-tag"]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1561 toggleTagButton.textContent = '+'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1562 toggleTagButton.title = 'Add "' + tag + '" to filter'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1563 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1564 tagListElement.appendChild(newNode); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1565 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1566 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1567 // insert new or last modified bookmark on top of the list |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1568 this.bookmarkListElement.insertBefore(newNode, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1569 this.bookmarkListElement.firstChild); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1570 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1571 this.updateBookmarkMessage(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1572 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1573 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1574 BookmarkView.prototype.onBookmarkDeleted = function (bookmarkUrl) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1575 var bookmarkElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1576 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1577 bookmarkElement = this.bookmarkListElement.querySelector('li' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1578 createDatasetSelector('bookmark-url', bookmarkUrl)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1579 if (bookmarkElement !== null) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1580 this.bookmarkListElement.removeChild(bookmarkElement); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1581 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1582 this.updateBookmarkMessage(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1583 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1584 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1585 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1586 BookmarkView.prototype.onFilterTagsSearchChanged = function (filteredBookmarks, |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1587 newFilterTags, newSearchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1588 var bookmarkElements; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1589 var i; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1590 var tagElements; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1591 var toggleTagButton; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1592 var j; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1593 var tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1594 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1595 this.searchTermInputElement.value = newSearchTerm; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1596 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1597 bookmarkElements = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1598 this.bookmarkListElement.querySelectorAll('ul#bookmark-list > li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1599 for (i = 0; i < bookmarkElements.length; i++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1600 // update visibility of bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1601 if (filteredBookmarks.has(bookmarkElements[i].dataset.bookmarkUrl)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1602 // update tag elements of visible bookmarks |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1603 tagElements = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1604 bookmarkElements[i].querySelectorAll('ul.tag-list > li'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1605 for (j = 0; j < tagElements.length; j++) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1606 tag = tagElements[j].dataset.tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1607 toggleTagButton = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1608 tagElements[j].querySelector('button[name="toggle-tag"]'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1609 if (newFilterTags.has(tag)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1610 tagElements[j].classList.add('active-filter-tag'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1611 toggleTagButton.textContent = '\u2212'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1612 toggleTagButton.title = 'Remove "' + tag + '" from filter'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1613 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1614 tagElements[j].classList.remove('active-filter-tag'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1615 toggleTagButton.textContent = '+'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1616 toggleTagButton.title = 'Add "' + tag + '" to filter'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1617 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1618 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1619 bookmarkElements[i].hidden = false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1620 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1621 bookmarkElements[i].hidden = true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1622 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1623 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1624 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1625 this.updateBookmarkMessage(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1626 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1627 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1628 BookmarkView.prototype.createTagInputElement = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1629 var newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1630 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1631 newNode = document.importNode(this.tagInputTemplate.content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1632 newNode.querySelector('input[name="tag"]').value = tag; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1633 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1634 return newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1635 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1636 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1637 BookmarkView.prototype.displayBookmarkEditor = function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1638 var bookmarkElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1639 var newNode; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1640 var formElement; |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1641 var faviconImageElement; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1642 var editTagListElement; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1643 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1644 bookmarkElement = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1645 this.bookmarkListElement.querySelector('ul#bookmark-list > li' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1646 createDatasetSelector('bookmark-url', bookmark.url)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1647 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1648 // disable edit button while editing |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1649 bookmarkElement.querySelector('button[name="edit-bookmark"]').disabled = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1650 true; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1651 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1652 // create new editor form from template |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1653 newNode = document.importNode(this.bookmarkEditorTemplate.content, true); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1654 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1655 // fill with data of given bookmark |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1656 formElement = newNode.querySelector('form.bookmark-editor-form'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1657 formElement.querySelector('legend').textContent = 'Edit Bookmark'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1658 formElement['original-url'].value = bookmark.url; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1659 formElement.url.value = bookmark.url; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1660 formElement.title.value = bookmark.title; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1661 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1662 faviconImageElement = formElement.querySelector('img.bookmark-favicon'); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1663 faviconImageElement.addEventListener('load', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1664 faviconImageElement.addEventListener('error', this); |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1665 this.missingFaviconUri = faviconImageElement.src; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1666 if (bookmark.favicon) { |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1667 faviconImageElement.src = bookmark.favicon; |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1668 } |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1669 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1670 editTagListElement = formElement.querySelector('ul.tag-input-list'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1671 bookmark.tags.forEach(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1672 editTagListElement.appendChild(this.createTagInputElement(tag)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1673 }, this); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1674 editTagListElement.appendChild(this.createTagInputElement('')); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1675 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1676 // insert editor form into bookmark item |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1677 bookmarkElement.appendChild(newNode); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1678 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1679 // focus first input element |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1680 formElement.querySelector('input').focus(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1681 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1682 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1683 BookmarkView.prototype.confirmReplaceBookmark = function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1684 return window.confirm('Replace bookmark "' + bookmark.title + '"\n[' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1685 bookmark.url + ']?'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1686 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1687 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1688 BookmarkView.prototype.confirmDeleteBookmark = function (bookmark) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1689 return window.confirm('Delete bookmark "' + bookmark.title + '"\n[' + |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1690 bookmark.url + ']?'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1691 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1692 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1693 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1694 /* |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1695 * controller |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1696 */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1697 |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1698 var BooketController = function(bookmarkModel, keyboardShortcutsView, |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1699 actionsView, tagView, bookmarkView) { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1700 this.bookmarkModel = bookmarkModel; |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1701 this.keyboardShortcutsView = keyboardShortcutsView; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1702 this.actionsView = actionsView; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1703 this.tagView = tagView; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1704 this.bookmarkView = bookmarkView; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1705 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1706 /* connect the views to the model */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1707 this.bookmarkModel.addObserver('bookmark-added', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1708 this.bookmarkView.onBookmarkAdded.bind(this.bookmarkView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1709 this.bookmarkModel.addObserver('bookmark-deleted', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1710 this.bookmarkView.onBookmarkDeleted.bind(this.bookmarkView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1711 this.bookmarkModel.addObserver('filter-tags-search-changed', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1712 this.bookmarkView.onFilterTagsSearchChanged.bind(this.bookmarkView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1713 this.bookmarkModel.addObserver('load-file-error', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1714 this.actionsView.onLoadFileError.bind(this.actionsView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1715 this.bookmarkModel.addObserver('parse-file-error', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1716 this.actionsView.onParseFileError.bind(this.actionsView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1717 this.bookmarkModel.addObserver('save-file', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1718 this.actionsView.onSaveFile.bind(this.actionsView)); |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1719 this.bookmarkModel.addObserver('export-file', |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1720 this.actionsView.onExportFile.bind(this.actionsView)); |
18
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1721 this.bookmarkModel.addObserver('unsaved-changes-changed', |
3642bb668af1
Indicate if there are unsaved changes
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
16
diff
changeset
|
1722 this.actionsView.onUnsavedChangesChanged.bind(this.actionsView)); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1723 this.bookmarkModel.addObserver('tag-added', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1724 this.tagView.onTagAdded.bind(this.tagView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1725 this.bookmarkModel.addObserver('tag-count-changed', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1726 this.tagView.onTagCountChanged.bind(this.tagView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1727 this.bookmarkModel.addObserver('tag-deleted', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1728 this.tagView.onTagDeleted.bind(this.tagView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1729 this.bookmarkModel.addObserver('filter-tags-search-changed', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1730 this.tagView.onFilterTagsSearchChanged.bind(this.tagView)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1731 this.bookmarkModel.addObserver('filter-tags-search-changed', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1732 this.onFilterTagsSearchChanged.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1733 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1734 /* handle input */ |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1735 window.addEventListener('hashchange', this.onHashChange.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1736 window.addEventListener('beforeunload', this.onBeforeUnload.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1737 this.actionsView.addObserver('save-file', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1738 this.bookmarkModel.saveFile.bind(this.bookmarkModel)); |
11
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1739 this.actionsView.addObserver('export-file', |
ef5d75bcac5e
Add Netscape bookmark file export function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
10
diff
changeset
|
1740 this.bookmarkModel.exportFile.bind(this.bookmarkModel)); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1741 this.actionsView.addObserver('load-file', this.onLoadFile.bind(this)); |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1742 this.actionsView.addObserver('import-file', this.onImportFile.bind(this)); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1743 this.actionsView.addObserver('save-bookmark', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1744 this.onSaveBookmark.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1745 this.bookmarkView.addObserver('edit-bookmark', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1746 this.onEditBookmark.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1747 this.bookmarkView.addObserver('save-bookmark', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1748 this.onSaveBookmark.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1749 this.bookmarkView.addObserver('delete-bookmark', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1750 this.onDeleteBookmark.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1751 this.bookmarkView.addObserver('toggle-tag', |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1752 this.onToggleFilterTag.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1753 this.bookmarkView.addObserver('set-tag', this.onSetTagFilter.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1754 this.bookmarkView.addObserver('search', this.onSearch.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1755 this.tagView.addObserver('toggle-tag', this.onToggleFilterTag.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1756 this.tagView.addObserver('set-tag', this.onSetTagFilter.bind(this)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1757 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1758 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1759 BooketController.prototype.parseTagsParameter = function (tagsString) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1760 var tags; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1761 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1762 tags = tagsString.split(',').filter(function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1763 return (tag !== '') && this.bookmarkModel.hasTag(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1764 }, this).sort(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1765 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1766 return new StringSet(tags); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1767 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1768 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1769 BooketController.prototype.onHashChange = function (e) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1770 var hashData; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1771 var filterTags; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1772 var searchTerm; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1773 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1774 hashData = parseHash(window.location.href); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1775 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1776 filterTags = hashData.has('tags') ? |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1777 this.parseTagsParameter(hashData.get('tags')) : new StringSet(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1778 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1779 searchTerm = hashData.has('search') ? hashData.get('search') : ''; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1780 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1781 this.bookmarkModel.setFilterTagsSearchTerm(filterTags, searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1782 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1783 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1784 BooketController.prototype.onBeforeUnload = function (e) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1785 var confirmationMessage = 'There are unsaved changes to your bookmarks.'; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1786 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1787 if (this.bookmarkModel.unsavedChanges) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1788 if (e) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1789 e.returnValue = confirmationMessage; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1790 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1791 if (window.event) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1792 window.event.returnValue = confirmationMessage; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1793 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1794 return confirmationMessage; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1795 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1796 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1797 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1798 BooketController.prototype.onFilterTagsSearchChanged = |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1799 function (filteredBookmarks, newFilterTags, newSearchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1800 var url = window.location.href; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1801 var hashData; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1802 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1803 // serialize tag filter and search term and update window.location |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1804 hashData = parseHash(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1805 hashData.set('tags', newFilterTags.values().join(',')); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1806 hashData.set('search', newSearchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1807 history.pushState(null, null, serializeHash(url, hashData)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1808 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1809 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1810 BooketController.prototype.onLoadFile = function (bookmarkFile, merge) { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1811 if (this.bookmarkModel.unsavedChanges) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1812 if (!this.actionsView.confirmLoadFile()) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1813 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1814 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1815 this.bookmarkModel.unsavedChanges = false; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1816 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1817 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1818 this.bookmarkModel.loadFile(bookmarkFile, merge); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1819 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1820 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1821 BooketController.prototype.onImportFile = function (bookmarkFile, merge) { |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1822 if (this.bookmarkModel.unsavedChanges) { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1823 if (!this.actionsView.confirmLoadFile()) { |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1824 return; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1825 } |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1826 this.bookmarkModel.unsavedChanges = false; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1827 } |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1828 |
19
4a4d9527c06f
Add merge options
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
18
diff
changeset
|
1829 this.bookmarkModel.importFile(bookmarkFile, merge); |
10
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1830 }; |
20902b548d9f
Add Netscape bookmark file import function
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
7
diff
changeset
|
1831 |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1832 BooketController.prototype.onEditBookmark = function (bookmarkUrl) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1833 this.bookmarkView.displayBookmarkEditor( |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1834 this.bookmarkModel.get(bookmarkUrl)); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1835 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1836 |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1837 BooketController.prototype.onSaveBookmark = function (url, title, |
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1838 favicon, tags, originalUrl) { |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1839 var ctime; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1840 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1841 if (originalUrl === undefined) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1842 // saving new bookmark, get confirmation before replacing existing one |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1843 if (this.bookmarkModel.has(url)) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1844 if (this.bookmarkView.confirmReplaceBookmark( |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1845 this.bookmarkModel.get(url))) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1846 this.bookmarkModel.delete(url); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1847 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1848 return; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1849 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1850 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1851 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1852 ctime = new Date(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1853 } else { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1854 // saving edited bookmark, preserve creation time of any replaced |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1855 // bookmark |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1856 ctime = (this.bookmarkModel.has(url)) ? |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1857 this.bookmarkModel.get(url).ctime : new Date(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1858 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1859 this.bookmarkModel.delete(originalUrl); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1860 } |
7
a1a934adff8d
Add support for favicons
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
6
diff
changeset
|
1861 this.bookmarkModel.add(new Bookmark(url, title, favicon, tags, ctime)); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1862 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1863 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1864 BooketController.prototype.onDeleteBookmark = function (bookmarkUrl) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1865 if (this.bookmarkView.confirmDeleteBookmark( |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1866 this.bookmarkModel.get(bookmarkUrl))) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1867 this.bookmarkModel.delete(bookmarkUrl); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1868 } |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1869 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1870 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1871 BooketController.prototype.onToggleFilterTag = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1872 this.bookmarkModel.toggleFilterTag(tag); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1873 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1874 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1875 BooketController.prototype.onSetTagFilter = function (tag) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1876 this.bookmarkModel.setFilterTags(new StringSet([tag])); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1877 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1878 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1879 BooketController.prototype.onSearch = function (searchTerm) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1880 this.bookmarkModel.setSearchTerm(searchTerm); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1881 }; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1882 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1883 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1884 document.addEventListener('DOMContentLoaded', function (e) { |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1885 var controller; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1886 var bookmarkModel; |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1887 var keyboardShortcutsView; |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1888 var actionsView; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1889 var tagView; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1890 var bookmarkView; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1891 var hashChangeEvent; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1892 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1893 bookmarkModel = new BookmarkModel(); |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1894 keyboardShortcutsView = new KeyboardShortcutsView(); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1895 tagView = new TagView(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1896 actionsView = new ActionsView(); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1897 bookmarkView = new BookmarkView(); |
22
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1898 controller = new BooketController(bookmarkModel, keyboardShortcutsView, |
b19db583b5f8
Display keyboard shortcuts as an overly when pressing Alt
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
19
diff
changeset
|
1899 actionsView, tagView, bookmarkView); |
0
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1900 |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1901 // initialize state from the current URL |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1902 hashChangeEvent = new Event('hashchange'); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1903 hashChangeEvent.oldURL = window.location.href; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1904 hashChangeEvent.newURL = window.location.href; |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1905 window.dispatchEvent(hashChangeEvent); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1906 }); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1907 }()); |
c2248f662a2c
Initial revision
Guido Berhoerster <guido+booket@berhoerster.name>
parents:
diff
changeset
|
1908 |