-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.temple.min.js
3 lines (3 loc) · 1.49 KB
/
jquery.temple.min.js
1
2
3
(function(){"undefined"!==typeof $&&($.fn.templeLeaf=function(c,b,g){var d=this;switch(typeof c){case "string":case "number":var e=d,f=d,e=b?e.filter('[data-templ-html~="'+b+'"]'):e.filter("[data-templ-html]");if(e.length){e.empty().html(c);g&&e.children().temple(g);break}b&&(f=f.filter('[data-templ~="'+b+'"]'));f.each(function(b,a){switch(a.nodeName){case "INPUT":case "TEXTAREA":$(a).val(c);break;case "OPTGROUP":$(a).attr("label",c);break;default:$(a).text(c)}});break;case "object":case "function":if(null===
c)d.filter('[data-templ~="'+b+'"]').remove();else{var g=c.value,a=c.attr;"+"==a.charAt(0)&&(a=a.substr(1),g=function(b,h){"undefined"==typeof h&&(h=d.attr(a)||"");return h+" "+c.value});"-"==a.charAt(0)&&(a=a.substr(1),g=function(b,h){"undefined"==typeof h&&(h=d.attr(a)||"");return h.replace(c.value,"")});d.filter('[data-templ~="'+b+'"]').attr(a,g)}}return d},$.fn.temple=function(c,b){var g=this.filter("[data-templ], [data-templ-html]").add(this.find("[data-templ], [data-templ-html]")),d;for(d in c){var e=
c[d];if($.isArray(e)){var f=g.filter(['[data-templ~="'+d+'"]','[data-templ-html~="'+d+'"]'].join());if(f.length){if("undefined"!==typeof b)"undefined"==typeof b.jquery&&(b=$(b));else var a=f.data("temple-stencil"),b=a&&a.length?a:f.children().eq(0);b.length&&(b=b.clone(),f.empty(),f.data("temple-stencil",b.clone()),$.each(e,function(a,c){var d=b.clone().show();"string"===typeof c&&d.templeLeaf(c);d.temple(c);f.append(d)}))}}else a=$.extend({},c),delete a[d],g.templeLeaf(e,d,a)}return this})})();