added Kinetic level pixelRatio property that can be used to override the detected pixel ratio. Also fixed up a pixel ratio related test for FF. added Kinetic.UA for user agent detection

This commit is contained in:
Eric Rowell
2013-09-13 23:26:58 -07:00
parent 88c419fef6
commit 659d0409b3
5 changed files with 29 additions and 7 deletions

View File

@@ -34,7 +34,7 @@
init: function(config) {
config = config || {};
var pixelRatio = config.pixelRatio || _pixelRatio;
var pixelRatio = config.pixelRatio || Kinetic.pixelRatio || _pixelRatio;
this.pixelRatio = pixelRatio;
this._canvas = document.createElement('canvas');

View File

@@ -47,6 +47,7 @@ var Kinetic = {};
enableTrace: false,
traceArrMax: 100,
dblClickWindow: 400,
pixelRatio: undefined,
/**
* @namespace Filters

View File

@@ -84,10 +84,7 @@
})(n);
}
};
})();
(function() {
/*
* Last updated November 2011
* By Simon Sarris
@@ -255,10 +252,25 @@
this.translate(xt, yt);
}
};
})();
/*
* jQuery UA
*/
Kinetic.UA = (function() {
var ua = navigator.userAgent.toLowerCase(),
match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
return {
browser: match[ 1 ] || '',
version: match[ 2 ] || '0'
};
})();
(function() {
// CONSTANTS
var CANVAS = 'canvas',
CONTEXT_2D = '2d',

View File

@@ -3,6 +3,8 @@ var assert = chai.assert,
kineticContainer = document.getElementById('kinetic-container');
Kinetic.enableTrace = true;
// make sure pixel ratio is 1 or else the tests will fail on devices with retina display
Kinetic.pixelRatio = 1;
function addStage() {
var container = document.createElement('div'),

View File

@@ -21,7 +21,14 @@ suite('Layer', function() {
var style = layer.getCanvas()._canvas.style;
assert.equal(style.position, 'absolute', 'canvas position style should be absolute');
assert.equal(style.border, '0px', 'canvas border style should be 0px');
if (Kinetic.UA.browser === 'mozilla') {
assert.equal(style.border, '0px none', 'canvas border style should be 0px');
}
else {
assert.equal(style.border, '0px', 'canvas border style should be 0px');
}
assert.equal(style.margin, '0px', 'canvas margin style should be 0px');
assert.equal(style.padding, '0px', 'canvas padding style should be 0px');
assert.equal(style.backgroundColor, 'transparent', 'canvas backgroundColor style should be transparent');