]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * This file includes the required ext-all js and css files based upon "theme" and "rtl"\r | |
3 | * url parameters. It first searches for these parameters on the page url, and if they\r | |
4 | * are not found there, it looks for them on the script tag src query string.\r | |
5 | * For example, to include the neptune flavor of ext from an index page in a subdirectory\r | |
6 | * of extjs/examples/:\r | |
7 | * <script type="text/javascript" src="../../examples/shared/include-ext.js?theme=neptune"></script>\r | |
8 | */\r | |
9 | (function() {\r | |
10 | function getQueryParam(name) {\r | |
11 | var regex = RegExp('[?&]' + name + '=([^&]*)');\r | |
12 | \r | |
13 | var match = regex.exec(location.search) || regex.exec(scriptPath);\r | |
14 | return match && decodeURIComponent(match[1]);\r | |
15 | }\r | |
16 | \r | |
17 | function hasOption(opt, queryString) {\r | |
18 | var s = queryString || location.search;\r | |
19 | var re = new RegExp('(?:^|[&?])' + opt + '(?:[=]([^&]*))?(?:$|[&])', 'i');\r | |
20 | var m = re.exec(s);\r | |
21 | \r | |
22 | return m ? (m[1] === undefined || m[1] === '' ? true : m[1]) : false;\r | |
23 | }\r | |
24 | \r | |
25 | function loadCss(url) {\r | |
26 | document.write('<link rel="stylesheet" type="text/css" href="' + url + '"/>');\r | |
27 | }\r | |
28 | \r | |
29 | function loadScript(url, defer) {\r | |
30 | document.write('<script type="text/javascript" src="' + url + '"' +\r | |
31 | (defer ? ' defer' : '') + '></script>');\r | |
32 | }\r | |
33 | \r | |
34 | Ext = window.Ext || {};\r | |
35 | \r | |
36 | // The value of Ext.repoDevMode gets replaced during a build - do not change this line\r | |
37 | // 2 == internal dev mode, 1 == external dev mode, 0 == build mode\r | |
38 | Ext.devMode = 0;\r | |
39 | \r | |
40 | var scriptEls = document.getElementsByTagName('script'),\r | |
41 | scriptPath = scriptEls[scriptEls.length - 1].src,\r | |
42 | rtl = getQueryParam('rtl'),\r | |
43 | themeName = getQueryParam('theme') || 'triton',\r | |
44 | includeCSS = !hasOption('nocss', scriptPath),\r | |
45 | useDebug = hasOption('debug'),\r | |
46 | hasOverrides = !hasOption('nooverrides', scriptPath) && !!{\r | |
47 | // TODO: remove neptune\r | |
48 | neptune: 1,\r | |
49 | triton: 1,\r | |
50 | classic: 1,\r | |
51 | gray: 1,\r | |
52 | triton: 1,\r | |
53 | 'neptune-touch': 1,\r | |
54 | crisp: 1,\r | |
55 | 'crisp-touch': 1\r | |
56 | }[themeName],\r | |
57 | i = 4,\r | |
58 | devMode = Ext.devMode,\r | |
59 | extDir = scriptPath,\r | |
60 | rtlSuffix = (rtl ? '-rtl' : ''),\r | |
61 | debugSuffix = (devMode ? '-debug' : ''),\r | |
62 | cssSuffix = rtlSuffix + debugSuffix + '.css',\r | |
63 | themePackageDir, chartsJS, uxJS, themeOverrideJS, extPrefix, extPackagesRoot;\r | |
64 | \r | |
65 | rtl = rtl && rtl.toString() === 'true';\r | |
66 | \r | |
67 | while (i--) {\r | |
68 | extDir = extDir.substring(0, extDir.lastIndexOf('/'));\r | |
69 | }\r | |
70 | \r | |
71 | extPackagesRoot = devMode ? (extDir + '/build') : extDir;\r | |
72 | \r | |
73 | uxJS = extPackagesRoot + '/packages/ux/classic/ux' + debugSuffix + '.js';\r | |
74 | chartsJS = extPackagesRoot + '/packages/charts/classic/charts' + debugSuffix + '.js';\r | |
75 | themePackageDir = extPackagesRoot + '/classic/theme-' + themeName + '/';\r | |
76 | \r | |
77 | if (includeCSS) {\r | |
78 | loadCss(themePackageDir + 'resources/theme-' + themeName + '-all' + cssSuffix);\r | |
79 | loadCss(extPackagesRoot + '/packages/charts/classic/' + themeName + '/resources/charts-all' + cssSuffix);\r | |
80 | loadCss(extPackagesRoot + '/packages/ux/classic/' + themeName + '/resources/ux-all' + cssSuffix);\r | |
81 | }\r | |
82 | \r | |
83 | extPrefix = useDebug ? '/ext' : '/ext-all';\r | |
84 | \r | |
85 | document.write('<script type="text/javascript" src="' + extDir + extPrefix + rtlSuffix + '.js"></script>');\r | |
86 | \r | |
87 | if (hasOverrides) {\r | |
88 | // since document.write('<script>') does not block execution in IE, we need to\r | |
89 | // make sure we prevent theme overrides from executing before ext-all.js\r | |
90 | // normally this can be done using the defer attribute on the script tag, however\r | |
91 | // this method does not work in IE when in repoDevMode. It seems the reason for\r | |
92 | // this is because in repoDevMode ext-all.js is simply a script that loads other\r | |
93 | // scripts and so Ext is still undefined when the neptune overrides are executed.\r | |
94 | // To work around this we use the _beforereadyhandler hook to load the theme\r | |
95 | // overrides dynamically after Ext has been defined.\r | |
96 | themeOverrideJS = themePackageDir + 'theme-' + themeName + debugSuffix + '.js';\r | |
97 | \r | |
98 | if (devMode) {\r | |
99 | if (window.ActiveXObject) {\r | |
100 | Ext = {\r | |
101 | _beforereadyhandler: function() {\r | |
102 | Ext.Loader.loadScript({url: themeOverrideJS});\r | |
103 | }\r | |
104 | };\r | |
105 | } else {\r | |
106 | loadScript(themeOverrideJS, true);\r | |
107 | }\r | |
108 | } else {\r | |
109 | loadScript(themeOverrideJS, true);\r | |
110 | // ux and charts js are not needed in dev mode because they are included in bootstrap\r | |
111 | loadScript(uxJS);\r | |
112 | loadScript(chartsJS);\r | |
113 | }\r | |
114 | }\r | |
115 | \r | |
116 | })();\r |