r97883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97882‎ | r97883 | r97884 >
Date:01:33, 23 September 2011
Author:inez
Status:deferred (Comments)
Tags:
Comment:
Little bit of a cleanup for getOffsetFromPosition
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js
@@ -18,10 +18,22 @@
1919
2020 /* Methods */
2121
 22+/**
 23+ * Gets the offset of a position.
 24+ *
 25+ * @method
 26+ * @param position {es.Position} Position to translate
 27+ * @returns {Integer} Offset nearest to position
 28+ */
2229 es.ListBlockView.prototype.getOffsetFromPosition = function( position ) {
23 - var contentOffset;
24 - var itemHeight;
25 - var offset = 0;
 30+ if ( this.items.length === 0 ) {
 31+ return 0;
 32+ }
 33+
 34+ var contentOffset,
 35+ itemHeight,
 36+ offset = 0;
 37+
2638 for ( var i = 0; i < this.items.length; i++ ) {
2739 contentOffset = this.items[i].$content.offset();
2840 if ( position.top >= contentOffset.top ) {
@@ -29,14 +41,27 @@
3042 if ( position.top < contentOffset.top + itemHeight ) {
3143 position.left -= contentOffset.left;
3244 position.top -= contentOffset.top;
33 - return offset + this.items[i].contentView.getOffset( position );
 45+ return offset + this.items[i].getContentOffset( position );
3446 }
3547 }
3648 offset += this.items[i].getLength() + 1;
3749 }
3850
39 - while(!documentView.list) {
40 -
 51+ throw 'Position coordinates are outside of the view.';
 52+};
 53+
 54+/**
 55+ * Draw selection around a given range.
 56+ *
 57+ * @method
 58+ * @param range {es.Range} Range of content to draw selection around
 59+ */
 60+es.ListBlockView.prototype.drawSelection = function( range ) {
 61+ var selectedItems = this.items.select( range );
 62+ for ( var i = 0; i < selectedItems.length; i++ ) {
 63+ selectedItems[i].item.drawSelection(
 64+ new es.Range( selectedItems[i].from, selectedItems[i].to )
 65+ );
4166 }
4267 };
4368
@@ -74,21 +99,6 @@
75100 };
76101
77102 /**
78 - * Draw selection around a given range.
79 - *
80 - * @method
81 - * @param range {es.Range} Range of content to draw selection around
82 - */
83 -es.ListBlockView.prototype.drawSelection = function( range ) {
84 - var selectedViews = this.items.select( range );
85 - for ( var i = 0; i < selectedViews.length; i++ ) {
86 - selectedViews[i].item.drawSelection(
87 - new es.Range( selectedViews[i].from, selectedViews[i].to )
88 - );
89 - }
90 -};
91 -
92 -/**
93103 * Gets length of contents.
94104 *
95105 * @method
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js
@@ -14,11 +14,18 @@
1515
1616 /* Methods */
1717
 18+/**
 19+ * Gets the offset of a position.
 20+ *
 21+ * @method
 22+ * @param position {es.Position} Position to translate
 23+ * @returns {Integer} Offset nearest to position
 24+ */
1825 es.TableBlockRowView.prototype.getOffsetFromPosition = function( position ) {
19 - var cellOffset;
20 - var itemWidth;
21 - var offset = 0;
22 -
 26+ var cellOffset,
 27+ itemWidth,
 28+ offset = 0;
 29+
2330 for ( var i = 0; i < this.items.length; i++ ) {
2431 cellOffset = this.items[i].$.offset();
2532 if ( position.left >= cellOffset.left ) {
@@ -29,6 +36,8 @@
3037 }
3138 offset += this.items[i].getLength() + 1;
3239 }
 40+
 41+ throw 'Position coordinates are outside of the view.';
3342 };
3443
3544 /**
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js
@@ -17,6 +17,13 @@
1818
1919 /* Methods */
2020
 21+/**
 22+ * Gets the offset of a position.
 23+ *
 24+ * @method
 25+ * @param position {es.Position} Position to translate
 26+ * @returns {Integer} Offset nearest to position
 27+ */
2128 es.ParagraphBlockView.prototype.getOffsetFromPosition = function( position ) {
2229 var blockPosition = this.$.offset();
2330 position.left -= blockPosition.left;
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js
@@ -13,10 +13,17 @@
1414
1515 /* Methods */
1616
 17+/**
 18+ * Gets the offset of a position.
 19+ *
 20+ * @method
 21+ * @param position {es.Position} Position to translate
 22+ * @returns {Integer} Offset nearest to position
 23+ */
1724 es.TableBlockCellView.prototype.getOffsetFromPosition = function( position ) {
18 - var blockOffset;
19 - var itemHeight;
20 - var offset = 0;
 25+ var blockOffset,
 26+ itemHeight,
 27+ offset = 0;
2128
2229 for ( var i = 0; i < this.items.length; i++ ) {
2330 blockOffset = this.items[i].$.offset();
@@ -28,6 +35,8 @@
2936 }
3037 offset += this.items[i].getLength() + 1;
3138 }
 39+
 40+ throw 'Position coordinates are outside of the view.';
3241 };
3342
3443 /**
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js
@@ -15,10 +15,21 @@
1616
1717 /* Methods */
1818
 19+/**
 20+ * Gets the offset of a position.
 21+ *
 22+ * @method
 23+ * @param position {es.Position} Position to translate
 24+ * @returns {Integer} Offset nearest to position
 25+ */
1926 es.TableBlockView.prototype.getOffsetFromPosition = function( position ) {
20 - var rowOffset;
21 - var itemHeight;
22 - var offset = 0;
 27+ if ( this.items.length === 0 ) {
 28+ return 0;
 29+ }
 30+
 31+ var rowOffset,
 32+ itemHeight,
 33+ offset = 0;
2334
2435 for ( var i = 0; i < this.items.length; i++ ) {
2536 rowOffset = this.items[i].$.offset();
@@ -30,6 +41,8 @@
3142 }
3243 offset += this.items[i].getLength() + 1;
3344 }
 45+
 46+ throw 'Position coordinates are outside of the view.';
3447 };
3548
3649 /**

Comments

#Comment by Krinkle (talk | contribs)   01:44, 23 September 2011
-	var rowOffset;
-	var itemHeight;
-	var offset = 0;
+	if ( this.items.length === 0 ) {
+		return 0;
+	}
+	
+	var rowOffset,
+		itemHeight,
+		offset = 0;

In core we use a tab after the word "var" as well (instead of a space), that way the variable names line up (regardless of whether the tab indention is 4, 8 or different number of characters)

Status & tagging log