Commit 96a6de90 authored by campaign's avatar campaign

修改语法

parent 531bf0ea
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
"$", "$",
"KM", "KM",
"keymap", "keymap",
"baidu" "baidu",
"browser"
] ]
} }
\ No newline at end of file
...@@ -68,7 +68,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -68,7 +68,7 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
if(this.getStatus() == 'textedit') if(this.getStatus() == 'textedit')
this.fire('contentchange'); this.fire('contentchange');
km.setStatus('normal') km.setStatus('normal');
} }
if(node){ if(node){
var textShape = node.getTextShape(); var textShape = node.getTextShape();
...@@ -108,7 +108,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -108,7 +108,7 @@ KityMinder.registerModule( "TextEditModule", function () {
if(node){ if(node){
if ( this.isSingleSelect() && node.isSelected()) { if ( this.isSingleSelect() && node.isSelected()) {
var orgEvt = e.originEvent,keyCode = orgEvt.keyCode; var orgEvt = e.originEvent,keyCode = orgEvt.keyCode;
if(!keymap.notContentInput[keyCode] && range.nativeSel.rangeCount != 0 && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey){ if(!keymap.notContentInput[keyCode] && range.nativeSel.rangeCount !== 0 && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey){
var nativeRange = range.nativeSel.getRangeAt(0); var nativeRange = range.nativeSel.getRangeAt(0);
if(nativeRange && (nativeRange.startContainer === receiver.container || receiver.container.contains(nativeRange.startContainer ))){ if(nativeRange && (nativeRange.startContainer === receiver.container || receiver.container.contains(nativeRange.startContainer ))){
...@@ -159,13 +159,13 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -159,13 +159,13 @@ KityMinder.registerModule( "TextEditModule", function () {
if(!sel.collapsed ){ if(!sel.collapsed ){
try{ try{
receiver.updateRange(range) receiver.updateRange(range);
}catch(e){ }catch(error){
console.log(e) console.log(error);
} }
}else }else
sel.setShow() sel.setShow();
}else{ }else{
//当选中节点后,输入状态准备 //当选中节点后,输入状态准备
var node = e.getTargetNode(); var node = e.getTargetNode();
...@@ -254,7 +254,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -254,7 +254,7 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setData('relatedNode',node); sel.setData('relatedNode',node);
}else { }else {
receiver.clear() receiver.clear();
} }
}, },
...@@ -315,7 +315,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -315,7 +315,7 @@ KityMinder.registerModule( "TextEditModule", function () {
if(sel.collapsed){ if(sel.collapsed){
receiver.updateSelection(); receiver.updateSelection();
}else{ }else{
receiver.updateSelectionShow(1) receiver.updateSelectionShow(1);
} }
return; return;
...@@ -323,18 +323,18 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -323,18 +323,18 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
receiver.clear().setTextEditStatus(false); receiver.clear().setTextEditStatus(false);
if(this.getStatus() == 'textedit'){ if(this.getStatus() == 'textedit'){
this.setStatus('normal') this.setStatus('normal');
} }
}, },
'selectionclear':function(){ 'selectionclear':function(){
km.setStatus('normal'); km.setStatus('normal');
receiver.setTextEditStatus(false).clear() receiver.setTextEditStatus(false).clear();
}, },
blur:function(){ blur:function(){
receiver.clear() receiver.clear();
}, },
'textedit.mousewheel':function(){ 'textedit.mousewheel':function(){
receiver.setContainerStyle() receiver.setContainerStyle();
} }
} }
}; };
......
...@@ -4,11 +4,11 @@ Minder.Range = kity.createClass('Range',{ ...@@ -4,11 +4,11 @@ Minder.Range = kity.createClass('Range',{
this.nativeSel = window.getSelection(); this.nativeSel = window.getSelection();
}, },
hasNativeRange : function(){ hasNativeRange : function(){
return this.nativeSel.rangeCount != 0 ; return this.nativeSel.rangeCount !== 0 ;
}, },
select:function(){ select:function(){
var start = this.nativeRange.startContainer; var start = this.nativeRange.startContainer;
if(start.nodeType == 1 && start.childNodes.length == 0){ if(start.nodeType == 1 && start.childNodes.length === 0){
var char = document.createTextNode('\u200b'); var char = document.createTextNode('\u200b');
start.appendChild(char); start.appendChild(char);
this.nativeRange.setStart(char,1); this.nativeRange.setStart(char,1);
...@@ -26,8 +26,8 @@ Minder.Range = kity.createClass('Range',{ ...@@ -26,8 +26,8 @@ Minder.Range = kity.createClass('Range',{
setStart:function(node,index){ setStart:function(node,index){
try{ try{
this.nativeRange.setStart(node,index); this.nativeRange.setStart(node,index);
}catch(e){ }catch(error){
console.log('e') console.log(error);
} }
return this; return this;
...@@ -41,7 +41,7 @@ Minder.Range = kity.createClass('Range',{ ...@@ -41,7 +41,7 @@ Minder.Range = kity.createClass('Range',{
return { return {
startContainer:range.startContainer, startContainer:range.startContainer,
startOffset:range.startOffset startOffset:range.startOffset
} };
}, },
collapse:function(toStart){ collapse:function(toStart){
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
Minder.Receiver = kity.createClass( 'Receiver', { Minder.Receiver = kity.createClass( 'Receiver', {
clear: function () { clear: function () {
this.container.innerHTML = ''; this.container.innerHTML = '';
this.selection && this.selection.setHide(); if(this.selection){
this.range && this.range.nativeSel.removeAllRanges(); this.selection.setHide();
}
if(this.range){
this.range.nativeSel.removeAllRanges();
}
this.index = 0; this.index = 0;
this.inputLength = 0; this.inputLength = 0;
return this; return this;
...@@ -25,8 +29,8 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -25,8 +29,8 @@ Minder.Receiver = kity.createClass( 'Receiver', {
this.container = document.body.insertBefore( _div, document.body.firstChild ); this.container = document.body.insertBefore( _div, document.body.firstChild );
if ( browser.ie && browser.version == 11 ) { if ( browser.ie && browser.version == 11 ) {
utils.listen( this.container, 'keydown keypress keyup', function ( e ) { utils.listen( this.container, 'keydown keypress keyup', function ( e ) {
me.keyboardEvents.call( me, new MinderEvent( e.type == 'keyup' ? "beforekeyup" : e.type, e ) ) me.keyboardEvents.call( me, new MinderEvent( e.type == 'keyup' ? "beforekeyup" : e.type, e ) );
} ) } );
} }
utils.addCssRule( 'km_receiver_css', ' .km_receiver{white-space:nowrap;position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}' ); // utils.addCssRule( 'km_receiver_css', ' .km_receiver{white-space:nowrap;position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}' ); //
this.km.on( 'textedit.beforekeyup textedit.keydown textedit.keypress textedit.paste', utils.proxy( this.keyboardEvents, this ) ); this.km.on( 'textedit.beforekeyup textedit.keydown textedit.keypress textedit.paste', utils.proxy( this.keyboardEvents, this ) );
...@@ -43,7 +47,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -43,7 +47,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
var me = this; var me = this;
setTimeout( function () { setTimeout( function () {
me.container.focus(); me.container.focus();
range.select() range.select();
} ); } );
return this; return this;
}, },
...@@ -88,7 +92,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -88,7 +92,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
} }
var text = me.container.textContent.replace( /[\u200b\t\r\n]/g, '' ); var text = me.container.textContent.replace( /[\u200b\t\r\n]/g, '' );
if ( me.textShape.getOpacity() == 0 ) { if ( me.textShape.getOpacity() === 0 ) {
me.textShape.setOpacity( 1 ); me.textShape.setOpacity( 1 );
} }
//#46 修复在ff下定位到文字后方空格光标不移动问题 //#46 修复在ff下定位到文字后方空格光标不移动问题
...@@ -98,14 +102,14 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -98,14 +102,14 @@ Minder.Receiver = kity.createClass( 'Receiver', {
me.setContainerStyle(); me.setContainerStyle();
me.minderNode.setText( text ); me.minderNode.setText( text );
if ( text.length == 0 ) { if ( text.length === 0 ) {
me.minderNode.setText( 'a' ); me.minderNode.setText( 'a' );
} }
me.km.updateLayout( me.minderNode ); me.km.updateLayout( me.minderNode );
me.textShape = me.minderNode.getTextShape(); me.textShape = me.minderNode.getTextShape();
if ( text.length == 0 ) { if ( text.length === 0 ) {
me.textShape.setOpacity( 0 ); me.textShape.setOpacity( 0 );
} }
me.setBaseOffset(); me.setBaseOffset();
...@@ -117,8 +121,8 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -117,8 +121,8 @@ Minder.Receiver = kity.createClass( 'Receiver', {
if( me.selection.getSelectionShowStatus()) { if( me.selection.getSelectionShowStatus()) {
me.updateSelection(); me.updateSelection();
me.timer = setTimeout(function () { me.timer = setTimeout(function () {
me.selection.setShow() me.selection.setShow();
}, 500) }, 500);
} }
} }
...@@ -139,7 +143,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -139,7 +143,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
this.km.setStatus( 'normal' ); this.km.setStatus( 'normal' );
e.preventDefault(); e.preventDefault();
return; return;
break;
} }
...@@ -154,13 +158,13 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -154,13 +158,13 @@ Minder.Receiver = kity.createClass( 'Receiver', {
var index = me.container.textContent.indexOf( '$$_kityminder_bookmark_$$' ); var index = me.container.textContent.indexOf( '$$_kityminder_bookmark_$$' );
me.container.textContent = me.container.textContent.replace( '$$_kityminder_bookmark_$$', '' ); me.container.textContent = me.container.textContent.replace( '$$_kityminder_bookmark_$$', '' );
me.range.setStart( me.container.firstChild, index ).collapse( true ).select(); me.range.setStart( me.container.firstChild, index ).collapse( true ).select();
setTextToContainer() setTextToContainer();
}, 100 ); }, 100 );
} }
//剪切 //剪切
if ( keyCode == keymap.x ) { if ( keyCode == keymap.x ) {
setTimeout( function () { setTimeout( function () {
setTextToContainer() setTextToContainer();
}, 100 ); }, 100 );
} }
return; return;
...@@ -224,18 +228,18 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -224,18 +228,18 @@ Minder.Receiver = kity.createClass( 'Receiver', {
//更新模拟选区的范围 //更新模拟选区的范围
this.selection.setStartOffset( this.index ).collapse( true ); this.selection.setStartOffset( this.index ).collapse( true );
if ( this.index == this.textData.length ) { if ( this.index == this.textData.length ) {
if ( this.index == 0 ) { if ( this.index === 0 ) {
this.selection.setPosition( this.getBaseOffset() ) this.selection.setPosition( this.getBaseOffset() );
} else { } else {
this.selection.setPosition( { this.selection.setPosition( {
x: this.textData[ this.index - 1 ].x + this.textData[ this.index - 1 ].width, x: this.textData[ this.index - 1 ].x + this.textData[ this.index - 1 ].width,
y: this.textData[ this.index - 1 ].y y: this.textData[ this.index - 1 ].y
} ) } );
} }
} else { } else {
this.selection.setPosition( this.textData[ this.index ] ) this.selection.setPosition( this.textData[ this.index ] );
} }
return this; return this;
}, },
...@@ -264,7 +268,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -264,7 +268,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
this.setContainerStyle(); this.setContainerStyle();
} else if ( height < this.container.offsetTop + this.container.offsetHeight ) { } else if ( height < this.container.offsetTop + this.container.offsetHeight ) {
this.km.getRenderContainer().translate( 0, height / -3 ); this.km.getRenderContainer().translate( 0, height / -3 );
this.setContainerStyle() this.setContainerStyle();
} }
} }
...@@ -273,13 +277,14 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -273,13 +277,14 @@ Minder.Receiver = kity.createClass( 'Receiver', {
}, },
getTextOffsetData: function () { getTextOffsetData: function () {
var text = this.textShape.getContent(); var text = this.textShape.getContent();
var box;
this.textData = []; this.textData = [];
for ( var i = 0, l = text.length; i < l; i++ ) { for ( var i = 0, l = text.length; i < l; i++ ) {
try { try {
var box = this.textShape.getExtentOfChar( i ); box = this.textShape.getExtentOfChar( i );
} catch ( e ) { } catch ( e ) {
console.log( e ) console.log( e );
} }
this.textData.push( { this.textData.push( {
...@@ -287,7 +292,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -287,7 +292,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
y: this.offset.y, y: this.offset.y,
width: box.width, width: box.width,
height: box.height height: box.height
} ) } );
} }
return this; return this;
}, },
...@@ -297,7 +302,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -297,7 +302,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
var hadChanged = false; var hadChanged = false;
utils.each( this.textData, function ( i, v ) { utils.each( this.textData, function ( i, v ) {
//点击开始之前 //点击开始之前
if ( i == 0 && offset.x <= v.x ) { if ( i === 0 && offset.x <= v.x ) {
me.index = 0; me.index = 0;
return false; return false;
} }
...@@ -306,7 +311,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -306,7 +311,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
me.index = i + 1; me.index = i + 1;
} else { } else {
me.index = i me.index = i;
} }
hadChanged = true; hadChanged = true;
...@@ -331,7 +336,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -331,7 +336,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
var me = this; var me = this;
utils.each( this.textData, function ( i, v ) { utils.each( this.textData, function ( i, v ) {
//点击开始之前 //点击开始之前
if ( i == 0 && offset.x <= v.x ) { if ( i === 0 && offset.x <= v.x ) {
me.selection.setStartOffset( 0 ); me.selection.setStartOffset( 0 );
return false; return false;
} }
...@@ -343,18 +348,18 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -343,18 +348,18 @@ Minder.Receiver = kity.createClass( 'Receiver', {
if ( offset.x >= v.x && offset.x <= v.x + v.width ) { if ( offset.x >= v.x && offset.x <= v.x + v.width ) {
if ( me.index == i ) { if ( me.index == i ) {
if ( i == 0 ) { if ( i === 0 ) {
me.selection.setStartOffset( i ) me.selection.setStartOffset( i );
} }
if ( offset.x <= v.x + v.width / 2 ) { if ( offset.x <= v.x + v.width / 2 ) {
me.selection.collapse() me.selection.collapse();
} else { } else {
me.selection.setEndOffset( i + ( ( me.selection.endOffset > i || dir == 1 ) && i != me.textData.length - 1 ? 1 : 0 ) ) me.selection.setEndOffset( i + ( ( me.selection.endOffset > i || dir == 1 ) && i != me.textData.length - 1 ? 1 : 0 ) );
} }
} else if ( i > me.index ) { } else if ( i > me.index ) {
me.selection.setStartOffset( me.index ); me.selection.setStartOffset( me.index );
me.selection.setEndOffset( i + 1 ) me.selection.setEndOffset( i + 1 );
} else { } else {
if ( dir == 1 ) { if ( dir == 1 ) {
me.selection.setStartOffset( i + ( offset.x >= v.x + v.width / 2 && i != me.textData.length - 1 ? 1 : 0 ) ); me.selection.setStartOffset( i + ( offset.x >= v.x + v.width / 2 && i != me.textData.length - 1 ? 1 : 0 ) );
...@@ -362,7 +367,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -362,7 +367,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
me.selection.setStartOffset( i ); me.selection.setStartOffset( i );
} }
me.selection.setEndOffset( me.index ) me.selection.setEndOffset( me.index );
} }
return false; return false;
...@@ -383,7 +388,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -383,7 +388,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
var lastOffset = this.textData[ this.textData.length - 1 ]; var lastOffset = this.textData[ this.textData.length - 1 ];
width = lastOffset.x - startOffset.x + lastOffset.width; width = lastOffset.x - startOffset.x + lastOffset.width;
} catch ( e ) { } catch ( e ) {
console.log( e ) console.log( e );
} }
} else { } else {
...@@ -402,7 +407,7 @@ Minder.Receiver = kity.createClass( 'Receiver', { ...@@ -402,7 +407,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
}, },
setIndex: function ( index ) { setIndex: function ( index ) {
this.index = index; this.index = index;
return this return this;
}, },
setContainerTxt: function ( txt ) { setContainerTxt: function ( txt ) {
this.container.textContent = txt; this.container.textContent = txt;
......
...@@ -66,7 +66,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -66,7 +66,7 @@ Minder.Selection = kity.createClass( 'Selection', {
} }
this.setPosition(offset).setWidth(width); this.setPosition(offset).setWidth(width);
//解决在框选内容时,出现很窄的光标 //解决在框选内容时,出现很窄的光标
if(width == 0){ if(width === 0){
this.setOpacity(0); this.setOpacity(0);
}else{ }else{
this.setOpacity(0.5); this.setOpacity(0.5);
...@@ -80,7 +80,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -80,7 +80,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.y = offset.y; this.y = offset.y;
} catch ( e ) { } catch ( e ) {
console.log(e) console.log(e);
} }
return this.update(); return this.update();
}, },
...@@ -125,13 +125,13 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -125,13 +125,13 @@ Minder.Selection = kity.createClass( 'Selection', {
} else { } else {
this.text = text; this.text = text;
} }
return this return this;
}, },
getTextShape: function () { getTextShape: function () {
return this.text return this.text;
}, },
setTxtContent: function ( text ) { setTxtContent: function ( text ) {
this.text.setContent( text ) this.text.setContent( text );
}, },
updatePosition: function ( index ) { updatePosition: function ( index ) {
...@@ -140,6 +140,6 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -140,6 +140,6 @@ Minder.Selection = kity.createClass( 'Selection', {
this.selectionShowStatus = status; this.selectionShowStatus = status;
}, },
getSelectionShowStatus:function(){ getSelectionShowStatus:function(){
return this.selectionShowStatus return this.selectionShowStatus;
} }
} ); } );
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment