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