| 1 | /*! |
| 2 | * VisualEditor DataModel GeneratedContentNode class. |
| 3 | * |
| 4 | * @copyright See AUTHORS.txt |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * DataModel generated content node. |
| 9 | * |
| 10 | * @class |
| 11 | * @abstract |
| 12 | * |
| 13 | * @constructor |
| 14 | */ |
| 15 | ve.dm.GeneratedContentNode = function VeDmGeneratedContentNode() { |
| 16 | }; |
| 17 | |
| 18 | /* Inheritance */ |
| 19 | |
| 20 | OO.initClass( ve.dm.GeneratedContentNode ); |
| 21 | |
| 22 | /* Events */ |
| 23 | |
| 24 | /** |
| 25 | * @event ve.dm.GeneratedContentNode#generatedContentsError |
| 26 | * @param {jQuery} $element Element containing the error message |
| 27 | */ |
| 28 | |
| 29 | /* Static methods */ |
| 30 | |
| 31 | /** |
| 32 | * Store HTML of DOM elements, hashed on data element |
| 33 | * |
| 34 | * @static |
| 35 | * @param {Object} dataElement Data element |
| 36 | * @param {Object|string|Array} generatedContents Generated contents |
| 37 | * @param {ve.dm.HashValueStore} store Hash-value store |
| 38 | * @return {string} Hash of stored data |
| 39 | */ |
| 40 | ve.dm.GeneratedContentNode.static.storeGeneratedContents = function ( dataElement, generatedContents, store ) { |
| 41 | const hash = OO.getHash( [ this.getHashObjectForRendering( dataElement ), undefined ] ); |
| 42 | return store.hash( generatedContents, hash ); |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * Get as hash object that uniquely describes the rendering |
| 47 | * |
| 48 | * Sub-classes can simplify this hash if certain attributes |
| 49 | * don't affect the rendering. |
| 50 | * |
| 51 | * @static |
| 52 | * @param {Object} dataElement Data element |
| 53 | * @return {Object} Hash object |
| 54 | */ |
| 55 | ve.dm.GeneratedContentNode.static.getHashObjectForRendering = function ( dataElement ) { |
| 56 | return this.getHashObject( dataElement ); |
| 57 | }; |
| 58 | |
| 59 | /* Methods */ |
| 60 | |
| 61 | /** |
| 62 | * Get as hash object that uniquely describes the rendering |
| 63 | * |
| 64 | * The actual logic is in a static function as this needs |
| 65 | * to be accessible from ve.dm.Converter |
| 66 | * |
| 67 | * @return {Object} Hash object |
| 68 | */ |
| 69 | ve.dm.GeneratedContentNode.prototype.getHashObjectForRendering = function () { |
| 70 | return this.constructor.static.getHashObjectForRendering( this.element ); |
| 71 | }; |