Skip to content

Instantly share code, notes, and snippets.

View jeffreytgilbert's full-sized avatar

Jeffrey Gilbert jeffreytgilbert

View GitHub Profile
@nanotronic
nanotronic / can.control.route
Created March 19, 2013 16:11
Allowing optional parameters for can.Control.route. E.g.: docs/:section(/:subsection) > create two routes: docs/:section and docs/:section/:subsection docs(/:section)(/:subsection) > create three routes: docs, docs/:section and docs/:section/:subsection
define(['can/util/library', 'can/route', 'can/control'], function (can) {
var optionalParam = /\((.*?)\)/g,
escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
var getOptionalParam = function(route){
return route.replace(escapeRegExp, '\\$&').match(optionalParam);
};
// ## control/route.js
@revolunet
revolunet / indexof-min.js
Created February 25, 2012 12:44
IE<9 indexOf polyfill
if(!Array.prototype.indexOf){Array.prototype.indexOf=function(b){var a=this.length>>>0;var c=Number(arguments[1])||0;c=(c<0)?Math.ceil(c):Math.floor(c);if(c<0){c+=a}for(;c<a;c++){if(c in this&&this[c]===b){return c}}return -1}};