Move named inner functions out of nested scopes, to prepare for 'use strict;' transition.

This commit is contained in:
Jürg Lehni 2013-02-08 18:23:33 -08:00
parent d793d8a43d
commit dc35fdbd02
5 changed files with 58 additions and 57 deletions

View file

@ -16,7 +16,6 @@
* @private * @private
*/ */
var DomElement = new function() { var DomElement = new function() {
// We use a mix of Bootstrap.js legacy and Bonzo.js magic, ported over and // We use a mix of Bootstrap.js legacy and Bonzo.js magic, ported over and
// furhter simplified to a subset actually required by Paper.js // furhter simplified to a subset actually required by Paper.js

View file

@ -69,6 +69,13 @@ this.Base = Base.inject(/** @lends Base# */{
* arrays and properties of objects. * arrays and properties of objects.
*/ */
equals: function(obj1, obj2) { equals: function(obj1, obj2) {
function checkKeys(o1, o2) {
for (var i in o1)
if (o1.hasOwnProperty(i) && typeof o2[i] === 'undefined')
return false;
return true;
}
if (obj1 == obj2) if (obj1 == obj2)
return true; return true;
// Call #equals() on both obj1 and obj2 // Call #equals() on both obj1 and obj2
@ -88,12 +95,6 @@ this.Base = Base.inject(/** @lends Base# */{
} }
// Compare objects // Compare objects
if (typeof obj1 === 'object' && typeof obj2 === 'object') { if (typeof obj1 === 'object' && typeof obj2 === 'object') {
function checkKeys(o1, o2) {
for (var i in o1)
if (o1.hasOwnProperty(i) && typeof o2[i] === 'undefined')
return false;
return true;
}
if (!checkKeys(obj1, obj2) || !checkKeys(obj2, obj1)) if (!checkKeys(obj1, obj2) || !checkKeys(obj2, obj1))
return false; return false;
for (var i in obj1) { for (var i in obj1) {

View file

@ -1131,6 +1131,15 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
* hit. * hit.
*/ */
hitTest: function(point, options) { hitTest: function(point, options) {
function checkBounds(type, part) {
var pt = bounds['get' + part]();
// TODO: We need to transform the point back to the coordinate
// system of the DOM level on which the inquiry was started!
if (point.getDistance(pt) < options.tolerance)
return new HitResult(type, that,
{ name: Base.hyphenate(part), point: pt });
}
point = Point.read(arguments); point = Point.read(arguments);
options = HitResult.getOptions(Base.read(arguments)); options = HitResult.getOptions(Base.read(arguments));
// Check if the point is withing roughBounds + tolerance, but only if // Check if the point is withing roughBounds + tolerance, but only if
@ -1153,14 +1162,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
points = ['TopLeft', 'TopRight', 'BottomLeft', 'BottomRight', points = ['TopLeft', 'TopRight', 'BottomLeft', 'BottomRight',
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'], 'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'],
res; res;
function checkBounds(type, part) {
var pt = bounds['get' + part]();
// TODO: We need to transform the point back to the coordinate
// system of the DOM level on which the inquiry was started!
if (point.getDistance(pt) < options.tolerance)
return new HitResult(type, that,
{ name: Base.hyphenate(part), point: pt });
}
if (options.center && (res = checkBounds('center', 'Center'))) if (options.center && (res = checkBounds('center', 'Center')))
return res; return res;
if (options.bounds) { if (options.bounds) {

View file

@ -1442,15 +1442,6 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
// performance. // performance.
function drawHandles(ctx, segments, matrix) { function drawHandles(ctx, segments, matrix) {
var coords = new Array(6);
for (var i = 0, l = segments.length; i < l; i++) {
var segment = segments[i];
segment._transformCoordinates(matrix, coords, false);
var state = segment._selectionState,
selected = state & /*#=*/ SelectionState.POINT,
pX = coords[0],
pY = coords[1];
function drawHandle(index) { function drawHandle(index) {
var hX = coords[index], var hX = coords[index],
hY = coords[index + 1]; hY = coords[index + 1];
@ -1465,6 +1456,14 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
} }
} }
var coords = new Array(6);
for (var i = 0, l = segments.length; i < l; i++) {
var segment = segments[i];
segment._transformCoordinates(matrix, coords, false);
var state = segment._selectionState,
selected = state & /*#=*/ SelectionState.POINT,
pX = coords[0],
pY = coords[1];
if (selected || (state & /*#=*/ SelectionState.HANDLE_IN)) if (selected || (state & /*#=*/ SelectionState.HANDLE_IN))
drawHandle(2); drawHandle(2);
if (selected || (state & /*#=*/ SelectionState.HANDLE_OUT)) if (selected || (state & /*#=*/ SelectionState.HANDLE_OUT))

View file

@ -265,28 +265,13 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
*/ */
draw: function(ctx, matrix) { draw: function(ctx, matrix) {
this._drawCount++; // Create a local lookup table for hierarchically concatenated matrices
ctx.save(); // by item id, to speed up drawing by eliminating repeated concatenation
if (!matrix.isIdentity()) // of parent's matrices through caching.
matrix.applyToContext(ctx);
var param = { offset: new Point(0, 0) };
for (var i = 0, l = this.layers.length; i < l; i++)
Item.draw(this.layers[i], ctx, param);
ctx.restore();
// Draw the selection of the selected items in the project:
if (this._selectedItemCount > 0) {
ctx.save();
ctx.strokeWidth = 1;
// TODO: use Layer#color
ctx.strokeStyle = ctx.fillStyle = '#009dec';
// Create a local lookup table for hierarchically concatenated
// matrices by item id, to speed up drawing by eliminating repeated
// concatenation of parent's matrices through caching.
var matrices = {}; var matrices = {};
// Description of the paramters to getGlobalMatrix(): // Description of the paramters to getGlobalMatrix():
// mx is the container for the final concatenated matrix, passed // mx is the container for the final concatenated matrix, passed to
// to getGlobalMatrix() on the initial call. // getGlobalMatrix() on the initial call.
// cached defines wether the result of the concatenation should be // cached defines wether the result of the concatenation should be
// cached, only used for parents of items that this is called for. // cached, only used for parents of items that this is called for.
function getGlobalMatrix(item, mx, cached) { function getGlobalMatrix(item, mx, cached) {
@ -307,6 +292,22 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
matrices[item._id] = mx.clone(); matrices[item._id] = mx.clone();
return mx; return mx;
} }
this._drawCount++;
ctx.save();
if (!matrix.isIdentity())
matrix.applyToContext(ctx);
var param = { offset: new Point(0, 0) };
for (var i = 0, l = this.layers.length; i < l; i++)
Item.draw(this.layers[i], ctx, param);
ctx.restore();
// Draw the selection of the selected items in the project:
if (this._selectedItemCount > 0) {
ctx.save();
ctx.strokeWidth = 1;
// TODO: use Layer#color
ctx.strokeStyle = ctx.fillStyle = '#009dec';
for (var id in this._selectedItems) { for (var id in this._selectedItems) {
var item = this._selectedItems[id]; var item = this._selectedItems[id];
if (item._drawCount === this._drawCount) if (item._drawCount === this._drawCount)