| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
ve.ce.ContentEditableNode = function VeCeContentEditableNode() { |
| 16 |
this.ceSurface = null; |
| 17 |
this.setContentEditable( true ); |
| 18 |
this.setReadOnly( false ); |
| 19 |
|
| 20 |
this.connect( this, { |
| 21 |
setup: 'onContentEditableSetup', |
| 22 |
teardown: 'onContentEditableTeardown' |
| 23 |
} ); |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
OO.initClass( ve.ce.ContentEditableNode ); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
ve.ce.ContentEditableNode.prototype.onContentEditableSetup = function () { |
| 37 |
|
| 38 |
if ( this.ceSurface || !this.root ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
this.ceSurface = this.root.getSurface().getSurface(); |
| 42 |
|
| 43 |
this.ceSurface.connect( this, { readOnly: 'onSurfaceReadOnly' } ); |
| 44 |
|
| 45 |
this.setReadOnly( this.ceSurface.isReadOnly() ); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
ve.ce.ContentEditableNode.prototype.onContentEditableTeardown = function () { |
| 52 |
|
| 53 |
if ( !this.ceSurface ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
this.ceSurface.disconnect( this, { readOnly: 'onSurfaceReadOnly' } ); |
| 57 |
this.ceSurface = null; |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.ce.ContentEditableNode.prototype.onSurfaceReadOnly = function ( readOnly ) { |
| 66 |
this.setReadOnly( readOnly ); |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
ve.ce.ContentEditableNode.prototype.setReadOnly = function ( readOnly ) { |
| 75 |
this.$element.prop( 'spellcheck', !readOnly ); |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
ve.ce.ContentEditableNode.prototype.setContentEditable = function ( enabled ) { |
| 84 |
this.$element.prop( 'contentEditable', ( !!enabled ).toString() ); |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ce.ContentEditableNode.prototype.isContentEditable = function () { |
| 93 |
return this.$element.prop( 'contentEditable' ) === 'true'; |
| 94 |
}; |