Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | (function( $ ){ |
2 | ||
3 | /* applies the tpl (a selector of a template) to the data and puts it as the html of the object | |
4 | * it triggers two events | |
5 | * assign (to be able to alter the data) | |
6 | * render (after the html has been added to the dom) to allow jquery event initialisations | |
7 | * options.method = html (or after or before or any html injection jquery method | |
8 | * | |
9 | */ | |
10 | ||
11 | $.fn.crmTemplate = function(tpl,data,options) { | |
12 | ||
13 | var settings = $.extend( { | |
14 | 'method': 'html', | |
15 | }, options); | |
16 | ||
17 | var mustacheTpl = $(tpl); | |
18 | mustacheTpl.trigger ('assign',data); | |
19 | ||
20 | return this.each(function() { | |
21 | //$(this).html($.mustache(mustacheTpl.html(),data)).trigger('render',data); | |
22 | $(this)[settings.method]($.mustache(mustacheTpl.html(),data)).trigger('render',data); | |
23 | //mustacheTpl.trigger ('render',data); | |
24 | ||
25 | }); | |
26 | }; | |
27 | })( jQuery ); | |
28 |