4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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-ComponentLoader'>/**
19 </span> * @class Ext.ComponentLoader
20 * @extends Ext.ElementLoader
22 * This class is used to load content via Ajax into a {@link Ext.Component}. In general
23 * this class will not be instanced directly, rather a loader configuration will be passed to the
24 * constructor of the {@link Ext.Component}.
27 * By default, the content loaded will be processed as raw html. The response text
28 * from the request is taken and added to the component. This can be used in
29 * conjunction with the {@link #scripts} option to execute any inline scripts in
30 * the resulting content. Using this renderer has the same effect as passing the
31 * {@link Ext.Component#html} configuration option.
34 * This renderer allows content to be added by using JSON data and a {@link Ext.XTemplate}.
35 * The content received from the response is passed to the {@link Ext.Component#update} method.
36 * This content is run through the attached {@link Ext.Component#tpl} and the data is added to
37 * the Component. Using this renderer has the same effect as using the {@link Ext.Component#data}
38 * configuration in conjunction with a {@link Ext.Component#tpl}.
40 * ## Component Renderer
41 * This renderer can only be used with a {@link Ext.container.Container} and subclasses. It allows for
42 * Components to be loaded remotely into a Container. The response is expected to be a single/series of
43 * {@link Ext.Component} configuration objects. When the response is received, the data is decoded
44 * and then passed to {@link Ext.container.Container#add}. Using this renderer has the same effect as specifying
45 * the {@link Ext.container.Container#items} configuration on a Container.
48 * A custom function can be passed to handle any other special case, see the {@link #renderer} option.
52 * tpl: '{firstName} - {lastName}',
62 Ext.define('Ext.ComponentLoader', {
64 /* Begin Definitions */
66 extend: 'Ext.ElementLoader',
70 Data: function(loader, response, active){
73 loader.getTarget().update(Ext.decode(response.responseText));
80 Component: function(loader, response, active){
82 target = loader.getTarget(),
86 if (!target.isContainer) {
89 msg: 'Components can only be loaded into a container'
95 items = Ext.decode(response.responseText);
101 if (active.removeAll) {
111 /* End Definitions */
113 <span id='Ext-ComponentLoader-cfg-target'> /**
114 </span> * @cfg {Ext.Component/String} target The target {@link Ext.Component} for the loader.
115 * If a string is passed it will be looked up via the id.
119 <span id='Ext-ComponentLoader-cfg-loadMask'> /**
120 </span> * @cfg {Boolean/Object} loadMask True or a {@link Ext.LoadMask} configuration to enable masking during loading.
124 <span id='Ext-ComponentLoader-cfg-scripts'> /**
125 </span> * @cfg {Boolean} scripts True to parse any inline script tags in the response. This only used when using the html
129 <span id='Ext-ComponentLoader-cfg-renderer'> /**
130 </span> * @cfg {String/Function} renderer
132 The type of content that is to be loaded into, which can be one of 3 types:
134 + **html** : Loads raw html content, see {@link Ext.Component#html}
135 + **data** : Loads raw html content, see {@link Ext.Component#data}
136 + **component** : Loads child {Ext.Component} instances. This option is only valid when used with a Container.
138 Alternatively, you can pass a function which is called with the following parameters.
140 + loader - Loader instance
141 + response - The server response
142 + active - The active request
144 The function must return false is loading is not successful. Below is a sample of using a custom renderer:
149 renderer: function(loader, response, active) {
150 var text = response.responseText;
151 loader.getTarget().update('The response is ' + text);
159 <span id='Ext-ComponentLoader-method-setTarget'> /**
160 </span> * Set a {Ext.Component} as the target of this loader. Note that if the target is changed,
161 * any active requests will be aborted.
162 * @param {String/Ext.Component} target The component to be the target of this loader. If a string is passed
163 * it will be looked up via its id.
165 setTarget: function(target){
168 if (Ext.isString(target)) {
169 target = Ext.getCmp(target);
172 if (me.target && me.target != target) {
179 removeMask: function(){
180 this.target.setLoading(false);
183 <span id='Ext-ComponentLoader-method-addMask'> /**
184 </span> * Add the mask on the target
186 * @param {Boolean/Object} mask The mask configuration
188 addMask: function(mask){
189 this.target.setLoading(mask);
192 <span id='Ext-ComponentLoader-method-setOptions'> /**
193 </span> * Get the target of this loader.
194 * @return {Ext.Component} target The target, null if none exists.
197 setOptions: function(active, options){
198 active.removeAll = Ext.isDefined(options.removeAll) ? options.removeAll : this.removeAll;
201 <span id='Ext-ComponentLoader-method-getRenderer'> /**
202 </span> * Gets the renderer to use
204 * @param {String/Function} renderer The renderer to use
205 * @return {Function} A rendering function to use.
207 getRenderer: function(renderer){
208 if (Ext.isFunction(renderer)) {
212 var renderers = this.statics().Renderer;
215 return renderers.Component;
217 return renderers.Data;
219 return Ext.ElementLoader.Renderer.Html;