PageRenderTime 50ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/webapp-eplugin/org.tizen.web.browser/scripts/firebug-lite/sandbox/sandbox/syntaxHighlight/prototype5c.html

https://review.tizen.org/git/
HTML | 396 lines | 324 code | 72 blank | 0 comment | 0 complexity | f1c738914da72bce378e3ec20509f123 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/DTD/strict.dtd">
  2. <html debug="true">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>~ improved sourceBox prototype #2</title>
  6. <script type="text/javascript">
  7. // *************************************************************************************************
  8. var sourceLocation = "../../../build/syntax-test1.js";
  9. var sourceText;
  10. window.onload = function()
  11. {
  12. var runButton = document.getElementById("run");
  13. var loading = document.getElementById("loading");
  14. loading.innerHTML = "requesting file...";
  15. loading.style.display = "block";
  16. setTimeout(function(){
  17. var xhr = getXHRObject();
  18. xhr.open("get", sourceLocation, true);
  19. xhr.onreadystatechange = function()
  20. {
  21. if (xhr.readyState == 4 && xhr.status == 200)
  22. {
  23. runButton.disabled = false;
  24. loading.style.display = "none";
  25. loading.innerHTML = "";
  26. sourceText = xhr.responseText;
  27. }
  28. };
  29. xhr.send();
  30. },100);
  31. };
  32. var run = function()
  33. {
  34. //process1();
  35. //return;
  36. var ParserInterruption = {toString: function() {return "ParserInterruption"}};
  37. var onProgress = function(position, total)
  38. {
  39. var value = (position+1)/total;
  40. progressFill.style.width = Math.round(value*progressBar.clientWidth) + "px";
  41. progressText.innerHTML = Math.round(value*100) + "%";
  42. };
  43. var onComplete = function(position, total)
  44. {
  45. progressText.innerHTML = new Date().getTime() - ts + " ms";
  46. };
  47. var parse = function()
  48. {
  49. try
  50. {
  51. var ts = new Date().getTime();
  52. while(hasTokens())
  53. {
  54. if (new Date().getTime() - ts > 50) throw ParserInterruption;
  55. token = next();
  56. }
  57. //console.log("FIM");
  58. running = false;
  59. tokenizer.sync(onProgress);
  60. tokenizer.sync(onComplete);
  61. }
  62. catch(e)
  63. {
  64. if (e == ParserInterruption)
  65. {
  66. //console.log("interruption parse");
  67. tokenizer.sync(onProgress);
  68. if (running)
  69. {
  70. setTimeout(parse, 25);
  71. }
  72. }
  73. }
  74. };
  75. var xxcount = 0;
  76. var progressFill = document.getElementById("progressFill");
  77. var progressBar = document.getElementById("progressBar");
  78. var progressText = document.getElementById("progressText");
  79. var runButton = document.getElementById("run");
  80. runButton.value = "pause";
  81. var running = true;
  82. var tokenizer = createTokenizer(sourceText, onProgress, onComplete);
  83. var next = tokenizer.next;
  84. var hasTokens = tokenizer.hasTokens;
  85. var token;
  86. runButton.onclick = function()
  87. {
  88. if (running)
  89. {
  90. runButton.value = "resume";
  91. tokenizer.pause();
  92. }
  93. else
  94. {
  95. runButton.value = "pause";
  96. tokenizer.resume();
  97. setTimeout(parse, 25);
  98. }
  99. running = !running;
  100. };
  101. var ts = new Date().getTime();
  102. parse();
  103. };
  104. var createTokenizer = function(sourceText, onProgress, onComplete)
  105. {
  106. var scope = {
  107. text: sourceText,
  108. i: 0,
  109. s: "",
  110. length: sourceText.length,
  111. count: 0,
  112. running: true
  113. };
  114. with (scope) {
  115. onProgress = onProgress || function(){};
  116. onComplete = onComplete || function(){};
  117. var TokenizerInterruption = {toString: function() {return "TokenizerInterruption"}};
  118. /*
  119. var text = sourceText;
  120. var i = 0;
  121. var s = "";
  122. var length = sourceText.length;
  123. var count = 0;
  124. var running = true;
  125. /**/
  126. var tokenizer = {
  127. next: function(){
  128. try
  129. {
  130. var ts = new Date().getTime();
  131. for(;i<length;i++)
  132. {
  133. if (new Date().getTime() - ts > 50) throw TokenizerInterruption;
  134. s += text.charAt(i);
  135. if (++count % 1000 == 0)
  136. {
  137. var r = s;
  138. s = "";
  139. i++;
  140. return r;
  141. }
  142. }
  143. running = false;
  144. onProgress(i, length);
  145. onComplete(i, length);
  146. }
  147. catch(e)
  148. {
  149. if (e == TokenizerInterruption)
  150. {
  151. //console.log("interruption next");
  152. onProgress(i, length);
  153. if (running)
  154. {
  155. setTimeout(tokenizer.next, 25);
  156. }
  157. //throw TokenizerInterruption;
  158. }
  159. }
  160. },
  161. pause: function()
  162. {
  163. running = false;
  164. },
  165. resume: function()
  166. {
  167. running = true;
  168. },
  169. sync: function(callback)
  170. {
  171. callback(i, length);
  172. },
  173. hasTokens: function()
  174. {
  175. return i < length;
  176. }
  177. };
  178. }
  179. return tokenizer;
  180. };
  181. var process1 = function()
  182. {
  183. var Interruption = {toString: function() {return "Interruption"}};
  184. /*
  185. var context = {
  186. Interruption: Interruption,
  187. text: sourceText,
  188. i: 0,
  189. s: "",
  190. length: sourceText.length,
  191. progressFill: document.getElementById("progressFill"),
  192. progressBar: document.getElementById("progressBar"),
  193. progressText: document.getElementById("progressText")
  194. };
  195. /**/
  196. var text = sourceText;
  197. var i = 0;
  198. var s = "";
  199. var length = sourceText.length;
  200. var progressFill = document.getElementById("progressFill");
  201. var progressBar = document.getElementById("progressBar");
  202. var progressText = document.getElementById("progressText");
  203. /**/
  204. //with(context) {
  205. var inner = function(){
  206. var ts = new Date().getTime();
  207. for(;i<length;i++)
  208. {
  209. if (new Date().getTime() - ts > 50)
  210. {
  211. setTimeout(inner, 25);
  212. break;
  213. }
  214. s += text.charAt(i);
  215. }
  216. var value = (i+1)/length;
  217. progressFill.style.width = Math.round(value*progressBar.clientWidth) + "px";
  218. progressText.innerHTML = Math.round(value*100) + "%";
  219. if (i >= length)
  220. progressText.innerHTML = new Date().getTime()-total + " ms";
  221. //}
  222. };
  223. var total = new Date().getTime();
  224. inner();
  225. };
  226. var getResource = function(url)
  227. {
  228. var xhr = getXHRObject();
  229. xhr.open("get", url, false);
  230. xhr.send(null);
  231. return xhr.responseText;
  232. };
  233. var getXHRObject = function()
  234. {
  235. var xhrObj = false;
  236. try
  237. {
  238. xhrObj = new XMLHttpRequest();
  239. }
  240. catch(e)
  241. {
  242. var progid = [
  243. "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
  244. "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"
  245. ];
  246. for ( var i=0; i < progid.length; ++i ) {
  247. try
  248. {
  249. xhrObj = new ActiveXObject(progid[i]);
  250. }
  251. catch(e)
  252. {
  253. continue;
  254. }
  255. break;
  256. }
  257. }
  258. finally
  259. {
  260. return xhrObj;
  261. }
  262. };
  263. </script>
  264. <style type="text/css">
  265. html, body {
  266. margin: 0;
  267. padding: 0;
  268. overflow: hidden;
  269. background: #eee;
  270. }
  271. .strn { color: #800; }
  272. .keyw { color: #008; }
  273. .comm { color: #080; }
  274. .punc { color: #660; }
  275. .regx { color: #606; }
  276. .numb { color: #606; }
  277. #source {
  278. overflow: auto;
  279. height: 300px;
  280. background: #fff;
  281. }
  282. pre span {
  283. }
  284. pre {
  285. margin: 0;
  286. padding: 0;
  287. background: #fff;
  288. }
  289. #progressBar {
  290. background: #eee;
  291. position: relative;
  292. font-size: 11px;
  293. height: 14px;
  294. }
  295. #progressFill {
  296. background:#316AC5;
  297. width:0; height:100%;
  298. position: absolute;
  299. }
  300. #progressText {
  301. text-align: center;
  302. width:100%; height:100%;
  303. position: absolute;
  304. }
  305. #loading {
  306. position: absolute;
  307. background: #ff0;
  308. padding: 2px;
  309. display: none;
  310. z-index: 99;
  311. }
  312. </style>
  313. </head>
  314. <body>
  315. <div id="loading">&nbsp;</div>
  316. <div id="progressBar">
  317. <div id="progressFill">&nbsp;</div>
  318. <div id="progressText"></div>
  319. </div>
  320. <pre id="source">
  321. </pre>
  322. <input disabled id="run" type="button" value="run" onclick="run()" /> <i>~ :O</i>
  323. </body>
  324. </html>