Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… examples
  • Loading branch information...
commit ff8898650b9a0099066d743ac3df44559b3cda0c 1 parent 8a709ab
@andykent authored
Showing with 28 additions and 1 deletion.
  1. +2 −1  lib/polypage.jquery.js
  2. +26 −0 spec/public-api-spec.js
View
3  lib/polypage.jquery.js
@@ -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
26 spec/public-api-spec.js
@@ -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);
+ });
+ });
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.