Skip to content

Commit bb1a8ed

Browse files
committed
updated bb tutes
1 parent deb1bbe commit bb1a8ed

File tree

113 files changed

+21574
-12441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+21574
-12441
lines changed

_layouts/default.html

+30-55
Original file line numberDiff line numberDiff line change
@@ -36,71 +36,46 @@
3636
<!-- (1) Moot depends on jQuery v1.7 or greater -->
3737
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
3838

39-
<!-- (1) Moot client application -->
40-
<script src="http://cdn.moot.it/1.1/moot.min.js"></script>
4139
</head>
4240
<body>
43-
44-
45-
46-
4741
<div class="container">
48-
<hr />
49-
50-
<div class="">
51-
52-
<div class="row">
53-
<div class="span12" style="position: relative;"> <h1>
54-
<a class="" href="/">Backbone Tutorials</a>
55-
</h1>
56-
<h3>By <a href="http://thomasdav.is">Thomas Davis</a></h3>
57-
<span style="position: absolute; right: 0; top: 0;"><a href="http://twitter.com/neutralthoughts" class="twitter-follow-button">Follow @neutralthoughts</a>
58-
<br />
59-
60-
<iframe src="http://ghbtns.com/github-btn.html?user=thomasdavis&repo=backbonetutorials&type=watch&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="170px" height="30px"></iframe>
61-
62-
<iframe src="http://ghbtns.com/github-btn.html?user=thomasdavis&repo=backbonetutorials&type=fork&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="146px" height="30px"></iframe>
63-
<br />
64-
Hiring Ruby developer - YC company - Remote<br />
65-
<a href="http://jobs.earbits.com">Details</a>
66-
<!--
67-
Building a RESTful API?<br />
68-
<a href="http://apiengine.io">ApiEngine.io</a> - Coming soon
69-
<br />
70-
<div style="background: url(earbits-b.png); padding: 7px; border-radius: 3px">
71-
<a href="http://www.earbits.com?#station/music-to-work-to-electronic-for-work" style="color: #fff; text-decoration: none">
72-
<img style="margin-top: -5px" src="earbits.png" alt="earbit.com - free online radio" />
73-
<span style="display:inline-block; line-height: 20px;margin-left: 20px;">Music for hackers</span>
74-
</a>
75-
</div>-->
76-
</span>
77-
78-
79-
<a class="btn btn-warning " href="http://feeds.feedburner.com/BackboneTutorials">subscribe</a>
80-
<a class="btn btn-success " href="http://leanpub.com/backbonetutorials">download ebook - (.pdf, .MOBI, .ePUB)</a>
81-
82-
<a href="http://gum.co/backbone-beginner-screencast" class="btn btn-primary">Watch Video Tutorial</a>
8342

43+
<div class="row">
44+
<div class="col-lg-12">
45+
<div class="navbar" style="margin-top:10px;">
46+
<div class="container">
47+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
48+
<span class="icon-bar"></span>
49+
<span class="icon-bar"></span>
50+
<span class="icon-bar"></span>
51+
</button>
52+
<a class="navbar-brand" href="#">Backbone Tutorials</a>
53+
<div class="nav-collapse collapse navbar-responsive-collapse">
54+
<ul class="nav navbar-nav">
55+
<li class="active"><a href="#">Home</a></li>
56+
<li><a href="#">Link</a></li>
57+
58+
</ul>
59+
<ul class="nav navbar-nav pull-right">
60+
<li><a href="#">Subscribe</a></li>
61+
<li><a href="#">Download eBook (.pdf, .MOBI, .ePub)</a></li>
62+
</ul>
63+
</div><!-- /.nav-collapse -->
64+
</div><!-- /.container -->
65+
</div>
8466

85-
<script type="text/javascript" src="https://gumroad.com/js/gumroad.js"></script>
8667

87-
<script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>
88-
</div>
89-
68+
</div>
9069
</div>
9170
</div>
92-
<hr />
93-
94-
<div class="row">
95-
<div class="span12">
96-
97-
9871

