//>>built
define("dijit/_editor/plugins/EnterKeyHandling","dojo/_base/declare dojo/dom-construct dojo/keys dojo/_base/lang dojo/on dojo/sniff dojo/_base/window dojo/window ../_Plugin ../RichText ../range".split(" "),function(w,l,x,r,v,q,z,t,y,u,k){return w("dijit._editor.plugins.EnterKeyHandling",y,{blockNodeForEnter:"BR",constructor:function(a){a&&("blockNodeForEnter"in a&&(a.blockNodeForEnter=a.blockNodeForEnter.toUpperCase()),r.mixin(this,a))},setEditor:function(a){if(this.editor!==a)if(this.editor=a,"BR"==
this.blockNodeForEnter)this.editor.customUndo=!0,a.onLoadDeferred.then(r.hitch(this,function(h){this.own(v(a.document,"keydown",r.hitch(this,function(f){if(f.keyCode==x.ENTER){var b=r.mixin({},f);b.shiftKey=!0;this.handleEnterKey(b)||(f.stopPropagation(),f.preventDefault())}})));9<=q("ie")&&10>=q("ie")&&this.own(v(a.document,"paste",r.hitch(this,function(f){setTimeout(r.hitch(this,function(){var b=this.editor.document.selection.createRange();b.move("character",-1);b.select();b.move("character",1);
b.select()}),0)})));return h}));else if(this.blockNodeForEnter){var d=r.hitch(this,"handleEnterKey");a.addKeyHandler(13,0,0,d);a.addKeyHandler(13,0,1,d);this.own(this.editor.on("KeyPressed",r.hitch(this,"onKeyPressed")))}},onKeyPressed:function(){if(this._checkListLater){if(this.editor.selection.isCollapsed()){var a=this.editor.selection.getAncestorElement("LI");if(a){q("mozilla")&&"LI"==a.parentNode.parentNode.nodeName&&(a=a.parentNode.parentNode);var d=a.firstChild;!d||1!=d.nodeType||"UL"!=d.nodeName&&
"OL"!=d.nodeName||(a.insertBefore(d.ownerDocument.createTextNode("\u00a0"),d),d=k.create(this.editor.window),d.setStart(a.firstChild,0),a=k.getSelection(this.editor.window,!0),a.removeAllRanges(),a.addRange(d))}else if(u.prototype.execCommand.call(this.editor,"formatblock",this.blockNodeForEnter),a=this.editor.selection.getAncestorElement(this.blockNodeForEnter))a.innerHTML=this.bogusHtmlContent,9>=q("ie")&&(a=this.editor.document.selection.createRange(),a.move("character",-1),a.select())}this._checkListLater=
!1}this._pressedEnterInBlock&&(this._pressedEnterInBlock.previousSibling&&this.removeTrailingBr(this._pressedEnterInBlock.previousSibling),delete this._pressedEnterInBlock)},bogusHtmlContent:"\x26#160;",blockNodes:/^(?:P|H1|H2|H3|H4|H5|H6|LI)$/,handleEnterKey:function(a){var d,h=this.editor.document,f;if(a.shiftKey){a=this.editor.selection.getParentElement();if(d=k.getAncestor(a,this.blockNodes)){if("LI"==d.tagName)return!0;a=k.getSelection(this.editor.window);var b=a.getRangeAt(0);b.collapsed||(b.deleteContents(),
a=k.getSelection(this.editor.window),b=a.getRangeAt(0));if(k.atBeginningOfContainer(d,b.startContainer,b.startOffset)){var e=h.createElement("br");b=k.create(this.editor.window);d.insertBefore(e,d.firstChild);b.setStartAfter(e);a.removeAllRanges();a.addRange(b)}else if(k.atEndOfContainer(d,b.startContainer,b.startOffset))b=k.create(this.editor.window),e=h.createElement("br"),d.appendChild(e),d.appendChild(h.createTextNode("\u00a0")),b.setStart(d.lastChild,0),a.removeAllRanges(),a.addRange(b);else{if((f=
b.startContainer)&&3==f.nodeType){var m=f.nodeValue;var n=h.createTextNode(m.substring(0,b.startOffset));var c=h.createTextNode(m.substring(b.startOffset));d=h.createElement("br");""==c.nodeValue&&q("webkit")&&(c=h.createTextNode("\u00a0"));l.place(n,f,"after");l.place(d,n,"after");l.place(c,d,"after");l.destroy(f);b=k.create(this.editor.window);b.setStart(c,0);a.removeAllRanges();a.addRange(b);return!1}return!0}}else a=k.getSelection(this.editor.window),a.rangeCount?(b=a.getRangeAt(0))&&b.startContainer&&
(b.collapsed||(b.deleteContents(),a=k.getSelection(this.editor.window),b=a.getRangeAt(0)),(f=b.startContainer)&&3==f.nodeType?(d=b.startOffset,f.length<d&&(c=this._adjustNodeAndOffset(f,d),f=c.node,d=c.offset),m=f.nodeValue,n=h.createTextNode(m.substring(0,d)),c=h.createTextNode(m.substring(d)),d=h.createElement("br"),c.length||(c=h.createTextNode("\u00a0")),n.length?l.place(n,f,"after"):n=f,l.place(d,n,"after"),l.place(c,d,"after"),l.destroy(f)):(0<=b.startOffset&&(e=f.childNodes[b.startOffset]),
d=h.createElement("br"),c=h.createTextNode("\u00a0"),e?(l.place(d,e,"before"),l.place(c,d,"after")):(f.appendChild(d),f.appendChild(c))),b=k.create(this.editor.window),b.setStart(c,0),b.setEnd(c,c.length),a.removeAllRanges(),a.addRange(b),this.editor.selection.collapse(!0)):u.prototype.execCommand.call(this.editor,"inserthtml","\x3cbr\x3e");return!1}var p=!0;a=k.getSelection(this.editor.window);b=a.getRangeAt(0);b.collapsed||(b.deleteContents(),a=k.getSelection(this.editor.window),b=a.getRangeAt(0));
e=k.getBlockAncestor(b.endContainer,null,this.editor.editNode);var g=e.blockNode;if(this._checkListLater=g&&("LI"==g.nodeName||"LI"==g.parentNode.nodeName))return q("mozilla")&&(this._pressedEnterInBlock=g),/^(\s|&nbsp;|&#160;|\xA0|<span\b[^>]*\bclass=['"]Apple-style-span['"][^>]*>(\s|&nbsp;|&#160;|\xA0)<\/span>)?(<br>)?$/.test(g.innerHTML)&&(g.innerHTML="",q("webkit")&&(b=k.create(this.editor.window),b.setStart(g,0),a.removeAllRanges(),a.addRange(b)),this._checkListLater=!1),!0;if(!e.blockNode||
e.blockNode===this.editor.editNode){try{u.prototype.execCommand.call(this.editor,"formatblock",this.blockNodeForEnter)}catch(A){}e={blockNode:this.editor.selection.getAncestorElement(this.blockNodeForEnter),blockContainer:this.editor.editNode};if(e.blockNode){if(e.blockNode!=this.editor.editNode&&!(e.blockNode.textContent||e.blockNode.innerHTML).replace(/^\s+|\s+$/g,"").length)return this.removeTrailingBr(e.blockNode),!1}else e.blockNode=this.editor.editNode;a=k.getSelection(this.editor.window);b=
a.getRangeAt(0)}g=h.createElement(this.blockNodeForEnter);g.innerHTML=this.bogusHtmlContent;this.removeTrailingBr(e.blockNode);c=b.endOffset;p=b.endContainer;p.length<c&&(c=this._adjustNodeAndOffset(p,c),p=c.node,c=c.offset);if(k.atEndOfContainer(e.blockNode,p,c))e.blockNode===e.blockContainer?e.blockNode.appendChild(g):l.place(g,e.blockNode,"after"),p=!1,b=k.create(this.editor.window),b.setStart(g,0),a.removeAllRanges(),a.addRange(b),this.editor.height&&t.scrollIntoView(g);else if(k.atBeginningOfContainer(e.blockNode,
b.startContainer,b.startOffset))l.place(g,e.blockNode,e.blockNode===e.blockContainer?"first":"before"),g.nextSibling&&this.editor.height&&(b=k.create(this.editor.window),b.setStart(g.nextSibling,0),a.removeAllRanges(),a.addRange(b),t.scrollIntoView(g.nextSibling)),p=!1;else{e.blockNode===e.blockContainer?e.blockNode.appendChild(g):l.place(g,e.blockNode,"after");p=!1;e.blockNode.style&&g.style&&e.blockNode.style.cssText&&(g.style.cssText=e.blockNode.style.cssText);if((f=b.startContainer)&&3==f.nodeType){c=
b.endOffset;f.length<c&&(c=this._adjustNodeAndOffset(f,c),f=c.node,c=c.offset);m=f.nodeValue;n=h.createTextNode(m.substring(0,c));c=h.createTextNode(m.substring(c,m.length));l.place(n,f,"before");l.place(c,f,"after");l.destroy(f);for(b=n.parentNode;b!==e.blockNode;){m=h.createElement(b.tagName);b.style&&m.style&&b.style.cssText&&(m.style.cssText=b.style.cssText);"FONT"===b.tagName&&(b.color&&(m.color=b.color),b.face&&(m.face=b.face),b.size&&(m.size=b.size));for(;c;)f=c.nextSibling,m.appendChild(c),
c=f;l.place(m,b,"after");n=b;c=m;b=b.parentNode}if(1==c.nodeType||3==c.nodeType&&c.nodeValue)g.innerHTML="";for(n=c;c;)f=c.nextSibling,g.appendChild(c),c=f}b=k.create(this.editor.window);h=n;if("BR"!==this.blockNodeForEnter){for(;h;)d=h,h=f=h.firstChild;d&&d.parentNode?(g=d.parentNode,b.setStart(g,0),a.removeAllRanges(),a.addRange(b),this.editor.height&&t.scrollIntoView(g),q("mozilla")&&(this._pressedEnterInBlock=e.blockNode)):p=!0}else b.setStart(g,0),a.removeAllRanges(),a.addRange(b),this.editor.height&&
t.scrollIntoView(g),q("mozilla")&&(this._pressedEnterInBlock=e.blockNode)}return p},_adjustNodeAndOffset:function(a,d){for(;a.length<d&&a.nextSibling&&3==a.nextSibling.nodeType;)d-=a.length,a=a.nextSibling;return{node:a,offset:d}},removeTrailingBr:function(a){if(a=/P|DIV|LI/i.test(a.tagName)?a:this.editor.selection.getParentOfType(a,["P","DIV","LI"]))a.lastChild&&(1<a.childNodes.length&&3==a.lastChild.nodeType&&/^[\s\xAD]*$/.test(a.lastChild.nodeValue)||"BR"==a.lastChild.tagName)&&l.destroy(a.lastChild),
a.childNodes.length||(a.innerHTML=this.bogusHtmlContent)}})});