| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ce.View = function VeCeView( model, config ) { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
this.model = model; |
| 23 |
|
| 24 |
|
| 25 |
ve.ce.View.super.call( this, config ); |
| 26 |
|
| 27 |
|
| 28 |
OO.EventEmitter.call( this ); |
| 29 |
|
| 30 |
|
| 31 |
this.live = false; |
| 32 |
|
| 33 |
|
| 34 |
this.connect( this, { |
| 35 |
setup: 'onSetup', |
| 36 |
teardown: 'onTeardown' |
| 37 |
} ); |
| 38 |
|
| 39 |
|
| 40 |
this.initialize(); |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
OO.inheritClass( ve.ce.View, OO.ui.Element ); |
| 46 |
|
| 47 |
OO.mixinClass( ve.ce.View, OO.EventEmitter ); |
| 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 |
ve.ce.View.static.renderHtmlAttributes = function ( attribute ) { |
| 79 |
const attributes = [ |
| 80 |
'abbr', 'about', 'align', 'alt', 'axis', 'bgcolor', 'border', 'cellpadding', 'cellspacing', |
| 81 |
'char', 'charoff', 'cite', 'class', 'clear', 'color', 'colspan', 'datatype', 'datetime', |
| 82 |
'dir', 'face', 'frame', 'headers', 'height', 'href', 'id', 'itemid', 'itemprop', 'itemref', |
| 83 |
'itemscope', 'itemtype', 'lang', 'noshade', 'nowrap', 'property', 'rbspan', 'rel', |
| 84 |
'resource', 'rev', 'rowspan', 'rules', 'scope', 'size', 'span', 'src', 'start', 'style', |
| 85 |
'summary', 'title', 'type', 'typeof', 'valign', 'value', 'width' |
| 86 |
]; |
| 87 |
return attributes.indexOf( attribute ) !== -1; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
ve.ce.View.prototype.getModelHtmlDocument = function () { |
| 102 |
return null; |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
ve.ce.View.prototype.initialize = function () { |
| 110 |
if ( this.model.element && this.model.element.originalDomElementsHash !== undefined ) { |
| 111 |
|
| 112 |
ve.dm.Converter.static.renderHtmlAttributeList( |
| 113 |
this.model.getOriginalDomElements( this.model.getStore() ), |
| 114 |
this.$element, |
| 115 |
this.constructor.static.renderHtmlAttributes, |
| 116 |
|
| 117 |
true, |
| 118 |
|
| 119 |
!( this.model instanceof ve.dm.Node ) || |
| 120 |
!this.model.canHaveChildren() || |
| 121 |
this.model.handlesOwnChildren() |
| 122 |
); |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
ve.ce.View.prototype.onSetup = function () { |
| 130 |
this.$element.data( 'view', this ); |
| 131 |
}; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
ve.ce.View.prototype.onTeardown = function () { |
| 137 |
this.$element.removeData( 'view' ); |
| 138 |
}; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
ve.ce.View.prototype.getModel = function () { |
| 146 |
return this.model; |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
ve.ce.View.prototype.isLive = function () { |
| 155 |
return this.live; |
| 156 |
}; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
ve.ce.View.prototype.setLive = function ( live ) { |
| 166 |
this.live = live; |
| 167 |
if ( this.live ) { |
| 168 |
this.emit( 'setup' ); |
| 169 |
} else { |
| 170 |
this.emit( 'teardown' ); |
| 171 |
} |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
ve.ce.View.prototype.getResolvedAttribute = function ( key ) { |
| 181 |
const plainValue = this.model.getAttribute( key ), |
| 182 |
doc = this.getModelHtmlDocument(); |
| 183 |
return doc && typeof plainValue === 'string' ? ve.resolveUrl( plainValue, doc ) : plainValue; |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
ve.ce.View.prototype.destroy = function () { |
| 190 |
this.disconnect( this ); |
| 191 |
this.model.disconnect( this ); |
| 192 |
this.model = null; |
| 193 |
}; |