Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 1 | function number_format( number, decimals, dec_point, thousands_sep ) { |
| 2 | // http://kevin.vanzonneveld.net |
| 3 | // + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) |
| 4 | // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| 5 | // + bugfix by: Michael White (http://crestidg.com) |
| 6 | // + bugfix by: Benjamin Lupton |
| 7 | // + bugfix by: Allan Jensen (http://www.winternet.no) |
| 8 | // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) |
| 9 | // * example 1: number_format(1234.5678, 2, '.', ''); |
| 10 | // * returns 1: 1234.57 |
| 11 | |
| 12 | var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals; |
| 13 | var d = dec_point == undefined ? "," : dec_point; |
| 14 | var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : ""; |
| 15 | var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; |
| 16 | |
| 17 | return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); |
| 18 | } |
| 19 | |
| 20 | function SegNumToFileSize (segNum) { |
| 21 | filesize = segNum * 1024; |
| 22 | |
| 23 | if (filesize >= 1073741824) { |
| 24 | filesize = number_format(filesize / 1073741824, 2, '.', '') + ' Gb'; |
| 25 | } else { |
| 26 | if (filesize >= 1048576) { |
| 27 | filesize = number_format(filesize / 1048576, 2, '.', '') + ' Mb'; |
| 28 | } else { |
| 29 | if (filesize > 1024) { |
| 30 | filesize = number_format(filesize / 1024, 0) + ' Kb'; |
| 31 | } else { |
| 32 | filesize = '< 1 Kb'; |
| 33 | }; |
| 34 | }; |
| 35 | }; |
| 36 | return filesize; |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * @brief Convert binary data represented as non-escaped hex string to Uint8Array |
| 41 | * @param str String like ba0cb43e4b9639c114a0487d5faa7c70452533963fc8beb37d1b67c09a48a21d |
| 42 | * |
| 43 | * Note that if string length is odd, null will be returned |
| 44 | */ |
| 45 | StringHashToUint8Array = function (str) { |
| 46 | if (str.length % 2 != 0) { |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | var buf = new Uint8Array (str.length / 2); |
| 51 | |
| 52 | for (var i = 0; i < str.length; i+=2) { |
| 53 | value = parseInt (str.substring (i, i+2), 16); |
| 54 | buf[i/2] = value; |
| 55 | } |
| 56 | |
| 57 | return buf; |
| 58 | }; |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 59 | |
| 60 | imgFullPath = function (imgName) { |
| 61 | return "images/" + imgName + ".png"; |
| 62 | } |
| 63 | |
| 64 | fileExtension = function (fileName) { |
| 65 | defaultExtension = "file"; |
| 66 | knownExtensions = ["ai", "aiff", "bib", "bz2", "c", "chm", "conf", "cpp", "css", "csv", "deb", "divx", "doc", "file", "gif", "gz", "hlp", "htm", "html", "iso", "jpeg", "jpg", "js", "mov", "mp3", "mpg", "odc", "odf", "odg", "odi", "odp", "ods", "odt", "ogg", "pdf", "pgp", "php", "pl", "png", "ppt", "pptx", "ps", "py", "ram", "rar", "rb", "rm", "rpm", "rtf", "sql", "swf", "sxc", "sxd", "sxi", "sxw", "tar", "tex", "tgz", "txt", "vcf", "wav", "wma", "wmv", "xls", "xml", "xpi", "xvid", "zip"]; |
| 67 | |
| 68 | extStart = fileName.lastIndexOf('.'); |
| 69 | if (extStart < 0) { |
| 70 | return imgFullPath (defaultExtension); |
| 71 | } |
| 72 | |
| 73 | extension = fileName.substr (extStart+1); |
| 74 | // return imgFullPath (extension); |
| 75 | if ($.inArray(extension, knownExtensions) >= 0) { |
Alexander Afanasyev | c24db64 | 2013-03-09 16:41:02 -0800 | [diff] [blame^] | 76 | return extension; |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 77 | } |
| 78 | else { |
Alexander Afanasyev | c24db64 | 2013-03-09 16:41:02 -0800 | [diff] [blame^] | 79 | return defaultExtension; |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 80 | } |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | openHistoryForItem = function (fileName) { |
Alexander Afanasyev | c24db64 | 2013-03-09 16:41:02 -0800 | [diff] [blame^] | 85 | url = new HistoryClosure (null).base_no_item_url ("fileHistory") |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 86 | url += "&item=" + encodeURIComponent (encodeURIComponent (fileName)); |
| 87 | document.location = url; |
| 88 | }; |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 90 | displayContent = function (newcontent, more, baseUrl) { |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 92 | $("#content").fadeOut ("fast", function () { |
| 93 | $(this).replaceWith (newcontent); |
| 94 | $("#content").fadeIn ("fast"); |
| 95 | }); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 97 | $("#content-nav").fadeOut ("fast", function () { |
| 98 | $("#content-nav a").hide (); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 100 | if (PARAMS.offset !== undefined || more !== undefined) { |
| 101 | $("#content-nav").fadeIn ("fast"); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 103 | if (more !== undefined) { |
| 104 | $("#get-more").show (); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 106 | $("#get-more").unbind ('click').click (function () { |
| 107 | url = baseUrl; |
| 108 | url += "&offset="+more; |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 110 | document.location = url; |
| 111 | }); |
| 112 | } |
| 113 | if (PARAMS.offset > 0) { |
| 114 | $("#get-less").show (); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 115 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 116 | $("#get-less").unbind ('click').click (function () { |
| 117 | url = baseUrl; |
| 118 | if (PARAMS.offset > 5) { |
| 119 | url += "&offset="+(PARAMS.offset - 5); |
| 120 | } |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 121 | |
Alexander Afanasyev | 10babd2 | 2013-03-04 13:53:36 -0800 | [diff] [blame] | 122 | document.location = url; |
| 123 | }); |
| 124 | } |
| 125 | } |
| 126 | }); |
| 127 | }; |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame] | 128 | |
| 129 | function custom_alert (output_msg, title_msg) |
| 130 | { |
| 131 | if (!title_msg) |
| 132 | title_msg = 'Alert'; |
| 133 | |
| 134 | if (!output_msg) |
| 135 | output_msg = 'No Message to Display'; |
| 136 | |
| 137 | $("<div></div>").html(output_msg).dialog({ |
| 138 | title: title_msg, |
| 139 | resizable: false, |
| 140 | modal: true, |
| 141 | buttons: { |
| 142 | "Ok": function() |
| 143 | { |
| 144 | $( this ).dialog( "close" ); |
| 145 | } |
| 146 | } |
| 147 | }); |
| 148 | } |