Created
December 19, 2014 00:57
-
-
Save devdays/703ba7bf8b0892aba7a8 to your computer and use it in GitHub Desktop.
Single Page App - SammyJS, RequireJS, jQuery together
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>RequireJS and SammyJS</title> | |
</head> | |
<body> | |
<nav> | |
<ul> | |
<li><a href="#/">Items</a></li> | |
<li><a href="#/3">3</a></li> | |
</ul> | |
</nav> | |
<div id='content'></div> | |
<script src="Scripts/require.js"></script> | |
<script> | |
// ====== set up require.js ================ | |
(function () { | |
"use strict"; | |
require.config({ | |
baseUrl: 'Scripts', | |
paths: { | |
"jquery": "jquery-1.9.1", | |
"sammy": "sammy-0.7.4", | |
}, | |
shim: { | |
// we get an error that "jQuery is not defined" error without this | |
// shim for sammy | |
"sammy": { | |
deps: ["jquery"], | |
exports: "sammy" | |
} | |
} | |
}); | |
})(); | |
require(['sammy'], function (sammy) { | |
"use strict"; | |
console.log("initializing sammy"); | |
var app = $.sammy('#content', function () { | |
this.get('#/', function (context) { | |
context.log('Yo yo yo'); | |
}); | |
this.get('#/:item', function (context) { | |
var param = this.params['item']; | |
context.log('Ho ho ho ' + param); | |
}); | |
}); | |
$(function () { | |
app.run('#/'); | |
}); | |
//})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment