summaryrefslogtreecommitdiffabout
path: root/content
authorMichael Krelin <hacker@klever.net>2006-09-29 22:27:02 (UTC)
committer Michael Krelin <hacker@klever.net>2006-09-29 22:27:02 (UTC)
commit3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8 (patch) (unidiff)
treeb76d0ba42afa8252747bc2c9a0bfd6c5b8b3f07b /content
parentdcd46fa0189aa1893eb2faa7da4fd823dc6c392d (diff)
downloadfireflix-3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8.zip
fireflix-3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8.tar.gz
fireflix-3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8.tar.bz2
code beauty: moved some code into util.js
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@168 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'content') (more/less context) (ignore whitespace changes)
-rw-r--r--content/Makefile.am2
-rw-r--r--content/fireflix-panel.xul1
-rw-r--r--content/flickr.js50
-rw-r--r--content/util.js61
4 files changed, 63 insertions, 51 deletions
diff --git a/content/Makefile.am b/content/Makefile.am
index 8548400..d8607fb 100644
--- a/content/Makefile.am
+++ b/content/Makefile.am
@@ -2,7 +2,7 @@ xpichromecontent_DATA = \
2 autoconf.dtd \ 2 autoconf.dtd \
3 browser.xul about.xul fireflix-panel.xul photoset-props.xul \ 3 browser.xul about.xul fireflix-panel.xul photoset-props.xul \
4 generated-content.xul \ 4 generated-content.xul \
5 photoset-props.js fireflix.js flickr.js md5.js \ 5 photoset-props.js fireflix.js flickr.js util.js md5.js \
6 generated-content.js \ 6 generated-content.js \
7 fireflix.css \ 7 fireflix.css \
8 background.jpeg 8 background.jpeg
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul
index 569beb0..2a15a51 100644
--- a/content/fireflix-panel.xul
+++ b/content/fireflix-panel.xul
@@ -14,6 +14,7 @@
14 <script src="chrome://global/content/nsDragAndDrop.js"/> 14 <script src="chrome://global/content/nsDragAndDrop.js"/>
15 <script src="chrome://global/content/nsTransferable.js"/> 15 <script src="chrome://global/content/nsTransferable.js"/>
16 <script type="application/x-javascript" src="md5.js" /> 16 <script type="application/x-javascript" src="md5.js" />
17 <script type="application/x-javascript" src="util.js" />
17 <script type="application/x-javascript" src="flickr.js" /> 18 <script type="application/x-javascript" src="flickr.js" />
18 <script type="application/x-javascript" src="fireflix.js" /> 19 <script type="application/x-javascript" src="fireflix.js" />
19 20
diff --git a/content/flickr.js b/content/flickr.js
index 3554796..add628a 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -89,56 +89,6 @@ Photo.prototype = {
89 } 89 }
90}; 90};
91 91
92function toutf8(ucode) {
93 var rv = '';
94 for(var i=0;i<ucode.length;++i) {
95 var cc = ucode.charCodeAt(i);
96 if(cc<=0x7F)
97 rv += ucode.charAt(i);
98 else if(cc<=0x7ff)
99 rv += String.fromCharCode(
100 0xc0|((cc>> 6)&0x1f),
101 0x80|( cc &0x3f) );
102 else if(cc<=0xffff)
103 rv += String.fromCharCode(
104 0xe0|((cc>>12)&0x0f),
105 0x80|((cc>> 6)&0x3f),
106 0x80|( cc &0x3f) );
107 else if(cc<=0x1fffff)
108 rv += String.fromCharCode(
109 0xf0|((cc>>18)&0x07),
110 0x80|((cc>>12)&0x3f),
111 0x80|((cc>> 6)&0x3f),
112 0x80|( cc &0x3f) );
113 else if(cc<=0x03ffffff)
114 rv += String.fromCharCode(
115 0xf8|((cc>>24)&0x03),
116 0x80|((cc>>18)&0x3f),
117 0x80|((cc>>12)&0x3f),
118 0x80|((cc>> 6)&0x3f),
119 0x80|( cc &0x3f) );
120 else if(cc<=0x7fffffff)
121 rv += String.fromCharCode(
122 0xfc|((cc>>30)&0x01),
123 0x80|((cc>>24)&0x3f),
124 0x80|((cc>>18)&0x3f),
125 0x80|((cc>>12)&0x3f),
126 0x80|((cc>> 6)&0x3f),
127 0x80|( cc &0x3f) );
128 }
129 return rv;
130}
131function xp_str(xp,x) {
132 var rv = x.evaluate(
133 xp, x, null, XPathResult.STRING_TYPE, null );
134 return rv.stringValue;
135}
136function xp_node(xp,x) {
137 var rv = x.evaluate(
138 xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
139 return rv.singleNodeValue;
140}
141
142function Flickr() { } 92function Flickr() { }
143Flickr.prototype = { 93Flickr.prototype = {
144 94
diff --git a/content/util.js b/content/util.js
new file mode 100644
index 0000000..5af0978
--- a/dev/null
+++ b/content/util.js
@@ -0,0 +1,61 @@
1/*
2 * convert unicode string to utf-8 representation.
3 * needed for correct md5 hash calculation.
4 */
5function toutf8(ucode) {
6 var rv = '';
7 for(var i=0;i<ucode.length;++i) {
8 var cc = ucode.charCodeAt(i);
9 if(cc<=0x7F)
10 rv += ucode.charAt(i);
11 else if(cc<=0x7ff)
12 rv += String.fromCharCode(
13 0xc0|((cc>> 6)&0x1f),
14 0x80|( cc &0x3f) );
15 else if(cc<=0xffff)
16 rv += String.fromCharCode(
17 0xe0|((cc>>12)&0x0f),
18 0x80|((cc>> 6)&0x3f),
19 0x80|( cc &0x3f) );
20 else if(cc<=0x1fffff)
21 rv += String.fromCharCode(
22 0xf0|((cc>>18)&0x07),
23 0x80|((cc>>12)&0x3f),
24 0x80|((cc>> 6)&0x3f),
25 0x80|( cc &0x3f) );
26 else if(cc<=0x03ffffff)
27 rv += String.fromCharCode(
28 0xf8|((cc>>24)&0x03),
29 0x80|((cc>>18)&0x3f),
30 0x80|((cc>>12)&0x3f),
31 0x80|((cc>> 6)&0x3f),
32 0x80|( cc &0x3f) );
33 else if(cc<=0x7fffffff)
34 rv += String.fromCharCode(
35 0xfc|((cc>>30)&0x01),
36 0x80|((cc>>24)&0x3f),
37 0x80|((cc>>18)&0x3f),
38 0x80|((cc>>12)&0x3f),
39 0x80|((cc>> 6)&0x3f),
40 0x80|( cc &0x3f) );
41 }
42 return rv;
43}
44
45/*
46 * extract xpath-specified string value
47 */
48function xp_str(xp,x) {
49 var rv = x.evaluate(
50 xp, x, null, XPathResult.STRING_TYPE, null );
51 return rv.stringValue;
52}
53/*
54 * extract xpath-specified node
55 */
56function xp_node(xp,x) {
57 var rv = x.evaluate(
58 xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
59 return rv.singleNodeValue;
60}
61