4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-ElementLoader'>/**
19 </span> * @class Ext.ElementLoader
20 * A class used to load remote content to an Element. Sample usage:
21 * <pre><code>
29 * </code></pre>
31 * In general this class will not be instanced directly, rather the {@link Ext.core.Element#load} method
35 Ext.define('Ext.ElementLoader', {
37 /* Begin Definitions */
40 observable: 'Ext.util.Observable'
44 'Ext.data.Connection',
50 Html: function(loader, response, active){
51 loader.getTarget().update(response.responseText, active.scripts === true);
59 <span id='Ext-ElementLoader-cfg-url'> /**
60 </span> * @cfg {String} url The url to retrieve the content from. Defaults to <tt>null</tt>.
64 <span id='Ext-ElementLoader-cfg-params'> /**
65 </span> * @cfg {Object} params Any params to be attached to the Ajax request. These parameters will
66 * be overridden by any params in the load options. Defaults to <tt>null</tt>.
70 <span id='Ext-ElementLoader-cfg-baseParams'> /**
71 </span> * @cfg {Object} baseParams Params that will be attached to every request. These parameters
72 * will not be overridden by any params in the load options. Defaults to <tt>null</tt>.
76 <span id='Ext-ElementLoader-cfg-autoLoad'> /**
77 </span> * @cfg {Boolean/Object} autoLoad True to have the loader make a request as soon as it is created. Defaults to <tt>false</tt>.
78 * This argument can also be a set of options that will be passed to {@link #load} is called.
82 <span id='Ext-ElementLoader-cfg-target'> /**
83 </span> * @cfg {Mixed} target The target element for the loader. It can be the DOM element, the id or an Ext.Element.
87 <span id='Ext-ElementLoader-cfg-loadMask'> /**
88 </span> * @cfg {Mixed} loadMask True or a string to show when the element is loading.
92 <span id='Ext-ElementLoader-cfg-ajaxOptions'> /**
93 </span> * @cfg {Object} ajaxOptions Any additional options to be passed to the request, for example timeout or headers. Defaults to <tt>null</tt>.
97 <span id='Ext-ElementLoader-cfg-scripts'> /**
98 </span> * @cfg {Boolean} scripts True to parse any inline script tags in the response.
102 <span id='Ext-ElementLoader-cfg-success'> /**
103 </span> * @cfg {Function} success A function to be called when a load request is successful.
106 <span id='Ext-ElementLoader-cfg-failure'> /**
107 </span> * @cfg {Function} failure A function to be called when a load request fails.
110 <span id='Ext-ElementLoader-cfg-scope'> /**
111 </span> * @cfg {Object} scope The scope to execute the {@link #success} and {@link #failure} functions in.
114 <span id='Ext-ElementLoader-cfg-renderer'> /**
115 </span> * @cfg {Function} renderer A custom function to render the content to the element. The passed parameters
118 * <li>The loader</li>
119 * <li>The response</li>
120 * <li>The active request</li>
126 constructor: function(config) {
130 config = config || {};
131 Ext.apply(me, config);
132 me.setTarget(me.target);
134 <span id='Ext-ElementLoader-event-beforeload'> /**
135 </span> * @event beforeload
136 * Fires before a load request is made to the server.
137 * Returning false from an event listener can prevent the load
139 * @param {Ext.ElementLoader} this
140 * @param {Object} options The options passed to the request
144 <span id='Ext-ElementLoader-event-exception'> /**
145 </span> * @event exception
146 * Fires after an unsuccessful load.
147 * @param {Ext.ElementLoader} this
148 * @param {Object} response The response from the server
149 * @param {Object} options The options passed to the request
153 <span id='Ext-ElementLoader-event-exception'> /**
154 </span> * @event exception
155 * Fires after a successful load.
156 * @param {Ext.ElementLoader} this
157 * @param {Object} response The response from the server
158 * @param {Object} options The options passed to the request
163 // don't pass config because we have already applied it.
164 me.mixins.observable.constructor.call(me);
167 autoLoad = me.autoLoad;
168 if (autoLoad === true) {
175 <span id='Ext-ElementLoader-method-setTarget'> /**
176 </span> * Set an {Ext.Element} as the target of this loader. Note that if the target is changed,
177 * any active requests will be aborted.
178 * @param {Mixed} target The element
180 setTarget: function(target){
182 target = Ext.get(target);
183 if (me.target && me.target != target) {
189 <span id='Ext-ElementLoader-method-getTarget'> /**
190 </span> * Get the target of this loader.
191 * @return {Ext.Component} target The target, null if none exists.
193 getTarget: function(){
194 return this.target || null;
197 <span id='Ext-ElementLoader-method-abort'> /**
198 </span> * Aborts the active load request
201 var active = this.active;
202 if (active !== undefined) {
203 Ext.Ajax.abort(active.request);
211 <span id='Ext-ElementLoader-method-removeMask'> /**
212 </span> * Remove the mask on the target
215 removeMask: function(){
216 this.target.unmask();
219 <span id='Ext-ElementLoader-method-addMask'> /**
220 </span> * Add the mask on the target
222 * @param {Mixed} mask The mask configuration
224 addMask: function(mask){
225 this.target.mask(mask === true ? null : mask);
228 <span id='Ext-ElementLoader-method-load'> /**
229 </span> * Load new data from the server.
230 * @param {Object} options The options for the request. They can be any configuration option that can be specified for
231 * the class, with the exception of the target option. Note that any options passed to the method will override any
234 load: function(options) {
237 Ext.Error.raise('A valid target is required when loading content');
241 options = Ext.apply({}, options);
245 mask = Ext.isDefined(options.loadMask) ? options.loadMask : me.loadMask,
246 params = Ext.apply({}, options.params),
247 ajaxOptions = Ext.apply({}, options.ajaxOptions),
248 callback = options.callback || me.callback,
249 scope = options.scope || me.scope || me,
252 Ext.applyIf(ajaxOptions, me.ajaxOptions);
253 Ext.applyIf(options, ajaxOptions);
255 Ext.applyIf(params, me.params);
256 Ext.apply(params, me.baseParams);
258 Ext.applyIf(options, {
264 Ext.Error.raise('You must specify the URL from which content should be loaded');
271 callback: me.onComplete
274 if (me.fireEvent('beforeload', me, options) === false) {
282 request = Ext.Ajax.request(options);
289 success: options.success || me.success,
290 failure: options.failure || me.failure,
291 renderer: options.renderer || me.renderer,
292 scripts: Ext.isDefined(options.scripts) ? options.scripts : me.scripts
294 me.setOptions(me.active, options);
297 <span id='Ext-ElementLoader-property-setOptions'> /**
298 </span> * Set any additional options on the active request
300 * @param {Object} active The active request
301 * @param {Object} options The initial options
303 setOptions: Ext.emptyFn,
305 <span id='Ext-ElementLoader-method-onComplete'> /**
306 </span> * Parse the response after the request completes
308 * @param {Object} options Ajax options
309 * @param {Boolean} success Success status of the request
310 * @param {Object} response The response object
312 onComplete: function(options, success, response) {
315 scope = active.scope,
316 renderer = me.getRenderer(active.renderer);
320 success = renderer.call(me, me, response, active);
324 Ext.callback(active.success, scope, [me, response, options]);
325 me.fireEvent('load', me, response, options);
327 Ext.callback(active.failure, scope, [me, response, options]);
328 me.fireEvent('exception', me, response, options);
330 Ext.callback(active.callback, scope, [me, success, response, options]);
339 <span id='Ext-ElementLoader-method-getRenderer'> /**
340 </span> * Gets the renderer to use
342 * @param {String/Function} renderer The renderer to use
343 * @return {Function} A rendering function to use.
345 getRenderer: function(renderer){
346 if (Ext.isFunction(renderer)) {
349 return this.statics().Renderer.Html;
352 <span id='Ext-ElementLoader-method-startAutoRefresh'> /**
353 </span> * Automatically refreshes the content over a specified period.
354 * @param {Number} interval The interval to refresh in ms.
355 * @param {Object} options (optional) The options to pass to the load method. See {@link #load}
357 startAutoRefresh: function(interval, options){
359 me.stopAutoRefresh();
360 me.autoRefresh = setInterval(function(){
365 <span id='Ext-ElementLoader-method-stopAutoRefresh'> /**
366 </span> * Clears any auto refresh. See {@link #startAutoRefresh}.
368 stopAutoRefresh: function(){
369 clearInterval(this.autoRefresh);
370 delete this.autoRefresh;
373 <span id='Ext-ElementLoader-method-isAutoRefreshing'> /**
374 </span> * Checks whether the loader is automatically refreshing. See {@link #startAutoRefresh}.
375 * @return {Boolean} True if the loader is automatically refreshing
377 isAutoRefreshing: function(){
378 return Ext.isDefined(this.autoRefresh);
381 <span id='Ext-ElementLoader-method-destroy'> /**
382 </span> * Destroys the loader. Any active requests will be aborted.
386 me.stopAutoRefresh();