洛阳中航光电项目,为12年项目,此处使用反编译工具恢复源码,恢复为.netframe4.0版本,但仍需使用ie8访问; 数据库使用oracle,现再192.168.8.3服务器,访问账户scott,密码800100

template.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. Copyright 2011, KISSY UI Library v1.20dev
  3. MIT Licensed
  4. build time: Nov 18 17:24
  5. */
  6. /**
  7. * @fileoverview KISSY Template Engine.
  8. * @author yyfrankyy@gmail.com
  9. */
  10. KISSY.add('template/base', function(S) {
  11. var // Template Cache
  12. templateCache = {},
  13. // start/end tag mark
  14. tagStartEnd = {
  15. '#': 'start',
  16. '/': 'end'
  17. },
  18. // static string
  19. KS_TEMPL_STAT_PARAM = 'KS_TEMPL_STAT_PARAM',
  20. KS_TEMPL_STAT_PARAM_REG = new RegExp(KS_TEMPL_STAT_PARAM, "g"),
  21. KS_TEMPL = 'KS_TEMPL',
  22. KS_DATA = 'KS_DATA_',
  23. KS_EMPTY = '',
  24. KS_AS = 'as',
  25. PREFIX = '");',
  26. SUFFIX = KS_TEMPL + '.push("',
  27. PARSER_SYNTAX_ERROR = 'KISSY.Template: Syntax Error. ',
  28. PARSER_RENDER_ERROR = 'KISSY.Template: Render Error. ',
  29. PARSER_PREFIX = 'var ' + KS_TEMPL + '=[],' +
  30. KS_TEMPL_STAT_PARAM + '=false;with(',
  31. PARSER_MIDDLE = '||{}){try{' + KS_TEMPL + '.push("',
  32. PARSER_SUFFIX = '");}catch(e){' + KS_TEMPL + '=["' +
  33. PARSER_RENDER_ERROR + '" + e.message]}};return ' +
  34. KS_TEMPL + '.join("");',
  35. restoreQuote = function(str) {
  36. return str.replace(/\\"/g, '"');
  37. },
  38. escapeQuote = function(str) {
  39. return str.replace(/"/g, '\\"');
  40. },
  41. trim = S.trim,
  42. // build a static parser
  43. buildParser = function(tpl) {
  44. var _parser,
  45. _empty_index;
  46. return escapeQuote(trim(tpl)
  47. .replace(/[\r\t\n]/g, ' ')
  48. // escape escape ...
  49. .replace(/\\/g, '\\\\'))
  50. .replace(/\{\{([#/]?)(?!\}\})([^}]*)\}\}/g,
  51. function(all, expr, body) {
  52. _parser = KS_EMPTY;
  53. // is an expression
  54. if (expr) {
  55. body = trim(body);
  56. _empty_index = body.indexOf(' ');
  57. body = _empty_index === -1 ?
  58. [ body, '' ] :
  59. [
  60. body.substring(0, _empty_index),
  61. body.substring(_empty_index)
  62. ];
  63. var operator = body[0],
  64. fn,
  65. args = trim(body[1]),
  66. opStatement = Statements[operator];
  67. if (opStatement && tagStartEnd[expr]) {
  68. // get expression definition function/string
  69. fn = opStatement[tagStartEnd[expr]];
  70. _parser = S.isFunction(fn) ?
  71. restoreQuote(fn.apply(this, args.split(/\s+/))) :
  72. restoreQuote(fn.replace(KS_TEMPL_STAT_PARAM_REG, args));
  73. }
  74. }
  75. // return array directly
  76. else {
  77. _parser = KS_TEMPL +
  78. '.push(' +
  79. restoreQuote(body) +
  80. ');';
  81. }
  82. return PREFIX + _parser + SUFFIX;
  83. });
  84. },
  85. // expression
  86. Statements = {
  87. 'if': {
  88. start: 'if(' + KS_TEMPL_STAT_PARAM + '){',
  89. end: '}'
  90. },
  91. 'else': {
  92. start: '}else{'
  93. },
  94. 'elseif': {
  95. start: '}else if(' + KS_TEMPL_STAT_PARAM + '){'
  96. },
  97. // KISSY.each function wrap
  98. 'each': {
  99. start: function(obj, as, v, k) {
  100. var _ks_value = '_ks_value',
  101. _ks_index = '_ks_index';
  102. if (as === KS_AS && v) {
  103. _ks_value = v || _ks_value,
  104. _ks_index = k || _ks_index;
  105. }
  106. return 'KISSY.each(' + obj +
  107. ', function(' + _ks_value +
  108. ', ' + _ks_index + '){';
  109. },
  110. end: '});'
  111. },
  112. // comments
  113. '!': {
  114. start: '/*' + KS_TEMPL_STAT_PARAM + '*/'
  115. }
  116. };
  117. /**
  118. * Template
  119. * @param {String} tpl template to be rendered.
  120. * @return {Object} return this for chain.
  121. */
  122. function Template(tpl) {
  123. if (!(templateCache[tpl])) {
  124. var _ks_data = S.guid(KS_DATA),
  125. func,
  126. o,
  127. _parser = [
  128. PARSER_PREFIX,
  129. _ks_data,
  130. PARSER_MIDDLE,
  131. o = buildParser(tpl),
  132. PARSER_SUFFIX
  133. ];
  134. try {
  135. func = new Function(_ks_data, _parser.join(KS_EMPTY));
  136. } catch (e) {
  137. _parser[3] = PREFIX + SUFFIX +
  138. PARSER_SYNTAX_ERROR + ',' +
  139. e.message + PREFIX + SUFFIX;
  140. func = new Function(_ks_data, _parser.join(KS_EMPTY));
  141. }
  142. templateCache[tpl] = {
  143. name: _ks_data,
  144. o:o,
  145. parser: _parser.join(KS_EMPTY),
  146. render: func
  147. };
  148. }
  149. return templateCache[tpl];
  150. }
  151. S.mix(Template, {
  152. /**
  153. * Logging Compiled Template Codes
  154. * @param {String} tpl template string.
  155. */
  156. log: function(tpl) {
  157. if (tpl in templateCache) {
  158. if ('js_beautify' in window) {
  159. // S.log(js_beautify(templateCache[tpl].parser, {
  160. // indent_size: 4,
  161. // indent_char: ' ',
  162. // preserve_newlines: true,
  163. // braces_on_own_line: false,
  164. // keep_array_indentation: false,
  165. // space_after_anon_function: true
  166. // }), 'info');
  167. } else {
  168. S.log(templateCache[tpl].parser, 'info');
  169. }
  170. } else {
  171. Template(tpl);
  172. this.log(tpl);
  173. }
  174. },
  175. /**
  176. * add statement for extending template tags
  177. * @param {String} statement tag name.
  178. * @param {String} o extent tag object.
  179. */
  180. addStatement: function(statement, o) {
  181. if (S.isString(statement)) {
  182. Statements[statement] = o;
  183. } else {
  184. S.mix(Statements, statement);
  185. }
  186. }
  187. });
  188. return Template;
  189. });
  190. /**
  191. * 2011-09-20 note by yiminghe :
  192. * - code style change
  193. * - remove reg cache , ugly to see
  194. * - fix escape by escape
  195. * - expect(T('{{#if a=="a"}}{{b}}\\"{{/if}}').render({a:"a",b:"b"})).toBe('b\\"');
  196. */
  197. /**
  198. * @fileoverview KISSY.Template Node.
  199. * @author 文河<wenhe@taobao.com>
  200. */
  201. KISSY.add('template/node', function(S, Template, Node) {
  202. var $ = Node.all;
  203. S.mix(S, {
  204. tmpl: function(selector, data) {
  205. return $(Template($(selector).html()).render(data));
  206. }
  207. });
  208. }, {requires:["./base",'node']});
  209. KISSY.add("template", function(S, T) {
  210. S.Template = T;
  211. return T;
  212. }, {
  213. requires:["template/base","template/node"]
  214. });