Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/annotations/ve.ce.NailedAnnotation.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable NailedAnnotation class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * ContentEditable nailed annotation.
9 *
10 * @class
11 * @abstract
12 * @constructor
13 */
14 ve.ce.NailedAnnotation = function VeCeNailedAnnotation() {
15 // Initialization
16 this.contentFragment = document.createDocumentFragment();
17
18 this.$element.addClass( 've-ce-nailedAnnotation' );
19 };
20
21 /* Inheritance */
22
23 OO.initClass( ve.ce.NailedAnnotation );
24
25 /* Static Properties */
26
27 ve.ce.NailedAnnotation.static.canBeActive = true;
28
29 /* Static Methods */
30
31 /**
32 * Create a nail (a zero-width image) to add extra cursor positions around annotations
33 *
34 * @param {string} type Nail type, one of 'pre-open', 'pre-close', 'post-open' and 'post-close'
35 * @return {HTMLElement} The new nail
36 */
37 ve.ce.NailedAnnotation.static.makeNail = function ( type ) {
38 const nail = document.createElement( 'img' );
39 // Support: Firefox
40 // Firefox <=37 misbehaves if we don't set an src: https://bugzilla.mozilla.org/show_bug.cgi?id=989012
41 // Firefox <= ~69 misbehaves if we don't set an src and there is no sizing at node creation time: https://bugzilla.mozilla.org/show_bug.cgi?id=1267906
42 // Setting an src in Chrome is slow, so only set it in affected versions of Firefox
43 if ( $.client.profile().layout === 'gecko' || ve.inputDebug ) {
44 nail.src = ve.inputDebug ? ve.ce.nailImgDataUri : ve.ce.minImgDataUri;
45 }
46 // The following classes are used here:
47 // * ve-ce-nail-pre-open
48 // * ve-ce-nail-pre-close
49 // * ve-ce-nail-post-open
50 // * ve-ce-nail-post-close
51 nail.className = 've-ce-nail ve-ce-nail-' + type + ( ve.inputDebug ? ' ve-ce-nail-debug' : '' );
52 return nail;
53 };
54
55 /* Methods */
56
57 // eslint-disable-next-line jsdoc/require-returns
58 /**
59 * @see ve.ce.Annotation
60 */
61 ve.ce.NailedAnnotation.prototype.getContentContainer = function () {
62 return this.contentFragment;
63 };
64
65 /**
66 * @see ve.ce.Annotation
67 */
68 ve.ce.NailedAnnotation.prototype.attachContents = function () {
69 const element = this.$element[ 0 ];
70 // Insert post-open nail, annotation contents, and pre-close nail into the element
71 element.appendChild( this.constructor.static.makeNail( 'post-open' ) );
72 element.appendChild( this.contentFragment );
73 element.appendChild( this.constructor.static.makeNail( 'pre-close' ) );
74 };
75
76 // eslint-disable-next-line jsdoc/require-param
77 /**
78 * @see ve.ce.Annotation
79 */
80 ve.ce.NailedAnnotation.prototype.appendTo = function ( node ) {
81 // Insert pre-open nail, element, and post-close nail into a parent node
82 node.appendChild( this.constructor.static.makeNail( 'pre-open' ) );
83 node.appendChild( this.$element[ 0 ] );
84 node.appendChild( this.constructor.static.makeNail( 'post-close' ) );
85 };