fcp-fl.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /**
  2. * 注册命名空间:baidu.FL
  3. */
  4. baidu.namespace.register("baidu.FL");
  5. /**
  6. * FL常量
  7. * @author lichengyin (FCP:PHP代码)
  8. * @cover zhaoxianlie (FCPHelper:将PHP代码重写为Javascript代码)
  9. */
  10. baidu.FL = new (function() {
  11. this.FL_EOF = 1; //结束
  12. this.FL_TPL_DELIMITER = 2; //模板语法
  13. this.FL_NEW_LINE = 3; //new line
  14. this.FL_NORMAL = 4; //normal,一般很少出现这个
  15. this.HTML_CONTENT = 111; //文本
  16. this.HTML_TAG = 112; //一般标签
  17. this.HTML_JS_START = 113; //js start
  18. this.HTML_JS_CONTENT = 114; //js content,要手工调用js analytic
  19. this.HTML_JS_END = 115; //js end
  20. this.HTML_CSS_START = 116; //css start
  21. this.HTML_CSS_CONTENT = 117; //css content,要手工调用css analytic
  22. this.HTML_CSS_END = 118; //css end
  23. this.HTML_IE_HACK_START = 119; //ie hack start
  24. this.HTML_IE_HACK_EDN = 120; //ie hack end
  25. this.HTML_DOC_TYPE = 121; //doc type
  26. this.HTML_COMMENT = 122; //html comment
  27. this.HTML_STATUS_OK = 123; //status ok
  28. this.HTML_TAG_START = 124; //tag start
  29. this.HTML_TAG_END = 125; //tag end
  30. this.HTML_TPL_ATTR_NAME = 126; //tpl attributes name
  31. this.HTML_XML = 127; //is xml
  32. this.HTML_TEXTAREA_START = 128; //textarea tag start
  33. this.HTML_TEXTAREA_CONTENT = 129; //textarea tag end
  34. this.HTML_TEXTAREA_END = 130; //textarea tag end
  35. this.HTML_PRE_START = 131; //pre tag start
  36. this.HTML_PRE_CONTENT = 132; //pre tag end
  37. this.HTML_PRE_END = 133; //pre tag end
  38. this.JS_START_EXPR = 211; //start expression
  39. this.JS_END_EXPR = 212; //end expression
  40. this.JS_START_BLOCK = 213; //start block
  41. this.JS_END_BLOCK = 214; //end block
  42. this.JS_SEMICOLON = 215; //分号
  43. this.JS_WORD = 216; //单词
  44. this.JS_OPERATOR = 217; //操作符
  45. this.JS_EQUALS = 218; //等号
  46. this.JS_INLINE_COMMENT = 219; //行内注释
  47. this.JS_BLOCK_COMMENT = 220; //跨级注释
  48. this.JS_COMMENT = 221; //注释
  49. this.JS_STRING = 222; //字符串
  50. this.JS_IE_CC = 223; //条件编译
  51. this.JS_REGEXP = 224; //正则
  52. this.JS_MODE_EXPRESSION = 250; //
  53. this.JS_MODE_INDENT_EXPRESSION = 251; //
  54. this.JS_MODE_DO_BLOCK = 252; //
  55. this.JS_MODE_BLOCK = 253; //
  56. this.JS_MODE_ARRAY = 254;
  57. this.CSS_AT = 311; //@
  58. this.CSS_NORMAL = 312; //
  59. this.CSS_DEVICE_DESC = 313; //设备描述内容
  60. this.CSS_DEVICE_START = 314; //设备开始符,为{
  61. this.CSS_DEVICE_END = 315; //设备结束符,为}
  62. this.CSS_SELECTOER = 316; //选择器
  63. this.CSS_SELECTOER_START = 317; //选择器开始符,为{
  64. this.CSS_SELECTOER_END = 318; //选择器结束符,为}
  65. this.CSS_COMMENT = 319; //评论
  66. this.CSS_PROPERTY = 320; //属性
  67. this.CSS_VALUE = 321; //值
  68. this.CSS_SEMICOLON = 322; //分号
  69. this.CSS_COLON = 323; //冒号
  70. })();
  71. // FL常量
  72. baidu.FlConst = {};
  73. //首先配一个DTD中的白名单
  74. baidu.FlConst.PUBLIC_ID_WHITE_LIST = {
  75. '': {
  76. systemIds: {
  77. '': true
  78. }
  79. },
  80. '-//W3C//DTD HTML 3.2 Final//EN': {
  81. systemIds: {
  82. '': true
  83. }
  84. },
  85. '-//W3C//DTD HTML 4.0//EN': {
  86. systemIds: {
  87. '': true,
  88. 'http://www.w3.org/TR/html4/strict.dtd': true
  89. }
  90. },
  91. '-//W3C//DTD HTML 4.01//EN': {
  92. systemIds: {
  93. '': true,
  94. 'http://www.w3.org/TR/html4/strict.dtd': true
  95. }
  96. },
  97. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  98. systemIds: {
  99. '': true,
  100. 'http://www.w3.org/TR/html4/loose.dtd': true
  101. }
  102. },
  103. '-//W3C//DTD HTML 4.01 Transitional//EN': {
  104. systemIds: {
  105. '': true,
  106. 'http://www.w3.org/TR/html4/loose.dtd': true,
  107. 'http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd': true
  108. }
  109. },
  110. '-//W3C//DTD XHTML 1.1//EN': {
  111. systemIds: {
  112. 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd': true
  113. }
  114. },
  115. '-//W3C//DTD XHTML Basic 1.0//EN': {
  116. systemIds: {
  117. 'http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd': true
  118. }
  119. },
  120. '-//W3C//DTD XHTML 1.0 Strict//EN': {
  121. systemIds: {
  122. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd': true
  123. }
  124. },
  125. '-//W3C//DTD XHTML 1.0 Transitional//EN': {
  126. systemIds: {
  127. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd': true
  128. }
  129. },
  130. 'ISO/IEC 15445:1999//DTD HyperText Markup Language//EN': {
  131. systemIds: {
  132. '': true
  133. }
  134. },
  135. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  136. systemIds: {
  137. '': true
  138. }
  139. },
  140. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  141. systemIds: {
  142. '': true
  143. }
  144. }
  145. };
  146. /**
  147. * IE和Webkit对Doctype的解析差异
  148. */
  149. baidu.FlConst.COMPAT_MODE_DIFF_PUBLIC_ID_MAP = {
  150. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  151. systemIds: {
  152. 'http://www.w3.org/TR/html4/loose.dtd': {
  153. IE: 'S',
  154. WebKit: 'Q'
  155. }
  156. }
  157. },
  158. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  159. systemIds: {
  160. '': {
  161. IE: 'Q',
  162. WebKit: 'S'
  163. }
  164. }
  165. },
  166. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  167. systemIds: {
  168. '': {
  169. IE: 'Q',
  170. WebKit: 'S'
  171. }
  172. }
  173. }
  174. };
  175. /**
  176. * 过时的HTML标签,HTML5已经不再支持
  177. */
  178. baidu.FlConst.HTML_DEPRECATED_TAGS = {
  179. acronym: "定义首字母缩写",
  180. applet: "定义Java Applet",
  181. basefont: "定义Font定义",
  182. big: "定义大号文本",
  183. center: "定义居中的文本",
  184. dir: "定义目录列表",
  185. font: "定义文字相关",
  186. frame: "定义框架",
  187. frameset: "定义框架集",
  188. isindex: "定义单行的输入域",
  189. noframes: "定义noframe 部分",
  190. s: "定义加删除线的文本",
  191. strike: "定义加删除线的文本",
  192. tt: "定义打字机文本",
  193. u: "定义下划线文本",
  194. xmp: "定义预格式文本",
  195. layer: "定义层"
  196. };
  197. /**
  198. * 过时的HTML属性,HTML5已经不再支持
  199. */
  200. baidu.FlConst.HTML_DEPRECATED_ATTRIBUTES = {
  201. align: {
  202. iframe: true,
  203. img: true,
  204. object: true,
  205. table: true
  206. },
  207. color: {
  208. font: true
  209. },
  210. height: {
  211. td: true,
  212. th: true
  213. },
  214. language: {
  215. script: true
  216. },
  217. noshade: {
  218. hr: true
  219. },
  220. nowrap: {
  221. td: true,
  222. th: true
  223. },
  224. size: {
  225. hr: true,
  226. font: true,
  227. basefont: true
  228. }
  229. };
  230. /**
  231. * 块级元素
  232. */
  233. baidu.FlConst.BLOCK_HTML_ELEMENT = [
  234. 'address','blockquote','center','dir',
  235. 'div','dl','fieldset','form','h1','h2',
  236. 'h3','h4','h5','h6','hr','isindex','menu',
  237. 'noframes','noscript','ol','p','pre','table','ul'
  238. ];
  239. /**
  240. * 内联元素
  241. */
  242. baidu.FlConst.INLINE_HTML_ELEMENT = [
  243. 'a','acronym','b','bdo','big','br','cite','code',
  244. 'dfn','em','font','i','img','input','kbd','label',
  245. 'q','s','samp','select','small','span','strike','strong',
  246. 'sub','sup','textarea','tt','u','var'
  247. ];
  248. /**
  249. * 可变元素:为根据上下文语境决定该元素为块元素或者内联元素。
  250. */
  251. baidu.FlConst.CHANGE_ABLE_HTML_ELEMENT = [
  252. 'applet','button','del','iframe',
  253. 'ins','map','object','script'
  254. ];
  255. //关于IE的条件注释,可以参考这里:http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
  256. //条件注释的正则匹配规则
  257. baidu.FlConst.CONDITIONAL_COMMENT_REGEXP = /\[\s*if\s+[^\]][\s\w]*\]/i;
  258. // 非IE条件注释开始:<![if !IE]> or <![if false]>
  259. baidu.FlConst.NOT_IE_REVEALED_OPENING_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]$/i;
  260. // IE条件注释结束:<![endif]>
  261. baidu.FlConst.REVEALED_CLOSING_CONDITIONAL_COMMENT_REGEXP = /^\[endif\s*\]$/i;
  262. // 非IE的条件注释整体: <!--[if !IE]> HTML <![endif]--> or <!--[if false]> HTML <![endif]-->
  263. baidu.FlConst.NOT_IE_HIDDEN_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]>.*<!\[endif\]$/i;
  264. /* 正则 */
  265. baidu.FlConst.REG = {
  266. //script标签
  267. SCRIPT: /<script[^>]*>[\s\S]*?<\/[^>]*script>/gi,
  268. //注释
  269. COMMENT: /<!--[\s\S]*?--\>/g,
  270. //cssExpression
  271. CSS_EXPRESSION: /expression[\s\r\n ]?\(/gi,
  272. //textarea
  273. TEXTAREA:/<textarea[^>]*>[\s\S]*?<\/[^>]*textarea>/gi,
  274. //不合法的标签
  275. INVALID_TAG:/<\W+>/gi
  276. };
  277. /**
  278. * 能够自动闭合的标签,就算不闭合也不影响兄弟节点的布局
  279. */
  280. baidu.FlConst.SELF_CLOSING_TAGS = [
  281. 'meta','link','area','base',
  282. 'col','input','img','br',
  283. 'hr','param','embed'
  284. ];