editor1.js
2 years ago
handlebars.baldrick2.js
8 years ago
handlebars2.js
8 years ago
jquery.baldrick3.js
8 years ago
panel.js
8 years ago
scripts-pod_reference.js
2 years ago
scripts-view_template.js
8 years ago
handlebars.baldrick2.js
49 lines
| 1 | /* Baldrick handlebars.js templating plugin */ |
| 2 | (function ( $ ) { |
| 3 | var compiledTemplates = {}; |
| 4 | $.fn.baldrick.registerhelper( 'handlebars', { |
| 5 | bind : function ( triggers, defaults ) { |
| 6 | var templates = triggers.filter( "[data-template-url]" ); |
| 7 | if ( templates.length ) { |
| 8 | templates.each( function () { |
| 9 | var trigger = $( this ); |
| 10 | if ( typeof compiledTemplates[trigger.data( 'templateUrl' )] === 'undefined' ) { |
| 11 | compiledTemplates[trigger.data( 'templateUrl' )] = true; |
| 12 | $.get( trigger.data( 'templateUrl' ), function ( data ) { |
| 13 | compiledTemplates[trigger.data( 'templateUrl' )] = Handlebars.compile( data ); |
| 14 | } ); |
| 15 | } |
| 16 | } ); |
| 17 | } |
| 18 | |
| 19 | }, request_params : function ( request, defaults, params ) { |
| 20 | if ( (params.trigger.data( 'templateUrl' ) || params.trigger.data( 'template' )) && typeof Handlebars === 'object' ) { |
| 21 | request.dataType = 'json'; |
| 22 | return request; |
| 23 | } |
| 24 | }, filter : function ( opts, defaults ) { |
| 25 | |
| 26 | if ( opts.params.trigger.data( 'templateUrl' ) ) { |
| 27 | if ( typeof compiledTemplates[opts.params.trigger.data( 'templateUrl' )] === 'function' ) { |
| 28 | opts.data = compiledTemplates[opts.params.trigger.data( 'templateUrl' )]( opts.data ); |
| 29 | } |
| 30 | } |
| 31 | else { |
| 32 | if ( opts.params.trigger.data( 'template' ) ) { |
| 33 | if ( typeof compiledTemplates[opts.params.trigger.data( 'template' )] === 'function' ) { |
| 34 | opts.data = compiledTemplates[opts.params.trigger.data( 'template' )]( opts.data ); |
| 35 | } |
| 36 | else { |
| 37 | if ( $( opts.params.trigger.data( 'template' ) ) ) { |
| 38 | compiledTemplates[opts.params.trigger.data( 'template' )] = Handlebars.compile( $( opts.params.trigger.data( 'template' ) ).html() ); |
| 39 | opts.data = compiledTemplates[opts.params.trigger.data( 'template' )]( opts.data ); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return opts; |
| 46 | } |
| 47 | } ); |
| 48 | |
| 49 | })( jQuery ); |