Created
February 21, 2012 16:06
-
-
Save danmillar/1877181 to your computer and use it in GitHub Desktop.
Sammy SelectiveHearing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sammy SelectiveHearing (plugin) | |
* Version 1.0 | |
* https://gist.github.com/1877181 | |
* | |
* This little plugin stops Sammy reporting an error when the route is not handled, | |
* and also only listens to form submissions which start with a #. | |
* | |
* Copyright (c) 2012 Dan Millar (@danmillar / decode.uk.com) | |
* Dual licensed under the MIT and GPL licenses. | |
*/ | |
;(function($) { | |
Sammy = Sammy || {}; | |
Sammy.SelectiveHearing = function(app) { | |
this.init_location = this.getLocation(); | |
this.notFound = function(verb, path) { | |
if(this.debug) { | |
var ret = this.error(['404 Not Found', verb, path].join(' ')); | |
return (verb === 'get') ? ret : true; | |
} | |
}; | |
this.defaultCheckFormSubmission = this._checkFormSubmission; | |
this._checkFormSubmission = function(form) { | |
var $form = $(form), | |
path = $form.attr("action"); | |
if(!(/^#/).test(path)) { | |
return; | |
} else { | |
return this.defaultCheckFormSubmission(form); | |
} | |
}; | |
this.restart = function() { | |
this.setLocation(this.init_location) | |
}; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment