Permalink
Browse files

Rearranging callbacks

  • Loading branch information...
adiezbal committed Mar 2, 2012
1 parent 1b34a91 commit 5018aafe7638dd69928da8b2e423e3bc01b8332b
@@ -11,14 +11,6 @@ var socialCheesecake = socialCheesecake || {};
cheesecake.rMax = cheesecakeData.rMax;
cheesecake.sectors = [];
cheesecake.highlightedSector = null;
- cheesecake.onSectorHighlight = cheesecakeData.onSectorHighlight || null;
- cheesecake.onSubsectorAddedBegin = cheesecakeData.onSubsectorAddedBegin || null;
- cheesecake.onSubsectorAddedEnd = cheesecakeData.onSubsectorAddedEnd || null;
- cheesecake.onSectorFocusBegin = cheesecakeData.onSectorFocusBegin || null;
- cheesecake.onSectorFocusEnd = cheesecakeData.onSectorFocusEnd || null;
- cheesecake.onSectorUnfocusBegin = cheesecakeData.onSectorUnfocusBegin || null;
- cheesecake.onSectorUnfocusEnd = cheesecakeData.onSectorUnfocusEnd || null;
- cheesecake.syncSectorFocusCallbacks = cheesecake.syncSectorFocusCallbacks || false;
cheesecake.auxiliarSectors = [];
cheesecake.stage = new Kinetic.Stage(cheesecakeData.container.id, cheesecakeData.container.width, cheesecakeData.container.height);
cheesecake.stage.add(new Kinetic.Layer({name: "main"}));
@@ -33,7 +25,6 @@ var socialCheesecake = socialCheesecake || {};
if(cheesecake.matchActorsNumber == null) cheesecake.matchActorsNumber = true;
cheesecake._initialState = {};
cheesecake._changes = {};
- if(cheesecakeData.onChange) cheesecake.onChange = cheesecakeData.onChange;
//Text settings
if(cheesecakeData.text) {
for(var style in cheesecakeData.text) {
@@ -48,6 +39,13 @@ var socialCheesecake = socialCheesecake || {};
}
}
}
+ //Callback settings
+ if(cheesecakeData.callbacks){
+ for(var type in cheesecakeData.callbacks) {
+ socialCheesecake.eventCallbackHandlers[type] = cheesecakeData.callbacks[type];
+ }
+ }
+ cheesecake.syncSectorFocusCallbacks = cheesecake.syncSectorFocusCallbacks || false;
//Extra sector if necessary
if(jsonSectors.length < 16) {
var extraSector = new socialCheesecake.Sector({
@@ -105,6 +103,7 @@ var socialCheesecake = socialCheesecake || {};
socialCheesecake.Cheesecake.prototype.focusAndBlurCheesecake = function(sector) {
var cheesecake = this;
var sectorIndex;
+ var onSectorFocusBegin = socialCheesecake.eventCallbackHandlers.onSectorFocusBegin;
for(var i in cheesecake.sectors) {
if(cheesecake.sectors[i] === sector)
sectorIndex = i;
@@ -157,11 +156,11 @@ var socialCheesecake = socialCheesecake || {};
callback : dummyResizeCallback
});
}
- if(cheesecake.onSectorFocusBegin) {
+ if(onSectorFocusBegin) {
if(cheesecake.syncSectorFocusCallbacks) {
- cheesecake.onSectorFocusBegin(cheesecake, callback);
+ onSectorFocusBegin(cheesecake, callback);
} else {
- cheesecake.onSectorFocusBegin(cheesecake);
+ onSectorFocusBegin(cheesecake);
callback();
}
} else {
@@ -203,6 +202,8 @@ var socialCheesecake = socialCheesecake || {};
socialCheesecake.Cheesecake.prototype.unfocusAndUnblurCheesecake = function() {
var cheesecake = this;
var auxiliarSectors = this.auxiliarSectors;
+ var onSectorUnfocusEnd = socialCheesecake.eventCallbackHandlers.onSectorUnfocusEnd;
+ var onSectorUnfocusBegin = socialCheesecake.eventCallbackHandlers.onSectorUnfocusBegin;
var dummySector;
var sectorNewDelta;
var sectorNewPhi;
@@ -230,8 +231,8 @@ var socialCheesecake = socialCheesecake || {};
anchor : "M",
delta : dummyNewDelta,
callback : function() {
- if(cheesecake.onSectorUnfocusEnd) {
- cheesecake.onSectorUnfocusEnd(cheesecake);
+ if(onSectorUnfocusEnd) {
+ onSectorUnfocusEnd(cheesecake);
}
cheesecake.grid.showAll();
dummySector.rotateTo({
@@ -252,11 +253,11 @@ var socialCheesecake = socialCheesecake || {};
}
});
}
- if(cheesecake.onSectorUnfocusBegin) {
+ if(onSectorUnfocusBegin) {
if(cheesecake.syncSectorFocusCallbacks) {
- cheesecake.onSectorUnfocusBegin(cheesecake, actions);
+ onSectorUnfocusBegin(cheesecake, actions);
} else {
- cheesecake.onSectorUnfocusBegin(cheesecake);
+ onSectorUnfocusBegin(cheesecake);
actions();
}
} else {
@@ -312,7 +313,7 @@ var socialCheesecake = socialCheesecake || {};
var actorParents = actor.getParentsIds();
var actorName = actor.name;
var actorExtraInfo = actor.extraInfo;
- var onChange = this.onChange;
+ var onChange = socialCheesecake.eventCallbackHandlers.onChange;
for(var a in changesInActors) {
if(changesInActors[a].id == actorId) {
@@ -330,7 +331,7 @@ var socialCheesecake = socialCheesecake || {};
});
}
//Execute onChange Callback
- onChange(this);
+ if(onChange) onChange(this);
}
/*
@@ -451,11 +452,10 @@ var socialCheesecake = socialCheesecake || {};
}
socialCheesecake.Cheesecake.prototype.setHighlightedSector = function(sector) {
+ var onSectorHighlight = socialCheesecake.eventCallbackHandlers.onSectorHighlight;
if(this.highlightedSector != sector) {
this.highlightedSector = sector;
- if(this.onSectorHighlight) {
- this.onSectorHighlight(this);
- }
+ if(onSectorHighlight) onSectorHighlight(this);
}
}
@@ -112,6 +112,14 @@ var socialCheesecake = socialCheesecake || {};
mouseup : function() {
return;
}
- }
+ },
+ onSectorHighlight : null,
+ onSubsectorAddedBegin : null,
+ onSubsectorAddedEnd : null,
+ onSectorFocusBegin : null,
+ onSectorFocusEnd : null,
+ onSectorUnfocusBegin : null,
+ onSectorUnfocusEnd : null,
+ onChange : null
}
})();
@@ -216,7 +216,9 @@ var socialCheesecake = socialCheesecake || {};
var dummyNormal = [];
var dummyExtra = [];
var step = 1.5;
- var mainExtraAnchor = "m"
+ var mainExtraAnchor = "m";
+ var onSubsectorAddedBegin = socialCheesecake.eventCallbackHandlers.onSubsectorAddedBegin;
+ var onSubsectorAddedEnd = socialCheesecake.eventCallbackHandlers.onSubsectorAddedEnd;
if(this.subsectors.length >= 4){
console.log("Reached subsectors limit. No new subsectors will be added");
@@ -250,7 +252,7 @@ var socialCheesecake = socialCheesecake || {};
cheesecake.removeFromLayer(allSubsectors);
this.addNewSubsector(subsectorIndex);
//Initial callback
- if(cheesecake.onSubsectorAddedBegin != null) cheesecake.onSubsectorAddedBegin(sector.subsectors[subsectorIndex]);
+ if(onSubsectorAddedBegin != null) onSubsectorAddedBegin(sector.subsectors[subsectorIndex]);
var normalSubsectors = this.subsectors;
this.extraSubsectors = [];
var extraSubsectors = sector.extraSubsectors;
@@ -342,7 +344,7 @@ var socialCheesecake = socialCheesecake || {};
if(extraSubsectors) cheesecake.addToLayer(extraSubsectors);
cheesecake.drawLayer();
cheesecake.enable();
- if(cheesecake.onSubsectorAddedEnd != null) cheesecake.onSubsectorAddedEnd(sector.subsectors[subsectorIndex]);
+ if(onSubsectorAddedEnd != null) onSubsectorAddedEnd(sector.subsectors[subsectorIndex]);
};
for (var i = 0; i< dummyNormal.length; i++){
dummyNormal[i].resizeWidth({
@@ -356,7 +358,7 @@ var socialCheesecake = socialCheesecake || {};
socialCheesecake.Sector.prototype.splitUp = function() {
var cheesecake = this.getCheesecake();
- var callback = cheesecake.onSectorFocusEnd;
+ var onSectorFocusEnd = socialCheesecake.eventCallbackHandlers.onSectorFocusEnd;
var sector = (this.simulate != null) ? cheesecake.sectors[this.simulate] : this;
var subsectors = sector.subsectors;
@@ -366,9 +368,7 @@ var socialCheesecake = socialCheesecake || {};
this.calculateSubportions();
cheesecake.addToLayer(subsectors.concat(sector.extraSubsectors));
cheesecake.drawLayer();
- if(callback){
- callback(cheesecake);
- }
+ if(onSectorFocusEnd) onSectorFocusEnd(cheesecake);
}
socialCheesecake.Sector.prototype.putTogether = function() {
@@ -1,7 +1,8 @@
var socialCheesecake = socialCheesecake || {};
(function() {
socialCheesecake.Subsector = function(settings) {
- this.id = settings.id || null;
+ this.id = null;
+ if(settings.id != undefined ) this.id = settings.id;
if(settings.parent != null) this.parent = settings.parent;
this.label = "";
if(settings.label != null) this.label = settings.label;
@@ -3,7 +3,6 @@ window.requestAnimFrame = (function(callback) {
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
-
})();
var sectorsCounter = 0;
var subsectorsCounter = [0];
@@ -19,16 +18,33 @@ var cheesecakeData = {
id : "grid",
divIdPrefix : "actor_"
},
- onChange : function() {
- console.log("Cambio detectado");
- },
- onSubsectorAddedBegin : function(subsector){
- console.log("New subsector is going to be added.");
- console.log(subsector);
- },
- onSubsectorAddedEnd : function(subsector){
- console.log("New subsector "+ subsector.getIndex() +" added in sector "+subsector.parent.getIndex());
- console.log(subsector.getCheesecake());
+ callbacks : {
+ onChange : function() {
+ console.log("Cambio detectado");
+ },
+ onSubsectorAddedBegin : function(subsector){
+ console.log("New subsector is going to be added.");
+ console.log(subsector);
+ },
+ onSubsectorAddedEnd : function(subsector){
+ console.log("New subsector "+ subsector.getIndex() +" added in sector "+subsector.parent.getIndex());
+ console.log(subsector.getCheesecake());
+ },
+ onSectorHighlight : function(){
+ console.log("sector HIGHLIGHTED");
+ },
+ onSectorFocusBegin : function(){
+ console.log("going to FOCUS sector ");
+ },
+ onSectorFocusEnd : function(){
+ console.log("sector FOCUSED");
+ },
+ onSectorUnfocusBegin : function(){
+ console.log("going to UNFOCUS sector");
+ },
+ onSectorUnfocusEnd : function(sector){
+ console.log("sector UNFOCUSED");
+ }
},
text : {
newStyle : "bold italic 14px sans-serif"

0 comments on commit 5018aaf

Please sign in to comment.