Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / core / Template.js
diff --git a/source/core/Template.js b/source/core/Template.js
deleted file mode 100644 (file)
index aaf70d1..0000000
+++ /dev/null
@@ -1,242 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
-* @class Ext.Template\r
-* Represents an HTML fragment template. Templates can be precompiled for greater performance.\r
-* For a list of available format functions, see {@link Ext.util.Format}.<br />\r
-* Usage:\r
-<pre><code>\r
-var t = new Ext.Template(\r
-    '&lt;div name="{id}"&gt;',\r
-        '&lt;span class="{cls}"&gt;{name:trim} {value:ellipsis(10)}&lt;/span&gt;',\r
-    '&lt;/div&gt;'\r
-);\r
-t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});\r
-</code></pre>\r
-* @constructor\r
-* @param {String/Array} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")\r
-*/\r
-Ext.Template = function(html){\r
-    var a = arguments;\r
-    if(Ext.isArray(html)){\r
-        html = html.join("");\r
-    }else if(a.length > 1){\r
-        var buf = [];\r
-        for(var i = 0, len = a.length; i < len; i++){\r
-            if(typeof a[i] == 'object'){\r
-                Ext.apply(this, a[i]);\r
-            }else{\r
-                buf[buf.length] = a[i];\r
-            }\r
-        }\r
-        html = buf.join('');\r
-    }\r
-    /**@private*/\r
-    this.html = html;\r
-    if(this.compiled){\r
-        this.compile();\r
-    }\r
-};\r
-Ext.Template.prototype = {\r
-    /**\r
-     * Returns an HTML fragment of this template with the specified values applied.\r
-     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
-     * @return {String} The HTML fragment\r
-     */\r
-    applyTemplate : function(values){\r
-        if(this.compiled){\r
-            return this.compiled(values);\r
-        }\r
-        var useF = this.disableFormats !== true;\r
-        var fm = Ext.util.Format, tpl = this;\r
-        var fn = function(m, name, format, args){\r
-            if(format && useF){\r
-                if(format.substr(0, 5) == "this."){\r
-                    return tpl.call(format.substr(5), values[name], values);\r
-                }else{\r
-                    if(args){\r
-                        // quoted values are required for strings in compiled templates,\r
-                        // but for non compiled we need to strip them\r
-                        // quoted reversed for jsmin\r
-                        var re = /^\s*['"](.*)["']\s*$/;\r
-                        args = args.split(',');\r
-                        for(var i = 0, len = args.length; i < len; i++){\r
-                            args[i] = args[i].replace(re, "$1");\r
-                        }\r
-                        args = [values[name]].concat(args);\r
-                    }else{\r
-                        args = [values[name]];\r
-                    }\r
-                    return fm[format].apply(fm, args);\r
-                }\r
-            }else{\r
-                return values[name] !== undefined ? values[name] : "";\r
-            }\r
-        };\r
-        return this.html.replace(this.re, fn);\r
-    },\r
-\r
-    /**\r
-     * Sets the HTML used as the template and optionally compiles it.\r
-     * @param {String} html\r
-     * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)\r
-     * @return {Ext.Template} this\r
-     */\r
-    set : function(html, compile){\r
-        this.html = html;\r
-        this.compiled = null;\r
-        if(compile){\r
-            this.compile();\r
-        }\r
-        return this;\r
-    },\r
-\r
-    /**\r
-     * True to disable format functions (defaults to false)\r
-     * @type Boolean\r
-     */\r
-    disableFormats : false,\r
-\r
-    /**\r
-    * The regular expression used to match template variables\r
-    * @type RegExp\r
-    * @property\r
-    */\r
-    re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,\r
-\r
-    /**\r
-     * Compiles the template into an internal function, eliminating the RegEx overhead.\r
-     * @return {Ext.Template} this\r
-     */\r
-    compile : function(){\r
-        var fm = Ext.util.Format;\r
-        var useF = this.disableFormats !== true;\r
-        var sep = Ext.isGecko ? "+" : ",";\r
-        var fn = function(m, name, format, args){\r
-            if(format && useF){\r
-                args = args ? ',' + args : "";\r
-                if(format.substr(0, 5) != "this."){\r
-                    format = "fm." + format + '(';\r
-                }else{\r
-                    format = 'this.call("'+ format.substr(5) + '", ';\r
-                    args = ", values";\r
-                }\r
-            }else{\r
-                args= ''; format = "(values['" + name + "'] == undefined ? '' : ";\r
-            }\r
-            return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";\r
-        };\r
-        var body;\r
-        // branched to use + in gecko and [].join() in others\r
-        if(Ext.isGecko){\r
-            body = "this.compiled = function(values){ return '" +\r
-                   this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +\r
-                    "';};";\r
-        }else{\r
-            body = ["this.compiled = function(values){ return ['"];\r
-            body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));\r
-            body.push("'].join('');};");\r
-            body = body.join('');\r
-        }\r
-        eval(body);\r
-        return this;\r
-    },\r
-\r
-    // private function used to call members\r
-    call : function(fnName, value, allValues){\r
-        return this[fnName](value, allValues);\r
-    },\r
-\r
-    /**\r
-     * Applies the supplied values to the template and inserts the new node(s) as the first child of el.\r
-     * @param {Mixed} el The context element\r
-     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
-     * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)\r
-     * @return {HTMLElement/Ext.Element} The new node or Element\r
-     */\r
-    insertFirst: function(el, values, returnElement){\r
-        return this.doInsert('afterBegin', el, values, returnElement);\r
-    },\r
-\r
-    /**\r
-     * Applies the supplied values to the template and inserts the new node(s) before el.\r
-     * @param {Mixed} el The context element\r
-     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
-     * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)\r
-     * @return {HTMLElement/Ext.Element} The new node or Element\r
-     */\r
-    insertBefore: function(el, values, returnElement){\r
-        return this.doInsert('beforeBegin', el, values, returnElement);\r
-    },\r
-\r
-    /**\r
-     * Applies the supplied values to the template and inserts the new node(s) after el.\r
-     * @param {Mixed} el The context element\r
-     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
-     * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)\r
-     * @return {HTMLElement/Ext.Element} The new node or Element\r
-     */\r
-    insertAfter : function(el, values, returnElement){\r
-        return this.doInsert('afterEnd', el, values, returnElement);\r
-    },\r
-\r
-    /**\r
-     * Applies the supplied values to the template and appends the new node(s) to el.\r
-     * @param {Mixed} el The context element\r
-     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
-     * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)\r
-     * @return {HTMLElement/Ext.Element} The new node or Element\r
-     */\r
-    append : function(el, values, returnElement){\r
-        return this.doInsert('beforeEnd', el, values, returnElement);\r
-    },\r
-\r
-    doInsert : function(where, el, values, returnEl){\r
-        el = Ext.getDom(el);\r
-        var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values));\r
-        return returnEl ? Ext.get(newNode, true) : newNode;\r
-    },\r
-\r
-    /**\r
-     * Applies the supplied values to the template and overwrites the content of el with the new node(s).\r
-     * @param {Mixed} el The context element\r
-     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
-     * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)\r
-     * @return {HTMLElement/Ext.Element} The new node or Element\r
-     */\r
-    overwrite : function(el, values, returnElement){\r
-        el = Ext.getDom(el);\r
-        el.innerHTML = this.applyTemplate(values);\r
-        return returnElement ? Ext.get(el.firstChild, true) : el.firstChild;\r
-    }\r
-};\r
-/**\r
- * Alias for {@link #applyTemplate}\r
- * Returns an HTML fragment of this template with the specified values applied.\r
- * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})\r
- * @return {String} The HTML fragment\r
- * @member Ext.Template\r
- * @method apply\r
- */\r
-Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;\r
-\r
-// backwards compat\r
-Ext.DomHelper.Template = Ext.Template;\r
-\r
-/**\r
- * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.\r
- * @param {String/HTMLElement} el A DOM element or its id\r
- * @param {Object} config A configuration object\r
- * @return {Ext.Template} The created template\r
- * @static\r
- */\r
-Ext.Template.from = function(el, config){\r
-    el = Ext.getDom(el);\r
-    return new Ext.Template(el.value || el.innerHTML, config || '');\r
-};
\ No newline at end of file