r101410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101409‎ | r101410 | r101411 >
Date:21:34, 31 October 2011
Author:inez
Status:deferred
Tags:
Comment:
Fix/adjust methods getOffsetFromRenderedPosition and getRenderedPositionFromOffset in DocumentViewBranch to match new DocumentModel structure
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/bases/es.DocumentViewBranchNode.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/views/es.TableRowView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentViewBranchNode.js
@@ -7,7 +7,8 @@
88 * @param model {es.ModelNode} Model to observe
99 * @param {jQuery} [$element] Element to use as a container
1010 */
11 -es.DocumentViewBranchNode = function( model, $element ) {
 11+es.DocumentViewBranchNode = function( model, $element, horizontal ) {
 12+ this.horizontal = horizontal || false;
1213 // Extension
1314 return es.extendObject( new es.DocumentNode( new es.ViewNode( model, $element ) ), this );
1415 };
@@ -69,13 +70,15 @@
7071 }
7172 var node = this[0];
7273 for ( var i = 1; i < this.length; i++ ) {
73 - if ( this[i].$.offset().top > position.top ) {
 74+ if ( this.horizontal && this[i].$.offset().left > position.left ) {
7475 break;
 76+ } else if ( this[i].$.offset().top > position.top ) {
 77+ break;
7578 }
7679 node = this[i];
7780 }
7881 return node.getParent().getOffsetFromNode( node, true ) +
79 - node.getOffsetFromRenderedPosition( position );
 82+ node.getOffsetFromRenderedPosition( position ) + 1;
8083 };
8184
8285 /**
@@ -88,7 +91,7 @@
8992 es.DocumentViewBranchNode.prototype.getRenderedPositionFromOffset = function( offset ) {
9093 var node = this.getNodeFromOffset( offset, true );
9194 if ( node !== null ) {
92 - return node.getRenderedPositionFromOffset( offset - this.getOffsetFromNode( node, true ) );
 95+ return node.getRenderedPositionFromOffset( offset - this.getOffsetFromNode( node, true ) - 1);
9396 }
9497 return null;
9598 };
Index: trunk/parsers/wikidom/lib/hype/views/es.TableRowView.js
@@ -7,35 +7,7 @@
88 */
99 es.TableRowView = function( model ) {
1010 // Extension
11 - var view = es.extendObject( new es.DocumentViewBranchNode( model, $( '<tr>' ) ), this );
 11+ var view = es.extendObject( new es.DocumentViewBranchNode( model, $( '<tr>' ), true ), this );
1212 view.$.attr( 'style', model.getElementAttribute( 'html/style' ) );
1313 return view;
14 -};
15 -
16 -/**
17 - * Gets the nearest offset of a rendered position.
18 - *
19 - * The only difference between this method and one in DocumentViewBranchNode is that it checks
20 - * 'left' property of position instead of 'top'. If such case will become more frequent lets
21 - * consider having private property in DocumentViewBranchNode which defines if horizontal
22 - * or vertical scanning should be executed.
23 - *
24 - * @method
25 - * @param {es.Position} position Position to get offset for
26 - * @returns {Integer} Offset of position
27 - */
28 -es.TableRowView.prototype.getOffsetFromRenderedPosition = function( position ) {
29 - if ( this.length === 0 ) {
30 - return 0;
31 - }
32 - var node = this[0];
33 - for ( var i = 1; i < this.length; i++ ) {
34 - if ( this[i].$.offset().left > position.left ) {
35 - break;
36 - }
37 - node = this[i];
38 - }
39 - return node.getParent().getOffsetFromNode( node, true ) +
40 - node.getOffsetFromRenderedPosition( position );
41 -};
42 -
 14+};
\ No newline at end of file

Status & tagging log