Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/nodes/ve.ce.ContentEditableNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable ContentEditableNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * A ContentEditableNode maintains its own contentEditable property
9 *
10 * @class
11 * @abstract
12 *
13 * @constructor
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 /* Inheritance */
27
28 OO.initClass( ve.ce.ContentEditableNode );
29 // Assumes ve.ce.Node as a base class
30
31 /* Methods */
32
33 /**
34 * Handle setup events on the node
35 */
36 ve.ce.ContentEditableNode.prototype.onContentEditableSetup = function () {
37 // Exit if already setup or not attached
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 // Set initial state
45 this.setReadOnly( this.ceSurface.isReadOnly() );
46 };
47
48 /**
49 * Handle teardown events on the node
50 */
51 ve.ce.ContentEditableNode.prototype.onContentEditableTeardown = function () {
52 // Exit if not setup
53 if ( !this.ceSurface ) {
54 return;
55 }
56 this.ceSurface.disconnect( this, { readOnly: 'onSurfaceReadOnly' } );
57 this.ceSurface = null;
58 };
59
60 /**
61 * Handle readOnly events from the surface
62 *
63 * @param {boolean} readOnly Surface is read-only
64 */
65 ve.ce.ContentEditableNode.prototype.onSurfaceReadOnly = function ( readOnly ) {
66 this.setReadOnly( readOnly );
67 };
68
69 /**
70 * Called when the surface read-only state changes
71 *
72 * @param {boolean} readOnly Surface is read-only
73 */
74 ve.ce.ContentEditableNode.prototype.setReadOnly = function ( readOnly ) {
75 this.$element.prop( 'spellcheck', !readOnly );
76 };
77
78 /**
79 * Enable or disable editing on this node
80 *
81 * @param {boolean} enabled Whether to enable editing
82 */
83 ve.ce.ContentEditableNode.prototype.setContentEditable = function ( enabled ) {
84 this.$element.prop( 'contentEditable', ( !!enabled ).toString() );
85 };
86
87 /**
88 * Check if the node is currently editable
89 *
90 * @return {boolean} Node is currently editable
91 */
92 ve.ce.ContentEditableNode.prototype.isContentEditable = function () {
93 return this.$element.prop( 'contentEditable' ) === 'true';
94 };