forked from malsup/cycle2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.cycle2.tmpl.js
40 lines (36 loc) · 1.19 KB
/
jquery.cycle2.tmpl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*! tmpl plugin for Cycle2; version: 20121227 */
(function($) {
"use strict";
$.extend($.fn.cycle.defaults, {
tmplRegex: '{{((.)?.*?)}}'
});
$.extend($.fn.cycle.API, {
tmpl: function( str, opts /*, ... */) {
var regex = new RegExp( opts.tmplRegex || $.fn.cycle.defaults.tmplRegex, 'g' );
var args = $.makeArray( arguments );
args.shift();
return str.replace(regex, function(_, str) {
var i, j, obj, prop, names = str.split('.');
for (i=0; i < args.length; i++) {
obj = args[i];
if ( ! obj )
continue;
if (names.length > 1) {
prop = obj;
for (j=0; j < names.length; j++) {
obj = prop;
prop = prop[ names[j] ] || str;
}
} else {
prop = obj[str];
}
if ($.isFunction(prop))
return prop.apply(obj, args);
if (prop !== undefined && prop !== null && prop != str)
return prop;
}
return str;
});
}
});
})(jQuery);