sf.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. var SF = (function() {
  6. function d(a) {
  7. return (a = a.attributes ? a.attributes.getNamedItem("class") : null)
  8. ? a.value.split(" ")
  9. : [];
  10. }
  11. function c(a) {
  12. var e = document.createAttribute("class");
  13. e.value = a.join(" ");
  14. return e;
  15. }
  16. var b = {
  17. attachListener: function(a, e, b) {
  18. if (a.addEventListener) a.addEventListener(e, b, !1);
  19. else if (a.attachEvent)
  20. a.attachEvent("on" + e, function() {
  21. b.apply(a, arguments);
  22. });
  23. else throw Error("Could not attach event.");
  24. }
  25. };
  26. b.indexOf = (function() {
  27. var a = Array.prototype.indexOf;
  28. return "function" === a
  29. ? function(e, b) {
  30. return a.call(e, b);
  31. }
  32. : function(a, b) {
  33. for (var c = a.length, d = 0; d < c; d++) if (a[d] === b) return d;
  34. return -1;
  35. };
  36. })();
  37. b.accept = function(a, e) {
  38. var c;
  39. a.children
  40. ? ((c = a.children), e(a))
  41. : "number" === typeof a.length && (c = a);
  42. for (var d = c ? c.length || 0 : 0; d--; ) b.accept(c[d], e);
  43. };
  44. b.getByClass = (function() {
  45. var a = document.getElementsByClassName;
  46. return "function" === typeof a
  47. ? function(e, b) {
  48. "string" === typeof e && ((b = e), (e = document));
  49. return a.call(e, b);
  50. }
  51. : function(a, c) {
  52. "string" === typeof a &&
  53. ((c = a), (a = document.getElementsByTagName("html")[0]));
  54. var d = [];
  55. b.accept(a, function(a) {
  56. b.classList.contains(a, c) && d.push(a);
  57. });
  58. return d;
  59. };
  60. })();
  61. b.classList = {};
  62. b.classList.add = function(a, b) {
  63. var f = d(a);
  64. f.push(b);
  65. a.attributes.setNamedItem(c(f));
  66. };
  67. b.classList.remove = function(a, e) {
  68. var f = d(a, e),
  69. n = b.indexOf(f, e);
  70. -1 !== n && (f.splice(n, 1), a.attributes.setNamedItem(c(f)));
  71. };
  72. b.classList.contains = function(a, c) {
  73. return -1 !== b.indexOf(d(a), c);
  74. };
  75. b.classList.toggle = function(a, b) {
  76. this.contains(a, b) ? this.remove(a, b) : this.add(a, b);
  77. };
  78. return b;
  79. })();
  80. ("use strict");
  81. (function() {
  82. function d(c) {
  83. for (var b in c) delete c[b];
  84. }
  85. SF.modal = function(c) {
  86. function b(a) {
  87. 27 == a.keyCode && f.close();
  88. }
  89. c.modalClass = "modal content";
  90. c.closeClass = "modal-close";
  91. c.modalStyles = d;
  92. c.closeStyles = d;
  93. var a = c.afterCreate,
  94. e = c.afterClose;
  95. c.afterCreate = function(c) {
  96. a && a(c);
  97. window.addEventListener("keydown", b);
  98. };
  99. c.afterClose = function(a) {
  100. e && e(a);
  101. window.removeEventListener("keydown", b);
  102. };
  103. var f = new picoModal(c)
  104. .afterCreate(c.afterCreate)
  105. .afterClose(c.afterClose);
  106. return f;
  107. };
  108. })();
  109. ("use strict");
  110. (function() {
  111. for (var d = SF.getByClass("toggler"), c = d.length; c--; )
  112. SF.attachListener(d[c], "click", function() {
  113. var b =
  114. SF.classList.contains(this, "icon-toggler-expanded") ||
  115. SF.classList.contains(this, "icon-toggler-collapsed"),
  116. a = document.getElementById(this.getAttribute("data-for"));
  117. SF.classList.toggle(this, "collapsed");
  118. SF.classList.contains(this, "collapsed")
  119. ? (SF.classList.add(a, "collapsed"),
  120. b &&
  121. (SF.classList.remove(this, "icon-toggler-expanded"),
  122. SF.classList.add(this, "icon-toggler-collapsed")))
  123. : (SF.classList.remove(a, "collapsed"),
  124. b &&
  125. (SF.classList.remove(this, "icon-toggler-collapsed"),
  126. SF.classList.add(this, "icon-toggler-expanded")));
  127. });
  128. })();
  129. ("use strict");
  130. (function() {
  131. for (var d = SF.getByClass("tree-a"), c = d.length; c--; )
  132. SF.attachListener(d[c], "click", function(b) {
  133. b = b.target || b.srcElement;
  134. "H2" !== b.nodeName ||
  135. SF.classList.contains(b, "tree-a-no-sub") ||
  136. SF.classList.toggle(b, "tree-a-active");
  137. });
  138. })();
  139. (function(d, c) {
  140. function b(a) {
  141. return "object" === typeof Node
  142. ? a instanceof Node
  143. : a && "object" === typeof a && "number" === typeof a.nodeType;
  144. }
  145. function a() {
  146. var a = [];
  147. return {
  148. watch: a.push.bind(a),
  149. trigger: function(b) {
  150. for (
  151. var c = !0,
  152. d = {
  153. preventDefault: function() {
  154. c = !1;
  155. }
  156. },
  157. e = 0;
  158. e < a.length;
  159. e++
  160. )
  161. a[e](b, d);
  162. return c;
  163. }
  164. };
  165. }
  166. function e(a) {
  167. this.elem = a;
  168. }
  169. function f(a, b) {
  170. return e
  171. .div()
  172. .clazz("pico-overlay")
  173. .clazz(a("overlayClass", ""))
  174. .stylize({
  175. display: "block",
  176. position: "fixed",
  177. top: "0px",
  178. left: "0px",
  179. height: "100%",
  180. width: "100%",
  181. zIndex: 1e4
  182. })
  183. .stylize(a("overlayStyles", { opacity: 0.5, background: "#000" }))
  184. .onClick(function() {
  185. a("overlayClose", !0) && b();
  186. });
  187. }
  188. function n(a, b) {
  189. var c = a("width", "auto");
  190. "number" === typeof c && (c = "" + c + "px");
  191. return e
  192. .div()
  193. .clazz("pico-content")
  194. .clazz(a("modalClass", ""))
  195. .stylize({
  196. display: "block",
  197. position: "fixed",
  198. zIndex: 10001,
  199. left: "50%",
  200. top: "50px",
  201. width: c,
  202. "-ms-transform": "translateX(-50%)",
  203. "-moz-transform": "translateX(-50%)",
  204. "-webkit-transform": "translateX(-50%)",
  205. "-o-transform": "translateX(-50%)",
  206. transform: "translateX(-50%)"
  207. })
  208. .stylize(
  209. a("modalStyles", {
  210. backgroundColor: "white",
  211. padding: "20px",
  212. borderRadius: "5px"
  213. })
  214. )
  215. .html(a("content"))
  216. .attr("role", "dialog")
  217. .onClick(function(a) {
  218. new e(a.target).anyAncestor(function(a) {
  219. return /\bpico-close\b/.test(a.elem.className);
  220. }) && b();
  221. });
  222. }
  223. function p(a) {
  224. return function() {
  225. return a().elem;
  226. };
  227. }
  228. function k(c) {
  229. function e(a, b) {
  230. var d = c[a];
  231. "function" === typeof d && (d = d(b));
  232. return void 0 === d ? b : d;
  233. }
  234. function k() {
  235. l().hide();
  236. m().hide();
  237. v.trigger(h);
  238. }
  239. function q() {
  240. w.trigger(h) && k();
  241. }
  242. function g(a) {
  243. return function() {
  244. a.apply(this, arguments);
  245. return h;
  246. };
  247. }
  248. function r(a) {
  249. if (!t) {
  250. var c = n(e, q),
  251. b = f(e, q),
  252. d;
  253. d = e("closeButton", !0)
  254. ? c
  255. .child()
  256. .html(e("closeHtml", "\x26#xD7;"))
  257. .clazz("pico-close")
  258. .clazz(e("closeClass"))
  259. .stylize(
  260. e("closeStyles", {
  261. borderRadius: "2px",
  262. cursor: "pointer",
  263. height: "15px",
  264. width: "15px",
  265. position: "absolute",
  266. top: "5px",
  267. right: "5px",
  268. fontSize: "16px",
  269. textAlign: "center",
  270. lineHeight: "15px",
  271. background: "#CCC"
  272. })
  273. )
  274. : void 0;
  275. t = { modal: c, overlay: b, close: d };
  276. x.trigger(h);
  277. }
  278. return t[a];
  279. }
  280. if ("string" === typeof c || b(c)) c = { content: c };
  281. var x = a(),
  282. y = a(),
  283. z = a(),
  284. w = a(),
  285. v = a(),
  286. t,
  287. m = r.bind(d, "modal"),
  288. l = r.bind(d, "overlay"),
  289. u = r.bind(d, "close"),
  290. h = {
  291. modalElem: p(m),
  292. closeElem: p(u),
  293. overlayElem: p(l),
  294. show: function() {
  295. y.trigger(h) && (l().show(), u(), m().show(), z.trigger(h));
  296. return this;
  297. },
  298. close: g(q),
  299. forceClose: g(k),
  300. destroy: function() {
  301. m = m().destroy();
  302. l = l().destroy();
  303. u = void 0;
  304. },
  305. options: function(a) {
  306. c = a;
  307. },
  308. afterCreate: g(x.watch),
  309. beforeShow: g(y.watch),
  310. afterShow: g(z.watch),
  311. beforeClose: g(w.watch),
  312. afterClose: g(v.watch)
  313. };
  314. return h;
  315. }
  316. e.div = function(a) {
  317. var b = c.createElement("div");
  318. (a || c.body).appendChild(b);
  319. return new e(b);
  320. };
  321. e.prototype = {
  322. child: function() {
  323. return e.div(this.elem);
  324. },
  325. stylize: function(a) {
  326. a = a || {};
  327. "undefined" !== typeof a.opacity &&
  328. (a.filter = "alpha(opacity\x3d" + 100 * a.opacity + ")");
  329. for (var b in a) a.hasOwnProperty(b) && (this.elem.style[b] = a[b]);
  330. return this;
  331. },
  332. clazz: function(a) {
  333. this.elem.className += " " + a;
  334. return this;
  335. },
  336. html: function(a) {
  337. b(a) ? this.elem.appendChild(a) : (this.elem.innerHTML = a);
  338. return this;
  339. },
  340. onClick: function(a) {
  341. this.elem.addEventListener("click", a);
  342. return this;
  343. },
  344. destroy: function() {
  345. c.body.removeChild(this.elem);
  346. },
  347. hide: function() {
  348. this.elem.style.display = "none";
  349. },
  350. show: function() {
  351. this.elem.style.display = "block";
  352. },
  353. attr: function(a, b) {
  354. this.elem.setAttribute(a, b);
  355. return this;
  356. },
  357. anyAncestor: function(a) {
  358. for (var b = this.elem; b; ) {
  359. if (a(new e(b))) return !0;
  360. b = b.parentNode;
  361. }
  362. return !1;
  363. }
  364. };
  365. "function" === typeof d.define && d.define.amd
  366. ? d.define(function() {
  367. return k;
  368. })
  369. : (d.picoModal = k);
  370. })(window, document);