r93312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93311‎ | r93312 | r93313 >
Date:20:52, 27 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Moved utility classes into their own files.
Modified paths:
  • /trunk/parsers/wikidom/demos/es/index.html (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Location.js (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.Position.js (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.Range.js (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.Selection.js (added) (history)
  • /trunk/parsers/wikidom/lib/es/es.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.js
@@ -36,158 +36,3 @@
3737 }
3838 }
3939 }
40 -
41 -/**
42 - * Range of content.
43 - *
44 - * @param start {Integer} Starting point
45 - * @param end {Integer} Ending point
46 - * @returns {es.Range}
47 - */
48 -es.Range = function( start, end ) {
49 - this.start = start || null;
50 - this.end = end || null;
51 -}
52 -
53 -/**
54 - * Pixel position, a 2D position within a rendered document.
55 - *
56 - * This can also support an optional bottom field, to represent a vertical line, such as a cursor.
57 - *
58 - * @param left {Integer} Horizontal position
59 - * @param top {Integer} Vertical top position
60 - * @param bottom {Integer} Vertical bottom position of bottom (optional, default: top)
61 - * @returns {es.Position}
62 - */
63 -es.Position = function( left, top, bottom ) {
64 - this.left = left || 0;
65 - this.top = top || 0;
66 - this.bottom = bottom || this.top;
67 -};
68 -
69 -es.Position.newFromEventScreenPosition = function( event ) {
70 - return new es.Position( event.screenX, event.screenY );
71 -};
72 -
73 -es.Position.newFromEventPagePosition = function( event ) {
74 - return new es.Position( event.pageX, event.pageY );
75 -};
76 -
77 -es.Position.newFromEventLayerPosition = function( event ) {
78 - return new es.Position( event.layerX, event.layerY );
79 -};
80 -
81 -es.Position.prototype.at = function( position ) {
82 - return this.left === position.left && this.top === position.top;
83 -};
84 -
85 -es.Position.prototype.perpendicularWith = function( position ) {
86 - return this.left === position.left || this.top === position.top;
87 -};
88 -
89 -es.Position.prototype.levelWith = function( position ) {
90 - return this.top === position.top;
91 -};
92 -
93 -es.Position.prototype.plumbWith = function( position ) {
94 - return this.left === position.left;
95 -};
96 -
97 -es.Position.prototype.near = function( position, range ) {
98 - var x = this.left - position.left,
99 - y = this.top - position.top;
100 - return Math.sqrt( x * x, y * y ) <= range;
101 -};
102 -
103 -es.Position.prototype.above = function( position ) {
104 - return this.bottom < position.top;
105 -};
106 -
107 -es.Position.prototype.below = function( position ) {
108 - return this.top > position.bottom;
109 -};
110 -
111 -es.Position.prototype.leftOf = function( left ) {
112 - return this.left < left;
113 -};
114 -
115 -es.Position.prototype.rightOf = function( left ) {
116 - return this.left > left;
117 -};
118 -
119 -/**
120 - * Content location, an offset within a block.
121 - *
122 - * @param block {es.Block} Location target
123 - * @param offset {Integer} Location offset
124 - * @returns {es.Location}
125 - */
126 -es.Location = function( block, offset ) {
127 - this.block = block;
128 - this.offset = offset || 0;
129 -}
130 -
131 -/**
132 - * Content selection, a pair of locations.
133 - *
134 - * @param from {es.Location} Starting location
135 - * @param to {es.Location} Ending location
136 - * @returns {es.Selection}
137 - */
138 -es.Selection = function( from, to ) {
139 - this.from = from;
140 - this.to = to;
141 - this.start = from;
142 - this.end = to;
143 -}
144 -
145 -/**
146 - * Ensures that "from" is before "to".
147 - */
148 -es.Selection.prototype.normalize = function() {
149 - if ( this.from.block.getIndex() < this.to.block.getIndex()
150 - || ( this.from.block === this.to.block && this.from.offset < this.to.offset ) ) {
151 - this.start = this.from;
152 - this.end = this.to;
153 - } else {
154 - this.start = this.to;
155 - this.end = this.from;
156 - }
157 -};
158 -
159 -/**
160 - * Gets all blocks selected completely, between from and to.
161 - *
162 - * If from and to are adjacent blocks, or the same block, the result will always be an empty array.
163 - *
164 - * @returns {Array} List of blocks
165 - */
166 -es.Selection.prototype.through = function() {
167 - var through = [];
168 - if ( this.from !== this.to && this.from.nextBlock() !== this.to ) {
169 - var next = this.from.nextBlock();
170 - while ( next && next !== this.to ) {
171 - through.push( next );
172 - next = next.nextBlock();
173 - }
174 - }
175 - return through;
176 -};
177 -
178 -es.Content = function( data ) {
179 - this.setData( data );
180 -}
181 -
182 -es.Content.prototype.setData = function( data ) {
183 - // Data type detection
184 - if ( typeof data === 'string' ) {
185 - this.type = 'string';
186 - } else if ( $.isArray( data ) ) {
187 - // TODO
188 - } else if ( $.isPlainObject( data ) ) {
189 - if ( 'type' in data && '' ) {
190 - // TODO
191 - }
192 - }
193 - this.data = data;
194 -};
Index: trunk/parsers/wikidom/lib/es/es.Position.js
@@ -0,0 +1,65 @@
 2+/**
 3+ * Pixel position, a 2D position within a rendered document.
 4+ *
 5+ * This can also support an optional bottom field, to represent a vertical line, such as a cursor.
 6+ *
 7+ * @param left {Integer} Horizontal position
 8+ * @param top {Integer} Vertical top position
 9+ * @param bottom {Integer} Vertical bottom position of bottom (optional, default: top)
 10+ * @returns {es.Position}
 11+ */
 12+es.Position = function( left, top, bottom ) {
 13+ this.left = left || 0;
 14+ this.top = top || 0;
 15+ this.bottom = bottom || this.top;
 16+};
 17+
 18+es.Position.newFromEventScreenPosition = function( event ) {
 19+ return new es.Position( event.screenX, event.screenY );
 20+};
 21+
 22+es.Position.newFromEventPagePosition = function( event ) {
 23+ return new es.Position( event.pageX, event.pageY );
 24+};
 25+
 26+es.Position.newFromEventLayerPosition = function( event ) {
 27+ return new es.Position( event.layerX, event.layerY );
 28+};
 29+
 30+es.Position.prototype.at = function( position ) {
 31+ return this.left === position.left && this.top === position.top;
 32+};
 33+
 34+es.Position.prototype.perpendicularWith = function( position ) {
 35+ return this.left === position.left || this.top === position.top;
 36+};
 37+
 38+es.Position.prototype.levelWith = function( position ) {
 39+ return this.top === position.top;
 40+};
 41+
 42+es.Position.prototype.plumbWith = function( position ) {
 43+ return this.left === position.left;
 44+};
 45+
 46+es.Position.prototype.near = function( position, range ) {
 47+ var x = this.left - position.left,
 48+ y = this.top - position.top;
 49+ return Math.sqrt( x * x, y * y ) <= range;
 50+};
 51+
 52+es.Position.prototype.above = function( position ) {
 53+ return this.bottom < position.top;
 54+};
 55+
 56+es.Position.prototype.below = function( position ) {
 57+ return this.top > position.bottom;
 58+};
 59+
 60+es.Position.prototype.leftOf = function( left ) {
 61+ return this.left < left;
 62+};
 63+
 64+es.Position.prototype.rightOf = function( left ) {
 65+ return this.left > left;
 66+};
Property changes on: trunk/parsers/wikidom/lib/es/es.Position.js
___________________________________________________________________
Added: svn:eol-style
167 + native
Added: svn:mime-type
268 + text/plain
Index: trunk/parsers/wikidom/lib/es/es.Location.js
@@ -0,0 +1,11 @@
 2+/**
 3+ * Content location, an offset within a block.
 4+ *
 5+ * @param block {es.Block} Location target
 6+ * @param offset {Integer} Location offset
 7+ * @returns {es.Location}
 8+ */
 9+es.Location = function( block, offset ) {
 10+ this.block = block;
 11+ this.offset = offset || 0;
 12+}
Property changes on: trunk/parsers/wikidom/lib/es/es.Location.js
___________________________________________________________________
Added: svn:eol-style
113 + native
Added: svn:mime-type
214 + text/plain
Index: trunk/parsers/wikidom/lib/es/es.Selection.js
@@ -0,0 +1,46 @@
 2+/**
 3+ * Content selection, a pair of locations.
 4+ *
 5+ * @param from {es.Location} Starting location
 6+ * @param to {es.Location} Ending location
 7+ * @returns {es.Selection}
 8+ */
 9+es.Selection = function( from, to ) {
 10+ this.from = from;
 11+ this.to = to;
 12+ this.start = from;
 13+ this.end = to;
 14+}
 15+
 16+/**
 17+ * Ensures that "from" is before "to".
 18+ */
 19+es.Selection.prototype.normalize = function() {
 20+ if ( this.from.block.getIndex() < this.to.block.getIndex()
 21+ || ( this.from.block === this.to.block && this.from.offset < this.to.offset ) ) {
 22+ this.start = this.from;
 23+ this.end = this.to;
 24+ } else {
 25+ this.start = this.to;
 26+ this.end = this.from;
 27+ }
 28+};
 29+
 30+/**
 31+ * Gets all blocks selected completely, between from and to.
 32+ *
 33+ * If from and to are adjacent blocks, or the same block, the result will always be an empty array.
 34+ *
 35+ * @returns {Array} List of blocks
 36+ */
 37+es.Selection.prototype.through = function() {
 38+ var through = [];
 39+ if ( this.from !== this.to && this.from.nextBlock() !== this.to ) {
 40+ var next = this.from.nextBlock();
 41+ while ( next && next !== this.to ) {
 42+ through.push( next );
 43+ next = next.nextBlock();
 44+ }
 45+ }
 46+ return through;
 47+};
Property changes on: trunk/parsers/wikidom/lib/es/es.Selection.js
___________________________________________________________________
Added: svn:eol-style
148 + native
Added: svn:mime-type
249 + text/plain
Index: trunk/parsers/wikidom/lib/es/es.Range.js
@@ -0,0 +1,11 @@
 2+/**
 3+ * Range of content.
 4+ *
 5+ * @param start {Integer} Starting point
 6+ * @param end {Integer} Ending point
 7+ * @returns {es.Range}
 8+ */
 9+es.Range = function( start, end ) {
 10+ this.start = start || null;
 11+ this.end = end || null;
 12+}
Property changes on: trunk/parsers/wikidom/lib/es/es.Range.js
___________________________________________________________________
Added: svn:eol-style
113 + native
Added: svn:mime-type
214 + text/plain
Index: trunk/parsers/wikidom/demos/es/index.html
@@ -54,6 +54,10 @@
5555 <script type="text/javascript" src="../../lib/jquery.js"></script>
5656 <script type="text/javascript" src="../../lib/es/es.js"></script>
5757 <script type="text/javascript" src="../../lib/es/es.EventEmitter.js"></script>
 58+ <script type="text/javascript" src="../../lib/es/es.Position.js"></script>
 59+ <script type="text/javascript" src="../../lib/es/es.Location.js"></script>
 60+ <script type="text/javascript" src="../../lib/es/es.Range.js"></script>
 61+ <script type="text/javascript" src="../../lib/es/es.Selection.js"></script>
5862 <script type="text/javascript" src="../../lib/es/es.Content.js"></script>
5963 <script type="text/javascript" src="../../lib/es/es.Container.js"></script>
6064 <script type="text/javascript" src="../../lib/es/es.Block.js"></script>

Status & tagging log