99-
{{ content }}
100-
</div>
101-
</div>
10272

103-
73+
<div style=""></div>
74+
<div class="container">
75+
76+
<div class="container">
77+
{{ content }}
78+
</div>
10479
</div>
10580
<script src="//static.getclicky.com/js" type="text/javascript"></script>
10681
<script type="text/javascript">try{ clicky.init(66406579); }catch(e){}</script>

_site/2011-12-12-cross-domain-backbone-apps.html

+53-74
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<!-- syntax highlighting CSS -->
1212
<link rel="stylesheet" href="/css/syntax.css" type="text/css" />
1313

14-
14+
<link rel="stylesheet" href="http://cdn.moot.it/1.1/moot.css"/>
1515
<!-- Homepage CSS -->
1616
<link rel="stylesheet" href="/css/bootstrap.css" type="text/css" media="screen, projection" />
1717
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen, projection" />
@@ -33,43 +33,48 @@
3333
})();
3434
/* ]]> */
3535
</script>
36+
<!-- (1) Moot depends on jQuery v1.7 or greater -->
37+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
38+
3639
</head>
3740
<body>
38-
39-
40-
41-
4241
<div class="container">
43-
<hr />
44-
45-
<div class="">
4642

47-
<div class="row">
48-
<div class="span12" style="position: relative;"> <h1>
49-
<a class="" href="/">Backbone Tutorials</a>
50-
</h1>
51-
<h3>By <a href="http://thomasdavis.github.com">Thomas Davis</a></h3>
52-
<span style="position: absolute; right: 0; top: 0;"><a href="http://twitter.com/neutralthoughts" class="twitter-follow-button">Follow @neutralthoughts</a>
53-
<br />
54-
<iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=thomasdavis&repo=backbonetutorials&type=watch&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="170px" height="30px"></iframe>
43+
<div class="row">
44+
<div class="col-lg-12">
45+
<div class="navbar" style="margin-top:10px;">
46+
<div class="container">
47+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
48+
<span class="icon-bar"></span>
49+
<span class="icon-bar"></span>
50+
<span class="icon-bar"></span>
51+
</button>
52+
<a class="navbar-brand" href="#">Backbone Tutorials</a>
53+
<div class="nav-collapse collapse navbar-responsive-collapse">
54+
<ul class="nav navbar-nav">
55+
<li class="active"><a href="#">Home</a></li>
56+
<li><a href="#">Link</a></li>
57+
58+
</ul>
59+
<ul class="nav navbar-nav pull-right">
60+
<li><a href="#">Subscribe</a></li>
61+
<li><a href="#">Download eBook (.pdf, .MOBI, .ePub)</a></li>
62+
</ul>
63+
</div><!-- /.nav-collapse -->
64+
</div><!-- /.container -->
65+
</div>
5566

56-
<iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=thomasdavis&repo=backbonetutorials&type=fork&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="146px" height="30px"></iframe>
5767

58-
</span><a class="btn btn-warning btn-mini" href="http://feeds.feedburner.com/BackboneTutorials">subscribe</a>
59-
<a class="btn btn-success btn-mini" href="http://leanpub.com/backbonetutorials">download free - (.pdf, .MOBI, .ePUB)</a>
60-
<script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>
61-
</div>
62-
68+
</div>
6369
</div>
6470
</div>
65-
<hr />
66-
67-
<div class="row">
68-
<div class="span12">
69-
70-
7171

72-
<div id="post">
72+
73+
<div style=""></div>
74+
<div class="container">
75+
76+
<div class="container">
77+
<div id="post">
7378
<h2>Cross Browser problems when consuming your own <span class="caps">API</span></h2>
7479
<p>This tutorial aims to help those who have separated their front-end completely from their back-end by building a restful interface as the mediator between the two.</p>
7580
<p>Consuming your own public api has great benefits and sites such as foursquare have <a href="http://engineering.foursquare.com/2011/12/08/web-sites-are-clients-too/">recently</a> converted.</p>
@@ -143,9 +148,7 @@ <h3>Example File Structure</h3>
143148
<span class="cm">└── index.html</span>
144149

