Implement a better way to name and export class constructors.

This change also simplified the way classes are exported to PaperScope objects.
This commit is contained in:
Jürg Lehni 2013-05-27 12:48:58 -07:00
parent 15b1ea7af0
commit 10d5de3ed6
45 changed files with 127 additions and 154 deletions

View file

@ -18,7 +18,7 @@
* http://dev.helma.org/Wiki/JavaScript+Inheritance+Sugar/
*/
var Base = this.Base = new function() { // Straps scope
var Base = new function() { // Straps scope
var hidden = /^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,
proto = Object.prototype,
toString = proto.toString,
@ -201,7 +201,8 @@ var Base = this.Base = new function() { // Straps scope
}
// Inject into new ctor object that's passed to inject(), and then returned
return inject(function() {}, {
// as the Base class.
return inject(function Base() {}, {
inject: function(src/*, ... */) {
if (src) {
var proto = this.prototype,

View file

@ -15,7 +15,7 @@
*
* @class The Line object represents..
*/
var Line = this.Line = Base.extend(/** @lends Line# */{
var Line = Base.extend(/** @lends Line# */{
// DOCS: document Line class and constructor
/**
* Creates a Line object.
@ -24,7 +24,7 @@ var Line = this.Line = Base.extend(/** @lends Line# */{
* @param {Point} point2
* @param {Boolean} [asVector=false]
*/
initialize: function(arg0, arg1, arg2, arg3, arg4) {
initialize: function Line(arg0, arg1, arg2, arg3, arg4) {
var asVector = false;
if (arguments.length >= 4) {
this._px = arg0;

View file

@ -37,9 +37,7 @@
* knowledge of the underlying matrix (as opposed to say simply performing
* matrix multiplication).
*/
var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
_class: 'Matrix',
var Matrix = Base.extend(/** @lends Matrix# */{
/**
* Creates a 2D affine transform.
*
@ -50,7 +48,7 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* @param {Number} tx The translateX coordinate of the transform
* @param {Number} ty The translateY coordinate of the transform
*/
initialize: function(arg) {
initialize: function Matrix(arg) {
var count = arguments.length,
ok = true;
if (count == 6) {

View file

@ -23,8 +23,7 @@
* console.log(point.x); // 10
* console.log(point.y); // 5
*/
var Point = this.Point = Base.extend(/** @lends Point# */{
_class: 'Point',
var Point = Base.extend(/** @lends Point# */{
// Tell Base.read that the Point constructor supports reading with index
_readIndex: true,
@ -129,7 +128,7 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
* @param {Point} point
* @name Point#initialize
*/
initialize: function(arg0, arg1) {
initialize: function Point(arg0, arg1) {
var type = typeof arg0;
if (type === 'number') {
var hasY = typeof arg1 === 'number';

View file

@ -17,8 +17,7 @@
* point (x, y), its width, and its height. It should not be confused with a
* rectangular path, it is not an item.
*/
var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
_class: 'Rectangle',
var Rectangle = Base.extend(/** @lends Rectangle# */{
// Tell Base.read that the Rectangle constructor supports reading with index
_readIndex: true,
@ -72,7 +71,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
* @name Rectangle#initialize
* @param {Rectangle} rt
*/
initialize: function(arg0, arg1, arg2, arg3) {
initialize: function Rectangle(arg0, arg1, arg2, arg3) {
var type = typeof arg0,
read = 0;
if (type === 'number') {

View file

@ -22,8 +22,7 @@
* console.log(size.width); // 10
* console.log(size.height); // 5
*/
var Size = this.Size = Base.extend(/** @lends Size# */{
_class: 'Size',
var Size = Base.extend(/** @lends Size# */{
// Tell Base.read that the Point constructor supports reading with index
_readIndex: true,
@ -90,7 +89,7 @@ var Size = this.Size = Base.extend(/** @lends Size# */{
* console.log(size.width); // 50
* console.log(size.height); // 50
*/
initialize: function(arg0, arg1) {
initialize: function Size(arg0, arg1) {
var type = typeof arg0;
if (type === 'number') {
var hasHeight = typeof arg1 === 'number';

View file

@ -17,7 +17,7 @@
*/
// Extend Base with utility functions used across the library. Also set
// this.Base on the injection scope, since straps.js ommits that.
this.Base = Base.inject(/** @lends Base# */{
Base.inject(/** @lends Base# */{
// Have generics versions of #clone() and #toString():
generics: true,
@ -36,7 +36,7 @@ this.Base = Base.inject(/** @lends Base# */{
*/
toString: function() {
return this._id != null
? (this._class || 'Object') + (this._name
? (this.constructor.name || 'Object') + (this._name
? " '" + this._name + "'"
: ' @' + this._id)
: '{ ' + Base.each(this, function(value, key) {
@ -80,15 +80,18 @@ this.Base = Base.inject(/** @lends Base# */{
statics: /** @lends Base */{
_classes: {},
// Keep track of all named classes for serialization and exporting.
// Also register the Base class itself.
_classes: { 'Base': Base },
extend: function extend(src) {
// Override Base.extend() with a version that registers classes that
// define #_class inside the Base._classes lookup, for
// deserialization.
var res = extend.base.apply(this, arguments);
if (src._class)
Base._classes[src._class] = res;
var res = extend.base.apply(this, arguments),
name = res.name;
if (name)
Base._classes[name] = res;
return res;
},
@ -289,11 +292,12 @@ this.Base = Base.inject(/** @lends Base# */{
ref = this.references[id];
if (!ref) {
this.length++;
var res = create.call(item);
var res = create.call(item),
name = item.constructor.name;
// Also automatically insert class for dictionary
// entries.
if (item._class && res[0] !== item._class)
res.unshift(item._class);
if (name && res[0] !== name)
res.unshift(name);
this.definitions[id] = res;
ref = this.references[id] = [id];
}
@ -306,8 +310,9 @@ this.Base = Base.inject(/** @lends Base# */{
// If we don't serialize to compact form (meaning no type
// identifier), see if _serialize didn't already add the class,
// e.g. for classes that do not support compact form.
if (obj._class && !compact && res[0] !== obj._class)
res.unshift(obj._class);
var name = obj.constructor.name;
if (name && !compact && res[0] !== name)
res.unshift(name);
} else if (Array.isArray(obj)) {
res = [];
for (var i = 0, l = obj.length; i < l; i++)

View file

@ -32,7 +32,7 @@
* The global {@link paper} object is simply a reference to the currently active
* {@code PaperScope}.
*/
var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
var PaperScope = Base.extend(/** @lends PaperScope# */{
/**
* Creates a PaperScope object.
@ -40,7 +40,7 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
* @name PaperScope#initialize
* @function
*/
initialize: function(script) {
initialize: function PaperScope(script) {
// script is only used internally, when creating scopes for PaperScript.
// Whenever a PaperScope is created, it automatically becomes the active
// one.

View file

@ -21,7 +21,7 @@
/*#*/ include('../../lib/esprima-min.js');
/*#*/ }
var PaperScript = this.PaperScript = new function() {
var PaperScript = new function() {
// Operators to overload
var binaryOperators = {

View file

@ -1,24 +0,0 @@
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/*#*/ if (options.version == 'dev') {
// When in dev mode, also export all classes through PaperScope, to mimick
// scoping behavior of the built library.
Base.each(this, function(val, key) {
if (val && val.prototype instanceof Base || val === Base)
PaperScope.prototype[key] = val;
});
// See paper.js for the non-dev version of this code. We cannot handle dev there
// due to the seperate loading of all source files, which are only availabe
// after the execution of paper.js
var paper = new PaperScope();
/*#*/ } // options.version == 'dev'

14
src/export.js Normal file
View file

@ -0,0 +1,14 @@
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
// Export all named classes to PaperScope and create the initial paper object.
var paper = new (PaperScope.inject(Base._classes))();

View file

@ -20,7 +20,10 @@
*
* @extends Group
*/
var Clip = this.Clip = Group.extend(/** @lends Clip# */{
_class: 'Clip',
_applyMatrix: false
var Clip = Group.extend(/** @lends Clip# */{
_applyMatrix: false,
initialize: function Clip() {
Group.apply(this, arguments);
}
});

View file

@ -19,8 +19,7 @@
*
* @extends Item
*/
var Group = this.Group = Item.extend(/** @lends Group# */{
_class: 'Group',
var Group = Item.extend(/** @lends Group# */{
_serializeFields: {
children: []
},
@ -88,7 +87,7 @@ var Group = this.Group = Item.extend(/** @lends Group# */{
* position: view.center
* });
*/
initialize: function(arg) {
initialize: function Group(arg) {
Item.call(this);
// Allow Group to have children and named children
this._children = [];

View file

@ -17,8 +17,8 @@
* test. It is returned by {@link Item#hitTest(point)} and
* {@link Project#hitTest(point)}.
*/
var HitResult = this.HitResult = Base.extend(/** @lends HitResult# */{
initialize: function(type, item, values) {
var HitResult = Base.extend(/** @lends HitResult# */{
initialize: function HitResult(type, item, values) {
this.type = type;
this.item = item;
// Inject passed values, so we can be flexible about the HitResult

View file

@ -20,7 +20,7 @@
* is unique to their type, but share the underlying properties and functions
* that they inherit from Item.
*/
var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
var Item = Base.extend(Callback, /** @lends Item# */{
statics: {
/**
* Override Item.extend() to merge the subclass' _serializeFields with
@ -30,10 +30,12 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
if (src._serializeFields)
src._serializeFields = Base.merge(
this.prototype._serializeFields, src._serializeFields);
// Derive the _type string from _class
if (src._class)
src._type = Base.hyphenate(src._class);
return extend.base.apply(this, arguments);
var res = extend.base.apply(this, arguments),
name = res.name;
// Derive the _type string from constructor name
if (name)
res.prototype._type = Base.hyphenate(name);
return res;
}
},
@ -55,7 +57,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
data: {}
},
initialize: function(point) {
initialize: function Item(point) {
// Define this Item's unique id.
this._id = Item._id = (Item._id || 0) + 1;
// If _project is already set, the item was already moved into the DOM
@ -168,7 +170,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
serialize(this._style._defaults);
// There is no compact form for Item serialization, we always keep the
// type.
return [ this._class, props ];
return [ this.constructor.name, props ];
},
/**

View file

@ -22,8 +22,7 @@
*
* @extends Group
*/
var Layer = this.Layer = Group.extend(/** @lends Layer# */{
_class: 'Layer',
var Layer = Group.extend(/** @lends Layer# */{
// DOCS: improve constructor code example.
/**
* Creates a new Layer item and places it at the end of the
@ -57,7 +56,7 @@ var Layer = this.Layer = Group.extend(/** @lends Layer# */{
* position: view.center
* });
*/
initialize: function(items) {
initialize: function Layer(items) {
this._project = paper.project;
// Push it onto project.layers and set index:
this._index = this._project.layers.push(this) - 1;

View file

@ -18,8 +18,7 @@
*
* @extends Item
*/
var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
_class: 'PlacedSymbol',
var PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
_applyMatrix: false,
// PlacedSymbol uses strokeBounds for bounds
_boundsGetter: { getBounds: 'getStrokeBounds' },
@ -68,7 +67,7 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
* instance.scale(0.25 + Math.random() * 0.75);
* }
*/
initialize: function(arg0, arg1) {
initialize: function PlacedSymbol(arg0, arg1) {
// Support two forms of item initialization: Passing one object literal
// describing all the different properties to be set, or a symbol (arg0)
// and a point where it should be placed (arg1).

View file

@ -17,8 +17,7 @@
*
* @extends Item
*/
var Raster = this.Raster = Item.extend(/** @lends Raster# */{
_class: 'Raster',
var Raster = Item.extend(/** @lends Raster# */{
_applyMatrix: false,
// Raster doesn't make the distinction between the different bounds,
// so use the same name for all of them
@ -72,7 +71,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
* raster.scale(0.5);
* raster.rotate(10);
*/
initialize: function(object, position) {
initialize: function Raster(object, position) {
// Support two forms of item initialization: Passing one object literal
// describing all the different properties to be set, or an image
// (object) and a point where it should be placed (point).

View file

@ -17,11 +17,10 @@
*
* @extends Item
*/
var Shape = this.Shape = Item.extend(/** @lends Shape# */{
_class: 'Shape',
var Shape = Item.extend(/** @lends Shape# */{
_applyMatrix: false,
initialize: function(type, point, size) {
initialize: function Shape(type, point, size) {
Item.call(this, point);
this._type = type;
this._size = size;

View file

@ -53,7 +53,7 @@ var paper = new function() {
// Include Paper classes, which are later injected into PaperScope by setting
// them on the 'this' object, e.g.:
// var Point = this.Point = Base.extend(...);
// var Point = Base.extend(...);
/*#*/ include('basic/Point.js');
/*#*/ include('basic/Size.js');
@ -126,18 +126,7 @@ var paper = new function() {
/*#*/ } // options.svg
/*#*/ include('core/PaperScript.js');
/*#*/ include('core/initialize.js');
/*#*/ if (options.server) {
/*#*/ include('export.js');
return paper;
/*#*/ } else if (options.version != 'dev') {
// Finally inject the classes set on 'this' into the PaperScope class and create
// the first PaperScope and return it, all in one statement.
// The version for 'dev' of this happens in core/initialize.js, since it depends
// on sequentiality of include() loading.
// Mark this object as enumerable, so all the injected classes can be enumerated
// again in PaperScope#install().
this.enumerable = true;
return new (PaperScope.inject(this));
/*#*/ } // options.version != 'dev'
};

View file

@ -20,8 +20,7 @@
*
* @extends PathItem
*/
var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
_class: 'CompoundPath',
var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
_serializeFields: {
pathData: ''
},
@ -49,7 +48,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
* // Move the inner circle 5pt to the right:
* compoundPath.children[1].position.x += 5;
*/
initialize: function(arg) {
initialize: function CompoundPath(arg) {
PathItem.call(this);
// CompoundPath has children and supports named children.
this._children = [];

View file

@ -24,7 +24,7 @@
* convenient ways to work with parts of the path, finding lengths, positions or
* tangents at given offsets.
*/
var Curve = this.Curve = Base.extend(/** @lends Curve# */{
var Curve = Base.extend(/** @lends Curve# */{
/**
* Creates a new curve object.
*
@ -55,7 +55,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
* @param {Number} x2
* @param {Number} y2
*/
initialize: function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
initialize: function Curve(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
var count = arguments.length;
if (count === 0) {
this._segment1 = new Segment();

View file

@ -26,7 +26,7 @@
* {@link PathItem#getIntersections(path)},
* etc.
*/
var CurveLocation = this.CurveLocation = Base.extend(/** @lends CurveLocation# */{
var CurveLocation = Base.extend(/** @lends CurveLocation# */{
// DOCS: CurveLocation class description: add these back when the mentioned
// functioned have been added: {@link Path#split(location)}
/**
@ -36,7 +36,8 @@ var CurveLocation = this.CurveLocation = Base.extend(/** @lends CurveLocation# *
* @param {Number} parameter
* @param {Point} point
*/
initialize: function(curve, parameter, point, _otherCurve, _distance) {
initialize: function CurveLocation(curve, parameter, point, _otherCurve,
_distance) {
// Define this CurveLocation's unique id.
this._id = CurveLocation._id = (CurveLocation._id || 0) + 1;
this._curve = curve;

View file

@ -18,8 +18,7 @@
* @extends PathItem
*/
// DOCS: Explain that path matrix is always applied with each transformation.
var Path = this.Path = PathItem.extend(/** @lends Path# */{
_class: 'Path',
var Path = PathItem.extend(/** @lends Path# */{
_serializeFields: {
segments: [],
closed: false
@ -67,7 +66,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
* selected: true
* });
*/
initialize: function(arg) {
initialize: function Path(arg) {
this._closed = false;
this._segments = [];
Item.call(this);

View file

@ -19,7 +19,7 @@
*
* @extends Item
*/
var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
var PathItem = Item.extend(/** @lends PathItem# */{
/**
* Returns all intersections between two {@link PathItem} items as an array
* of {@link CurveLocation} objects. {@link CompoundPath} items are also

View file

@ -22,9 +22,7 @@
* {@link Segment#handleOut}), describing the tangents of the two {@link Curve}
* objects that are connected by this segment.
*/
var Segment = this.Segment = Base.extend(/** @lends Segment# */{
_class: 'Segment',
var Segment = Base.extend(/** @lends Segment# */{
/**
* Creates a new Segment object.
*
@ -110,7 +108,7 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
* path.strokeColor = 'black';
* @ignore
*/
initialize: function(arg0, arg1, arg2, arg3, arg4, arg5) {
initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) {
var count = arguments.length,
createPoint = SegmentPoint.create,
point, handleIn, handleOut;

View file

@ -30,7 +30,7 @@
* An array of all open projects is accessible through the
* {@link PaperScope#projects} variable.
*/
var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
var Project = PaperScopeItem.extend(/** @lends Project# */{
_list: 'projects',
_reference: 'project',
@ -44,7 +44,7 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
* @param {View|HTMLCanvasElement} view Either a view object or an HTML
* Canvas element that should be wrapped in a newly created view.
*/
initialize: function(view) {
initialize: function Project(view) {
// Activate straight away by passing true to base(), so paper.project is
// set, as required by Layer and DoumentView constructors.
PaperScopeItem.call(this, true);

View file

@ -19,9 +19,7 @@
* internal properties such as segment lists and gradient positions don't need
* to be updated with every transformation.
*/
var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
_class: 'Symbol',
var Symbol = Base.extend(/** @lends Symbol# */{
/**
* Creates a Symbol item.
*
@ -59,7 +57,7 @@ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
* instance.scale(0.25 + Math.random() * 0.75);
* }
*/
initialize: function(item, dontCenter) {
initialize: function Symbol(item, dontCenter) {
// Define this Symbols's unique id.
this._id = Symbol._id = (Symbol._id || 0) + 1;
this.project = paper.project;
@ -72,7 +70,7 @@ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
_serialize: function(options, dictionary) {
return dictionary.add(this, function() {
return Base.serialize([this._class, this._definition],
return Base.serialize([this.constructor.name, this._definition],
options, false, dictionary);
});
},

View file

@ -40,7 +40,7 @@
* // converted to a Color.
* circle.fillColor = '#ff0000';
*/
var Color = this.Color = Base.extend(new function() {
var Color = Base.extend(new function() {
var types = {
gray: ['gray'],
@ -275,7 +275,6 @@ var Color = this.Color = Base.extend(new function() {
};
}, this);
}, /** @lends Color# */{
_class: 'Color',
// Tell Base.read that the Point constructor supports reading with index
_readIndex: true,
@ -436,7 +435,7 @@ var Color = this.Color = Base.extend(new function() {
* // 100% and a lightness of 50%:
* circle.fillColor = { hue: 90, saturation: 1, lightness: 0.5 };
*/
initialize: function(arg) {
initialize: function Color(arg) {
// We are storing color internally as an array of components
var slice = Array.prototype.slice,
args = arguments,
@ -503,7 +502,7 @@ var Color = this.Color = Base.extend(new function() {
: nameToRGB(arg);
type = 'rgb';
} else if (argType === 'object') {
if (arg._class === 'Color') {
if (arg.constructor === Color) {
type = arg._type;
components = arg._components.slice();
alpha = arg._alpha;
@ -516,7 +515,7 @@ var Color = this.Color = Base.extend(new function() {
components[i] = point.clone();
}
}
} else if (arg._class === 'Gradient') {
} else if (arg.constructor === Gradient) {
type = 'gradient';
values = args;
} else {

View file

@ -59,11 +59,9 @@
* destination: path.bounds.rightCenter
* };
*/
var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
_class: 'Gradient',
var Gradient = Base.extend(/** @lends Gradient# */{
// DOCS: Document #initialize()
initialize: function(stops, radial) {
initialize: function Gradient(stops, radial) {
// Define this Gradient's unique id.
this._id = Gradient._id = (Gradient._id || 0) + 1;
if (stops && this._set(stops))

View file

@ -16,7 +16,7 @@
*
* @class The GradientStop object.
*/
var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
var GradientStop = Base.extend(/** @lends GradientStop# */{
/**
* Creates a GradientStop object.
*
@ -24,7 +24,7 @@ var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
* @param {Number} [rampPoint=0] the position of the stop on the gradient
* ramp as a value between 0 and 1.
*/
initialize: function(arg0, arg1) {
initialize: function GradientStop(arg0, arg1) {
if (arg0) {
var color, rampPoint;
if (arg1 === undefined && Array.isArray(arg0)) {

View file

@ -65,7 +65,7 @@
* };
*
*/
var Style = this.Style = Base.extend(new function() {
var Style = Base.extend(new function() {
// windingRule / resolution / fillOverprint / strokeOverprint are currently
// not supported.
var defaults = {
@ -201,7 +201,7 @@ var Style = this.Style = Base.extend(new function() {
Item.inject(item);
return fields;
}, /** @lends Style# */{
initialize: function(style) {
initialize: function Style(style) {
// We keep values in a separate object that we can iterate over.
this._values = {};
if (this._item instanceof TextItem)

View file

@ -19,9 +19,7 @@
*
* @extends TextItem
*/
var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
_class: 'PointText',
var PointText = TextItem.extend(/** @lends PointText# */{
/**
* Creates a point text item
*
@ -43,6 +41,9 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
* fontSize: 25
* });
*/
initialize: function PointText() {
TextItem.apply(this, arguments);
},
clone: function() {
return this._clone(new PointText());

View file

@ -21,7 +21,7 @@
*
* @extends Item
*/
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
var TextItem = Item.extend(/** @lends TextItem# */{
_boundsSelected: true,
_serializeFields: {
content: null
@ -30,7 +30,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
// so use the same name for all of them
_boundsGetter: 'getBounds',
initialize: function(arg) {
initialize: function TextItem(arg) {
// Support two forms of item initialization: Passing one object literal
// describing all the different properties to be set, or a point where
// it should be placed (arg).

View file

@ -42,7 +42,7 @@
* path.add(event.point);
* }
*/
var Tool = this.Tool = PaperScopeItem.extend(/** @lends Tool# */{
var Tool = PaperScopeItem.extend(/** @lends Tool# */{
_list: 'tools',
_reference: '_tool', // PaperScope has accessor for #tool
_events: [ 'onActivate', 'onDeactivate', 'onEditOptions',
@ -50,7 +50,7 @@ var Tool = this.Tool = PaperScopeItem.extend(/** @lends Tool# */{
'onKeyDown', 'onKeyUp' ],
// DOCS: rewrite Tool constructor explanation
initialize: function(props) {
initialize: function Tool(props) {
PaperScopeItem.call(this);
this._firstMove = true;
this._count = 0;

View file

@ -21,11 +21,11 @@
*
* @extends Event
*/
var ToolEvent = this.ToolEvent = Event.extend(/** @lends ToolEvent# */{
var ToolEvent = Event.extend(/** @lends ToolEvent# */{
// Have ToolEvent#item fall back to returning null, not undefined.
_item: null,
initialize: function(tool, type, event) {
initialize: function ToolEvent(tool, type, event) {
this.tool = tool;
this.type = type;
this.event = event;

View file

@ -22,7 +22,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
* @param {HTMLCanvasElement} canvas The canvas object that this view should
* wrap
*/
initialize: function(canvas) {
initialize: function CanvasView(canvas) {
// Handle canvas argument
if (!(canvas instanceof HTMLCanvasElement)) {
// 2nd argument onwards could be view size, otherwise use default:

View file

@ -14,7 +14,7 @@
* @name Component
* @class
*/
var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
var Component = Base.extend(Callback, /** @lends Component# */{
_events: [ 'onChange', 'onClick' ],
_types: {
@ -58,7 +58,7 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
}
},
initialize: function(obj) {
initialize: function Component(obj) {
this._type = obj.type in this._types
? obj.type
: 'options' in obj

View file

@ -14,8 +14,8 @@
* @name Event
* @class
*/
var Event = this.Event = Base.extend(/** @lends Event# */{
initialize: function(event) {
var Event = Base.extend(/** @lends Event# */{
initialize: function Event(event) {
this.event = event;
},

View file

@ -14,7 +14,7 @@
* @name Key
* @namespace
*/
var Key = this.Key = new function() {
var Key = new function() {
// TODO: Make sure the keys are called the same as in Scriptographer
// Missing: tab, cancel, clear, page-down, page-up, comma, minus, period,
// slash, etc etc etc.

View file

@ -20,8 +20,8 @@
*
* @extends Event
*/
var KeyEvent = this.KeyEvent = Event.extend(/** @lends KeyEvent# */{
initialize: function(down, key, character, event) {
var KeyEvent = Event.extend(/** @lends KeyEvent# */{
initialize: function KeyEvent(down, key, character, event) {
Event.call(this, event);
this.type = down ? 'keydown' : 'keyup';
this.key = key;

View file

@ -22,8 +22,8 @@
*
* @extends Event
*/
var MouseEvent = this.MouseEvent = Event.extend(/** @lends MouseEvent# */{
initialize: function(type, event, point, target, delta) {
var MouseEvent = Event.extend(/** @lends MouseEvent# */{
initialize: function MouseEvent(type, event, point, target, delta) {
Event.call(this, event);
this.type = type;
this.point = point;

View file

@ -14,10 +14,10 @@
* @name Palette
* @class
*/
var Palette = this.Palette = Base.extend(Callback, /** @lends Palette# */{
var Palette = Base.extend(Callback, /** @lends Palette# */{
_events: [ 'onChange' ],
initialize: function(title, components, values) {
initialize: function Palette(title, components, values) {
var parent = DomElement.find('.palettejs-panel')
|| DomElement.find('body').appendChild(
DomElement.create('div', { 'class': 'palettejs-panel' }));

View file

@ -19,8 +19,8 @@
* center, both useful for constructing artwork that should appear centered on
* screen.
*/
var View = this.View = Base.extend(Callback, /** @lends View# */{
initialize: function(element) {
var View = Base.extend(Callback, /** @lends View# */{
initialize: function View(element) {
// Store reference to the currently active global paper scope, and the
// active project, which will be represented by this view
this._scope = paper;

View file

@ -10,7 +10,7 @@
* All rights reserved.
*/
var Numerical = this.Numerical = new function() {
var Numerical = new function() {
// Lookup tables for abscissas and weights with values for n = 2 .. 16.
// As values are symetric, only store half of them and addapt algorithm