Pictures!
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. function api(method, args, cb) {
  2. var argstr = "?" + Object.keys(args).map(function(key) {
  3. return encodeURIComponent(key)+"="+encodeURIComponent(args[key]);
  4. }).join("&");
  5. fetch("/admin/api/"+method+argstr, { method: "POST" })
  6. .then(response => response.json())
  7. .then(res => cb(res.err, res.obj));
  8. }
  9. function elem(tag, props, children) {
  10. var e;
  11. if (tag instanceof HTMLElement)
  12. e = tag;
  13. else
  14. e = document.createElement(tag);
  15. if (props) {
  16. for (var i in props) {
  17. e[i] = props[i];
  18. }
  19. }
  20. if (children) {
  21. for (var i in children) {
  22. e.appendChild(children[i]);
  23. }
  24. }
  25. e.appendTo = function(p) {
  26. p.appendChild(e);
  27. return e;
  28. }
  29. e.on = function() {
  30. e.addEventListener.apply(e, arguments);
  31. return e;
  32. }
  33. e.addClass = function(name) {
  34. if (e.className.indexOf(name) !== -1)
  35. return e;
  36. e.className += " "+name;
  37. return e;
  38. }
  39. e.removeClass = function(name) {
  40. e.className = e.className
  41. .replace(name, "")
  42. .trim()
  43. .replace(/ +/, "");
  44. return e;
  45. }
  46. e.clear = function() {
  47. var fc;
  48. while (fc = e.firstChild)
  49. e.removeChild(fc);
  50. return e;
  51. }
  52. return e;
  53. }
  54. function uploadEl() {
  55. var fileEl;
  56. elem("div", { className: "uploader" }, [
  57. fileEl = elem("input", {
  58. type: "file",
  59. style: "display: none"
  60. });
  61. elem("button", {
  62. innerHTML: "Upload"
  63. }).on("click", () => {
  64. fileEl.click();
  65. });
  66. ]);
  67. }
  68. function async(n, cb) {
  69. var args = [];
  70. return function(arg) {
  71. args.push(arg);
  72. n -= 1;
  73. if (n === 0)
  74. cb(args);
  75. }
  76. }
  77. function debounce(fn, ms) {
  78. if (ms === undefined)
  79. ms = 100;
  80. var timeout;
  81. return function() {
  82. if (timeout)
  83. clearTimeout(timeout);
  84. timeout = setTimeout(function() {
  85. fn();
  86. timeout = null;
  87. }, ms);
  88. }
  89. }
  90. function error(msg) {
  91. alert(msg);
  92. }
  93. var $$ = function() {
  94. return elem(document.querySelector.apply(document, arguments));
  95. }