All files / src/ce ve.ce.Node.js

85.33% Statements 64/75
83.33% Branches 5/6
67.74% Functions 21/31
85.33% Lines 64/75

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334                                  1x   5584x     5584x         1x   1x                           1x                       1x                       1x                       1x                 1x                       1x                 1x             1x             1x             1x 2x           1x 11416x           1x             1x             1x 1258x           1x             1x 6x           1x 99x                     1x 1413x           1x             1x 545x           1x 554x           1x             1x             1x 16x           1x 177x           1x 12331x           1x 4577x               1x 80x               1x 19x                     1x 95x 267x   95x     95x                 1x 364x               1x 1x           1x 254x 254x 254x     254x               1x 235x    
/*!
 * VisualEditor ContentEditable Node class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Generic ContentEditable node.
 *
 * @abstract
 * @extends ve.ce.View
 * @mixins ve.Node
 *
 * @constructor
 * @param {ve.dm.Node} model Model to observe
 * @param {Object} [config] Configuration options
 */
ve.ce.Node = function VeCeNode() {
	// Parent constructor
	ve.ce.Node.super.apply( this, arguments );
 
	// Mixin constructor
	ve.Node.call( this );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.Node, ve.ce.View );
 
OO.mixinClass( ve.ce.Node, ve.Node );
 
/* Static Members */
 
/**
 * Whether Enter splits this node type.
 *
 * When the user presses Enter, we split the node they're in (if splittable), then split its parent
 * if splittable, and continue traversing up the tree and stop at the first non-splittable node.
 *
 * @static
 * @property {boolean}
 * @inheritable
 */
ve.ce.Node.static.splitOnEnter = false;
 
/**
 * Whether Enter removes the empty last child of this node.
 *
 * Set true on the parent of a splitOnEnter node (e.g. a ListNode) to ensure that the last splittable
 * child (e.g a ListItemNode) is removed when empty and enter is pressed.
 *
 * @static
 * @property {boolean}
 * @inheritable
 */
ve.ce.Node.static.removeEmptyLastChildOnEnter = false;
 
/**
 * Whether a node supports multiline input at all.
 *
 * If set to false, pressing Enter will not perform any splitting at all. If set to null, traverse
 * up the tree until a boolean value is found.
 *
 * @static
 * @property {boolean|null}
 * @inheritable
 */
ve.ce.Node.static.isMultiline = null;
 
/**
 * Whether a node can take the cursor when its surface is focused
 *
 * When set to false, this will prevent the selection from being placed in
 * any of the node's descendant ContentBranchNodes.
 *
 * @static
 * @property {boolean}
 * @inheritable
 */
ve.ce.Node.static.autoFocus = true;
 
/**
 * Whether a node traps the cursor when active, e.g. in table cells
 *
 * @static
 * @property {boolean}
 * @inheritable
 */
ve.ce.Node.static.trapsCursor = false;
 
/* Static Methods */
 
/**
 * Get a plain text description.
 *
 * @static
 * @inheritable
 * @param {ve.dm.Node} node Node model
 * @return {string} Description of node
 */
ve.ce.Node.static.getDescription = function () {
	return '';
};
 
/* Methods */
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.getChildNodeTypes = function () {
	return this.model.getChildNodeTypes();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.getParentNodeTypes = function () {
	return this.model.getParentNodeTypes();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.getSuggestedParentNodeTypes = function () {
	return this.model.getSuggestedParentNodeTypes();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.canHaveChildren = function () {
	return this.model.canHaveChildren();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.canHaveChildrenNotContent = function () {
	return this.model.canHaveChildrenNotContent();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isInternal = function () {
	return this.model.isInternal();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isMetaData = function () {
	return this.model.isMetaData();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isWrapped = function () {
	return this.model.isWrapped();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isUnwrappable = function () {
	return this.model.isUnwrappable();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.canContainContent = function () {
	return this.model.canContainContent();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isContent = function () {
	return this.model.isContent();
};
 
/**
 * @inheritdoc ve.Node
 *
 * If this is set to true it should implement:
 *
 *     setFocused( boolean val )
 *     boolean isFocused()
 */
ve.ce.Node.prototype.isFocusable = function () {
	return this.model.isFocusable();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isAlignable = function () {
	return this.model.isAlignable();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isCellable = function () {
	return this.model.isCellable();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.isCellEditable = function () {
	return this.model.isCellEditable();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.hasSignificantWhitespace = function () {
	return this.model.hasSignificantWhitespace();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.handlesOwnChildren = function () {
	return this.model.handlesOwnChildren();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.shouldIgnoreChildren = function () {
	return this.model.shouldIgnoreChildren();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.getLength = function () {
	return this.model.getLength();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.getOuterLength = function () {
	return this.model.getOuterLength();
};
 
/**
 * @inheritdoc ve.Node
 */
ve.ce.Node.prototype.getOffset = function () {
	return this.model.getOffset();
};
 
/**
 * Check if the node can be split.
 *
 * @return {boolean} Node can be split
 */
ve.ce.Node.prototype.splitOnEnter = function () {
	return this.constructor.static.splitOnEnter;
};
 
/**
 * Check if the node removes its empty last child on 'enter'.
 *
 * @return {boolean} Node removes empty last child on 'enter'
 */
ve.ce.Node.prototype.removeEmptyLastChildOnEnter = function () {
	return this.constructor.static.removeEmptyLastChildOnEnter;
};
 
/**
 * Check if the node is supports multiline input.
 *
 * Traverses upstream until a boolean value is found. If no value
 * is found, reads the default from the surface.
 *
 * @return {boolean} Node supports multiline input
 */
ve.ce.Node.prototype.isMultiline = function () {
	var booleanNode = this.traverseUpstream( function ( node ) {
		return node.constructor.static.isMultiline === null;
	} );
	Iif ( booleanNode ) {
		return booleanNode.constructor.static.isMultiline;
	} else {
		return !this.root || this.getRoot().getSurface().getSurface().isMultiline();
	}
};
 
/**
 * Check if the node can take the cursor when its surface is focused
 *
 * @return {boolean} Node can be take the cursor
 */
ve.ce.Node.prototype.autoFocus = function () {
	return this.constructor.static.autoFocus;
};
 
/**
 * Check if the node traps cursor when active
 *
 * @return {boolean} Node traps cursor
 */
ve.ce.Node.prototype.trapsCursor = function () {
	return this.constructor.static.trapsCursor;
};
 
/**
 * Release all memory.
 */
ve.ce.Node.prototype.destroy = function () {
	this.parent = null;
	this.root = null;
	this.doc = null;
 
	// Parent method
	ve.ce.Node.super.prototype.destroy.call( this );
};
 
/**
 * Get the model's HTML document
 *
 * @return {HTMLDocument} Model document
 */
ve.ce.Node.prototype.getModelHtmlDocument = function () {
	return this.model.getDocument() && this.model.getDocument().getHtmlDocument();
};