moved UA to Global namespace, and fixed scope issue in _drawChildren that was preventing nested draws from working correctly

This commit is contained in:
Eric Rowell
2013-09-14 11:02:47 -07:00
parent 6131385a4e
commit 91fd14cc9f
5 changed files with 27 additions and 32 deletions

View File

@@ -235,10 +235,9 @@
return arr;
},
_setChildrenIndices: function() {
var children = this.children, len = children.length;
for(var n = 0; n < len; n++) {
children[n].index = n;
}
this.children.each(function(child, n) {
child.index = n;
});
},
drawScene: function(canvas) {
var layer = this.getLayer(),
@@ -261,12 +260,9 @@
return this;
},
_drawChildren: function(canvas) {
var children = this.children;
len = children.length;
for(n = 0; n < len; n++) {
children[n].drawScene(canvas);
}
this.children.each(function(child) {
child.drawScene(canvas);
});
},
drawHit: function() {
var hasClip = this.getClipWidth() && this.getClipHeight() && this.nodeType !== 'Stage',

View File

@@ -49,6 +49,23 @@ var Kinetic = {};
dblClickWindow: 400,
pixelRatio: undefined,
// user agent
UA: (function() {
var ua = navigator.userAgent.toLowerCase(),
// jQuery UA regex
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'
};
})(),
/**
* @namespace Filters
* @memberof Kinetic

View File

@@ -253,24 +253,6 @@
}
};
/*
* 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'
};
})();
// CONSTANTS
var CANVAS = 'canvas',
CONTEXT_2D = '2d',
@@ -589,8 +571,8 @@
canvas = document.createElement(CANVAS);
canvas.width = arg.width;
canvas.height = arg.height;
context = canvas.getContext(CONTEXT_2D);
context.putImageData(arg, 0, 0);
_context = canvas.getContext(CONTEXT_2D);
_context.putImageData(arg, 0, 0);
dataUrl = canvas.toDataURL();
imageObj = new Image();
imageObj.onload = function() {

View File

@@ -51,6 +51,8 @@
cropHeight = this.getCropHeight(),
image;
//TODO: this logic needs to hook int othe new caching system
// if a filter is set, and the filter needs to be updated, reapply
if (this.getFilter() && this._applyFilter) {
this.applyFilter();

View File

@@ -2138,8 +2138,6 @@ suite('Node', function() {
layer.add(group);
stage.add(layer);
var startDataUrl = layer.toDataURL();
assert.equal(triangle.getId(), 'myTriangle');
var expectedJson = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"className":"Shape"}]}]}]}';