forked from BorisMoore/jquery-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.tmplPlus.min.js
11 lines (11 loc) · 2.24 KB
/
jquery.tmplPlus.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
* tmplPlus.js: for jQuery Templates Plugin 1.0.0pre
* Additional templating features or support for more advanced/less common scenarios.
* Requires jquery.tmpl.js
* http://github.com/jquery/jquery-tmpl
*
* Copyright 2011, Software Freedom Conservancy, Inc.
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory)}else if(typeof exports==="object"){factory(require("jquery"))}else{factory(jQuery)}})(function(jQuery){var oldComplete=jQuery.tmpl.complete,oldManip=jQuery.fn.domManip;jQuery.tmpl.complete=function(tmplItems){var tmplItem;oldComplete(tmplItems);for(tmplItem in tmplItems){tmplItem=tmplItems[tmplItem];if(tmplItem.addedTmplItems&&jQuery.inArray(tmplItem,tmplItem.addedTmplItems)===-1){tmplItem.addedTmplItems.push(tmplItem)}}for(tmplItem in tmplItems){tmplItem=tmplItems[tmplItem];if(tmplItem.rendered){tmplItem.rendered(tmplItem)}}};jQuery.extend({tmplCmd:function(command,data,tmplItems){var retTmplItems=[],before;function find(data,tmplItems){var found=[],tmplItem,ti,tl=tmplItems.length,dataItem,di=0,dl=data.length;for(;di<dl;){dataItem=data[di++];for(ti=0;ti<tl;){tmplItem=tmplItems[ti++];if(tmplItem.data===dataItem){found.push(tmplItem)}}}return found}data=jQuery.isArray(data)?data:[data];switch(command){case"find":return find(data,tmplItems);case"replace":data.reverse()}jQuery.each(tmplItems?find(data,tmplItems):data,function(i,tmplItem){coll=tmplItem.nodes;switch(command){case"update":tmplItem.update();break;case"remove":jQuery(coll).remove();if(tmplItems){tmplItems.splice(jQuery.inArray(tmplItem,tmplItems),1)}break;case"replace":before=before?jQuery(coll).insertBefore(before)[0]:jQuery(coll).appendTo(coll[0].parentNode)[0];retTmplItems.unshift(tmplItem)}});return retTmplItems}});jQuery.fn.extend({domManip:function(args,table,callback,options){var data=args[1],tmpl=args[0],dmArgs;if(args.length>=2&&typeof data==="object"&&!data.nodeType&&!(data instanceof jQuery)){dmArgs=jQuery.makeArray(arguments);dmArgs[0]=[jQuery.tmpl(jQuery.template(tmpl),data,args[2],args[3])];dmArgs[2]=function(fragClone){jQuery.tmpl.afterManip(this,fragClone,callback)};return oldManip.apply(this,dmArgs)}return oldManip.apply(this,arguments)}})});