]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /*\r |
2 | * This file is generated by Sencha Cmd and should NOT be edited. It will be replaced\r | |
3 | * during an upgrade.\r | |
4 | */\r | |
5 | \r | |
6 | Ext.require([\r | |
7 | 'Ext.layout.Context'\r | |
8 | ]);\r | |
9 | \r | |
10 | Ext.theme = {\r | |
11 | /**\r | |
12 | * The array of all component manifests. These objects have the following set of\r | |
13 | * properties recognized by the slicer:\r | |
14 | * @private\r | |
15 | */\r | |
16 | _manifest: [],\r | |
17 | \r | |
18 | /**\r | |
19 | * The collection of shortcuts for a given alias (e.g., 'widget.panel'). This is an\r | |
20 | * object keyed by alias whose values are arrays of shortcut definitions.\r | |
21 | * @private\r | |
22 | */\r | |
23 | _shortcuts: {},\r | |
24 | \r | |
25 | doRequire : function(xtype) {\r | |
26 | if(xtype.indexOf("widget.") != 0) {\r | |
27 | xtype = "widget." + xtype;\r | |
28 | }\r | |
29 | Ext.require([xtype]);\r | |
30 | },\r | |
31 | \r | |
32 | /**\r | |
33 | * Adds one ore more component entries to the theme manifest. These entries will be\r | |
34 | * instantiated by the `Ext.theme.render` method when the page is ready.\r | |
35 | *\r | |
36 | * Usage:\r | |
37 | *\r | |
38 | * Ext.theme.addManifest({\r | |
39 | * xtype: 'widget.menu',\r | |
40 | * folder: 'menu',\r | |
41 | * delegate: '.x-menu-item-link',\r | |
42 | * filename: 'menu-item-active',\r | |
43 | * config: {\r | |
44 | * floating: false,\r | |
45 | * width: 200,\r | |
46 | * items: [{\r | |
47 | * text: 'test',\r | |
48 | * cls: 'x-menu-item-active'\r | |
49 | * }]\r | |
50 | * }\r | |
51 | * },{\r | |
52 | * //...\r | |
53 | * });\r | |
54 | *\r | |
55 | * @param manifest {Object} An object with type of component, slicing information and\r | |
56 | * component configuration. If this parameter is an array, each element is treated as\r | |
57 | * a manifest entry. Otherwise, each argument passed is treated as a manifest entry.\r | |
58 | *\r | |
59 | * @param manifest.xtype {String} The xtype ('grid') or alias ('widget.grid'). This\r | |
60 | * is used to specify the type of component to create as well as a potential key to\r | |
61 | * any `shortcuts` defined for the xtype.\r | |
62 | *\r | |
63 | * @param manifest.config {Object} The component configuration object. The properties\r | |
64 | * of this depend on the `xtype` of the component.\r | |
65 | *\r | |
66 | * @param [manifest.delegate] {String} The DOM query to use to select the element to\r | |
67 | * slice. The default is to slice the primary element of the component.\r | |
68 | *\r | |
69 | * @param [manifest.parentCls] An optional CSS class to add to the parent of the\r | |
70 | * component.\r | |
71 | *\r | |
72 | * @param [manifest.setup] {Function} An optional function to be called to initialize\r | |
73 | * the component.\r | |
74 | * @param manifest.setup.component {Ext.Component} The component instance\r | |
75 | * @param manifest.setup.container {Element} The component's container.\r | |
76 | *\r | |
77 | * @param [manifest.folder] {String} The folder in to which to produce image slices.\r | |
78 | * Only applies to Ext JS 4.1 (removed in 4.2).\r | |
79 | *\r | |
80 | * @param [manifest.filename] {String} The base filename for slices.\r | |
81 | * Only applies to Ext JS 4.1 (removed in 4.2).\r | |
82 | *\r | |
83 | * @param [manifest.reverse] {Boolean} True to position the slices for linear gradient\r | |
84 | * background at then opposite "end" (right or bottom) and apply the stretch to the\r | |
85 | * area before it (left or top). Only applies to Ext JS 4.1 (removed in 4.2).\r | |
86 | */\r | |
87 | addManifest: function (manifest) {\r | |
88 | var all = Ext.theme._manifest;\r | |
89 | var add = Ext.isArray(manifest) ? manifest : arguments;\r | |
90 | \r | |
91 | if(manifest.xtype) {\r | |
92 | Ext.theme.doRequire(manifest.xtype);\r | |
93 | }\r | |
94 | \r | |
95 | for (var i = 0, n = add.length; i < n; ++i) {\r | |
96 | if(add[i].xtype) {\r | |
97 | Ext.theme.doRequire(add[i].xtype);\r | |
98 | }\r | |
99 | all.push(add[i]);\r | |
100 | }\r | |
101 | },\r | |
102 | \r | |
103 | /**\r | |
104 | * Adds one or more shortcuts to the rendering process. A `shortcut` is an object that\r | |
105 | * looks the same as a `manifest` entry. These are combined by copying the properties\r | |
106 | * from the shortcut over those of the manifest entry. In basic terms:\r | |
107 | *\r | |
108 | * var config = Ext.apply(Ext.apply({}, manfiest.config), shortcut.config);\r | |
109 | * var entry = Ext.apply(Ext.apply({}, manfiest), shortcut);\r | |
110 | * entry.config = config;\r | |
111 | *\r | |
112 | * This is not exactly the process, but the idea is the same. The difference is that\r | |
113 | * the `ui` of the manifest entry is used to replace any `"{ui}"` substrings found in\r | |
114 | * any string properties of the shortcut or its `config` object.\r | |
115 | *\r | |
116 | * Usage:\r | |
117 | *\r | |
118 | * Ext.theme.addShortcuts({\r | |
119 | * 'widget.foo': [{\r | |
120 | * config: {\r | |
121 | * }\r | |
122 | * },{\r | |
123 | * config: {\r | |
124 | * }\r | |
125 | * }],\r | |
126 | *\r | |
127 | * 'widget.bar': [ ... ]\r | |
128 | * });\r | |
129 | */\r | |
130 | addShortcuts: function (shortcuts) {\r | |
131 | var all = Ext.theme._shortcuts;\r | |
132 | \r | |
133 | for (var key in shortcuts) {\r | |
134 | \r | |
135 | var add = shortcuts[key];\r | |
136 | var xtype = Ext.theme.addWidget(key);\r | |
137 | var existing = all[xtype];\r | |
138 | \r | |
139 | Ext.theme.doRequire(xtype);\r | |
140 | for(var i=0; i < add.length; i++) {\r | |
141 | var config = add[i];\r | |
142 | if(config.xtype) {\r | |
143 | Ext.theme.doRequire(config.xtype);\r | |
144 | }\r | |
145 | }\r | |
146 | \r | |
147 | if (!existing) {\r | |
148 | all[xtype] = existing = [];\r | |
149 | }\r | |
150 | \r | |
151 | existing.push.apply(existing, add);\r | |
152 | }\r | |
153 | },\r | |
154 | \r | |
155 | /**\r | |
156 | * This method ensures that a given string has the specified prefix (e.g., "widget.").\r | |
157 | * @private\r | |
158 | */\r | |
159 | addPrefix: function (prefix, s) {\r | |
160 | if (!s || (s.length > prefix.length && s.substring(0,prefix.length) === prefix)) {\r | |
161 | return s;\r | |
162 | }\r | |
163 | return prefix + s;\r | |
164 | },\r | |
165 | \r | |
166 | /**\r | |
167 | * This method returns the given string with "widget." added to the front if that is\r | |
168 | * not already present.\r | |
169 | * @private\r | |
170 | */\r | |
171 | addWidget: function (str) {\r | |
172 | return Ext.theme.addPrefix('widget.', str);\r | |
173 | },\r | |
174 | \r | |
175 | /**\r | |
176 | * This method accepts an manifest entry and a shortcut entry and returns the merged\r | |
177 | * version.\r | |
178 | * @private\r | |
179 | */\r | |
180 | applyShortcut: function (manifestEntry, shortcut) {\r | |
181 | var ui = manifestEntry.ui;\r | |
182 | var config = Ext.theme.copyProps({}, manifestEntry.config);\r | |
183 | var entry = Ext.theme.copyProps({}, manifestEntry);\r | |
184 | \r | |
185 | if (ui && !config.ui) {\r | |
186 | config.ui = ui;\r | |
187 | }\r | |
188 | if (shortcut) {\r | |
189 | var tpl = { ui: ui };\r | |
190 | Ext.theme.copyProps(entry, shortcut, tpl);\r | |
191 | Ext.theme.copyProps(config, shortcut.config, tpl);\r | |
192 | }\r | |
193 | \r | |
194 | entry.xtype = Ext.theme.addWidget(entry.xtype);\r | |
195 | entry.config = config; // both guys have "config" so smash merged one on now...\r | |
196 | return entry;\r | |
197 | },\r | |
198 | \r | |
199 | /**\r | |
200 | * This method copies property from a `src` object to a `dest` object and reaplces\r | |
201 | * `"{foo}"` fragments of any string properties as defined in the `tpl` object.\r | |
202 | *\r | |
203 | * var obj = Ext.theme.copyProps({}, {\r | |
204 | * foo: 'Hello-{ui}'\r | |
205 | * }, {\r | |
206 | * ui: 'World'\r | |
207 | * });\r | |
208 | *\r | |
209 | * console.log('obj.foo: ' + obj.foo); // logs "Hello-World"\r | |
210 | *\r | |
211 | * @return {Object} The `dest` object or a new object (if `dest` was null).\r | |
212 | * @private\r | |
213 | */\r | |
214 | copyProps: function (dest, src, tpl) {\r | |
215 | var out = dest || {};\r | |
216 | var replacements = [];\r | |
217 | var token;\r | |
218 | \r | |
219 | if (src) {\r | |
220 | if (tpl) {\r | |
221 | for (token in tpl) {\r | |
222 | replacements.push({\r | |
223 | re: new RegExp('\\{' + token + '\\}', 'g'),\r | |
224 | value: tpl[token]\r | |
225 | });\r | |
226 | }\r | |
227 | }\r | |
228 | \r | |
229 | for (var key in src) {\r | |
230 | var val = src[key];\r | |
231 | if (tpl && typeof val === 'string') {\r | |
232 | for (var i = 0; i < replacements.length; ++ i) {\r | |
233 | val = val.replace(replacements[i].re, replacements[i].value);\r | |
234 | }\r | |
235 | }\r | |
236 | out[key] = val;\r | |
237 | }\r | |
238 | }\r | |
239 | \r | |
240 | return out;\r | |
241 | },\r | |
242 | \r | |
243 | /**\r | |
244 | * Renders a component given its manifest and shortcut entries.\r | |
245 | * @private\r | |
246 | */\r | |
247 | renderWidget: function (manifestEntry, shortcut) {\r | |
248 | var entry = Ext.theme.applyShortcut(manifestEntry, shortcut);\r | |
249 | var config = entry.config;\r | |
250 | var widget = Ext.create(entry.xtype, config);\r | |
251 | var ct = Ext.fly(document.body).createChild({ cls: 'widget-container' });\r | |
252 | \r | |
253 | Ext.theme.currentWidget = widget;\r | |
254 | \r | |
255 | if (widget.floating === true) {\r | |
256 | widget.floating = { shadow: false };\r | |
257 | }\r | |
258 | if (widget.floating) {\r | |
259 | widget.focusOnToFront = false;\r | |
260 | }\r | |
261 | \r | |
262 | if (entry.setup) {\r | |
263 | entry.setup.call(widget, widget, ct);\r | |
264 | } else {\r | |
265 | widget.render(ct);\r | |
266 | if (widget.floating) {\r | |
267 | widget.showAt(0, 0);\r | |
268 | ct.setHeight(widget.getHeight());\r | |
269 | }\r | |
270 | }\r | |
271 | \r | |
272 | var el = widget.el;\r | |
273 | if (entry.delegate) {\r | |
274 | el = el.down(entry.delegate);\r | |
275 | }\r | |
276 | \r | |
277 | el.addCls('x-slicer-target'); // this is what generateSlicerManifest looks for\r | |
278 | \r | |
279 | if (entry.over) {\r | |
280 | widget.addOverCls();\r | |
281 | }\r | |
282 | if (config.parentCls) {\r | |
283 | el.parent().addCls(config.parentCls);\r | |
284 | }\r | |
285 | \r | |
286 | if (Ext.theme.legacy) {\r | |
287 | // The 4.1 approach has some interesting extra pieces\r | |
288 | //\r | |
289 | var data = {};\r | |
290 | if (entry.reverse) {\r | |
291 | data.reverse = true;\r | |
292 | }\r | |
293 | if (entry.filename) {\r | |
294 | data.filename = entry.filename;\r | |
295 | }\r | |
296 | if (entry.folder) {\r | |
297 | data.folder = entry.folder;\r | |
298 | }\r | |
299 | if (entry.offsets) {\r | |
300 | data.offsets = entry.offsets;\r | |
301 | }\r | |
302 | \r | |
303 | Ext.theme.setData(el.dom, data);\r | |
304 | }\r | |
305 | \r | |
306 | Ext.theme.currentWidget = null;\r | |
307 | },\r | |
308 | \r | |
309 | /**\r | |
310 | * Renders all of the components that have been added to the manifest.\r | |
311 | * @private\r | |
312 | */\r | |
313 | render: function () {\r | |
314 | console.log("rendering widgets...")\r | |
315 | var manifest = Ext.theme._manifest;\r | |
316 | var shortcuts = Ext.theme._shortcuts;\r | |
317 | \r | |
318 | for (var k = 0, n = manifest ? manifest.length : 0; k < n; ++k) {\r | |
319 | var manifestEntry = manifest[k];\r | |
320 | var xtype = Ext.theme.addWidget(manifestEntry.xtype);\r | |
321 | var widgetShortcuts = xtype ? shortcuts[xtype] : null;\r | |
322 | \r | |
323 | if (xtype && manifestEntry.ui && widgetShortcuts) {\r | |
324 | for (var i = 0; i < widgetShortcuts.length; i++) {\r | |
325 | Ext.theme.renderWidget(manifestEntry, widgetShortcuts[i]);\r | |
326 | }\r | |
327 | } else {\r | |
328 | Ext.theme.renderWidget(manifestEntry);\r | |
329 | }\r | |
330 | }\r | |
331 | },\r | |
332 | \r | |
333 | /**\r | |
334 | * Renders all components (see `render`) and notifies the Slicer that things are ready.\r | |
335 | * @private\r | |
336 | */\r | |
337 | run: function () {\r | |
338 | var extjsVer = Ext.versions.extjs;\r | |
339 | var globalData = {};\r | |
340 | \r | |
341 | if (Ext.layout.Context) {\r | |
342 | Ext.override(Ext.layout.Context, {\r | |
343 | run: function () {\r | |
344 | var ok = this.callParent(),\r | |
345 | widget = Ext.theme.currentWidget;\r | |
346 | if (!ok && widget) {\r | |
347 | Ext.Error.raise("Layout run failed: " + widget.id);\r | |
348 | }\r | |
349 | return ok;\r | |
350 | }\r | |
351 | });\r | |
352 | }\r | |
353 | \r | |
354 | console.log("loading widget definitions...");\r | |
355 | \r | |
356 | // Previous to Ext JS 4.2, themes and their manifests where defined differently.\r | |
357 | // So pass this along if we are hosting a pre-4.2 theme.\r | |
358 | //\r | |
359 | if (extjsVer && extjsVer.isLessThan(new Ext.Version("4.2"))) {\r | |
360 | globalData.format = "1.0"; // tell the Slicer tool\r | |
361 | Ext.theme.legacy = true; // not for our own data collection\r | |
362 | \r | |
363 | // Check for the Cmd3.0/ExtJS4.1 variables:\r | |
364 | //\r | |
365 | if (Ext.manifest && Ext.manifest.widgets) {\r | |
366 | Ext.theme.addManifest(Ext.manifest.widgets);\r | |
367 | }\r | |
368 | if (Ext.shortcuts) {\r | |
369 | Ext.theme.addShortcuts(Ext.shortcuts);\r | |
370 | }\r | |
371 | if (Ext.userManifest && Ext.userManifest.widgets) {\r | |
372 | Ext.theme.addManifest(Ext.userManifest.widgets);\r | |
373 | }\r | |
374 | }\r | |
375 | \r | |
376 | Ext.theme.setData(document.body, globalData);\r | |
377 | Ext.theme.render();\r | |
378 | Ext.theme.generateSlicerManifest();\r | |
379 | },\r | |
380 | \r | |
381 | generateSlicerManifest: function() {\r | |
382 | var now = new Date().getTime(),\r | |
383 | me = Ext.theme,\r | |
384 | // This function is defined by slicer.js (the framework-independent piece)\r | |
385 | gsm = window && window['generateSlicerManifest'],\r | |
386 | delta;\r | |
387 | \r | |
388 | me.generateStart = me.generateStart || now;\r | |
389 | delta = now - me.generateStart;\r | |
390 | \r | |
391 | if(gsm) {\r | |
392 | gsm();\r | |
393 | } else if(delta < (10 * 1000)){\r | |
394 | // allow the outer script wrapper a chance to inject the capture function\r | |
395 | // but stop trying after 10 seconds\r | |
396 | Ext.defer(Ext.theme.generateSlicerManifest, 100);\r | |
397 | }\r | |
398 | },\r | |
399 | \r | |
400 | /**\r | |
401 | * Sets the `data-slicer` attribute to the JSON-encoded value of the provided data.\r | |
402 | * @private\r | |
403 | */\r | |
404 | setData: function (el, data) {\r | |
405 | if (data) {\r | |
406 | var json = Ext.encode(data);\r | |
407 | if (json !== '{}') {\r | |
408 | el.setAttribute('data-slicer', json);\r | |
409 | }\r | |
410 | }\r | |
411 | },\r | |
412 | \r | |
413 | /**\r | |
414 | * This used to be `loadExtStylesheet`.\r | |
415 | * @private\r | |
416 | */\r | |
417 | loadCss: function (src, callback) {\r | |
418 | var xhr = new XMLHttpRequest();\r | |
419 | \r | |
420 | xhr.open('GET', src);\r | |
421 | \r | |
422 | xhr.onload = function() {\r | |
423 | var css = xhr.responseText,\r | |
424 | head = document.getElementsByTagName('head')[0],\r | |
425 | style = document.createElement('style');\r | |
426 | \r | |
427 | // There's bugginess in the next gradient syntax in WebKit r84622\r | |
428 | // This might be fixed in a later WebKit, but for now we're going to\r | |
429 | // strip it out here since compass generates it.\r | |
430 | //\r | |
431 | // TODO: Upgrade to later WebKit revision\r | |
432 | css = css.replace(/background(-image)?: ?-webkit-linear-gradient(?:.*?);/g, '');\r | |
433 | \r | |
434 | style.type = 'text/css';\r | |
435 | style.innerText = css;\r | |
436 | \r | |
437 | head.appendChild(style);\r | |
438 | callback();\r | |
439 | };\r | |
440 | \r | |
441 | xhr.send(null);\r | |
442 | }\r | |
443 | };\r | |
444 | \r | |
445 | console.log("registering ready listener...");\r | |
446 | Ext.onReady(Ext.theme.run, Ext.theme);\r |