Created
September 6, 2012 11:39
-
-
Save nickdunn/3655237 to your computer and use it in GitHub Desktop.
Very basic controller/action based on a page ID
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
// camelcase body ID e.g. #page-home => home, #page-contact-us => contactUs | |
var action = $('body').attr('id') | |
.replace(/^(page-)/, '') | |
.replace(/^([a-z]{1})/, function(letter) { return letter.toUpperCase(); }) | |
.replace(/-([a-z]{1})/, function(letter) { return letter.replace(/-/,'').toUpperCase(); }); | |
var Controller = { | |
// #page-home | |
home: function() { | |
... | |
} | |
// #page-contact-us | |
contactUs: function() { | |
... | |
} | |
} | |
if (typeof Controller[action] != 'undefined') { | |
Controller[action](); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment