mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge branch 'master' into private-listening-public-on
This commit is contained in:
90
.eslintrc
Normal file
90
.eslintrc
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"amd": true
|
||||
},
|
||||
"globals": {
|
||||
"attachEvent": false,
|
||||
"detachEvent": false
|
||||
},
|
||||
"rules": {
|
||||
"array-bracket-spacing": 2,
|
||||
"block-scoped-var": 2,
|
||||
"brace-style": [1, "1tbs", {"allowSingleLine": true}],
|
||||
"camelcase": 2,
|
||||
"comma-dangle": [2, "never"],
|
||||
"comma-spacing": 2,
|
||||
"computed-property-spacing": [2, "never"],
|
||||
"dot-notation": [2, { "allowKeywords": false }],
|
||||
"eol-last": 2,
|
||||
"eqeqeq": [2, "smart"],
|
||||
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}],
|
||||
"key-spacing": 1,
|
||||
"keyword-spacing": [2, { "after": true }],
|
||||
"linebreak-style": 2,
|
||||
"max-depth": [1, 4],
|
||||
"max-params": [1, 5],
|
||||
"new-cap": [2, {"newIsCapExceptions": ["model"]}],
|
||||
"no-alert": 2,
|
||||
"no-caller": 2,
|
||||
"no-catch-shadow": 2,
|
||||
"no-console": 2,
|
||||
"no-debugger": 2,
|
||||
"no-delete-var": 2,
|
||||
"no-div-regex": 1,
|
||||
"no-dupe-args": 2,
|
||||
"no-dupe-keys": 2,
|
||||
"no-duplicate-case": 2,
|
||||
"no-else-return": 1,
|
||||
"no-empty-character-class": 2,
|
||||
"no-eval": 2,
|
||||
"no-ex-assign": 2,
|
||||
"no-extend-native": 2,
|
||||
"no-extra-boolean-cast": 2,
|
||||
"no-extra-parens": 1,
|
||||
"no-extra-semi": 2,
|
||||
"no-fallthrough": 2,
|
||||
"no-floating-decimal": 2,
|
||||
"no-func-assign": 2,
|
||||
"no-implied-eval": 2,
|
||||
"no-inner-declarations": 2,
|
||||
"no-irregular-whitespace": 2,
|
||||
"no-label-var": 2,
|
||||
"no-labels": 2,
|
||||
"no-lone-blocks": 2,
|
||||
"no-lonely-if": 2,
|
||||
"no-multi-str": 2,
|
||||
"no-native-reassign": 2,
|
||||
"no-negated-in-lhs": 1,
|
||||
"no-new-object": 2,
|
||||
"no-new-wrappers": 2,
|
||||
"no-obj-calls": 2,
|
||||
"no-octal": 2,
|
||||
"no-octal-escape": 2,
|
||||
"no-proto": 2,
|
||||
"no-redeclare": 2,
|
||||
"no-shadow": 2,
|
||||
"no-spaced-func": 2,
|
||||
"no-throw-literal": 2,
|
||||
"no-trailing-spaces": 2,
|
||||
"no-undef": 2,
|
||||
"no-undef-init": 2,
|
||||
"no-undefined": 2,
|
||||
"no-unneeded-ternary": 2,
|
||||
"no-unreachable": 2,
|
||||
"no-unused-expressions": [2, {"allowTernary": true, "allowShortCircuit": true}],
|
||||
"no-with": 2,
|
||||
"object-curly-spacing": [2, "never"],
|
||||
"quote-props": [1, "consistent-as-needed"],
|
||||
"quotes": [2, "single", "avoid-escape"],
|
||||
"radix": 2,
|
||||
"semi": 2,
|
||||
"space-before-function-paren": [2, {"anonymous": "never", "named": "never"}],
|
||||
"space-infix-ops": 2,
|
||||
"space-unary-ops": [2, { "words": true, "nonwords": false }],
|
||||
"use-isnan": 2,
|
||||
"valid-typeof": 2,
|
||||
"wrap-iife": [2, "inside"]
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,12 @@ before_script:
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
script:
|
||||
- npm test
|
||||
# Karma sauce is limited to running about 5-7 browsers (or it will timeout) at a time so we just run vendor by vendor here
|
||||
- karma start karma.conf-sauce.js --browsers FIREFOX_V4,FIREFOX_V11,FIREFOX_V21,FIREFOX_V30,FIREFOX_V35,CHROME_V26,CHROME_V31,CHROME_V39,CHROME_V40,ANDROID_V4.0,ANDROID_V4.3
|
||||
- karma start karma.conf-sauce.js --browsers IE_V7,IE_V8,IE_V9,IE_V10,IE_V11
|
||||
- karma start karma.conf-sauce.js --browsers SAFARI_V5,SAFARI_V6,SAFARI_V7,SAFARI_V8.0,OPERA_V11,OPERA_V12
|
||||
- karma start karma.conf-sauce.js
|
||||
notifications:
|
||||
email: false
|
||||
sudo: false
|
||||
env:
|
||||
global:
|
||||
- NPM_CONFIG_PROGRESS="false"
|
||||
- secure: G9oDQUXytNHni0wasGDXO3lQE/xuP9gd6VZ20kuh5FzVlqfY5L7JfYWki435nZ1z2yPD1QVAZi+1BCmCwnkTLVO9gB7cmDJDt1VzeHdCSOqCXGDAbOcq67/OO4FUa77sCQSDnqOOGVbiUPldaDl8G6uylk72Ll8b0pPwUWdRCM8=
|
||||
- secure: dniSzTSxXzaSGYjW3+LiNesx/BtTWo6RHuMKm19MwNo/YJYJJ/1YSEH/9vCmlVzc00CqvJ5Khwu9XPzcDV4gkuNQFN1+QcgGI2heVUqac/jqlGF39VEH8Xc+H40MsRLkwgSIkadIPWj4wBbbzqyC9M+J/KjUPOhBXGtp+FARu0I=
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2010-2015 Jeremy Ashkenas, DocumentCloud
|
||||
Copyright (c) 2010-2017 Jeremy Ashkenas, DocumentCloud
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
@@ -16,9 +16,14 @@ Backbone supplies structure to JavaScript-heavy applications by providing models
|
||||
For Docs, License, Tests, pre-packed downloads, and everything else, really, see:
|
||||
http://backbonejs.org
|
||||
|
||||
To suggest a feature, report a bug, or general discussion:
|
||||
To suggest a feature or report a bug:
|
||||
https://github.com/jashkenas/backbone/issues
|
||||
|
||||
For questions on working with Backbone or general discussions:
|
||||
https://groups.google.com/forum/#!forum/backbonejs,
|
||||
http://stackoverflow.com/questions/tagged/backbone.js, or
|
||||
https://gitter.im/jashkenas/backbone
|
||||
|
||||
Backbone is an open-sourced component of DocumentCloud:
|
||||
https://github.com/documentcloud
|
||||
|
||||
|
||||
2
backbone-min.js
vendored
2
backbone-min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
735
backbone.js
735
backbone.js
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,8 @@
|
||||
{
|
||||
"name" : "backbone",
|
||||
"version" : "1.2.0",
|
||||
"main" : "backbone.js",
|
||||
"dependencies" : {
|
||||
"underscore" : ">=1.7.0"
|
||||
"underscore" : ">=1.8.3"
|
||||
},
|
||||
"ignore" : ["docs", "examples", "test", "*.yml", "*.html", "*.ico", "*.md", "CNAME", ".*", "karma.*", "component.json", "package.json"]
|
||||
"ignore" : ["docs", "examples", "test", "*.yml", "*.html", "*.ico", "*.md", "CNAME", ".*", "karma.*", "package.json"]
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"name" : "backbone",
|
||||
"version" : "1.2.0",
|
||||
"description" : "Give your JS App some Backbone with Models, Views, Collections, and Events.",
|
||||
"keywords" : ["model", "view", "controller", "router", "server", "client", "browser"],
|
||||
"repo" : "jashkenas/backbone",
|
||||
"dependencies" : {
|
||||
"jashkenas/underscore" : "*"
|
||||
},
|
||||
"main" : "backbone.js",
|
||||
"scripts" : ["backbone.js"],
|
||||
"license" : "MIT"
|
||||
}
|
||||
2833
docs/backbone.html
2833
docs/backbone.html
File diff suppressed because it is too large
Load Diff
@@ -59,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>
|
||||
@@ -75,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>
|
||||
|
||||
@@ -109,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>
|
||||
|
||||
@@ -153,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>
|
||||
|
||||
@@ -170,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>
|
||||
|
||||
@@ -185,11 +185,11 @@ to make things work even if they are removed from the global namespace</p>
|
||||
</div>
|
||||
<p>Our Store is represented by a single JS object in <em>localStorage</em>. Create it
|
||||
with a meaningful name, like the name you’d give a table.
|
||||
window.Store is deprectated, use Backbone.LocalStorage instead</p>
|
||||
window.Store is deprecated, use Backbone.LocalStorage instead</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>{
|
||||
<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>)) || [];
|
||||
@@ -210,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>
|
||||
|
||||
@@ -228,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);
|
||||
@@ -252,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();
|
||||
@@ -272,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>
|
||||
|
||||
@@ -289,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()
|
||||
@@ -311,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>
|
||||
|
||||
@@ -339,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);
|
||||
}
|
||||
|
||||
@@ -360,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 = <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>{
|
||||
<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>
|
||||
@@ -427,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;
|
||||
}
|
||||
@@ -449,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]);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# JavaScriptLint configuration file for Backbone.
|
||||
|
||||
+no_return_value # function {0} does not always return a value
|
||||
+duplicate_formal # duplicate formal argument {0}
|
||||
-equal_as_assign # test for equality (==) mistyped as assignment (=)?{0}
|
||||
+var_hides_arg # variable {0} hides argument
|
||||
+redeclared_var # redeclaration of {0} {1}
|
||||
-anon_no_return_value # anonymous function does not always return a value
|
||||
+missing_semicolon # missing semicolon
|
||||
+meaningless_block # meaningless block; curly braces have no impact
|
||||
-comma_separated_stmts # multiple statements separated by commas (use semicolons?)
|
||||
+unreachable_code # unreachable code
|
||||
+missing_break # missing break statement
|
||||
+missing_break_for_last_case # missing break statement for last case in switch
|
||||
-comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)
|
||||
-inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement
|
||||
-useless_void # use of the void type may be unnecessary (void is always undefined)
|
||||
+multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs
|
||||
+use_of_label # use of label
|
||||
-block_without_braces # block statement without curly braces
|
||||
+leading_decimal_point # leading decimal point may indicate a number or an object member
|
||||
+trailing_decimal_point # trailing decimal point may indicate a number or an object member
|
||||
+octal_number # leading zeros make an octal number
|
||||
+nested_comment # nested comment
|
||||
+misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma
|
||||
-ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement
|
||||
+empty_statement # empty statement or extra semicolon
|
||||
-missing_option_explicit # the "option explicit" control comment is missing
|
||||
+partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag
|
||||
+dup_option_explicit # duplicate "option explicit" control comment
|
||||
+useless_assign # useless assignment
|
||||
+ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity
|
||||
+ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent)
|
||||
-missing_default_case # missing default case in switch statement
|
||||
+duplicate_case_in_switch # duplicate case in switch statements
|
||||
+default_not_at_end # the default case is not at the end of the switch statement
|
||||
+legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax
|
||||
+jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax
|
||||
+useless_comparison # useless comparison; comparing identical expressions
|
||||
+with_statement # with statement hides undeclared variables; use temporary variable instead
|
||||
+trailing_comma_in_array # extra comma is not recommended in array initializers
|
||||
+assign_to_function_call # assignment to a function call
|
||||
+parseint_missing_radix # parseInt missing radix parameter
|
||||
+lambda_assign_requires_semicolon
|
||||
58
docs/search.js
Normal file
58
docs/search.js
Normal file
@@ -0,0 +1,58 @@
|
||||
(function() {
|
||||
var functions = document.querySelectorAll('[data-name]');
|
||||
var sections = document.querySelectorAll('.searchable_section');
|
||||
var searchInput = document.getElementById('function_filter');
|
||||
|
||||
function strIn(a, b) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
return b.indexOf(a) >= 0;
|
||||
}
|
||||
|
||||
function doesMatch(element) {
|
||||
var name = element.getAttribute('data-name');
|
||||
var aliases = element.getAttribute('data-aliases') || '';
|
||||
return strIn(searchInput.value, name) || strIn(searchInput.value, aliases);
|
||||
}
|
||||
|
||||
function filterElement(element) {
|
||||
element.style.display = doesMatch(element) ? '' : 'none';
|
||||
}
|
||||
|
||||
function filterToc() {
|
||||
_.each(functions, filterElement);
|
||||
|
||||
var emptySearch = searchInput.value === '';
|
||||
|
||||
// Hide the titles of empty sections
|
||||
_.each(sections, function(section) {
|
||||
var sectionFunctions = section.querySelectorAll('[data-name]');
|
||||
var showSection = emptySearch || _.some(sectionFunctions, doesMatch);
|
||||
section.style.display = showSection ? '' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
function gotoFirst() {
|
||||
var firstFunction = _.find(functions, doesMatch);
|
||||
if(firstFunction) {
|
||||
window.location.hash = firstFunction.lastChild.getAttribute('href');
|
||||
searchInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
searchInput.addEventListener('input', filterToc, false);
|
||||
|
||||
// Press "Enter" to jump to the first matching function
|
||||
searchInput.addEventListener('keypress', function(e) {
|
||||
if (e.which === 13) {
|
||||
gotoFirst();
|
||||
}
|
||||
});
|
||||
|
||||
// Press "/" to search
|
||||
document.body.addEventListener('keyup', function(event) {
|
||||
if (191 === event.which) {
|
||||
searchInput.focus();
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -52,7 +52,7 @@
|
||||
</div>
|
||||
<p>An example Backbone application contributed by
|
||||
<a href="http://jgn.me/">Jérôme Gravel-Niquet</a>. This demo uses a simple
|
||||
<a href="backbone.localstorage.html">LocalStorage adapter</a>
|
||||
<a href="backbone.localStorage.html">LocalStorage adapter</a>
|
||||
to persist Backbone models within your browser.</p>
|
||||
|
||||
</div>
|
||||
@@ -70,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>
|
||||
|
||||
@@ -125,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(),
|
||||
@@ -146,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>)});
|
||||
}
|
||||
|
||||
@@ -236,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>
|
||||
|
||||
@@ -253,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>
|
||||
|
||||
@@ -271,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>
|
||||
@@ -414,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>
|
||||
@@ -432,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>);
|
||||
@@ -452,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>
|
||||
|
||||
@@ -469,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>
|
||||
@@ -487,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();
|
||||
@@ -510,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>
|
||||
|
||||
@@ -527,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();
|
||||
}
|
||||
|
||||
@@ -638,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>];
|
||||
@@ -662,12 +662,12 @@ loading any preexisting todos that might be saved in <em>localStorage</em>.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-38">¶</a>
|
||||
</div>
|
||||
<p>Re-rendering the App just means refreshing the statistics — the rest
|
||||
<p>Re-rendering the App just means refreshing the statistics – the rest
|
||||
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;
|
||||
|
||||
@@ -697,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>
|
||||
@@ -715,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>
|
||||
|
||||
@@ -733,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>;
|
||||
|
||||
@@ -754,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>
|
||||
|
||||
@@ -35,7 +35,7 @@ function guid() {
|
||||
|
||||
// Our Store is represented by a single JS object in *localStorage*. Create it
|
||||
// with a meaningful name, like the name you'd give a table.
|
||||
// window.Store is deprectated, use Backbone.LocalStorage instead
|
||||
// window.Store is deprecated, use Backbone.LocalStorage instead
|
||||
Backbone.LocalStorage = window.Store = function(name) {
|
||||
this.name = name;
|
||||
var store = this.localStorage().getItem(this.name);
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
Created by
|
||||
<br />
|
||||
<a href="http://jgn.me/">Jérôme Gravel-Niquet</a>.
|
||||
<br />Rewritten by: <a href="http://addyosmani.github.com/todomvc">TodoMVC</a>.
|
||||
<br />Rewritten by: <a href="https://github.com/tastejs/todomvc">TodoMVC</a>.
|
||||
</div>
|
||||
|
||||
<script src="../../test/vendor/json2.js"></script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// An example Backbone application contributed by
|
||||
// [Jérôme Gravel-Niquet](http://jgn.me/). This demo uses a simple
|
||||
// [LocalStorage adapter](backbone.localstorage.html)
|
||||
// [LocalStorage adapter](backbone.localStorage.html)
|
||||
// to persist Backbone models within your browser.
|
||||
|
||||
// Load the application once the DOM is ready, using `jQuery.ready`:
|
||||
|
||||
752
index.html
752
index.html
File diff suppressed because it is too large
Load Diff
@@ -13,19 +13,20 @@ var sauceBrowsers = _.reduce([
|
||||
['chrome', '31'],
|
||||
['chrome', '26'],
|
||||
|
||||
['internet explorer', '11', 'Windows 8.1'],
|
||||
['microsoftedge', '20.10240', 'Windows 10'],
|
||||
['internet explorer', '11', 'Windows 10'],
|
||||
['internet explorer', '10', 'Windows 8'],
|
||||
['internet explorer', '9', 'Windows 7'],
|
||||
['internet explorer', '8'],
|
||||
['internet explorer', '7', 'Windows XP'],
|
||||
// ['internet explorer', '6', 'Windows XP'],
|
||||
|
||||
['opera', '12'],
|
||||
['opera', '11'],
|
||||
|
||||
['android', '5'],
|
||||
['android', '4.4'],
|
||||
['android', '4.3'],
|
||||
|
||||
// 4.3 currently erros with some router tests
|
||||
// ['android', '4.3'],
|
||||
|
||||
['android', '4.0'],
|
||||
|
||||
['safari', '8.0', 'OS X 10.10'],
|
||||
@@ -69,6 +70,9 @@ module.exports = function(config) {
|
||||
'test/*.js'
|
||||
],
|
||||
|
||||
// Number of sauce tests to start in parallel
|
||||
concurrency: 9,
|
||||
|
||||
// test results reporter to use
|
||||
reporters: ['dots', 'saucelabs'],
|
||||
port: 9876,
|
||||
|
||||
48
package.json
48
package.json
@@ -1,36 +1,48 @@
|
||||
{
|
||||
"name" : "backbone",
|
||||
"description" : "Give your JS App some Backbone with Models, Views, Collections, and Events.",
|
||||
"url" : "http://backbonejs.org",
|
||||
"keywords" : ["model", "view", "controller", "router", "server", "client", "browser"],
|
||||
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
|
||||
"dependencies" : {
|
||||
"underscore" : ">=1.7.0"
|
||||
"name": "backbone",
|
||||
"description": "Give your JS App some Backbone with Models, Views, Collections, and Events.",
|
||||
"url": "http://backbonejs.org",
|
||||
"keywords": [
|
||||
"model",
|
||||
"view",
|
||||
"controller",
|
||||
"router",
|
||||
"server",
|
||||
"client",
|
||||
"browser"
|
||||
],
|
||||
"author": "Jeremy Ashkenas",
|
||||
"dependencies": {
|
||||
"underscore": ">=1.8.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coffee-script": "1.7.1",
|
||||
"docco": "0.7.0",
|
||||
"karma": "^0.12.31",
|
||||
"karma-phantomjs-launcher": "^0.1.4",
|
||||
"karma-qunit": "^0.1.4",
|
||||
"eslint": "^2.11.0",
|
||||
"karma": "^0.13.13",
|
||||
"karma-phantomjs-launcher": "^1.0.0",
|
||||
"karma-qunit": "^1.0.0",
|
||||
"phantomjs-prebuilt": "^2.1.7",
|
||||
"qunitjs": "^2.0.0",
|
||||
"uglify-js": "^2.4.17"
|
||||
},
|
||||
"main": "backbone.js",
|
||||
"scripts": {
|
||||
"test": "./node_modules/karma/bin/karma start && coffee test/model.coffee",
|
||||
"test": "karma start && coffee test/model.coffee && npm run lint",
|
||||
"build": "uglifyjs backbone.js --mangle --source-map backbone-min.map -o backbone-min.js",
|
||||
"doc": "docco backbone.js && docco examples/todos/todos.js examples/backbone.localStorage.js",
|
||||
"lint": "jsl -nofilelisting -nologo -conf docs/jsl.conf -process backbone.js"
|
||||
"lint": "eslint backbone.js test/*.js"
|
||||
},
|
||||
"main" : "backbone.js",
|
||||
"version" : "1.2.0",
|
||||
"license" : "MIT",
|
||||
"main": "backbone.js",
|
||||
"version": "1.3.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jashkenas/backbone.git"
|
||||
},
|
||||
"files": [
|
||||
"backbone.js", "backbone-min.js", "backbone-min.map", "LICENSE"
|
||||
"backbone.js",
|
||||
"backbone-min.js",
|
||||
"backbone-min.map",
|
||||
"LICENSE"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
15
test/.eslintrc
Normal file
15
test/.eslintrc
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true
|
||||
},
|
||||
"globals": {
|
||||
"QUnit": false,
|
||||
"Backbone": true,
|
||||
"_": true,
|
||||
"$": true
|
||||
},
|
||||
"rules": {
|
||||
"no-throw-literal": 0,
|
||||
"no-undefined": 0
|
||||
}
|
||||
}
|
||||
1873
test/collection.js
1873
test/collection.js
File diff suppressed because it is too large
Load Diff
520
test/events.js
520
test/events.js
@@ -1,42 +1,44 @@
|
||||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
module("Backbone.Events");
|
||||
QUnit.module('Backbone.Events');
|
||||
|
||||
test("on and trigger", 2, function() {
|
||||
var obj = { counter: 0 };
|
||||
_.extend(obj,Backbone.Events);
|
||||
QUnit.test('on and trigger', function(assert) {
|
||||
assert.expect(2);
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
obj.on('event', function() { obj.counter += 1; });
|
||||
obj.trigger('event');
|
||||
equal(obj.counter,1,'counter should be incremented.');
|
||||
assert.equal(obj.counter, 1, 'counter should be incremented.');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
equal(obj.counter, 5, 'counter should be incremented five times.');
|
||||
assert.equal(obj.counter, 5, 'counter should be incremented five times.');
|
||||
});
|
||||
|
||||
test("binding and triggering multiple events", 4, function() {
|
||||
var obj = { counter: 0 };
|
||||
QUnit.test('binding and triggering multiple events', function(assert) {
|
||||
assert.expect(4);
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
|
||||
obj.on('a b c', function() { obj.counter += 1; });
|
||||
|
||||
obj.trigger('a');
|
||||
equal(obj.counter, 1);
|
||||
assert.equal(obj.counter, 1);
|
||||
|
||||
obj.trigger('a b');
|
||||
equal(obj.counter, 3);
|
||||
assert.equal(obj.counter, 3);
|
||||
|
||||
obj.trigger('c');
|
||||
equal(obj.counter, 4);
|
||||
assert.equal(obj.counter, 4);
|
||||
|
||||
obj.off('a c');
|
||||
obj.trigger('a b c');
|
||||
equal(obj.counter, 5);
|
||||
assert.equal(obj.counter, 5);
|
||||
});
|
||||
|
||||
test("binding and triggering with event maps", function() {
|
||||
var obj = { counter: 0 };
|
||||
QUnit.test('binding and triggering with event maps', function(assert) {
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
|
||||
var increment = function() {
|
||||
@@ -50,36 +52,85 @@
|
||||
}, obj);
|
||||
|
||||
obj.trigger('a');
|
||||
equal(obj.counter, 1);
|
||||
assert.equal(obj.counter, 1);
|
||||
|
||||
obj.trigger('a b');
|
||||
equal(obj.counter, 3);
|
||||
assert.equal(obj.counter, 3);
|
||||
|
||||
obj.trigger('c');
|
||||
equal(obj.counter, 4);
|
||||
assert.equal(obj.counter, 4);
|
||||
|
||||
obj.off({
|
||||
a: increment,
|
||||
c: increment
|
||||
}, obj);
|
||||
obj.trigger('a b c');
|
||||
equal(obj.counter, 5);
|
||||
assert.equal(obj.counter, 5);
|
||||
});
|
||||
|
||||
test("listenTo and stopListening", 1, function() {
|
||||
QUnit.test('binding and triggering multiple event names with event maps', function(assert) {
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
|
||||
var increment = function() {
|
||||
this.counter += 1;
|
||||
};
|
||||
|
||||
obj.on({
|
||||
'a b c': increment
|
||||
});
|
||||
|
||||
obj.trigger('a');
|
||||
assert.equal(obj.counter, 1);
|
||||
|
||||
obj.trigger('a b');
|
||||
assert.equal(obj.counter, 3);
|
||||
|
||||
obj.trigger('c');
|
||||
assert.equal(obj.counter, 4);
|
||||
|
||||
obj.off({
|
||||
'a c': increment
|
||||
});
|
||||
obj.trigger('a b c');
|
||||
assert.equal(obj.counter, 5);
|
||||
});
|
||||
|
||||
QUnit.test('binding and trigger with event maps context', function(assert) {
|
||||
assert.expect(2);
|
||||
var obj = {counter: 0};
|
||||
var context = {};
|
||||
_.extend(obj, Backbone.Events);
|
||||
|
||||
obj.on({
|
||||
a: function() {
|
||||
assert.strictEqual(this, context, 'defaults `context` to `callback` param');
|
||||
}
|
||||
}, context).trigger('a');
|
||||
|
||||
obj.off().on({
|
||||
a: function() {
|
||||
assert.strictEqual(this, context, 'will not override explicit `context` param');
|
||||
}
|
||||
}, this, context).trigger('a');
|
||||
});
|
||||
|
||||
QUnit.test('listenTo and stopListening', function(assert) {
|
||||
assert.expect(1);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenTo(b, 'all', function(){ ok(true); });
|
||||
a.listenTo(b, 'all', function(){ assert.ok(true); });
|
||||
b.trigger('anything');
|
||||
a.listenTo(b, 'all', function(){ ok(false); });
|
||||
a.listenTo(b, 'all', function(){ assert.ok(false); });
|
||||
a.stopListening();
|
||||
b.trigger('anything');
|
||||
});
|
||||
|
||||
test("listenTo and stopListening with event maps", 4, function() {
|
||||
QUnit.test('listenTo and stopListening with event maps', function(assert) {
|
||||
assert.expect(4);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
var cb = function(){ ok(true); };
|
||||
var cb = function(){ assert.ok(true); };
|
||||
a.listenTo(b, {event: cb});
|
||||
b.trigger('event');
|
||||
a.listenTo(b, {event2: cb});
|
||||
@@ -90,10 +141,11 @@
|
||||
b.trigger('event event2');
|
||||
});
|
||||
|
||||
test("stopListening with omitted args", 2, function () {
|
||||
QUnit.test('stopListening with omitted args', function(assert) {
|
||||
assert.expect(2);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
var cb = function () { ok(true); };
|
||||
var cb = function() { assert.ok(true); };
|
||||
a.listenTo(b, 'event', cb);
|
||||
b.on('event', cb);
|
||||
a.listenTo(b, 'event2', cb);
|
||||
@@ -106,219 +158,237 @@
|
||||
b.trigger('event2');
|
||||
});
|
||||
|
||||
test("listenToOnce", 2, function() {
|
||||
QUnit.test('listenToOnce', function(assert) {
|
||||
assert.expect(2);
|
||||
// Same as the previous test, but we use once rather than having to explicitly unbind
|
||||
var obj = { counterA: 0, counterB: 0 };
|
||||
var obj = {counterA: 0, counterB: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var incrA = function(){ obj.counterA += 1; obj.trigger('event'); };
|
||||
var incrB = function(){ obj.counterB += 1; };
|
||||
obj.listenToOnce(obj, 'event', incrA);
|
||||
obj.listenToOnce(obj, 'event', incrB);
|
||||
obj.trigger('event');
|
||||
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
||||
assert.equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
assert.equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
||||
});
|
||||
|
||||
test("listenToOnce and stopListening", 1, function() {
|
||||
QUnit.test('listenToOnce and stopListening', function(assert) {
|
||||
assert.expect(1);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenToOnce(b, 'all', function() { ok(true); });
|
||||
a.listenToOnce(b, 'all', function() { assert.ok(true); });
|
||||
b.trigger('anything');
|
||||
b.trigger('anything');
|
||||
a.listenToOnce(b, 'all', function() { ok(false); });
|
||||
a.listenToOnce(b, 'all', function() { assert.ok(false); });
|
||||
a.stopListening();
|
||||
b.trigger('anything');
|
||||
});
|
||||
|
||||
test("listenTo, listenToOnce and stopListening", 1, function() {
|
||||
QUnit.test('listenTo, listenToOnce and stopListening', function(assert) {
|
||||
assert.expect(1);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenToOnce(b, 'all', function() { ok(true); });
|
||||
a.listenToOnce(b, 'all', function() { assert.ok(true); });
|
||||
b.trigger('anything');
|
||||
b.trigger('anything');
|
||||
a.listenTo(b, 'all', function() { ok(false); });
|
||||
a.listenTo(b, 'all', function() { assert.ok(false); });
|
||||
a.stopListening();
|
||||
b.trigger('anything');
|
||||
});
|
||||
|
||||
test("listenTo and stopListening with event maps", 1, function() {
|
||||
QUnit.test('listenTo and stopListening with event maps', function(assert) {
|
||||
assert.expect(1);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenTo(b, {change: function(){ ok(true); }});
|
||||
a.listenTo(b, {change: function(){ assert.ok(true); }});
|
||||
b.trigger('change');
|
||||
a.listenTo(b, {change: function(){ ok(false); }});
|
||||
a.listenTo(b, {change: function(){ assert.ok(false); }});
|
||||
a.stopListening();
|
||||
b.trigger('change');
|
||||
});
|
||||
|
||||
test("listenTo yourself", 1, function(){
|
||||
QUnit.test('listenTo yourself', function(assert) {
|
||||
assert.expect(1);
|
||||
var e = _.extend({}, Backbone.Events);
|
||||
e.listenTo(e, "foo", function(){ ok(true); });
|
||||
e.trigger("foo");
|
||||
e.listenTo(e, 'foo', function(){ assert.ok(true); });
|
||||
e.trigger('foo');
|
||||
});
|
||||
|
||||
test("listenTo yourself cleans yourself up with stopListening", 1, function(){
|
||||
QUnit.test('listenTo yourself cleans yourself up with stopListening', function(assert) {
|
||||
assert.expect(1);
|
||||
var e = _.extend({}, Backbone.Events);
|
||||
e.listenTo(e, "foo", function(){ ok(true); });
|
||||
e.trigger("foo");
|
||||
e.listenTo(e, 'foo', function(){ assert.ok(true); });
|
||||
e.trigger('foo');
|
||||
e.stopListening();
|
||||
e.trigger("foo");
|
||||
e.trigger('foo');
|
||||
});
|
||||
|
||||
test("stopListening cleans up references", 12, function() {
|
||||
QUnit.test('stopListening cleans up references', function(assert) {
|
||||
assert.expect(12);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
var fn = function() {};
|
||||
b.on('event', fn);
|
||||
a.listenTo(b, 'event', fn).stopListening();
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenTo(b, 'event', fn).stopListening(b);
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenTo(b, 'event', fn).stopListening(b, 'event');
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenTo(b, 'event', fn).stopListening(b, 'event', fn);
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
});
|
||||
|
||||
test("stopListening cleans up references from listenToOnce", 12, function() {
|
||||
QUnit.test('stopListening cleans up references from listenToOnce', function(assert) {
|
||||
assert.expect(12);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
var fn = function() {};
|
||||
b.on('event', fn);
|
||||
a.listenToOnce(b, 'event', fn).stopListening();
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenToOnce(b, 'event', fn).stopListening(b);
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenToOnce(b, 'event', fn).stopListening(b, 'event');
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenToOnce(b, 'event', fn).stopListening(b, 'event', fn);
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._events.event), 1);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._events.event), 1);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
});
|
||||
|
||||
test("listenTo and off cleaning up references", 8, function() {
|
||||
QUnit.test('listenTo and off cleaning up references', function(assert) {
|
||||
assert.expect(8);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
var fn = function() {};
|
||||
a.listenTo(b, 'event', fn);
|
||||
b.off();
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenTo(b, 'event', fn);
|
||||
b.off('event');
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenTo(b, 'event', fn);
|
||||
b.off(null, fn);
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
a.listenTo(b, 'event', fn);
|
||||
b.off(null, null, a);
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
equal(_.size(b._listeners), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(b._listeners), 0);
|
||||
});
|
||||
|
||||
test("listenTo and stopListening cleaning up references", 2, function() {
|
||||
QUnit.test('listenTo and stopListening cleaning up references', function(assert) {
|
||||
assert.expect(2);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenTo(b, 'all', function(){ ok(true); });
|
||||
a.listenTo(b, 'all', function(){ assert.ok(true); });
|
||||
b.trigger('anything');
|
||||
a.listenTo(b, 'other', function(){ ok(false); });
|
||||
a.listenTo(b, 'other', function(){ assert.ok(false); });
|
||||
a.stopListening(b, 'other');
|
||||
a.stopListening(b, 'all');
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
});
|
||||
|
||||
test("listenToOnce without context cleans up references after the event has fired", 2, function() {
|
||||
QUnit.test('listenToOnce without context cleans up references after the event has fired', function(assert) {
|
||||
assert.expect(2);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenToOnce(b, 'all', function(){ ok(true); });
|
||||
a.listenToOnce(b, 'all', function(){ assert.ok(true); });
|
||||
b.trigger('anything');
|
||||
equal(_.size(a._listeningTo), 0);
|
||||
assert.equal(_.size(a._listeningTo), 0);
|
||||
});
|
||||
|
||||
test("listenToOnce with event maps cleans up references", 2, function() {
|
||||
QUnit.test('listenToOnce with event maps cleans up references', function(assert) {
|
||||
assert.expect(2);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenToOnce(b, {
|
||||
one: function() { ok(true); },
|
||||
two: function() { ok(false); }
|
||||
one: function() { assert.ok(true); },
|
||||
two: function() { assert.ok(false); }
|
||||
});
|
||||
b.trigger('one');
|
||||
equal(_.size(a._listeningTo), 1);
|
||||
assert.equal(_.size(a._listeningTo), 1);
|
||||
});
|
||||
|
||||
test("listenToOnce with event maps binds the correct `this`", 1, function() {
|
||||
QUnit.test('listenToOnce with event maps binds the correct `this`', function(assert) {
|
||||
assert.expect(1);
|
||||
var a = _.extend({}, Backbone.Events);
|
||||
var b = _.extend({}, Backbone.Events);
|
||||
a.listenToOnce(b, {
|
||||
one: function() { ok(this === a); },
|
||||
two: function() { ok(false); }
|
||||
one: function() { assert.ok(this === a); },
|
||||
two: function() { assert.ok(false); }
|
||||
});
|
||||
b.trigger('one');
|
||||
});
|
||||
|
||||
test("listenTo with empty callback doesn't throw an error", 1, function(){
|
||||
QUnit.test("listenTo with empty callback doesn't throw an error", function(assert) {
|
||||
assert.expect(1);
|
||||
var e = _.extend({}, Backbone.Events);
|
||||
e.listenTo(e, "foo", null);
|
||||
e.trigger("foo");
|
||||
ok(true);
|
||||
e.listenTo(e, 'foo', null);
|
||||
e.trigger('foo');
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
test("trigger all for each event", 3, function() {
|
||||
var a, b, obj = { counter: 0 };
|
||||
QUnit.test('trigger all for each event', function(assert) {
|
||||
assert.expect(3);
|
||||
var a, b, obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
obj.on('all', function(event) {
|
||||
obj.counter++;
|
||||
if (event == 'a') a = true;
|
||||
if (event == 'b') b = true;
|
||||
if (event === 'a') a = true;
|
||||
if (event === 'b') b = true;
|
||||
})
|
||||
.trigger('a b');
|
||||
ok(a);
|
||||
ok(b);
|
||||
equal(obj.counter, 2);
|
||||
assert.ok(a);
|
||||
assert.ok(b);
|
||||
assert.equal(obj.counter, 2);
|
||||
});
|
||||
|
||||
test("on, then unbind all functions", 1, function() {
|
||||
var obj = { counter: 0 };
|
||||
_.extend(obj,Backbone.Events);
|
||||
QUnit.test('on, then unbind all functions', function(assert) {
|
||||
assert.expect(1);
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var callback = function() { obj.counter += 1; };
|
||||
obj.on('event', callback);
|
||||
obj.trigger('event');
|
||||
obj.off('event');
|
||||
obj.trigger('event');
|
||||
equal(obj.counter, 1, 'counter should have only been incremented once.');
|
||||
assert.equal(obj.counter, 1, 'counter should have only been incremented once.');
|
||||
});
|
||||
|
||||
test("bind two callbacks, unbind only one", 2, function() {
|
||||
var obj = { counterA: 0, counterB: 0 };
|
||||
_.extend(obj,Backbone.Events);
|
||||
QUnit.test('bind two callbacks, unbind only one', function(assert) {
|
||||
assert.expect(2);
|
||||
var obj = {counterA: 0, counterB: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var callback = function() { obj.counterA += 1; };
|
||||
obj.on('event', callback);
|
||||
obj.on('event', function() { obj.counterB += 1; });
|
||||
obj.trigger('event');
|
||||
obj.off('event', callback);
|
||||
obj.trigger('event');
|
||||
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
equal(obj.counterB, 2, 'counterB should have been incremented twice.');
|
||||
assert.equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
assert.equal(obj.counterB, 2, 'counterB should have been incremented twice.');
|
||||
});
|
||||
|
||||
test("unbind a callback in the midst of it firing", 1, function() {
|
||||
QUnit.test('unbind a callback in the midst of it firing', function(assert) {
|
||||
assert.expect(1);
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var callback = function() {
|
||||
@@ -329,12 +399,13 @@
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
equal(obj.counter, 1, 'the callback should have been unbound.');
|
||||
assert.equal(obj.counter, 1, 'the callback should have been unbound.');
|
||||
});
|
||||
|
||||
test("two binds that unbind themeselves", 2, function() {
|
||||
var obj = { counterA: 0, counterB: 0 };
|
||||
_.extend(obj,Backbone.Events);
|
||||
QUnit.test('two binds that unbind themeselves', function(assert) {
|
||||
assert.expect(2);
|
||||
var obj = {counterA: 0, counterB: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var incrA = function(){ obj.counterA += 1; obj.off('event', incrA); };
|
||||
var incrB = function(){ obj.counterB += 1; obj.off('event', incrB); };
|
||||
obj.on('event', incrA);
|
||||
@@ -342,48 +413,64 @@
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
||||
assert.equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
assert.equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
||||
});
|
||||
|
||||
test("bind a callback with a supplied context", 1, function () {
|
||||
var TestClass = function () {
|
||||
return this;
|
||||
};
|
||||
TestClass.prototype.assertTrue = function () {
|
||||
ok(true, '`this` was bound to the callback');
|
||||
};
|
||||
QUnit.test('bind a callback with a default context when none supplied', function(assert) {
|
||||
assert.expect(1);
|
||||
var obj = _.extend({
|
||||
assertTrue: function() {
|
||||
assert.equal(this, obj, '`this` was bound to the callback');
|
||||
}
|
||||
}, Backbone.Events);
|
||||
|
||||
var obj = _.extend({},Backbone.Events);
|
||||
obj.on('event', function () { this.assertTrue(); }, (new TestClass));
|
||||
obj.once('event', obj.assertTrue);
|
||||
obj.trigger('event');
|
||||
});
|
||||
|
||||
test("nested trigger with unbind", 1, function () {
|
||||
var obj = { counter: 0 };
|
||||
QUnit.test('bind a callback with a supplied context', function(assert) {
|
||||
assert.expect(1);
|
||||
var TestClass = function() {
|
||||
return this;
|
||||
};
|
||||
TestClass.prototype.assertTrue = function() {
|
||||
assert.ok(true, '`this` was bound to the callback');
|
||||
};
|
||||
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
obj.on('event', function() { this.assertTrue(); }, new TestClass);
|
||||
obj.trigger('event');
|
||||
});
|
||||
|
||||
QUnit.test('nested trigger with unbind', function(assert) {
|
||||
assert.expect(1);
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var incr1 = function(){ obj.counter += 1; obj.off('event', incr1); obj.trigger('event'); };
|
||||
var incr2 = function(){ obj.counter += 1; };
|
||||
obj.on('event', incr1);
|
||||
obj.on('event', incr2);
|
||||
obj.trigger('event');
|
||||
equal(obj.counter, 3, 'counter should have been incremented three times');
|
||||
assert.equal(obj.counter, 3, 'counter should have been incremented three times');
|
||||
});
|
||||
|
||||
test("callback list is not altered during trigger", 2, function () {
|
||||
QUnit.test('callback list is not altered during trigger', function(assert) {
|
||||
assert.expect(2);
|
||||
var counter = 0, obj = _.extend({}, Backbone.Events);
|
||||
var incr = function(){ counter++; };
|
||||
var incrOn = function(){ obj.on('event all', incr); };
|
||||
var incrOff = function(){ obj.off('event all', incr); };
|
||||
|
||||
obj.on('event all', incrOn).trigger('event');
|
||||
equal(counter, 0, 'on does not alter callback list');
|
||||
assert.equal(counter, 0, 'on does not alter callback list');
|
||||
|
||||
obj.off().on('event', incrOff).on('event all', incr).trigger('event');
|
||||
equal(counter, 2, 'off does not alter callback list');
|
||||
assert.equal(counter, 2, 'off does not alter callback list');
|
||||
});
|
||||
|
||||
test("#1282 - 'all' callback list is retrieved after each event.", 1, function() {
|
||||
QUnit.test("#1282 - 'all' callback list is retrieved after each event.", function(assert) {
|
||||
assert.expect(1);
|
||||
var counter = 0;
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
var incr = function(){ counter++; };
|
||||
@@ -391,61 +478,68 @@
|
||||
obj.on('y', incr).on('all', incr);
|
||||
})
|
||||
.trigger('x y');
|
||||
strictEqual(counter, 2);
|
||||
assert.strictEqual(counter, 2);
|
||||
});
|
||||
|
||||
test("if no callback is provided, `on` is a noop", 0, function() {
|
||||
QUnit.test('if no callback is provided, `on` is a noop', function(assert) {
|
||||
assert.expect(0);
|
||||
_.extend({}, Backbone.Events).on('test').trigger('test');
|
||||
});
|
||||
|
||||
test("if callback is truthy but not a function, `on` should throw an error just like jQuery", 1, function() {
|
||||
QUnit.test('if callback is truthy but not a function, `on` should throw an error just like jQuery', function(assert) {
|
||||
assert.expect(1);
|
||||
var view = _.extend({}, Backbone.Events).on('test', 'noop');
|
||||
throws(function() {
|
||||
assert.raises(function() {
|
||||
view.trigger('test');
|
||||
});
|
||||
});
|
||||
|
||||
test("remove all events for a specific context", 4, function() {
|
||||
QUnit.test('remove all events for a specific context', function(assert) {
|
||||
assert.expect(4);
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
obj.on('x y all', function() { ok(true); });
|
||||
obj.on('x y all', function() { ok(false); }, obj);
|
||||
obj.on('x y all', function() { assert.ok(true); });
|
||||
obj.on('x y all', function() { assert.ok(false); }, obj);
|
||||
obj.off(null, null, obj);
|
||||
obj.trigger('x y');
|
||||
});
|
||||
|
||||
test("remove all events for a specific callback", 4, function() {
|
||||
QUnit.test('remove all events for a specific callback', function(assert) {
|
||||
assert.expect(4);
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
var success = function() { ok(true); };
|
||||
var fail = function() { ok(false); };
|
||||
var success = function() { assert.ok(true); };
|
||||
var fail = function() { assert.ok(false); };
|
||||
obj.on('x y all', success);
|
||||
obj.on('x y all', fail);
|
||||
obj.off(null, fail);
|
||||
obj.trigger('x y');
|
||||
});
|
||||
|
||||
test("#1310 - off does not skip consecutive events", 0, function() {
|
||||
QUnit.test('#1310 - off does not skip consecutive events', function(assert) {
|
||||
assert.expect(0);
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
obj.on('event', function() { ok(false); }, obj);
|
||||
obj.on('event', function() { ok(false); }, obj);
|
||||
obj.on('event', function() { assert.ok(false); }, obj);
|
||||
obj.on('event', function() { assert.ok(false); }, obj);
|
||||
obj.off(null, null, obj);
|
||||
obj.trigger('event');
|
||||
});
|
||||
|
||||
test("once", 2, function() {
|
||||
QUnit.test('once', function(assert) {
|
||||
assert.expect(2);
|
||||
// Same as the previous test, but we use once rather than having to explicitly unbind
|
||||
var obj = { counterA: 0, counterB: 0 };
|
||||
var obj = {counterA: 0, counterB: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
var incrA = function(){ obj.counterA += 1; obj.trigger('event'); };
|
||||
var incrB = function(){ obj.counterB += 1; };
|
||||
obj.once('event', incrA);
|
||||
obj.once('event', incrB);
|
||||
obj.trigger('event');
|
||||
equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
||||
assert.equal(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
assert.equal(obj.counterB, 1, 'counterB should have only been incremented once.');
|
||||
});
|
||||
|
||||
test("once variant one", 3, function() {
|
||||
var f = function(){ ok(true); };
|
||||
QUnit.test('once variant one', function(assert) {
|
||||
assert.expect(3);
|
||||
var f = function(){ assert.ok(true); };
|
||||
|
||||
var a = _.extend({}, Backbone.Events).once('event', f);
|
||||
var b = _.extend({}, Backbone.Events).on('event', f);
|
||||
@@ -456,8 +550,9 @@
|
||||
b.trigger('event');
|
||||
});
|
||||
|
||||
test("once variant two", 3, function() {
|
||||
var f = function(){ ok(true); };
|
||||
QUnit.test('once variant two', function(assert) {
|
||||
assert.expect(3);
|
||||
var f = function(){ assert.ok(true); };
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
|
||||
obj
|
||||
@@ -467,8 +562,9 @@
|
||||
.trigger('event');
|
||||
});
|
||||
|
||||
test("once with off", 0, function() {
|
||||
var f = function(){ ok(true); };
|
||||
QUnit.test('once with off', function(assert) {
|
||||
assert.expect(0);
|
||||
var f = function(){ assert.ok(true); };
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
|
||||
obj.once('event', f);
|
||||
@@ -476,8 +572,8 @@
|
||||
obj.trigger('event');
|
||||
});
|
||||
|
||||
test("once with event maps", function() {
|
||||
var obj = { counter: 0 };
|
||||
QUnit.test('once with event maps', function(assert) {
|
||||
var obj = {counter: 0};
|
||||
_.extend(obj, Backbone.Events);
|
||||
|
||||
var increment = function() {
|
||||
@@ -491,101 +587,123 @@
|
||||
}, obj);
|
||||
|
||||
obj.trigger('a');
|
||||
equal(obj.counter, 1);
|
||||
assert.equal(obj.counter, 1);
|
||||
|
||||
obj.trigger('a b');
|
||||
equal(obj.counter, 2);
|
||||
assert.equal(obj.counter, 2);
|
||||
|
||||
obj.trigger('c');
|
||||
equal(obj.counter, 3);
|
||||
assert.equal(obj.counter, 3);
|
||||
|
||||
obj.trigger('a b c');
|
||||
equal(obj.counter, 3);
|
||||
assert.equal(obj.counter, 3);
|
||||
});
|
||||
|
||||
test("once with off only by context", 0, function() {
|
||||
QUnit.test('bind a callback with a supplied context using once with object notation', function(assert) {
|
||||
assert.expect(1);
|
||||
var obj = {counter: 0};
|
||||
var context = {};
|
||||
_.extend(obj, Backbone.Events);
|
||||
|
||||
obj.once({
|
||||
a: function() {
|
||||
assert.strictEqual(this, context, 'defaults `context` to `callback` param');
|
||||
}
|
||||
}, context).trigger('a');
|
||||
});
|
||||
|
||||
QUnit.test('once with off only by context', function(assert) {
|
||||
assert.expect(0);
|
||||
var context = {};
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
obj.once('event', function(){ ok(false); }, context);
|
||||
obj.once('event', function(){ assert.ok(false); }, context);
|
||||
obj.off(null, null, context);
|
||||
obj.trigger('event');
|
||||
});
|
||||
|
||||
test("Backbone object inherits Events", function() {
|
||||
ok(Backbone.on === Backbone.Events.on);
|
||||
QUnit.test('Backbone object inherits Events', function(assert) {
|
||||
assert.ok(Backbone.on === Backbone.Events.on);
|
||||
});
|
||||
|
||||
asyncTest("once with asynchronous events", 1, function() {
|
||||
var func = _.debounce(function() { ok(true); start(); }, 50);
|
||||
QUnit.test('once with asynchronous events', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
var func = _.debounce(function() { assert.ok(true); done(); }, 50);
|
||||
var obj = _.extend({}, Backbone.Events).once('async', func);
|
||||
|
||||
obj.trigger('async');
|
||||
obj.trigger('async');
|
||||
});
|
||||
|
||||
test("once with multiple events.", 2, function() {
|
||||
QUnit.test('once with multiple events.', function(assert) {
|
||||
assert.expect(2);
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
obj.once('x y', function() { ok(true); });
|
||||
obj.once('x y', function() { assert.ok(true); });
|
||||
obj.trigger('x y');
|
||||
});
|
||||
|
||||
test("Off during iteration with once.", 2, function() {
|
||||
QUnit.test('Off during iteration with once.', function(assert) {
|
||||
assert.expect(2);
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
var f = function(){ this.off('event', f); };
|
||||
obj.on('event', f);
|
||||
obj.once('event', function(){});
|
||||
obj.on('event', function(){ ok(true); });
|
||||
obj.on('event', function(){ assert.ok(true); });
|
||||
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
});
|
||||
|
||||
test("`once` on `all` should work as expected", 1, function() {
|
||||
QUnit.test('`once` on `all` should work as expected', function(assert) {
|
||||
assert.expect(1);
|
||||
Backbone.once('all', function() {
|
||||
ok(true);
|
||||
assert.ok(true);
|
||||
Backbone.trigger('all');
|
||||
});
|
||||
Backbone.trigger('all');
|
||||
});
|
||||
|
||||
test("once without a callback is a noop", 0, function() {
|
||||
QUnit.test('once without a callback is a noop', function(assert) {
|
||||
assert.expect(0);
|
||||
_.extend({}, Backbone.Events).once('event').trigger('event');
|
||||
});
|
||||
|
||||
test("listenToOnce without a callback is a noop", 0, function() {
|
||||
QUnit.test('listenToOnce without a callback is a noop', function(assert) {
|
||||
assert.expect(0);
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
obj.listenToOnce(obj, 'event').trigger('event');
|
||||
});
|
||||
|
||||
test("event functions are chainable", function() {
|
||||
QUnit.test('event functions are chainable', function(assert) {
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
var obj2 = _.extend({}, Backbone.Events);
|
||||
var fn = function() {};
|
||||
equal(obj, obj.trigger('noeventssetyet'));
|
||||
equal(obj, obj.off('noeventssetyet'));
|
||||
equal(obj, obj.stopListening('noeventssetyet'));
|
||||
equal(obj, obj.on('a', fn));
|
||||
equal(obj, obj.once('c', fn));
|
||||
equal(obj, obj.trigger('a'));
|
||||
equal(obj, obj.listenTo(obj2, 'a', fn));
|
||||
equal(obj, obj.listenToOnce(obj2, 'b', fn));
|
||||
equal(obj, obj.off('a c'));
|
||||
equal(obj, obj.stopListening(obj2, 'a'));
|
||||
equal(obj, obj.stopListening());
|
||||
assert.equal(obj, obj.trigger('noeventssetyet'));
|
||||
assert.equal(obj, obj.off('noeventssetyet'));
|
||||
assert.equal(obj, obj.stopListening('noeventssetyet'));
|
||||
assert.equal(obj, obj.on('a', fn));
|
||||
assert.equal(obj, obj.once('c', fn));
|
||||
assert.equal(obj, obj.trigger('a'));
|
||||
assert.equal(obj, obj.listenTo(obj2, 'a', fn));
|
||||
assert.equal(obj, obj.listenToOnce(obj2, 'b', fn));
|
||||
assert.equal(obj, obj.off('a c'));
|
||||
assert.equal(obj, obj.stopListening(obj2, 'a'));
|
||||
assert.equal(obj, obj.stopListening());
|
||||
});
|
||||
|
||||
test("#3448 - listenToOnce with space-separated events", 2, function() {
|
||||
QUnit.test('#3448 - listenToOnce with space-separated events', function(assert) {
|
||||
assert.expect(2);
|
||||
var one = _.extend({}, Backbone.Events);
|
||||
var two = _.extend({}, Backbone.Events);
|
||||
var count = 1;
|
||||
one.listenToOnce(two, 'x y', function(n) { ok(n === count++); });
|
||||
one.listenToOnce(two, 'x y', function(n) { assert.ok(n === count++); });
|
||||
two.trigger('x', 1);
|
||||
two.trigger('x', 1);
|
||||
two.trigger('y', 2);
|
||||
two.trigger('y', 2);
|
||||
});
|
||||
|
||||
test("#3611 - listenTo is compatible with non-Backbone event libraries", 1, function() {
|
||||
QUnit.test('#3611 - listenTo is compatible with non-Backbone event libraries', function(assert) {
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
var other = {
|
||||
events: {},
|
||||
@@ -597,11 +715,11 @@
|
||||
}
|
||||
};
|
||||
|
||||
obj.listenTo(other, 'test', function() { ok(true); });
|
||||
obj.listenTo(other, 'test', function() { assert.ok(true); });
|
||||
other.trigger('test');
|
||||
});
|
||||
|
||||
test("#3611 - stopListening is compatible with non-Backbone event libraries", 1, function() {
|
||||
QUnit.test('#3611 - stopListening is compatible with non-Backbone event libraries', function(assert) {
|
||||
var obj = _.extend({}, Backbone.Events);
|
||||
var other = {
|
||||
events: {},
|
||||
@@ -617,9 +735,9 @@
|
||||
}
|
||||
};
|
||||
|
||||
obj.listenTo(other, 'test', function() { ok(false); });
|
||||
obj.listenTo(other, 'test', function() { assert.ok(false); });
|
||||
obj.stopListening(other);
|
||||
other.trigger('test');
|
||||
equal(_.size(obj._listeningTo), 0);
|
||||
assert.equal(_.size(obj._listeningTo), 0);
|
||||
});
|
||||
})();
|
||||
})(QUnit);
|
||||
|
||||
1203
test/model.js
1203
test/model.js
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,13 @@
|
||||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
module("Backbone.noConflict");
|
||||
QUnit.module('Backbone.noConflict');
|
||||
|
||||
test('noConflict', 2, function() {
|
||||
QUnit.test('noConflict', function(assert) {
|
||||
assert.expect(2);
|
||||
var noconflictBackbone = Backbone.noConflict();
|
||||
equal(window.Backbone, undefined, 'Returned window.Backbone');
|
||||
assert.equal(window.Backbone, undefined, 'Returned window.Backbone');
|
||||
window.Backbone = noconflictBackbone;
|
||||
equal(window.Backbone, noconflictBackbone, 'Backbone is still pointing to the original Backbone');
|
||||
assert.equal(window.Backbone, noconflictBackbone, 'Backbone is still pointing to the original Backbone');
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
||||
621
test/router.js
621
test/router.js
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,4 @@
|
||||
$('body').append(
|
||||
'<div id="qunit"></div>' +
|
||||
'<div id="qunit-fixture">' +
|
||||
'<div id="testElement"><h1>Test</h1></div>' +
|
||||
'</div>'
|
||||
);
|
||||
'<div id="qunit-fixture"></div>'
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var sync = Backbone.sync;
|
||||
var ajax = Backbone.ajax;
|
||||
@@ -8,11 +8,13 @@
|
||||
var pushState = history.pushState;
|
||||
var replaceState = history.replaceState;
|
||||
|
||||
QUnit.config.noglobals = true;
|
||||
|
||||
QUnit.testStart(function() {
|
||||
var env = QUnit.config.current.testEnvironment;
|
||||
|
||||
// We never want to actually call these during tests.
|
||||
history.pushState = history.replaceState = function(){};
|
||||
history.pushState = history.replaceState = function() {};
|
||||
|
||||
// Capture ajax settings for comparison.
|
||||
Backbone.ajax = function(settings) {
|
||||
@@ -40,4 +42,4 @@
|
||||
history.replaceState = replaceState;
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
||||
200
test/sync.js
200
test/sync.js
@@ -1,221 +1,239 @@
|
||||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var Library = Backbone.Collection.extend({
|
||||
url : function() { return '/library'; }
|
||||
url: function() { return '/library'; }
|
||||
});
|
||||
var library;
|
||||
|
||||
var attrs = {
|
||||
title : "The Tempest",
|
||||
author : "Bill Shakespeare",
|
||||
length : 123
|
||||
title: 'The Tempest',
|
||||
author: 'Bill Shakespeare',
|
||||
length: 123
|
||||
};
|
||||
|
||||
module("Backbone.sync", {
|
||||
QUnit.module('Backbone.sync', {
|
||||
|
||||
setup : function() {
|
||||
beforeEach: function(assert) {
|
||||
library = new Library;
|
||||
library.create(attrs, {wait: false});
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach: function(assert) {
|
||||
Backbone.emulateHTTP = false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
test("read", 4, function() {
|
||||
QUnit.test('read', function(assert) {
|
||||
assert.expect(4);
|
||||
library.fetch();
|
||||
equal(this.ajaxSettings.url, '/library');
|
||||
equal(this.ajaxSettings.type, 'GET');
|
||||
equal(this.ajaxSettings.dataType, 'json');
|
||||
ok(_.isEmpty(this.ajaxSettings.data));
|
||||
assert.equal(this.ajaxSettings.url, '/library');
|
||||
assert.equal(this.ajaxSettings.type, 'GET');
|
||||
assert.equal(this.ajaxSettings.dataType, 'json');
|
||||
assert.ok(_.isEmpty(this.ajaxSettings.data));
|
||||
});
|
||||
|
||||
test("passing data", 3, function() {
|
||||
QUnit.test('passing data', function(assert) {
|
||||
assert.expect(3);
|
||||
library.fetch({data: {a: 'a', one: 1}});
|
||||
equal(this.ajaxSettings.url, '/library');
|
||||
equal(this.ajaxSettings.data.a, 'a');
|
||||
equal(this.ajaxSettings.data.one, 1);
|
||||
assert.equal(this.ajaxSettings.url, '/library');
|
||||
assert.equal(this.ajaxSettings.data.a, 'a');
|
||||
assert.equal(this.ajaxSettings.data.one, 1);
|
||||
});
|
||||
|
||||
test("create", 6, function() {
|
||||
equal(this.ajaxSettings.url, '/library');
|
||||
equal(this.ajaxSettings.type, 'POST');
|
||||
equal(this.ajaxSettings.dataType, 'json');
|
||||
QUnit.test('create', function(assert) {
|
||||
assert.expect(6);
|
||||
assert.equal(this.ajaxSettings.url, '/library');
|
||||
assert.equal(this.ajaxSettings.type, 'POST');
|
||||
assert.equal(this.ajaxSettings.dataType, 'json');
|
||||
var data = JSON.parse(this.ajaxSettings.data);
|
||||
equal(data.title, 'The Tempest');
|
||||
equal(data.author, 'Bill Shakespeare');
|
||||
equal(data.length, 123);
|
||||
assert.equal(data.title, 'The Tempest');
|
||||
assert.equal(data.author, 'Bill Shakespeare');
|
||||
assert.equal(data.length, 123);
|
||||
});
|
||||
|
||||
test("update", 7, function() {
|
||||
QUnit.test('update', function(assert) {
|
||||
assert.expect(7);
|
||||
library.first().save({id: '1-the-tempest', author: 'William Shakespeare'});
|
||||
equal(this.ajaxSettings.url, '/library/1-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'PUT');
|
||||
equal(this.ajaxSettings.dataType, 'json');
|
||||
assert.equal(this.ajaxSettings.url, '/library/1-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'PUT');
|
||||
assert.equal(this.ajaxSettings.dataType, 'json');
|
||||
var data = JSON.parse(this.ajaxSettings.data);
|
||||
equal(data.id, '1-the-tempest');
|
||||
equal(data.title, 'The Tempest');
|
||||
equal(data.author, 'William Shakespeare');
|
||||
equal(data.length, 123);
|
||||
assert.equal(data.id, '1-the-tempest');
|
||||
assert.equal(data.title, 'The Tempest');
|
||||
assert.equal(data.author, 'William Shakespeare');
|
||||
assert.equal(data.length, 123);
|
||||
});
|
||||
|
||||
test("update with emulateHTTP and emulateJSON", 7, function() {
|
||||
QUnit.test('update with emulateHTTP and emulateJSON', function(assert) {
|
||||
assert.expect(7);
|
||||
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'}, {
|
||||
emulateHTTP: true,
|
||||
emulateJSON: true
|
||||
});
|
||||
equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'POST');
|
||||
equal(this.ajaxSettings.dataType, 'json');
|
||||
equal(this.ajaxSettings.data._method, 'PUT');
|
||||
assert.equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'POST');
|
||||
assert.equal(this.ajaxSettings.dataType, 'json');
|
||||
assert.equal(this.ajaxSettings.data._method, 'PUT');
|
||||
var data = JSON.parse(this.ajaxSettings.data.model);
|
||||
equal(data.id, '2-the-tempest');
|
||||
equal(data.author, 'Tim Shakespeare');
|
||||
equal(data.length, 123);
|
||||
assert.equal(data.id, '2-the-tempest');
|
||||
assert.equal(data.author, 'Tim Shakespeare');
|
||||
assert.equal(data.length, 123);
|
||||
});
|
||||
|
||||
test("update with just emulateHTTP", 6, function() {
|
||||
QUnit.test('update with just emulateHTTP', function(assert) {
|
||||
assert.expect(6);
|
||||
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'}, {
|
||||
emulateHTTP: true
|
||||
});
|
||||
equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'POST');
|
||||
equal(this.ajaxSettings.contentType, 'application/json');
|
||||
assert.equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'POST');
|
||||
assert.equal(this.ajaxSettings.contentType, 'application/json');
|
||||
var data = JSON.parse(this.ajaxSettings.data);
|
||||
equal(data.id, '2-the-tempest');
|
||||
equal(data.author, 'Tim Shakespeare');
|
||||
equal(data.length, 123);
|
||||
assert.equal(data.id, '2-the-tempest');
|
||||
assert.equal(data.author, 'Tim Shakespeare');
|
||||
assert.equal(data.length, 123);
|
||||
});
|
||||
|
||||
test("update with just emulateJSON", 6, function() {
|
||||
QUnit.test('update with just emulateJSON', function(assert) {
|
||||
assert.expect(6);
|
||||
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'}, {
|
||||
emulateJSON: true
|
||||
});
|
||||
equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'PUT');
|
||||
equal(this.ajaxSettings.contentType, 'application/x-www-form-urlencoded');
|
||||
assert.equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'PUT');
|
||||
assert.equal(this.ajaxSettings.contentType, 'application/x-www-form-urlencoded');
|
||||
var data = JSON.parse(this.ajaxSettings.data.model);
|
||||
equal(data.id, '2-the-tempest');
|
||||
equal(data.author, 'Tim Shakespeare');
|
||||
equal(data.length, 123);
|
||||
assert.equal(data.id, '2-the-tempest');
|
||||
assert.equal(data.author, 'Tim Shakespeare');
|
||||
assert.equal(data.length, 123);
|
||||
});
|
||||
|
||||
test("read model", 3, function() {
|
||||
QUnit.test('read model', function(assert) {
|
||||
assert.expect(3);
|
||||
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
|
||||
library.first().fetch();
|
||||
equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'GET');
|
||||
ok(_.isEmpty(this.ajaxSettings.data));
|
||||
assert.equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'GET');
|
||||
assert.ok(_.isEmpty(this.ajaxSettings.data));
|
||||
});
|
||||
|
||||
test("destroy", 3, function() {
|
||||
QUnit.test('destroy', function(assert) {
|
||||
assert.expect(3);
|
||||
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
|
||||
library.first().destroy({wait: true});
|
||||
equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'DELETE');
|
||||
equal(this.ajaxSettings.data, null);
|
||||
assert.equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'DELETE');
|
||||
assert.equal(this.ajaxSettings.data, null);
|
||||
});
|
||||
|
||||
test("destroy with emulateHTTP", 3, function() {
|
||||
QUnit.test('destroy with emulateHTTP', function(assert) {
|
||||
assert.expect(3);
|
||||
library.first().save({id: '2-the-tempest', author: 'Tim Shakespeare'});
|
||||
library.first().destroy({
|
||||
emulateHTTP: true,
|
||||
emulateJSON: true
|
||||
});
|
||||
equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
equal(this.ajaxSettings.type, 'POST');
|
||||
equal(JSON.stringify(this.ajaxSettings.data), '{"_method":"DELETE"}');
|
||||
assert.equal(this.ajaxSettings.url, '/library/2-the-tempest');
|
||||
assert.equal(this.ajaxSettings.type, 'POST');
|
||||
assert.equal(JSON.stringify(this.ajaxSettings.data), '{"_method":"DELETE"}');
|
||||
});
|
||||
|
||||
test("urlError", 2, function() {
|
||||
QUnit.test('urlError', function(assert) {
|
||||
assert.expect(2);
|
||||
var model = new Backbone.Model();
|
||||
throws(function() {
|
||||
assert.raises(function() {
|
||||
model.fetch();
|
||||
});
|
||||
model.fetch({url: '/one/two'});
|
||||
equal(this.ajaxSettings.url, '/one/two');
|
||||
assert.equal(this.ajaxSettings.url, '/one/two');
|
||||
});
|
||||
|
||||
test("#1052 - `options` is optional.", 0, function() {
|
||||
QUnit.test('#1052 - `options` is optional.', function(assert) {
|
||||
assert.expect(0);
|
||||
var model = new Backbone.Model();
|
||||
model.url = '/test';
|
||||
Backbone.sync('create', model);
|
||||
});
|
||||
|
||||
test("Backbone.ajax", 1, function() {
|
||||
Backbone.ajax = function(settings){
|
||||
strictEqual(settings.url, '/test');
|
||||
QUnit.test('Backbone.ajax', function(assert) {
|
||||
assert.expect(1);
|
||||
Backbone.ajax = function(settings) {
|
||||
assert.strictEqual(settings.url, '/test');
|
||||
};
|
||||
var model = new Backbone.Model();
|
||||
model.url = '/test';
|
||||
Backbone.sync('create', model);
|
||||
});
|
||||
|
||||
test("Call provided error callback on error.", 1, function() {
|
||||
QUnit.test('Call provided error callback on error.', function(assert) {
|
||||
assert.expect(1);
|
||||
var model = new Backbone.Model;
|
||||
model.url = '/test';
|
||||
Backbone.sync('read', model, {
|
||||
error: function() { ok(true); }
|
||||
error: function() { assert.ok(true); }
|
||||
});
|
||||
this.ajaxSettings.error();
|
||||
});
|
||||
|
||||
test('Use Backbone.emulateHTTP as default.', 2, function() {
|
||||
QUnit.test('Use Backbone.emulateHTTP as default.', function(assert) {
|
||||
assert.expect(2);
|
||||
var model = new Backbone.Model;
|
||||
model.url = '/test';
|
||||
|
||||
Backbone.emulateHTTP = true;
|
||||
model.sync('create', model);
|
||||
strictEqual(this.ajaxSettings.emulateHTTP, true);
|
||||
assert.strictEqual(this.ajaxSettings.emulateHTTP, true);
|
||||
|
||||
Backbone.emulateHTTP = false;
|
||||
model.sync('create', model);
|
||||
strictEqual(this.ajaxSettings.emulateHTTP, false);
|
||||
assert.strictEqual(this.ajaxSettings.emulateHTTP, false);
|
||||
});
|
||||
|
||||
test('Use Backbone.emulateJSON as default.', 2, function() {
|
||||
QUnit.test('Use Backbone.emulateJSON as default.', function(assert) {
|
||||
assert.expect(2);
|
||||
var model = new Backbone.Model;
|
||||
model.url = '/test';
|
||||
|
||||
Backbone.emulateJSON = true;
|
||||
model.sync('create', model);
|
||||
strictEqual(this.ajaxSettings.emulateJSON, true);
|
||||
assert.strictEqual(this.ajaxSettings.emulateJSON, true);
|
||||
|
||||
Backbone.emulateJSON = false;
|
||||
model.sync('create', model);
|
||||
strictEqual(this.ajaxSettings.emulateJSON, false);
|
||||
assert.strictEqual(this.ajaxSettings.emulateJSON, false);
|
||||
});
|
||||
|
||||
test("#1756 - Call user provided beforeSend function.", 4, function() {
|
||||
QUnit.test('#1756 - Call user provided beforeSend function.', function(assert) {
|
||||
assert.expect(4);
|
||||
Backbone.emulateHTTP = true;
|
||||
var model = new Backbone.Model;
|
||||
model.url = '/test';
|
||||
var xhr = {
|
||||
setRequestHeader: function(header, value) {
|
||||
strictEqual(header, 'X-HTTP-Method-Override');
|
||||
strictEqual(value, 'DELETE');
|
||||
assert.strictEqual(header, 'X-HTTP-Method-Override');
|
||||
assert.strictEqual(value, 'DELETE');
|
||||
}
|
||||
};
|
||||
model.sync('delete', model, {
|
||||
beforeSend: function(_xhr) {
|
||||
ok(_xhr === xhr);
|
||||
assert.ok(_xhr === xhr);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
strictEqual(this.ajaxSettings.beforeSend(xhr), false);
|
||||
assert.strictEqual(this.ajaxSettings.beforeSend(xhr), false);
|
||||
});
|
||||
|
||||
test('#2928 - Pass along `textStatus` and `errorThrown`.', 2, function() {
|
||||
QUnit.test('#2928 - Pass along `textStatus` and `errorThrown`.', function(assert) {
|
||||
assert.expect(2);
|
||||
var model = new Backbone.Model;
|
||||
model.url = '/test';
|
||||
model.on('error', function(model, xhr, options) {
|
||||
strictEqual(options.textStatus, 'textStatus');
|
||||
strictEqual(options.errorThrown, 'errorThrown');
|
||||
model.on('error', function(m, xhr, options) {
|
||||
assert.strictEqual(options.textStatus, 'textStatus');
|
||||
assert.strictEqual(options.errorThrown, 'errorThrown');
|
||||
});
|
||||
model.fetch();
|
||||
this.ajaxSettings.error({}, 'textStatus', 'errorThrown');
|
||||
});
|
||||
|
||||
})();
|
||||
})(QUnit);
|
||||
|
||||
43
test/vendor/qunit.css
vendored
Executable file → Normal file
43
test/vendor/qunit.css
vendored
Executable file → Normal file
@@ -1,27 +1,27 @@
|
||||
/*!
|
||||
* QUnit 1.17.1
|
||||
* http://qunitjs.com/
|
||||
* QUnit 1.21.0
|
||||
* https://qunitjs.com/
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
* Released under the MIT license
|
||||
* http://jquery.org/license
|
||||
* https://jquery.org/license
|
||||
*
|
||||
* Date: 2015-01-20T19:39Z
|
||||
* Date: 2016-02-01T13:07Z
|
||||
*/
|
||||
|
||||
/** Font Family and Sizes */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult {
|
||||
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
||||
#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
||||
#qunit-tests { font-size: smaller; }
|
||||
|
||||
|
||||
/** Resets */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
@@ -68,6 +68,12 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#qunit-filteredTest {
|
||||
padding: 0.5em 1em 0.5em 1em;
|
||||
background-color: #F4FF77;
|
||||
color: #366097;
|
||||
}
|
||||
|
||||
#qunit-userAgent {
|
||||
padding: 0.5em 1em 0.5em 1em;
|
||||
background-color: #2B81AF;
|
||||
@@ -114,9 +120,19 @@
|
||||
display: list-item;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass li.running,
|
||||
#qunit-tests.hidepass li.pass {
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#qunit-tests li strong {
|
||||
@@ -132,6 +148,11 @@
|
||||
color: #C2CCD1;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests li p a {
|
||||
padding: 0.25em;
|
||||
color: #6B6464;
|
||||
}
|
||||
#qunit-tests li a:hover,
|
||||
#qunit-tests li a:focus {
|
||||
color: #000;
|
||||
@@ -151,6 +172,10 @@
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.qunit-source {
|
||||
margin: 0.6em 0 0.3em;
|
||||
}
|
||||
|
||||
.qunit-collapsed {
|
||||
display: none;
|
||||
}
|
||||
@@ -277,4 +302,4 @@
|
||||
left: -10000px;
|
||||
width: 1000px;
|
||||
height: 1000px;
|
||||
}
|
||||
}
|
||||
|
||||
3298
test/vendor/qunit.js
vendored
Executable file → Normal file
3298
test/vendor/qunit.js
vendored
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
747
test/vendor/underscore.js
vendored
747
test/vendor/underscore.js
vendored
File diff suppressed because it is too large
Load Diff
463
test/view.js
463
test/view.js
@@ -1,91 +1,137 @@
|
||||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var view;
|
||||
|
||||
module("Backbone.View", {
|
||||
QUnit.module('Backbone.View', {
|
||||
|
||||
beforeEach: function() {
|
||||
$('#qunit-fixture').append(
|
||||
'<div id="testElement"><h1>Test</h1></div>'
|
||||
);
|
||||
|
||||
setup: function() {
|
||||
view = new Backbone.View({
|
||||
id : 'test-view',
|
||||
className : 'test-view',
|
||||
other : 'non-special-option'
|
||||
id: 'test-view',
|
||||
className: 'test-view',
|
||||
other: 'non-special-option'
|
||||
});
|
||||
},
|
||||
|
||||
afterEach: function() {
|
||||
$('#testElement').remove();
|
||||
$('#test-view').remove();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
test("constructor", 3, function() {
|
||||
equal(view.el.id, 'test-view');
|
||||
equal(view.el.className, 'test-view');
|
||||
equal(view.el.other, void 0);
|
||||
QUnit.test('constructor', function(assert) {
|
||||
assert.expect(3);
|
||||
assert.equal(view.el.id, 'test-view');
|
||||
assert.equal(view.el.className, 'test-view');
|
||||
assert.equal(view.el.other, void 0);
|
||||
});
|
||||
|
||||
test("$", 2, function() {
|
||||
var view = new Backbone.View;
|
||||
view.setElement('<p><a><b>test</b></a></p>');
|
||||
var result = view.$('a b');
|
||||
QUnit.test('$', function(assert) {
|
||||
assert.expect(2);
|
||||
var myView = new Backbone.View;
|
||||
myView.setElement('<p><a><b>test</b></a></p>');
|
||||
var result = myView.$('a b');
|
||||
|
||||
strictEqual(result[0].innerHTML, 'test');
|
||||
ok(result.length === +result.length);
|
||||
assert.strictEqual(result[0].innerHTML, 'test');
|
||||
assert.ok(result.length === +result.length);
|
||||
});
|
||||
|
||||
test("$el", 3, function() {
|
||||
var view = new Backbone.View;
|
||||
view.setElement('<p><a><b>test</b></a></p>');
|
||||
strictEqual(view.el.nodeType, 1);
|
||||
QUnit.test('$el', function(assert) {
|
||||
assert.expect(3);
|
||||
var myView = new Backbone.View;
|
||||
myView.setElement('<p><a><b>test</b></a></p>');
|
||||
assert.strictEqual(myView.el.nodeType, 1);
|
||||
|
||||
ok(view.$el instanceof Backbone.$);
|
||||
strictEqual(view.$el[0], view.el);
|
||||
assert.ok(myView.$el instanceof Backbone.$);
|
||||
assert.strictEqual(myView.$el[0], myView.el);
|
||||
});
|
||||
|
||||
test("initialize", 1, function() {
|
||||
QUnit.test('initialize', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.one = 1;
|
||||
}
|
||||
});
|
||||
|
||||
strictEqual(new View().one, 1);
|
||||
assert.strictEqual(new View().one, 1);
|
||||
});
|
||||
|
||||
test("delegateEvents", 6, function() {
|
||||
QUnit.test('preinitialize', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
preinitialize: function() {
|
||||
this.one = 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(new View().one, 1);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize occurs before the view is set up', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
preinitialize: function() {
|
||||
assert.equal(this.el, undefined);
|
||||
}
|
||||
});
|
||||
var _view = new View({});
|
||||
assert.notEqual(_view.el, undefined);
|
||||
});
|
||||
|
||||
QUnit.test('render', function(assert) {
|
||||
assert.expect(1);
|
||||
var myView = new Backbone.View;
|
||||
assert.equal(myView.render(), myView, '#render returns the view instance');
|
||||
});
|
||||
|
||||
QUnit.test('delegateEvents', function(assert) {
|
||||
assert.expect(6);
|
||||
var counter1 = 0, counter2 = 0;
|
||||
|
||||
var view = new Backbone.View({el: '#testElement'});
|
||||
view.increment = function(){ counter1++; };
|
||||
view.$el.on('click', function(){ counter2++; });
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.increment = function() { counter1++; };
|
||||
myView.$el.on('click', function() { counter2++; });
|
||||
|
||||
var events = {'click h1': 'increment'};
|
||||
|
||||
view.delegateEvents(events);
|
||||
view.$('h1').trigger('click');
|
||||
equal(counter1, 1);
|
||||
equal(counter2, 1);
|
||||
myView.delegateEvents(events);
|
||||
myView.$('h1').trigger('click');
|
||||
assert.equal(counter1, 1);
|
||||
assert.equal(counter2, 1);
|
||||
|
||||
view.$('h1').trigger('click');
|
||||
equal(counter1, 2);
|
||||
equal(counter2, 2);
|
||||
myView.$('h1').trigger('click');
|
||||
assert.equal(counter1, 2);
|
||||
assert.equal(counter2, 2);
|
||||
|
||||
view.delegateEvents(events);
|
||||
view.$('h1').trigger('click');
|
||||
equal(counter1, 3);
|
||||
equal(counter2, 3);
|
||||
myView.delegateEvents(events);
|
||||
myView.$('h1').trigger('click');
|
||||
assert.equal(counter1, 3);
|
||||
assert.equal(counter2, 3);
|
||||
});
|
||||
|
||||
test("delegate", 2, function() {
|
||||
var view = new Backbone.View({el: '#testElement'});
|
||||
view.delegate('click', 'h1', function() {
|
||||
ok(true);
|
||||
QUnit.test('delegate', function(assert) {
|
||||
assert.expect(3);
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.delegate('click', 'h1', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
view.delegate('click', function() {
|
||||
ok(true);
|
||||
myView.delegate('click', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
view.$('h1').trigger('click');
|
||||
myView.$('h1').trigger('click');
|
||||
|
||||
assert.equal(myView.delegate(), myView, '#delegate returns the view instance');
|
||||
});
|
||||
|
||||
test("delegateEvents allows functions for callbacks", 3, function() {
|
||||
var view = new Backbone.View({el: '<p></p>'});
|
||||
view.counter = 0;
|
||||
QUnit.test('delegateEvents allows functions for callbacks', function(assert) {
|
||||
assert.expect(3);
|
||||
var myView = new Backbone.View({el: '<p></p>'});
|
||||
myView.counter = 0;
|
||||
|
||||
var events = {
|
||||
click: function() {
|
||||
@@ -93,133 +139,147 @@
|
||||
}
|
||||
};
|
||||
|
||||
view.delegateEvents(events);
|
||||
view.$el.trigger('click');
|
||||
equal(view.counter, 1);
|
||||
myView.delegateEvents(events);
|
||||
myView.$el.trigger('click');
|
||||
assert.equal(myView.counter, 1);
|
||||
|
||||
view.$el.trigger('click');
|
||||
equal(view.counter, 2);
|
||||
myView.$el.trigger('click');
|
||||
assert.equal(myView.counter, 2);
|
||||
|
||||
view.delegateEvents(events);
|
||||
view.$el.trigger('click');
|
||||
equal(view.counter, 3);
|
||||
myView.delegateEvents(events);
|
||||
myView.$el.trigger('click');
|
||||
assert.equal(myView.counter, 3);
|
||||
});
|
||||
|
||||
|
||||
test("delegateEvents ignore undefined methods", 0, function() {
|
||||
var view = new Backbone.View({el: '<p></p>'});
|
||||
view.delegateEvents({'click': 'undefinedMethod'});
|
||||
view.$el.trigger('click');
|
||||
QUnit.test('delegateEvents ignore undefined methods', function(assert) {
|
||||
assert.expect(0);
|
||||
var myView = new Backbone.View({el: '<p></p>'});
|
||||
myView.delegateEvents({click: 'undefinedMethod'});
|
||||
myView.$el.trigger('click');
|
||||
});
|
||||
|
||||
test("undelegateEvents", 6, function() {
|
||||
QUnit.test('undelegateEvents', function(assert) {
|
||||
assert.expect(7);
|
||||
var counter1 = 0, counter2 = 0;
|
||||
|
||||
var view = new Backbone.View({el: '#testElement'});
|
||||
view.increment = function(){ counter1++; };
|
||||
view.$el.on('click', function(){ counter2++; });
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.increment = function() { counter1++; };
|
||||
myView.$el.on('click', function() { counter2++; });
|
||||
|
||||
var events = {'click h1': 'increment'};
|
||||
|
||||
view.delegateEvents(events);
|
||||
view.$('h1').trigger('click');
|
||||
equal(counter1, 1);
|
||||
equal(counter2, 1);
|
||||
myView.delegateEvents(events);
|
||||
myView.$('h1').trigger('click');
|
||||
assert.equal(counter1, 1);
|
||||
assert.equal(counter2, 1);
|
||||
|
||||
view.undelegateEvents();
|
||||
view.$('h1').trigger('click');
|
||||
equal(counter1, 1);
|
||||
equal(counter2, 2);
|
||||
myView.undelegateEvents();
|
||||
myView.$('h1').trigger('click');
|
||||
assert.equal(counter1, 1);
|
||||
assert.equal(counter2, 2);
|
||||
|
||||
view.delegateEvents(events);
|
||||
view.$('h1').trigger('click');
|
||||
equal(counter1, 2);
|
||||
equal(counter2, 3);
|
||||
myView.delegateEvents(events);
|
||||
myView.$('h1').trigger('click');
|
||||
assert.equal(counter1, 2);
|
||||
assert.equal(counter2, 3);
|
||||
|
||||
assert.equal(myView.undelegateEvents(), myView, '#undelegateEvents returns the view instance');
|
||||
});
|
||||
|
||||
test("undelegate", 0, function() {
|
||||
view = new Backbone.View({el: '#testElement'});
|
||||
view.delegate('click', function() { ok(false); });
|
||||
view.delegate('click', 'h1', function() { ok(false); });
|
||||
QUnit.test('undelegate', function(assert) {
|
||||
assert.expect(1);
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.delegate('click', function() { assert.ok(false); });
|
||||
myView.delegate('click', 'h1', function() { assert.ok(false); });
|
||||
|
||||
view.undelegate('click');
|
||||
myView.undelegate('click');
|
||||
|
||||
view.$('h1').trigger('click');
|
||||
view.$el.trigger('click');
|
||||
myView.$('h1').trigger('click');
|
||||
myView.$el.trigger('click');
|
||||
|
||||
assert.equal(myView.undelegate(), myView, '#undelegate returns the view instance');
|
||||
});
|
||||
|
||||
test("undelegate with passed handler", 1, function() {
|
||||
view = new Backbone.View({el: '#testElement'});
|
||||
var listener = function() { ok(false); };
|
||||
view.delegate('click', listener);
|
||||
view.delegate('click', function() { ok(true); });
|
||||
view.undelegate('click', listener);
|
||||
view.$el.trigger('click');
|
||||
QUnit.test('undelegate with passed handler', function(assert) {
|
||||
assert.expect(1);
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
var listener = function() { assert.ok(false); };
|
||||
myView.delegate('click', listener);
|
||||
myView.delegate('click', function() { assert.ok(true); });
|
||||
myView.undelegate('click', listener);
|
||||
myView.$el.trigger('click');
|
||||
});
|
||||
|
||||
test("undelegate with selector", 2, function() {
|
||||
view = new Backbone.View({el: '#testElement'});
|
||||
view.delegate('click', function() { ok(true); });
|
||||
view.delegate('click', 'h1', function() { ok(false); });
|
||||
view.undelegate('click', 'h1');
|
||||
view.$('h1').trigger('click');
|
||||
view.$el.trigger('click');
|
||||
QUnit.test('undelegate with selector', function(assert) {
|
||||
assert.expect(2);
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.delegate('click', function() { assert.ok(true); });
|
||||
myView.delegate('click', 'h1', function() { assert.ok(false); });
|
||||
myView.undelegate('click', 'h1');
|
||||
myView.$('h1').trigger('click');
|
||||
myView.$el.trigger('click');
|
||||
});
|
||||
|
||||
test("undelegate with handler and selector", 2, function() {
|
||||
view = new Backbone.View({el: '#testElement'});
|
||||
view.delegate('click', function() { ok(true); });
|
||||
var handler = function(){ ok(false); };
|
||||
view.delegate('click', 'h1', handler);
|
||||
view.undelegate('click', 'h1', handler);
|
||||
view.$('h1').trigger('click');
|
||||
view.$el.trigger('click');
|
||||
QUnit.test('undelegate with handler and selector', function(assert) {
|
||||
assert.expect(2);
|
||||
var myView = new Backbone.View({el: '#testElement'});
|
||||
myView.delegate('click', function() { assert.ok(true); });
|
||||
var handler = function() { assert.ok(false); };
|
||||
myView.delegate('click', 'h1', handler);
|
||||
myView.undelegate('click', 'h1', handler);
|
||||
myView.$('h1').trigger('click');
|
||||
myView.$el.trigger('click');
|
||||
});
|
||||
|
||||
test("tagName can be provided as a string", 1, function() {
|
||||
QUnit.test('tagName can be provided as a string', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
tagName: 'span'
|
||||
});
|
||||
|
||||
equal(new View().el.tagName, 'SPAN');
|
||||
assert.equal(new View().el.tagName, 'SPAN');
|
||||
});
|
||||
|
||||
test("tagName can be provided as a function", 1, function() {
|
||||
QUnit.test('tagName can be provided as a function', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
tagName: function() {
|
||||
return 'p';
|
||||
}
|
||||
});
|
||||
|
||||
ok(new View().$el.is('p'));
|
||||
assert.ok(new View().$el.is('p'));
|
||||
});
|
||||
|
||||
test("_ensureElement with DOM node el", 1, function() {
|
||||
QUnit.test('_ensureElement with DOM node el', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
el: document.body
|
||||
});
|
||||
|
||||
equal(new View().el, document.body);
|
||||
assert.equal(new View().el, document.body);
|
||||
});
|
||||
|
||||
test("_ensureElement with string el", 3, function() {
|
||||
QUnit.test('_ensureElement with string el', function(assert) {
|
||||
assert.expect(3);
|
||||
var View = Backbone.View.extend({
|
||||
el: "body"
|
||||
el: 'body'
|
||||
});
|
||||
strictEqual(new View().el, document.body);
|
||||
assert.strictEqual(new View().el, document.body);
|
||||
|
||||
View = Backbone.View.extend({
|
||||
el: "#testElement > h1"
|
||||
el: '#testElement > h1'
|
||||
});
|
||||
strictEqual(new View().el, $("#testElement > h1").get(0));
|
||||
assert.strictEqual(new View().el, $('#testElement > h1').get(0));
|
||||
|
||||
View = Backbone.View.extend({
|
||||
el: "#nonexistent"
|
||||
el: '#nonexistent'
|
||||
});
|
||||
ok(!new View().el);
|
||||
assert.ok(!new View().el);
|
||||
});
|
||||
|
||||
test("with className and id functions", 2, function() {
|
||||
QUnit.test('with className and id functions', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
className: function() {
|
||||
return 'className';
|
||||
@@ -229,33 +289,54 @@
|
||||
}
|
||||
});
|
||||
|
||||
strictEqual(new View().el.className, 'className');
|
||||
strictEqual(new View().el.id, 'id');
|
||||
assert.strictEqual(new View().el.className, 'className');
|
||||
assert.strictEqual(new View().el.id, 'id');
|
||||
});
|
||||
|
||||
test("with attributes", 2, function() {
|
||||
QUnit.test('with attributes', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
attributes: {
|
||||
id: 'id',
|
||||
'id': 'id',
|
||||
'class': 'class'
|
||||
}
|
||||
});
|
||||
|
||||
strictEqual(new View().el.className, 'class');
|
||||
strictEqual(new View().el.id, 'id');
|
||||
assert.strictEqual(new View().el.className, 'class');
|
||||
assert.strictEqual(new View().el.id, 'id');
|
||||
});
|
||||
|
||||
test("with attributes as a function", 1, function() {
|
||||
QUnit.test('with attributes as a function', function(assert) {
|
||||
assert.expect(1);
|
||||
var View = Backbone.View.extend({
|
||||
attributes: function() {
|
||||
return {'class': 'dynamic'};
|
||||
}
|
||||
});
|
||||
|
||||
strictEqual(new View().el.className, 'dynamic');
|
||||
assert.strictEqual(new View().el.className, 'dynamic');
|
||||
});
|
||||
|
||||
test("multiple views per element", 3, function() {
|
||||
QUnit.test('should default to className/id properties', function(assert) {
|
||||
assert.expect(4);
|
||||
var View = Backbone.View.extend({
|
||||
className: 'backboneClass',
|
||||
id: 'backboneId',
|
||||
attributes: {
|
||||
'class': 'attributeClass',
|
||||
'id': 'attributeId'
|
||||
}
|
||||
});
|
||||
|
||||
var myView = new View;
|
||||
assert.strictEqual(myView.el.className, 'backboneClass');
|
||||
assert.strictEqual(myView.el.id, 'backboneId');
|
||||
assert.strictEqual(myView.$el.attr('class'), 'backboneClass');
|
||||
assert.strictEqual(myView.$el.attr('id'), 'backboneId');
|
||||
});
|
||||
|
||||
QUnit.test('multiple views per element', function(assert) {
|
||||
assert.expect(3);
|
||||
var count = 0;
|
||||
var $el = $('<p></p>');
|
||||
|
||||
@@ -269,105 +350,112 @@
|
||||
});
|
||||
|
||||
var view1 = new View;
|
||||
$el.trigger("click");
|
||||
equal(1, count);
|
||||
$el.trigger('click');
|
||||
assert.equal(1, count);
|
||||
|
||||
var view2 = new View;
|
||||
$el.trigger("click");
|
||||
equal(3, count);
|
||||
$el.trigger('click');
|
||||
assert.equal(3, count);
|
||||
|
||||
view1.delegateEvents();
|
||||
$el.trigger("click");
|
||||
equal(5, count);
|
||||
$el.trigger('click');
|
||||
assert.equal(5, count);
|
||||
});
|
||||
|
||||
test("custom events", 2, function() {
|
||||
QUnit.test('custom events', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
el: $('body'),
|
||||
events: {
|
||||
"fake$event": function() { ok(true); }
|
||||
fake$event: function() { assert.ok(true); }
|
||||
}
|
||||
});
|
||||
|
||||
var view = new View;
|
||||
var myView = new View;
|
||||
$('body').trigger('fake$event').trigger('fake$event');
|
||||
|
||||
$('body').off('fake$event');
|
||||
$('body').trigger('fake$event');
|
||||
});
|
||||
|
||||
test("#1048 - setElement uses provided object.", 2, function() {
|
||||
QUnit.test('#1048 - setElement uses provided object.', function(assert) {
|
||||
assert.expect(2);
|
||||
var $el = $('body');
|
||||
|
||||
var view = new Backbone.View({el: $el});
|
||||
ok(view.$el === $el);
|
||||
var myView = new Backbone.View({el: $el});
|
||||
assert.ok(myView.$el === $el);
|
||||
|
||||
view.setElement($el = $($el));
|
||||
ok(view.$el === $el);
|
||||
myView.setElement($el = $($el));
|
||||
assert.ok(myView.$el === $el);
|
||||
});
|
||||
|
||||
test("#986 - Undelegate before changing element.", 1, function() {
|
||||
QUnit.test('#986 - Undelegate before changing element.', function(assert) {
|
||||
assert.expect(1);
|
||||
var button1 = $('<button></button>');
|
||||
var button2 = $('<button></button>');
|
||||
|
||||
var View = Backbone.View.extend({
|
||||
events: {
|
||||
click: function(e) {
|
||||
ok(view.el === e.target);
|
||||
assert.ok(myView.el === e.target);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var view = new View({el: button1});
|
||||
view.setElement(button2);
|
||||
var myView = new View({el: button1});
|
||||
myView.setElement(button2);
|
||||
|
||||
button1.trigger('click');
|
||||
button2.trigger('click');
|
||||
});
|
||||
|
||||
test("#1172 - Clone attributes object", 2, function() {
|
||||
QUnit.test('#1172 - Clone attributes object', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
attributes: {foo: 'bar'}
|
||||
});
|
||||
|
||||
var view1 = new View({id: 'foo'});
|
||||
strictEqual(view1.el.id, 'foo');
|
||||
assert.strictEqual(view1.el.id, 'foo');
|
||||
|
||||
var view2 = new View();
|
||||
ok(!view2.el.id);
|
||||
assert.ok(!view2.el.id);
|
||||
});
|
||||
|
||||
test("views stopListening", 0, function() {
|
||||
QUnit.test('views stopListening', function(assert) {
|
||||
assert.expect(0);
|
||||
var View = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, 'all x', function(){ ok(false); });
|
||||
this.listenTo(this.collection, 'all x', function(){ ok(false); });
|
||||
this.listenTo(this.model, 'all x', function() { assert.ok(false); });
|
||||
this.listenTo(this.collection, 'all x', function() { assert.ok(false); });
|
||||
}
|
||||
});
|
||||
|
||||
var view = new View({
|
||||
var myView = new View({
|
||||
model: new Backbone.Model,
|
||||
collection: new Backbone.Collection
|
||||
});
|
||||
|
||||
view.stopListening();
|
||||
view.model.trigger('x');
|
||||
view.collection.trigger('x');
|
||||
myView.stopListening();
|
||||
myView.model.trigger('x');
|
||||
myView.collection.trigger('x');
|
||||
});
|
||||
|
||||
test("Provide function for el.", 2, function() {
|
||||
QUnit.test('Provide function for el.', function(assert) {
|
||||
assert.expect(2);
|
||||
var View = Backbone.View.extend({
|
||||
el: function() {
|
||||
return "<p><a></a></p>";
|
||||
return '<p><a></a></p>';
|
||||
}
|
||||
});
|
||||
|
||||
var view = new View;
|
||||
ok(view.$el.is('p'));
|
||||
ok(view.$el.has('a'));
|
||||
var myView = new View;
|
||||
assert.ok(myView.$el.is('p'));
|
||||
assert.ok(myView.$el.has('a'));
|
||||
});
|
||||
|
||||
test("events passed in options", 1, function() {
|
||||
QUnit.test('events passed in options', function(assert) {
|
||||
assert.expect(1);
|
||||
var counter = 0;
|
||||
|
||||
var View = Backbone.View.extend({
|
||||
@@ -377,29 +465,52 @@
|
||||
}
|
||||
});
|
||||
|
||||
var view = new View({
|
||||
var myView = new View({
|
||||
events: {
|
||||
'click h1': 'increment'
|
||||
}
|
||||
});
|
||||
|
||||
view.$('h1').trigger('click').trigger('click');
|
||||
equal(counter, 2);
|
||||
myView.$('h1').trigger('click').trigger('click');
|
||||
assert.equal(counter, 2);
|
||||
});
|
||||
|
||||
test("remove", 1, function() {
|
||||
var view = new Backbone.View;
|
||||
QUnit.test('remove', function(assert) {
|
||||
assert.expect(2);
|
||||
var myView = new Backbone.View;
|
||||
document.body.appendChild(view.el);
|
||||
|
||||
view.delegate('click', function() { ok(false); });
|
||||
view.listenTo(view, 'all x', function() { ok(false); });
|
||||
myView.delegate('click', function() { assert.ok(false); });
|
||||
myView.listenTo(myView, 'all x', function() { assert.ok(false); });
|
||||
|
||||
view.remove();
|
||||
view.$el.trigger('click');
|
||||
view.trigger('x');
|
||||
assert.equal(myView.remove(), myView, '#remove returns the view instance');
|
||||
myView.$el.trigger('click');
|
||||
myView.trigger('x');
|
||||
|
||||
// In IE8 and below, parentNode still exists but is not document.body.
|
||||
notEqual(view.el.parentNode, document.body);
|
||||
assert.notEqual(myView.el.parentNode, document.body);
|
||||
});
|
||||
|
||||
})();
|
||||
QUnit.test('setElement', function(assert) {
|
||||
assert.expect(3);
|
||||
var myView = new Backbone.View({
|
||||
events: {
|
||||
click: function() { assert.ok(false); }
|
||||
}
|
||||
});
|
||||
myView.events = {
|
||||
click: function() { assert.ok(true); }
|
||||
};
|
||||
var oldEl = myView.el;
|
||||
var $oldEl = myView.$el;
|
||||
|
||||
myView.setElement(document.createElement('div'));
|
||||
|
||||
$oldEl.click();
|
||||
myView.$el.click();
|
||||
|
||||
assert.notEqual(oldEl, myView.el);
|
||||
assert.notEqual($oldEl, myView.$el);
|
||||
});
|
||||
|
||||
})(QUnit);
|
||||
|
||||
Reference in New Issue
Block a user