social_cheesecake 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Rakefile +111 -0
- data/app/assets/javascripts/kinetic.js +448 -407
- data/app/assets/javascripts/social_cheesecake.js +1 -2
- data/app/assets/javascripts/socialcheesecake/_header.js +28 -0
- data/app/assets/javascripts/socialcheesecake/actor.js +104 -41
- data/app/assets/javascripts/socialcheesecake/cheesecake.js +26 -31
- data/app/assets/javascripts/socialcheesecake/grid.js +53 -12
- data/app/assets/javascripts/socialcheesecake/sector.js +108 -93
- data/app/assets/javascripts/socialcheesecake/text.js +39 -36
- data/lib/generators/social_cheesecake/install_generator.rb +10 -0
- data/lib/social_cheesecake/version.rb +1 -1
- data/social_cheesecake.gemspec +1 -0
- data/test/dummy/.gitignore +15 -0
- data/test/dummy/Gemfile +34 -0
- data/test/dummy/README +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/images/beatriz.png +0 -0
- data/test/dummy/app/assets/images/rails.png +0 -0
- data/test/dummy/app/assets/images/youngAlberto.png +0 -0
- data/test/dummy/app/assets/javascripts/application.js +10 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +48 -0
- data/test/dummy/config/boot.rb +6 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/doc/README_FOR_APP +2 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/lib/tasks/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/index.html +133 -0
- data/test/dummy/public/robots.txt +5 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/.gitkeep +0 -0
- data/test/dummy/test/functional/.gitkeep +0 -0
- data/test/dummy/test/integration/.gitkeep +0 -0
- data/test/dummy/test/performance/browsing_test.rb +12 -0
- data/test/dummy/test/test_helper.rb +13 -0
- data/test/dummy/test/unit/.gitkeep +0 -0
- data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/dummy/vendor/plugins/.gitkeep +0 -0
- metadata +114 -29
- data/app/assets/javascripts/socialCheesecake.js +0 -161
@@ -1,9 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
* KineticJS JavaScript Library
|
2
|
+
* KineticJS JavaScript Library v3.1.0
|
3
3
|
* http://www.kineticjs.com/
|
4
4
|
* Copyright 2011, Eric Rowell
|
5
5
|
* Licensed under the MIT or GPL Version 2 licenses.
|
6
|
-
* Date: Dec
|
6
|
+
* Date: Dec 19 2011
|
7
7
|
*
|
8
8
|
* Copyright (C) 2011 by Eric Rowell
|
9
9
|
*
|
@@ -27,515 +27,556 @@
|
|
27
27
|
*/
|
28
28
|
var Kinetic = {};
|
29
29
|
|
30
|
+
/****************************************
|
31
|
+
* Layer
|
32
|
+
*/
|
33
|
+
Kinetic.Layer = function(stage, stripStyling) {
|
34
|
+
this.canvas = document.createElement('canvas');
|
35
|
+
this.context = this.canvas.getContext('2d');
|
36
|
+
this.canvas.width = stage.width;
|
37
|
+
this.canvas.height = stage.height;
|
38
|
+
this.canvas.style.position = 'absolute';
|
39
|
+
this.shapes = [];
|
40
|
+
|
41
|
+
if(stripStyling) {
|
42
|
+
this.context.stroke = function() {
|
43
|
+
};
|
44
|
+
this.context.fill = function() {
|
45
|
+
};
|
46
|
+
}
|
47
|
+
|
48
|
+
stage.container.appendChild(this.canvas);
|
49
|
+
}
|
50
|
+
/*
|
51
|
+
* clear layer
|
52
|
+
*/
|
53
|
+
Kinetic.Layer.prototype.clear = function() {
|
54
|
+
var context = this.getContext();
|
55
|
+
var canvas = this.getCanvas();
|
56
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
57
|
+
}
|
58
|
+
/*
|
59
|
+
* get layer canvas
|
60
|
+
*/
|
61
|
+
Kinetic.Layer.prototype.getCanvas = function() {
|
62
|
+
return this.canvas;
|
63
|
+
}
|
64
|
+
/*
|
65
|
+
* get layer context
|
66
|
+
*/
|
67
|
+
Kinetic.Layer.prototype.getContext = function() {
|
68
|
+
return this.context;
|
69
|
+
}
|
70
|
+
/*
|
71
|
+
* get layer shapes
|
72
|
+
*/
|
73
|
+
Kinetic.Layer.prototype.getShapes = function() {
|
74
|
+
return this.shapes;
|
75
|
+
}
|
76
|
+
/*
|
77
|
+
* draw all shapes in layer
|
78
|
+
*/
|
79
|
+
Kinetic.Layer.prototype.draw = function() {
|
80
|
+
this.clear();
|
81
|
+
var context = this.getContext();
|
82
|
+
|
83
|
+
for(var n = 0; n < this.getShapes().length; n++) {
|
84
|
+
this.getShapes()[n].draw(this);
|
85
|
+
}
|
86
|
+
};
|
30
87
|
/****************************************
|
31
88
|
* Stage
|
32
89
|
*/
|
33
|
-
Kinetic.Stage = function(containerId, width, height){
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
this.canvas.style.position = 'absolute';
|
59
|
-
this.container.appendChild(this.canvas);
|
60
|
-
|
61
|
-
this.listen();
|
90
|
+
Kinetic.Stage = function(containerId, width, height) {
|
91
|
+
this.container = document.getElementById(containerId);
|
92
|
+
this.width = width;
|
93
|
+
this.height = height;
|
94
|
+
this.zIndexCounter = 9999;
|
95
|
+
this.idCounter = 0;
|
96
|
+
this.dblClickWindow = 400;
|
97
|
+
// ms
|
98
|
+
// desktop flags
|
99
|
+
this.mousePos = null;
|
100
|
+
this.mouseDown = false;
|
101
|
+
this.mouseUp = false;
|
102
|
+
|
103
|
+
// mobile flags
|
104
|
+
this.touchPos = null;
|
105
|
+
this.touchStart = false;
|
106
|
+
this.touchEnd = false;
|
107
|
+
|
108
|
+
// create layers
|
109
|
+
this.backStageLayer = new Kinetic.Layer(this, true);
|
110
|
+
this.stageLayer = new Kinetic.Layer(this);
|
111
|
+
this.propsLayer = new Kinetic.Layer(this);
|
112
|
+
this.actorsLayer = new Kinetic.Layer(this);
|
113
|
+
this.backStageLayer.getCanvas().style.display = 'none';
|
114
|
+
this.listen();
|
62
115
|
};
|
63
|
-
|
64
116
|
/*
|
65
|
-
*
|
117
|
+
* get back stage layer
|
66
118
|
*/
|
67
|
-
Kinetic.Stage.prototype.
|
68
|
-
|
69
|
-
var canvas = this.getCanvas();
|
70
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
119
|
+
Kinetic.Stage.prototype.getBackStageLayer = function() {
|
120
|
+
return this.backStageLayer;
|
71
121
|
};
|
72
|
-
|
73
122
|
/*
|
74
|
-
*
|
123
|
+
* get stage layer
|
75
124
|
*/
|
76
|
-
Kinetic.Stage.prototype.
|
77
|
-
|
78
|
-
this.clear();
|
79
|
-
|
80
|
-
// clear shapes
|
81
|
-
for (var n = 0; n < this.shapes.length; n++) {
|
82
|
-
this.shapes[n].clear();
|
83
|
-
}
|
125
|
+
Kinetic.Stage.prototype.getStageLayer = function() {
|
126
|
+
return this.stageLayer;
|
84
127
|
};
|
85
|
-
|
86
128
|
/*
|
87
|
-
*
|
129
|
+
* get props layer
|
88
130
|
*/
|
89
|
-
Kinetic.Stage.prototype.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
131
|
+
Kinetic.Stage.prototype.getPropsLayer = function() {
|
132
|
+
return this.propsLayer;
|
133
|
+
};
|
134
|
+
/*
|
135
|
+
* get actors layer
|
136
|
+
*/
|
137
|
+
Kinetic.Stage.prototype.getActorsLayer = function() {
|
138
|
+
return this.actorsLayer;
|
139
|
+
};
|
140
|
+
/*
|
141
|
+
* clear stage
|
142
|
+
*/
|
143
|
+
Kinetic.Stage.prototype.clear = function() {
|
144
|
+
this.stageLayer.clear();
|
145
|
+
};
|
146
|
+
/*
|
147
|
+
* clear all canvases
|
148
|
+
*/
|
149
|
+
Kinetic.Stage.prototype.clearAll = function() {
|
150
|
+
this.backStageLayer.clear();
|
151
|
+
this.stageLayer.clear();
|
152
|
+
this.propsLayer.clear();
|
153
|
+
this.actorsLayer.clear();
|
154
|
+
};
|
155
|
+
/*
|
156
|
+
* short-hand for draw actors layer
|
157
|
+
*/
|
158
|
+
Kinetic.Stage.prototype.draw = function() {
|
159
|
+
this.getActorsLayer().draw();
|
94
160
|
};
|
95
|
-
|
96
161
|
/*
|
97
162
|
* remove a shape from the stage
|
98
163
|
*/
|
99
|
-
Kinetic.Stage.prototype.remove = function(shape){
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
if (id == shape.id) {
|
109
|
-
this.shapes.splice(n, 1);
|
110
|
-
}
|
111
|
-
}
|
164
|
+
Kinetic.Stage.prototype.remove = function(shape) {
|
165
|
+
// remove from shapes array
|
166
|
+
var shapes = this.getShapes();
|
167
|
+
for(var n = 0; n < shapes.length; n++) {
|
168
|
+
var id = shapes[n].id;
|
169
|
+
if(id == shape.id) {
|
170
|
+
shape.getLayer().getShapes().splice(n, 1);
|
171
|
+
}
|
172
|
+
}
|
112
173
|
};
|
113
|
-
|
114
174
|
/*
|
115
175
|
* remove all shapes from the stage
|
116
176
|
*/
|
117
|
-
Kinetic.Stage.prototype.removeAll = function(){
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
this.remove(that.shapes[0]);
|
122
|
-
}
|
177
|
+
Kinetic.Stage.prototype.removeAll = function() {
|
178
|
+
// remove all shapes
|
179
|
+
this.getPropsLayer().shapes = [];
|
180
|
+
this.getActorsLayer().shapes = [];
|
123
181
|
};
|
124
|
-
|
125
182
|
/*
|
126
183
|
* get stage canvas
|
127
184
|
*/
|
128
|
-
Kinetic.Stage.prototype.getCanvas = function(){
|
129
|
-
|
185
|
+
Kinetic.Stage.prototype.getCanvas = function() {
|
186
|
+
return this.stageLayer.getCanvas();
|
130
187
|
};
|
131
|
-
|
132
188
|
/*
|
133
189
|
* get stage context
|
134
190
|
*/
|
135
|
-
Kinetic.Stage.prototype.getContext = function(){
|
136
|
-
|
191
|
+
Kinetic.Stage.prototype.getContext = function() {
|
192
|
+
return this.stageLayer.getContext();
|
137
193
|
};
|
138
|
-
|
139
194
|
/*
|
140
195
|
* add event listener to stage (which is essentially
|
141
196
|
* the container DOM)
|
142
197
|
*/
|
143
|
-
Kinetic.Stage.prototype.addEventListener = function(type, func){
|
144
|
-
|
198
|
+
Kinetic.Stage.prototype.addEventListener = function(type, func) {
|
199
|
+
this.container.addEventListener(type, func);
|
145
200
|
};
|
146
|
-
|
147
201
|
/*
|
148
202
|
* add shape to stage
|
149
203
|
*/
|
150
|
-
Kinetic.Stage.prototype.add = function(shape){
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
204
|
+
Kinetic.Stage.prototype.add = function(shape) {
|
205
|
+
shape.stage = this;
|
206
|
+
if(shape.isProp) {
|
207
|
+
shape.layer = this.propsLayer;
|
208
|
+
} else {
|
209
|
+
shape.layer = this.actorsLayer;
|
210
|
+
}
|
211
|
+
|
212
|
+
shape.getLayer().shapes.push(shape);
|
213
|
+
|
214
|
+
shape.id = this.idCounter++;
|
215
|
+
shape.draw(shape.layer);
|
162
216
|
};
|
163
|
-
|
164
217
|
/*
|
165
218
|
* handle incoming event
|
166
219
|
*/
|
167
|
-
Kinetic.Stage.prototype.handleEvent = function(evt){
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
n = -1; // break;
|
277
|
-
}
|
278
|
-
}());
|
279
|
-
}
|
220
|
+
Kinetic.Stage.prototype.handleEvent = function(evt) {
|
221
|
+
if(!evt) {
|
222
|
+
evt = window.event;
|
223
|
+
}
|
224
|
+
|
225
|
+
this.setMousePosition(evt);
|
226
|
+
this.setTouchPosition(evt);
|
227
|
+
|
228
|
+
var backStageLayer = this.backStageLayer;
|
229
|
+
var backStageLayerContext = backStageLayer.getContext();
|
230
|
+
var that = this;
|
231
|
+
|
232
|
+
backStageLayer.clear();
|
233
|
+
|
234
|
+
for(var n = this.getShapes().length - 1; n >= 0; n--) {
|
235
|
+
var pubShape = this.getShapes()[n]; ( function() {
|
236
|
+
var shape = pubShape;
|
237
|
+
shape.draw(backStageLayer);
|
238
|
+
var pos = that.touchPos || that.mousePos;
|
239
|
+
var el = shape.eventListeners;
|
240
|
+
|
241
|
+
if(shape.visible && pos !== null && backStageLayerContext.isPointInPath(pos.x, pos.y)) {
|
242
|
+
// handle onmousedown
|
243
|
+
if(that.mouseDown) {
|
244
|
+
that.mouseDown = false;
|
245
|
+
shape.clickStart = true;
|
246
|
+
|
247
|
+
if(el.onmousedown !== undefined) {
|
248
|
+
el.onmousedown(evt);
|
249
|
+
}
|
250
|
+
n = -1;
|
251
|
+
}
|
252
|
+
// handle onmouseup & onclick
|
253
|
+
else if(that.mouseUp) {
|
254
|
+
that.mouseUp = false;
|
255
|
+
if(el.onmouseup !== undefined) {
|
256
|
+
el.onmouseup(evt);
|
257
|
+
}
|
258
|
+
|
259
|
+
// detect if click or double click occurred
|
260
|
+
if(shape.clickStart) {
|
261
|
+
|
262
|
+
if(el.onclick !== undefined) {
|
263
|
+
el.onclick(evt);
|
264
|
+
}
|
265
|
+
|
266
|
+
if(el.ondblclick !== undefined && shape.inDoubleClickWindow) {
|
267
|
+
el.ondblclick(evt);
|
268
|
+
}
|
269
|
+
|
270
|
+
shape.inDoubleClickWindow = true;
|
271
|
+
|
272
|
+
setTimeout(function() {
|
273
|
+
shape.inDoubleClickWindow = false;
|
274
|
+
}, that.dblClickWindow);
|
275
|
+
}
|
276
|
+
n = -1;
|
277
|
+
}
|
278
|
+
|
279
|
+
// handle touchstart
|
280
|
+
else if(that.touchStart) {
|
281
|
+
that.touchStart = false;
|
282
|
+
if(el.touchstart !== undefined) {
|
283
|
+
el.touchstart(evt);
|
284
|
+
}
|
285
|
+
n = -1;
|
286
|
+
}
|
287
|
+
|
288
|
+
// handle touchend
|
289
|
+
else if(that.touchEnd) {
|
290
|
+
that.touchEnd = false;
|
291
|
+
if(el.touchend !== undefined) {
|
292
|
+
el.touchend(evt);
|
293
|
+
}
|
294
|
+
n = -1;
|
295
|
+
}
|
296
|
+
|
297
|
+
// handle touchmove
|
298
|
+
else if(el.touchmove !== undefined) {
|
299
|
+
el.touchmove(evt);
|
300
|
+
n = -1;
|
301
|
+
}
|
302
|
+
|
303
|
+
// handle onmouseover
|
304
|
+
else if(!shape.mouseOver) {
|
305
|
+
shape.mouseOver = true;
|
306
|
+
if(el.onmouseover !== undefined) {
|
307
|
+
el.onmouseover(evt);
|
308
|
+
}
|
309
|
+
n = -1;
|
310
|
+
}
|
311
|
+
|
312
|
+
// handle onmousemove
|
313
|
+
else if(el.onmousemove !== undefined) {
|
314
|
+
el.onmousemove(evt);
|
315
|
+
n = -1;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
// handle mouseout condition
|
319
|
+
else if(shape.mouseOver) {
|
320
|
+
shape.mouseOver = false;
|
321
|
+
if(el.onmouseout !== undefined) {
|
322
|
+
el.onmouseout(evt);
|
323
|
+
}
|
324
|
+
n = -1;
|
325
|
+
}
|
326
|
+
}());
|
327
|
+
}
|
280
328
|
};
|
281
|
-
|
282
329
|
/*
|
283
330
|
* begin listening for events by adding event handlers
|
284
331
|
* to the container
|
285
332
|
*/
|
286
|
-
Kinetic.Stage.prototype.listen = function(){
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
}, false);
|
333
|
+
Kinetic.Stage.prototype.listen = function() {
|
334
|
+
var that = this;
|
335
|
+
|
336
|
+
// desktop events
|
337
|
+
this.container.addEventListener("mousedown", function(evt) {
|
338
|
+
that.mouseDown = true;
|
339
|
+
that.handleEvent(evt);
|
340
|
+
}, false);
|
341
|
+
|
342
|
+
this.container.addEventListener("mousemove", function(evt) {
|
343
|
+
that.mouseUp = false;
|
344
|
+
that.mouseDown = false;
|
345
|
+
that.handleEvent(evt);
|
346
|
+
}, false);
|
347
|
+
|
348
|
+
this.container.addEventListener("mouseup", function(evt) {
|
349
|
+
that.mouseUp = true;
|
350
|
+
that.mouseDown = false;
|
351
|
+
that.handleEvent(evt);
|
352
|
+
|
353
|
+
// clear all click starts
|
354
|
+
for(var i = 0; i < that.getShapes().length; i++) {
|
355
|
+
that.getShapes()[i].clickStart = false;
|
356
|
+
}
|
357
|
+
}, false);
|
358
|
+
|
359
|
+
this.container.addEventListener("mouseover", function(evt) {
|
360
|
+
that.handleEvent(evt);
|
361
|
+
}, false);
|
362
|
+
|
363
|
+
this.container.addEventListener("mouseout", function(evt) {
|
364
|
+
that.mousePos = null;
|
365
|
+
}, false);
|
366
|
+
// mobile events
|
367
|
+
this.container.addEventListener("touchstart", function(evt) {
|
368
|
+
evt.preventDefault();
|
369
|
+
that.touchStart = true;
|
370
|
+
that.handleEvent(evt);
|
371
|
+
}, false);
|
372
|
+
|
373
|
+
this.container.addEventListener("touchmove", function(evt) {
|
374
|
+
evt.preventDefault();
|
375
|
+
that.handleEvent(evt);
|
376
|
+
}, false);
|
377
|
+
|
378
|
+
this.container.addEventListener("touchend", function(evt) {
|
379
|
+
evt.preventDefault();
|
380
|
+
that.touchEnd = true;
|
381
|
+
that.handleEvent(evt);
|
382
|
+
}, false);
|
337
383
|
};
|
338
|
-
|
339
384
|
/*
|
340
385
|
* get mouse position for desktop apps
|
341
386
|
*/
|
342
|
-
Kinetic.Stage.prototype.getMousePos = function(evt){
|
343
|
-
|
387
|
+
Kinetic.Stage.prototype.getMousePos = function(evt) {
|
388
|
+
return this.mousePos;
|
344
389
|
};
|
345
|
-
|
346
390
|
/*
|
347
391
|
* get touch position for mobile apps
|
348
392
|
*/
|
349
|
-
Kinetic.Stage.prototype.getTouchPos = function(evt){
|
350
|
-
|
393
|
+
Kinetic.Stage.prototype.getTouchPos = function(evt) {
|
394
|
+
return this.touchPos;
|
351
395
|
};
|
352
|
-
|
353
396
|
/*
|
354
397
|
* set mouse positon for desktop apps
|
355
398
|
*/
|
356
|
-
Kinetic.Stage.prototype.setMousePosition = function(evt){
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
399
|
+
Kinetic.Stage.prototype.setMousePosition = function(evt) {
|
400
|
+
var mouseX = evt.clientX - this.getContainerPos().left + window.pageXOffset;
|
401
|
+
var mouseY = evt.clientY - this.getContainerPos().top + window.pageYOffset;
|
402
|
+
this.mousePos = {
|
403
|
+
x : mouseX,
|
404
|
+
y : mouseY
|
405
|
+
};
|
363
406
|
};
|
364
|
-
|
365
407
|
/*
|
366
408
|
* set touch position for mobile apps
|
367
409
|
*/
|
368
|
-
Kinetic.Stage.prototype.setTouchPosition = function(evt){
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
410
|
+
Kinetic.Stage.prototype.setTouchPosition = function(evt) {
|
411
|
+
if(evt.touches !== undefined && evt.touches.length == 1) {// Only deal with
|
412
|
+
// one finger
|
413
|
+
var touch = evt.touches[0];
|
414
|
+
// Get the information for finger #1
|
415
|
+
var touchX = touch.clientX - this.getContainerPos().left + window.pageXOffset;
|
416
|
+
var touchY = touch.clientY - this.getContainerPos().top + window.pageYOffset;
|
417
|
+
|
418
|
+
this.touchPos = {
|
419
|
+
x : touchX,
|
420
|
+
y : touchY
|
421
|
+
};
|
422
|
+
}
|
381
423
|
};
|
382
|
-
|
383
424
|
/*
|
384
425
|
* get container position
|
385
426
|
*/
|
386
|
-
Kinetic.Stage.prototype.getContainerPos = function(){
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
427
|
+
Kinetic.Stage.prototype.getContainerPos = function() {
|
428
|
+
var obj = this.container;
|
429
|
+
var top = 0;
|
430
|
+
var left = 0;
|
431
|
+
while(obj.tagName != "BODY") {
|
432
|
+
top += obj.offsetTop;
|
433
|
+
left += obj.offsetLeft;
|
434
|
+
obj = obj.offsetParent;
|
435
|
+
}
|
436
|
+
return {
|
437
|
+
top : top,
|
438
|
+
left : left
|
439
|
+
};
|
399
440
|
};
|
400
|
-
|
401
441
|
/*
|
402
442
|
* get container DOM element
|
403
443
|
*/
|
404
|
-
Kinetic.Stage.prototype.getContainer = function(){
|
405
|
-
|
444
|
+
Kinetic.Stage.prototype.getContainer = function() {
|
445
|
+
return this.container;
|
446
|
+
};
|
447
|
+
/*
|
448
|
+
* get all shapes
|
449
|
+
*/
|
450
|
+
Kinetic.Stage.prototype.getShapes = function() {
|
451
|
+
return (this.getPropsLayer().getShapes()).concat(this.getActorsLayer().getShapes());
|
406
452
|
};
|
407
|
-
|
408
453
|
/****************************************
|
409
454
|
* Shape
|
410
455
|
*/
|
411
|
-
Kinetic.Shape = function(drawFunc){
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
456
|
+
Kinetic.Shape = function(drawFunc, isProp) {
|
457
|
+
this.drawFunc = drawFunc;
|
458
|
+
this.isProp = isProp === undefined ? false : isProp;
|
459
|
+
this.x = 0;
|
460
|
+
this.y = 0;
|
461
|
+
this.scale = {
|
462
|
+
x : 1,
|
463
|
+
y : 1
|
464
|
+
};
|
465
|
+
this.rotation = 0;
|
466
|
+
// radians
|
467
|
+
// store state for next clear
|
468
|
+
this.lastX = 0;
|
469
|
+
this.lastY = 0;
|
470
|
+
this.lastRotation = 0;
|
471
|
+
// radians
|
472
|
+
this.lastScale = {
|
473
|
+
x : 1,
|
474
|
+
y : 1
|
475
|
+
};
|
476
|
+
|
477
|
+
this.eventListeners = {};
|
478
|
+
this.mouseOver = false;
|
479
|
+
this.clickStart = false;
|
480
|
+
this.inDblClickWindow = false;
|
481
|
+
|
482
|
+
this.visible = true;
|
424
483
|
};
|
425
|
-
|
426
484
|
/*
|
427
485
|
* get stage
|
428
486
|
*/
|
429
|
-
Kinetic.Shape.prototype.getStage = function(){
|
430
|
-
|
487
|
+
Kinetic.Shape.prototype.getStage = function() {
|
488
|
+
return this.stage;
|
431
489
|
};
|
432
|
-
|
433
490
|
/*
|
434
491
|
* draw shape
|
435
492
|
*/
|
436
|
-
Kinetic.Shape.prototype.draw = function(
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
493
|
+
Kinetic.Shape.prototype.draw = function(layer) {
|
494
|
+
if(this.visible) {
|
495
|
+
var stage = this.getStage();
|
496
|
+
var context = layer.getContext();
|
497
|
+
|
498
|
+
context.save();
|
499
|
+
|
500
|
+
if(this.x !== 0 || this.y !== 0) {
|
501
|
+
context.translate(this.x, this.y);
|
502
|
+
}
|
503
|
+
if(this.rotation !== 0) {
|
504
|
+
context.rotate(this.rotation);
|
505
|
+
}
|
506
|
+
if(this.scale.x != 1 || this.scale.y != 1) {
|
507
|
+
context.scale(this.scale.x, this.scale.y);
|
508
|
+
}
|
509
|
+
|
510
|
+
this.drawFunc.call(layer);
|
511
|
+
context.restore();
|
512
|
+
}
|
453
513
|
};
|
454
|
-
|
455
514
|
/*
|
456
|
-
*
|
515
|
+
* set shape canvas scale
|
457
516
|
*/
|
458
|
-
Kinetic.Shape.prototype.
|
459
|
-
|
517
|
+
Kinetic.Shape.prototype.setScale = function(scale) {
|
518
|
+
this.scale.x = scale;
|
519
|
+
this.scale.y = scale;
|
460
520
|
};
|
461
|
-
|
462
521
|
/*
|
463
|
-
*
|
522
|
+
* add event listener to shape
|
464
523
|
*/
|
465
|
-
Kinetic.Shape.prototype.
|
466
|
-
|
524
|
+
Kinetic.Shape.prototype.addEventListener = function(type, func) {
|
525
|
+
var event = (type.indexOf('touch') == -1) ? 'on' + type : type;
|
526
|
+
this.eventListeners[event] = func;
|
467
527
|
};
|
468
|
-
|
469
528
|
/*
|
470
|
-
*
|
529
|
+
* show shape
|
471
530
|
*/
|
472
|
-
Kinetic.Shape.prototype.
|
473
|
-
|
474
|
-
this.scale.y = scale;
|
531
|
+
Kinetic.Shape.prototype.show = function() {
|
532
|
+
this.visible = true;
|
475
533
|
};
|
476
|
-
|
477
534
|
/*
|
478
|
-
*
|
535
|
+
* hide shape
|
479
536
|
*/
|
480
|
-
Kinetic.Shape.prototype.
|
481
|
-
|
482
|
-
var canvas = this.getCanvas();
|
483
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
537
|
+
Kinetic.Shape.prototype.hide = function() {
|
538
|
+
this.visible = false;
|
484
539
|
};
|
485
|
-
|
486
540
|
/*
|
487
|
-
*
|
541
|
+
* move shape to top
|
488
542
|
*/
|
489
|
-
Kinetic.Shape.prototype.
|
490
|
-
|
491
|
-
|
543
|
+
Kinetic.Shape.prototype.moveToTop = function() {
|
544
|
+
var stage = this.stage;
|
545
|
+
var layer = this.getLayer();
|
546
|
+
var shapes = layer.getShapes();
|
547
|
+
|
548
|
+
for(var n = 0; n < shapes.length; n++) {
|
549
|
+
var shape = shapes[n];
|
550
|
+
if(shape.id == this.id) {
|
551
|
+
layer.shapes.splice(n, 1);
|
552
|
+
layer.shapes.push(this);
|
553
|
+
break;
|
554
|
+
}
|
555
|
+
}
|
492
556
|
};
|
493
|
-
|
494
557
|
/*
|
495
|
-
*
|
558
|
+
* get shape layer
|
496
559
|
*/
|
497
|
-
Kinetic.Shape.prototype.
|
498
|
-
|
499
|
-
// remove shape from shapes
|
500
|
-
for (var n = 0; n < stage.shapes.length; n++) {
|
501
|
-
var reg = stage.shapes[n];
|
502
|
-
if (reg.id == this.id) {
|
503
|
-
stage.shapes.splice(n, 1);
|
504
|
-
stage.shapes.push(this);
|
505
|
-
break;
|
506
|
-
}
|
507
|
-
}
|
508
|
-
|
509
|
-
// reorder canvases
|
510
|
-
for (var n = 0; n < stage.shapes.length; n++) {
|
511
|
-
var reg = stage.shapes[n];
|
512
|
-
reg.getCanvas().style.zIndex = ++stage.zIndexCounter;
|
513
|
-
}
|
560
|
+
Kinetic.Shape.prototype.getLayer = function() {
|
561
|
+
return this.layer;
|
514
562
|
};
|
515
|
-
|
516
563
|
/****************************************
|
517
564
|
* drawImage util
|
518
565
|
* This util function draws a rectangular shape
|
519
566
|
* over a canvas image to provide a detectable path
|
520
567
|
*/
|
521
|
-
Kinetic.drawImage = function(imageObj, x, y, width, height){
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
568
|
+
Kinetic.drawImage = function(imageObj, x, y, width, height) {
|
569
|
+
if(!width) {
|
570
|
+
width = imageObj.width;
|
571
|
+
}
|
572
|
+
if(!height) {
|
573
|
+
height = imageObj.height;
|
574
|
+
}
|
575
|
+
return function() {
|
576
|
+
var context = this.getContext();
|
577
|
+
context.drawImage(imageObj, x, y, width, height);
|
578
|
+
context.beginPath();
|
579
|
+
context.rect(x, y, width, height);
|
580
|
+
context.closePath();
|
581
|
+
};
|
535
582
|
};
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|