Last active
December 3, 2020 05:42
-
-
Save rajeshsegu/4030445 to your computer and use it in GitHub Desktop.
Revisions
-
rajeshsegu revised this gist
Feb 22, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,7 +50,7 @@ //Handle loading multiple templates $('script[type="'+Handlebars.Templates.TYPE+'"]') .each(function(handlebar){ Handlebars.Templates.processTemplate(handlebar); -
rajeshsegu revised this gist
Nov 7, 2012 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ //Handlebars Template helper (function(Handlebars){ @@ -86,7 +85,7 @@ }; })(Handlebars); //Basic Handlebars Loader (function(Handlebars, $){ Handlebars.Loader = { @@ -111,6 +110,13 @@ //Process Templates Handlebars.Templates.process(); //Final callback if(args.callback){ args.callback(); } } }) .error(function(response){ -
rajeshsegu renamed this gist
Nov 7, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ //Handlebars Template helper (function(Handlebars){ Handlebars.Templates = { @@ -84,7 +86,7 @@ }; })(Handlebars); //Handlebars Basic Loader (function(Handlebars, $){ Handlebars.Loader = { -
rajeshsegu revised this gist
Nov 7, 2012 . No changes.There are no files selected for viewing
-
rajeshsegu renamed this gist
Nov 7, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rajeshsegu created this gist
Nov 7, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,120 @@ (function(Handlebars){ Handlebars.Templates = { //script type of handle bar template TYPE: "text/x-handlebars-template", //Handlebar identifier attribute NAME: "data-template-name", //Template Store. _store: {}, //Get the template from template store get: function(templateName, context){ var template = this._store[templateName]; if(context){ template = template(context); } return template; }, //Add the template to the template store. add: function(templateName, templateContent){ var template = Handlebars.compile(templateContent); this._store[templateName] = template; return template; }, //Remote the template from the Templates store remove: function(templateName){ this._store[templateName] = null; delete this._store[templateName]; }, //Process the entire DOM for handlebar templates process: function(el){ var found = false; //Handle loading multiple templates $('script[type="'+Handlebars.Templates.TYPE+'"]') .forEach(function(handlebar){ Handlebars.Templates.processTemplate(handlebar); found = true; } ); return found; }, //Process individual handlebar script processTemplate: function(el){ //Access the handlebar template var handlebarTemplate = $(el), template; //Add template to templateStore template = Handlebars.Templates.add( handlebarTemplate.attr(Handlebars.Templates.NAME), handlebarTemplate.text() ); //Cleanup DOM once processed handlebarTemplate.remove(); return template; } }; })(Handlebars); (function(Handlebars, $){ Handlebars.Loader = { load: function(args){ args = args || {}; $.ajax({ url: args.path, async: !args.sync, type: "GET", cache: true }, "html") .success(function(data, status ,response){ if(status == "success"){ data = response.responseText; //Append to make it part of DOM $('body').append(data); //Process Templates Handlebars.Templates.process(); } }) .error(function(response){ alert("Failed to load templates @ " + args.path); }); } } })(window.Handlebars, jQuery);