Prechádzať zdrojové kódy

change how isTouch querying happens

Adam Shaw 10 rokov pred
rodič
commit
4f0a6d50e7

+ 6 - 1
src/Calendar.js

@@ -9,6 +9,7 @@ var Calendar = FC.Calendar = Class.extend({
 	view: null, // current View object
 	header: null,
 	loadingLevel: 0, // number of simultaneous loading tasks
+	isTouch: false,
 
 
 	// a lot of this class' OOP logic is scoped within this constructor function,
@@ -55,6 +56,10 @@ var Calendar = FC.Calendar = Class.extend({
 		]);
 		populateInstanceComputableOptions(this.options);
 
+		this.isTouch = this.options.isTouch != null ?
+			this.options.isTouch :
+			FC.isTouch;
+
 		this.viewSpecCache = {}; // somewhat unrelated
 	},
 
@@ -512,7 +517,7 @@ function Calendar_constructor(element, overrides) {
 		element.addClass('fc');
 
 		element.addClass(
-			FC.isTouchEnabled ? 'fc-touch' : 'fc-cursor'
+			t.isTouch ? 'fc-touch' : 'fc-cursor'
 		);
 
 		if (options.isRTL) {

+ 1 - 1
src/common/Grid.events.js

@@ -175,7 +175,7 @@ Grid.mixin({
 
 	// Attaches event-element-related handlers to the container element and leverage bubbling
 	bindSegHandlers: function() {
-		if (FC.isTouchEnabled) {
+		if (this.view.calendar.isTouch) {
 			this.bindSegHandler('touchstart', this.handleSegTouchStart);
 		}
 		else {

+ 1 - 1
src/common/Grid.js

@@ -170,7 +170,7 @@ var Grid = FC.Grid = Class.extend(ListenerMixin, {
 		this.el = el;
 		preventSelection(el);
 
-		if (FC.isTouchEnabled) {
+		if (this.view.calendar.isTouch) {
 			this.bindDayHandler('touchstart', this.dayTouchStart);
 		}
 		else {

+ 1 - 1
src/common/View.js

@@ -957,7 +957,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 	handleDocumentMousedown: function(ev) {
 		// touch devices fire simulated mouse events on a "click".
 		// only process mousedown if we know this isn't a touch device.
-		if (!FC.isTouchEnabled && isPrimaryMouseButton(ev)) {
+		if (!this.calendar.isTouch && isPrimaryMouseButton(ev)) {
 			this.processRangeUnselect(ev);
 			this.processEventUnselect(ev);
 		}

+ 1 - 2
src/main.js

@@ -6,8 +6,7 @@ var FC = $.fullCalendar = {
 var fcViews = FC.views = {};
 
 
-FC.isTouchEnabled = ('ontouchstart' in document) &&
-	!window.__karma__; // workaround for phantomjs falsely reporting touch
+FC.isTouch = 'ontouchstart' in document;
 
 
 $.fn.fullCalendar = function(options) {

+ 6 - 0
tests/lib/jasmine-ext.js

@@ -7,6 +7,12 @@ beforeEach(function() {
 	// (not the best place for this)
 	moment.suppressDeprecationWarnings = true;
 
+	// phantom JS falsely reports touch abilities, so explicitly disable.
+	// tests can override this on a per-calendar basis.
+	// (not the best place for this)
+	$.fullCalendar.isTouch = false;
+
+
 	jasmine.addMatchers({
 
 		// Moment and Duration