/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:28
*/
KISSY.add("editor/core/dom",function(l,r,o){function s(a,b){var c=a[b?"next":"prev"](j,1);if(c&&c[0].nodeType==e.ELEMENT_NODE){for(var d=[];c.attr("_ke_bookmark")||c._4e_isEmptyInlineRemovable(j);)if(d.push(c),c=b?c.next(j,1):c.prev(j,1),!c)return;if(a._4e_isIdentical(c,j)){for(var h=new p(b?a[0].lastChild:a[0].firstChild);d.length;)d.shift()._4e_move(a,!b,j);c._4e_moveChildren(a,!b,j);c.remove();h[0]&&h[0].nodeType==e.ELEMENT_NODE&&h._4e_mergeSiblings()}}}var j=j,q=r.XHTML_DTD,e=l.DOM,m=l.UA,p=l.Node,
t={a:1,abbr:1,acronym:1,address:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,s:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,"var":1};r.POSITION={POSITION_IDENTICAL:0,POSITION_DISCONNECTED:1,POSITION_FOLLOWING:2,POSITION_PRECEDING:4,POSITION_IS_CONTAINED:8,POSITION_CONTAINS:16};var g=r.POSITION,u={block:1,"list-item":1,table:1,"table-row-group":1,"table-header-group":1,"table-footer-group":1,"table-row":1,"table-column-group":1,"table-column":1,
"table-cell":1,"table-caption":1},v={hr:1},k=function(a){return a&&(a[0]||a)};o.injectDom({_4e_sameLevel:function(a,b){var b=k(b),c=a.parentNode;return c&&c==b.parentNode},_4e_isBlockBoundary:function(a,b){var c=l.merge(v,b);return!(!u[e.css(a,"display")]&&!c[e.nodeName(a)])},_4e_index:function(a,b){for(var c=a.parentNode.childNodes,d,e=-1,f=0;f<c.length;f++)if(d=c[f],!b||!(3==d.nodeType&&d.previousSibling&&3==d.previousSibling.nodeType))if(e++,d===a)return e;return-1},_4e_move:function(a,b,c){b=
k(b);c?b.insertBefore(a,b.firstChild):b.appendChild(a)},_4e_isIdentical:function(a,b){if(!b)return!1;b=k(b);if(e.nodeName(a)!=e.nodeName(b))return!1;var c=a.attributes,d=b.attributes,h=c.length,f=d.length;if(h!=f)return!1;for(var n=0;n<h;n++){var i=c[n],g=i.name;if(i.specified&&e.attr(a,g)!=e.attr(b,g))return!1}if(8>o.ieEngine)for(n=0;n<f;n++)if(i=d[n],g=i.name,i.specified&&e.attr(a,g)!=e.attr(b,g))return!1;return!0},_4e_isEmptyInlineRemovable:function(a){if(!q.$removeEmpty[e.nodeName(a)])return!1;
for(var a=a.childNodes,b=0,c=a.length;b<c;b++){var d=a[b],h=d.nodeType;if(!(h==e.ELEMENT_NODE&&d.getAttribute("_ke_bookmark"))&&(h==e.ELEMENT_NODE&&!e._4e_isEmptyInlineRemovable(d)||h==e.TEXT_NODE&&l.trim(d.nodeValue)))return!1}return!0},_4e_moveChildren:function(a,b,c){b=k(b);if(a!=b)if(c)for(;c=a.lastChild;)b.insertBefore(a.removeChild(c),b.firstChild);else for(;c=a.firstChild;)b.appendChild(a.removeChild(c))},_4e_mergeSiblings:function(a){a=new p(a);t[a.nodeName()]&&(s(a,!0),s(a))},_4e_splitText:function(a,
b){var c=a.ownerDocument;if(a.nodeType==e.TEXT_NODE){if(m.ie&&b==a.nodeValue.length){var d=c.createTextNode("");e.insertAfter(d,a);return d}d=a.splitText(b);c.documentMode&&(c=c.createTextNode(""),e.insertAfter(c,d),e.remove(c));return d}},_4e_parents:function(a,b){var c=[];c.__IS_NODELIST=1;do c[b?"push":"unshift"](a);while(a=a.parentNode);return c},_4e_nextSourceNode:function(a,b,c,d){if(d&&!d.call)var h=k(d),d=function(a){return a!==h};var b=!b&&a.firstChild,f=a;if(!b){if(a.nodeType==e.ELEMENT_NODE&&
d&&!1===d(a,!0))return null;b=a.nextSibling}for(;!b&&(f=f.parentNode);){if(d&&!1===d(f,!0))return null;b=f.nextSibling}return!b||d&&!1===d(b)?null:c&&c!=b.nodeType?e._4e_nextSourceNode(b,!1,c,d):b},_4e_previousSourceNode:function(a,b,c,d){if(d&&!d.call)var h=k(d),d=function(a){return a!==h};var b=!b&&a.lastChild,f=a;if(!b){if(a.nodeType==e.ELEMENT_NODE&&d&&!1===d(a,!0))return null;b=a.previousSibling}for(;!b&&(f=f.parentNode);){if(d&&!1===d(f,!0))return null;b=f.previousSibling}return!b||d&&!1===
d(b)?null:c&&b.nodeType!=c?e._4e_previousSourceNode(b,!1,c,d):b},_4e_commonAncestor:function(a,b){b=k(b);if(a===b)return a;if(e.contains(b,a))return b;var c=a;do if(e.contains(c,b))return c;while(c=c.parentNode);return null},_4e_hasAttributes:9>o.ieEngine?function(a){for(var b=a.attributes,c=0;c<b.length;c++){var d=b[c];switch(d.name){case "class":if(a.getAttribute("class"))return!0;break;default:if(d.specified)return!0}}return!1}:function(a){m.gecko&&a.removeAttribute("_moz_dirty");return a.hasAttributes()},
_4e_position:function(a,b){var c=k(b);if(a.compareDocumentPosition)return a.compareDocumentPosition(c);if(a==c)return g.POSITION_IDENTICAL;if(a.nodeType==e.ELEMENT_NODE&&c.nodeType==e.ELEMENT_NODE){if(e.contains(a,c))return g.POSITION_CONTAINS+g.POSITION_PRECEDING;if(e.contains(c,a))return g.POSITION_IS_CONTAINED+g.POSITION_FOLLOWING;if("sourceIndex"in a)return 0>a.sourceIndex||0>c.sourceIndex?g.POSITION_DISCONNECTED:a.sourceIndex<c.sourceIndex?g.POSITION_PRECEDING:g.POSITION_FOLLOWING}for(var d=
e._4e_address(a),c=e._4e_address(c),h=Math.min(d.length,c.length),f=0;f<=h-1;f++)if(d[f]!=c[f])return d[f]<c[f]?g.POSITION_PRECEDING:g.POSITION_FOLLOWING;return d.length<c.length?g.POSITION_CONTAINS+g.POSITION_PRECEDING:g.POSITION_IS_CONTAINED+g.POSITION_FOLLOWING},_4e_address:function(a,b){for(var c=[],d=a.ownerDocument.documentElement,h=a;h&&h!=d;)c.unshift(e._4e_index(h,b)),h=h.parentNode;return c},_4e_remove:function(a,b){var c=a.parentNode;if(c){if(b)for(var d;d=a.firstChild;)c.insertBefore(a.removeChild(d),
a);c.removeChild(a)}return a},_4e_trim:function(a){e._4e_ltrim(a);e._4e_rtrim(a)},_4e_ltrim:function(a){for(var b;b=a.firstChild;){if(b.nodeType==e.TEXT_NODE){var c=o.ltrim(b.nodeValue),d=b.nodeValue.length;if(c)c.length<d&&(e._4e_splitText(b,d-c.length),a.removeChild(a.firstChild));else{a.removeChild(b);continue}}break}},_4e_rtrim:function(a){for(var b;b=a.lastChild;){if(b.type==e.TEXT_NODE){var c=o.rtrim(b.nodeValue),d=b.nodeValue.length;if(c)c.length<d&&(e._4e_splitText(b,c.length),a.removeChild(a.lastChild));
else{a.removeChild(b);continue}}break}!m.ie&&!m.opera&&(b=a.lastChild)&&1==b.nodeType&&"br"==e.nodeName(b)&&a.removeChild(b)},_4e_appendBogus:function(a){for(var b=a.lastChild;b&&b.nodeType==e.TEXT_NODE&&!l.trim(b.nodeValue);)b=b.previousSibling;if(!b||b.nodeType==e.TEXT_NODE||"br"!==e.nodeName(b))b=m.opera?a.ownerDocument.createTextNode(""):a.ownerDocument.createElement("br"),m.gecko&&b.setAttribute("type","_moz"),a.appendChild(b)},_4e_outerHtml:function(a){if(a.outerHTML)return a.outerHTML.replace(/<\?[^>]*>/,
"");var b=a.ownerDocument.createElement("div");b.appendChild(a.cloneNode(!0));return b.innerHTML},_4e_setMarker:function(a,b,c,d){var a=new p(a),e=a.data("list_marker_id")||a.data("list_marker_id",l.guid()).data("list_marker_id"),f=a.data("list_marker_names")||a.data("list_marker_names",{}).data("list_marker_names");b[e]=a;f[c]=1;return a.data(c,d)},_4e_clearMarkers:function(a,b,c){var a=new p(a),d=a.data("list_marker_names"),e=a.data("list_marker_id"),f;for(f in d)d.hasOwnProperty(f)&&a.removeData(f);
a.removeData("list_marker_names");c&&(a.removeData("list_marker_id"),delete b[e])},_4e_copyAttributes:function(a,b,c){for(var b=new p(b),d=a.attributes,c=c||{},h=0;h<d.length;h++){var f=d[h],g=f.name.toLowerCase(),i;if(!(g in c))if("checked"==g&&(i=e.attr(a,g)))b.attr(g,i);else if(f.specified||m.ie&&f.value&&"value"==g)i=e.attr(a,g),null===i&&(i=f.nodeValue),b.attr(g,i)}""!==a.style.cssText&&(b[0].style.cssText=a.style.cssText)},_4e_isEditable:function(a){a=e.nodeName(a);return(a=!q.$nonEditable[a]&&
(q[a]||q.span))&&a["#text"]},_4e_getByAddress:function(a,b,c){for(var a=a.documentElement,d=0;a&&d<b.length;d++){var e=b[d];if(c)for(var f=-1,g=0;g<a.childNodes.length;g++){var i=a.childNodes[g];if(!(!0===c&&3==i.nodeType&&i.previousSibling&&3==i.previousSibling.nodeType)&&(f++,f==e)){a=i;break}}else a=a.childNodes[e]}return a}})},{requires:["./base","./utils"]});
