social_cheesecake 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,131 @@
1
+ socialCheesecake.defineModule(
2
+ 'SocialCheesecake#Actor'
3
+ )
4
+ .dependsOn(
5
+ 'SocialCheesecake#Text'
6
+ )
7
+ .withCode(function() {
8
+ socialCheesecake.Actor = function(settings) {
9
+ if(!settings) throw "No arguments passed to the function"
10
+ if(!settings.parent) throw "Actor must be associated to at least a subsector"
11
+ var defaultSettings = {
12
+ }
13
+ for(var property in defaultSettings) {
14
+ if(!( property in settings)) {
15
+ settings[property] = defaultSettings[property];
16
+ }
17
+ }
18
+ this.id = settings.id;
19
+ this.parents = [];
20
+ if(settings.parent) this.parents.push(settings.parent);
21
+
22
+ var actor = this;
23
+ var gridIdPrefix = this.parents[0].parent.parent.grid.divIdPrefix;
24
+ var actor_div = document.getElementById(gridIdPrefix+this.id);
25
+ var mouseoverCallback = function(){
26
+ var sector;
27
+ actor.focus();
28
+ for (var subsector in actor.parents){
29
+ sector = actor.parents[subsector].parent;
30
+ sector.eventHandler("mouseover");
31
+ actor.parents[subsector].eventHandler("mouseover");
32
+ }
33
+ }
34
+ var mouseoutCallback = function(){
35
+ var sector;
36
+ actor.unfocus();
37
+ for (var subsector in actor.parents){
38
+ sector = actor.parents[subsector].parent;
39
+ sector.eventHandler("mouseout");
40
+ actor.parents[subsector].eventHandler("mouseout");
41
+ }
42
+ console.log("mouseout");
43
+ }
44
+ actor_div.addEventListener("mouseover", mouseoverCallback, false);
45
+ actor_div.addEventListener("mouseout", mouseoutCallback, false);
46
+ actor_div.addEventListener("mousedown", function(){
47
+ var sector;
48
+ if( arguments.callee.activeActor){
49
+ // Deactivate actor
50
+ arguments.callee.activeActor = false;
51
+ actor_div.addEventListener("mouseover", mouseoverCallback, false);
52
+ actor_div.addEventListener("mouseout", mouseoutCallback, false);
53
+ }else{
54
+ //Activate actor
55
+ arguments.callee.activeActor = true;
56
+ actor_div.removeEventListener("mouseover", mouseoverCallback, false);
57
+ actor_div.removeEventListener("mouseout", mouseoutCallback, false);
58
+ }
59
+ });
60
+ }
61
+
62
+ socialCheesecake.Actor.prototype.focus = function() {
63
+ var cheesecake = this.parents[0].parent.parent;
64
+ var gridIdPrefix = cheesecake.grid.divIdPrefix;
65
+ var actor_id = this.id;
66
+ var actor_div = document.getElementById(gridIdPrefix+actor_id);
67
+ var newClass="";
68
+ if (actor_div.getAttribute("class")){
69
+ if (!(actor_div.getAttribute("class").match(/\sfocused/) )){
70
+ newClass = actor_div.getAttribute("class").concat(" focused");
71
+ actor_div.setAttribute("class", newClass);
72
+ }
73
+ }else{
74
+ newClass = "focused";
75
+ actor_div.setAttribute("class", newClass);
76
+ }
77
+ }
78
+
79
+ socialCheesecake.Actor.prototype.unfocus = function() {
80
+ var cheesecake = this.parents[0].parent.parent;
81
+ var gridIdPrefix = cheesecake.grid.divIdPrefix;
82
+ var actor_id = this.id;
83
+ var actor_div = document.getElementById(gridIdPrefix+actor_id);
84
+ var newClass="";
85
+ if (actor_div.getAttribute("class")){
86
+ newClass = actor_div.getAttribute("class").replace(/(^|\s)focused($|\s)/, "");
87
+ actor_div.setAttribute("class", newClass);
88
+ }
89
+ }
90
+
91
+ socialCheesecake.Actor.prototype.isFocused = function() {
92
+ var cheesecake = this.parents[0].parent.parent;
93
+ var gridIdPrefix = cheesecake.grid.divIdPrefix;
94
+ var actor_id = this.id;
95
+ var actor_div = document.getElementById(gridIdPrefix+actor_id);
96
+ var focused = false;
97
+ if ((actor_div.getAttribute("class")) &&
98
+ (actor_div.getAttribute("class").match(/(^|\s)focused($|\s)/))){
99
+ focused = true;
100
+ }
101
+ return focused;
102
+ }
103
+
104
+ socialCheesecake.Actor.prototype.hide = function() {
105
+ var cheesecake = this.parents[0].parent.parent;
106
+ var gridIdPrefix = cheesecake.grid.divIdPrefix;
107
+ var actor_id = this.id;
108
+ var actor_div = document.getElementById(gridIdPrefix+actor_id);
109
+ var newStyle=" display: none;";
110
+ if (actor_div.getAttribute("style")){
111
+ if (actor_div.getAttribute("style").match(/display\s*:\s*[a-z]*;/)){
112
+ newStyle = actor_div.getAttribute("style").replace(/display\s*:\s*[a-z]*;/, "display: none;");
113
+ }else{
114
+ newStyle = actor_div.getAttribute("style").concat("display: none;");
115
+ }
116
+ }
117
+ actor_div.setAttribute("style", newStyle);
118
+ }
119
+
120
+ socialCheesecake.Actor.prototype.show = function() {
121
+ var cheesecake = this.parents[0].parent.parent;
122
+ var gridIdPrefix = cheesecake.grid.divIdPrefix;
123
+ var actor_id = this.id;
124
+ var actor_div = document.getElementById(gridIdPrefix+actor_id);
125
+ if (actor_div.getAttribute("style")){
126
+ var newStyle = actor_div.getAttribute("style").replace(/display\s*:\s*none;/, "");
127
+ actor_div.setAttribute("style", newStyle);
128
+ }
129
+ }
130
+ });
131
+
@@ -0,0 +1,256 @@
1
+ socialCheesecake.defineModule(
2
+ 'SocialCheesecake#Cheesecake'
3
+ )
4
+ .dependsOn(
5
+ 'SocialCheesecake#Sector',
6
+ 'SocialCheesecake#Grid'
7
+ )
8
+ .withCode(function() {
9
+ socialCheesecake.Cheesecake = function(cheesecakeData) {
10
+ var jsonSectors = cheesecakeData.sectors;
11
+ var cheesecake = this;
12
+ //Properties
13
+ cheesecake.center = {
14
+ x : cheesecakeData.center.x,
15
+ y : cheesecakeData.center.y
16
+ };
17
+ cheesecake.rMax = cheesecakeData.rMax;
18
+ cheesecake.sectors = [];
19
+ cheesecake.auxiliarSectors = [];
20
+ cheesecake.stage = new Kinetic.Stage(cheesecakeData.container.id,
21
+ cheesecakeData.container.width, cheesecakeData.container.height);
22
+ cheesecake.grid = new socialCheesecake.Grid({
23
+ parent : this,
24
+ grid_id : cheesecakeData.grid.id,
25
+ divIdPrefix : cheesecakeData.grid.divIdPrefix || "actor_"
26
+ });
27
+
28
+ var phi = 0;
29
+ var delta = 2 * Math.PI / jsonSectors.length;
30
+ var actors = [];
31
+ for(var i = 0; i < jsonSectors.length; i++) {
32
+ var settings = {
33
+ parent : cheesecake,
34
+ center : {
35
+ x : cheesecakeData.center.x,
36
+ y : cheesecakeData.center.y
37
+ },
38
+ label : jsonSectors[i].name,
39
+ phi : phi,
40
+ delta : delta,
41
+ rOut : cheesecakeData.rMax,
42
+ subsectors : jsonSectors[i].subsectors,
43
+ mouseover : {
44
+ color : "#aaffaa",
45
+ callback : function(sector) {
46
+ document.body.style.cursor = "pointer";
47
+ cheesecake.grid.hideAll();
48
+ for (var actor in sector.actors){
49
+ sector.actors[actor].show();
50
+ }
51
+ }
52
+ },
53
+ mouseout : {
54
+ color : "#eeffee",
55
+ callback : function(sector) {
56
+ document.body.style.cursor = "default";
57
+ cheesecake.grid.showAll();
58
+ }
59
+ },
60
+ mousedown : {
61
+ color : "#77ff77",
62
+ callback : function(sector) {
63
+ cheesecake.focusAndBlurCheesecake(sector);
64
+ cheesecake.grid.hideAll();
65
+ for (var actor in sector.actors){
66
+ sector.actors[actor].show();
67
+ }
68
+ }
69
+ },
70
+ mouseup : { color : "#aaffaa" }
71
+ };
72
+ cheesecake.sectors[i] = new socialCheesecake.Sector(settings);
73
+ cheesecake.stage.add(cheesecake.sectors[i].getRegion());
74
+ phi += delta;
75
+ }
76
+ }
77
+
78
+ socialCheesecake.Cheesecake.prototype.focusAndBlurCheesecake = function(sector) {
79
+ var cheesecake = this;
80
+ var regions = cheesecake.stage.shapes;
81
+ var sectorIndex;
82
+ for(var i in cheesecake.sectors) {
83
+ if(cheesecake.sectors[i] === sector) sectorIndex = i;
84
+ }
85
+ if(sectorIndex == null)
86
+ throw "sector doesn't belong to this cheesecake"
87
+ for(var i = (regions.length - 1); i >= 0; i--) {
88
+ if(!regions[i].permanent) {
89
+ cheesecake.stage.remove(regions[i]);
90
+ }
91
+ }
92
+
93
+ //Unfocus all actors
94
+ cheesecake.grid.unfocusAll();
95
+
96
+ //Add auxiliar sectors
97
+ var greySettings = {
98
+ parent : cheesecake,
99
+ center : {
100
+ x : cheesecake.center.x,
101
+ y : cheesecake.center.y
102
+ },
103
+ phi : sector.phi + sector.delta,
104
+ delta : 2 * Math.PI - sector.delta,
105
+ rOut : cheesecake.rMax,
106
+ mouseout : {
107
+ color : "#f5f5f5",
108
+ callback : function() {
109
+ document.body.style.cursor = "default";
110
+ }
111
+ },
112
+ mousedown : { color : "#f5f5f5" },
113
+ mouseup : { color : "#f5f5f5" },
114
+ mouseover : {
115
+ color : "#f5f5f5",
116
+ callback : function() {
117
+ document.body.style.cursor = "pointer";
118
+ }
119
+ },
120
+ color : "#f5f5f5"
121
+ };
122
+ var dummySettings = {
123
+ parent : cheesecake,
124
+ center : {
125
+ x : cheesecake.center.x,
126
+ y : cheesecake.center.y
127
+ },
128
+ phi : sector.phi,
129
+ delta : sector.delta,
130
+ rOut : sector.rOut,
131
+ label : sector.label,
132
+ simulate : sectorIndex,
133
+ mouseout : {
134
+ callback : function() {
135
+ document.body.style.cursor = "default";
136
+ }
137
+ },
138
+ mouseover : {
139
+ callback : function() {
140
+ document.body.style.cursor = "pointer";
141
+ }
142
+ }
143
+ };
144
+ var greySector = new socialCheesecake.Sector(greySettings);
145
+ cheesecake.auxiliarSectors.push(greySector);
146
+ var dummySector = new socialCheesecake.Sector(dummySettings)
147
+ cheesecake.auxiliarSectors.push(dummySector);
148
+
149
+ cheesecake.stage.add(greySector.getRegion());
150
+ cheesecake.stage.add(dummySector.getRegion());
151
+ var greySectorContext = greySector.getRegion().getContext();
152
+ var dummySectorContext = dummySector.getRegion().getContext();
153
+
154
+ //Animations
155
+ var greyMousedownCallback = function() {
156
+ cheesecake.unfocusAndUnblurCheesecake();
157
+ cheesecake.grid.showAll();
158
+ }
159
+ var greyResizeCallback = function() {
160
+ greySector.mousedown.callback = greyMousedownCallback;
161
+ }
162
+ var greyRotateToCallback = function() {
163
+ greySector.resize({
164
+ context : greySectorContext,
165
+ delta : 3 * Math.PI / 2,
166
+ anchor : "M",
167
+ callback : greyResizeCallback
168
+ });
169
+ }
170
+ var dummyResizeCallback = function() {
171
+ dummySector.splitUp();
172
+ }
173
+ var dummyRotateToCallback = function() {
174
+ dummySector.resize({
175
+ context : dummySectorContext,
176
+ anchor : "M",
177
+ callback : dummyResizeCallback
178
+ });
179
+ }
180
+
181
+ greySector.rotateTo({
182
+ context : greySectorContext,
183
+ destination : 5*Math.PI / 4,
184
+ callback : greyRotateToCallback,
185
+ anchor : "M"
186
+ });
187
+
188
+ dummySector.rotateTo({
189
+ context : dummySectorContext,
190
+ destination : Math.PI / 4 ,
191
+ callback : dummyRotateToCallback,
192
+ anchor : "M"
193
+ });
194
+ }
195
+ socialCheesecake.Cheesecake.prototype.recoverCheesecake = function() {
196
+ var cheesecake = this;
197
+ var regions = cheesecake.stage.shapes;
198
+
199
+ //Delete the auxiliar sectors
200
+ for(var i = (regions.length - 1); i >= 0; i--) {
201
+ if(!regions[i].permanent) {
202
+ cheesecake.stage.remove(regions[i]);
203
+ }
204
+ }
205
+ cheesecake.auxiliarSectors.pop();
206
+
207
+ // Add the former sectors
208
+ for(var i in cheesecake.sectors) {
209
+ cheesecake.stage.add(cheesecake.sectors[i].getRegion());
210
+ }
211
+ }
212
+ socialCheesecake.Cheesecake.prototype.unfocusAndUnblurCheesecake = function() {
213
+ var cheesecake = this;
214
+ var auxiliarSectors = this.auxiliarSectors;
215
+ var sector;
216
+ var greySector;
217
+
218
+ //Localize the dummy and grey sectors
219
+ for(var i in auxiliarSectors) {
220
+ if(auxiliarSectors[i].simulate != null) {
221
+ sector = auxiliarSectors[i];
222
+ } else {
223
+ greySector = auxiliarSectors[i];
224
+ }
225
+ }
226
+
227
+ //Animate and go back to the general view
228
+ sector.putTogether();
229
+ sector.resize({
230
+ context : sector.getRegion().getContext(),
231
+ anchor : "M",
232
+ delta : sector.originalAttr.delta,
233
+ callback : function() {
234
+ sector.rotateTo({
235
+ context : sector.getRegion().getContext(),
236
+ destination : sector.originalAttr.phi
237
+ });
238
+ }
239
+ });
240
+ greySector.resize({
241
+ context : greySector.getRegion().getContext(),
242
+ anchor : "M",
243
+ delta : greySector.originalAttr.delta,
244
+ callback : function() {
245
+ greySector.rotateTo({
246
+ context : greySector.getRegion().getContext(),
247
+ destination : greySector.originalAttr.phi,
248
+ callback : function() {
249
+ cheesecake.recoverCheesecake();
250
+ }
251
+ });
252
+ }
253
+ });
254
+ }
255
+ });
256
+
@@ -0,0 +1,149 @@
1
+ socialCheesecake.defineModule(
2
+ 'SocialCheesecake#Grid'
3
+ )
4
+ .dependsOn(
5
+ 'SocialCheesecake#Actor'
6
+ )
7
+ .withCode(function() {
8
+ socialCheesecake.Grid = function (settings){
9
+ if (!settings) throw "No arguments passed to the function";
10
+ console.log(settings.actors);
11
+
12
+ //Actors dimensions and positions
13
+ this.actors = [];
14
+ this.parent = settings.parent;
15
+ this.id = settings.grid_id;
16
+ this.divIdPrefix = settings.divIdPrefix;
17
+ }
18
+
19
+ socialCheesecake.Grid.prototype.addActor = function (actor_info, subsector) {
20
+ var actors = this.actors;
21
+ var actor;
22
+
23
+ //Check if the actor is already in the array
24
+ var actorAlreadyDeclared = false;
25
+ for (var i in actors){
26
+ if (actors[i].id == actor_info.id){
27
+ actorAlreadyDeclared = true;
28
+ actor = actors[i];
29
+ //Check if the subsector has already been declared a parent of the actor
30
+ var subsectorAlreadyDeclared = false;
31
+ for ( var parent in actor.parents){
32
+ if (actor.parents[parent] == subsector) subsectorAlreadyDeclared=true;
33
+ }
34
+ if (!subsectorAlreadyDeclared) actor.parents.push(subsector);
35
+ }
36
+ }
37
+ // If the actor was not in the array, create it and add it to the array
38
+ if(!actorAlreadyDeclared){
39
+ actor = new socialCheesecake.Actor({
40
+ id : actor_info.id,
41
+ parent: subsector
42
+ });
43
+ actors.push(actor);
44
+ }
45
+ return actor;
46
+ }
47
+
48
+ socialCheesecake.Grid.prototype.getActor = function (id) {
49
+ for (var i in actors){
50
+ if (this.actors[i].id == id){
51
+ return this.actors[i];
52
+ }
53
+ }
54
+ return null
55
+ }
56
+
57
+ socialCheesecake.Grid.prototype.focus = function (actor_ids) {
58
+ if (actor_ids instanceof Array) {
59
+ for(var i in actor_ids){
60
+ var actor = actor_ids[i];
61
+ if(actor instanceof socialCheesecake.Actor){
62
+ actor.focus();
63
+ }else{
64
+ this.getActor(actor).focus();
65
+ }
66
+ }
67
+ } else {
68
+ if(actor_ids instanceof socialCheesecake.Actor){
69
+ actor_ids.focus();
70
+ }else{
71
+ this.getActor(actor_ids).focus();
72
+ }
73
+ }
74
+ }
75
+
76
+ socialCheesecake.Grid.prototype.focusAll = function () {
77
+ this.focus(this.actors);
78
+ }
79
+
80
+ socialCheesecake.Grid.prototype.hide = function (actor_ids) {
81
+ if (actor_ids instanceof Array) {
82
+ for(var i in actor_ids){
83
+ var actor = actor_ids[i];
84
+ if(actor instanceof socialCheesecake.Actor){
85
+ actor.hide();
86
+ }else{
87
+ this.getActor(actor).hide();
88
+ }
89
+ }
90
+ } else {
91
+ if(actor_ids instanceof socialCheesecake.Actor){
92
+ actor_ids.hide();
93
+ }else{
94
+ this.getActor(actor_ids).hide();
95
+ }
96
+ }
97
+ }
98
+
99
+ socialCheesecake.Grid.prototype.hideAll = function () {
100
+ this.hide(this.actors)
101
+ }
102
+
103
+ socialCheesecake.Grid.prototype.show = function (actor_ids) {
104
+ if (actor_ids instanceof Array) {
105
+ for(var i in actor_ids){
106
+ var actor = actor_ids[i];
107
+ if(actor instanceof socialCheesecake.Actor){
108
+ actor.show();
109
+ }else{
110
+ this.getActor(actor).show();
111
+ }
112
+ }
113
+ } else {
114
+ if(actor_ids instanceof socialCheesecake.Actor){
115
+ actor_ids.show();
116
+ }else{
117
+ this.getActor(actor_ids).show();
118
+ }
119
+ }
120
+ }
121
+
122
+ socialCheesecake.Grid.prototype.showAll = function () {
123
+ this.show(this.actors)
124
+ }
125
+
126
+ socialCheesecake.Grid.prototype.unfocus = function (actor_ids) {
127
+ if (actor_ids instanceof Array) {
128
+ for(var i in actor_ids){
129
+ var actor = actor_ids[i];
130
+ if(actor instanceof socialCheesecake.Actor){
131
+ actor.unfocus();
132
+ }else{
133
+ this.getActor(actor).unfocus();
134
+ }
135
+ }
136
+ } else {
137
+ if(actor_ids instanceof socialCheesecake.Actor){
138
+ actor_ids.unfocus();
139
+ }else{
140
+ this.getActor(actor_ids).unfocus();
141
+ }
142
+ }
143
+ }
144
+
145
+ socialCheesecake.Grid.prototype.unfocusAll = function () {
146
+ this.unfocus(this.actors)
147
+ }
148
+ });
149
+