Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 19, 2014 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/703ba7bf8b0892aba7a8 to your computer and use it in GitHub Desktop.
Save devdays/703ba7bf8b0892aba7a8 to your computer and use it in GitHub Desktop.
Single Page App - SammyJS, RequireJS, jQuery together
<!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