From 7fc19bd55695ac1c519c76b5ebe244a4920dcae0 Mon Sep 17 00:00:00 2001 From: Matt Bridges Date: Tue, 8 May 2012 11:26:17 -0500 Subject: [PATCH 1/3] optionally name a form that is present on pages with different URLs --- sisyphus.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sisyphus.js b/sisyphus.js index 54e3ede..732b936 100644 --- a/sisyphus.js +++ b/sisyphus.js @@ -109,6 +109,7 @@ customKeyPrefix: "", timeout: 0, autoRelease: true, + name: null, onSave: function() {}, onRestore: function() {}, onRelease: function() {} @@ -142,7 +143,7 @@ targets = targets || {}; var self = this; this.targets = this.targets || []; - this.href = location.hostname + location.pathname + location.search; + this.href = this.options.name || location.hostname + location.pathname + location.search; this.targets = $.merge( this.targets, targets ); this.targets = $.unique( this.targets ); From 8120de7393b2d58dafeaf8f0137aecaed3c75b45 Mon Sep 17 00:00:00 2001 From: Matt Bridges Date: Fri, 11 May 2012 13:43:48 -0500 Subject: [PATCH 2/3] adding tests for named forms --- spec/javascripts/fixtures/fixtures.html | 17 +++++++++++++++++ spec/spec.js | 22 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/spec/javascripts/fixtures/fixtures.html b/spec/javascripts/fixtures/fixtures.html index 9d58c56..764055a 100644 --- a/spec/javascripts/fixtures/fixtures.html +++ b/spec/javascripts/fixtures/fixtures.html @@ -139,6 +139,23 @@ +
+ Form 3 +
+
+ + +
+
+ + +
+
+ + +
+
+
diff --git a/spec/spec.js b/spec/spec.js index fb02a26..1156d67 100644 --- a/spec/spec.js +++ b/spec/spec.js @@ -1,11 +1,12 @@ describe("Sisyphus", function() { - var sisyphus, targetForm; + var sisyphus, targetForm, namedForm; beforeEach( function() { loadFixtures( "fixtures.html" ); sisyphus = Sisyphus.getInstance(); sisyphus.setOptions( {} ); targetForm = $( "#form1" ); + namedForm = $( "#named" ); sisyphus.protect( targetForm ); } ); @@ -18,7 +19,7 @@ describe("Sisyphus", function() { var sisyphus1 = Sisyphus.getInstance(); expect( typeof sisyphus1 ).toEqual( "object" ); } ); - + it( "should return null on freeing", function() { sisyphus = Sisyphus.free(); expect( sisyphus ).toEqual( null ); @@ -77,6 +78,13 @@ describe("Sisyphus", function() { expect( targets1 ).toBeLessThan( targets2 ); } ); + it( "should allow a custom name for the form", function() { + sisyphus = Sisyphus.getInstance(); + sisyphus.setOptions( { name: "something" } ); + sisyphus.protect( namedForm ); + expect ( sisyphus.href ).toEqual( "something" ); + } ); + it( "should not protect the same form twice and more times", function() { // #form1 is already being protected from 'beforeEach' method var targets1 = sisyphus.targets.length, @@ -184,8 +192,14 @@ describe("jQuery.sisyphus", function() { sisyphus = Sisyphus.getInstance(); expect( o ).toEqual( sisyphus ); } ); - - + + it( "should set the custom name on the Sisyphus instance", function() { + Sisyphus.free() + var o = $(" #named" ).sisyphus( { name: "custom-name" } ); + sisyphus = Sisyphus.getInstance(); + expect( o.href ).toEqual( "custom-name" ); + } ); + it( "should protect matched forms with Sisyphus", function() { spyOn( Sisyphus.getInstance(), "protect" ); $( "#form1" ).sisyphus(), From 19a1531eb6938cc5591d315884c99c749905e516 Mon Sep 17 00:00:00 2001 From: Matt Bridges Date: Fri, 11 May 2012 13:45:18 -0500 Subject: [PATCH 3/3] renaming Submit Both button in fixtures --- spec/javascripts/fixtures/fixtures.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/javascripts/fixtures/fixtures.html b/spec/javascripts/fixtures/fixtures.html index 764055a..456fe81 100644 --- a/spec/javascripts/fixtures/fixtures.html +++ b/spec/javascripts/fixtures/fixtures.html @@ -157,7 +157,7 @@
- +