You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tt-rss/lib/dijit/_editor/plugins/EnterKeyHandling.js

2 lines
9.5 KiB
JavaScript

//>>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"],function(_1,_2,_3,_4,on,_5,_6,_7,_8,_9,_a){return _1("dijit._editor.plugins.EnterKeyHandling",_8,{blockNodeForEnter:"BR",constructor:function(_b){if(_b){if("blockNodeForEnter" in _b){_b.blockNodeForEnter=_b.blockNodeForEnter.toUpperCase();}_4.mixin(this,_b);}},setEditor:function(_c){if(this.editor===_c){return;}this.editor=_c;if(this.blockNodeForEnter=="BR"){this.editor.customUndo=true;_c.onLoadDeferred.then(_4.hitch(this,function(d){this.own(on(_c.document,"keydown",_4.hitch(this,function(e){if(e.keyCode==_3.ENTER){var ne=_4.mixin({},e);ne.shiftKey=true;if(!this.handleEnterKey(ne)){e.stopPropagation();e.preventDefault();}}})));if(_5("ie")>=9&&_5("ie")<=10){this.own(on(_c.document,"paste",_4.hitch(this,function(e){setTimeout(_4.hitch(this,function(){var r=this.editor.document.selection.createRange();r.move("character",-1);r.select();r.move("character",1);r.select();}),0);})));}return d;}));}else{if(this.blockNodeForEnter){var h=_4.hitch(this,"handleEnterKey");_c.addKeyHandler(13,0,0,h);_c.addKeyHandler(13,0,1,h);this.own(this.editor.on("KeyPressed",_4.hitch(this,"onKeyPressed")));}}},onKeyPressed:function(){if(this._checkListLater){if(this.editor.selection.isCollapsed()){var _d=this.editor.selection.getAncestorElement("LI");if(!_d){_9.prototype.execCommand.call(this.editor,"formatblock",this.blockNodeForEnter);var _e=this.editor.selection.getAncestorElement(this.blockNodeForEnter);if(_e){_e.innerHTML=this.bogusHtmlContent;if(_5("ie")<=9){var r=this.editor.document.selection.createRange();r.move("character",-1);r.select();}}else{console.error("onKeyPressed: Cannot find the new block node");}}else{if(_5("mozilla")){if(_d.parentNode.parentNode.nodeName=="LI"){_d=_d.parentNode.parentNode;}}var fc=_d.firstChild;if(fc&&fc.nodeType==1&&(fc.nodeName=="UL"||fc.nodeName=="OL")){_d.insertBefore(fc.ownerDocument.createTextNode(" "),fc);var _f=_a.create(this.editor.window);_f.setStart(_d.firstChild,0);var _10=_a.getSelection(this.editor.window,true);_10.removeAllRanges();_10.addRange(_f);}}}this._checkListLater=false;}if(this._pressedEnterInBlock){if(this._pressedEnterInBlock.previousSibling){this.removeTrailingBr(this._pressedEnterInBlock.previousSibling);}delete this._pressedEnterInBlock;}},bogusHtmlContent:"&#160;",blockNodes:/^(?:P|H1|H2|H3|H4|H5|H6|LI)$/,handleEnterKey:function(e){var _11,_12,_13,_14,_15,_16,doc=this.editor.document,br,rs,txt;if(e.shiftKey){var _17=this.editor.selection.getParentElement();var _18=_a.getAncestor(_17,this.blockNodes);if(_18){if(_18.tagName=="LI"){return true;}_11=_a.getSelection(this.editor.window);_12=_11.getRangeAt(0);if(!_12.collapsed){_12.deleteContents();_11=_a.getSelection(this.editor.window);_12=_11.getRangeAt(0);}if(_a.atBeginningOfContainer(_18,_12.startContainer,_12.startOffset)){br=doc.createElement("br");_13=_a.create(this.editor.window);_18.insertBefore(br,_18.firstChild);_13.setStartAfter(br);_11.removeAllRanges();_11.addRange(_13);}else{if(_a.atEndOfContainer(_18,_12.startContainer,_12.startOffset)){_13=_a.create(this.editor.window);br=doc.createElement("br");_18.appendChild(br);_18.appendChild(doc.createTextNode(" "));_13.setStart(_18.lastChild,0);_11.removeAllRanges();_11.addRange(_13);}else{rs=_12.startContainer;if(rs&&rs.nodeType==3){txt=rs.nodeValue;_14=doc.createTextNode(txt.substring(0,_12.startOffset));_15=doc.createTextNode(txt.substring(_12.startOffset));_16=doc.createElement("br");if(_15.nodeValue==""&&_5("webkit")){_15=doc.createTextNode(" ");}_2.place(_14,rs,"after");_2.place(_16,_14,"after");_2.place(_15,_16,"after");_2.destroy(rs);_13=_a.create(this.editor.window);_13.setStart(_15,0);_11.removeAllRanges();_11.addRange(_13);return false;}return true;}}}else{_11=_a.getSelection(this.editor.window);if(_11.rangeCount){_12=_11.getRangeAt(0);if(_12&&_12.startContainer){if(!_12.collapsed){_12.deleteContents();_11=_a.getSelection(this.editor.window);_12=_11.g