03.03.2015 Views

First Demo Flip Book

This is my First Demo Flip Book

This is my First Demo Flip Book

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Displaying a Static View<br />

Now that we have the basics set up, let’s use Marionette to display content in our index.html.<br />

We’ll start by putting everything within the HTML file. But as you can guess, this approach isn’t<br />

advisable for anything beyond a trivial application: you’d lose your mind. So we’ll quickly get around<br />

to refactoring our simple application into something more robust.<br />

Let’s start by adding some javascript code at the bottom of our index.html:<br />

1 <br />

2 var ContactManager = new Marionette.Application();<br />

3<br />

4 ContactManager.start();<br />

5 <br />

What did we do? Nothing really exciting: we simply declared a new Marionette application, then<br />

started it. If you refresh the index.html page in your browser, you’ll see absolutely nothing has<br />

changed… This isn’t surprising: our application doesn’t do anything yet.<br />

Let’s now make our app display a message to the console once it has started:<br />

1 <br />

2 var ContactManager = new Marionette.Application();<br />

3<br />

4 ContactManager.on("initialize:after", function(){<br />

5 console.log("ContactManager has started!");<br />

6 });<br />

7<br />

8 ContactManager.start();<br />

9 <br />

Note we’ve defined the initialize:after handler code before we start the application.<br />

If you refresh the page with (e.g.) Firebug’s console open, you’ll see the message we’ve just added.<br />

How about we make the app do somehting a little more useful (and visual) by displaying some static<br />

content?<br />

Before we can have our app do that, we need to fulfill a few preconditions:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!