145150
<span class="cm">*/</span>
146-
</code></pre>
147-
</div>
148-
<p>To continue you must really understand what we are aiming towards as described in the introduction.</p>
151+
</code></pre></div><p>To continue you must really understand what we are aiming towards as described in the introduction.</p>
149152
<h3>Bootstrapping your application</h3>
150153
<p>Using Require.js we define a single entry point on our index page.<br />
151154
We should setup any useful containers that might be used by our Backbone views.</p>
@@ -166,9 +169,7 @@ <h3>Bootstrapping your application</h3>
166169

167170
<span class="nt">&lt;/body&gt;</span>
168171
<span class="nt">&lt;/html&gt;</span>
169-
</code></pre>
170-
</div>
171-
<p>You should most always end up with quite a light weight index file. You can serve this off your server and then the rest of your site off a <span class="caps">CDN</span> ensuring that everything that can be cached, will be.</p>
172+
</code></pre></div><p>You should most always end up with quite a light weight index file. You can serve this off your server and then the rest of your site off a <span class="caps">CDN</span> ensuring that everything that can be cached, will be.</p>
172173
<h4>What does the bootstrap look like?</h4>
173174
<p>Our bootstrap file will be responsible for configuring Require.js and loading initially important dependencies.</p>
174175
<p>In the below example we configure Require.js to create shortcut alias to commonly used scripts such as jQuery, Underscore and Backbone.</p>
@@ -204,9 +205,7 @@ <h4>What does the bootstrap look like?</h4>
204205
<span class="c1">// Again, the other dependencies passed in are not &quot;AMD&quot; therefore don&#39;t pass a parameter to this function</span>
205206
<span class="nx">App</span><span class="p">.</span><span class="nx">initialize</span><span class="p">();</span>
206207
<span class="p">});</span>
207-
</code></pre>
208-
</div>
209-
<h3>How should we lay out external scripts?</h3>
208+
</code></pre></div><h3>How should we lay out external scripts?</h3>
210209
<p>Any modules we develop for our application using <span class="caps">AMD</span>/Require.js will be asynchronously loaded.</p>
211210
<p>We have a heavy dependency on jQuery, Underscore and Backbone, unfortunatly this libraries are loaded synchronously and also depend on each other existing in the global namespace.</p>
212211
<p>Below I propose a solution(until these libraries allow themselves to be loaded asynchronously) to allow these libraries to be loaded properly(synchronously) and also removing themselves from global scope.</p>
@@ -219,17 +218,13 @@ <h3>How should we lay out external scripts?</h3>
219218
<span class="c1">// Tell Require.js that this module returns a reference to jQuery</span>
220219
<span class="k">return</span> <span class="nx">$</span><span class="p">;</span>
221220
<span class="p">});</span>
222-
</code></pre>
223-
</div>
224-
<div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: libs/underscore/underscore</span>
221+
</code></pre></div><div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: libs/underscore/underscore</span>
225222
<span class="c1">// As above lets load the original underscore source code</span>
226223
<span class="nx">define</span><span class="p">([</span><span class="s1">&#39;order!libs/underscore/underscore-min&#39;</span><span class="p">],</span> <span class="kd">function</span><span class="p">(){</span>
227224
<span class="c1">// Tell Require.js that this module returns a reference to Underscore</span>
228225
<span class="k">return</span> <span class="nx">_</span><span class="p">;</span>
229226
<span class="p">});</span>
230-
</code></pre>
231-
</div>
232-
<div class="highlight"><pre><code class="javascript"> <span class="c1">// Filename: libs/backbone/backbone</span>
227+
</code></pre></div><div class="highlight"><pre><code class="javascript"> <span class="c1">// Filename: libs/backbone/backbone</span>
233228
<span class="c1">// Finally lets load the original backbone source code</span>
234229
<span class="nx">define</span><span class="p">([</span><span class="s1">&#39;order!libs/backbone/backbone-min&#39;</span><span class="p">],</span> <span class="kd">function</span><span class="p">(){</span>
235230
<span class="c1">// Now that all the orignal source codes have ran and accessed each other</span>
@@ -239,9 +234,7 @@ <h3>How should we lay out external scripts?</h3>
239234
<span class="nx">$</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">();</span>
240235
<span class="k">return</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">();</span>
241236
<span class="p">});</span>
242-
</code></pre>
243-
</div>
244-
<h3>A boiler plate module</h3>
237+
</code></pre></div><h3>A boiler plate module</h3>
245238
<p>So before we start developing our application, let&#8217;s quickly look over boiler plate code that will be reused quite often.</p>
246239
<p>For convience sake I generally keep a &#8220;boilerplate.js&#8221; in my application root so I can copy it when I need to.</p>
247240
<div class="highlight"><pre><code class="javascript"><span class="c1">//Filename: boilerplate.js</span>
@@ -257,9 +250,7 @@ <h3>A boiler plate module</h3>
257250
<span class="k">return</span> <span class="p">{};</span>
258251
<span class="c1">// What we return here will be used by other modules</span>
259252
<span class="p">});</span>
260-
</code></pre>
261-
</div>
262-
<p>The first argument of the define function is our dependency array, we can pass in any modules we like in the future.</p>
253+
</code></pre></div><p>The first argument of the define function is our dependency array, we can pass in any modules we like in the future.</p>
263254
<h3>App.js Building our applications main module</h3>
264255
<p>Our applications main module should always remain quite light weight. This tutorial covers only setting up a Backbone Router and initializing it in our main module.</p>
265256
<p>The router will then load the correct dependencies depending on the current <span class="caps">URL</span>.</p>
@@ -279,9 +270,7 @@ <h3>App.js Building our applications main module</h3>
279270
<span class="nx">initialize</span><span class="o">:</span> <span class="nx">initialize</span>
280271
<span class="p">};</span>
281272
<span class="p">});</span>
282-
</code></pre>
283-
</div>
284-
<div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: router.js</span>
273+
</code></pre></div><div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: router.js</span>
285274
<span class="nx">define</span><span class="p">([</span>
286275
<span class="s1">&#39;jQuery&#39;</span><span class="p">,</span>
287276
<span class="s1">&#39;Underscore&#39;</span><span class="p">,</span>
@@ -322,9 +311,7 @@ <h3>App.js Building our applications main module</h3>
322311
<span class="nx">initialize</span><span class="o">:</span> <span class="nx">initialize</span>
323312
<span class="p">};</span>
324313
<span class="p">});</span>
325-
</code></pre>
326-
</div>
327-
<h3>Modularizing a Backbone View</h3>
314+
</code></pre></div><h3>Modularizing a Backbone View</h3>
328315
<p>Backbone views most usually always interact with the <span class="caps">DOM</span>, using our new modular system we can load in Javascript templates using Require.js text! plugin.</p>
329316
<div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: views/project/list</span>
330317
<span class="nx">define</span><span class="p">([</span>
@@ -349,9 +336,7 @@ <h3>Modularizing a Backbone View</h3>
349336
<span class="c1">// Sometimes you might return an un-instantiated view e.g. return projectListView</span>
350337
<span class="k">return</span> <span class="k">new</span> <span class="nx">projectListView</span><span class="p">;</span>
351338
<span class="p">});</span>
352-
</code></pre>
353-
</div>
354-
<p>Javascript templating allows us to seperate the design from the application logic placing all our html in the templates folder.</p>
339+
</code></pre></div><p>Javascript templating allows us to seperate the design from the application logic placing all our html in the templates folder.</p>
355340
<h3>Modularizing a Collection, Model and View</h3>
356341
<p>Now we put it altogether by chaining up a Model, Collection and View which is a typical scenairo when building a Backbone.js application.</p>
357342
<p>First off we will define our model</p>
@@ -368,9 +353,7 @@ <h3>Modularizing a Collection, Model and View</h3>
368353
<span class="c1">// You usually don&#39;t return a model instantiated</span>
369354
<span class="k">return</span> <span class="nx">projectModel</span><span class="p">;</span>
370355
<span class="p">});</span>
371-
</code></pre>
372-
</div>
373-
<p>Now we have a model, our collection module can depend on it. We will set the &#8220;model&#8221; attribute of our collection to the loaded module. Backbone.js offers great benefits when doing this.</p>
356+
</code></pre></div><p>Now we have a model, our collection module can depend on it. We will set the &#8220;model&#8221; attribute of our collection to the loaded module. Backbone.js offers great benefits when doing this.</p>
374357
<p>&#8220;Collection.model: Override this property to specify the model class that the collection contains. If defined, you can pass raw attributes objects (and arrays) to add, create, and reset, and the attributes will be converted into a model of the proper type.&#8221;</p>
375358
<div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: collections/projects</span>
376359
<span class="nx">define</span><span class="p">([</span>
@@ -385,9 +368,7 @@ <h3>Modularizing a Collection, Model and View</h3>
385368
<span class="c1">// You don&#39;t usually return a collection instantiated</span>
386369
<span class="k">return</span> <span class="k">new</span> <span class="nx">projectCollection</span><span class="p">;</span>
387370
<span class="p">});</span>
388-
</code></pre>
389-
</div>
390-
<p>Now we can simply depend on our collection in our view and pass it to our Javascript template.</p>
371+
</code></pre></div><p>Now we can simply depend on our collection in our view and pass it to our Javascript template.</p>
391372
<div class="highlight"><pre><code class="javascript"><span class="c1">// Filename: views/projects/list</span>
392373
<span class="nx">define</span><span class="p">([</span>
393374
<span class="s1">&#39;jQuery&#39;</span><span class="p">,</span>
@@ -410,9 +391,7 @@ <h3>Modularizing a Collection, Model and View</h3>
410391
<span class="c1">// Returning instantiated views can be quite useful for having &quot;state&quot;</span>
411392
<span class="k">return</span> <span class="k">new</span> <span class="nx">projectListView</span><span class="p">;</span>
412393
<span class="p">});</span>
413-
</code></pre>
414-
</div>
415-
<h3>Conclusion</h3>
394+
</code></pre></div><h3>Conclusion</h3>
416395
<p>Looking forward to feedback so I can turn this post and example into quality references on building modular Javascript applications.</p>
417396
<p>Get in touch with me on twitter, comments or github!</p>
418397
<h3>Relevant Links</h3>
@@ -427,7 +406,11 @@ <h3>Contributors</h3>
427406
</ul>
428407
</div>
429408

430-
<p>Leave a comment or question and I will try my very hardest to get back to you!</p>
409+
<div style="border: 1px solid #ccc; box-shadow: 0 0 10px #ccc; margin-top: 15px; margin-bottom: 20px;padding: 15px;">
410+
<h3 style="margin-bottom:15 px;">Backbone.js Beginner Video Tutorial</h3><img src="/backbone.png" style="float: left;" /><p>I have put extra effort into making a very easy to understand Backbone.js video which is also free. It is 70mins long and covers everything you need to know when getting started.</p>
411+
<a href="http://gum.co/backbone-beginner-screencast" class="btn btn-primary">Watch Video</a>
412+
<div style="clear: both;"></div>
413+
</div>
431414

432415

433416
<a class="FlattrButton" style="display:none;" href="http://backbonetutorials.com/"></a>
@@ -456,11 +439,7 @@ <h3>Contributors</h3>
456439
})();
457440
</script>
458441

459-
</div>
460-
</div>
461-
462-
463-
442+
</div>
464443
</div>
465444
<script src="//static.getclicky.com/js" type="text/javascript"></script>
466445
<script type="text/javascript">try{ clicky.init(66406579); }catch(e){}</script>

0 commit comments

Comments
 (0)