Skip to content

Instantly share code, notes, and snippets.

@danmillar
Created February 21, 2012 16:06
Show Gist options
  • Save danmillar/1877181 to your computer and use it in GitHub Desktop.
Save danmillar/1877181 to your computer and use it in GitHub Desktop.
Sammy SelectiveHearing
/*
* 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