(function() {
-/*global Dygraph:false, G_vmlCanvasManager:false, Node:false */
+/*global Dygraph:false, Node:false */
"use strict";
Dygraph.LOG_SCALE = 10;
};
/**
- * Add an event handler. This smooths a difference between IE and the rest of
- * the world.
+ * Add an event handler.
* @param {!Node} elem The element to add the event to.
* @param {string} type The type of the event, e.g. 'click' or 'mousemove'.
* @param {function(Event):(boolean|undefined)} fn The function to call
* @private
*/
Dygraph.addEvent = function addEvent(elem, type, fn) {
- if (elem.addEventListener) {
- elem.addEventListener(type, fn, false);
- } else {
- elem[type+fn] = function(){fn(window.event);};
- elem.attachEvent('on'+type, elem[type+fn]);
- }
+ elem.addEventListener(type, fn, false);
};
/**
};
/**
- * Remove an event handler. This smooths a difference between IE and the rest
- * of the world.
+ * Remove an event handler.
* @param {!Node} elem The element to remove the event from.
* @param {string} type The type of the event, e.g. 'click' or 'mousemove'.
* @param {function(Event):(boolean|undefined)} fn The function to call
* @private
*/
Dygraph.removeEvent = function(elem, type, fn) {
- if (elem.removeEventListener) {
- elem.removeEventListener(type, fn, false);
- } else {
- try {
- elem.detachEvent('on'+type, elem[type+fn]);
- } catch(e) {
- // We only detach event listeners on a "best effort" basis in IE. See:
- // http://stackoverflow.com/questions/2553632/detachevent-not-working-with-named-inline-functions
- }
- elem[type+fn] = null;
- }
+ elem.removeEventListener(type, fn, false);
};
Dygraph.prototype.removeTrackedEvents_ = function() {
if (obj.offsetParent) {
var copyObj = obj;
while (1) {
- // NOTE: the if statement here is for IE8.
var borderLeft = "0", borderTop = "0";
- if (window.getComputedStyle) {
- var computedStyle = window.getComputedStyle(copyObj, null);
- borderLeft = computedStyle.borderLeft || "0";
- borderTop = computedStyle.borderTop || "0";
- }
+ var computedStyle = window.getComputedStyle(copyObj, null);
+ borderLeft = computedStyle.borderLeft || "0";
+ borderTop = computedStyle.borderTop || "0";
curleft += parseInt(borderLeft, 10) ;
curtop += parseInt(borderTop, 10) ;
curleft += copyObj.offsetLeft;
};
/**
- * Create a new canvas element. This is more complex than a simple
- * document.createElement("canvas") because of IE and excanvas.
+ * Create a new canvas element.
*
* @return {!HTMLCanvasElement}
* @private
*/
Dygraph.createCanvas = function() {
- var canvas = document.createElement("canvas");
-
- var isIE = (/MSIE/.test(navigator.userAgent) && !window.opera);
- if (isIE && (typeof(G_vmlCanvasManager) != 'undefined')) {
- canvas = G_vmlCanvasManager.initElement(
- /**@type{!HTMLCanvasElement}*/(canvas));
- }
-
- return canvas;
+ return document.createElement('canvas');
};
/**
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
- context.backingStorePixelRatio;
- if (devicePixelRatio !== undefined &&
- backingStorePixelRatio !== undefined) {
+ context.backingStorePixelRatio || 1;
+ if (devicePixelRatio !== undefined) {
return devicePixelRatio / backingStoreRatio;
} else {
- // If either value is undefined, the ratio is meaningless so we want to
- // return 1.
+ // At least devicePixelRatio must be defined for this ratio to make sense.
+ // We default backingStoreRatio to 1: this does not exist on some browsers
+ // (i.e. desktop Chrome).
return 1;
}
} catch (e) {
* @return {boolean} Whether the browser supports canvas.
*/
Dygraph.isCanvasSupported = function(opt_canvasElement) {
- var canvas;
try {
- canvas = opt_canvasElement || document.createElement("canvas");
+ var canvas = opt_canvasElement || document.createElement("canvas");
canvas.getContext("2d");
- }
- catch (e) {
- var ie = navigator.appVersion.match(/MSIE (\d\.\d)/);
- var opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
- if ((!ie) || (ie[1] < 6) || (opera))
- return false;
- return true;
+ } catch (e) {
+ return false;
}
return true;
};