]>
git.proxmox.com Git - extjs.git/blob - extjs/classic/theme-crisp/sass/example/render.js
2 * This file is generated by Sencha Cmd and should NOT be edited. It will be replaced
6 // This flag is checked by many Components to avoid compatibility warnings when
7 // the code is running under the slicer
14 Ext
.theme
= Ext
.apply(Ext
.theme
|| {}, {
16 * The array of all component manifests. These objects have the following set of
17 * properties recognized by the slicer:
23 * The collection of shortcuts for a given alias (e.g., 'widget.panel'). This is an
24 * object keyed by alias whose values are arrays of shortcut definitions.
29 doRequire : function(xtype
) {
30 if(xtype
.indexOf("widget.") != 0) {
31 xtype
= "widget." + xtype
;
37 * Adds one ore more component entries to the theme manifest. These entries will be
38 * instantiated by the `Ext.theme.render` method when the page is ready.
42 * Ext.theme.addManifest({
43 * xtype: 'widget.menu',
45 * delegate: '.x-menu-item-link',
46 * filename: 'menu-item-active',
52 * cls: 'x-menu-item-active'
59 * @param manifest {Object} An object with type of component, slicing information and
60 * component configuration. If this parameter is an array, each element is treated as
61 * a manifest entry. Otherwise, each argument passed is treated as a manifest entry.
63 * @param manifest.xtype {String} The xtype ('grid') or alias ('widget.grid'). This
64 * is used to specify the type of component to create as well as a potential key to
65 * any `shortcuts` defined for the xtype.
67 * @param manifest.config {Object} The component configuration object. The properties
68 * of this depend on the `xtype` of the component.
70 * @param [manifest.delegate] {String} The DOM query to use to select the element to
71 * slice. The default is to slice the primary element of the component.
73 * @param [manifest.parentCls] An optional CSS class to add to the parent of the
76 * @param [manifest.setup] {Function} An optional function to be called to initialize
78 * @param manifest.setup.component {Ext.Component} The component instance
79 * @param manifest.setup.container {Element} The component's container.
81 * @param [manifest.folder] {String} The folder in to which to produce image slices.
82 * Only applies to Ext JS 4.1 (removed in 4.2).
84 * @param [manifest.filename] {String} The base filename for slices.
85 * Only applies to Ext JS 4.1 (removed in 4.2).
87 * @param [manifest.reverse] {Boolean} True to position the slices for linear gradient
88 * background at then opposite "end" (right or bottom) and apply the stretch to the
89 * area before it (left or top). Only applies to Ext JS 4.1 (removed in 4.2).
91 addManifest: function (manifest
) {
92 var all
= Ext
.theme
._manifest
;
93 var add
= Ext
.isArray(manifest
) ? manifest
: arguments
;
96 Ext
.theme
.doRequire(manifest
.xtype
);
99 for (var i
= 0, n
= add
.length
; i
< n
; ++i
) {
101 Ext
.theme
.doRequire(add
[i
].xtype
);
108 * Adds one or more shortcuts to the rendering process. A `shortcut` is an object that
109 * looks the same as a `manifest` entry. These are combined by copying the properties
110 * from the shortcut over those of the manifest entry. In basic terms:
112 * var config = Ext.apply(Ext.apply({}, manfiest.config), shortcut.config);
113 * var entry = Ext.apply(Ext.apply({}, manfiest), shortcut);
114 * entry.config = config;
116 * This is not exactly the process, but the idea is the same. The difference is that
117 * the `ui` of the manifest entry is used to replace any `"{ui}"` substrings found in
118 * any string properties of the shortcut or its `config` object.
122 * Ext.theme.addShortcuts({
131 * 'widget.bar': [ ... ]
134 addShortcuts: function (shortcuts
) {
135 var all
= Ext
.theme
._shortcuts
;
137 for (var key
in shortcuts
) {
139 var add
= shortcuts
[key
];
140 var xtype
= Ext
.theme
.addWidget(key
);
141 var existing
= all
[xtype
];
143 Ext
.theme
.doRequire(xtype
);
144 for(var i
=0; i
< add
.length
; i
++) {
147 Ext
.theme
.doRequire(config
.xtype
);
152 all
[xtype
] = existing
= [];
155 existing
.push
.apply(existing
, add
);
160 * This method ensures that a given string has the specified prefix (e.g., "widget.").
163 addPrefix: function (prefix
, s
) {
164 if (!s
|| (s
.length
> prefix
.length
&& s
.substring(0,prefix
.length
) === prefix
)) {
171 * This method returns the given string with "widget." added to the front if that is
172 * not already present.
175 addWidget: function (str
) {
176 return Ext
.theme
.addPrefix('widget.', str
);
180 * This method accepts an manifest entry and a shortcut entry and returns the merged
184 applyShortcut: function (manifestEntry
, shortcut
) {
185 var ui
= manifestEntry
.ui
;
186 var config
= Ext
.theme
.copyProps({}, manifestEntry
.config
);
187 var entry
= Ext
.theme
.copyProps({}, manifestEntry
);
189 if (ui
&& !config
.ui
) {
193 var tpl
= { ui
: ui
};
194 Ext
.theme
.copyProps(entry
, shortcut
, tpl
);
195 Ext
.theme
.copyProps(config
, shortcut
.config
, tpl
);
198 entry
.xtype
= Ext
.theme
.addWidget(entry
.xtype
);
199 entry
.config
= config
; // both guys have "config" so smash merged one on now...
204 * This method copies property from a `src` object to a `dest` object and reaplces
205 * `"{foo}"` fragments of any string properties as defined in the `tpl` object.
207 * var obj = Ext.theme.copyProps({}, {
213 * console.log('obj.foo: ' + obj.foo); // logs "Hello-World"
215 * @return {Object} The `dest` object or a new object (if `dest` was null).
218 copyProps: function (dest
, src
, tpl
) {
219 var out
= dest
|| {};
220 var replacements
= [];
227 re
: new RegExp('\\{' + token
+ '\\}', 'g'),
233 for (var key
in src
) {
235 if (tpl
&& typeof val
=== 'string') {
236 for (var i
= 0; i
< replacements
.length
; ++ i
) {
237 val
= val
.replace(replacements
[i
].re
, replacements
[i
].value
);
248 * Renders a component given its manifest and shortcut entries.
251 renderWidget: function (manifestEntry
, shortcut
) {
252 var entry
= Ext
.theme
.applyShortcut(manifestEntry
, shortcut
);
253 var config
= entry
.config
;
254 var widget
= Ext
.create(entry
.xtype
, config
);
255 var ct
= Ext
.fly(document
.body
).createChild({ cls
: 'widget-container' });
257 Ext
.theme
.currentWidget
= widget
;
259 if (widget
.floating
=== true) {
260 widget
.floating
= { shadow
: false };
262 if (widget
.floating
) {
263 widget
.focusOnToFront
= false;
267 entry
.setup
.call(widget
, widget
, ct
);
270 if (widget
.floating
) {
272 ct
.setHeight(widget
.getHeight());
277 if (entry
.delegate
) {
278 el
= el
.down(entry
.delegate
);
281 el
.addCls('x-slicer-target'); // this is what generateSlicerManifest looks for
286 if (config
.parentCls
) {
287 el
.parent().addCls(config
.parentCls
);
290 if (Ext
.theme
.legacy
) {
291 // The 4.1 approach has some interesting extra pieces
297 if (entry
.filename
) {
298 data
.filename
= entry
.filename
;
301 data
.folder
= entry
.folder
;
304 data
.offsets
= entry
.offsets
;
307 Ext
.theme
.setData(el
.dom
, data
);
310 Ext
.theme
.currentWidget
= null;
314 * Renders all of the components that have been added to the manifest.
317 render: function () {
318 console
.log("rendering widgets...")
319 var manifest
= Ext
.theme
._manifest
;
320 var shortcuts
= Ext
.theme
._shortcuts
;
322 for (var k
= 0, n
= manifest
? manifest
.length
: 0; k
< n
; ++k
) {
323 var manifestEntry
= manifest
[k
];
324 var xtype
= Ext
.theme
.addWidget(manifestEntry
.xtype
);
325 var widgetShortcuts
= xtype
? shortcuts
[xtype
] : null;
327 if (xtype
&& manifestEntry
.ui
&& widgetShortcuts
) {
328 for (var i
= 0; i
< widgetShortcuts
.length
; i
++) {
329 Ext
.theme
.renderWidget(manifestEntry
, widgetShortcuts
[i
]);
332 Ext
.theme
.renderWidget(manifestEntry
);
338 * Renders all components (see `render`) and notifies the Slicer that things are ready.
342 var extjsVer
= Ext
.versions
.extjs
;
345 if (Ext
.layout
.Context
) {
346 Ext
.override(Ext
.layout
.Context
, {
348 var ok
= this.callParent(),
349 widget
= Ext
.theme
.currentWidget
;
351 Ext
.Error
.raise("Layout run failed: " + widget
.id
);
358 console
.log("loading widget definitions...");
360 // Previous to Ext JS 4.2, themes and their manifests where defined differently.
361 // So pass this along if we are hosting a pre-4.2 theme.
363 if (extjsVer
&& extjsVer
.isLessThan(new Ext
.Version("4.2"))) {
364 globalData
.format
= "1.0"; // tell the Slicer tool
365 Ext
.theme
.legacy
= true; // not for our own data collection
367 // Check for the Cmd3.0/ExtJS4.1 variables:
369 if (Ext
.manifest
&& Ext
.manifest
.widgets
) {
370 Ext
.theme
.addManifest(Ext
.manifest
.widgets
);
373 Ext
.theme
.addShortcuts(Ext
.shortcuts
);
375 if (Ext
.userManifest
&& Ext
.userManifest
.widgets
) {
376 Ext
.theme
.addManifest(Ext
.userManifest
.widgets
);
380 Ext
.theme
.setData(document
.body
, globalData
);
382 Ext
.theme
.generateSlicerManifest();
385 generateSlicerManifest: function() {
386 var now
= new Date().getTime(),
388 // This function is defined by slicer.js (the framework-independent piece)
389 gsm
= window
&& window
['generateSlicerManifest'],
392 me
.generateStart
= me
.generateStart
|| now
;
393 delta
= now
- me
.generateStart
;
397 } else if(delta
< (10 * 1000)){
398 // allow the outer script wrapper a chance to inject the capture function
399 // but stop trying after 10 seconds
400 Ext
.defer(Ext
.theme
.generateSlicerManifest
, 100);
405 * Sets the `data-slicer` attribute to the JSON-encoded value of the provided data.
408 setData: function (el
, data
) {
410 var json
= Ext
.encode(data
);
412 el
.setAttribute('data-slicer', json
);
418 * This used to be `loadExtStylesheet`.
421 loadCss: function (src
, callback
) {
422 var xhr
= new XMLHttpRequest();
424 xhr
.open('GET', src
);
426 xhr
.onload = function() {
427 var css
= xhr
.responseText
,
428 head
= document
.getElementsByTagName('head')[0],
429 style
= document
.createElement('style');
431 // There's bugginess in the next gradient syntax in WebKit r84622
432 // This might be fixed in a later WebKit, but for now we're going to
433 // strip it out here since compass generates it.
435 // TODO: Upgrade to later WebKit revision
436 css
= css
.replace(/background(-image)?: ?-webkit-linear-gradient(?:.*?);/g, '');
438 style
.type
= 'text/css';
439 style
.innerText
= css
;
441 head
.appendChild(style
);
449 console
.log("registering ready listener...");
450 Ext
.onReady(Ext
.theme
.run
, Ext
.theme
);