| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ve.ui.DimensionsWidget = function VeUiDimensionsWidget( config ) { |
| 21 |
|
| 22 |
config = config || {}; |
| 23 |
|
| 24 |
|
| 25 |
ve.ui.DimensionsWidget.super.call( this, config ); |
| 26 |
|
| 27 |
this.widthInput = new OO.ui.TextInputWidget( { |
| 28 |
validate: config.validate || $.isNumeric |
| 29 |
} ); |
| 30 |
this.widthInput.$input.attr( 'aria-label', ve.msg( 'visualeditor-dimensionswidget-width' ) ); |
| 31 |
this.heightInput = new OO.ui.TextInputWidget( { |
| 32 |
validate: config.validate || $.isNumeric |
| 33 |
} ); |
| 34 |
this.heightInput.$input.attr( 'aria-label', ve.msg( 'visualeditor-dimensionswidget-height' ) ); |
| 35 |
|
| 36 |
this.defaults = config.defaults || { width: '', height: '' }; |
| 37 |
this.setReadOnly( !!config.readOnly ); |
| 38 |
this.renderDefaults(); |
| 39 |
|
| 40 |
const labelTimes = new OO.ui.LabelWidget( { |
| 41 |
label: ve.msg( 'visualeditor-dimensionswidget-times' ) |
| 42 |
} ); |
| 43 |
const labelPx = new OO.ui.LabelWidget( { |
| 44 |
label: ve.msg( 'visualeditor-dimensionswidget-px' ) |
| 45 |
} ); |
| 46 |
|
| 47 |
|
| 48 |
this.widthInput.connect( this, { change: 'onWidthChange' } ); |
| 49 |
this.heightInput.connect( this, { change: 'onHeightChange' } ); |
| 50 |
|
| 51 |
|
| 52 |
this.$element |
| 53 |
.addClass( 've-ui-dimensionsWidget' ) |
| 54 |
.append( |
| 55 |
this.widthInput.$element, |
| 56 |
labelTimes.$element |
| 57 |
.addClass( 've-ui-dimensionsWidget-label-times' ), |
| 58 |
this.heightInput.$element, |
| 59 |
labelPx.$element |
| 60 |
.addClass( 've-ui-dimensionsWidget-label-px' ) |
| 61 |
); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
OO.inheritClass( ve.ui.DimensionsWidget, OO.ui.Widget ); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
ve.ui.DimensionsWidget.prototype.onWidthChange = function ( value ) { |
| 89 |
this.emit( 'widthChange', value ); |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
ve.ui.DimensionsWidget.prototype.onHeightChange = function ( value ) { |
| 99 |
this.emit( 'heightChange', value ); |
| 100 |
}; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
ve.ui.DimensionsWidget.prototype.setDefaults = function ( dimensions ) { |
| 110 |
if ( dimensions.width && dimensions.height ) { |
| 111 |
this.defaults = ve.copy( dimensions ); |
| 112 |
this.renderDefaults(); |
| 113 |
} |
| 114 |
return this; |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
ve.ui.DimensionsWidget.prototype.renderDefaults = function () { |
| 121 |
this.widthInput.$input.prop( 'placeholder', this.getDefaults().width ); |
| 122 |
this.heightInput.$input.prop( 'placeholder', this.getDefaults().height ); |
| 123 |
}; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ve.ui.DimensionsWidget.prototype.getDefaults = function () { |
| 131 |
return this.defaults; |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
ve.ui.DimensionsWidget.prototype.removeDefaults = function () { |
| 141 |
this.defaults = { width: '', height: '' }; |
| 142 |
this.renderDefaults(); |
| 143 |
return this; |
| 144 |
}; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
ve.ui.DimensionsWidget.prototype.isEmpty = function () { |
| 152 |
return ( |
| 153 |
this.widthInput.getValue() === '' && |
| 154 |
this.heightInput.getValue() === '' |
| 155 |
); |
| 156 |
}; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
ve.ui.DimensionsWidget.prototype.clear = function () { |
| 166 |
this.widthInput.setValue( '' ); |
| 167 |
this.heightInput.setValue( '' ); |
| 168 |
return this; |
| 169 |
}; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
ve.ui.DimensionsWidget.prototype.reset = function () { |
| 178 |
this.setDimensions( this.getDefaults() ); |
| 179 |
return this; |
| 180 |
}; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
ve.ui.DimensionsWidget.prototype.setDimensions = function ( dimensions ) { |
| 192 |
if ( dimensions.width ) { |
| 193 |
this.setWidth( dimensions.width ); |
| 194 |
} |
| 195 |
if ( dimensions.height ) { |
| 196 |
this.setHeight( dimensions.height ); |
| 197 |
} |
| 198 |
return this; |
| 199 |
}; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
ve.ui.DimensionsWidget.prototype.getDimensions = function () { |
| 214 |
return { |
| 215 |
width: +this.widthInput.getValue(), |
| 216 |
height: +this.heightInput.getValue() |
| 217 |
}; |
| 218 |
}; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
ve.ui.DimensionsWidget.prototype.setDisabled = function ( disabled ) { |
| 228 |
|
| 229 |
ve.ui.DimensionsWidget.super.prototype.setDisabled.call( this, disabled ); |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
if ( this.widthInput ) { |
| 234 |
this.widthInput.setDisabled( disabled ); |
| 235 |
} |
| 236 |
if ( this.heightInput ) { |
| 237 |
this.heightInput.setDisabled( disabled ); |
| 238 |
} |
| 239 |
return this; |
| 240 |
}; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
ve.ui.DimensionsWidget.prototype.isReadOnly = function () { |
| 248 |
return this.readOnly; |
| 249 |
}; |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
ve.ui.DimensionsWidget.prototype.setReadOnly = function ( readOnly ) { |
| 259 |
this.readOnly = readOnly; |
| 260 |
this.widthInput.setReadOnly( readOnly ); |
| 261 |
this.heightInput.setReadOnly( readOnly ); |
| 262 |
return this; |
| 263 |
}; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
ve.ui.DimensionsWidget.prototype.getWidth = function () { |
| 271 |
return this.widthInput.getValue(); |
| 272 |
}; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
ve.ui.DimensionsWidget.prototype.getHeight = function () { |
| 280 |
return this.heightInput.getValue(); |
| 281 |
}; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
ve.ui.DimensionsWidget.prototype.setWidth = function ( value ) { |
| 291 |
this.widthInput.setValue( value ); |
| 292 |
return this; |
| 293 |
}; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
ve.ui.DimensionsWidget.prototype.setHeight = function ( value ) { |
| 303 |
this.heightInput.setValue( value ); |
| 304 |
return this; |
| 305 |
}; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
ve.ui.DimensionsWidget.prototype.setValidityFlag = function () { |
| 314 |
this.widthInput.setValidityFlag(); |
| 315 |
this.heightInput.setValidityFlag(); |
| 316 |
return this; |
| 317 |
}; |