util.js.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. // This is an automatically generated file. Do not edit.
  2. "\n"
  3. "\n"
  4. "\n"
  5. "\n"
  6. "\n"
  7. "\n"
  8. "\n"
  9. "\n"
  10. "\n"
  11. "\n"
  12. "\n"
  13. "\n"
  14. "\n"
  15. "\n"
  16. "\n"
  17. "\n"
  18. "\n"
  19. "\n"
  20. "\n"
  21. "\n"
  22. "\n"
  23. "\n"
  24. "Error.prototype.toString = function() {\n"
  25. "if (this.stackTrace) return this.name + ': ' + this.message + this.stackTrace;\n"
  26. "return this.name + ': ' + this.message;\n"
  27. "};\n"
  28. "\n"
  29. "\n"
  30. "var display = {\n"
  31. "visible: 0,\n"
  32. "hidden: 1,\n"
  33. "noPrint: 2,\n"
  34. "noView: 3,\n"
  35. "};\n"
  36. "\n"
  37. "var border = {\n"
  38. "b: 'beveled',\n"
  39. "d: 'dashed',\n"
  40. "i: 'inset',\n"
  41. "s: 'solid',\n"
  42. "u: 'underline',\n"
  43. "};\n"
  44. "\n"
  45. "var color = {\n"
  46. "transparent: [ 'T' ],\n"
  47. "black: [ 'G', 0 ],\n"
  48. "white: [ 'G', 1 ],\n"
  49. "gray: [ 'G', 0.5 ],\n"
  50. "ltGray: [ 'G', 0.75 ],\n"
  51. "dkGray: [ 'G', 0.25 ],\n"
  52. "red: [ 'RGB', 1, 0, 0 ],\n"
  53. "green: [ 'RGB', 0, 1, 0 ],\n"
  54. "blue: [ 'RGB', 0, 0, 1 ],\n"
  55. "cyan: [ 'CMYK', 1, 0, 0, 0 ],\n"
  56. "magenta: [ 'CMYK', 0, 1, 0, 0 ],\n"
  57. "yellow: [ 'CMYK', 0, 0, 1, 0 ],\n"
  58. "};\n"
  59. "\n"
  60. "color.convert = function (c, colorspace) {\n"
  61. "switch (colorspace) {\n"
  62. "case 'G':\n"
  63. "if (c[0] === 'RGB')\n"
  64. "return [ 'G', c[1] * 0.3 + c[2] * 0.59 + c[3] * 0.11 ];\n"
  65. "if (c[0] === 'CMYK')\n"
  66. "return [ 'CMYK', 1 - Math.min(1, c[1] * 0.3 + c[2] * 0.59 + c[3] * 0.11 + c[4])];\n"
  67. "break;\n"
  68. "case 'RGB':\n"
  69. "if (c[0] === 'G')\n"
  70. "return [ 'RGB', c[1], c[1], c[1] ];\n"
  71. "if (c[0] === 'CMYK')\n"
  72. "return [ 'RGB',\n"
  73. "1 - Math.min(1, c[1] + c[4]),\n"
  74. "1 - Math.min(1, c[2] + c[4]),\n"
  75. "1 - Math.min(1, c[3] + c[4]) ];\n"
  76. "break;\n"
  77. "case 'CMYK':\n"
  78. "if (c[0] === 'G')\n"
  79. "return [ 'CMYK', 0, 0, 0, 1 - c[1] ];\n"
  80. "if (c[0] === 'RGB')\n"
  81. "return [ 'CMYK', 1 - c[1], 1 - c[2], 1 - c[3], 0 ];\n"
  82. "break;\n"
  83. "}\n"
  84. "return c;\n"
  85. "}\n"
  86. "\n"
  87. "color.equal = function (a, b) {\n"
  88. "var i, n;\n"
  89. "if (a[0] === 'G')\n"
  90. "a = color.convert(a, b[0]);\n"
  91. "else\n"
  92. "b = color.convert(b, a[0]);\n"
  93. "if (a[0] !== b[0])\n"
  94. "return false;\n"
  95. "switch (a[0]) {\n"
  96. "case 'G': n = 1; break;\n"
  97. "case 'RGB': n = 3; break;\n"
  98. "case 'CMYK': n = 4; break;\n"
  99. "default: n = 0; break;\n"
  100. "}\n"
  101. "for (i = 1; i <= n; ++i)\n"
  102. "if (a[i] !== b[i])\n"
  103. "return false;\n"
  104. "return true;\n"
  105. "}\n"
  106. "\n"
  107. "var font = {\n"
  108. "Cour: 'Courier',\n"
  109. "CourB: 'Courier-Bold',\n"
  110. "CourBI: 'Courier-BoldOblique',\n"
  111. "CourI: 'Courier-Oblique',\n"
  112. "Helv: 'Helvetica',\n"
  113. "HelvB: 'Helvetica-Bold',\n"
  114. "HelvBI: 'Helvetica-BoldOblique',\n"
  115. "HelvI: 'Helvetica-Oblique',\n"
  116. "Symbol: 'Symbol',\n"
  117. "Times: 'Times-Roman',\n"
  118. "TimesB: 'Times-Bold',\n"
  119. "TimesBI: 'Times-BoldItalic',\n"
  120. "TimesI: 'Times-Italic',\n"
  121. "ZapfD: 'ZapfDingbats',\n"
  122. "};\n"
  123. "\n"
  124. "var highlight = {\n"
  125. "i: 'invert',\n"
  126. "n: 'none',\n"
  127. "o: 'outline',\n"
  128. "p: 'push',\n"
  129. "};\n"
  130. "\n"
  131. "var position = {\n"
  132. "textOnly: 0,\n"
  133. "iconOnly: 1,\n"
  134. "iconTextV: 2,\n"
  135. "textIconV: 3,\n"
  136. "iconTextH: 4,\n"
  137. "textIconH: 5,\n"
  138. "overlay: 6,\n"
  139. "};\n"
  140. "\n"
  141. "var scaleHow = {\n"
  142. "proportional: 0,\n"
  143. "anamorphic: 1,\n"
  144. "};\n"
  145. "\n"
  146. "var scaleWhen = {\n"
  147. "always: 0,\n"
  148. "never: 1,\n"
  149. "tooBig: 2,\n"
  150. "tooSmall: 3,\n"
  151. "};\n"
  152. "\n"
  153. "var style = {\n"
  154. "ch: 'check',\n"
  155. "ci: 'circle',\n"
  156. "cr: 'cross',\n"
  157. "di: 'diamond',\n"
  158. "sq: 'square',\n"
  159. "st: 'star',\n"
  160. "};\n"
  161. "\n"
  162. "var zoomtype = {\n"
  163. "fitH: 'FitHeight',\n"
  164. "fitP: 'FitPage',\n"
  165. "fitV: 'FitVisibleWidth',\n"
  166. "fitW: 'FitWidth',\n"
  167. "none: 'NoVary',\n"
  168. "pref: 'Preferred',\n"
  169. "refW: 'ReflowWidth',\n"
  170. "};\n"
  171. "\n"
  172. "util.scand = function (fmt, input) {\n"
  173. "\n"
  174. "return AFParseDateEx(input, fmt);\n"
  175. "}\n"
  176. "\n"
  177. "util.printd = function (fmt, date) {\n"
  178. "var monthName = [\n"
  179. "'January',\n"
  180. "'February',\n"
  181. "'March',\n"
  182. "'April',\n"
  183. "'May',\n"
  184. "'June',\n"
  185. "'July',\n"
  186. "'August',\n"
  187. "'September',\n"
  188. "'October',\n"
  189. "'November',\n"
  190. "'December'\n"
  191. "];\n"
  192. "var dayName = [\n"
  193. "'Sunday',\n"
  194. "'Monday',\n"
  195. "'Tuesday',\n"
  196. "'Wednesday',\n"
  197. "'Thursday',\n"
  198. "'Friday',\n"
  199. "'Saturday'\n"
  200. "];\n"
  201. "if (fmt === 0)\n"
  202. "fmt = 'D:yyyymmddHHMMss';\n"
  203. "else if (fmt === 1)\n"
  204. "fmt = 'yyyy.mm.dd HH:MM:ss';\n"
  205. "else if (fmt === 2)\n"
  206. "fmt = 'm/d/yy h:MM:ss tt';\n"
  207. "if (!date)\n"
  208. "date = new Date();\n"
  209. "else if (!(date instanceof Date))\n"
  210. "date = new Date(date);\n"
  211. "var tokens = fmt.match(/(\\\\.|m+|d+|y+|H+|h+|M+|s+|t+|[^\\\\mdyHhMst]*)/g);\n"
  212. "var out = '';\n"
  213. "for (var i = 0; i < tokens.length; ++i) {\n"
  214. "var token = tokens[i];\n"
  215. "switch (token) {\n"
  216. "case 'mmmm': out += monthName[date.getMonth()]; break;\n"
  217. "case 'mmm': out += monthName[date.getMonth()].substring(0, 3); break;\n"
  218. "case 'mm': out += util.printf('%02d', date.getMonth()+1); break;\n"
  219. "case 'm': out += date.getMonth()+1; break;\n"
  220. "case 'dddd': out += dayName[date.getDay()]; break;\n"
  221. "case 'ddd': out += dayName[date.getDay()].substring(0, 3); break;\n"
  222. "case 'dd': out += util.printf('%02d', date.getDate()); break;\n"
  223. "case 'd': out += date.getDate(); break;\n"
  224. "case 'yyyy': out += date.getFullYear(); break;\n"
  225. "case 'yy': out += date.getFullYear() % 100; break;\n"
  226. "case 'HH': out += util.printf('%02d', date.getHours()); break;\n"
  227. "case 'H': out += date.getHours(); break;\n"
  228. "case 'hh': out += util.printf('%02d', (date.getHours()+11)%12+1); break;\n"
  229. "case 'h': out += (date.getHours() + 11) % 12 + 1; break;\n"
  230. "case 'MM': out += util.printf('%02d', date.getMinutes()); break;\n"
  231. "case 'M': out += date.getMinutes(); break;\n"
  232. "case 'ss': out += util.printf('%02d', date.getSeconds()); break;\n"
  233. "case 's': out += date.getSeconds(); break;\n"
  234. "case 'tt': out += date.getHours() < 12 ? 'am' : 'pm'; break;\n"
  235. "case 't': out += date.getHours() < 12 ? 'a' : 'p'; break;\n"
  236. "default: out += (token[0] == '\\\\') ? token[1] : token; break;\n"
  237. "}\n"
  238. "}\n"
  239. "return out;\n"
  240. "}\n"
  241. "\n"
  242. "util.printx = function (fmt, val) {\n"
  243. "function toUpper(str) { return str.toUpperCase(); }\n"
  244. "function toLower(str) { return str.toLowerCase(); }\n"
  245. "function toSame(str) { return str; }\n"
  246. "var convertCase = toSame;\n"
  247. "var res = '';\n"
  248. "var i, m;\n"
  249. "var n = fmt ? fmt.length : 0;\n"
  250. "for (i = 0; i < n; ++i) {\n"
  251. "switch (fmt.charAt(i)) {\n"
  252. "case '\\\\':\n"
  253. "if (++i < n)\n"
  254. "res += fmt.charAt(i);\n"
  255. "break;\n"
  256. "case 'X':\n"
  257. "m = val.match(/\\w/);\n"
  258. "if (m) {\n"
  259. "res += convertCase(m[0]);\n"
  260. "val = val.replace(/^\\W*\\w/, '');\n"
  261. "}\n"
  262. "break;\n"
  263. "case 'A':\n"
  264. "m = val.match(/[A-Za-z]/);\n"
  265. "if (m) {\n"
  266. "res += convertCase(m[0]);\n"
  267. "val = val.replace(/^[^A-Za-z]*[A-Za-z]/, '');\n"
  268. "}\n"
  269. "break;\n"
  270. "case '9':\n"
  271. "m = val.match(/\\d/);\n"
  272. "if (m) {\n"
  273. "res += m[0];\n"
  274. "val = val.replace(/^\\D*\\d/, '');\n"
  275. "}\n"
  276. "break;\n"
  277. "case '*':\n"
  278. "res += convertCase(val);\n"
  279. "val = '';\n"
  280. "break;\n"
  281. "case '?':\n"
  282. "if (val !== '') {\n"
  283. "res += convertCase(val.charAt(0));\n"
  284. "val = val.substring(1);\n"
  285. "}\n"
  286. "break;\n"
  287. "case '=':\n"
  288. "convertCase = toSame;\n"
  289. "break;\n"
  290. "case '>':\n"
  291. "convertCase = toUpper;\n"
  292. "break;\n"
  293. "case '<':\n"
  294. "convertCase = toLower;\n"
  295. "break;\n"
  296. "default:\n"
  297. "res += convertCase(fmt.charAt(i));\n"
  298. "break;\n"
  299. "}\n"
  300. "}\n"
  301. "return res;\n"
  302. "}\n"
  303. "\n"
  304. "\n"
  305. "\n"
  306. "\n"
  307. "\n"
  308. "\n"
  309. "\n"
  310. "\n"
  311. "\n"
  312. "\n"
  313. "\n"
  314. "\n"
  315. "\n"
  316. "\n"
  317. "\n"
  318. "\n"
  319. "\n"
  320. "\n"
  321. "\n"
  322. "\n"
  323. "\n"
  324. "\n"
  325. "\n"
  326. "\n"
  327. "function AFMergeChange(event) {\n"
  328. "var prefix, postfix;\n"
  329. "var value = event.value;\n"
  330. "if (event.willCommit)\n"
  331. "return value;\n"
  332. "if (event.selStart >= 0)\n"
  333. "prefix = value.substring(0, event.selStart);\n"
  334. "else\n"
  335. "prefix = '';\n"
  336. "if (event.selEnd >= 0 && event.selEnd <= value.length)\n"
  337. "postfix = value.substring(event.selEnd, value.length);\n"
  338. "else\n"
  339. "postfix = '';\n"
  340. "return prefix + event.change + postfix;\n"
  341. "}\n"
  342. "\n"
  343. "function AFExtractNums(string) {\n"
  344. "if (string.charAt(0) == '.' || string.charAt(0) == ',')\n"
  345. "string = '0' + string;\n"
  346. "return string.match(/\\d+/g);\n"
  347. "}\n"
  348. "\n"
  349. "function AFMakeNumber(string) {\n"
  350. "if (typeof string == 'number')\n"
  351. "return string;\n"
  352. "if (typeof string != 'string')\n"
  353. "return null;\n"
  354. "var nums = AFExtractNums(string);\n"
  355. "if (!nums)\n"
  356. "return null;\n"
  357. "var result = nums.join('.');\n"
  358. "if (string.indexOf('-.') >= 0)\n"
  359. "result = '0.' + result;\n"
  360. "if (string.indexOf('-') >= 0)\n"
  361. "return -result;\n"
  362. "return +result;\n"
  363. "}\n"
  364. "\n"
  365. "function AFExtractTime(string) {\n"
  366. "var pattern = /\\d\\d?:\\d\\d?(:\\d\\d?)?\\s*(am|pm)?/i;\n"
  367. "var match = pattern.exec(string);\n"
  368. "if (match) {\n"
  369. "var prefix = string.substring(0, match.index);\n"
  370. "var suffix = string.substring(match.index + match[0].length);\n"
  371. "return [ prefix + suffix, match[0] ];\n"
  372. "}\n"
  373. "return null;\n"
  374. "}\n"
  375. "\n"
  376. "function AFParseDateOrder(fmt) {\n"
  377. "var order = '';\n"
  378. "fmt += 'mdy';\n"
  379. "for (var i = 0; i < fmt.length; i++) {\n"
  380. "var c = fmt.charAt(i);\n"
  381. "if ((c == 'y' || c == 'm' || c == 'd') && order.indexOf(c) < 0)\n"
  382. "order += c;\n"
  383. "}\n"
  384. "return order;\n"
  385. "}\n"
  386. "\n"
  387. "function AFMatchMonth(date) {\n"
  388. "var names = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'];\n"
  389. "var month = date.match(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/i);\n"
  390. "if (month)\n"
  391. "return names.indexOf(month[0].toLowerCase()) + 1;\n"
  392. "return null;\n"
  393. "}\n"
  394. "\n"
  395. "function AFParseTime(string, date) {\n"
  396. "if (!date)\n"
  397. "date = new Date();\n"
  398. "if (!string)\n"
  399. "return date;\n"
  400. "var nums = AFExtractNums(string);\n"
  401. "if (!nums || nums.length < 2 || nums.length > 3)\n"
  402. "return null;\n"
  403. "var hour = nums[0];\n"
  404. "var min = nums[1];\n"
  405. "var sec = (nums.length == 3) ? nums[2] : 0;\n"
  406. "if (hour < 12 && (/pm/i).test(string))\n"
  407. "hour += 12;\n"
  408. "if (hour >= 12 && (/am/i).test(string))\n"
  409. "hour -= 12;\n"
  410. "date.setHours(hour, min, sec);\n"
  411. "if (date.getHours() != hour || date.getMinutes() != min || date.getSeconds() != sec)\n"
  412. "return null;\n"
  413. "return date;\n"
  414. "}\n"
  415. "\n"
  416. "function AFMakeDate(out, year, month, date, time)\n"
  417. "{\n"
  418. "year = year | 0;\n"
  419. "if (year < 50)\n"
  420. "year += 2000;\n"
  421. "if (year < 100)\n"
  422. "year += 1900;\n"
  423. "out.setFullYear(year, month, date);\n"
  424. "if (out.getFullYear() != year || out.getMonth() != month || out.getDate() != date)\n"
  425. "return null;\n"
  426. "if (time)\n"
  427. "out = AFParseTime(time, out);\n"
  428. "else\n"
  429. "out.setHours(0, 0, 0);\n"
  430. "return out;\n"
  431. "}\n"
  432. "\n"
  433. "function AFParseDateEx(string, fmt) {\n"
  434. "var out = new Date();\n"
  435. "var year = out.getFullYear();\n"
  436. "var month;\n"
  437. "var date;\n"
  438. "var i;\n"
  439. "\n"
  440. "out.setHours(12, 0, 0);\n"
  441. "\n"
  442. "var order = AFParseDateOrder(fmt);\n"
  443. "\n"
  444. "var time = AFExtractTime(string);\n"
  445. "if (time) {\n"
  446. "string = time[0];\n"
  447. "time = time[1];\n"
  448. "}\n"
  449. "\n"
  450. "var nums = AFExtractNums(string);\n"
  451. "if (!nums)\n"
  452. "return null;\n"
  453. "\n"
  454. "if (nums.length == 3) {\n"
  455. "year = nums[order.indexOf('y')];\n"
  456. "month = nums[order.indexOf('m')];\n"
  457. "date = nums[order.indexOf('d')];\n"
  458. "return AFMakeDate(out, year, month-1, date, time);\n"
  459. "}\n"
  460. "\n"
  461. "month = AFMatchMonth(string);\n"
  462. "\n"
  463. "if (nums.length == 2) {\n"
  464. "\n"
  465. "if (month) {\n"
  466. "if (order.indexOf('y') < order.indexOf('d')) {\n"
  467. "year = nums[0];\n"
  468. "date = nums[1];\n"
  469. "} else {\n"
  470. "year = nums[1];\n"
  471. "date = nums[0];\n"
  472. "}\n"
  473. "}\n"
  474. "\n"
  475. "\n"
  476. "else if (order.indexOf('y') < order.indexOf('d')) {\n"
  477. "if (order.indexOf('y') < order.indexOf('m')) {\n"
  478. "year = nums[0];\n"
  479. "month = nums[1];\n"
  480. "date = 1;\n"
  481. "} else {\n"
  482. "year = nums[1];\n"
  483. "month = nums[0];\n"
  484. "date = 1;\n"
  485. "}\n"
  486. "}\n"
  487. "\n"
  488. "\n"
  489. "else {\n"
  490. "if (order.indexOf('d') < order.indexOf('m')) {\n"
  491. "date = nums[0];\n"
  492. "month = nums[1];\n"
  493. "} else {\n"
  494. "date = nums[1];\n"
  495. "month = nums[0];\n"
  496. "}\n"
  497. "}\n"
  498. "\n"
  499. "return AFMakeDate(out, year, month-1, date, time);\n"
  500. "}\n"
  501. "\n"
  502. "if (nums.length == 1) {\n"
  503. "if (month) {\n"
  504. "if (order.indexOf('y') < order.indexOf('d')) {\n"
  505. "year = nums[0];\n"
  506. "date = 1;\n"
  507. "} else {\n"
  508. "date = nums[0];\n"
  509. "}\n"
  510. "return AFMakeDate(out, year, month-1, date, time);\n"
  511. "}\n"
  512. "\n"
  513. "\n"
  514. "if (string.length == fmt.length) {\n"
  515. "year = month = date = '';\n"
  516. "for (i = 0; i < fmt.length; ++i) {\n"
  517. "switch (fmt.charAt(i)) {\n"
  518. "case '\\\\': ++i; break;\n"
  519. "case 'y': year += string.charAt(i); break;\n"
  520. "case 'm': month += string.charAt(i); break;\n"
  521. "case 'd': date += string.charAt(i); break;\n"
  522. "}\n"
  523. "}\n"
  524. "return AFMakeDate(out, year, month-1, date, time);\n"
  525. "}\n"
  526. "}\n"
  527. "\n"
  528. "return null;\n"
  529. "}\n"
  530. "\n"
  531. "var AFDate_oldFormats = [\n"
  532. "'m/d',\n"
  533. "'m/d/yy',\n"
  534. "'mm/dd/yy',\n"
  535. "'mm/yy',\n"
  536. "'d-mmm',\n"
  537. "'d-mmm-yy',\n"
  538. "'dd-mm-yy',\n"
  539. "'yy-mm-dd',\n"
  540. "'mmm-yy',\n"
  541. "'mmmm-yy',\n"
  542. "'mmm d, yyyy',\n"
  543. "'mmmm d, yyyy',\n"
  544. "'m/d/yy h:MM tt',\n"
  545. "'m/d/yy HH:MM'\n"
  546. "];\n"
  547. "\n"
  548. "function AFDate_KeystrokeEx(fmt) {\n"
  549. "var value = AFMergeChange(event);\n"
  550. "if (event.willCommit && !AFParseDateEx(value, fmt)) {\n"
  551. "app.alert('The date/time entered ('+value+') does not match the format ('+fmt+') of the field [ '+event.target.name+' ]');\n"
  552. "event.rc = false;\n"
  553. "}\n"
  554. "}\n"
  555. "\n"
  556. "function AFDate_Keystroke(index) {\n"
  557. "AFDate_KeystrokeEx(AFDate_oldFormats[index]);\n"
  558. "}\n"
  559. "\n"
  560. "function AFDate_FormatEx(fmt) {\n"
  561. "var d = AFParseDateEx(event.value, fmt);\n"
  562. "event.value = d ? util.printd(fmt, d) : '';\n"
  563. "}\n"
  564. "\n"
  565. "function AFDate_Format(index) {\n"
  566. "AFDate_FormatEx(AFDate_oldFormats[index]);\n"
  567. "}\n"
  568. "\n"
  569. "function AFTime_Keystroke(index) {\n"
  570. "if (event.willCommit && !AFParseTime(event.value, null)) {\n"
  571. "app.alert('The value entered ('+event.value+') does not match the format of the field [ '+event.target.name+' ]');\n"
  572. "event.rc = false;\n"
  573. "}\n"
  574. "}\n"
  575. "\n"
  576. "function AFTime_FormatEx(fmt) {\n"
  577. "var d = AFParseTime(event.value, null);\n"
  578. "event.value = d ? util.printd(fmt, d) : '';\n"
  579. "}\n"
  580. "\n"
  581. "function AFTime_Format(index) {\n"
  582. "var formats = [ 'HH:MM', 'h:MM tt', 'HH:MM:ss', 'h:MM:ss tt' ];\n"
  583. "AFTime_FormatEx(formats[index]);\n"
  584. "}\n"
  585. "\n"
  586. "function AFSpecial_KeystrokeEx(fmt) {\n"
  587. "function toUpper(str) { return str.toUpperCase(); }\n"
  588. "function toLower(str) { return str.toLowerCase(); }\n"
  589. "function toSame(str) { return str; }\n"
  590. "var convertCase = toSame;\n"
  591. "var val = AFMergeChange(event);\n"
  592. "var res = '';\n"
  593. "var i = 0;\n"
  594. "var m;\n"
  595. "var length = fmt ? fmt.length : 0;\n"
  596. "\n"
  597. "\n"
  598. "if (!val || val == \"\") {\n"
  599. "event.rc = true;\n"
  600. "return;\n"
  601. "}\n"
  602. "\n"
  603. "while (i < length) {\n"
  604. "\n"
  605. "if (!event.willCommit && (!val || val.length == 0))\n"
  606. "break;\n"
  607. "switch (fmt.charAt(i)) {\n"
  608. "case '\\\\':\n"
  609. "i++;\n"
  610. "if (i >= length)\n"
  611. "break;\n"
  612. "res += fmt.charAt(i);\n"
  613. "if (val && val.charAt(0) === fmt.charAt(i))\n"
  614. "val = val.substring(1);\n"
  615. "break;\n"
  616. "\n"
  617. "case 'X':\n"
  618. "m = val.match(/^\\w/);\n"
  619. "if (!m) {\n"
  620. "event.rc = false;\n"
  621. "break;\n"
  622. "}\n"
  623. "res += convertCase(m[0]);\n"
  624. "val = val.substring(1);\n"
  625. "break;\n"
  626. "\n"
  627. "case 'A':\n"
  628. "m = val.match(/^[A-Za-z]/);\n"
  629. "if (!m) {\n"
  630. "event.rc = false;\n"
  631. "break;\n"
  632. "}\n"
  633. "res += convertCase(m[0]);\n"
  634. "val = val.substring(1);\n"
  635. "break;\n"
  636. "\n"
  637. "case '9':\n"
  638. "m = val.match(/^\\d/);\n"
  639. "if (!m) {\n"
  640. "event.rc = false;\n"
  641. "break;\n"
  642. "}\n"
  643. "res += m[0];\n"
  644. "val = val.substring(1);\n"
  645. "break;\n"
  646. "\n"
  647. "case '*':\n"
  648. "res += convertCase(val);\n"
  649. "val = '';\n"
  650. "break;\n"
  651. "\n"
  652. "case '?':\n"
  653. "res += convertCase(val.charAt(0));\n"
  654. "val = val.substring(1);\n"
  655. "break;\n"
  656. "\n"
  657. "case '=':\n"
  658. "convertCase = toSame;\n"
  659. "break;\n"
  660. "case '>':\n"
  661. "convertCase = toUpper;\n"
  662. "break;\n"
  663. "case '<':\n"
  664. "convertCase = toLower;\n"
  665. "break;\n"
  666. "\n"
  667. "default:\n"
  668. "res += fmt.charAt(i);\n"
  669. "if (val && val.charAt(0) === fmt.charAt(i))\n"
  670. "val = val.substring(1);\n"
  671. "break;\n"
  672. "}\n"
  673. "\n"
  674. "i++;\n"
  675. "}\n"
  676. "\n"
  677. "\n"
  678. "\n"
  679. "if (i < length && event.willCommit)\n"
  680. "event.rc = false;\n"
  681. "\n"
  682. "\n"
  683. "if (val.length > 0)\n"
  684. "event.rc = false;\n"
  685. "\n"
  686. "if (event.rc) {\n"
  687. "if (event.willCommit)\n"
  688. "event.value = res;\n"
  689. "else {\n"
  690. "event.change = res;\n"
  691. "event.selStart = 0;\n"
  692. "event.selEnd = event.value.length;\n"
  693. "}\n"
  694. "} else\n"
  695. "app.alert('The value entered ('+event.value+') does not match the format of the field [ '+event.target.name+' ] should be '+fmt);\n"
  696. "}\n"
  697. "\n"
  698. "function AFSpecial_Keystroke(index) {\n"
  699. "if (event.willCommit) {\n"
  700. "switch (index) {\n"
  701. "case 0:\n"
  702. "if (!event.value.match(/^\\d{5}$/))\n"
  703. "event.rc = false;\n"
  704. "break;\n"
  705. "case 1:\n"
  706. "if (!event.value.match(/^\\d{5}[-. ]?\\d{4}$/))\n"
  707. "event.rc = false;\n"
  708. "break;\n"
  709. "case 2:\n"
  710. "if (!event.value.match(/^((\\(\\d{3}\\)|\\d{3})[-. ]?)?\\d{3}[-. ]?\\d{4}$/))\n"
  711. "event.rc = false;\n"
  712. "break;\n"
  713. "case 3:\n"
  714. "if (!event.value.match(/^\\d{3}[-. ]?\\d{2}[-. ]?\\d{4}$/))\n"
  715. "event.rc = false;\n"
  716. "break;\n"
  717. "}\n"
  718. "if (!event.rc)\n"
  719. "app.alert('The value entered ('+event.value+') does not match the format of the field [ '+event.target.name+' ]');\n"
  720. "}\n"
  721. "}\n"
  722. "\n"
  723. "function AFSpecial_Format(index) {\n"
  724. "var res;\n"
  725. "if (!event.value)\n"
  726. "return;\n"
  727. "switch (index) {\n"
  728. "case 0:\n"
  729. "res = util.printx('99999', event.value);\n"
  730. "break;\n"
  731. "case 1:\n"
  732. "res = util.printx('99999-9999', event.value);\n"
  733. "break;\n"
  734. "case 2:\n"
  735. "res = util.printx('9999999999', event.value);\n"
  736. "res = util.printx(res.length >= 10 ? '(999) 999-9999' : '999-9999', event.value);\n"
  737. "break;\n"
  738. "case 3:\n"
  739. "res = util.printx('999-99-9999', event.value);\n"
  740. "break;\n"
  741. "}\n"
  742. "event.value = res ? res : '';\n"
  743. "}\n"
  744. "\n"
  745. "function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) {\n"
  746. "var value = AFMergeChange(event);\n"
  747. "if (sepStyle & 2) {\n"
  748. "if (!value.match(/^[+-]?\\d*[,.]?\\d*$/))\n"
  749. "event.rc = false;\n"
  750. "} else {\n"
  751. "if (!value.match(/^[+-]?\\d*\\.?\\d*$/))\n"
  752. "event.rc = false;\n"
  753. "}\n"
  754. "if (event.willCommit) {\n"
  755. "if (!value.match(/\\d/))\n"
  756. "event.rc = false;\n"
  757. "if (!event.rc)\n"
  758. "app.alert('The value entered ('+value+') does not match the format of the field [ '+event.target.name+' ]');\n"
  759. "}\n"
  760. "}\n"
  761. "\n"
  762. "function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) {\n"
  763. "var value = AFMakeNumber(event.value);\n"
  764. "var fmt = '%,' + sepStyle + '.' + nDec + 'f';\n"
  765. "if (value == null) {\n"
  766. "event.value = '';\n"
  767. "return;\n"
  768. "}\n"
  769. "if (bCurrencyPrepend)\n"
  770. "fmt = strCurrency + fmt;\n"
  771. "else\n"
  772. "fmt = fmt + strCurrency;\n"
  773. "if (value < 0) {\n"
  774. "/* negStyle: 0=MinusBlack, 1=Red, 2=ParensBlack, 3=ParensRed */\n"
  775. "value = Math.abs(value);\n"
  776. "if (negStyle == 2 || negStyle == 3)\n"
  777. "fmt = '(' + fmt + ')';\n"
  778. "else if (negStyle == 0)\n"
  779. "fmt = '-' + fmt;\n"
  780. "if (negStyle == 1 || negStyle == 3)\n"
  781. "event.target.textColor = color.red;\n"
  782. "else\n"
  783. "event.target.textColor = color.black;\n"
  784. "} else {\n"
  785. "event.target.textColor = color.black;\n"
  786. "}\n"
  787. "event.value = util.printf(fmt, value);\n"
  788. "}\n"
  789. "\n"
  790. "function AFPercent_Keystroke(nDec, sepStyle) {\n"
  791. "AFNumber_Keystroke(nDec, sepStyle, 0, 0, '', true);\n"
  792. "}\n"
  793. "\n"
  794. "function AFPercent_Format(nDec, sepStyle) {\n"
  795. "var val = AFMakeNumber(event.value);\n"
  796. "if (val == null) {\n"
  797. "event.value = '';\n"
  798. "return;\n"
  799. "}\n"
  800. "event.value = (val * 100) + '';\n"
  801. "AFNumber_Format(nDec, sepStyle, 0, 0, '%', false);\n"
  802. "}\n"
  803. "\n"
  804. "function AFSimple_Calculate(op, list) {\n"
  805. "var i, res;\n"
  806. "\n"
  807. "switch (op) {\n"
  808. "case 'SUM': res = 0; break;\n"
  809. "case 'PRD': res = 1; break;\n"
  810. "case 'AVG': res = 0; break;\n"
  811. "}\n"
  812. "\n"
  813. "if (typeof list === 'string')\n"
  814. "list = list.split(/ *, */);\n"
  815. "\n"
  816. "for (i = 0; i < list.length; i++) {\n"
  817. "var field = this.getField(list[i]);\n"
  818. "var value = Number(field.value);\n"
  819. "switch (op) {\n"
  820. "case 'SUM': res += value; break;\n"
  821. "case 'PRD': res *= value; break;\n"
  822. "case 'AVG': res += value; break;\n"
  823. "case 'MIN': if (i === 0 || value < res) res = value; break;\n"
  824. "case 'MAX': if (i === 0 || value > res) res = value; break;\n"
  825. "}\n"
  826. "}\n"
  827. "\n"
  828. "if (op === 'AVG')\n"
  829. "res /= list.length;\n"
  830. "\n"
  831. "event.value = res;\n"
  832. "}\n"
  833. "\n"
  834. "function AFRange_Validate(lowerCheck, lowerLimit, upperCheck, upperLimit) {\n"
  835. "if (upperCheck && event.value > upperLimit)\n"
  836. "event.rc = false;\n"
  837. "if (lowerCheck && event.value < lowerLimit)\n"
  838. "event.rc = false;\n"
  839. "if (!event.rc) {\n"
  840. "if (lowerCheck && upperCheck)\n"
  841. "app.alert(util.printf('The entered value ('+event.value+') must be greater than or equal to %s and less than or equal to %s', lowerLimit, upperLimit));\n"
  842. "else if (lowerCheck)\n"
  843. "app.alert(util.printf('The entered value ('+event.value+') must be greater than or equal to %s', lowerLimit));\n"
  844. "else\n"
  845. "app.alert(util.printf('The entered value ('+event.value+') must be less than or equal to %s', upperLimit));\n"
  846. "}\n"
  847. "}\n"
  848. "\n"
  849. "\n"
  850. "function mupdf_createInfoProxy(doc) {\n"
  851. "doc.info = {\n"
  852. "get Title() { return doc.title; },\n"
  853. "set Title(value) { doc.title = value; },\n"
  854. "get Author() { return doc.author; },\n"
  855. "set Author(value) { doc.author = value; },\n"
  856. "get Subject() { return doc.subject; },\n"
  857. "set Subject(value) { doc.subject = value; },\n"
  858. "get Keywords() { return doc.keywords; },\n"
  859. "set Keywords(value) { doc.keywords = value; },\n"
  860. "get Creator() { return doc.creator; },\n"
  861. "set Creator(value) { doc.creator = value; },\n"
  862. "get Producer() { return doc.producer; },\n"
  863. "set Producer(value) { doc.producer = value; },\n"
  864. "get CreationDate() { return doc.creationDate; },\n"
  865. "set CreationDate(value) { doc.creationDate = value; },\n"
  866. "get ModDate() { return doc.modDate; },\n"
  867. "set ModDate(value) { doc.modDate = value; },\n"
  868. "};\n"
  869. "}\n"
  870. "mupdf_createInfoProxy(global);\n"
  871. "\n"
  872. "/* Compatibility ECMAScript functions */\n"
  873. "String.prototype.substr = function (start, length) {\n"
  874. "if (start < 0)\n"
  875. "start = this.length + start;\n"
  876. "if (length === undefined)\n"
  877. "return this.substring(start, this.length);\n"
  878. "return this.substring(start, start + length);\n"
  879. "}\n"
  880. "Date.prototype.getYear = Date.prototype.getFullYear;\n"
  881. "Date.prototype.setYear = Date.prototype.setFullYear;\n"
  882. "Date.prototype.toGMTString = Date.prototype.toUTCString;\n"
  883. "\n"
  884. "app.plugIns = [];\n"
  885. "app.viewerType = 'Reader';\n"
  886. "app.language = 'ENU';\n"
  887. "app.viewerVersion = NaN;\n"
  888. "app.execDialog = function () { return 'cancel'; }\n"