http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94975
Revision: 94975
Author: tparscal
Date: 2011-08-19 00:40:54 +0000 (Fri, 19 Aug 2011)
Log Message:
-----------
Added es.Location.compareWith
Modified Paths:
--------------
trunk/parsers/wikidom/lib/es/es.Location.js
Modified: trunk/parsers/wikidom/lib/es/es.Location.js
===================================================================
--- trunk/parsers/wikidom/lib/es/es.Location.js 2011-08-19 00:38:11 UTC (rev
94974)
+++ trunk/parsers/wikidom/lib/es/es.Location.js 2011-08-19 00:40:54 UTC (rev
94975)
@@ -11,4 +11,27 @@
es.Location = function( block, offset ) {
this.block = block;
this.offset = offset || 0;
-}
+};
+
+/**
+ * Compares location with another.
+ *
+ * @method
+ * @param location {es.Location} Location to compare with
+ * @returns {Integer} -1 if this is before the argument, 0 if at the same
place or 1 if after
+ */
+es.Location.prototype.compareWith = function( location ) {
+ var a = this,
+ b = location;
+ if ( a === b ) {
+ return 0;
+ }
+ var aIndex = this.block.getIndex(),
+ bIndex = location.block.getIndex();
+ if ( aIndex < bIndex || ( aIndex === bIndex && a.offset < b.offset ) ) {
+ return -1;
+ } else if ( aIndex > bIndex || ( aIndex === bIndex && a.offset >
b.offset ) ) {
+ return 1;
+ }
+ return 0;
+};
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs