Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Created August 12, 2013 11:06
Show Gist options
  • Save Haraldson/6209969 to your computer and use it in GitHub Desktop.
Save Haraldson/6209969 to your computer and use it in GitHub Desktop.
Quiz application using cool JS techs.
requirejs.config(
{
appDir: '../',
baseUrl: 'assets/js/lib/',
paths: {
app: '../app'
},
shim: {
'lodash': {
exports: '_'
},
'backbone': {
deps: ['lodash', 'jquery'],
exports: 'Backbone'
},
/*
https://github.com/nervetattoo/backbone.touch ;---)
'backbone.touch': {
deps: ['backbone'],
exports: 'Backbone'
},
*/
'handlebars': {
exports: 'Handlebars'
}
}
});
requirejs(['backbone', 'handlebars', 'app/model/quiz', 'app/view/quiz'], function(Backbone, Handlebars, QuizModel, QuizView)
{
var QuizRouter = Backbone.Router.extend(
{
routes: {
'': 'init',
'quiz/:id(/:questionNo)': 'quiz'
},
init: function()
{
console.log('init');
},
quiz: function(id, questionNo)
{
console.log(id);
}
});
// Using jQuery for now...
$(function()
{
var quizRouter = new QuizRouter;
quizRouter.on('route:init', function()
{
alert('init');
});
Backbone.history.start(
{
pushState: true
});
});
});
requirejs(['backbone'], function(Backbone)
{
var Quiz = Backbone.Model.extend(
{
defaults: {
title: '',
description: '',
questions: [],
maxParticipants: false, // false = no limit,
feedback: {
public: false,
private: true
},
behavior: {
mode: 'manual',
questionDuration: false, // only applies for the 'auto' mode; can be overriden on a per-Question basis
pauseBetweenQuestions: false // only applies for the 'auto' mode
}
},
validate: function(attribute)
{
// Validate stuff
}
});
return Quiz;
});
requirejs(['backbone'], function(Backbone)
{
var Quiz = Backbone.View.extend(
{
id: 'quiz',
// Cache the template function for a single item.
questionTemplate: _.template($('#item-template').html()),
events: {
'click button': 'something'
},
// Called when the view is first created
initialize: function()
{
this.render();
},
// Re-render the titles of the todo item.
render: function()
{
},
something: function()
{
//
}
});
return Quiz;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment