Merge pull request #1369 from totten/master-api-reload
[civicrm-core.git] / js / jquery / jquery.crmtemplate.js
CommitLineData
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
e1f05567 5 * assign (to be able to alter the data)
6a488035
TO
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( {
e1f05567 14 'method': 'html',
6a488035
TO
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);
e1f05567 23 //mustacheTpl.trigger ('render',data);
6a488035
TO
24 });
25 };
26})( jQuery );
27