Skip to content
Extraits de code Groupes Projets
Valider 0d1b8d95 rédigé par mattab's avatar mattab
Parcourir les fichiers

Refs #4300 Adding Array.reduce fallback for IE8. Array.reduce is used in jqplot.

parent bb973707
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -322,17 +322,65 @@ function isEnterKey(e) ...@@ -322,17 +322,65 @@ function isEnterKey(e)
// workarounds // workarounds
(function($){ (function($){
try { // this code is not vital, so we make sure any errors are ignored try {
// this code is not vital, so we make sure any errors are ignored
// monkey patch that works around bug in arc function of some browsers where //--------------------------------------
// nothing gets drawn if angles are 2 * PI apart and in counter-clockwise direction. //
// affects some versions of chrome & IE 8 // monkey patch that works around bug in arc function of some browsers where
var oldArc = CanvasRenderingContext2D.prototype.arc; // nothing gets drawn if angles are 2 * PI apart and in counter-clockwise direction.
CanvasRenderingContext2D.prototype.arc = function(x, y, r, sAngle, eAngle, clockwise) { // affects some versions of chrome & IE 8
if (Math.abs(eAngle - sAngle - Math.PI * 2) < 0.000001 && !clockwise) //
eAngle -= 0.000001; //--------------------------------------
oldArc.call(this, x, y, r, sAngle, eAngle, clockwise); var oldArc = CanvasRenderingContext2D.prototype.arc;
}; CanvasRenderingContext2D.prototype.arc = function(x, y, r, sAngle, eAngle, clockwise) {
if (Math.abs(eAngle - sAngle - Math.PI * 2) < 0.000001 && !clockwise)
eAngle -= 0.000001;
oldArc.call(this, x, y, r, sAngle, eAngle, clockwise);
};
//--------------------------------------
//
// Array.reduce is not available in IE8 but used in Jqplot
//
//--------------------------------------
if ('function' !== typeof Array.prototype.reduce) {
Array.prototype.reduce = function(callback, opt_initialValue){
'use strict';
if (null === this || 'undefined' === typeof this) {
// At the moment all modern browsers, that support strict mode, have
// native implementation of Array.prototype.reduce. For instance, IE8
// does not support strict mode, so this check is actually useless.
throw new TypeError(
'Array.prototype.reduce called on null or undefined');
}
if ('function' !== typeof callback) {
throw new TypeError(callback + ' is not a function');
}
var index, value,
length = this.length >>> 0,
isValueSet = false;
if (1 < arguments.length) {
value = opt_initialValue;
isValueSet = true;
}
for (index = 0; length > index; ++index) {
if (this.hasOwnProperty(index)) {
if (isValueSet) {
value = callback(value, this[index], index, this);
}
else {
value = this[index];
isValueSet = true;
}
}
}
if (!isValueSet) {
throw new TypeError('Reduce of empty array with no initial value');
}
return value;
};
}
} catch (e) {} } catch (e) {}
}(jQuery)); }(jQuery));
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter