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.

274 lines
8.9 KiB

2 years ago
  1. var widgetInit = function () {
  2. $.widget('custom.ToolBar', {
  3. options: {
  4. custom: {},
  5. common: {
  6. classname: 'btn-custom orange'
  7. },
  8. fncallback: null,
  9. //btext: {
  10. // Add: '新增', ReAdd: '儲存後新增', Save: '儲存', Add: '新增', Del: '刪除', Clear: '清除', Upd: '修改', Qry: '查詢',
  11. // Exp: '匯出', Imp: '匯入', Leave: '離開', Cpy: '複製', Print: '列印'
  12. //}
  13. btext: {
  14. //╠common.Toolbar_View⇒檢視╣╠common.Toolbar_Add⇒新增╣╠common.Toolbar_ReAdd⇒儲存后新增╣╠common.Toolbar_Save⇒儲存╣╠common.Toolbar_Del⇒刪除╣╠common.Toolbar_Clear⇒清除╣╠common.Toolbar_Upd⇒修改╣╠common.Toolbar_Qry⇒查詢╣
  15. //╠common.Toolbar_Exp⇒匯出╣╠common.Toolbar_Imp⇒匯入╣╠common.Toolbar_Leave⇒離開╣╠common.Toolbar_Copy⇒複製╣╠common.Toolbar_Print⇒列印╣╠common.Toolbar_Void⇒作廢╣
  16. Add: 'common.Toolbar_Add', ReAdd: 'common.Toolbar_ReAdd', Save: 'common.Toolbar_Save', Del: 'common.Toolbar_Del', Clear: 'common.Toolbar_Clear', Upd: 'common.Toolbar_Upd', Qry: 'common.Toolbar_Qry',
  17. Exp: 'common.Toolbar_Exp', Imp: 'common.Toolbar_Imp', Leave: 'common.Toolbar_Leave', Cpy: 'common.Toolbar_Copy', Print: 'common.Toolbar_Print', Void: 'common.Toolbar_Void'
  18. }
  19. },
  20. _createBtn: function () {
  21. //return $('<input type="button" />');
  22. return $('<button type="button" />');
  23. },
  24. _create: function () {
  25. var self = this,
  26. hotkeys = {};
  27. $.each(self.options.btns, function (idx, btnInfo) {
  28. var btnInst = self._createBtn(),
  29. dicAttr = {};
  30. for (var attr in btnInfo) {
  31. if (typeof btnInfo[attr] !== 'function') {
  32. dicAttr[attr] = btnInfo[attr];
  33. }
  34. }
  35. dicAttr.id = dicAttr.id || 'Toolbar_' + dicAttr.key;
  36. dicAttr.name = dicAttr.id;
  37. //dicAttr.value = dicAttr.value || self.options.btext[dicAttr.key];
  38. dicAttr["data-i18n"] = dicAttr.value || self.options.btext[dicAttr.key];// new fo i18n
  39. dicAttr.class = dicAttr.classname || self.options.common.classname;
  40. btnInst.attr(dicAttr);
  41. self.element.append(btnInst);
  42. btnInst.on("click", function (e) {
  43. self.options.fncallback(this, e);
  44. });
  45. if (dicAttr.hasOwnProperty("hotkey")) {
  46. hotkeys[dicAttr.hotkey] = dicAttr;
  47. }
  48. });
  49. $(document).on('compositionend', function (e) {
  50. e.target.ime = false;
  51. });
  52. $(document).on('compositionstart', function (e) {
  53. e.target.ime = true;
  54. });
  55. $(document).on('keydown', function (e) {
  56. var sKey = self._keyMapping[e.keyCode],
  57. btn = null;
  58. if (sKey === "escape") {
  59. sKey = "esc";
  60. }
  61. else if (e.keyCode >= 112 && e.keyCode <= 123) {
  62. sKey = "f" + (e.keyCode - 111).toString();
  63. }
  64. if (e.ctrlKey === true) {
  65. sKey = "ctrl + " + sKey;
  66. }
  67. // 非中文
  68. if (!e.target.ime) {
  69. if (sKey !== "esc" && sKey !== "enter" && sKey !== "ctrl + enter") {
  70. // Input
  71. if (this !== e.target && (/textarea|select/i.test(e.target.nodeName) || e.target.type === "text")) {
  72. return;
  73. }
  74. }
  75. // Process hot key
  76. if (hotkeys.hasOwnProperty(sKey)) {
  77. btn = hotkeys[sKey];
  78. }
  79. if (btn) {
  80. if (!$("#" + btn.id).is(":disabled") && $("#" + btn.id).is(":visible")) {
  81. $("#" + btn.id).trigger("click");
  82. e.preventDefault();
  83. }
  84. }
  85. }
  86. });
  87. },
  88. destroy: function () {
  89. this.element.empty();
  90. $.Widget.prototype.destroy.call(this);
  91. },
  92. _keyMapping: {
  93. 3: "break",
  94. 8: "backspace / delete",
  95. 9: "tab",
  96. 12: 'clear',
  97. 13: "enter",
  98. 16: "shift",
  99. 17: "ctrl ",
  100. 18: "alt",
  101. 19: "pause/break",
  102. 20: "caps lock",
  103. 27: "escape",
  104. 32: "spacebar",
  105. 33: "page up",
  106. 34: "page down",
  107. 35: "end",
  108. 36: "home ",
  109. 37: "left arrow ",
  110. 38: "up arrow ",
  111. 39: "right arrow",
  112. 40: "down arrow ",
  113. 41: "select",
  114. 42: "print",
  115. 43: "execute",
  116. 44: "Print Screen",
  117. 45: "insert ",
  118. 46: "delete",
  119. 48: "0",
  120. 49: "1",
  121. 50: "2",
  122. 51: "3",
  123. 52: "4",
  124. 53: "5",
  125. 54: "6",
  126. 55: "7",
  127. 56: "8",
  128. 57: "9",
  129. 58: ":",
  130. 59: "semicolon (firefox), equals",
  131. 60: "<",
  132. 61: "equals (firefox)",
  133. 63: "ß",
  134. 64: "@ (firefox)",
  135. 65: "a",
  136. 66: "b",
  137. 67: "c",
  138. 68: "d",
  139. 69: "e",
  140. 70: "f",
  141. 71: "g",
  142. 72: "h",
  143. 73: "i",
  144. 74: "j",
  145. 75: "k",
  146. 76: "l",
  147. 77: "m",
  148. 78: "n",
  149. 79: "o",
  150. 80: "p",
  151. 81: "q",
  152. 82: "r",
  153. 83: "s",
  154. 84: "t",
  155. 85: "u",
  156. 86: "v",
  157. 87: "w",
  158. 88: "x",
  159. 89: "y",
  160. 90: "z",
  161. 91: "Windows Key / Left ⌘ / Chromebook Search key",
  162. 92: "right window key ",
  163. 93: "Windows Menu / Right ⌘",
  164. 96: "numpad 0 ",
  165. 97: "numpad 1 ",
  166. 98: "numpad 2 ",
  167. 99: "numpad 3 ",
  168. 100: "numpad 4 ",
  169. 101: "numpad 5 ",
  170. 102: "numpad 6 ",
  171. 103: "numpad 7 ",
  172. 104: "numpad 8 ",
  173. 105: "numpad 9 ",
  174. 106: "multiply ",
  175. 107: "add",
  176. 108: "numpad period (firefox)",
  177. 109: "subtract ",
  178. 110: "decimal point",
  179. 111: "divide ",
  180. 112: "f1 ",
  181. 113: "f2 ",
  182. 114: "f3 ",
  183. 115: "f4 ",
  184. 116: "f5 ",
  185. 117: "f6 ",
  186. 118: "f7 ",
  187. 119: "f8 ",
  188. 120: "f9 ",
  189. 121: "f10",
  190. 122: "f11",
  191. 123: "f12",
  192. 124: "f13",
  193. 125: "f14",
  194. 126: "f15",
  195. 127: "f16",
  196. 128: "f17",
  197. 129: "f18",
  198. 130: "f19",
  199. 131: "f20",
  200. 132: "f21",
  201. 133: "f22",
  202. 134: "f23",
  203. 135: "f24",
  204. 144: "num lock ",
  205. 145: "scroll lock",
  206. 160: "^",
  207. 161: '!',
  208. 163: "#",
  209. 164: '$',
  210. 165: 'ù',
  211. 166: "page backward",
  212. 167: "page forward",
  213. 169: "closing paren (AZERTY)",
  214. 170: '*',
  215. 171: "~ + * key",
  216. 173: "minus (firefox), mute/unmute",
  217. 174: "decrease volume level",
  218. 175: "increase volume level",
  219. 176: "next",
  220. 177: "previous",
  221. 178: "stop",
  222. 179: "play/pause",
  223. 180: "e-mail",
  224. 181: "mute/unmute (firefox)",
  225. 182: "decrease volume level (firefox)",
  226. 183: "increase volume level (firefox)",
  227. 186: "semi-colon / ñ",
  228. 187: "equal sign ",
  229. 188: "comma",
  230. 189: "dash ",
  231. 190: "period ",
  232. 191: "forward slash / ç",
  233. 192: "grave accent / ñ",
  234. 193: "?, / or °",
  235. 194: "numpad period (chrome)",
  236. 219: "open bracket ",
  237. 220: "back slash ",
  238. 221: "close bracket ",
  239. 222: "single quote ",
  240. 223: "`",
  241. 224: "left or right ⌘ key (firefox)",
  242. 225: "altgr",
  243. 226: "< /git >",
  244. 230: "GNOME Compose Key",
  245. 233: "XF86Forward",
  246. 234: "XF86Back",
  247. 255: "toggle touchpad"
  248. }
  249. });
  250. },
  251. delayWidgetInit = function () {
  252. if ($.widget) {
  253. widgetInit();
  254. }
  255. else {
  256. setTimeout(function () {
  257. delayWidgetInit();
  258. }, 100);
  259. }
  260. };
  261. delayWidgetInit();