can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r21829: LJSUP-11969: Add an api to insert transl...

Committer: dpetrov
LJSUP-11969: Add an api to insert translated template into page
U   trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-04-27 11:41:15 UTC (rev 21828)
+++ trunk/htdocs/js/basic.js	2012-04-27 12:30:20 UTC (rev 21829)
@@ -311,7 +311,6 @@
 
 LJ.DOM = LJ.DOM || {};
 
-
 /**
  * Inject stylesheet into page.
  *
@@ -332,7 +331,53 @@
 	//console.log(fileName + ' injected from ' + w.location.href);
 };
 
+LJ.UI = LJ.UI || {};
+LJ.UI._templates = {};
 
+LJ.UI.registerTemplate = function(name, id, type) {
+	var node = jQuery('#' + id),
+		template;
+
+	type = type || 'JQuery';
+
+	if (node.length > 0) {
+		template = node.text();
+	} else {
+		template = id;
+	}
+
+	LJ.UI._templates[name] = {
+		type: type
+	}
+
+	var tmplObject = LJ.UI._templates[name];
+
+	switch(type) {
+		case 'JQuery':
+			jQuery.template(name, template);
+			break;
+	}
+
+};
+
+LJ.UI.template = function(name, data) {
+	var tmplObj = LJ.UI._templates[name],
+		html;
+
+	if (!tmplObj) {
+		LJ.console.log('Warn: template ', name, ' was called but is not defined yet.'); 
+		return jQuery();
+	}
+
+	switch (tmplObj.type) {
+		default:
+			html = jQuery.tmpl(name, data);
+	}
+
+	return html;
+};
+
+
 /* object extensions */
 if (!Object.extend)
 	Object.extend = function (d, s){

Tags: can3p, dpetrov, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments