From 7e92918f9ef266e7ce8cb8a122c51882075a5ad5 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 24 May 2012 21:36:03 +0000 Subject: [PATCH] Add support for 'content' attribute, to create namespace for template using something other than its ID --- etemplate/js/et2_widget_template.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/etemplate/js/et2_widget_template.js b/etemplate/js/et2_widget_template.js index 74f2d952b6..d295ac5135 100644 --- a/etemplate/js/et2_widget_template.js +++ b/etemplate/js/et2_widget_template.js @@ -48,7 +48,11 @@ var et2_template = et2_DOMWidget.extend({ "name": "Language", "type": "string", "description": "Language the template is written in" - } + }, + "content": { + "name": "Content index", + "default": et2_no_init + }, }, createNamespace: true, @@ -56,7 +60,12 @@ var et2_template = et2_DOMWidget.extend({ /** * Initializes this template widget as a simple container. */ - init: function() { + init: function(_parent, _attrs) { + // Set this early, so it's available for creating namespace + if(_attrs.content) + { + this.content = _attrs.content; + } this._super.apply(this, arguments); this.div = document.createElement("div"); @@ -102,6 +111,22 @@ var et2_template = et2_DOMWidget.extend({ } }, + /** + * Override parent to support content attribute + */ + checkCreateNamespace: function() { + if(this.content) + { + var old_id = this.id; + this.id = this.content; + this._super.apply(this, arguments); + } + else + { + this._super.apply(this, arguments); + } + }, + getDOMNode: function() { return this.div; }