Last active
December 17, 2015 13:49
-
-
Save puleos/5620456 to your computer and use it in GitHub Desktop.
Web Application Exercise
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
var App = new Marionette.Application(); | |
App.addRegions({ | |
"content": "#content", | |
"navigation": "#navigation", | |
}); | |
App.on("initialize:after", function() { | |
Backbone.history.start(); | |
}); | |
App.module("Module", function(Mod, App, Backbone, Marionette, $, _){ | |
// Define Models to Represent our application state | |
// -------------------------------------- | |
Mod.QueryModel = Backbone.Model.extend({ | |
defaults: { | |
keywords: "", | |
searchOptions: [] | |
} | |
}); | |
Mod.SearchResults = Backbone.Collection.extend({ | |
url: "", | |
initialize: function(){ | |
}, | |
parse: function(res){ | |
} | |
}); | |
// Define a Views to render our templates | |
// -------------------------------------- | |
Mod.HomeView = Marionette.ItemView.extend({ | |
template: "#home-template" | |
}); | |
Mod.NavigationView = Marionette.ItemView.extend({ | |
template: "#navigation-template", | |
events: { | |
'keypress #search-input' : 'searchKeywords', | |
}, | |
searchKeywords: function(e){ | |
if ( typeof e.keyCode == 'undefined' || e.keyCode == 13) { | |
var keywords = $(e.target).val(); | |
if(keywords === '') return; | |
this.model.set({keywords: keywords}); | |
} | |
} | |
}); | |
Mod.SearchResultItem = Marionette.ItemView.extend({ | |
tagName: "li", | |
template: "#search-result-item-template" | |
}); | |
Mod.SearchResultCompositeView = Marionette.CompositeView.extend({ | |
template: "#search-result-template", | |
itemView: Mod.SearchResultItem, | |
itemViewContainer: "ul", | |
tagName: "ul" | |
}); | |
// Define a controller to run this module | |
// -------------------------------------- | |
var Router = Marionette.AppRouter.extend({ | |
appRoutes: { | |
"": "home", | |
"search/:keywords": "search" | |
} | |
}); | |
var Controller = Marionette.Controller.extend({ | |
start: function(){ | |
this.queryModel = new Mod.QueryModel(); | |
this.searchResults = new Mod.SearchResults(); | |
this.setupNavigation(); | |
this.setupSearch(); | |
}, | |
search: function(keywords){ | |
App.content.show(this.searchResultsView); | |
console.log(keywords); | |
}, | |
home: function() { | |
var homeView = new Mod.HomeView(); | |
App.content.show(homeView); | |
}, | |
setupNavigation: function(){ | |
this.navigationView = new Mod.NavigationView({ | |
model: this.queryModel | |
}); | |
App.navigation.show(this.navigationView); | |
}, | |
setupSearch: function() { | |
var self = this; | |
this.queryModel.on("change:keywords", function(){ | |
var keywords = this.get('keywords'); | |
self.search(keywords); | |
// todo, update route silently | |
}); | |
this.searchResultsView = new Mod.SearchResultCompositeView({ | |
model: this.queryModel, | |
collection: this.searchResults | |
}); | |
} | |
}); | |
Mod.addInitializer(function(){ | |
Mod.controller = new Controller(); | |
Mod.router = new Router({ | |
controller: Mod.controller | |
}); | |
Mod.controller.start(); | |
}); | |
}); | |
// Start the app | |
// ------------- | |
App.start(); |
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> | |
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | |
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | |
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | |
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width"> | |
<!-- Place favicon.ico and apple-touch-icon.png in the root directory --> | |
<link rel="stylesheet" href="styles/main.css"> | |
<!-- build:js scripts/vendor/modernizr.js --> | |
<script src="bower_components/modernizr/modernizr.js"></script> | |
<!-- endbuild --> | |
</head> | |
<body> | |
<div class="navbar navbar-inverse navbar-fixed-top"> | |
<div class="navbar-inner"> | |
<div class="container-fluid"> | |
<a class="btn btn-navbar collapsed" data-toggle="collapse" data-target=".navbar-inverse-collapse"> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</a> | |
<a class="brand logo" href="#">Limelight Labs</a> | |
<div class="nav-collapse collapse navbar-inverse-collapse"> | |
<ul class="nav"> | |
<li class="active"><a href="#">Home</a></li> | |
<li><a href="#">Blog</a></li> | |
<li><a href="#">Events</a></li> | |
<li class="dropdown"> | |
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Knowledge Base <b class="caret"></b></a> | |
<ul class="dropdown-menu"> | |
<li><a href="#">Contextual Editing</a></li> | |
<li><a href="#">Email Newsletters</a></li> | |
<li><a href="#">Interativity Tools</a></li> | |
<li class="divider"></li> | |
<li><a href="#">Mobile</a></li> | |
<li><a href="#">Registraton & Single-Sign-On</a></li> | |
</ul> | |
</li> | |
</ul> | |
<div class="navbar-search pull-left" action=""> | |
<section id="navigation"> | |
</section> | |
</div> | |
</div> | |
<section id="navbar"></section> | |
</div> | |
</div><!-- /navbar-inner --> | |
</div> | |
<div class="container" id="content"> | |
</div> | |
<!-- Templates --> | |
<script id="home-template" type="text/html"> | |
<div class="hero-unit"> | |
<h1>Home View</h1> | |
<p>Welcome to Limelight Labs</p> | |
</div> | |
</script> | |
<script id="navigation-template" type="text/html"> | |
<input id="search-input" type="text" class="search-query span3" placeholder="Search"> | |
</script> | |
<script id="search-result-item-template" type="text/html"> | |
item... | |
</script> | |
<script id="search-result-template" type="text/html"> | |
Search Results | |
<ul></ul> | |
</script> | |
<!--[if lt IE 7]> | |
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p> | |
<![endif]--> | |
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. --> | |
<script> | |
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']]; | |
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; | |
g.src='//www.google-analytics.com/ga.js'; | |
s.parentNode.insertBefore(g,s)}(document,'script')); | |
</script> | |
<!-- build:js scripts/main.js --> | |
<script src="bower_components/jquery/jquery.js"></script> | |
<script src="bower_components/underscore/underscore.js"></script> | |
<script src="bower_components/backbone/backbone.js"></script> | |
<script src="bower_components/backbone.marionette/lib/backbone.marionette.js"></script> | |
<script src="scripts/main.js"></script> | |
<!-- endbuild --> | |
<!-- build:js scripts/plugins.js --> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-affix.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-alert.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-dropdown.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-tooltip.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-modal.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-transition.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-button.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-popover.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-typeahead.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-carousel.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-scrollspy.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-collapse.js"></script> | |
<script src="bower_components/sass-bootstrap/js/bootstrap-tab.js"></script> | |
<!-- endbuild --> | |
</body> | |
</html> |
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
$iconSpritePath: "../images/glyphicons-halflings.png"; | |
$iconWhiteSpritePath: "../images/glyphicons-halflings-white.png"; | |
@import 'sass-bootstrap/lib/bootstrap'; | |
@import 'sass-bootstrap/lib/responsive'; | |
a.logo { | |
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAeCAIAAADCaIt+AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllP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YBQwPir9MOwqtti7LLc2TjEOKXODX89thDJhuvfXgchmqrZ+zRwVMolGuBCEw3mH1QFJgFTAPTaMgF7Wh1jzxDfzhUZHbJT1iYIyN922MqgNiEs9MLmA0urIPXY57paSota4bWSFY9WYetdd7CUHSduup8A2GD6sZC1yETc2OJllU1qPgQXzBEPM+mVwf0NCTR8xBcAVSlOkprrX813q7LrtvzWlQ6QUKTF9WaqDhyYPE/AQYAYOZbsJAIe8YAAAAASUVORK5CYII='); | |
background-repeat: no-repeat; | |
text-indent: 25px; | |
} | |
.hero-unit { | |
margin: 50px auto 0 auto; | |
width: 300px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment