Permalink
Browse files

pp now fires an event on every genuine state change. See the spec for…

… examples
  • Loading branch information...
1 parent 8a709ab commit ff8898650b9a0099066d743ac3df44559b3cda0c @andykent committed Mar 7, 2009
Showing with 28 additions and 1 deletion.
  1. +2 −1 lib/polypage.jquery.js
  2. +26 −0 spec/public-api-spec.js
View
@@ -42,9 +42,11 @@
setState: function(stateName,val){
var newState = !!val;
+ if(this.getState(stateName)==newState) return newState;
this.states[stateName] = newState;
this.setCookie(stateName, newState);
this.refresh();
+ this.scope.trigger('pp_stateChange', { name:stateName, value:newState });
return newState;
},
@@ -139,7 +141,6 @@
evaluateNode: function(node){
var on = this.evaluate(this.extractDataFromClassName($(node).attr('class')));
- // toggle on or off if to be displayed
$(node).toggle(on);
return on;
},
View
@@ -55,5 +55,31 @@ Screw.Unit(function() {
expect('.pp_admin').to(be_visible);
});
});
+
+ describe("fired events", function() {
+ it("fires 'pp_stateChanged' everytime a page state changes (via toggling)", function() {
+ $('#dom').trigger('pp_setState', {logged_in:false});
+ var data = false;
+ $('#dom').bind('pp_stateChange', function(e, obj) { data = obj });
+ $('#dom').trigger('pp_toggleStates', 'logged_in');
+ expect(data).to(equal, {name:'logged_in', value:true});
+ });
+
+ it("fires 'pp_stateChanged' everytime a page state changes (via switching)", function() {
+ $('#dom').trigger('pp_setState', {logged_in:true});
+ var data = false;
+ $('#dom').bind('pp_stateChange', function(e, obj) { data = obj });
+ $('#dom').trigger('pp_setState', {logged_in:false});
+ expect(data).to(equal, {name:'logged_in', value:false});
+ });
+
+ it("doesn't fire 'pp_stateChanged' if the state hasn't changed", function() {
+ $('#dom').trigger('pp_setState', {logged_in:true});
+ var data = false;
+ $('#dom').bind('pp_stateChange', function(e, obj) { data = true });
+ $('#dom').trigger('pp_setState', {logged_in:true});
+ expect(data).to(be_false);
+ });
+ });
});
});

0 comments on commit ff88986

Please sign in to comment.