| 1 |
'use strict'; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ce.MWReferenceNode = function VeCeMWReferenceNode() { |
| 20 |
|
| 21 |
ve.ce.MWReferenceNode.super.apply( this, arguments ); |
| 22 |
|
| 23 |
|
| 24 |
ve.ce.FocusableNode.call( this ); |
| 25 |
|
| 26 |
|
| 27 |
this.$link = $( '<a>' ).attr( 'href', '#' ); |
| 28 |
this.$element.addClass( 've-ce-mwReferenceNode mw-ref reference' ).append( this.$link ); |
| 29 |
this.$text = $( '<span>' ).addClass( 'mw-reflink-text' ); |
| 30 |
this.$link.append( this.$text ); |
| 31 |
|
| 32 |
this.index = ''; |
| 33 |
this.internalList = this.model.getDocument().internalList; |
| 34 |
|
| 35 |
|
| 36 |
this.connect( this, { |
| 37 |
setup: 'onSetup', |
| 38 |
teardown: 'onTeardown' |
| 39 |
} ); |
| 40 |
this.model.connect( this, { attributeChange: 'onAttributeChange' } ); |
| 41 |
|
| 42 |
|
| 43 |
this.update(); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
OO.inheritClass( ve.ce.MWReferenceNode, ve.ce.LeafNode ); |
| 49 |
|
| 50 |
OO.mixinClass( ve.ce.MWReferenceNode, ve.ce.FocusableNode ); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
ve.ce.MWReferenceNode.static.name = 'mwReference'; |
| 55 |
|
| 56 |
ve.ce.MWReferenceNode.static.tagName = 'sup'; |
| 57 |
|
| 58 |
ve.ce.MWReferenceNode.static.primaryCommandName = 'reference'; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.ce.MWReferenceNode.prototype.onSetup = function () { |
| 66 |
ve.ce.MWReferenceNode.super.prototype.onSetup.call( this ); |
| 67 |
|
| 68 |
this.internalList.connect( this, { update: 'onInternalListUpdate' } ); |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
ve.ce.MWReferenceNode.prototype.onTeardown = function () { |
| 75 |
|
| 76 |
|
| 77 |
this.internalList.disconnect( this ); |
| 78 |
|
| 79 |
ve.ce.MWReferenceNode.super.prototype.onTeardown.call( this ); |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ve.ce.MWReferenceNode.prototype.onInternalListUpdate = function ( groupsChanged ) { |
| 90 |
|
| 91 |
if ( groupsChanged.indexOf( this.model.getAttribute( 'listGroup' ) ) !== -1 ) { |
| 92 |
this.update(); |
| 93 |
} |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
ve.ce.MWReferenceNode.prototype.onAttributeChange = function ( key ) { |
| 104 |
if ( key === 'placeholder' ) { |
| 105 |
this.update(); |
| 106 |
} |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
ve.ce.MWReferenceNode.prototype.executeCommand = function () { |
| 114 |
const items = ve.ui.contextItemFactory.getRelatedItems( [ this.model ] ); |
| 115 |
|
| 116 |
if ( items.length ) { |
| 117 |
const contextItem = ve.ui.contextItemFactory.lookup( items[ 0 ].name ); |
| 118 |
if ( contextItem ) { |
| 119 |
const command = this.getRoot().getSurface().getSurface().commandRegistry |
| 120 |
.lookup( contextItem.static.commandName ); |
| 121 |
if ( command ) { |
| 122 |
command.execute( this.focusableSurface.getSurface() ); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
ve.ce.MWReferenceNode.prototype.update = function () { |
| 132 |
this.$text.html( this.model.getIndexLabel() ); |
| 133 |
this.$link |
| 134 |
.attr( 'data-mw-group', this.model.getGroup() || null ); |
| 135 |
this.$element.toggleClass( 've-ce-mwReferenceNode-placeholder', !!this.model.getAttribute( 'placeholder' ) ); |
| 136 |
}; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
ve.ce.nodeFactory.register( ve.ce.MWReferenceNode ); |