@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines (2 loc) • 3.46 kB
JavaScript
!function(e){"function"==typeof define&&define.amd?define(["kendo.core.min"],e):e()}((function(){!function(e){function t(){this.node=null}function n(){}t.prototype={remove:function(){this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.attr={}},attr:{},text:function(){return""}},n.prototype={nodeName:"#null",attr:{style:{}},children:[],remove:function(){}};var o=new n;function r(e,t,n){this.nodeName=e,this.attr=t||{},this.children=n||[]}function i(e,t){this.nodeValue=String(e),this.force=t}function s(e,t){this.html=e,this.force=t}r.prototype=new t,r.prototype.appendTo=function(e){for(var t="string"==typeof this.nodeName?document.createElement(this.nodeName):this.nodeName,n=this.children,r=0;r<n.length;r++)n[r].render(t,o);return e.appendChild(t),t},r.prototype.render=function(e,t){var n;if(t.nodeName!==this.nodeName)t.remove(),n=this.appendTo(e);else{var r;n=t.node;var i=this.children,s=i.length,d=t.children,h=d.length;if(Math.abs(h-s)>2)return void this.render({appendChild:function(n){e.replaceChild(n,t.node)}},o);for(r=0;r<s;r++)i[r].render(n,d[r]||o);for(r=s;r<h;r++)d[r].remove()}this.node=n,this.syncAttributes(t.attr),this.removeAttributes(t.attr)},r.prototype.syncAttributes=function(e){var t=this.attr;for(var n in t){var o=t[n],r=e[n];"style"===n?this.setStyle(o,r):o!==r&&this.setAttribute(n,o,r)}},r.prototype.setStyle=function(e,t){var n,o=this.node;if(t)for(n in e)e[n]!==t[n]&&(o.style[n]=e[n]);else for(n in e)o.style[n]=e[n]},r.prototype.removeStyle=function(e){var t=this.attr.style||{},n=this.node;for(var o in e)void 0===t[o]&&(n.style[o]="")},r.prototype.removeAttributes=function(e){var t=this.attr;for(var n in e)"style"===n?this.removeStyle(e.style):void 0===t[n]&&this.removeAttribute(n)},r.prototype.removeAttribute=function(e){var t=this.node;"style"===e?t.style.cssText="":"className"===e?t.className="":t.removeAttribute(e)},r.prototype.setAttribute=function(e,t){var n=this.node;void 0!==n[e]?n[e]=t:n.setAttribute(e,t)},r.prototype.text=function(){for(var e="",t=0;t<this.children.length;++t)e+=this.children[t].text();return e},i.prototype=new t,i.prototype.nodeName="#text",i.prototype.render=function(e,t){var n;t.nodeName!==this.nodeName||this.force?(t.remove(),n=document.createTextNode(this.nodeValue),e.appendChild(n)):(n=t.node,this.nodeValue!==t.nodeValue&&n.parentNode&&(n.nodeValue=this.nodeValue)),this.node=n},i.prototype.text=function(){return this.nodeValue},s.prototype={nodeName:"#html",attr:{},remove:function(){for(var e=0;e<this.nodes.length;e++){var t=this.nodes[e];t.parentNode&&t.parentNode.removeChild(t)}},render:function(e,t){if(t.nodeName!==this.nodeName||t.html!==this.html||this.force){t.remove();var n=e.lastChild;!function(e,t){d.innerHTML=t;for(;d.firstChild;)e.appendChild(d.firstChild)}(e,this.html),this.nodes=[];for(var o=n?n.nextSibling:e.firstChild;o;o=o.nextSibling)this.nodes.push(o)}else this.nodes=t.nodes.slice(0)}};var d=document.createElement("div");function h(e,t){return new s(e,t)}function a(e,t,n){return new r(e,t,n)}function l(e,t){return new i(e,t)}function u(e){this.root=e,this.children=[]}u.prototype={html:h,element:a,text:l,render:function(e){var t,n,r=this.children;for(t=0,n=e.length;t<n;t++){var i=r[t];i?i.node&&i.node.parentNode||(i.remove(),i=o):i=o,e[t].render(this.root,i)}for(t=n;t<r.length;t++)r[t].remove();this.children=e}},e.dom={html:h,text:l,element:a,Tree:u,Node:t}}(window.kendo)}));
//# sourceMappingURL=kendo.dom.min.js.map