Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

script_start.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. "use strict";
  2. /* Prototypes */
  3. if (!String.prototype.trim) {
  4. String.prototype.trim = function () {
  5. return this.replace(/^\s+|\s+$/g,'');
  6. };
  7. }
  8. var listener = {
  9. set: function (el,type,callback) {
  10. if (document.addEventListener) {
  11. el.addEventListener(type, callback, false);
  12. } else {
  13. // IE hack courtesy of http://blog.stchur.com/2006/10/12/fixing-ies-attachevent-failures
  14. var f = function() {
  15. callback.call(el);
  16. };
  17. el.attachEvent('on' + type, f);
  18. }
  19. }
  20. };
  21. /* Site wide functions */
  22. // http://www.thefutureoftheweb.com/blog/adddomloadevent
  23. // retrieved 2010-08-12
  24. var addDOMLoadEvent = (
  25. function() {
  26. var e = [], t, s, n, i, o, d = document, w = window, r = 'readyState', c = 'onreadystatechange',
  27. x = function() {
  28. n = 1;
  29. clearInterval(t);
  30. while (i = e.shift()) {
  31. i();
  32. }
  33. if (s) {
  34. s[c] = ''
  35. }
  36. };
  37. return function(f) {
  38. if (n) {
  39. return f();
  40. }
  41. if (!e[0]) {
  42. d.addEventListener && d.addEventListener("DOMContentLoaded", x, false);
  43. /*@cc_on@*//*@if(@_win32)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/
  44. if (/WebKit/i.test(navigator.userAgent))
  45. t = setInterval(function() {
  46. /loaded|complete/.test(d[r]) && x()
  47. }, 10);
  48. o = w.onload;
  49. w.onload = function() {
  50. x();
  51. o && o()
  52. }
  53. }
  54. e.push(f)
  55. }
  56. }
  57. )();
  58. //PHP ports
  59. function isset(variable) {
  60. return (typeof(variable) === 'undefined') ? false : true;
  61. }
  62. function is_array(input) {
  63. return typeof(input) === 'object' && input instanceof Array;
  64. }
  65. function function_exists(function_name) {
  66. return (typeof this.window[function_name] === 'function');
  67. }
  68. function html_entity_decode(str) {
  69. var el = document.createElement("div");
  70. el.innerHTML = str;
  71. for (var i = 0, ret = ''; i < el.childNodes.length; i++) {
  72. ret += el.childNodes[i].nodeValue;
  73. }
  74. return ret;
  75. }
  76. function get_size(size) {
  77. var steps = 0
  78. while (size >= 1024) {
  79. steps++
  80. size = size / 1024
  81. }
  82. var exts = ['B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']
  83. return (size.toFixed(2) + (exts[steps]||''))
  84. }
  85. function get_ratio_color(ratio) {
  86. if (ratio < 0.1) { return 'r00'; }
  87. if (ratio < 0.2) { return 'r01'; }
  88. if (ratio < 0.3) { return 'r02'; }
  89. if (ratio < 0.4) { return 'r03'; }
  90. if (ratio < 0.5) { return 'r04'; }
  91. if (ratio < 0.6) { return 'r05'; }
  92. if (ratio < 0.7) { return 'r06'; }
  93. if (ratio < 0.8) { return 'r07'; }
  94. if (ratio < 0.9) { return 'r08'; }
  95. if (ratio < 1) { return 'r09'; }
  96. if (ratio < 2) { return 'r10'; }
  97. if (ratio < 5) { return 'r20'; }
  98. return 'r50';
  99. }
  100. function ratio(dividend, divisor, color) {
  101. if (!color) {
  102. color = true;
  103. }
  104. if (divisor == 0 && dividend == 0) {
  105. return '--';
  106. } else if (divisor == 0) {
  107. return '<span class="r99">∞</span>';
  108. } else if (dividend == 0 && divisor > 0) {
  109. return '<span class="r00">-∞</span>';
  110. }
  111. var rat = ((dividend / divisor) - 0.005).toFixed(2); //Subtract .005 to floor to 2 decimals
  112. if (color) {
  113. var col = get_ratio_color(rat);
  114. if (col) {
  115. rat = '<span class="' + col + '">' + rat + '</span>';
  116. }
  117. }
  118. return rat;
  119. }
  120. function save_message(message) {
  121. var messageDiv = document.createElement("div");
  122. messageDiv.className = "save_message";
  123. messageDiv.innerHTML = message;
  124. $("#content").raw().insertBefore(messageDiv,$("#content").raw().firstChild);
  125. }
  126. function error_message(message) {
  127. var messageDiv = document.createElement("div");
  128. messageDiv.className = "error_message";
  129. messageDiv.innerHTML = message;
  130. $("#content").raw().insertBefore(messageDiv,$("#content").raw().firstChild);
  131. }
  132. //returns key if true, and false if false. better than the PHP funciton
  133. function in_array(needle, haystack, strict) {
  134. if (strict === undefined) {
  135. strict = false;
  136. }
  137. for (var key in haystack) {
  138. if ((haystack[key] == needle && strict === false) || haystack[key] === needle) {
  139. return true;
  140. }
  141. }
  142. return false;
  143. }
  144. function array_search(needle, haystack, strict) {
  145. if (strict === undefined) {
  146. strict = false;
  147. }
  148. for (var key in haystack) {
  149. if ((strict === false && haystack[key] == needle) || haystack[key] === needle) {
  150. return key;
  151. }
  152. }
  153. return false;
  154. }
  155. var util = function (selector, context) {
  156. return new util.fn.init(selector, context);
  157. }
  158. function URL() {
  159. var path = window.location.pathname.split('/');
  160. var path = path[path.length - 1].split(".")[0];
  161. var splitted = window.location.search.substr(1).split("&");
  162. var query = {};
  163. var length = 0;
  164. for (var i = 0; i < splitted.length; i++) {
  165. var q = splitted[i].split("=");
  166. if (q != "") {
  167. query[q[0]] = q[1];
  168. length++;
  169. }
  170. };
  171. query['length'] = length;
  172. var response = new Array();
  173. response['path'] = path;
  174. response['query'] = query;
  175. return response;
  176. }
  177. function isNumberKey(e) {
  178. var charCode = (e.which) ? e.which : e.keyCode
  179. if (charCode == 46) {
  180. return true;
  181. }
  182. if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  183. return false;
  184. }
  185. return true;
  186. }
  187. function sleep(milliseconds) {
  188. var start = new Date().getTime();
  189. for (var i = 0; i < 1e7; i++) {
  190. if ((new Date().getTime() - start) > milliseconds){
  191. break;
  192. }
  193. }
  194. }
  195. $.fn.extend({
  196. results: function () {
  197. return this.size();
  198. },
  199. gshow: function () {
  200. return this.remove_class('hidden');
  201. },
  202. ghide: function (force) {
  203. return this.add_class('hidden', force);
  204. },
  205. gtoggle: function (force) {
  206. //Should we interate and invert all entries, or just go by the first?
  207. if (!in_array('hidden', this[0].className.split(' '))) {
  208. this.add_class('hidden', force);
  209. } else {
  210. this.remove_class('hidden');
  211. }
  212. return this;
  213. },
  214. listen: function (event, callback) {
  215. for (var i = 0, il = this.size(); i < il; i++) {
  216. var object = this[i];
  217. if (document.addEventListener) {
  218. object.addEventListener(event, callback, false);
  219. } else {
  220. object.attachEvent('on' + event, callback);
  221. }
  222. }
  223. return this;
  224. },
  225. add_class: function (class_name, force) {
  226. for (var i = 0, il = this.size(); i < il; i++) {
  227. var object = this[i];
  228. if (object.className === '') {
  229. object.className = class_name;
  230. } else if (force || !in_array(class_name, object.className.split(' '))) {
  231. object.className = object.className + ' ' + class_name;
  232. }
  233. }
  234. return this;
  235. },
  236. remove_class: function (class_name) {
  237. for (var i = 0, il = this.size(); i < il; i++) {
  238. var object = this[i];
  239. var classes = object.className.split(' ');
  240. var result = array_search(class_name, classes);
  241. if (result !== false) {
  242. classes.splice(result, 1);
  243. object.className = classes.join(' ');
  244. }
  245. }
  246. return this;
  247. },
  248. has_class: function(class_name) {
  249. for (var i = 0, il = this.size(); i < il; i++) {
  250. var object = this[i];
  251. var classes = object.className.split(' ');
  252. if (array_search(class_name, classes)) {
  253. return true;
  254. }
  255. }
  256. return false;
  257. },
  258. toggle_class: function(class_name) {
  259. for (var i = 0, il = this.size(); i < il; i++) {
  260. var object = this[i];
  261. var classes = object.className.split(' ');
  262. var result = array_search(class_name, classes);
  263. if (result !== false) {
  264. classes.splice(result, 1);
  265. object.className = classes.join(' ');
  266. } else {
  267. if (object.className === '') {
  268. object.className = class_name;
  269. } else {
  270. object.className = object.className + ' ' + class_name;
  271. }
  272. }
  273. }
  274. return this;
  275. },
  276. disable : function () {
  277. $(this).prop('disabled', true);
  278. return this;
  279. },
  280. enable : function () {
  281. $(this).prop('disabled', false);
  282. return this;
  283. },
  284. raw: function (number) {
  285. if (typeof number == 'undefined') {
  286. number = 0;
  287. }
  288. return $(this).get(number);
  289. },
  290. nextElementSibling: function () {
  291. var here = this[0];
  292. if (here.nextElementSibling) {
  293. return $(here.nextElementSibling);
  294. }
  295. do {
  296. here = here.nextSibling;
  297. } while (here.nodeType != 1);
  298. return $(here);
  299. },
  300. previousElementSibling: function () {
  301. var here = this[0];
  302. if (here.previousElementSibling) {
  303. return $(here.previousElementSibling);
  304. }
  305. do {
  306. here = here.nextSibling;
  307. } while (here.nodeType != 1);
  308. return $(here);
  309. },
  310. updateTooltip: function(tooltip) {
  311. if ($.fn.tooltipster) {
  312. $(this).tooltipster('update', tooltip);
  313. } else {
  314. $(this).attr('title', tooltip);
  315. }
  316. return this;
  317. },
  318. // Disable unset form elements to allow search URLs cleanups
  319. disableUnset: function() {
  320. $('input, select', this).filter(function() {
  321. return $(this).val() === "";
  322. }).disable();
  323. return this;
  324. },
  325. // Prevent double submission of forms
  326. preventDoubleSubmission: function() {
  327. $(this).submit(function(e) {
  328. var $form = $(this);
  329. if ($form.data('submitted') === true) {
  330. // Previously submitted - don't submit again
  331. e.preventDefault();
  332. } else {
  333. // Mark it so that the next submit can be ignored
  334. $form.data('submitted', true);
  335. }
  336. });
  337. // Keep chainability
  338. return this;
  339. }
  340. });
  341. if ($('meta[name=authkey]').raw()) {
  342. var authkey = $('meta[name=authkey]').raw().content;
  343. var userid = parseInt($('meta[name=userid]').raw().content);
  344. }