瀏覽代碼

better code reuse for numericSort

Adam Shaw 11 年之前
父節點
當前提交
68c25ddf86
共有 3 個文件被更改,包括 7 次插入11 次删除
  1. 1 1
      src/common/Grid.js
  2. 1 5
      src/common/View.js
  3. 5 5
      src/util.js

+ 1 - 1
src/common/Grid.js

@@ -107,7 +107,7 @@ $.extend(Grid.prototype, {
 
 					dayEl = _this.getCellDayEl(cell);
 
-					dates = [ date, dragListener.origDate ].sort(dateCompare);
+					dates = [ date, dragListener.origDate ].sort(compareNumbers); // works with Moments
 					start = dates[0];
 					end = dates[1].clone().add(_this.cellDuration);
 

+ 1 - 5
src/common/View.js

@@ -800,7 +800,7 @@ function View(calendar) {
 				var segmentCellLast = cellOffsetToCell(segmentCellOffsetLast);
 
 				// view might be RTL, so order by leftmost column
-				var cols = [ segmentCellFirst.col, segmentCellLast.col ].sort(numericSort);
+				var cols = [ segmentCellFirst.col, segmentCellLast.col ].sort(compareNumbers);
 
 				// Determine if segment's first/last cell is the beginning/end of the date range.
 				// We need to compare "day offset" because "cell offsets" are often ambiguous and
@@ -860,10 +860,6 @@ function View(calendar) {
 		return range.end.diff(range.start, 'days') > 1;
 	}
 
-	function numericSort(a, b) {
-		return a-b;
-	}
-
 }
 
 

+ 5 - 5
src/util.js

@@ -268,11 +268,6 @@ function isNativeDate(input) {
 }
 
 
-function dateCompare(a, b) { // works with Moments and native Dates
-	return a - b;
-}
-
-
 // Returns a boolean about whether the given input is a time string, like "06:40:00" or "06:00"
 function isTimeString(str) {
 	return /^\d+\:\d+(?:\:\d+\.?(?:\d{3})?)?$/.test(str);
@@ -337,6 +332,11 @@ function capitaliseFirstLetter(str) {
 }
 
 
+function compareNumbers(a, b) { // for .sort()
+	return a - b;
+}
+
+
 // Returns a function, that, as long as it continues to be invoked, will not
 // be triggered. The function will be called after it stops being called for
 // N milliseconds.