ht-menu.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. !function(L, H) {
  2. "use strict";
  3. var M = "ht"
  4. , d = L[M]
  5. , P = "innerHTML"
  6. , n = "className"
  7. , q = null
  8. , k = "px"
  9. , E = d.Default
  10. , N = E.getInternal()
  11. , u = "0"
  12. , t = function() {
  13. return document
  14. }
  15. , x = function(B) {
  16. return t().createElement(B)
  17. }
  18. , z = function() {
  19. return x("canvas")
  20. }
  21. , e = function(k, E, o) {
  22. k.style.setProperty(E, o, q)
  23. }
  24. , h = function(F, t, M) {
  25. E.def(d.widget[F], t, M)
  26. }
  27. , Y = function(v, F) {
  28. v.appendChild(F)
  29. }
  30. , s = function(g, p) {
  31. g.removeChild(p)
  32. }
  33. , $ = function(k, E, h, I) {
  34. k.addEventListener(E, h, !!I)
  35. }
  36. , i = function(f, A, g, z) {
  37. f.removeEventListener(A, g, !!z)
  38. }
  39. , v = E.isTouchable;
  40. N.addMethod(E, {
  41. menuLabelFont: (v ? "16" : "13") + "px arial, sans-serif",
  42. menuLabelColor: "#000",
  43. menuBackground: "#F0EFEE",
  44. menuHoverBackground: "#648BFE",
  45. menuHoverLabelColor: "#fff",
  46. menuSeparatorWidth: 1,
  47. menuSeparatorColor: "#999"
  48. }, !0),
  49. d.widget.Menu = function(W) {
  50. var v = this
  51. , O = v._view = N.createView(null, v)
  52. , g = v.$1g = new d.widget.ContextMenu
  53. , D = x("ul");
  54. g._r = !0,
  55. g._view[n] += " ht-widget-dropdownmenu",
  56. O[n] = "ht-widget-menu",
  57. D[n] = "header",
  58. e(O, "margin", u),
  59. e(O, "padding", u),
  60. e(O, "background", E.menuBackground),
  61. e(O, "-webkit-user-select", "none"),
  62. e(O, "-moz-user-select", "none"),
  63. e(O, "user-select", "none"),
  64. e(O, "text-align", "left"),
  65. e(O, "border-bottom", E.menuSeparatorWidth + "px solid " + E.menuSeparatorColor),
  66. e(O, "cursor", "default"),
  67. e(O, "overflow", "auto"),
  68. e(O, "white-space", "nowrap"),
  69. e(O, "font", E.menuLabelFont),
  70. e(O, "color", E.menuLabelColor),
  71. e(O, "box-sizing", "border-box"),
  72. e(O, "-moz-box-sizing", "border-box"),
  73. e(D, "list-style", "none"),
  74. e(D, "margin", u),
  75. e(D, "padding", u),
  76. e(D, "display", "inline-block"),
  77. Y(O, D),
  78. v.setItems(W),
  79. v.$2g = function(A) {
  80. v.$3g(A)
  81. }
  82. ,
  83. v.$4g = function(_) {
  84. v.$5g(_)
  85. }
  86. ,
  87. v.$6g = function(B) {
  88. v.$7g(B)
  89. }
  90. ,
  91. v.$8g = function(y) {
  92. v.$9g(y)
  93. }
  94. ,
  95. v.$9b = function(T) {
  96. v.$10g(T)
  97. }
  98. ,
  99. v._autoShow = !0,
  100. v.setAutoShow(!1),
  101. g.afterHide = function() {
  102. v.$11g()
  103. }
  104. ,
  105. g.afterShow = function() {
  106. v.$12g()
  107. }
  108. ,
  109. i(t(), "keydown", g.$3b),
  110. v.$3b = function($) {
  111. v.$13g($)
  112. }
  113. ,
  114. v.invalidate()
  115. }
  116. ,
  117. h("Menu", H, {
  118. _items: q,
  119. $14g: E.menuHoverBackground,
  120. $15g: E.menuHoverLabelColor,
  121. $16g: {},
  122. _enableGlobalKey: !1,
  123. ms_v: 1,
  124. $21g: "smallicons",
  125. $22g: 0,
  126. $23g: 0,
  127. $24g: "left",
  128. getDropDownMenu: function() {
  129. return this.$1g
  130. },
  131. setLayout: function(b) {
  132. var $ = this;
  133. if ($.$21g = b,
  134. $.setItems($._items),
  135. "largeicons" === b) {
  136. for (var N = $._view.querySelectorAll(".header-item"), G = 0, M = 0; M < N.length; M++) {
  137. var E = N[M];
  138. G = Math.max(G, E.clientWidth)
  139. }
  140. for (var M = 0; M < N.length; M++) {
  141. var E = N[M];
  142. e(E, "min-width", G + k)
  143. }
  144. }
  145. this.invalidate()
  146. },
  147. getLayout: function() {
  148. return this.$21g
  149. },
  150. setHeaderItemHGap: function(y) {
  151. this.$22g = y;
  152. for (var r = this._view.querySelectorAll(".header-item"), Z = 0; Z < r.length; Z++) {
  153. var F = r[Z];
  154. e(F, "margin-left", y + k),
  155. e(F, "margin-right", y + k)
  156. }
  157. },
  158. getHeaderItemHGap: function() {
  159. return this.$22g
  160. },
  161. setHeaderItemVGap: function(l) {
  162. this.$23g = l;
  163. for (var P = this._view.querySelectorAll(".header-item"), U = 0; U < P.length; U++) {
  164. var A = P[U];
  165. e(A, "margin-top", l + k),
  166. e(A, "margin-bottom", l + k)
  167. }
  168. },
  169. getHeaderItemVGap: function() {
  170. return this.$24g
  171. },
  172. setHeaderItemAlign: function(o) {
  173. this.$24g = o,
  174. e(this._view, "text-align", o)
  175. },
  176. getHeaderItemAlign: function() {
  177. return this.$23g
  178. },
  179. enableGlobalKey: function() {
  180. var i = this
  181. , O = i._enableGlobalKey;
  182. O === !1 && ($(t(), "keydown", i.$3b),
  183. i._enableGlobalKey = !0)
  184. },
  185. disableGlobalKey: function() {
  186. this._enableGlobalKey = !1,
  187. i(t(), "keydown", this.$3b)
  188. },
  189. setItemBackground: function (j) {
  190. this.$99g = j;
  191. },
  192. setHoverBackground: function(J) {
  193. this.$14g = J
  194. },
  195. setHoverColor: function(I) {
  196. this.$15g = I
  197. },
  198. setItems: function(D) {
  199. var l = this
  200. , C = l._view
  201. , h = l.$21g;
  202. if (l._items = D,
  203. C.children[0][P] = "",
  204. l.$16g = {},
  205. D && D.length) {
  206. for (var b = C.children[0], d = 0, c = t().createDocumentFragment(); d < D.length; d++) {
  207. var w = D[d]
  208. , o = x("li")
  209. , J = x("span");
  210. if (w.icon) {
  211. var s = z();
  212. s[n] = "menu-item-icon",
  213. "smallicons" === h ? (e(s, "height", "1.2em"),
  214. e(s, "width", "1.2em"),
  215. e(s, "vertical-align", "middle")) : (e(s, "height", "32px"),
  216. e(s, "width", "32px"),
  217. e(s, "display", "block"),
  218. e(s, "margin", "0 auto")),
  219. s.$20g = w.icon,
  220. Y(o, s)
  221. }
  222. if (w.hoverIcon) {
  223. var _s = z();
  224. _s[n] = "menu-item-icon menu-item-icon-hover",
  225. "smallicons" === h ? (e(_s, "height", "1.2em"),
  226. e(_s, "width", "1.2em"),
  227. e(_s, "vertical-align", "middle")) : (e(_s, "height", "32px"),
  228. e(_s, "width", "32px"),
  229. e(_s, "display", "none"),
  230. e(_s, "margin", "0 auto")),
  231. _s.$20g = w.hoverIcon,
  232. Y(o, _s)
  233. }
  234. o[n] = "header-item",
  235. e(o, "display", "inline-block"),
  236. e(o, "vertical-align", "top"),
  237. e(o, "padding", "0 1.2em"),
  238. e(o, "line-height", "1.8em"),
  239. e(o, 'overflow', 'hidden'),
  240. "largeicons" === h && e(o, "text-align", "center"),
  241. e(o, "background-color", "rgba(0,0,0,0)"),
  242. o.setAttribute("data-index", d),
  243. l.$16g[d] = w.items,
  244. J[P] = w.label,
  245. "iconsonly" !== h && Y(o, J);
  246. w.background && e(o, "background", w.background);
  247. if (w.isCurrent) {
  248. o[n] = "header-item";
  249. o.id = 'header-item-current';
  250. }
  251. Y(c, o);
  252. }
  253. Y(b, c)
  254. }
  255. },
  256. showDropdownMenu: function(i) {
  257. var U = this
  258. , S = U.$16g[i]
  259. , Y = U.$1g
  260. , r = U._view.children[0].children[i]
  261. , g = U.$17g;
  262. if (r && r !== g) {
  263. g && U.hideDropdownMenu();
  264. var c = r.getBoundingClientRect()
  265. , Z = E.getWindowInfo();
  266. U.$17g = r,
  267. Y.setItems(S),
  268. Y.show(c.left + Z.left, c.top + c.height + Z.top, !1)
  269. }
  270. },
  271. hideDropdownMenu: function() {
  272. this.$1g.hide()
  273. },
  274. getItemByProperty: function(l, U) {
  275. var L = this
  276. , J = L._items;
  277. return J && 0 !== J.length ? L.$1g.getItemByProperty(l, U, J) : q
  278. },
  279. $12g: function() {
  280. var E = this
  281. , n = E.$17g;
  282. n.style.background = E.$14g,
  283. n.style.color = E.$15g,
  284. E._autoShow || $(t(), v ? "touchstart" : "mousedown", E.$9b)
  285. },
  286. $11g: function() {
  287. var C = this
  288. , V = C.$17g;
  289. V && (V.style.background = C.$99g,
  290. V.style.color = "",
  291. C.$17g = q),
  292. i(t(), v ? "touchstart" : "mousedown", C.$9b)
  293. },
  294. $10g: function(y) {
  295. var u = this
  296. , C = u._view
  297. , S = u.$1g
  298. , x = C.children[0];
  299. !t().body.contains(C) || x.contains(y.target) || S._view.contains(y.target) || u.hideDropdownMenu()
  300. },
  301. $13g: function(D) {
  302. var l = this
  303. , c = l.$1g;
  304. t().body.contains(l._view) && c.$13b.$4b.call(c.$13b, D, l._items)
  305. },
  306. setAutoShow: function(n) {
  307. var u = this
  308. , D = u.$1g
  309. , f = u._view;
  310. u._autoShow !== n && (u._autoShow ? (i(f, "mouseover", u.$2g),
  311. i(f, "mouseout", u.$4g),
  312. i(D._view, "mouseout", u.$4g),
  313. v || ($(f, "mouseover", u.$8g),
  314. $(f, "mouseout", u.$8g)),
  315. $(f, v ? "touchstart" : "mousedown", u.$6g)) : (i(f, "mouseover", u.$8g),
  316. i(f, "mouseout", u.$8g),
  317. i(f, v ? "touchstart" : "mousedown", u.$6g),
  318. i(t(), v ? "touchstart" : "mousedown", u.$9b),
  319. v || ($(f, "mouseover", u.$2g),
  320. $(f, "mouseout", u.$4g),
  321. $(D._view, "mouseout", u.$4g))),
  322. u._autoShow = n)
  323. },
  324. $3g: function(R) {
  325. var k = this
  326. , C = k._view.children[0]
  327. , W = R.target;
  328. if (C !== W && C.contains(W)) {
  329. for (; "header-item" !== W[n]; )
  330. W = W.parentNode;
  331. k.showDropdownMenu(W.getAttribute("data-index"))
  332. }
  333. },
  334. $5g: function(v) {
  335. var B = this
  336. , L = B._view.children[0]
  337. , N = B.$1g
  338. , w = v.target
  339. , C = v.relatedTarget;
  340. !L.contains(w) && !N._view.contains(w) || L.contains(C) || N._view.contains(C) || B.hideDropdownMenu()
  341. },
  342. $7g: function(r) {
  343. r.preventDefault();
  344. var L = this
  345. , d = L._view.children[0]
  346. , O = L.$1g
  347. , o = r.target;
  348. if (E.isLeftButton(r) && d !== o && d.contains(o))
  349. if (v) {
  350. for (; "header-item" !== o[n]; )
  351. o = o.parentNode;
  352. var y = o.getAttribute("data-index")
  353. , O = L.$1g
  354. , F = L._view.children[0].children[y]
  355. , p = L.$17g;
  356. O.isShowing() && L.hideDropdownMenu(),
  357. F !== p && L.showDropdownMenu(y)
  358. } else if (O.isShowing())
  359. L.hideDropdownMenu();
  360. else {
  361. for (; "header-item" !== o[n]; )
  362. o = o.parentNode;
  363. L.showDropdownMenu(o.getAttribute("data-index"))
  364. }
  365. },
  366. $9g: function(X) {
  367. var V = this
  368. , B = V._view
  369. , Z = V.$1g
  370. , I = X.target;
  371. if (B.contains(I)) {
  372. for (var m = B.querySelectorAll(".header-item"), t = q, v = 0; v < m.length; v++) {
  373. var P = m[v];
  374. P.style.background = V.$99g,
  375. P.style.color = "",
  376. "mouseover" === X.type ? P.contains(I) && (t = P) : "mouseout" === X.type && Z.isShowing() && V.$17g === P && (t = P)
  377. }
  378. Z.isShowing() && (t || (t = V.$17g),
  379. V.showDropdownMenu(t.getAttribute("data-index"))),
  380. t && (t.style.background = V.$14g,
  381. t.style.color = V.$15g)
  382. }
  383. },
  384. getShowingMenuIndex: function() {
  385. var u = this.$17g;
  386. return u ? u.getAttribute("data-index") : -1
  387. },
  388. addTo: function(_) {
  389. var $ = this
  390. , R = $._view;
  391. Y(_, R),
  392. $.invalidate()
  393. },
  394. dispose: function() {
  395. var W = this
  396. , P = W._view
  397. , R = W.$1g;
  398. P && (W._autoShow ? (i(P, "mouseover", W.$2g),
  399. i(P, "mouseout", W.$4g),
  400. i(R._view, "mouseout", W.$4g)) : (i(P, "mouseover", W.$8g),
  401. i(P, "mouseout", W.$8g),
  402. i(P, v ? "touchstart" : "mousedown", W.$6g),
  403. i(t(), v ? "touchstart" : "mousedown", W.$9b)),
  404. i(t(), "keydown", W.$3b),
  405. R.dispose(),
  406. P.parentNode && s(P.parentNode, P),
  407. W._view = W.$1g = W.$16g = W._items = W.$17g = W.$2g = W.$4g = W.$6g = W.$8g = W.$9b = W.$3b = q)
  408. },
  409. $19g: function(I, v, w, Z) {
  410. var e = N.initContext(I);
  411. N.translateAndScale(e, 0, 0, 1),
  412. e.clearRect(0, 0, w, Z),
  413. E.drawStretchImage(e, E.getImage(v), "fill", 0, 0, w, Z),
  414. e.restore()
  415. },
  416. validateImpl: function() {
  417. var I, U, T, c = this, Z = c._view, $ = Z.querySelectorAll(".menu-item-icon"), $hoverIcon = Z.querySelectorAll('.menu-item-icon-hover');
  418. for (T = 0; T < $.length; T++) {
  419. var K = $[T];
  420. I = K.clientWidth,
  421. U = K.clientHeight,
  422. I && U && (N.setCanvas(K, I, U),
  423. c.$19g(K, E.getImage(K.$20g), I, U))
  424. }
  425. for (var i = 0, len = $hoverIcon.length; i < len; i++) {
  426. var hicon = $hoverIcon[i];
  427. c.$19g(hicon, E.getImage(hicon.$20g), I, U);
  428. hicon.style.position = 'absolute';
  429. hicon.style.left = '-80px';
  430. // hicon.style.top = '50%';
  431. // hicon.style.marginTop = '-' + U * 0.5 + 'px';
  432. }
  433. }
  434. })
  435. }("undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : this, Object);