author | Michael Krelin <hacker@klever.net> | 2006-09-29 22:27:02 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-09-29 22:27:02 (UTC) |
commit | 3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8 (patch) (side-by-side diff) | |
tree | b76d0ba42afa8252747bc2c9a0bfd6c5b8b3f07b | |
parent | dcd46fa0189aa1893eb2faa7da4fd823dc6c392d (diff) | |
download | fireflix-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
-rw-r--r-- | content/Makefile.am | 2 | ||||
-rw-r--r-- | content/fireflix-panel.xul | 1 | ||||
-rw-r--r-- | content/flickr.js | 50 | ||||
-rw-r--r-- | content/util.js | 61 |
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 @@ -1,11 +1,11 @@ xpichromecontent_DATA = \ autoconf.dtd \ browser.xul about.xul fireflix-panel.xul photoset-props.xul \ generated-content.xul \ - photoset-props.js fireflix.js flickr.js md5.js \ + photoset-props.js fireflix.js flickr.js util.js md5.js \ generated-content.js \ fireflix.css \ background.jpeg sized_icons = \ $(addsuffix .png, \ 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 @@ -11,12 +11,13 @@ ondragdrop="nsDragAndDrop.drop(event,fireflix.uploadObserver)" > <script src="chrome://global/content/nsDragAndDrop.js"/> <script src="chrome://global/content/nsTransferable.js"/> <script type="application/x-javascript" src="md5.js" /> + <script type="application/x-javascript" src="util.js" /> <script type="application/x-javascript" src="flickr.js" /> <script type="application/x-javascript" src="fireflix.js" /> <stringbundleset> <stringbundle id="loc_strings" src="chrome://fireflix/locale/fireflix.properties" /> </stringbundleset> diff --git a/content/flickr.js b/content/flickr.js index 3554796..add628a 100644 --- a/content/flickr.js +++ b/content/flickr.js @@ -86,62 +86,12 @@ Photo.prototype = { // TODO: notes/note // TODO: tags/tag/@id tags/tag/@author tags/tag/@raw tags/tag // TODO: urls/url/@type urls/url } }; -function toutf8(ucode) { - var rv = ''; - for(var i=0;i<ucode.length;++i) { - var cc = ucode.charCodeAt(i); - if(cc<=0x7F) - rv += ucode.charAt(i); - else if(cc<=0x7ff) - rv += String.fromCharCode( - 0xc0|((cc>> 6)&0x1f), - 0x80|( cc &0x3f) ); - else if(cc<=0xffff) - rv += String.fromCharCode( - 0xe0|((cc>>12)&0x0f), - 0x80|((cc>> 6)&0x3f), - 0x80|( cc &0x3f) ); - else if(cc<=0x1fffff) - rv += String.fromCharCode( - 0xf0|((cc>>18)&0x07), - 0x80|((cc>>12)&0x3f), - 0x80|((cc>> 6)&0x3f), - 0x80|( cc &0x3f) ); - else if(cc<=0x03ffffff) - rv += String.fromCharCode( - 0xf8|((cc>>24)&0x03), - 0x80|((cc>>18)&0x3f), - 0x80|((cc>>12)&0x3f), - 0x80|((cc>> 6)&0x3f), - 0x80|( cc &0x3f) ); - else if(cc<=0x7fffffff) - rv += String.fromCharCode( - 0xfc|((cc>>30)&0x01), - 0x80|((cc>>24)&0x3f), - 0x80|((cc>>18)&0x3f), - 0x80|((cc>>12)&0x3f), - 0x80|((cc>> 6)&0x3f), - 0x80|( cc &0x3f) ); - } - return rv; -} -function xp_str(xp,x) { - var rv = x.evaluate( - xp, x, null, XPathResult.STRING_TYPE, null ); - return rv.stringValue; -} -function xp_node(xp,x) { - var rv = x.evaluate( - xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); - return rv.singleNodeValue; -} - function Flickr() { } Flickr.prototype = { rest_url: 'http://www.flickr.com/services/rest/', auth_url: 'http://flickr.com/services/auth/', photo_url: 'http://static.flickr.com/', 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 @@ +/* + * convert unicode string to utf-8 representation. + * needed for correct md5 hash calculation. + */ +function toutf8(ucode) { + var rv = ''; + for(var i=0;i<ucode.length;++i) { + var cc = ucode.charCodeAt(i); + if(cc<=0x7F) + rv += ucode.charAt(i); + else if(cc<=0x7ff) + rv += String.fromCharCode( + 0xc0|((cc>> 6)&0x1f), + 0x80|( cc &0x3f) ); + else if(cc<=0xffff) + rv += String.fromCharCode( + 0xe0|((cc>>12)&0x0f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + else if(cc<=0x1fffff) + rv += String.fromCharCode( + 0xf0|((cc>>18)&0x07), + 0x80|((cc>>12)&0x3f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + else if(cc<=0x03ffffff) + rv += String.fromCharCode( + 0xf8|((cc>>24)&0x03), + 0x80|((cc>>18)&0x3f), + 0x80|((cc>>12)&0x3f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + else if(cc<=0x7fffffff) + rv += String.fromCharCode( + 0xfc|((cc>>30)&0x01), + 0x80|((cc>>24)&0x3f), + 0x80|((cc>>18)&0x3f), + 0x80|((cc>>12)&0x3f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + } + return rv; +} + +/* + * extract xpath-specified string value + */ +function xp_str(xp,x) { + var rv = x.evaluate( + xp, x, null, XPathResult.STRING_TYPE, null ); + return rv.stringValue; +} +/* + * extract xpath-specified node + */ +function xp_node(xp,x) { + var rv = x.evaluate( + xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); + return rv.singleNodeValue; +} + |