Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #27 from mattdbridges/named_forms

optionally name a form that is present on pages with different URLs
  • Loading branch information...
commit 1dc5791399f38305b71f348d009332fe4c73eb66 2 parents bce583a + 19a1531
@simsalabim authored
View
3  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 );
View
19 spec/javascripts/fixtures/fixtures.html
@@ -143,8 +143,25 @@
</div>
</form>
</fieldset>
+ <fieldset class="form-wrap sexy-border">
+ <legend class="form-legend">Form 3</legend>
+ <form name="named" id="named" method="get">
+ <div class="field">
+ <label for="yetAnotherName" class="input-label">Input Text <span class="code">[name="name"]</span>:</label>
+ <input type="text" name="name" value="" id="yetAnotherName" class="width-all dark"/>
+ </div>
+ <div class="field">
+ <label for="yetAnotherTextarea" class="input-label">Textarea <span class="code">[name="description"]</span>:</label>
+ <textarea name="description" cols="50" rows="10" id="yetAnotherTextarea" class="width-all dark"></textarea>
+ </div>
+ <div class="field">
+ <input type="submit" value="Submit" />
+ <input type="reset" value="Reset" />
+ </div>
+ </form>
+ </fieldset>
<div class="submit-both">
- <input type="button" value="Submit Both" id="sendAll" />
+ <input type="button" value="Submit All" id="sendAll" />
</div>
</div>
View
22 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(),
Please sign in to comment.
Something went wrong with that request. Please try again.