From 91fd14cc9f67cd73156c792e2b6b17ff2ad8b2e3 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Sat, 14 Sep 2013 11:02:47 -0700 Subject: [PATCH] moved UA to Global namespace, and fixed scope issue in _drawChildren that was preventing nested draws from working correctly --- src/Container.js | 16 ++++++---------- src/Global.js | 17 +++++++++++++++++ src/Util.js | 22 ++-------------------- src/shapes/Image.js | 2 ++ test/unit/Node-test.js | 2 -- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/Container.js b/src/Container.js index 46fbe133..7bc0f8e5 100644 --- a/src/Container.js +++ b/src/Container.js @@ -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', diff --git a/src/Global.js b/src/Global.js index f255e3e0..0bfee5f7 100644 --- a/src/Global.js +++ b/src/Global.js @@ -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 diff --git a/src/Util.js b/src/Util.js index c1427731..10080859 100644 --- a/src/Util.js +++ b/src/Util.js @@ -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() { diff --git a/src/shapes/Image.js b/src/shapes/Image.js index 0cbcd097..41459dff 100644 --- a/src/shapes/Image.js +++ b/src/shapes/Image.js @@ -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(); diff --git a/test/unit/Node-test.js b/test/unit/Node-test.js index 6425840c..bbe66f4d 100644 --- a/test/unit/Node-test.js +++ b/test/unit/Node-test.js @@ -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"}]}]}]}';