PageRenderTime 1122ms CodeModel.GetById 28ms RepoModel.GetById 25ms app.codeStats 0ms

/src/ecma-debugger/templates.js

https://github.com/runeh/dragonfly-stp-1
JavaScript | 623 lines | 537 code | 51 blank | 35 comment | 40 complexity | 752f777744e0c418bfc165bfad776232 MD5 | raw file
  1. window.templates = window.templates || {};
  2. (function()
  3. {
  4. var self = this;
  5. this.hello = function(enviroment)
  6. {
  7. var ret = ['ul'];
  8. var prop = '';
  9. var prop_dict =
  10. {
  11. "stpVersion": ui_strings.S_TEXT_ENVIRONMENT_PROTOCOL_VERSION,
  12. "coreVersion": "Core Version",
  13. "operatingSystem": ui_strings.S_TEXT_ENVIRONMENT_OPERATING_SYSTEM,
  14. "platform": ui_strings.S_TEXT_ENVIRONMENT_PLATFORM,
  15. "userAgent": ui_strings.S_TEXT_ENVIRONMENT_USER_AGENT
  16. }
  17. for( prop in prop_dict)
  18. {
  19. ret[ret.length] = ['li', prop_dict[prop] + ': ' + enviroment[prop]];
  20. }
  21. if( ini.revision_number.indexOf("$") != -1 && ini.mercurial_revision )
  22. {
  23. ini.revision_number = ini.mercurial_revision;
  24. }
  25. ret[ret.length] = ['li', ui_strings.S_TEXT_ENVIRONMENT_DRAGONFLY_VERSION + ': ' + ini.dragonfly_version];
  26. ret[ret.length] = ['li', ui_strings.S_TEXT_ENVIRONMENT_REVISION_NUMBER + ': ' + ini.revision_number];
  27. return ['div', ret, 'class', 'padding'];
  28. }
  29. this.runtimes = function(runtimes, type, arg_list)
  30. {
  31. var ret = [], rt = null, i = 0;
  32. for( ; rt = runtimes[i]; i++)
  33. {
  34. ret[ret.length] = self['runtime-' + type](rt, arg_list);
  35. }
  36. return ret;
  37. }
  38. this['runtime-runtime'] = function(runtime, arg_list)
  39. {
  40. var display_uri = helpers.shortenURI(runtime.uri);
  41. return [
  42. 'cst-option',
  43. runtime['title'] || display_uri.uri,
  44. 'rt-id', runtime.runtime_id.toString()
  45. ].concat( display_uri.title ? ['title', display_uri.title] : [] )
  46. ;
  47. }
  48. this['runtime-script'] = function(runtime, arg_list)
  49. {
  50. var
  51. display_uri = helpers.shortenURI(runtime.uri),
  52. is_reloaded_window = runtimes.isReloadedWindow(runtime.window_id),
  53. ret = [
  54. ['h2', runtime['title'] || display_uri.uri].
  55. concat( runtime.selected ? ['class', 'selected-runtime'] : [] ).
  56. concat( display_uri.title ? ['title', display_uri.title] : [] )
  57. ],
  58. scripts = runtimes.getScripts(runtime.runtime_id),
  59. script = null,
  60. i=0,
  61. stopped_script_id = arg_list[0],
  62. selected_script_id = arg_list[1];
  63. if( scripts.length )
  64. {
  65. for( ; script = scripts[i]; i++)
  66. {
  67. ret[ret.length] = templates.scriptOption(script, selected_script_id, stopped_script_id);
  68. }
  69. }
  70. /*
  71. TODO handle runtimes with no scripts
  72. else
  73. {
  74. scripts_container = ['p',
  75. settings.runtimes.get('reload-runtime-automatically') || is_reloaded_window
  76. ? ui_strings.S_INFO_RUNTIME_HAS_NO_SCRIPTS
  77. : ui_strings.S_INFO_RELOAD_FOR_SCRIPT,
  78. 'class', 'info-text'];
  79. }
  80. */
  81. return ret;
  82. }
  83. this.scriptOption = function(script, selected_script_id, stopped_script_id)
  84. {
  85. var
  86. display_uri = helpers.shortenURI(script.uri),
  87. /* script types in the protocol:
  88. "inline" | "event" | "linked" | "timeout" | "java" | "generated" | "unknown" */
  89. type_dict =
  90. {
  91. "inline": ui_strings.S_TEXT_ECMA_SCRIPT_TYPE_INLINE,
  92. "linked": ui_strings.S_TEXT_ECMA_SCRIPT_TYPE_LINKED,
  93. "unknown": ui_strings.S_TEXT_ECMA_SCRIPT_TYPE_UNKNOWN
  94. },
  95. script_type = script.script_type,
  96. ret = [
  97. 'cst-option',
  98. ( type_dict[script_type] || script_type ) + ' - ' +
  99. (
  100. display_uri.uri
  101. ? display_uri.uri
  102. : ui_strings.S_TEXT_ECMA_SCRIPT_SCRIPT_ID + ': ' + script.script_id
  103. ),
  104. 'script-id', script.script_id.toString()
  105. ],
  106. class_name = script.script_id == selected_script_id && 'selected' || '';
  107. if(stopped_script_id == script.script_id)
  108. {
  109. class_name += ( class_name && ' ' || '' ) + 'stopped';
  110. }
  111. if( display_uri.title )
  112. {
  113. ret.splice(ret.length, 0, 'title', display_uri.title);
  114. }
  115. if( class_name )
  116. {
  117. ret.splice(ret.length, 0, 'class', class_name);
  118. }
  119. /*
  120. if( script.stop_ats.length )
  121. {
  122. ret.splice(ret.length, 0, 'style', 'background-position: 0 0');
  123. }
  124. */
  125. return ret;
  126. }
  127. this['runtime-css'] = function(runtime, org_args)
  128. {
  129. const
  130. OBJECT_ID = 0,
  131. HREF = 2,
  132. TITLE = 7;
  133. var
  134. display_uri = helpers.shortenURI(runtime.uri),
  135. ret =
  136. [
  137. ['h2', runtime['title'] || display_uri.uri].
  138. concat( display_uri.title ? ['title', display_uri.title] : [] )
  139. ],
  140. sheets = stylesheets.getStylesheets(runtime.runtime_id),
  141. sheet = null,
  142. i = 0,
  143. container = [],
  144. rt_id = runtime.runtime_id,
  145. title = '';
  146. if(sheets)
  147. {
  148. for( ; sheet = sheets[i]; i++)
  149. {
  150. title = sheet[HREF] ? sheet[HREF] : 'inline stylesheet ' + ( i + 1 ) ;
  151. container[container.length] =
  152. [
  153. 'cst-option',
  154. title,
  155. 'runtime-id', '' + rt_id,
  156. 'index', '' + i
  157. ];
  158. }
  159. }
  160. /*
  161. else
  162. {
  163. container = ['p', ui_strings.S_INFO_DOCUMNENT_LOADING, 'class', 'info-text'];
  164. }
  165. */
  166. //container.splice(container.length, 0, 'runtime-id', runtime.runtime_id);
  167. ret = ret.concat([container])
  168. return ret;
  169. }
  170. this['runtime-dom'] = function(runtime)
  171. {
  172. var display_uri = runtime['title'] || helpers.shortenURI(runtime.uri).uri;
  173. return (
  174. [
  175. 'cst-option',
  176. runtime['title'] || runtime.uri,
  177. 'runtime-id', runtime.runtime_id.toString()
  178. ].concat( dom_data.getDataRuntimeId() == runtime.runtime_id ? ['class', 'selected-runtime'] : [] ).
  179. concat( display_uri != runtime.uri ? ['title', runtime.uri] : [] ) )
  180. }
  181. this.checkbox = function(settingName, settingValue)
  182. {
  183. return ['li',
  184. ['label',
  185. ['input',
  186. 'type', 'checkbox',
  187. 'value', settingName,
  188. 'checked', settingValue ? true : false,
  189. 'handler', 'set-stop-at'
  190. ],
  191. settingName
  192. ]
  193. ]
  194. }
  195. this.frame = function(frame, is_top)
  196. {
  197. // %(function name)s line %(line number)s script id %(script id)s
  198. return ['li',
  199. ui_strings.S_TEXT_CALL_STACK_FRAME_LINE.
  200. replace("%(FUNCTION_NAME)s", ( frame.fn_name || ui_strings.ANONYMOUS_FUNCTION_NAME ) ).
  201. replace("%(LINE_NUMBER)s", ( frame.line || '-' ) ).
  202. replace("%(SCRIPT_ID)s", ( frame.script_id || '-' ) ),
  203. 'handler', 'show-frame',
  204. 'ref-id', frame.id,
  205. ].concat( is_top ? ['class', 'selected'] : [] );
  206. }
  207. this.configStopAt = function(config)
  208. {
  209. var ret =['ul'];
  210. var arr = ["script", "exception", "error", "abort"], n='', i=0;
  211. for( ; n = arr[i]; i++)
  212. {
  213. ret[ret.length] = this.checkbox(n, config[n]);
  214. }
  215. return ['div'].concat([ret]);
  216. }
  217. /*
  218. MODE ::= "<mode>"
  219. ( "run" | "step-into-call" | "step-next-line" | "step-out-of-call" )
  220. "</mode>" ;
  221. */
  222. this.continues = function()
  223. {
  224. var ret = [];
  225. ret[ret.length] = self.continueWithMode('run ( F5 )', 'run');
  226. ret[ret.length] = self.continueWithMode('step into call ( F11 )', 'step-into-call');
  227. ret[ret.length] = self.continueWithMode('step next line ( F10 )', 'step-next-line');
  228. ret[ret.length] = self.continueWithMode('step out of call ( Shift F11 )', 'step-out-of-call');
  229. return ret;
  230. }
  231. this.continueWithMode = function(name, mode)
  232. {
  233. return ['input',
  234. 'type', 'button',
  235. 'value', '',
  236. 'title', name,
  237. 'mode', mode,
  238. 'id', 'continue-' + mode,
  239. 'handler', 'continue',
  240. 'disabled', true
  241. ]
  242. }
  243. this.examineObject = function( data )
  244. {
  245. var prop = null,
  246. i = 0,
  247. ret = ['ul'];
  248. for( i=0 ; prop = data[i]; i++)
  249. {
  250. switch(prop.type)
  251. {
  252. case 'object':
  253. {
  254. ret[ret.length] = self.key_value_folder(prop.key, i);
  255. break;
  256. }
  257. case 'undefined':
  258. case 'null':
  259. {
  260. ret[ret.length] = self.key_value(prop.key, prop.value, prop.type, i);
  261. break;
  262. }
  263. default:
  264. {
  265. ret[ret.length] = ret[ret.length] = self.key_value(prop.key, prop.value, prop.type, i);
  266. break;
  267. }
  268. }
  269. }
  270. if( window.__profiling__ )
  271. {
  272. window.__times__[4] = new Date().getTime(); // creating markup
  273. }
  274. return ret;
  275. }
  276. this.key_value = function(key, value, value_class, ref_index)
  277. {
  278. return ['li',
  279. ['span', key, 'class', 'key'],
  280. ['span', value].concat( value_class ? ['class', value_class] : []),
  281. 'ref_index', ref_index
  282. ];
  283. }
  284. this.key_value_folder = function(key, ref_index)
  285. {
  286. return ['li',
  287. ['input', 'type', 'button', 'handler', 'examine-object', 'class', 'folder-key'],
  288. ['span', key, 'class', 'key'],
  289. ['span', 'object', 'class', 'object'],
  290. 'ref_index', ref_index
  291. ];
  292. }
  293. this.breakpoint = function(line_nr, top)
  294. {
  295. return ['li',
  296. 'class', 'breakpoint',
  297. 'line_nr', line_nr,
  298. 'style', 'top:'+ top +'px'
  299. ]
  300. }
  301. this.runtimes_dropdown = function(ele)
  302. {
  303. return ['div', ['ul', 'id', 'runtimes'], 'class', 'window-container'];
  304. }
  305. this.cssInspector = function(categories)
  306. {
  307. var ret = [], cat = null, i = 0;
  308. for( ; cat = categories[i]; i++)
  309. {
  310. ret[ret.length] = this.cssInspectorCategory(cat);
  311. }
  312. return ret;
  313. }
  314. this.cssInspectorCategory = function(cat)
  315. {
  316. //<input type="button" handler="toggle-setting" view-id="css-inspector" tab-id="css-inspector" class="unfolded" />
  317. var ret = ['category',
  318. ['header',
  319. ['input',
  320. 'type', 'button',
  321. 'handler', 'css-toggle-category',
  322. 'cat-id', cat.id
  323. ].concat( cat.is_unfolded() ? ['class', 'unfolded'] : [] ),
  324. cat.name,
  325. 'handler', 'css-toggle-category'
  326. ],
  327. ['styles']
  328. ];
  329. if( cat.is_unfolded() )
  330. {
  331. ret.splice(ret.length, 0, 'class', 'unfolded');
  332. }
  333. if( cat.handler )
  334. {
  335. ret.splice(ret.length, 0, 'handler', cat.handler);
  336. }
  337. return ret;
  338. }
  339. this['js-script-select'] = function(ui_obj)
  340. {
  341. return self['cst-select'](ui_obj.script_select);
  342. }
  343. this.breadcrumb = function(model, obj_id, parent_node_chain)
  344. {
  345. var
  346. css_path = model._get_css_path(obj_id, parent_node_chain,
  347. window.settings.dom.get('force-lowercase'),
  348. window.settings.dom.get('show-id_and_classes-in-breadcrumb'),
  349. window.settings.dom.get('show-siblings-in-breadcrumb')),
  350. ret = ["breadcrumb"],
  351. i = 0;
  352. if (css_path)
  353. {
  354. for( ; i < css_path.length; i++ )
  355. {
  356. ret[ret.length] =
  357. [
  358. "span", css_path[i].name,
  359. 'obj-id', css_path[i].id.toString(),
  360. 'handler', 'breadcrumb-link',
  361. 'class', css_path[i].is_parent_offset ? 'parent-offset' : '',
  362. ];
  363. ret[ret.length] = css_path[i].combinator;
  364. }
  365. }
  366. ret.push('data-model-id', model.id);
  367. return ret;
  368. }
  369. this.uiLangOptions = function(lang_dict)
  370. {
  371. var dict =
  372. [
  373. {
  374. browserLanguge: "be",
  375. key: "be",
  376. name: "български език"
  377. },
  378. {
  379. browserLanguge: "cs",
  380. key: "cs",
  381. name: "Česky"
  382. },
  383. {
  384. browserLanguge: "da",
  385. key: "da",
  386. name: "Dansk"
  387. },
  388. {
  389. browserLanguge: "de",
  390. key: "de",
  391. name: "Deutsch"
  392. },
  393. {
  394. browserLanguge: "el",
  395. key: "el",
  396. name: "Ελληνικά"
  397. },
  398. {
  399. browserLanguge: "en",
  400. key: "en",
  401. name: "English"
  402. },
  403. {
  404. browserLanguge: "es-ES",
  405. key: "es-ES",
  406. name: "Español (España)"
  407. },
  408. {
  409. browserLanguge: "es-LA",
  410. key: "es-LA",
  411. name: "Español (Latinoamérica)"
  412. },
  413. {
  414. browserLanguge: "et",
  415. key: "et",
  416. name: "Eesti keel"
  417. },
  418. {
  419. browserLanguge: "fi",
  420. key: "fi",
  421. name: "Suomen kieli"
  422. },
  423. {
  424. browserLanguge: "fr",
  425. key: "fr",
  426. name: "Français"
  427. },
  428. {
  429. browserLanguge: "fr-CA",
  430. key: "fr-CA",
  431. name: "Français Canadien"
  432. },
  433. {
  434. browserLanguge: "fy",
  435. key: "fy",
  436. name: "Frysk"
  437. },
  438. {
  439. browserLanguge: "hi",
  440. key: "hi",
  441. name: "हिन्दी"
  442. },
  443. {
  444. browserLanguge: "hr",
  445. key: "hr",
  446. name: "Hrvatski"
  447. },
  448. {
  449. browserLanguge: "hu",
  450. key: "hu",
  451. name: "Magyar"
  452. },
  453. {
  454. browserLanguge: "id",
  455. key: "id",
  456. name: "Bahasa Indonesia"
  457. },
  458. {
  459. browserLanguge: "it",
  460. key: "it",
  461. name: "Italiano"
  462. },
  463. {
  464. browserLanguge: "ja",
  465. key: "ja",
  466. name: "日本語"
  467. },
  468. {
  469. browserLanguge: "ka",
  470. key: "ka",
  471. name: "ქართული"
  472. },
  473. {
  474. browserLanguge: "ko",
  475. key: "ko",
  476. name: "한국어"
  477. },
  478. {
  479. browserLanguge: "lt",
  480. key: "lt",
  481. name: "Lietuvių kalba"
  482. },
  483. {
  484. browserLanguge: "mk",
  485. key: "mk",
  486. name: "македонски јазик"
  487. },
  488. {
  489. browserLanguge: "nb",
  490. key: "nb",
  491. name: "Norsk bokmål"
  492. },
  493. {
  494. browserLanguge: "nl",
  495. key: "nl",
  496. name: "Nederlands"
  497. },
  498. {
  499. browserLanguge: "nn",
  500. key: "nn",
  501. name: "Norsk nynorsk"
  502. },
  503. {
  504. browserLanguge: "pl",
  505. key: "pl",
  506. name: "Polski"
  507. },
  508. {
  509. browserLanguge: "pt",
  510. key: "pt",
  511. name: "Português"
  512. },
  513. {
  514. browserLanguge: "pt-BR",
  515. key: "pt-BR",
  516. name: "Português (Brasil)"
  517. },
  518. {
  519. browserLanguge: "ru",
  520. key: "ru",
  521. name: "Русский язык"
  522. },
  523. {
  524. browserLanguge: "sv",
  525. key: "sv",
  526. name: "Svenska"
  527. },
  528. {
  529. browserLanguge: "ta",
  530. key: "ta",
  531. name: "தமிழ்"
  532. },
  533. {
  534. browserLanguge: "te",
  535. key: "te",
  536. name: "తెలుగు"
  537. },
  538. {
  539. browserLanguge: "tr",
  540. key: "tr",
  541. name: "Türkçe"
  542. },
  543. {
  544. browserLanguge: "uk",
  545. key: "uk",
  546. name: "Українська"
  547. },
  548. {
  549. browserLanguge: "zh-cn",
  550. key: "zh-cn",
  551. name: "简体中文"
  552. },
  553. {
  554. browserLanguge: "zh-tw",
  555. key: "zh-tw",
  556. name: "繁體中文"
  557. }
  558. ],
  559. lang = null,
  560. i = 0,
  561. selected_lang = window.ui_strings.lang_code,
  562. ret = [];
  563. for( ; lang = dict[i]; i++)
  564. {
  565. ret[ret.length] = ['option', lang.name, 'value', lang.key].
  566. concat( selected_lang == lang.key ? ['selected', 'selected'] : [] );
  567. }
  568. return ret;
  569. }
  570. }).apply(window.templates);