Re:templates.js

From disqus.com, 1 Month ago, written in JavaScript, viewed 3 times. This paste is a reply to Re: modals.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/fe8ade34 Embed
Download Paste or View Raw
  1. var template = (function () {
  2.     var that = {
  3.         loadById: function (id, config) {
  4.             return that.loadBySelector('script[data-template-name="' + id + '"]', config);
  5.         },
  6.         loadBySelector: function (selector, config) {
  7.             var $templateContainer = $(selector).first();
  8.             return that.loadString($templateContainer.html(), config);
  9.         },
  10.         loadString: function (templateString, config) {
  11.             var templateContext = _.extend({}, context, context.auth, config || {});
  12.             return _.template(templateString, {data: templateContext});
  13.         }
  14.     };
  15.     return that;
  16. }());
  17.  
  18. /*
  19. Renders either a jquery template or underscore template in the position in the document where it is declared, resolving the need for code
  20. glueing the thing to it's location.
  21. */
  22. $('.js-inline-template').each(function () {
  23.     var $this = $(this);
  24.     var built;
  25.     if ($this.attr('type') === 'text/x-jquery-tmpl') {
  26.         // JQuery template engine, variables referenceable directly
  27.         built = $this.tmpl($.extend({}, context, context.auth));
  28.     } else if ($this.attr('type') === 'text/x-underscore-template') {
  29.         // Underscore template engine, variables referenceable via data
  30.         built = template.loadString($this.html());
  31.     }
  32.     if (built) {
  33.         $this.replaceWith(built);
  34.     }
  35. });
  36. // https://a.disquscdn.com/js/src/templates.js

Replies to Re:templates.js rss

Title Name Language When
disqus.ui.config disqus.com javascript 1 Month ago.

Reply to "Re:templates.js"

Here you can reply to the paste above