mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
redoc
This commit is contained in:
3159
docs/backbone.html
3159
docs/backbone.html
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>backbone.localstorage.js</title>
|
||||
<title>backbone.localStorage.js</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
@@ -16,18 +16,20 @@
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
<div id="jump_page_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
<a class="source" href="backbone.localstorage.html">
|
||||
backbone.localstorage.js
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="backbone.localStorage.html">
|
||||
backbone.localStorage.js
|
||||
</a>
|
||||
|
||||
<a class="source" href="todos.html">
|
||||
todos.js
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="todos.html">
|
||||
todos.js
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -36,7 +38,7 @@
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>backbone.localstorage.js</h1>
|
||||
<h1>backbone.localStorage.js</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
@@ -57,7 +59,7 @@
|
||||
*
|
||||
* https://github.com/jeromegn/Backbone.localStorage
|
||||
*/</span>
|
||||
(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(root, factory)</span> {</span>
|
||||
(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(root, factory)</span> </span>{
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> define === <span class="hljs-string">"function"</span> && define.amd) {</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -73,7 +75,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> define([<span class="hljs-string">"underscore"</span>,<span class="hljs-string">"backbone"</span>], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(_, Backbone)</span> {</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> define([<span class="hljs-string">"underscore"</span>,<span class="hljs-string">"backbone"</span>], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(_, Backbone)</span> </span>{</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -107,7 +109,7 @@
|
||||
|
||||
<div class="content"><div class='highlight'><pre> factory(_, Backbone);
|
||||
}
|
||||
}(<span class="hljs-keyword">this</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(_, Backbone)</span> {</span></pre></div></div>
|
||||
}(<span class="hljs-keyword">this</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(_, Backbone)</span> </span>{</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -151,7 +153,7 @@ to make things work even if they are removed from the global namespace</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">S4</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">S4</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> (((<span class="hljs-number">1</span>+<span class="hljs-built_in">Math</span>.random())*<span class="hljs-number">0x10000</span>)|<span class="hljs-number">0</span>).toString(<span class="hljs-number">16</span>).substring(<span class="hljs-number">1</span>);
|
||||
};</pre></div></div>
|
||||
|
||||
@@ -168,7 +170,7 @@ to make things work even if they are removed from the global namespace</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">guid</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">guid</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> (S4()+S4()+<span class="hljs-string">"-"</span>+S4()+<span class="hljs-string">"-"</span>+S4()+<span class="hljs-string">"-"</span>+S4()+<span class="hljs-string">"-"</span>+S4()+S4()+S4());
|
||||
};</pre></div></div>
|
||||
|
||||
@@ -187,7 +189,7 @@ window.Store is deprectated, use Backbone.LocalStorage instead</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Backbone.LocalStorage = window.Store = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(name)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre>Backbone.LocalStorage = <span class="hljs-built_in">window</span>.Store = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(name)</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.name = name;
|
||||
<span class="hljs-keyword">var</span> store = <span class="hljs-keyword">this</span>.localStorage().getItem(<span class="hljs-keyword">this</span>.name);
|
||||
<span class="hljs-keyword">this</span>.records = (store && store.split(<span class="hljs-string">","</span>)) || [];
|
||||
@@ -208,7 +210,7 @@ _.extend(Backbone.LocalStorage.prototype, {</pre></div></div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> save: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> save: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.localStorage().setItem(<span class="hljs-keyword">this</span>.name, <span class="hljs-keyword">this</span>.records.join(<span class="hljs-string">","</span>));
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -226,7 +228,7 @@ have an id of it’s own.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> create: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> create: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> </span>{
|
||||
<span class="hljs-keyword">if</span> (!model.id) {
|
||||
model.id = guid();
|
||||
model.set(model.idAttribute, model.id);
|
||||
@@ -250,7 +252,7 @@ have an id of it’s own.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> update: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> update: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.localStorage().setItem(<span class="hljs-keyword">this</span>.name+<span class="hljs-string">"-"</span>+model.id, <span class="hljs-built_in">JSON</span>.stringify(model));
|
||||
<span class="hljs-keyword">if</span> (!_.include(<span class="hljs-keyword">this</span>.records, model.id.toString()))
|
||||
<span class="hljs-keyword">this</span>.records.push(model.id.toString()); <span class="hljs-keyword">this</span>.save();
|
||||
@@ -270,7 +272,7 @@ have an id of it’s own.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> find: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> find: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> </span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.jsonData(<span class="hljs-keyword">this</span>.localStorage().getItem(<span class="hljs-keyword">this</span>.name+<span class="hljs-string">"-"</span>+model.id));
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -287,9 +289,9 @@ have an id of it’s own.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> findAll: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> findAll: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> _(<span class="hljs-keyword">this</span>.records).chain()
|
||||
.map(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(id)</span>{</span>
|
||||
.map(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(id)</span></span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.jsonData(<span class="hljs-keyword">this</span>.localStorage().getItem(<span class="hljs-keyword">this</span>.name+<span class="hljs-string">"-"</span>+id));
|
||||
}, <span class="hljs-keyword">this</span>)
|
||||
.compact()
|
||||
@@ -309,18 +311,18 @@ have an id of it’s own.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> destroy: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> destroy: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> </span>{
|
||||
<span class="hljs-keyword">if</span> (model.isNew())
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
|
||||
<span class="hljs-keyword">this</span>.localStorage().removeItem(<span class="hljs-keyword">this</span>.name+<span class="hljs-string">"-"</span>+model.id);
|
||||
<span class="hljs-keyword">this</span>.records = _.reject(<span class="hljs-keyword">this</span>.records, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(id)</span>{</span>
|
||||
<span class="hljs-keyword">this</span>.records = _.reject(<span class="hljs-keyword">this</span>.records, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(id)</span></span>{
|
||||
<span class="hljs-keyword">return</span> id === model.id.toString();
|
||||
});
|
||||
<span class="hljs-keyword">this</span>.save();
|
||||
<span class="hljs-keyword">return</span> model;
|
||||
},
|
||||
|
||||
localStorage: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
localStorage: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> localStorage;
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -337,7 +339,7 @@ have an id of it’s own.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> jsonData: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(data)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> jsonData: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(data)</span> </span>{
|
||||
<span class="hljs-keyword">return</span> data && <span class="hljs-built_in">JSON</span>.parse(data);
|
||||
}
|
||||
|
||||
@@ -358,7 +360,7 @@ window.Store.sync and Backbone.localSync is deprectated, use Backbone.LocalStora
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(method, model, options)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre>Backbone.LocalStorage.sync = <span class="hljs-built_in">window</span>.Store.sync = Backbone.localSync = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(method, model, options)</span> </span>{
|
||||
<span class="hljs-keyword">var</span> store = model.localStorage || model.collection.localStorage;
|
||||
|
||||
<span class="hljs-keyword">var</span> resp, errorMessage, syncDfd = $.Deferred && $.Deferred(); <span class="hljs-comment">//If $ is having Deferred - use it.</span>
|
||||
@@ -381,7 +383,7 @@ window.Store.sync and Backbone.localSync is deprectated, use Backbone.LocalStora
|
||||
}
|
||||
|
||||
} <span class="hljs-keyword">catch</span>(error) {
|
||||
<span class="hljs-keyword">if</span> (error.code === DOMException.QUOTA_EXCEEDED_ERR && window.localStorage.length === <span class="hljs-number">0</span>)
|
||||
<span class="hljs-keyword">if</span> (error.code === DOMException.QUOTA_EXCEEDED_ERR && <span class="hljs-built_in">window</span>.localStorage.length === <span class="hljs-number">0</span>)
|
||||
errorMessage = <span class="hljs-string">"Private browsing is unsupported"</span>;
|
||||
<span class="hljs-keyword">else</span>
|
||||
errorMessage = error.message;
|
||||
@@ -425,7 +427,7 @@ always execute callback for success and error</p>
|
||||
|
||||
Backbone.ajaxSync = Backbone.sync;
|
||||
|
||||
Backbone.getSyncMethod = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> {</span>
|
||||
Backbone.getSyncMethod = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(model)</span> </span>{
|
||||
<span class="hljs-keyword">if</span>(model.localStorage || (model.collection && model.collection.localStorage)) {
|
||||
<span class="hljs-keyword">return</span> Backbone.localSync;
|
||||
}
|
||||
@@ -447,7 +449,7 @@ the original ‘Backbone.sync’ is still available in ‘Backbone.ajaxSync’</
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Backbone.sync = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(method, model, options)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre>Backbone.sync = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(method, model, options)</span> </span>{
|
||||
<span class="hljs-keyword">return</span> Backbone.getSyncMethod(model).apply(<span class="hljs-keyword">this</span>, [method, model, options]);
|
||||
};
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'novecento-bold';
|
||||
src: url('public/fonts/novecento-bold.eot');
|
||||
src: url('public/fonts/novecento-bold.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/novecento-bold.woff') format('woff'),
|
||||
url('public/fonts/novecento-bold.ttf') format('truetype');
|
||||
font-family: 'roboto-black';
|
||||
src: url('public/fonts/roboto-black.eot');
|
||||
src: url('public/fonts/roboto-black.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/roboto-black.woff') format('woff'),
|
||||
url('public/fonts/roboto-black.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ h1, h2, h3, h4, h5, h6 {
|
||||
color: #112233;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
font-family: "novecento-bold";
|
||||
font-family: "roboto-black";
|
||||
text-transform: uppercase;
|
||||
margin: 30px 0 15px 0;
|
||||
}
|
||||
@@ -75,6 +75,9 @@ h1, h2, h3, h4, h5, h6 {
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.26em;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
@@ -180,9 +183,18 @@ ul.sections > li > div {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#jump_page_wrapper{
|
||||
position: fixed;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
#jump_page {
|
||||
padding: 5px 0 3px;
|
||||
margin: 0 0 25px 25px;
|
||||
max-height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#jump_page .source {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
docs/public/fonts/roboto-black.eot
Executable file
BIN
docs/public/fonts/roboto-black.eot
Executable file
Binary file not shown.
BIN
docs/public/fonts/roboto-black.ttf
Executable file
BIN
docs/public/fonts/roboto-black.ttf
Executable file
Binary file not shown.
BIN
docs/public/fonts/roboto-black.woff
Executable file
BIN
docs/public/fonts/roboto-black.woff
Executable file
Binary file not shown.
@@ -16,18 +16,20 @@
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
<div id="jump_page_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
<a class="source" href="backbone.localstorage.html">
|
||||
backbone.localstorage.js
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="backbone.localStorage.html">
|
||||
backbone.localStorage.js
|
||||
</a>
|
||||
|
||||
<a class="source" href="todos.html">
|
||||
todos.js
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="todos.html">
|
||||
todos.js
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -68,7 +70,7 @@ to persist Backbone models within your browser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>$(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>$(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span></span>{</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -123,7 +125,7 @@ to persist Backbone models within your browser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> defaults: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> defaults: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
title: <span class="hljs-string">"empty todo..."</span>,
|
||||
order: Todos.nextOrder(),
|
||||
@@ -144,7 +146,7 @@ to persist Backbone models within your browser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> toggle: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> toggle: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.save({done: !<span class="hljs-keyword">this</span>.get(<span class="hljs-string">"done"</span>)});
|
||||
}
|
||||
|
||||
@@ -234,7 +236,7 @@ server.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> done: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> done: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.where({done: <span class="hljs-literal">true</span>});
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -251,7 +253,7 @@ server.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> remaining: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> remaining: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.where({done: <span class="hljs-literal">false</span>});
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -269,7 +271,7 @@ GUID in the database. This generates the next order number for new items.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> nextOrder: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> nextOrder: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.length) <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.last().get(<span class="hljs-string">'order'</span>) + <span class="hljs-number">1</span>;
|
||||
},</pre></div></div>
|
||||
@@ -412,7 +414,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> initialize: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> initialize: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.listenTo(<span class="hljs-keyword">this</span>.model, <span class="hljs-string">'change'</span>, <span class="hljs-keyword">this</span>.render);
|
||||
<span class="hljs-keyword">this</span>.listenTo(<span class="hljs-keyword">this</span>.model, <span class="hljs-string">'destroy'</span>, <span class="hljs-keyword">this</span>.remove);
|
||||
},</pre></div></div>
|
||||
@@ -430,7 +432,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.$el.html(<span class="hljs-keyword">this</span>.template(<span class="hljs-keyword">this</span>.model.toJSON()));
|
||||
<span class="hljs-keyword">this</span>.$el.toggleClass(<span class="hljs-string">'done'</span>, <span class="hljs-keyword">this</span>.model.get(<span class="hljs-string">'done'</span>));
|
||||
<span class="hljs-keyword">this</span>.input = <span class="hljs-keyword">this</span>.$(<span class="hljs-string">'.edit'</span>);
|
||||
@@ -450,7 +452,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> toggleDone: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> toggleDone: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.model.toggle();
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -467,7 +469,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> edit: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> edit: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.$el.addClass(<span class="hljs-string">"editing"</span>);
|
||||
<span class="hljs-keyword">this</span>.input.focus();
|
||||
},</pre></div></div>
|
||||
@@ -485,7 +487,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> close: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> close: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">var</span> value = <span class="hljs-keyword">this</span>.input.val();
|
||||
<span class="hljs-keyword">if</span> (!value) {
|
||||
<span class="hljs-keyword">this</span>.clear();
|
||||
@@ -508,7 +510,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> updateOnEnter: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(e)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> updateOnEnter: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(e)</span> </span>{
|
||||
<span class="hljs-keyword">if</span> (e.keyCode == <span class="hljs-number">13</span>) <span class="hljs-keyword">this</span>.close();
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -525,7 +527,7 @@ app, we set a direct reference on the model for convenience.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> clear: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> clear: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">this</span>.model.destroy();
|
||||
}
|
||||
|
||||
@@ -636,7 +638,7 @@ loading any preexisting todos that might be saved in <em>localStorage</em>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> initialize: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> initialize: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
|
||||
<span class="hljs-keyword">this</span>.input = <span class="hljs-keyword">this</span>.$(<span class="hljs-string">"#new-todo"</span>);
|
||||
<span class="hljs-keyword">this</span>.allCheckbox = <span class="hljs-keyword">this</span>.$(<span class="hljs-string">"#toggle-all"</span>)[<span class="hljs-number">0</span>];
|
||||
@@ -665,7 +667,7 @@ of the app doesn’t change.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">var</span> done = Todos.done().length;
|
||||
<span class="hljs-keyword">var</span> remaining = Todos.remaining().length;
|
||||
|
||||
@@ -695,7 +697,7 @@ appending its element to the <code><ul></code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> addOne: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(todo)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> addOne: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(todo)</span> </span>{
|
||||
<span class="hljs-keyword">var</span> view = <span class="hljs-keyword">new</span> TodoView({model: todo});
|
||||
<span class="hljs-keyword">this</span>.$(<span class="hljs-string">"#todo-list"</span>).append(view.render().el);
|
||||
},</pre></div></div>
|
||||
@@ -713,7 +715,7 @@ appending its element to the <code><ul></code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> addAll: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> addAll: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
Todos.each(<span class="hljs-keyword">this</span>.addOne, <span class="hljs-keyword">this</span>);
|
||||
},</pre></div></div>
|
||||
|
||||
@@ -731,7 +733,7 @@ persisting it to <em>localStorage</em>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> createOnEnter: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(e)</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> createOnEnter: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(e)</span> </span>{
|
||||
<span class="hljs-keyword">if</span> (e.keyCode != <span class="hljs-number">13</span>) <span class="hljs-keyword">return</span>;
|
||||
<span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.input.val()) <span class="hljs-keyword">return</span>;
|
||||
|
||||
@@ -752,14 +754,14 @@ persisting it to <em>localStorage</em>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> clearCompleted: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span>
|
||||
<div class="content"><div class='highlight'><pre> clearCompleted: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
_.invoke(Todos.done(), <span class="hljs-string">'destroy'</span>);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
|
||||
},
|
||||
|
||||
toggleAllComplete: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">()</span> {</span>
|
||||
toggleAllComplete: <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">()</span> </span>{
|
||||
<span class="hljs-keyword">var</span> done = <span class="hljs-keyword">this</span>.allCheckbox.checked;
|
||||
Todos.each(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(todo)</span> {</span> todo.save({<span class="hljs-string">'done'</span>: done}); });
|
||||
Todos.each(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(todo)</span> </span>{ todo.save({<span class="hljs-string">'done'</span>: done}); });
|
||||
}
|
||||
|
||||
});</pre></div></div>
|
||||
|
||||
Reference in New Issue
Block a user