Simple image host.
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.

global.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. (function() {
  2. window.util = {};
  3. util.notify = function notify(title, body) {
  4. var elem = $("#notify-box");
  5. elem.children(".title").html(title);
  6. elem.children(".body").html(body || "");
  7. elem.addClass("active");
  8. notify.timeout = setTimeout(function() {
  9. elem.removeClass("active");
  10. }, 5000);
  11. }
  12. $(document).ready(function() {
  13. $("#notify-box").on("mouseenter", function() {
  14. clearTimeout(util.notify.timeout);
  15. });
  16. $("#login-form").on("submit", function(evt) {
  17. evt.stopPropagation();
  18. evt.preventDefault();
  19. util.notify("Feature Not Implemented", "This feature is not implemented.");
  20. });
  21. });
  22. util.error = function(body) {
  23. util.notify("An error occurred.", body);
  24. }
  25. util.htmlEntities = function(str) {
  26. return str.replace(/&/g, "&")
  27. .replace(/</g, "&lt;")
  28. .replace(/>/g, "&lt;")
  29. .replace(/"/g, "&quot");
  30. }
  31. util.api = function(name, data, cb, getXhr) {
  32. var fd = new FormData();
  33. for (var i in data) {
  34. fd.append(i, data[i]);
  35. }
  36. return $.ajax({
  37. method: "POST",
  38. url: "/api/"+name,
  39. data: fd,
  40. processData: false,
  41. contentType: false,
  42. xhr: function() {
  43. var xhr = new XMLHttpRequest();
  44. if (getXhr)
  45. getXhr(xhr);
  46. return xhr;
  47. }
  48. }).done(function(res) {
  49. console.log("response from "+name+":");
  50. console.log(res);
  51. var obj = JSON.parse(res);
  52. if (obj.success)
  53. cb(null, obj);
  54. else
  55. cb(obj.error);
  56. });
  57. }
  58. util.async = function(n, cb) {
  59. if (typeof n !== "number")
  60. throw new Error("Expected number, got "+typeof n);
  61. if (n < 1)
  62. return cb();
  63. var res = {};
  64. return function(key, val) {
  65. if (key !== undefined)
  66. res[key] = val;
  67. if (n === 1)
  68. cb(res);
  69. else
  70. n -= 1;
  71. }
  72. }
  73. })();