Преглед изворни кода

getEventSourcesByMatchArray. have removeEventSources use it

Adam Shaw пре 9 година
родитељ
комит
fdee6dd5ad
2 измењених фајлова са 31 додато и 23 уклоњено
  1. 1 20
      src/Calendar.js
  2. 30 3
      src/EventManager.js

+ 1 - 20
src/Calendar.js

@@ -708,26 +708,7 @@ function Calendar_constructor(element, overrides) {
 
 
 	// TODO: move this into EventManager?
 	// TODO: move this into EventManager?
 	function refetchEventSources(matchInputs) {
 	function refetchEventSources(matchInputs) {
-		if (matchInputs) {
-
-			// coerce into an array
-			if (!$.isArray(matchInputs)) {
-				matchInputs = [ matchInputs ];
-			}
-
-			var specificSources = [];
-			var i;
-
-			// resolve raw inputs to real event source objects
-			for (i = 0; i < matchInputs.length; i++) {
-				specificSources.push.apply( // append
-					specificSources,
-					t.getEventSourcesByMatch(matchInputs[i])
-				);
-			}
-
-			fetchEventSources(specificSources);
-		}
+		fetchEventSources(t.getEventSourcesByMatchArray(matchInputs));
 	}
 	}
 
 
 
 

+ 30 - 3
src/EventManager.js

@@ -20,6 +20,7 @@ function EventManager(options) { // assumed to be a calendar
 	t.fetchEventSources = fetchEventSources;
 	t.fetchEventSources = fetchEventSources;
 	t.getEventSources = getEventSources;
 	t.getEventSources = getEventSources;
 	t.getEventSourceById = getEventSourceById;
 	t.getEventSourceById = getEventSourceById;
+	t.getEventSourcesByMatchArray = getEventSourcesByMatchArray;
 	t.getEventSourcesByMatch = getEventSourcesByMatch;
 	t.getEventSourcesByMatch = getEventSourcesByMatch;
 	t.addEventSource = addEventSource;
 	t.addEventSource = addEventSource;
 	t.removeEventSource = removeEventSource;
 	t.removeEventSource = removeEventSource;
@@ -346,13 +347,13 @@ function EventManager(options) { // assumed to be a calendar
 
 
 
 
 	// if called with no arguments, removes all.
 	// if called with no arguments, removes all.
-	function removeEventSources(matchInput) {
-		if (matchInput == null) {
+	function removeEventSources(matchInputs) {
+		if (matchInputs == null) {
 			removeSpecificEventSources(sources, true); // isAll=true
 			removeSpecificEventSources(sources, true); // isAll=true
 		}
 		}
 		else {
 		else {
 			removeSpecificEventSources(
 			removeSpecificEventSources(
-				getEventSourcesByMatch(matchInput)
+				getEventSourcesByMatchArray(matchInputs)
 			);
 			);
 		}
 		}
 	}
 	}
@@ -400,6 +401,32 @@ function EventManager(options) { // assumed to be a calendar
 	}
 	}
 
 
 
 
+	// like getEventSourcesByMatch, but accepts multple match criteria (like multiple IDs)
+	function getEventSourcesByMatchArray(matchInputs) {
+
+		// coerce into an array
+		if (!matchInputs) {
+			matchInputs = [];
+		}
+		else if (!$.isArray(matchInputs)) {
+			matchInputs = [ matchInputs ];
+		}
+
+		var matchingSources = [];
+		var i;
+
+		// resolve raw inputs to real event source objects
+		for (i = 0; i < matchInputs.length; i++) {
+			matchingSources.push.apply( // append
+				matchingSources,
+				getEventSourcesByMatch(matchInputs[i])
+			);
+		}
+
+		return matchingSources;
+	}
+
+
 	// matchInput can either by a real event source object, an ID, or the function/URL for the source.
 	// matchInput can either by a real event source object, an ID, or the function/URL for the source.
 	// returns an array of matching source objects.
 	// returns an array of matching source objects.
 	function getEventSourcesByMatch(matchInput) {
 	function getEventSourcesByMatch(matchInput) {