Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: OpenBookPrices/l2b-demo-app
base: 815085dc80
...
head fork: OpenBookPrices/l2b-demo-app
compare: 07260475cd
Checking mergeability… Don't worry, you can still create the pull request.
  • 7 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
3  Makefile
@@ -5,7 +5,8 @@ node-modules:
npm prune
jshint:
- node_modules/.bin/jshint --config config/jshint-node.json *.js
+ node_modules/.bin/jshint --config config/jshint-node.json *.js
+ node_modules/.bin/jshint --config config/jshint-browser.json public/js
css:
compass compile public
View
15 config/jshint-browser.json
@@ -0,0 +1,15 @@
+{
+ "browser": true,
+ "devel": true,
+
+ "camelcase": true,
+ "curly": true,
+ "indent": 2,
+ "newcap": true,
+ "quotmark": true,
+ "regexp": true,
+ "strict": true,
+ "trailing": true,
+ "undef": true,
+ "unused": true
+}
View
14 public/index.html
@@ -39,9 +39,23 @@
</form>
</div>
+ <div id="book-view">
+ </div>
+
<footer>
<a href="https://github.com/LinkToBooks/l2b-demo-app">The code for this website is on Github</a>
</footer>
</body>
</html>
+
+<script id="book-view-template" type="text/template">
+ <h1><%- book.title || 'Fetching title...' %></h1>
+
+ <p>
+ <strong>author:</strong> <%- book.author || '???' %>
+ </p>
+ <p>
+ <strong>isbn:</strong> <%- book.isbn || '???' %>
+ </p>
+</script>
View
80 public/js/app.js
@@ -1,17 +1,71 @@
-var SearchView = Backbone.View.extend({
- events : {
- "submit form": "doSearch"
- },
+/*global Backbone:false, $:false, _:false */
+
+(function () {
+ "use strict";
+
+ var BookModel = Backbone.Model.extend({
+ urlRoot: "http://api.127.0.0.1.xip.io:3000/books/"
+ });
+
+
+ var BookView = Backbone.View.extend({
+ el: function () {
+ return $("#book-view");
+ },
+
+ initialize: function () {
+ this.listenTo(this.model, "change", this.render);
+ },
+
+ render: function () {
+
+ var data = this.model ? this.model.toJSON() : {};
+
+ var content = _.template(
+ $("#book-view-template").text(),
+ { book: data }
+ );
+ this.$el.html(content);
- doSearch: function (e) {
- e.preventDefault();
+ return this;
+ }
+ });
+
+ var Router = Backbone.Router.extend({
+ routes: {
+ "isbn/:isbn": "isbnDisplay"
+ },
+
+ isbnDisplay: function (isbn) {
- var isbn = this.$('input[name=isbn]').val();
+ var model = new BookModel({ id: isbn });
+ var view = new BookView({ model: model });
+
+ view.render();
+ model.fetch();
+ }
+ });
+
+ var appRouter = new Router();
+
+ var SearchView = Backbone.View.extend({
+ events : {
+ "submit form": "doSearch"
+ },
+
+ doSearch: function (e) {
+ e.preventDefault();
+
+ var isbn = this.$("input[name=isbn]").val();
+
+ appRouter.navigate("isbn/" + isbn, {trigger: true});
+ }
+ });
+
+ $(function () {
+ new SearchView({el: $("#search-box")});
+ Backbone.history.start();
+ });
- console.log("doing a search for " + isbn);
- },
-});
+})();
-$(function() {
- var searcher = new SearchView({el: $('#search-box')});
-});
View
4 public/sass/screen.scss
@@ -18,5 +18,9 @@ h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1em; }
+strong {
+ font-weight: bold;
+}
+
header { border-bottom: 1px solid #888;}
footer { border-top: 1px solid #888;}

No commit comments for this range

Something went wrong with that request. Please try again.