PageRenderTime 93ms CodeModel.GetById 38ms RepoModel.GetById 16ms app.codeStats 0ms

/ext-4.1.0_b3/docs/extjs/examples/shared/include-theme.js

https://bitbucket.org/srogerf/javascript
JavaScript | 91 lines | 75 code | 11 blank | 5 comment | 4 complexity | b1539a473557022545e785eba5feca1d MD5 | raw file
  1. (function() {
  2. var url = getUrl(),
  3. thisDir = getDir(url),
  4. params = getMergedQueryParams(url),
  5. theme = getTheme(params),
  6. css = getCss(theme);
  7. document.write(Ext.String.format('<link rel="stylesheet" type="text/css" href="{0}/../../resources/css/ext-{1}.css" />', thisDir, css));
  8. if (params.themes_combo != null) {
  9. Ext.require('Ext.panel.Panel');
  10. Ext.require('Ext.data.ArrayStore');
  11. Ext.require('Ext.form.field.ComboBox');
  12. Ext.onReady(function() {
  13. Ext.create('Ext.panel.Panel', {
  14. autoShow: true,
  15. frame: true,
  16. renderTo: Ext.getBody(),
  17. items: {
  18. editable: false,
  19. fieldLabel: 'Theme',
  20. labelWidth: 50,
  21. value: theme,
  22. width: 180,
  23. xtype: 'combo',
  24. listeners: {
  25. change: function(combo, value) {
  26. params.theme = value;
  27. location.search = Ext.Object.toQueryString(params);
  28. }
  29. },
  30. store: [
  31. ['classic', 'Classic'],
  32. ['gray', 'Gray'],
  33. ['access', 'Accessibility']
  34. ],
  35. style: {
  36. margin: '2px'
  37. }
  38. },
  39. style: {
  40. position: 'absolute',
  41. right: '10px',
  42. top: '10px'
  43. }
  44. });
  45. });
  46. }
  47. // The URL used to load this script file
  48. function getUrl() {
  49. var scripts = document.getElementsByTagName('script'),
  50. thisScript = scripts[scripts.length - 1];
  51. return thisScript.src;
  52. }
  53. // The directory of this script file
  54. function getDir(url) {
  55. return url.slice(0, url.lastIndexOf('/'));
  56. }
  57. // Combines the query parameters from the page URL and the script URL
  58. function getMergedQueryParams(url) {
  59. var searchIndex = url.indexOf('?'),
  60. parse = Ext.Object.fromQueryString;
  61. return Ext.apply(searchIndex === -1 ? {} : parse(url.slice(searchIndex)), parse(location.search));
  62. }
  63. // Get the canonical theme name from the query parameters
  64. function getTheme(params) {
  65. return {
  66. access: 'access',
  67. accessibility: 'access',
  68. gray: 'gray',
  69. grey: 'gray'
  70. }[params.theme || params.css] || 'classic';
  71. }
  72. // Get the CSS file name from the theme name
  73. function getCss(theme) {
  74. return {
  75. access: 'all-access',
  76. classic: 'all',
  77. gray: 'all-gray'
  78. }[theme];
  79. }
  80. })();