| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ui.ContextItem = function VeUiContextItem( context, model, config ) { |
| 19 |
|
| 20 |
ve.ui.ContextItem.super.call( this, config ); |
| 21 |
|
| 22 |
|
| 23 |
this.context = context; |
| 24 |
this.model = model; |
| 25 |
this.fragment = null; |
| 26 |
|
| 27 |
|
| 28 |
this.$element.on( 'mousedown', () => { |
| 29 |
|
| 30 |
|
| 31 |
context.getSurface().getView().deactivate(); |
| 32 |
} ); |
| 33 |
this.$element.on( 'keydown', ( e ) => { |
| 34 |
|
| 35 |
|
| 36 |
if ( e.keyCode === OO.ui.Keys.ESCAPE && context.getSurface().getView().isDeactivated() ) { |
| 37 |
context.getSurface().getView().activate(); |
| 38 |
return false; |
| 39 |
} |
| 40 |
} ); |
| 41 |
|
| 42 |
|
| 43 |
this.$element.addClass( 've-ui-contextItem' ); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
OO.inheritClass( ve.ui.ContextItem, OO.ui.Widget ); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
ve.ui.ContextItem.static.exclusive = true; |
| 68 |
|
| 69 |
ve.ui.ContextItem.static.commandName = null; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
ve.ui.ContextItem.static.sortOrder = 0; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
ve.ui.ContextItem.static.modelClasses = []; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
ve.ui.ContextItem.static.suppresses = []; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
ve.ui.ContextItem.static.isCompatibleWith = function ( model ) { |
| 115 |
return ve.isInstanceOfAny( model, this.modelClasses ); |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
ve.ui.ContextItem.prototype.isNode = function () { |
| 124 |
return this.model && this.model instanceof ve.dm.Node; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ui.ContextItem.prototype.getCommand = function () { |
| 133 |
return this.context.getSurface().commandRegistry.lookup( this.constructor.static.commandName ); |
| 134 |
}; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.ui.ContextItem.prototype.getFragment = function () { |
| 142 |
if ( !this.fragment ) { |
| 143 |
const surfaceModel = this.context.getSurface().getModel(); |
| 144 |
this.fragment = this.isNode() ? |
| 145 |
surfaceModel.getLinearFragment( this.model.getOuterRange() ) : |
| 146 |
surfaceModel.getFragment(); |
| 147 |
} |
| 148 |
return this.fragment; |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
ve.ui.ContextItem.prototype.isReadOnly = function () { |
| 157 |
return this.context.getSurface().isReadOnly(); |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
ve.ui.ContextItem.prototype.equals = function ( other ) { |
| 167 |
return this.constructor.static.name === other.constructor.static.name && |
| 168 |
this.getFragment().getSelection().equals( other.getFragment().getSelection() ); |
| 169 |
}; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
ve.ui.ContextItem.prototype.setup = function () { |
| 179 |
return this; |
| 180 |
}; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
ve.ui.ContextItem.prototype.teardown = function () { |
| 189 |
return this; |
| 190 |
}; |