Compare commits

...
683 Commits
Author SHA1 Message Date
Tim Branyen 2da330561c No longer maintained 2018-07-31 17:43:16 -07:00
Tim Branyen 5ae3117659 Bump to version 1.0.0 2016-03-01 08:27:54 -08:00
Tim Branyen b4a6a429e7 Merge pull request #490 from Cleod9/backbone-1-2-0-support
Support for Backbone 1.2.0
2016-01-22 11:10:47 -08:00
Greg McLeod e1ddfdec1d -Returned readme to previous state 2016-01-22 00:57:59 -05:00
Greg McLeod 8b6da4e9ee -Updated readme with cheerio hook info (+1 squashed commits)
Squashed commits:

[773cdd3] -Updated to Backbone 1.2.0 dependency
-Fixed Node unit tests by providing a special _createElement View hook for cheerio
2016-01-20 23:08:59 -05:00
Tim Branyen a4c6184a57 Merge pull request #488 from liseki/raf-support-fix
Fix support for Request Animation Frame
2015-12-09 17:18:15 -08:00
Richard Manyanza 0744983c5b Fix support for Request Animation Frame 2015-12-08 13:54:16 +03:00
Tim Branyen e7bb750482 QUnit start does not take resolution objects
This commit ensures that QUnit's `start` is always called with no
arguments.
2015-11-09 10:28:50 -08:00
Tim Branyen 0e11e42f44 Version bump to 0.10.0 2015-11-09 10:16:31 -08:00
Tim Branyen b811797b6f Merge pull request #484 from SimenB/promise
Ensure compatibility with promise-spec
2015-09-03 14:07:44 -05:00
Simen Bekkhus aa6c3cab49 Ensure compatibility with promise-spec
Fix #483
2015-08-31 22:13:52 +02:00
Tim Branyen 2b2f66899d Reverted the qunit-istanbul package for Grunt 2015-06-21 11:25:12 -04:00
Tim Branyen ffe7afb738 Lock backwards breaking Backbone, bump sane pkgs 2015-06-21 11:09:55 -04:00
Tim Branyen cf6e007056 Add README.md and LICENSE files to package.json 2015-06-01 16:16:17 -04:00
Tim Branyen beb102cca5 Merge remote-tracking branch 'SimenB/files' 2015-06-01 16:00:48 -04:00
Tim Branyen 2c1b0d6985 Version bump to 0.9.7 2015-05-01 16:55:43 -04:00
Tim Branyen 8f03a152bc Merge pull request #478 from seanparmelee/lodash3
fix removeView for lodash 3
2015-05-01 14:07:37 -04:00
Sean Parmelee fc719cc110 run all the views tests with both underscore and lodash 2015-04-26 00:31:33 -05:00
Sean Parmelee 22fefbe149 might be useful to have these tests 2015-04-21 23:06:47 -05:00
Sean Parmelee 65b67d335c it might help if i add lodash back to package.json 2015-04-21 22:05:23 -05:00
Sean Parmelee 921cde96ed turns out we can just call .value() instead of .commit() 2015-04-21 21:50:53 -05:00
Sean Parmelee 4f21d616e1 demonstrate testing w/ lodash instead of underscore 2015-04-21 21:27:35 -05:00
Sean Parmelee 65ac129305 add some whitespace to hopefully get the build running again 2015-04-21 12:37:09 -05:00
Sean Parmelee f8e65fe938 fix removeView for lodash 3 2015-04-21 10:43:04 -05:00
Simen Bekkhus ba32956bd1 Use files in package.json 2015-04-18 20:44:24 +02:00
Tim Branyen d01217658d Merge pull request #474 from SimenB/update-travis
Update travis
2015-04-18 14:02:10 -04:00
Simen Bekkhus 10eef18238 Submit Coverage to coveralls 2015-04-18 19:44:19 +02:00
Simen Bekkhus 19bc78dc51 Build on Node 0.12 and Io.js
Don't build on unstable 0.11
2015-04-18 19:30:45 +02:00
Tim Branyen 34d82e4027 Merge pull request #476 from SimenB/remove-bower-dep
Remove dependency on bower for tests
2015-04-18 13:23:25 -04:00
Simen Bekkhus cb6d7c346c Remove dependency on bower for tests 2015-04-18 19:01:07 +02:00
Tim Branyen c4233d3ce6 Merge pull request #473 from SimenB/badges
Add npm badge
2015-04-18 11:40:37 -04:00
Simen Bekkhus 606f3fff45 Npm badge
Also use badges from shields.io
2015-04-18 17:33:22 +02:00
Tim Branyen b35256ac11 Merge pull request #475 from SimenB/update-jscs
Update JSCS
2015-04-18 11:31:35 -04:00
Simen Bekkhus 41388efd14 Update JSCS 2015-04-18 12:08:41 +02:00
Tim Branyen 37aa2445cb Merge pull request #471 from tbranyen/prevent-render
Prevent rendering in `beforeRender`
2015-04-08 11:28:06 -04:00
Tim 09ccd1a267 Allow returning a falsy value or reject Promise
To prevent rendering of a View.  This can surpress jank as well in an
application when changing between views that re-render on async changes.
The problem this fixes is when you render and then wait on async data to
re-render the View.  There will be a momentary flicker unless you
prevent it.
2015-04-08 11:15:31 -04:00
Tim Branyen 070d054f8e Fixes to ensure tests run and are styled 2015-04-08 11:14:49 -04:00
Tim Branyen d76889c46f Merge pull request #470 from jugglinmike/update-cheerio
Update dependency on Cheerio
2015-03-28 20:30:52 -04:00
Mike Pennisi 69eb380110 Update dependency on Cheerio
Recent releases of the Cheerio library included a regression that
triggered test failures in this project. The latest release of Cheerio
addresses that regression.
2015-03-28 19:55:37 -04:00
Tim Branyen 178a7acc2d Merge pull request #469 from benbria/master
Specify jquery as a peer dependency.
2015-02-23 19:53:23 -05:00
Jason Walton b10c8bede8 Add jquery as a dev dependency. 2015-02-23 19:45:37 -05:00
Jason Walton 201df6fb02 Specify jquery as a peer dependency. 2015-02-23 16:56:51 -05:00
Tim Branyen 74afc0e04d Merge pull request #468 from jugglinmike/remove-undocumented-usage
Use documented jQuery API
2015-02-22 15:57:06 -05:00
Mike Pennisi dcd41101ff Use documented jQuery API
Passing a string to the `$.fn.html` method works in the latest version
of the jQuery library, but this signature is neither documented [1] nor
tested [2]. This code does not work with the latest version of the
Cheerio library, and because it is non-standard, it is unlikely to be
implemented in a future version.

Use `$.fn.empty` and `$.fn.append` to implement the desired behavior in
a way that is compatable with Cheerio and unlikely to be removed in a
future release of jQuery.

[1] http://api.jquery.com/html/
[2] https://github.com/jquery/jquery/blob/2380028ec4a6a77401b867a51de26a3cb8e8d311/test/unit/manipulation.js
2015-02-19 19:14:49 -05:00
Tim Branyen a7b012f314 Removes Bower devdeps in favor of NPM
Bower does not handle development dependencies well.
2015-02-18 19:29:54 -05:00
Tim Branyen 50af7e8dae Merge pull request #461 from jhoegee/master
Added the cleanup event
2015-02-11 15:07:43 -06:00
Tim Branyen 4035435bdf Better visibility for Gitter 2015-02-11 16:05:41 -05:00
Tim Branyen 80982b7e42 Version bump to 0.9.6. 2015-02-11 16:01:18 -05:00
Tim Branyen f87bf1b3d9 Upgraded all dependencies that do not cause regressions 2015-02-11 15:46:49 -05:00
jhoegee 021d7f09e5 fixed missing semicolon
fixed missing semicolon
2015-02-06 10:19:20 +01:00
jhoegee 9371c0cfd1 Fixed the empty lines
Fixed the empty lines
2015-02-03 14:18:10 +01:00
Tim Branyen 03ee056063 Replace gemnasium badge with Gitter 2014-12-18 11:46:35 -05:00
jhoegee 879cf05d56 Added the cleanup event
I've added the cleanup event with the corresponding qunit test
2014-11-25 16:36:36 +01:00
Tim Branyen cd0b268529 Merge pull request #454 from gjlubbertsen/master
Raise an event when all views in a given selector are closed
2014-11-10 10:07:17 -05:00
Gerrit-Jan Lubbertsen 410a08201b Rename the event + minor formatting changes 2014-08-29 20:55:36 +02:00
Gerrit-Jan Lubbertsen c8c8d4f74a Fixed code style issues to match the guide 2014-08-29 15:45:50 +02:00
Gerrit-Jan Lubbertsen a9b611ddcb Fixed code style issues to match the guide
https://github.com/tbranyen/backbone.layoutmanager/blob/master/CONTRIBUTING.md#code-style
2014-08-29 14:48:00 +02:00
Gerrit-Jan Lubbertsen 0588d53248 Update test names and include link to issue 2014-08-29 11:22:25 +02:00
Gerrit-Jan Lubbertsen ef1a20a479 Raise an event when all views in a given selector are closed #453 2014-08-29 11:12:50 +02:00
Mike Pennisi 3a43fd24e4 Remove trailing whitespace 2014-07-23 19:32:09 -04:00
Tim Branyen 02c90c59f9 Merge pull request #447 from STRML/removedViewRenderFix
Fix #445, where a removed view could still render asynchronously.
2014-06-18 20:04:17 -04:00
Tim Branyen dbdda9efaf Merge pull request #449 from danwashusen/master
Improved the renderViews method by allowing it to render only some of the children views.
2014-06-18 20:04:01 -04:00
dan 137a014fdf Fixed code style issues introduced by improvements to renderViews method (issue #449). 2014-06-19 10:00:07 +10:00
dan fdc90557c1 Added tests for renderViews changes. 2014-06-18 19:02:16 +10:00
dan ce18c48ef6 Improved the renderViews method by allowing it to take an array of views or the same arguments as getView to determine the child views to be rendered. This change allows for a subset of child views to be rendered offering a considerable performance benifit in some circumstances. 2014-06-18 18:38:30 +10:00
Tim Branyen 38f63450f5 Merge pull request #448 from STRML/cleanViewTests
Cleanup view test definitions to prevent repetition.
2014-06-16 12:59:40 -04:00
Samuel Reed 78c79dd810 Cleanup view test definitions to prevent repetition. 2014-06-12 11:32:51 -05:00
Samuel Reed 2ab33d10d8 Fix #445, where a removed view could still render asynchronously. 2014-06-12 11:18:18 -05:00
Tim Branyen c2aef302e7 Upgraded dependencies.
The only dependency that cannot be upgraded to its latest stable is
cheerio.
2014-06-10 23:18:35 -04:00
Tim Branyen e9a5b213e5 Merge pull request #421 from STRML/useRAF
Use `requestAnimationFrame` to coalesce renders and discard unneeded renders.
2014-06-10 11:05:31 -04:00
Tim Branyen 163d3f2076 Merge pull request #444 from gfranko/update-amd-support
Updated the conditional AMD define() wrapper
2014-06-10 11:05:13 -04:00
Greg Franko d4f82339c2 Updated the conditional AMD define() wrapper - Removed return statement that was causing issues for AMDclean users: https://github.com/gfranko/amdclean/issues/49 2014-06-09 22:39:53 -07:00
Tim Branyen 6654c20234 Updates to get tests passing.
- Cleaned source code to match JSCS.
- Removed broken link.
- Updated tests to remove no long relevant test.
2014-06-09 21:31:07 -04:00
Samuel Reed 4390c88744 Fix tests under nodejs. Add RAF/cancelRAF to options. 2014-06-09 21:08:29 -04:00
Samuel Reed 352a84a4b0 Clean a few unused lines in _registerWithRAF. 2014-06-09 21:08:29 -04:00
Samuel Reed 8ba6439ab9 Updated tests to work with previous useRAF commit.
Views tests are now run with and without RAF coalescing.
2014-06-09 21:08:29 -04:00
Samuel Reed 8b34da2553 Add useRAF option. Converted all expected use to async.
`useRAF` coalesces repeated renders using the tick of the browser's
native `requestAnimationFrame`, allowing us to safely discard render
work that would not be seen before the next frame.

This brings with it significant performance advantages, especially
in situations where views may be listening to events on collections,
such as 'add', and 'remove'. Rather than rerender for every event
thrown, renders that would not be seen are thrown out.

It is still safe to use `.then()` on the promise returned by a render,
as it will be resolved at the next tick of `requestAnimationFrame`,
regardless of whether or not it was the actual render call used.

This change requires that we assume every render to be async, and
removes the current ambiguity where renders are synchronous, unless
they contain a single async component. It is now required that
users treat each and every render as async, because it is guaranteed
to be.

This behavior may be turned off without consequence by setting
`"useRAF": false` inside LayoutManager.configure().
2014-06-09 21:07:10 -04:00
Samuel Reed e4edcca09a Add test jshintrc to suppress qunit globals & line length errors.
Update QUnit to latest (1.13.0).
2014-06-09 21:07:10 -04:00
Tim Branyen 688edda4db Merge pull request #442 from worldjoe/master
Fixing incompatibility with Epoxy
2014-06-09 20:07:51 -04:00
jelwell c7aa18be51 fixing build
fixing a jshint error
2014-06-09 16:41:36 -07:00
Tim Branyen 70a4c0a37d Merge pull request #440 from amithgeorge/master
Fix for Issue #439
2014-06-01 13:28:24 -04:00
Tim Branyen 6ebddea01e Remove Node 0.8 from tests.
More information here: https://github.com/bower/bower/issues/1315
2014-05-31 23:41:50 -04:00
jelwell f629a723d5 Fixing incompatibility with Epoxy
https://github.com/gmac/backbone.epoxy/issues/57
2014-05-29 15:42:54 -07:00
Amith George e8131dc766 updated dependencies to point to bower_components
also removed gitignore rule to exclude the vendor directory
2014-05-12 22:27:06 +05:30
Amith George beac00e65b excluding vendor directory from repo 2014-05-12 20:36:34 +05:30
Amith George 09b36389e8 Removed this.getAllOptions and this.options
Replaced them with the appropriate property on the view instance.
2014-05-12 20:22:22 +05:30
Tim Branyen 2d3976f524 Fixed annoying placement of loadNpmTasks. 2014-04-09 14:54:53 -04:00
Tim Branyen 1cb6fccc24 Merge pull request #438 from STRML/browserify
Added browserify test & build task, updated UMD definition.
2014-04-07 12:31:29 -04:00
Samuel Reed 6bb4035fb3 Added browserify test & build task, updated UMD definition. 2014-04-07 14:21:17 +08:00
Tim Branyen ca5a3edf03 Merge pull request #436 from tbranyen/browserify-support
Ensure LayoutManager works with Browserify.
2014-04-05 11:00:51 -04:00
Tim Branyen 3efdef50e9 Ensure LayoutManager works with Browserify.
- Updated JSHint to allow Node-isms.
- Patched the UMD to require the correct dependencies.
- Ensure that jQuery is installed in Node environments as an optional
  dependency.
2014-04-04 19:35:48 -04:00
Tim Branyen 2fe6114fcc Merge pull request #435 from jugglinmike/fix-remove-view
Fix bug in `setView`
2014-04-04 19:21:03 -04:00
Mike Pennisi e5daf4d111 Fix bug in setView
Only remove the previously-existing view if it differs from the new
view. This prevents the removal of deeply-nested views.
2014-04-04 18:21:54 -04:00
Tim Branyen 8fdfe690a8 Merge pull request #433 from ssafejava/jscs-update
Update jscs version.
2014-03-24 23:41:31 -04:00
ssafejava c9942d8425 Update jscs version.
Previous version had a peerDependency on grunt (0.4.2 exact) that was too strict,
causing errors when running npm install in this repo.
2014-03-25 11:30:27 +08:00
Tim Branyen e6a399699d Merge pull request #427 from jugglinmike/template-context
Set context of template method to layout instance
2014-03-07 13:53:03 -05:00
Tim Branyen 2e242e28ec Merge pull request #428 from jugglinmike/remove-coveralls
Remove Coveralls
2014-03-07 13:52:01 -05:00
Mike Pennisi 06a9f053cf Remove Coveralls
The Coveralls service regularly fails due to problems which are
unrelated to this project.
2014-03-07 13:44:53 -05:00
Mike Pennisi 1683952344 Set context of template method to layout instance 2014-03-07 13:02:32 -05:00
Tim Branyen a5f865d7a2 Merge pull request #425 from STRML/fixOptions
Ensure options object is cloned when used, instead of attached directly.
2014-03-06 19:39:03 -05:00
Samuel Reed 0f1214852e Ensure options object is cloned when used, instead of attached directly.
This prevents modifications on the passed-in options object from changing
options on the view.
2014-02-28 23:33:04 +08:00
Samuel Reed c4d0f8ee97 Merge pull request #426 from tbranyen/fix-jquery
Changed jQuery location to dist/.
2014-02-28 23:16:51 +08:00
Tim Branyen 7e068490fb Include specific jQuery version for development. 2014-02-28 08:03:56 -05:00
Tim Branyen 188d44d313 Changed jQuery location to dist/.
jQuery recently updated their deployment to contain src and dist
directories.  This patch allows future tests to pass.
2014-02-28 07:06:09 -05:00
Tim Branyen 40bb604810 Added in browser field to allow browserify to pick the correct version. 2014-02-12 14:58:59 -05:00
Tim Branyen d62ff85341 Version bump to 0.9.5. 2014-02-03 17:16:34 -05:00
Tim Branyen 85621f5edd Updated all packages and changed testing strategy.
- No longer install bower, coveralls, and grunt-cli via devDependencies.
- Use Travis-CI before_install to get them included.
2014-02-03 17:16:32 -05:00
Tim Branyen fcab4ae568 Remove .tern-project file. 2014-02-03 17:01:22 -05:00
Tim Branyen 92d39cf7c9 Updated .gitattributes to normalize line endings for Windows developers. 2014-01-29 23:23:09 -05:00
Tim Branyen 0d1e308799 Merge pull request #423 from tbranyen/enforce-style
Enforce code style with JSCS.
2014-01-29 20:12:34 -08:00
Tim Branyen e36ed18d4d Enforce code style with JSCS. 2014-01-29 23:03:56 -05:00
Tim Branyen 3a0f05948d Merge pull request #418 from tbranyen/broken-test-417
Broken test 417
2014-01-29 17:47:29 -08:00
Tim Branyen 5658c958cc Merge pull request #422 from tbranyen/break-out-grunt-configuration
Broke out Grunt configuration into build tasks.
2014-01-29 17:46:39 -08:00
Tim Branyen 05cb6c116d Broke out Grunt configuration into build tasks.
- Makes it easier to configure individual build tasks.
2014-01-29 20:34:54 -05:00
Tim Branyen 8467a1e4e5 Updated to latest cheerio. 2014-01-27 01:34:44 -05:00
Tim d258ce4452 Added in supplmental test to ensure correct functionality. 2014-01-05 23:08:12 -05:00
Tim 1a60576404 Removing the benchmark runner for now as it's distracting while developing. 2014-01-05 22:52:35 -05:00
Tim Branyen e706bf3db9 One potential fix is to remove the logic in setView to insert into a parent view without an accompanying render. 2013-12-18 20:52:37 -05:00
Tim Branyen 442d201244 Adds a reduced test for #417.
This violates the assumption that parents of rendered children have been
previously rendered.
2013-12-17 19:07:11 -05:00
Mike Pennisi 1d23f91ecd Run CI against Node v0.11 as an allowed failure
Building against the latest unstable release of Node.js should help the
project stay on top of any bugs or breaking changes in the platform.
Specifying that job as an allowed failure guarantees that errors do
not block ongoing work for officially-supported releases.
2013-12-14 15:01:46 -05:00
Mike Pennisi a8b4be8b7b Run TravisCI against Node.js v0.10
Ensure that each commit is vetted with the latest stable version of
Node.js.
2013-12-14 15:00:03 -05:00
Tim Branyen 45620c6819 Merge pull request #403 from ssafejava/removeOptions
Remove dependence on `getAllOptions()`. Remove most uses of `.options`.
2013-11-07 06:15:35 -08:00
Tim Branyen 70ef1d0fcb Restore options. 2013-11-07 09:13:17 -05:00
ssafejava a4d4648c41 Style 2013-11-07 14:12:54 +08:00
ssafejava 2803675461 Remove unnecessary clone. 2013-11-07 14:12:23 +08:00
ssafejava f161d52e9b Remove dependence on getAllOptions(). Remove most use of .options, as it was removed from latest Backbone.
LayoutManager default options (deferred, when, partial, etc.) are now defined on the LayoutManager prototype directly.
2013-11-06 16:42:58 +08:00
Tim Branyen f0c05b4156 Merge pull request #398 from tbranyen/remove-partial
Remove partial method from node compatibility file.
2013-10-25 15:44:11 -07:00
Tim Branyen 7925caaec8 Remove partial method from node compatibility file. 2013-10-25 14:49:38 -04:00
Tim Branyen 411cd5afc8 Tagging 0.9.4. 2013-10-25 12:07:16 -04:00
Tim Branyen 676b387e5d Merge pull request #397 from tbranyen/update-to-latest
Updated to the latest Backbone version 1.1.0.
2013-10-25 09:01:13 -07:00
Tim Branyen 5c8616615b Update version's in package manager configs. 2013-10-25 11:58:42 -04:00
Tim Branyen 0a747284e3 Updated to the latest Backbone version 1.1.0.
This update removes dependencies on the private method `_configure`.
Instead we override the `Backbone.View` completely.  This isn't ideal,
but it's the "Backbone-way".
2013-10-24 15:40:19 -04:00
Tim Branyen ebed0c1e85 Merge pull request #391 from ssafejava/applyTemplateTrim
Trim input on noel applyTemplate. (Fix #387)
2013-10-20 20:36:31 -07:00
Tim Branyen a97974edb5 Updated the package.json to reflect the correct supported version. 2013-10-20 23:34:31 -04:00
ssafejava 68d2bce1f8 Move template trimming to renderTemplate, cache trim function. 2013-10-21 09:10:30 +08:00
Tim Branyen bf1d1abc04 Merge pull request #393 from jonypawks/patch-1
Move qunit to a development dependency in bower.json
2013-10-15 15:43:25 -07:00
Jesse Printz d40e3c9e51 Moved qunit to a development dependency in bower.json
qunit isn't required to use layoutmanager, only to run the test suite during development.  Specifying it as a devDependency seems more accurate and will save people installing qunit when not developing layoutmanager.
2013-10-15 17:32:53 -05:00
ssafejava 7f245526bf Add test for #387. 2013-09-26 12:05:56 +08:00
ssafejava 2ed5d29965 Use String.trim() when available, fixes node tests. 2013-09-25 16:09:56 +08:00
ssafejava c032c68eeb Trim input on noel applyTemplate. (Fix #387) 2013-09-24 09:23:10 +08:00
Tim 8809ba9caf Version bump to 0.9.3. 2013-09-16 08:07:26 -04:00
Simon Boudrias 6220684150 Merge pull request #365 from SBoudrias/serialize
Default `serialize` implementation (Fix #358)
2013-09-09 11:59:00 -07:00
Simon Boudrias 295eac02e4 Default serialize implementation (Fix #358) 2013-09-09 14:50:31 -04:00
Tim Branyen bd40bcacba Merge pull request #384 from ssafejava/bowerTests
Fix #383. Refactored test suite to use bower_components so we catch thes...
2013-09-09 09:09:15 -07:00
ssafejava e91c6389c9 Remove DS_Store gitignore, add bower as devdependency 2013-09-09 11:00:56 +08:00
ssafejava e00b0a1025 Fix #383. Refactored test suite to use bower_components so we catch these errors by staying on top of dep updates.
QUnit update now throws errors upon improper use of asyncTest/start/stop, so I fixed those errors as well.

Removed test/vendor and test/qunit directory as they are no longer needed.

Added test/spec directory.
2013-09-09 10:31:46 +08:00
Tim Branyen 36fd68cb01 Merge pull request #380 from jugglinmike/parsehtml
Parse `noel` templates with $.parseHTML
2013-09-05 11:01:50 -07:00
Mike Pennisi 10549b0e31 Update dependency on "nodequnit" test
This latest version will ensure that the TravisCI build fails in
response to failures in the Node.js unit tests.
2013-09-05 12:54:17 -04:00
Mike Pennisi f940ba2ccb Parse noel templates with $.parseHTML
Because template strings are so often defined within `script` tags in
the document, they commonly contain leading and trailing whitespace.
The jQuery team advises sanitizing such strings using $.parseHTML`
*before* passing them to the jQuery function [1].

[1] http://blog.jquery.com/2013/05/24/jquery-1-10-0-and-2-0-1-released/
2013-09-05 12:54:17 -04:00
Tim Branyen e05dbc1eb2 Broke out more internal methods into exposed private prototype methods for now until a formal api is created. 2013-09-04 22:54:44 -04:00
Tim Branyen 55d3b7d327 Minor style improvements to the README. 2013-09-04 22:24:23 -04:00
Tim Branyen 9a609528f0 Restyled version in README. 2013-09-04 22:18:13 -04:00
Tim Branyen d5a4e15c18 Reduced header size. 2013-09-04 22:14:16 -04:00
Tim Branyen a17b05a557 Merge pull request #378 from dfarnsworth/master
Update readme and contributing docs to fix url capitalization.
2013-09-03 14:42:12 -07:00
Dylan 4695104081 Another url caps update 2013-09-03 17:36:48 -04:00
Dylan a083ccb86c Update CONTRIBUTING.md to fix caps in README.md link 2013-09-03 17:18:26 -04:00
Dylan 843d0d285f Update README.md to fix caps in CHANGELOG.md link 2013-09-03 17:15:28 -04:00
Tim Branyen 220d34cb73 Updated homepage URL. 2013-09-03 15:15:09 -04:00
Tim Branyen 4900cbbedd Version bump to 0.9.2. 2013-09-03 15:05:28 -04:00
Tim Branyen a000e79f22 Patch for Node fix. 2013-09-03 15:01:17 -04:00
Tim Branyen ba4743df96 Fixed pathing issues with readFile and __dirname in Node builds. 2013-09-03 15:00:57 -04:00
Tim Branyen 4cb0277c87 Added coveralls badge. 2013-09-03 14:45:41 -04:00
Tim Branyen 6c7ce5d421 Testing coveralls support. 2013-09-03 14:42:25 -04:00
ssafejava a86c15980e Merge pull request #367 from ssafejava/viewFunctions
Implement 'Views object should accept functions that return a View', #366
2013-09-02 19:27:30 -07:00
ssafejava c67c206853 Pass 'view' var into functions declared as view configuration. 2013-09-03 10:05:57 +08:00
Tim 4b2bf27922 Removed undocumented and unused setup method call. Closes GH-372 2013-09-02 16:01:50 -04:00
ssafejava 8350109e75 Fix 'Views object should accept functions that return a View', #366 2013-08-15 14:56:56 +08:00
Tim Branyen e519cbce7b Merge pull request #364 from ssafejava/fixRequire
Patch layoutManager's AMD handling to play nice with r.js. Addresses #359
2013-08-07 18:26:41 -07:00
Tim 17688d112f Style adjustments. 2013-08-07 21:18:57 -04:00
ssafejava 6f81bb892e Style fixes related to UMD. Added .jshintrc and included inside Gruntfile. 2013-08-08 09:07:50 +08:00
ssafejava 00d65a4095 Patch layoutManager's AMD handling to play nice with r.js. Update test/expose.js to correct Backbone shim.
AMD wrapper adapted from https://github.com/umdjs/umd/blob/master/amdWeb.js
2013-08-07 09:42:19 +08:00
Tim Branyen b95d2bc013 Merge pull request #360 from ssafejava/master
Fix usage of `insert` flag (should be in parent manager).
2013-08-03 09:20:24 -07:00
Tim Branyen 0f7880d550 Version bump to 0.9.1 2013-08-02 14:12:55 -04:00
Tim Branyen dc82c05e09 Fixes #362 - Regression from not having default fetchTemplate tests. Added DOM and Node tests to cover this. 2013-08-02 14:05:42 -04:00
Tim Branyen ecabab5ce9 Renamed the define call to work with r.js builds. 2013-08-01 16:20:33 -04:00
ssafejava c2caa9deb4 Fix usage of insert flag (should be in parent manager), remove translation of insert argument in htmlBatch. 2013-08-01 09:34:21 +08:00
Tim Branyen fb1eb39bf2 Version bump to 0.9. 2013-07-31 13:38:28 -04:00
Mike Pennisi e1b0023ba1 Add stricter linting rules for test files
...and update test source code to pass.
2013-07-31 13:38:15 -04:00
Mike Pennisi 7488622e26 Lint test files
Temporarily relax rules for test environment (these errors to be fixed
in a separate commit)
2013-07-31 13:38:15 -04:00
Mike Pennisi 91fece8a49 Use linting to guard against undefined variables
This requires splitting the linting rules according to environment.
2013-07-31 13:38:15 -04:00
Mike Pennisi a0519a3fbf Remove references to unused variables
...and prevent future errors with a linting rule.
2013-07-31 13:38:15 -04:00
Mike Pennisi 891831bf81 Enforce project's code style with linting rules
These directives match the recommendations made by this project's style
guide.
2013-07-31 13:38:15 -04:00
Tim Branyen e07136175a Renamed files to be more consistent. Added a line break to the Node source. 2013-07-31 13:38:15 -04:00
Tim Branyen 8b99724c14 Upgraded underscore dependency. 2013-07-31 13:38:15 -04:00
Tim b91e0eddd6 Renamed fetch and render to fetchTemplate and renderTemplate. Modified some formatting in the Gruntfile. 2013-07-31 13:38:15 -04:00
Tim Branyen 5e187c7993 Initial work on renaming. 2013-07-31 13:38:15 -04:00
Tim Branyen 6062411e34 Fixed unfinished comment. Touched up comment alignment to 80 columns. Altered each to be reduce. 2013-07-28 21:53:26 -04:00
ssafejava 7758b557ae Style fixes. 2013-07-28 21:53:26 -04:00
ssafejava 07a488c06e Remove useFragment option and always append arrays of subviews as a group. 2013-07-28 21:53:26 -04:00
ssafejava 4b1747ac51 Fix node/cheerio tests; check for presence of keep flag to prevent re-appending existing views in htmlBatch(). jQuery is smart enough to detect this and not reappend but cheerio is not. 2013-07-28 21:53:26 -04:00
ssafejava 6ce9f11f5c Fix jq ref in views.js 2013-07-28 21:53:26 -04:00
ssafejava fd7150c766 Move insert responsibility to parent. Move insert flag to parent. Update test to reflect change and additional test for html() functionality on parent. All tests passing when useFragment: true. 2013-07-28 21:53:26 -04:00
ssafejava 357ca0eabb Update comments in htmlBatch() 2013-07-28 21:53:26 -04:00
ssafejava 4ddaed818b Create htmlBatch function. Allow subViews to define their own insert functions as was previously possible. Passes all tests except for a possibly invalid override of insert(). 2013-07-28 21:53:26 -04:00
ssafejava 3332932d00 Initial useFragment batch-rendering implementation. 2013-07-28 21:53:26 -04:00
Tim Branyen 0e79690a8f added dependencies graphic 2013-07-28 21:53:26 -04:00
Tim Branyen 7224a12096 Updated grunt-benchmark to handle results. 2013-07-28 21:53:26 -04:00
Tim Branyen 6683a93caa Added in clean task to remove benchmark results 2013-07-28 21:53:26 -04:00
Tim Branyen 241fbb8f87 Added in grunt-benchmark, cli-table, and a new results task to run benchmarks and display results 2013-07-28 21:53:26 -04:00
Tim Branyen bc7bb1ac98 updated tests to better account for trace and warn being non-functions 2013-07-28 21:53:26 -04:00
Tim Branyen 7bcc9ba898 minor tweaks to tests and removed the commented out serialize 2013-07-28 21:53:26 -04:00
Tim Branyen c228da4ab0 updated to use grunt-qunit-istanbul for code coverage - back to 100% again, fixed renderViews and added unit test, refactored setView to not need existing variable, some variable naming improvements 2013-07-28 21:53:25 -04:00
Tim Branyen 9519b9ebfe updated readme: removed donations link and added @sboudrias to maintainers 2013-07-28 21:53:25 -04:00
Tim Branyen 9192946247 fixed test 2013-07-28 21:53:25 -04:00
Tim Branyen d1243ab6a4 better error message 2013-07-28 21:53:25 -04:00
Tim Branyen bb7dc1f0aa experimental code for default view template context, and put hasRendered on the instance 2013-07-28 21:53:25 -04:00
Tim Branyen d06ef88033 removed event bubbling 2013-07-28 21:53:25 -04:00
Tim Branyen 53e6ec4cb7 fixed the wrapper to match current style 2013-07-28 21:53:25 -04:00
Simon Boudrias 429d19459d Integrate named DOM sections mapped to a view selector 2013-07-28 21:53:25 -04:00
Tim ca103c8e4b cleaner export to global 2013-07-28 21:53:25 -04:00
Tim e3bbc2f762 removed unused qunit/grunt flag 2013-07-28 21:53:25 -04:00
Tim 2a68c0f310 can remove shim now from jam configuration 2013-07-28 21:53:25 -04:00
Tim 332d8b739e added in requirejs as a dev dependency for node tests and got the amd test working in node 2013-07-28 21:53:25 -04:00
Tim 9c00fe6aff amd support 2013-07-28 21:53:25 -04:00
Tim baccdff96d brought the manager cleanup code into the callback function and removed window from setTimeout 2013-07-28 21:53:25 -04:00
Tim 8a8012dd11 refactored asynchronous rendering to be off the View instance instead of _makeAsync, allows beforeRender to be asynchronous 2013-07-28 21:53:25 -04:00
Tim 2c6e65536d patched tests to use promise api 2013-07-28 21:53:25 -04:00
Tim Branyen 1bac5af60f remove parent 2013-07-28 21:53:25 -04:00
Tim Branyen 33386e2986 fixed test with render() return 2013-07-28 21:53:25 -04:00
Tim Branyen c96c4b86a8 updated tests to use promise return 2013-07-28 21:53:24 -04:00
Tim Branyen 87fd3055c1 updated dom test to use promise return 2013-07-28 21:53:24 -04:00
Tim Branyen a858b62180 changed renderChildren to renderViews 2013-07-28 21:53:24 -04:00
Tim Branyen 219c74b04e updated new 0.8.1 fixes to work with the new return 2013-07-28 21:53:24 -04:00
Tim Branyen 8cf1b56e2a updated all tests to work with new changes 2013-07-28 21:53:24 -04:00
Tim Branyen a16e98f60e initial work with new feature 2013-07-28 21:53:24 -04:00
Tim 1b7d292a09 Upgraded cheerio dependency to 0.12.0 2013-06-14 17:32:54 -04:00
Tim Branyen 6c30474036 tagging 0.8.8 release 2013-05-18 00:09:49 -04:00
Tim Branyen 18f8b10644 >80 cols 2013-05-17 23:43:47 -04:00
Adam J. DiCarlo 55bf804695 Fix #349: Blank re-render should remove old render result. 2013-05-17 23:19:28 -04:00
Adam J. DiCarlo e8ff298146 Test #349: Blank re-render should remove old render result. 2013-05-17 23:19:18 -04:00
Simon Boudrias 111d1c6ad9 Add config files to ease settings work from each different collaborators 2013-03-27 20:34:11 -04:00
Tim Branyen 130bfbbab4 Merge pull request #330 from jugglinmike/configure-test
Remove invalid test
2013-03-25 08:03:51 -07:00
Mike Pennisi 3eb2875b30 Remove invalid test
`Layout.configure` does not support the signature exercised by this
test. The test only passes because it is using an invalid signature--the
functionality implied by the test is not supported. This means that
correcting the invocation results in a failing test, so the test should
be thrown out.
2013-03-24 18:59:44 -04:00
Tim 3209ab0d40 fix for travisci icon 2013-03-24 13:30:04 -04:00
Tim Branyen e55880749f Merge pull request #329 from jugglinmike/328-cleanup-invocation
Correct cleanViews invocation of cleanup methods
2013-03-24 09:21:56 -07:00
Mike Pennisi ce125ce25b Correct cleanViews invocation of cleanup methods
Ensure that cleanViews invokes cleanup methods in the context of the
target layout.
2013-03-24 06:30:13 -04:00
Tim Branyen f93256dfb5 Merge pull request #327 from jugglinmike/325-get-unknown-views
Fix Layout#getViews for unrecognized selectors
2013-03-23 19:57:45 -07:00
Tim Branyen 7edc9e671b Merge pull request #326 from jugglinmike/optimize-getviews
Optimize Layout#getViews
2013-03-23 19:56:53 -07:00
Mike Pennisi 3c544ae11b Optimize Layout#getViews still further
Avoid "unchaining" the comprehensive views collection, and use the
chained version to calculate the correct result.
2013-03-23 15:08:03 -04:00
Mike Pennisi 12989debb8 Optimize Layout#getViews further
`_.where` always returns an array, so there is no need to wrap the
result in an array and immediately flatten it.
2013-03-23 15:03:24 -04:00
Mike Pennisi db00c74910 Optimize Layout#getViews
Defer generation of comprehensive views collection until it is needed.
2013-03-23 14:56:00 -04:00
Mike Pennisi f911b8b6a9 Fix Layout#getViews for unrecognized selectors
Return an empty array when no views exist at the specified selector.
Fixes GitHub issue #325.
2013-03-23 14:49:31 -04:00
Tim ad7e3ba6bf bumping version 2013-03-23 11:40:41 -04:00
Tim 062d126179 Moved trimming to only where it's needed 2013-03-23 11:37:22 -04:00
Tim 5a145b75b2 fixed column widths to 80 2013-03-23 11:33:35 -04:00
Simon Boudrias 725d3bb9dc trim templates to prevent conflicts with jQuery 2013-03-22 10:38:22 -04:00
Simon Boudrias 2aab4ed4cc Update Cheerio dependency to 0.10.8 (version needed by issue #300) 2013-03-20 20:12:24 -04:00
Tim Branyen 4efeb959f9 updated release notes 2013-03-20 09:27:31 -04:00
Tim Branyen ace78132e4 allowing for latest node 0.10, bumping version 2013-03-20 09:25:25 -04:00
Tim Branyen eb2fa6ce7d upgraded to backbone 1.0 2013-03-20 09:10:19 -04:00
Tim Branyen 92f25a8338 changed logic around so that keep is only associated with insert and that force overrides all, Closes GH-312 2013-03-20 01:00:59 -04:00
Tim Branyen 4db526fcae Merge pull request #321 from tbranyen/warn-el
`el: false` multiple top level (officially not supporting) in 0.8.*
2013-03-19 09:41:42 -07:00
Tim Branyen dcd3a543bc added global iife wrapper for all tests and added tests for suppressWarnings 2013-03-19 12:23:14 -04:00
Tim Branyen 4288a72b45 removed check for QUnit, updated tests to suppressWarnings 2013-03-19 09:05:52 -04:00
Tim Branyen 63bd9456dc display warnings if using el: false with multiple top level elements, but allow suppression if the end user knows whats up 2013-03-19 01:42:31 -04:00
Tim Branyen 51b616edc6 bump version 2013-03-17 22:37:46 -04:00
Simon Boudrias 5d8a609740 Merge pull request #318 from SBoudrias/fix-302
Fix #302
2013-03-15 13:25:35 -07:00
Simon Boudrias c12198dff8 Fix #302 - passing a _.where object to getView() always returned the first subview (matching or not) 2013-03-15 16:18:25 -04:00
Tim Branyen 56d510d6e8 Merge pull request #310 from michaelorionmcmanus/master
Deleting template property from view instance during initialization is not necessary
2013-03-15 10:08:26 -07:00
Michael McManus f989f7a958 Don't delete template property from view during initialization.
`delete view.template` only removes the template property from the
instance's prototype. If the instance inherits from another view that
has a template property this can cause unexpected results during view
rendering.
2013-03-15 10:02:18 -07:00
Simon Boudrias 885e25253a Merge pull request #300 from SBoudrias/fix-duplicated-views
Fix view duplication when rerendering full template
2013-03-13 12:59:49 -07:00
Simon Boudrias 786ac7effa Fix view duplication when rerendering full template view with multiple top level elements (Fix #299) 2013-03-13 14:27:28 -04:00
Tim Branyen aac6394ddf version bump to 0.8.4 2013-02-13 11:52:39 -05:00
Tim Branyen a8369b74e4 Merge pull request #294 from jugglinmike/fix-white-space
Fix white space
2013-02-13 07:05:34 -08:00
Mike Pennisi 5a764587cc Fix white space
Replace tabs with spaces as per project convention.
2013-02-13 10:01:37 -05:00
Tim Branyen 7f1c8333e1 Merge pull request #292 from jugglinmike/remove-custom-contains
Remove custom implementation of $.contains
2013-02-12 19:47:14 -08:00
Mike Pennisi bdb58bc768 Remove custom implementation of $.contains
Prefer Cheerio's implementation of this jQuery method (implemented in
v0.10.6).
2013-02-12 22:02:18 -05:00
Tim Branyen ba2c6bca9a Merge pull request #287 from STRML/master
List items (inserted views) with el:false are rerendered improperly.
2013-02-12 08:45:11 -08:00
Samuel Reed c20d5ffa9e and... HOIST 2013-02-12 11:41:53 -05:00
jugglinmike a2f9ae1c45 Merge pull request #288 from jugglinmike/fix-node
Fix Node.js build
2013-02-11 05:55:29 -08:00
Mike Pennisi a8ac66512e Update Cheerio dependency
Previous versions of the Cheerio library exhibited a bug in the `filter`
method which triggered incorrect behavior in the `partial` method. The
latest version of Cheerio fixes that bug and, in turn, fixes the `partial`
method.
2013-02-10 22:46:56 -05:00
Mike Pennisi 31b1004c86 Correct implementation of "partial" in Node.js
GitHub issue #271 addressed a bug concerning the behavior of deeply-nested
views used with `el: false`. Because that work only patched
LayoutManager's behavior in browser environments, this patch is necessary
to address the bug in Node.js
2013-02-10 22:42:31 -05:00
Samuel Reed d6fff8bc8b Fix accidential insertion when rerendering elements with noel=true
Fix noel rerendering inside a list.

Add test
2013-02-10 21:38:09 -05:00
Tim Branyen 3206891065 changed jquery dependency to work with 1.9 and others 2013-02-06 11:30:43 -05:00
Tim Branyen e6ee8fd35e version bump 2013-02-03 12:51:01 -05:00
Tim Branyen f21d662654 Merge pull request #271 from morkai/master
Deeply nested views with `el: false` are not inserted into the specified selectors.
2013-01-29 14:16:00 -08:00
Łukasz Walukiewicz 66c7103805 Simplified the nested if/else. 2013-01-29 23:04:19 +01:00
Łukasz Walukiewicz 9b1fc400f9 Do not rely on DOM specific properties. 2013-01-29 23:03:49 +01:00
Łukasz Walukiewicz 986518e0dc Fixed deeply nested views with el: false not being inserted into the specified selector. 2013-01-29 22:24:32 +01:00
Tim Branyen 87b4c36fed fixed header to 0.8.1 2013-01-25 00:27:17 -05:00
Tim Branyen 3ee56f29e2 updated readme release notes 2013-01-25 00:05:03 -05:00
Tim Branyen 02d88c41d7 tagging 0.8.2 release 2013-01-25 00:03:04 -05:00
Tim Branyen 8e553a2a6e Updated LM to only reset template contents when you have an unrendered view, Closes GH-268 2013-01-24 22:20:09 -05:00
Tim Branyen a9f4532d9d Merge pull request #267 from tbranyen/afterrender-test
Edge case bug with `afterRender`.
2013-01-23 18:10:42 -08:00
Tim Branyen 85bd738dff removed unnecessary function expressions 2013-01-23 16:25:31 -05:00
Tim Branyen c79d5f9bdc refactored with @jugglinmike's suggestions 2013-01-23 15:55:12 -05:00
Tim Branyen c432106438 removed lingering diff markup 2013-01-23 15:08:29 -05:00
Tim Branyen de4d7acf32 updated the test a little 2013-01-23 15:07:23 -05:00
Tim Branyen 4c25021db1 added breaking test 2013-01-23 15:07:23 -05:00
Tim Branyen 324eeff0d8 Merge pull request #266 from fiznool/master
Events not delegated when rendering a single view
2013-01-23 09:31:48 -08:00
fiznool b1bd58361d Fixed issue with event delegation when managing own view element 2013-01-23 17:17:56 +00:00
fiznool 66cb44e830 Added test for issue with event delegation when managing own view element 2013-01-23 17:17:15 +00:00
Tim Branyen dba56930fd Merge pull request #264 from SBoudrias/patch-1
Update jamjs exports config
2013-01-21 06:53:14 -08:00
Simon Boudrias f214a1321d Update jamjs exports config
As `LayoutManager` is deprecated in favour of `Backbone.Layout`, the jamjs config should be updated too.

This would fix a part bug we had in Backbone-Boilerplate: https://github.com/tbranyen/backbone-boilerplate/issues/199

(I guess to fix this someone need to also republish the fixed version to Jam package repo)
2013-01-21 09:48:34 -05:00
Tim Branyen d5d0dcfcbb tagging 0.8.1 2013-01-20 00:21:52 -05:00
Tim Branyen dde48e417b Merge pull request #262 from jugglinmike/261-varying-fetch
Preserve view ordering with varying render delays
2013-01-19 21:15:23 -08:00
Tim Branyen 72026641d1 fix node build 2013-01-19 13:52:11 -05:00
Tim Branyen 531a603d5a changed node deps to be fuzzy 2013-01-19 13:41:51 -05:00
Mike Pennisi 67d50fe8d9 Preserve view ordering with varying render delays
Because sub-views may have independant rendering delays, the parent view
must wait for each view to complete rendering before inserting the next.

This addresses the issue first identified by @peterjmit in issue #261.
2013-01-19 12:46:45 -05:00
Tim Branyen 50cc39cdf0 Merge pull request #248 from tbranyen/wip
Merge 0.8 release.
2013-01-15 14:54:32 -08:00
Tim Branyen 2b69e2a344 updated noel unit tests and code to ensure views without a parent will work, Closes GH-255 2013-01-15 17:15:31 -05:00
Tim Branyen 4f62737346 marked el as experimental 2013-01-15 17:06:57 -05:00
Tim Branyen 46c72a9070 Merge pull request #258 from tbranyen/examples-cleanup
Tracking examples refactor.
2013-01-15 14:03:05 -08:00
Tim Branyen 62ce7588d5 Updated all examples to be easier to understand and explore. 2013-01-15 17:02:33 -05:00
Tim Branyen 2516eae5ae upgraded jquery and backbone dependencies 2013-01-15 15:40:30 -05:00
Tim Branyen 59f1171aa9 updated release notes 2013-01-15 14:45:14 -05:00
Tim Branyen 8279946285 can now pass a template function directly without needing to override fetch with an identity function 2013-01-15 11:32:07 -05:00
Tim Branyen ed2aa8627a updated to grunt 0.4rc5 urgh 2013-01-12 16:11:33 -05:00
Tim Branyen 6e8a3331a9 stripped out -pre in preparation for merge 2013-01-12 15:53:35 -05:00
Tim Branyen 005194eb23 updated changelog and readme 2013-01-12 15:41:40 -05:00
Tim Branyen 3d210f275e patched to allow global configuration to override 2013-01-07 13:37:35 -05:00
Tim Branyen 724c259c28 restore el disable functionality 2013-01-07 13:32:17 -05:00
Tim Branyen 4048159b16 updated maintainers in readme 2013-01-06 22:37:16 -05:00
Tim Branyen 5fff74a66f fixed contributing guide 2013-01-06 11:00:18 -05:00
Tim Branyen 91514b34b0 change removeView to call remove instead for consistency 2013-01-05 14:48:17 -05:00
Tim Branyen 9a7371f4ed moved migration guide to wiki 2013-01-05 11:16:05 -05:00
Tim Branyen 2ed4d3ec45 updated url to point to .org 2013-01-05 11:12:53 -05:00
Tim Branyen 20471d960e changed class method setupViews to accept a single or many Views 2013-01-05 11:12:53 -05:00
Tim Branyen 07264740b2 renamed configures argument from opts to options 2013-01-05 11:12:53 -05:00
Tim Branyen 8747a8caa3 reordered the class methods and updated cache to override if path and contents are passed 2013-01-05 11:12:53 -05:00
Tim Branyen daf6f022be hoisted the variable declaration inside of _configure 2013-01-05 11:12:53 -05:00
Tim Branyen c8044c2dbf updated contributing and readme docs 2013-01-05 11:12:53 -05:00
Tim Branyen ecfb5016a9 restored unbinding of collection and model 2013-01-05 11:12:53 -05:00
Tim Branyen b3a920907c updated release notes 2013-01-05 11:12:53 -05:00
Tim Branyen a53eb58fd6 removed named function 2012-12-31 08:27:31 -05:00
Tim Branyen aee4e0c952 send the $el instead of el to partial for application 2012-12-31 08:27:31 -05:00
Tim Branyen 42e832311c fixed merge conflict and updated commit message 2012-12-31 08:27:17 -05:00
Tim Branyen 7e029d284c updated readme with release notes 2012-12-30 17:57:46 -05:00
Tim Branyen fb13138350 this commit gets rid of that pesky unwanted element 2012-12-30 17:54:17 -05:00
Tim Branyen 28eaa28a0b fixed issue with rebase, but now rebased to master 2012-12-30 17:50:51 -05:00
Tim Branyen 4660110d3c some comment rewording, and less emphasis on testing in readme 2012-12-30 17:50:13 -05:00
Tim Branyen acbd5c71a4 reordering readme 2012-12-30 17:50:13 -05:00
Tim Branyen 3228bf4078 updated contributing notes in readme 2012-12-30 17:50:13 -05:00
Tim Branyen 210c6de5d0 switching to wiki and added a contributing.md file 2012-12-30 17:50:13 -05:00
Tim Branyen 6f4ece5875 added unit test showing #243 before/after callbacks to work correctly 2012-12-30 17:50:13 -05:00
kiwi 296295bb01 fix issue #243 2012-12-30 17:50:13 -05:00
Mike Pennisi e4d748ad2f Add test for default fetch method
Since the tests have been re-factored to use in-memory templates, a new
test is needed to explicitly exersize the default `fetch` method's
behavior.

Resolves #240
2012-12-30 17:50:13 -05:00
Mike Pennisi 6ff5f01400 Remove repeated logic from unit tests 2012-12-30 17:50:12 -05:00
Tim Branyen d1068913d3 travis-ci updates for wip 2012-12-30 17:50:12 -05:00
Tim Branyen 05c5914ad3 renamed _options to getAllOptions Closes GH-242 2012-12-30 17:50:12 -05:00
Tim Branyen 6971809738 updated release notes and changed make again to match the current pull request 2012-12-30 17:50:12 -05:00
Tim Branyen c07c2ff79c updated make to be more backbone compatible and reformatted some of the radme 2012-12-30 17:50:12 -05:00
Tim Branyen d1d39715f1 reverted readme branch travis-ci and updated blurbage 2012-12-30 17:50:12 -05:00
Tim Branyen 1daf20f2a7 wording changes to source and added unit test for insertView events 2012-12-30 17:49:51 -05:00
Tim Branyen 2ed04957a4 fix the build 2012-12-30 17:49:51 -05:00
Tim Branyen bf167b091e removed lodash testing, we expect lodash.underscore to pass underscore's tests. updated versioning for component and dependencies for jamjs 2012-12-30 17:49:51 -05:00
Tim Branyen c3db4dd097 massive node.js refactor, removed several unnecessary Backbone overrides. removed manage: true by default (in node). updated layoutmanager to use global in place of this for node.js environments 2012-12-30 17:49:16 -05:00
Tim Branyen a43bc3ae6e removed append/insert test and append fallback from node codebase 2012-12-30 17:49:16 -05:00
Tim Branyen 3108b62179 removed lodash as a viable dependency and added grunt-cli to devDeps for travis-ci compat 2012-12-30 17:49:16 -05:00
Tim Branyen 2c64991b8b removed augment, no longer supporting vanilla lodash. removed append alias for insert 2012-12-30 17:49:16 -05:00
Tim Branyen 09368925f1 upgraded to grunt 0.4, moved config language to coffeescript, npm formatted package.json, changed node qunit task to new grunt-nodequnit, added use strict to test files 2012-12-30 17:48:52 -05:00
Tim Branyen 2f6ea35e62 first stab at release notes and migration guide 2012-12-30 17:48:22 -05:00
Mike Pennisi 590fcf6d2e Add a grunt task for running tests in Node.js 2012-12-30 17:47:55 -05:00
Mike Pennisi c9f3a19564 Simplify default Node.js insertion operations
Move all Node.js (and Cheerio) implementation details into the
definition of the default "partial" method.

By specializing the "partial" method in this way, Node.js can share the
browser's default implementations of "html" and "append".

This approach also simplifies cross-environment code sharing for the
application developer. LayoutManager supports declaring Layout- and
View-specific "append" methods. If intended to run across environments,
these custom methods would otherwise have to contain conditional logic
to support the browser and Node.js.
2012-12-30 17:47:35 -05:00
Mike Pennisi 1a29a24b4c Use LayoutManager's "when" implementation in tests
Because this method is defined by LayoutManager (and over-ridden in
Node.js) it is safe for the browser and Node.
2012-12-30 17:47:35 -05:00
Mike Pennisi 66dbfa7136 Use latest QUnit API
The "equals" method has been deprecated since 2009, apparently.
2012-12-30 17:47:35 -05:00
Mike Pennisi f6e5a71607 Implement "contains" for Node.js
...and utilize in tests.
2012-12-30 17:47:34 -05:00
Mike Pennisi 1b250ae810 Correct Node.js implementation of DOM methods 2012-12-30 17:47:34 -05:00
Mike Pennisi b789aa8fec Remove DOM API call
Prefer instead the common jQuery methods exposed by the view so that the
tests can run in Node.js.
2012-12-30 17:47:34 -05:00
Mike Pennisi 8e6fa2a5de Create a context-sensitive "isDomNode" method
Because DOM nodes must be simulated in Node.js, the method that
determines if a given object is a "DOM node" should be contextual to the
environment in which the tests are running.
2012-12-30 17:47:34 -05:00
Mike Pennisi 6691d9a820 Remove references to global jQuery object
Neither "$" or "jQuery" are available in Node.js.
2012-12-30 17:47:34 -05:00
Mike Pennisi 952b5cca37 Remove complex selectors from test source
As discussed in the Cheerio issue tracker*, ":eq" selectors are not
supported. Prefer explicit collection dereference so that the tests run
as intended in Node.js.

* https://github.com/MatthewMueller/cheerio/issues/129
2012-12-30 17:47:34 -05:00
Mike Pennisi 7bb9918df9 Fix bug in HTML rendering in Node.js
When supplied with a Cheerio instance (instead of a string of HTML), the
Node.js-specific `html` and `append` methods should reference the
complete outer HTML (not just the contents) as generated by Cheerio's
`html` method.

Note that this was previously fixed with d60cf12, but Cheerio's public
API changed, which forced reversion to the earlier (incorrect)
implementation at 3fb562160e.
2012-12-30 17:47:34 -05:00
Mike Pennisi 017680349e Remove references to global "window" object
Because "window" is not defined in Node.js, access global methods by
name directly.
2012-12-30 17:47:34 -05:00
Mike Pennisi d0b5482585 Move DOM-dependent tests to dedicated test file
Certain tests may require the DOM. In order to ignore these tests in
Node.js, declare them in a dedicated file.
2012-12-30 17:47:34 -05:00
Mike Pennisi 499ae6edd9 Declare template sources in memory
Because Node.js does not have access to the DOM, template source strings
should be defined in memory.
2012-12-30 17:47:34 -05:00
Mike Pennisi 0cce97c904 Create a "testUtil" object
This object will hold utility methods and data for running the unit
tests.
2012-12-30 17:47:34 -05:00
Mike Pennisi afa1344012 Run tests in Node.js
Very many failures, but it's a start!
2012-12-30 17:47:34 -05:00
Mike Pennisi 8c71c7e361 Fix re-named methods in Node.js
This includes:

- LayoutView -> Layout
- Backbone.LayoutManager -> Backbone.Layout
- append -> insert
- data -> serialize
2012-12-30 17:47:04 -05:00
Mike Pennisi cfbe5be9ca Update Node.js dependencies to match the browser 2012-12-30 17:47:04 -05:00
Tim Branyen eb76837657 reduced some of the timeouts in tests and changed to serialize 2012-12-30 17:46:26 -05:00
Tim Branyen 36e90e7487 added in event bubbling 2012-12-30 17:45:41 -05:00
Tim Branyen afdac12bd7 removed a line because backbone has once now, :) 2012-12-30 17:45:41 -05:00
Tim Branyen 7e84932d0b upgraded layoutmanager to have -like functionality in getView, added support, hard dependency on latest backbone 0.9.9 now, and changed to lodash.underscore 2012-12-30 17:43:34 -05:00
Tim Branyen 5ea23f71a7 upgraded remaining assets 2012-12-30 17:43:34 -05:00
Tim Branyen c2d1d46b50 updated backbone to 0.9.9 release 2012-12-30 17:43:34 -05:00
Tim Branyen 52eaf759d0 upgraded backbone to latest and fixed test that was using a private property 2012-12-30 17:43:34 -05:00
Tim Branyen f4dbd23dc4 added latest backbone (master) in and fixed unit test failures 2012-12-30 17:43:33 -05:00
Mike Pennisi 4e4bad04b4 Maintain backwards compatability with 0.7.2
Maintain "append" as an alias for "insert" for short-term backwards
compatability.
2012-12-30 17:43:33 -05:00
Mike Pennisi 92113c03e1 Rename 'append' to 'insert'
The name 'insert' is more generic: it does not imply the method by which
elements are added to the DOM. Since this method is intended to be
overridden with any arbitray insertion logic, the API should not suggest
what form that method takes.
2012-12-30 17:43:33 -05:00
Tim Branyen aacd8c45dc renamed examples to be singular 2012-12-30 17:43:33 -05:00
Tim 1473676a5a initial work on 0.8, fixed bug with manage: true on Backbone.View, changed to only serializeData, removed Backbone.LayoutManager and Backbone.Layout and added in removeView 2012-12-30 17:43:33 -05:00
Tim Branyen 43a0e13c2a tagging 0.7.5 release 2012-12-29 13:19:28 -05:00
Tim Branyen 9d11d9b85a fix underscore issue with template 2012-12-29 13:10:09 -05:00
Tim Branyen bb57b11f24 updated serialize to look on instance instead of just options Closes GH-237 2012-12-29 13:08:09 -05:00
Tim Branyen 0f8f1574ac added unit test to show correct behavior of GH-2332 2012-12-29 12:41:44 -05:00
Tim Branyen 78fef3d989 removed names and issue # from release notes to remain consistent 2012-12-29 12:15:42 -05:00
Tim Branyen 19916d2c1f bumping version to 0.7.4 2012-12-20 20:16:41 -05:00
Tim Branyen ff0c5e3ad9 Merge pull request #236 from jugglinmike/235-ie-fix
Remove named function expression
2012-12-20 13:33:30 -08:00
Mike Pennisi d34d211b51 Remove named function expression
In JScript, named function expressions generate two unique function
objects. From http://kangax.github.com/nfe/#jscript-bugs:

    var f = function g(){};
    f === g; // false

    f.expando = 'foo';
    g.expando; // undefined

This means that in Internet Explorer, the `afterRender` function passed
to `.on()` is distinct from the function passed to `.off()` when it
attempts to unbind itself.

This implementation is slightly more verbose, but it ensures correct
behavior in IE8.
2012-12-20 09:30:54 -05:00
Tim Branyen 9c35d68d3c upgraded all test assets to latest, Closes GH-230 2012-12-13 18:23:24 -05:00
jugglinmike 253a3fd9c2 Merge pull request #226 from jugglinmike/simplify-insertion
Simplify insertion methods
2012-12-08 20:49:45 -08:00
Mike Pennisi 15143d67c6 Simplify insertion methods
Update the internal "applyTemplate" function to use the jQuery-wrapped
version of the given view's element. This obviates the need to wrap the
object passed to "html" and "append", making the code:

1. More efficient (the jQuery elements created in "partial" are no longer
   needlessly re-wrapped)
2. More usable (user-specified "html" and "append" methods can rely on
   the root element being a full jQuery object, with all the benefits
   that brings)
2012-12-08 17:45:01 -05:00
Tim Branyen 284d081285 bumping version to 0.7.3 2012-12-05 17:22:42 -05:00
Tim Branyen c5bf36faee Merge pull request #223 from JayceTDE/master
_options - Copy all prototype properties while using Lo-Dash
2012-12-05 14:13:25 -08:00
Jayce Pulsipher 2281d5d3c2 Refactor
use augment method to copy option properties
2012-12-05 17:10:39 -05:00
JayceTDE 3bbd9a45e5 _options - copy all inherited properties
Using this.constructor.prototype only copies the last
inherited prototype. If chaining multiple extends together,
the first prototypes will not be copied if using Lo-Dash
2012-12-05 17:03:12 -05:00
Tim Branyen cec1f5f864 more readme tweaks 2012-12-05 16:09:39 -05:00
Tim Branyen ceec8b0e97 changed back to header 2012-12-05 14:55:36 -05:00
Tim Branyen 350656513d changed title case 2012-12-05 14:42:44 -05:00
Tim Branyen f1bf3bca44 readme header tweak 2012-12-05 14:42:12 -05:00
Tim Branyen d7bea27b6b readme tweak 2012-12-05 14:40:44 -05:00
Tim Branyen 1a6acf4800 testing this travis-ci thing out 2012-12-05 14:34:24 -05:00
Tim Branyen b4b45d9929 updated to remove gittip, not a fan of subscription tipping 2012-12-05 14:23:29 -05:00
Tim Branyen 593a5ddbfa updated to add paypal solution too 2012-12-05 12:42:18 -05:00
Tim Branyen e18fce4c96 added donation section 2012-12-05 11:59:50 -05:00
Tim Branyen 85b8d63c6f updated order of rendering to be consistent regardless if the parent has previously rendered Closes GH-222 2012-12-05 11:05:50 -05:00
Tim Branyen a770de2d6d minor tweaks 2012-12-02 22:43:00 -05:00
Tim Branyen 4aea115447 Merge pull request #216 from rcs/master
Error handling in fetch() for node.js
2012-12-02 19:41:35 -08:00
Tim Branyen 8ba8bbdc03 Merge pull request #219 from jugglinmike/test-custom-append
Add unit test for user-defined "append" method
2012-12-02 19:40:41 -08:00
Mike Pennisi 9b7844058d Add unit test for user-defined "append" method
Ensure that LayoutManager uses custom "append" method when inserting view
HTML in the "insertView" method (when that method is specified).
2012-12-01 16:19:23 -05:00
Tim Branyen 7eb81df825 working example of issue 218 2012-11-30 14:31:19 -05:00
Ryan Sorensen 70d9858b44 Fix error message for readFile's open and return for execution context. Let exceptions be thrown from callbacks. 2012-11-28 21:11:29 -08:00
Tim Branyen 82c7125e19 bumped version to 0.7.2 2012-11-28 04:29:52 -05:00
Tim Branyen b91e543166 Merge pull request #214 from rcs/master
Node package "underscore" dependency
2012-11-27 10:06:08 -08:00
Ryan Sorensen ddbf79aac9 Explicitly depend and require underscore 2012-11-27 09:53:13 -08:00
Tim Branyen 3fb562160e cheerio thing 2012-11-26 10:48:08 -05:00
Tim Branyen 619311af13 Merge pull request #211 from jugglinmike/repeated-subviews
Fix bug in removing duplicate sub-views
2012-11-23 15:54:46 -08:00
Mike Pennisi 5a1353ee93 Fix bug in removing duplicate sub-views
Conditions that triggered this bug:

- A view has a sub-view which renders asynchronously due to an
  asynchronous `fetch` method
- The view's `render` method is invoked multiple times before the
  sub-view's `fetch` method resolves

Result:

The sub-view created in the first call to `render` is not removed by the
second call, yeilding repeated sub-views.

Fix:

Set the view's `hasRendered` flag *before* resolving the `render` method's
deferred.
2012-11-23 18:51:18 -05:00
Tim Branyen b132671f8c Ensure serialize has higher priority than data Closes GH-209 2012-11-23 12:21:58 -05:00
Tim Branyen fa42355d32 renamed test index.html to underscore and added a lodash version as well, fixed an inconsistency with lodash 2012-11-21 11:53:31 -05:00
Tim Branyen 545be74a61 updated version property 2012-11-15 17:56:18 -05:00
Tim Branyen 3a060a7769 updated component version 2012-11-15 17:51:59 -05:00
Tim Branyen 99d8c4e65d updated release notes and tagging 0.7.1 2012-11-15 17:37:56 -05:00
Tim Branyen d1554f29de added test to get back to 100% coverage 2012-11-15 17:30:17 -05:00
Tim Branyen 30f8d1a392 fix option overriding for template, Closes GH-201 2012-11-15 17:13:16 -05:00
Tim Branyen a181262a0f added asynchronous rendering of templates. Closes GH-197 2012-11-15 16:42:26 -05:00
Tim Branyen 81af88aa3f Merge pull request #205 from SoapyIllusions/master
insertViews should be able to accept an array of views
2012-11-13 18:45:41 -08:00
Alex Angelini 8ef8555b0c insertViews can accept an array of views 2012-11-13 18:30:29 -05:00
Tim Branyen 987e1edd7f removed minified build, one less thing to maintain 2012-11-07 15:04:42 -05:00
Tim Branyen e2728ae4d9 changed jam includes 2012-11-03 20:34:01 -07:00
Tim Branyen b97bda3281 fixed typeof check, thanks @hustKiwi 2012-11-03 11:45:57 -07:00
Tim Branyen 63558f920f some minor perf tweaks, added new getViews/getView selector searching Closes GH-200 2012-11-01 15:44:07 -06:00
Tim Branyen ca0bbe11de minor 2012-10-29 22:19:51 -04:00
Tim Branyen 48cde028db ensure view is not null when attempting to call __manager__ on it 2012-10-29 22:19:33 -04:00
BJTerry 15dc3cc10c Fixes issue #191 with cleanup not being called on subviews. 2012-10-27 15:13:57 -07:00
BJTerry 498ad55190 Fixes issue #191 with cleanup not being called on subviews. 2012-10-27 15:04:22 -07:00
Tim cfce2edaae Fixes GH-190 Updated the remove process to only remove views that have rendered or forced 2012-10-26 03:03:54 -04:00
Tim Branyen 0cd267734d Merge pull request #192 from drewzboto/master
Test case for issue 190
2012-10-25 22:57:55 -07:00
Drewz Lau 0a954915e3 Added new test case for reinserting views causing duplicate views 2012-10-25 22:45:00 -07:00
Tim Branyen 3bd09bb064 revert basic.html 2012-10-23 13:32:21 -04:00
Tim Branyen 1c24c21447 added backing unit test for previous commit and ran grunt 2012-10-23 12:39:37 -04:00
Tim Branyen 733d781350 updated layoutmanager to attach existing views when setView is called 2012-10-23 12:32:31 -04:00
Tim Branyen 034c15eca4 updated release notes in readme 2012-10-22 22:13:06 -04:00
Tim Branyen ee1c751d77 tagging 0.7.0 2012-10-21 23:42:42 -04:00
Tim Branyen 888fcdfb74 Merge pull request #184 from tbranyen/wip
0.7.0 Release Candidate
2012-10-21 20:40:35 -07:00
Tim Branyen 121ece1b38 line break 2012-10-21 23:40:03 -04:00
Tim Branyen ee07c812e6 updated readme to use until site is done 2012-10-21 23:39:37 -04:00
Tim Branyen db759605e5 updated with latest fixes to afterRender/beforeRender 2012-10-21 23:31:31 -04:00
Tim Branyen fb6e7a5fb4 ran grunt and updated views to have an expected number of asserts 2012-10-21 11:21:39 -04:00
Tim Branyen d4ca272801 updated codebase to ensure cleanup is called on views w/o a parent 2012-10-20 14:36:49 -04:00
Tim Branyen e7c957545c fixed major rendering issue 2012-10-17 17:38:20 -04:00
Tim Branyen 1ef55dbab0 resolved issue with afterRender being called too early 2012-10-15 14:58:26 -04:00
Tim Branyen faebfac4c6 basically working in node again 2012-10-15 00:52:10 -04:00
Tim Branyen 6975988c67 more readme tweaks 2012-10-15 00:40:10 -04:00
Tim Branyen 0200b3c50f updated readme 2012-10-15 00:37:31 -04:00
Tim Branyen 3af67c09e0 removed dead code 2012-10-15 00:33:34 -04:00
Tim Branyen 752c9887d0 fixed cleanup method being called erroneously 2012-10-15 00:29:33 -04:00
Tim Branyen e2c13c76c8 updated error message 2012-10-14 15:10:01 -04:00
Tim Branyen 3f5676e0f8 removed need to indexOf check, by clearing out the views property 2012-10-14 15:00:08 -04:00
Tim Branyen 627d0b5db6 added unit test backing issue #178 2012-10-14 14:54:22 -04:00
Tim Branyen 62f61b185a bower package management support 2012-10-08 01:01:14 -04:00
Tim Branyen 6e02c4937a fixed out of order append view rendering 2012-10-07 17:31:31 -04:00
Tim Branyen 712715859c Deprecated paths for prefix, deprecated Backbone.Layout for Backbone.LayoutView 2012-10-07 16:22:45 -04:00
Tim Branyen 479dbf3eac added unit test backing attrs 2012-10-06 16:55:10 -04:00
Tim Branyen fe96e7d4fc fixed element id issue 2012-10-06 16:52:28 -04:00
Tim Branyen e8fa5daeea performance tweaks 2012-10-06 16:42:27 -04:00
Tim Branyen b52f553c73 removed dead code 2012-10-06 12:36:21 -04:00
Tim Branyen 1eb7d52255 fixed render bug 2012-10-06 03:43:55 -04:00
Tim Branyen c2dfcc0e9c release notes 2012-10-05 02:59:33 -04:00
Tim Branyen bb182e36cf readme update 2012-10-05 02:52:40 -04:00
Tim Branyen bceeedd900 reuse elements 2012-10-05 02:05:55 -04:00
Tim Branyen a13d45ab1e moved afterRender logic 2012-10-05 01:57:06 -04:00
Tim Branyen 6c2caf717d removed logging module 2012-10-04 21:04:07 -04:00
Tim Branyen 741a29f599 added clean to gitignore, built latest, and huge refactoring 2012-10-04 20:58:34 -04:00
Tim Branyen ebceee564e full test coverage 2012-10-04 20:52:52 -04:00
Tim Branyen c09eec16b5 tests passing, readme cleaned 2012-10-04 15:04:28 -04:00
Tim Branyen 04bb9629a4 major refactorizing 2012-10-04 14:01:33 -04:00
Tim Branyen d2ec351488 proxying the views properties for chaining purposes, Closes GH-156 2012-09-29 16:50:43 -04:00
Tim Branyen 41065594fe updated remove check to only remove the correct sub view, Closes GH-160 2012-09-29 16:44:26 -04:00
Tim Branyen 3c8a8c3615 changed license formatting and removed dead code path from source 2012-09-29 16:08:01 -04:00
Tim Branyen a8ee9d881b Merge pull request #167 from jugglinmike/node-render
Fix bug in HTML rendering in Node.js
2012-09-29 11:29:19 -07:00
Mike Pennisi d60cf1222c Fix bug in HTML rendering in Node.js
When supplied with a Cheerio instance (instead of a string of HTML), the
Node.js-specific `html` and `append` methods should reference the
complete outer HTML (not just the contents) as generated by Cheerio's
`render` method.
2012-09-29 10:19:58 -04:00
tbranyen 284fe4a35d updated with jam config 2012-09-14 15:29:43 -04:00
tbranyen 46a79fec4a version bump to 0.6.6 2012-09-03 12:46:29 -04:00
tbranyen e90f86ff40 only allow force inside _removeView if the view contains a parent 2012-09-02 13:03:41 -04:00
tbranyen df8d0a5468 updated when renderDeferred is set to eliminate async bugs with lists, Closes GH-150 2012-09-02 12:05:06 -04:00
tbranyen 043ff32e2a updated comment 2012-09-02 11:37:08 -04:00
tbranyen 39c5b42c7a force remove views when jQuery#remove is explicity called Closes GH-148 2012-09-02 11:35:34 -04:00
tbranyen 5100e221cd updated to fix afterRender issue 2012-08-27 17:30:01 -04:00
tbranyen 8c7a73463b undid intentional error in example for testing 2012-08-22 14:01:05 -04:00
tbranyen 4bcf693ed5 Added better error handling for missing and updated documentation, Closes GH-141 2012-08-22 13:48:56 -04:00
tbranyen b3c1e6c85a version bump w/ events fix 2012-08-21 14:40:48 -04:00
tbranyen d5af8f65ea potential events fix 2012-08-21 13:17:10 -04:00
tbranyen af63d49af4 start on events reduced test case, need to get this to fail 2012-08-21 12:00:16 -04:00
tbranyen a83b7d10fc version update in readme 2012-08-16 01:27:23 -04:00
tbranyen 35bb091756 version bump to 0.6.4 2012-08-16 01:24:23 -04:00
tbranyen 02cb0210fd example showing a layout without a template 2012-08-16 00:53:18 -04:00
tbranyen 061c5de807 added in early return and some refactoring plus unit test to resolve afterRender not firing, Closes GH-137 2012-08-16 00:48:18 -04:00
tbranyen 7ee5d9605b bumped version to 0.6.3 2012-08-15 21:12:34 -04:00
tbranyen a2ff666164 updated examples 2012-08-15 12:51:24 -04:00
tbranyen 4c1bdaf4cd fixes memory leak where views were not being properly removed 2012-08-15 12:42:11 -04:00
tbranyen ea9297b137 whitespace changes and formatting 2012-08-15 00:34:14 -04:00
tbranyen 8bcbd738f2 fixed the way prefixes are set to be more consistent, Closes GH-131 2012-08-15 00:22:35 -04:00
tbranyen 1fa5f0a449 fix 0.6 example 2012-08-15 00:12:32 -04:00
tbranyen 86030967e4 ensuring collection can still be attached properly 2012-08-10 16:23:20 -04:00
tbranyen 64bdf86355 bumped version to 0.6.2 2012-08-10 14:44:43 -04:00
tbranyen f673aaa5cf vastly reworked how options are utilized, no longer copying all options to instance, Fixes GH-125. Thanks to @mitya777 for finding this. 2012-08-10 14:40:47 -04:00
tbranyen 2e180fd0ed fixed regression when removed delegateEvents from renderCallback, Fixes GH-126 2012-08-10 14:25:52 -04:00
tbranyen c4f5239b04 upgraded jquery 2012-08-10 13:36:41 -04:00
Tim Branyen 044a7a9bec Merge pull request #127 from Systemfault/master
Fix to make LayoutManager work with jQuery 1.8
2012-08-10 10:32:57 -07:00
Systemfault 9397981cb4 Fix for jQuery 1.8's changes to .then() 2012-08-10 02:23:19 -04:00
tbranyen 3dce59ff3d removed highly embarassing console.log, hope nobody noticed... >_> 2012-08-09 14:23:54 -04:00
tbranyen e2ed071a3a fixed resolving issue with afterRender, Closes GH-122 2012-08-09 14:02:13 -04:00
tbranyen 58fc80eef2 finally reproduced GH-122 2012-08-09 00:38:04 -04:00
tbranyen 256dbbc2b7 updated test for GH-122 2012-08-09 00:33:55 -04:00
tbranyen e3d2fb4b20 added unit test for GH-122 2012-08-08 19:08:42 -04:00
tbranyen d1f699681f bumped version to 0.6.1 2012-08-08 16:01:04 -04:00
tbranyen 97d4cc6432 added in better event delegation 2012-08-08 15:53:44 -04:00
tbranyen aa1666e57f fixed view order rendering 2012-08-06 13:09:41 -04:00
tbranyen 30f1c7d09e removed unused cidStart 2012-08-05 21:23:10 -04:00
tbranyen f414422601 fixed duplicate views being inserted, broken override logic, potentially Fixes 117 and 116 2012-08-05 21:12:46 -04:00
tbranyen 72286fc6c2 Added unit test showing GH-115 can be closed 2012-08-05 20:06:47 -04:00
tbranyen f126fdb5b8 Fixes GH-108 allowing multiple renders with callback style 2012-08-05 20:03:42 -04:00
tbranyen c59ec6f0b6 added in node.js documentation 2012-08-03 21:29:10 -04:00
tbranyen 98294be09f updated documentation and changelog 2012-08-03 16:49:53 -04:00
Tim Branyen 9993628881 Merge pull request #110 from tbranyen/wip
Version 0.6.0
2012-08-03 13:40:24 -07:00
tbranyen 078d21e9aa stable release 2012-08-03 16:41:56 -04:00
tbranyen c22fd32b8f merged with master 2012-08-03 16:16:55 -04:00
tbranyen 2d9081dd23 updated examples 2012-08-03 16:13:56 -04:00
tbranyen 4c82e650f7 updated to allow subViews renders to be withheld until a parent's render is triggered 2012-08-03 16:05:15 -04:00
tbranyen 9dc534c721 fixed remaining View rentention bug 2012-08-03 13:36:49 -04:00
tbranyen f7e6a14d4f latest fixes to layoutmanager 2012-08-03 13:14:18 -04:00
tbranyen 289d6beb93 backported changes to lm master 2012-07-25 15:33:57 -04:00
tbranyen 8bd04b26a0 only remove views that have rendered and give child views access to their parent 2012-07-25 15:28:02 -04:00
tbranyen 21c4311f42 merged from master 2012-07-25 00:32:46 -04:00
tbranyen 22d0027238 reverted deferred ordering and put in safety check for managed handlers 2012-07-25 00:20:08 -04:00
tbranyen 49c4909916 reworking documentation for 0.6.0 2012-07-25 00:08:26 -04:00
tbranyen 6009eebd21 updated to fix duplicate issues, ported from master 2012-07-24 23:29:59 -04:00
tbranyen 60fd98224e style change 2012-07-24 23:23:47 -04:00
tbranyen 9f9fe3a65d style change 2012-07-24 23:23:27 -04:00
tbranyen bc6dddc7da reverted back to using hasRendered 2012-07-24 23:20:23 -04:00
tbranyen cdb5eadbfc spacing 2012-07-24 23:17:26 -04:00
tbranyen 52e0179435 version bump to beta 2012-07-24 23:00:57 -04:00
tbranyen 8983c90f0b fixes to removeView that fixes duplicate bug 2012-07-24 22:56:20 -04:00
tbranyen 88104091c5 fix duplicate view bug 2012-07-23 00:33:12 -04:00
tbranyen 7f019b5dd2 added screencast 2012-07-21 14:44:40 -04:00
tbranyen 57b08764f1 moved render deferred to before fetch 2012-07-21 02:39:56 -04:00
tbranyen c225acaf2f fixed typo 2012-07-19 15:00:35 -04:00
tbranyen a59a5c5e14 added better error handling for missing files 2012-07-19 02:12:10 -04:00
tbranyen a85e5a542a fixed package.json version 2012-07-19 02:03:51 -04:00
tbranyen dfbb44f8c1 latest wip 2012-07-19 01:59:17 -04:00
Tim Branyen ed64ca9e8e Merge pull request #106 from tbranyen/node
Node.js support
2012-07-18 22:50:00 -07:00
tbranyen 8cfba1d6c0 removed docco stuff 2012-07-19 01:48:53 -04:00
tbranyen d68ca6e03f moved basic 2012-07-19 01:47:50 -04:00
tbranyen 16cb540283 added gitignore 2012-07-19 01:44:07 -04:00
tbranyen 6e7db37878 dunno 2012-07-19 01:44:07 -04:00
tbranyen b4511ebd70 . 2012-07-19 01:44:07 -04:00
tbranyen 99c806bf97 working node demo, pushed to NPM as well under version 0.0.0 - experimental 2012-07-19 01:43:11 -04:00
tbranyen a4fd77f699 isManaged isn't used anymore 2012-07-17 11:59:34 -04:00
tbranyen a79513a8b7 experimental swap stuff 2012-07-17 00:11:42 -04:00
tbranyen 4f0721dadc latest 2012-07-16 13:54:49 -04:00
tbranyen 890553c53c oh god 2012-07-13 03:19:33 -04:00
tbranyen d3555a7571 no progress, oh well, maybe tomorrow 2012-07-11 17:24:18 -04:00
tbranyen b90e57341d all unit tests fixed and pass, still needs some work, but before/afterRender works 2012-07-10 17:56:07 -04:00
tbranyen e7462057e5 changed how views are constructed, render is now the options.render override, nesting of layouts 2012-07-10 16:49:54 -04:00
tbranyen 211ff13866 added unit test ensuring keep: true 2012-07-10 13:12:10 -04:00
tbranyen 1797e88452 built 2012-07-10 13:12:00 -04:00
tbranyen 0118573746 patched setView to not break on going from append to non-append modes Closes GH-99 2012-07-10 13:11:52 -04:00
tbranyen 97190e5e3e added unit test ensuring keep: true 2012-07-10 13:03:36 -04:00
tbranyen e984d2ebad built 2012-07-10 12:43:23 -04:00
tbranyen cff1864aec patched setView to not break on going from append to non-append modes Closes GH-99 2012-07-10 12:43:10 -04:00
tbranyen 0553eabc81 updated to fix render regression 2012-07-09 13:44:16 -04:00
tbranyen 55fbafe0cc updated documentation 2012-06-29 02:57:19 -04:00
tbranyen 26df4c8ba6 minor readme tweak 2012-06-27 13:34:02 -04:00
tbranyen 2ce43fa526 updated cleanup section in readme 2012-06-27 13:33:03 -04:00
tbranyen 09f01839bb updated formatting in tests 2012-06-27 13:32:13 -04:00
tbranyen 4084e4dfb5 updated to support renders outside of lm, Closes GH-98 2012-06-24 14:34:16 -04:00
tbranyen 3f85a8fb0b cleaned up keep logic 2012-06-18 01:34:16 -04:00
tbranyen 5ee1bdfdc5 updated release 2012-06-17 14:39:21 -04:00
tbranyen 06fd5ea8b6 tagging 0.5.2 2012-06-17 14:37:52 -04:00
tbranyen 172c78657b removed unused variable test and added some comments 2012-06-17 03:48:57 -04:00
tbranyen ff4c399f91 bumped to 0.5.2pre 2012-06-17 02:56:24 -04:00
tbranyen ab97d4ae84 updated readme 2012-06-17 02:53:32 -04:00
tbranyen a219cf5160 fixed comments 2012-06-17 02:50:08 -04:00
tbranyen effcf98f59 removed the keep:true 2012-06-17 02:44:31 -04:00
tbranyen 93c3b14344 fixed issue with array rendering 2012-06-17 02:43:15 -04:00
tbranyen b2c2f5dad4 updated examples and updated layoutmanager to allow render to be assigned in initialize 2012-06-16 21:34:23 -05:00
Tim Branyen f899bad57f Merge pull request #93 from dancannon/patch-1
Fixed keep option
2012-06-12 11:24:27 -07:00
Daniel Cannon 384ca553c3 Fixed keep option 2012-06-12 20:10:07 +02:00
tbranyen 2231f4aa3c fixed readme updated min 2012-06-07 23:17:36 -04:00
tbranyen 73c3bae99e added keep property, renamed license, updated changelog, bumped version to 0.5.1 2012-06-07 08:22:46 -04:00
tbranyen 441f6e3e41 Merge branch 'master' of github.com:tbranyen/backbone.layoutmanager 2012-06-07 19:05:12 -04:00
tbranyen d6011c2f0a updated readme 2012-06-07 19:05:02 -04:00
Tim Branyen 1c98d314f2 Merge pull request #92 from atomictag/master
Correctly call remove() when child views are swapped. Fix #90
2012-06-06 08:28:00 -07:00
Davide Mancuso 90a895f54f Correctly call remove() when child views are swapped. Fix #90
with minor formatting changes
2012-06-06 17:19:27 +02:00
Davide Mancuso f7be7f25a9 Correctly call remove() when child views are swapped. Fix #90 2012-06-06 11:23:44 +02:00
tbranyen 1295946a09 fix readme for release 2012-06-06 04:21:58 -04:00
tbranyen d13216505c fixes duplication when using removeView 2012-06-06 04:00:15 -04:00
tbranyen 1493cfe3ec updated to fix major memory leak problem and clean up views when swapping 2012-06-06 03:50:39 -04:00
tbranyen 89695bcce8 updated example 2012-06-04 09:40:22 -04:00
tbranyen c322b46255 fixed broken removeView 2012-06-03 20:01:46 -04:00
Tim Branyen b41546d6f5 Merge pull request #84 from tbranyen/fixes
Fixes
2012-06-02 22:00:03 -07:00
tbranyen ced79a086d api and readme changes 2012-06-03 00:59:30 -04:00
tbranyen 1cc0afc7d3 fixed unit tests 2012-06-03 00:22:17 -04:00
tbranyen 9120f629a9 docs changes 2012-06-03 00:21:13 -04:00
tbranyen adc689538e more docs 2012-06-01 16:49:38 -04:00
Tim Branyen 805a812487 Merge pull request #83 from GeReV/master
Issue #82: Exception when appending a view after setting a view
2012-06-01 16:39:57 -04:00
tbranyen cb302af71f minor refactor and changes 2012-06-01 16:36:57 -04:00
Tim Branyen 8f5853bac6 Merge pull request #83 from GeReV/master
Issue #82: Exception when appending a view after setting a view
2012-06-01 13:28:59 -07:00
Tim Branyen 5b5692cc6b Merge pull request #87 from groovetrain/fixes
Changes to README.md to reflect change from insert to insertView
2012-06-01 13:27:45 -07:00
groovetrain 3b64572e5e Update README.md to reflect change from insert to insertView 2012-06-01 16:56:46 -03:00
tbranyen edbd269181 added new filter and get methods, normalized the view methods 2012-06-01 00:19:25 -04:00
tbranyen 79b364e15b latest 2012-05-31 23:35:36 -04:00
tbranyen 67d6f8af86 remove bug fixed 2012-05-25 17:50:20 -04:00
Amir Grozki 4165c8750e Requested changes. 2012-05-25 19:12:01 +03:00
tbranyen 5247230939 changelog/readme updates 2012-05-25 02:28:27 -04:00
tbranyen 5be9842d6b added in GeReV's fix to layoutmanager 2012-05-25 02:26:33 -04:00
tbranyen 18281c009e loads of fixes 2012-05-25 02:22:04 -04:00
tbranyen 6d85a696e7 loads more unit tests and bug fixes 2012-05-25 01:58:36 -04:00
tbranyen 36c2446f41 unit tests 2012-05-24 08:56:45 -04:00
Amir Grozki 4bea1c5368 Fixed issue when appending views with view(). 2012-05-20 10:53:37 +03:00
tbranyen 5073c4551a in progress 2012-05-16 08:27:58 -04:00
tbranyen ebfe6e64a3 tagging 0.4.1, fixes list dupe regression 2012-05-15 02:18:31 -04:00
tbranyen ca1605beab tagging 0.4.0 release 2012-05-14 00:03:01 -04:00
tbranyen 151ebccd14 jquery plugins should be runnable inside render callbacks now 2012-05-13 23:58:51 -04:00
tbranyen 294b880cab lots of bug fixes and changes to readme 2012-05-13 21:48:42 -04:00
tbranyen d1b20eb4a1 testing new features 2012-05-13 17:34:50 -04:00
tbranyen 41d4232664 minor fixes 2012-05-06 09:31:39 -04:00
tbranyen 79231c1cd4 readme and grunt updates 2012-05-05 18:49:37 -04:00
tbranyen be2fbf3e05 initial 0.4 2012-05-05 18:31:34 -04:00
Tim Branyen ab73ca2b91 Merge pull request #73 from fbuchinger/patch-1
Handlebars configuration example doesn't work
2012-04-30 13:52:52 -07:00
fbuchinger 323e0314d9 handlebars configuration example didn't work for me... when i changed it as stated in my pull request, i could get rid of the script error 2012-04-25 13:44:01 +03:00
tbranyen 839971da74 bumped to version 0.3.0 2012-04-10 14:21:15 -04:00
tbranyen b2ffe48f85 view and setView are now always available on Backbone.View's, Closes GH-63 2012-04-08 16:40:10 -04:00
Tim Branyen 96aec7d085 Merge pull request #66 from DavidQL/master
Fixing typo in README
2012-04-08 08:41:27 -07:00
DavidQL ff3316289c Fixing typo 2012-04-07 21:22:09 -06:00
tbranyen 49d0ad07a1 updated grunt config to latest 2012-03-25 12:03:22 -04:00
tbranyen e531fd628c allow setViews to chain 2012-03-20 01:53:46 -04:00
tbranyen 21a3398035 updated to clean append views 2012-03-18 14:34:39 -04:00
tbranyen 9b242fa476 updated license banner Closes GH-60 2012-03-18 13:56:42 -04:00
tbranyen 1b6dac990c updated config and license date 2012-03-11 01:31:58 -05:00
tbranyen 7e100d9735 corrected resolveWith to use array 2012-03-03 14:03:35 -05:00
tim a2dc789f98 fixed some bad wording 2012-03-02 18:53:18 -05:00
tim 77d251b880 unit test for #51, unable to reproduce problem 2012-02-23 01:51:32 -05:00
Tim Branyen 2250cd9ad2 Merge pull request #54 from amccloud/context
Made the render callback and deferred context for LayoutManager and mana...
2012-02-22 15:17:57 -08:00
Andrew McCloud d0bcb393f1 Made the render callback and deferred context for LayoutManager and managed Backbone views the view.
I found myself constantly binding the function I pass to view.render or deferred.then to the view. The el argument is no longer necessary in favor of this.el but i've left it in for backwards compatibility.
2012-02-22 14:35:23 -08:00
tbranyen f7789170a7 updated code to properly trigger callback functions and update render count 2012-02-22 03:29:09 -05:00
tbranyen 31e4d877ab setTimeout in resolve causes redraw flicker 2012-02-22 01:05:17 -05:00
tbranyen 7e9d844f37 unit test for #52, not able to reproduce 2012-02-22 00:58:08 -05:00
tbranyen 0104269729 Fixed layout so that it can render without a template provided, Closes GH-49 2012-02-22 00:26:56 -05:00
tbranyen ce8172780c Stop wrapping Views if they are already managed, Closes GH-48 2012-02-21 23:58:36 -05:00
tbranyen b008a868a3 added support for array notation to denoate append views 2012-02-21 05:00:21 -05:00
tbranyen 06aff10acd updated to backbone 0.9.1, underscore 1.3.1 and jquery 1.7.1 in test dir 2012-02-20 12:04:26 -05:00
tbranyen 49533dd69a fixes nested events not firing /cc @tvpmb Closes GH-46 2012-02-16 13:55:18 -05:00
tbranyen ca5182d1b7 adding in delegateEvents after partial 2012-02-16 13:20:19 -05:00
tbranyen 16a022bca6 changed Backbone.LayoutManager.View to just be a Backbone.View 2012-02-16 11:38:58 -05:00
tbranyen 213281c522 refresh subviews on subsequent renders, Closes GH-45 2012-02-16 11:06:51 -05:00
tbranyen 1d37415ec8 removed duplicate release history item 2012-02-15 18:24:54 -05:00
tbranyen bda3e4adc8 fixed merge conflicts 2012-02-15 18:18:02 -05:00
tbranyen 8e165db548 touched up section on insert 2012-02-15 18:12:20 -05:00
tbranyen f9bb231582 further docs additions/corrections 2012-02-15 16:54:44 -05:00
tbranyen 7967c60d13 added javascript syntax to list view 2012-02-15 16:34:59 -05:00
tbranyen d1a4877fe3 changed html syntax to plain 2012-02-15 16:33:49 -05:00
tbranyen 1ffb1cf7b5 significant docs changes 2012-02-15 16:31:18 -05:00
tbranyen 75dc6ffe8d removed cleaning on appended items 2012-02-15 12:33:01 -05:00
tbranyen 4b6f7e0525 major update that adds in a new cleanup method and scrubs subviews recursively 2012-02-14 18:12:44 -05:00
Tim Branyen 4c47332086 Merge pull request #42 from simax/master
Readme Typo
2012-02-11 16:00:09 -08:00
Simon Lomax a8fa9ac035 Readme Typo 2012-02-10 17:22:02 +00:00
tbranyen 4cbebe54bd clear the stack with setTimeout 2012-02-08 01:36:56 -05:00
Tim Branyen 2818bb0ca2 Merge pull request #37 from searls/patch-1
Makes the default underscore configuration a little more foolproof
2012-02-07 21:40:38 -08:00
Justin Searls 7cfdafdc0d Invokes the template and forces the context to be that of the provided template context. 2012-02-06 18:56:57 -05:00
tbranyen bc4a2ba85b updated documentation to latest version 2012-02-03 13:47:57 -05:00
tbranyen 6dd24e35c6 fixed remaining issues 2012-02-03 13:32:19 -05:00
tbranyen a751c51b91 fixes re-rendering of new views 2012-01-31 14:13:53 -05:00
tbranyen 409d8c865d updated fix for async events 2012-01-31 14:05:11 -05:00
tbranyen 84fc9a3b91 fixes to events 2012-01-31 01:36:43 -05:00
tbranyen f9a52a2c81 updated unit tests to be asynchronous 2012-01-31 01:15:44 -05:00
tbranyen 78d97b53dc removing demo page 2012-01-31 01:13:34 -05:00
tbranyen b791072e61 passing all tests now 2012-01-31 01:13:22 -05:00
tbranyen cb3a71974c more progress, tests starting to pass =) 2012-01-30 15:26:02 -05:00
tim 0add6b4291 added render mapping 2012-01-30 00:21:53 -05:00
tbranyen 4764903039 initial start at refactor 2012-01-29 20:45:15 -05:00
59 changed files with 6864 additions and 14105 deletions
+1
View File
@@ -0,0 +1 @@
service_name: travis-ci
+11
View File
@@ -0,0 +1,11 @@
root = true
[*]
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
+5
View File
@@ -0,0 +1,5 @@
# Protect whitespace line ending.
* text=auto
# Ensure line endings are always LF.
text eol=lf
+4
View File
@@ -0,0 +1,4 @@
node_modules
test/report
test/tmp
bower_components
+146
View File
@@ -0,0 +1,146 @@
{
"maximumLineLength": 80,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
},
"validateLineBreaks": "LF",
"validateQuoteMarks": { "mark": "\"", "escape": true },
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireSpaceAfterBinaryOperators": [
",",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowSpaceBeforeBinaryOperators": [
","
],
"requireSpacesInConditionalExpression": true,
"requireKeywordsOnNewLine": [
"catch",
"while"
],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireParenthesesAroundIIFE": true,
"requireCommaBeforeLineBreak": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"disallowSpaceAfterPrefixUnaryOperators": [
"++",
"--",
"+",
"-",
"~",
"!"
],
"disallowSpaceBeforePostfixUnaryOperators": [
"++",
"--"
],
"disallowImplicitTypeConversion": [
"numeric",
"boolean",
"binary",
"string"
],
"disallowKeywords": [
"with"
],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowTrailingWhitespace": true,
"disallowMixedSpacesAndTabs": "smart"
}
+17
View File
@@ -0,0 +1,17 @@
{
"browser": true,
"boss": true,
"immed": false,
"eqnull": true,
"maxlen": 80,
"es3": true,
"curly": true,
"quotmark": "double",
"trailing": true,
"unused": true,
"undef": true,
"node": true,
"globals": {
"define": true
}
}
+19
View File
@@ -0,0 +1,19 @@
language: node_js
node_js:
- "0.10"
- 0.12
- iojs
branches:
only:
- master
- wip
before_script:
- npm install -g grunt-cli
after_success: cat test/report/lcov.info | node_modules/.bin/coveralls --verbose
matrix:
fast_finish: true
+386
View File
@@ -0,0 +1,386 @@
## 0.10.0 ##
* Updated dependencies and locked Backbone to 1.1.2
* Removed `then` method, if you want to use promises, call `.promise().then`
## 0.9.7 ##
* Adds in a `cleanup` event whenever a view has been removed
* Fully support & test against LoDash 3.0 and Underscore
## 0.9.6 ##
* Full Browserify support.
* The options object is now cloned when passed into a Layout.
* Fixes a bug with `setView` removing deeply nested views.
* Fixes compatibility with Backbone Epoxy.
* Fixes a bug where a removed view could still be rendered asynchronously.
* `renderViews` now accepts an array of Views to render batched.
* Added an `empty` event that triggers when all Views are removed from a parent.
## 0.9.5 ##
* Removed `partial` shim from Node compatibility layer. No longer necessary.
* Removed `getAllOptions`, no longer necessary with 1.1.0.
* Now run our tests against the latest stable and unstable Node.js.
* `setView` will never render a View now.
* Broke out Grunt tasks into separate files.
* Enforcing code style with JSCS.
## 0.9.4 ##
* Fixed trimming for incoming templates so that multiple top level elements
warning isn't triggered annoyingly.
* Upgraded to work with Backbone 1.1.0.
* Minor housekeeping commits.
## 0.9.3 ##
* Style/spelling updates to markdown files.
* Broke out `_viewRender` and `_applyTemplate` from their closures and exposed
them on the LM object.
* Parsing with `$.parseHTML` to allow leading whitespace and retain whitespace
in templates.
* Using Bower to manage testing depenencies.
* Fixes for Underscore 1.5.
## 0.9.2 ##
* Updated AMD define shim to use UMD which fixes issues in some R.js builds.
* Updated views property to accept functions that return values, see #367.
* Fixed Node.js file lookup that was scoping to `__dirname`.
* Ensured all examples work.
* Hooked up Coveralls for monitoring and displaying code coverage during builds.
## 0.9.1 ##
* Fixed regression from 0.8->0.9 where the new AMD wrapper would fail to work
correctly in an r.js build.
* Fixed regression from 0.8->0.9 where the Node.js branch code was not updated
correctly and lack of default `fetchTemplate` tests didn't report the
failure.
## 0.9.0 ##
* Upgraded all internal dependencies.
* Batch rendering via jQuery collections has been added. Check out the
`htmlBatch` method.
* Full on AMD support. No more shimming necessary!
* `render` now returns the View instance to maintain parity with other
`Backbone.View` tutorials and plugins.
* `fetch` and `render` overrides have been renamed to `fetchTemplate` and
`renderTemplate` respectively.
* New method `renderViews` which will only render nested Views and not the
parent view, useful for top level layouts.
* Event bubbling has been removed.
* Named regions for selectors using the `section` object.
* Greatly refactored how the `async()` methods work. This allows every method
of the `render` lifecycle to be asynchronous and maintain the context of the
View.
## 0.8.8 ##
* Upgraded Cheerio dependency to v0.11.0.
* Many optimizations and fixes to `getViews` by @jugglinmike. This includes
fixes for issues like `removeView` on an invalid selector.
* `cleanup` is now called with the proper context.
* @SBoudrias added `.gitattributes` and `.editconfig` to ease development
stress for our contributors.
* Fix provided by @adamdicarlo to fix a bug where re-rendering with
empty rendered contents would not replace the existing content.
## 0.8.7 ##
* Upgraded Cheerio dependency.
* Trim templates in `el: false` Views to fix an issue with passing contents
into `$()`.
## 0.8.6 ##
* We now log a warning if you use mutliple top level elements inside a View's
template with `el: false`. This will not affect most developers. If you
wish to suppress the warnings you can run `Backbone.Layout.configure({
suppressWarnings: true });`. This is documented in the Wiki:
https://github.com/tbranyen/backbone.layoutmanager/wiki/Configuration#el
* Fixed minor bug with `cleanup` being defined on `options` instead of the instance.
* Changed behavior so that __all__ views are removed when you call `remove`.
* Upgraded to Backbone 1.0.
* Upgraded to Node 0.10.
## 0.8.5 ##
* Fixed View duplication bug with multiple top level elements (`el: false`).
* Fixed the deletion of the template property in initialize that would cause
bugs with View inheritance.
* Fixed issue with `getView` and `_.where` object.
## 0.8.4 ##
* Fixed package dependency issues with jQuery.
* Updated Cheerio version, which includes fixes to `filter`.
* Several fixes to the `el: false` implementation.
* Removed custom `$.contains` Node.js implementation.
## 0.8.3 ##
* Fix for deep nested `el: false` elements.
## 0.8.2 ##
* Fixed parts of the Node build.
* Changed from parallel rendering to serial loading which will make the render
process significantly more stable.
* Changed signature to `options.partial` and greatly fixed the way `noel` is
handled.
## 0.8.1 ##
* Updated JamJS configuration settings.
* Fixed event delegation when self managing the View element.
* Fixed edge case with `afterRender` causes the element to not be in the
parent container.
* Fixed re-rendering when self managing the View element.
## 0.8.0 ##
* Massive Node.js refactor, including: unit testing, significantly better
browser parity, and allowing more seamless browser/server View sharing.
* Ability to disable `Backbone.View#el` wrapper element using `el: false` and
opt for the first child inside the template instead. Very experimental!
* Added Backbone event bubbling from nested Views to parent.
* The `getView` function can receive a `_.where` object now, to easily filter
through the Views.
* Updated `getView` to have an `undefined` first argument to be passed allowing
for an optional selector.
* Changed Grunt configuration from JavaScript to CoffeeScript.
* Added a `removeView` function to match `setView`, `getView`, etc.
* Removed `LayoutManager` and `LayoutView` aliases.
* Removed `data` alias in favor of `serialize`.
* Removed `append` alias in favor of `insert`.
* Renamed `_options` to `getAllOptions` making it an endorsed method to use.
* Upgraded minimum support to Backbone 0.9.9, which will invoke `stopListening`
automatically for you.
* Internally using `Backbone.Events#once` to solve `afterRender` woes.
* Class method `cache` now allows you to override contents.
* Class method `setupViews` now allows you to manage many Views by passing an
array of Views.
* Can now directly set a template function to the `template` property and not
have to override fetch with an `_.identity` function.
* Miscellaneous code cleanup and minor bug/refactor fixes.
## 0.7.5 ##
* Updated lookup for `serialize` and `data` to also look on the instance so
that `configure` doesn't always override.
### 0.7.4 ###
* Simplified insertion methods.
* Fixed named function expression bug in IE.
### 0.7.3 ###
* Refactored `_.extend` to `LayoutManager.augment` to work with Lo-Dash and
underscore.
* Normalized rendering order, when the parent has already rendered.
* Added better error handling for node.js build.
* Updated error message for node.js build.
* Added in Travis-CI and README updates.
### 0.7.2 ###
* Fixed cheerio rendering bug with the latest version.
* Explicity depend and require underscore in NPM.
* Repeated subViews are a thing of the past :D.
* Fixed serialize/data priority.
* Fixed lodash issues and added in separate lodash testing.
### 0.7.1 ###
* Views that have already been rendered can now be inserted into existing Views.
* Fixed the logic that decides when to remove Views.
* Fixed issue with `cleanup` not being on nested Views.
* Miscellaneous fixes (inc. null checks, perf. updates, etc).
* Removed minified build file from the repo.
* `insertViews` can now accept an array of Views.
* `render` can now be asynchronous to allow template engines like dust.js to
work seamlessly, works identical to `fetch`.
* Overriding the template option at initialization level wil now override the
constructor option.
### 0.7.0 ###
* Refactored source to be less cryptic.
* 100% test code coverage.
* Re-wrote much of the internals.
* Performance greatly improved, especially with large lists.
* Removed `swapLayout`.
* `serialize` is deprecated and replaced by `data`.
* `render(callback)` is deprecated to `render().done()` deferreds only.
* Automatically unbind `model` and `collection` events inside `cleanup`.
* `Backbone.LayoutView, `Backbone.Layout`, and `Backbone.View` (with `manage`
set to `true`) are now all identical.
* `paths` is now a String `prefix`, set this to the folder where your templates live.
* `afterRender` now occurs after the `render()` deferred.
* `myView.render().view` now allows you to attach `view.el` after a render for
some nice one-liners.
`
new Backbone.LayoutView({ template: "#t" }).render().view.$el.appendTo("body");
`
### 0.6.6 ###
* Fixed asynchronous fetching bug that could in some circumstances duplicate
list items
* Calling `remove` on a View now completely removes it from LayoutManager
* Fixed issues with `afterRender`
* Better error handling for when `manage: true` is missing
### 0.6.5 ###
* Corrected event binding behaviors depending on the parent.
### 0.6.4 ###
* Fixed regression with `afterRender`
### 0.6.3 ###
* Fixed a memory leak that existed with appended Views
* Updated all examples
* Fixed regression with events being bound to Layouts
* General performance tweaks
* Updated cheerio dependency to 0.9.2 for the Node implementation
### 0.6.2 ###
* Updated to support jQuery 1.8
* Fixed missing events when calling `view.render`
* Fixed issues with `afterRender` not triggering
* No longer copying options to the View instance
### 0.6.1 ###
* Patch release fixing issues and upgrading Node.js dependencies
* Fixed error where inserted views rendered out of order #116, #117
* Fixed issue where events were not being bound correctly #118
### 0.6.0 ###
* Overriding `render` is now deprecated. Refer to `beforeRender` and
`afterRender`.
* Added a `swap` method that can be used on a Layout which allows you to
dynamically swap out the entire contents, but retain the rendered subViews.
* Code cleanup, removing unused code paths, properties, features, etc.
* Fixes to setView to not break when moving from an append mode to non-append
mode.
* Several bug fixes.
* Added more unit tests.
### 0.5.2 ###
* More methods can be overwritten from initialization
* Render can now be bound like `this.collection.on("reset", this.render, this);`
* Fixes to `keep: true` and append example, only checking `keep` if View has
already rendered
### 0.5.1 ###
* Patched massive memory leak and missing remove on setView
* Fixed bug with Named Function Expression breaking IE compatibility when
minified
* Added `keep: true` to View's to stop them from being removed pre-render
### 0.5.0 ###
* Tons of new unit tests
* More API normalization
* Collection rendering bug fixes
* New View methods
+ insertView & insertViews
+ getView and getViews
### 0.4.1 ###
* Fixed major regression regarding list duplication
### 0.4.0 ###
* Detach no longer internally happens on the root Layout
* `manage` function inside a custom render has a new property `raw` for getting
at the actual View instance
* Collection lists bugs solved
* Made `makeAsync` a private class method
* Cleanup method is now called whenever `remove` is called
* Major fixes allowing for single View append
* View function no longer requires "" for inserting into parent View
* SubView render functions only resolve after the element has been attached
to its parent View.
### 0.3.0 ###
* Context is now consistent in either callbacks or deferreds
* `setViews` is now chainable
* `view` and `setViews` are now available at all times on `Backbone.View`'s
* Bug fixes regarding list duplication
### 0.2.1 ###
* Made `template` optional inside of `Backbone.View`
* Added custom cleanup function to handle the removal of any custom events
* insert no longer requires a selector
* Several performance improvements along with general stability changes
### 0.2.0 ###
* Major re-write to codebase that eliminated a lot of repetitive and cludgy
code
* Deprecated the need to extend `Backbone.LayoutManager.View`
* All View `render` methods return promises and can accept a callback
* Views now render themselves first and then resolve/trigger the callback once
all the children are rendered. This helps with jQuery plugins.
### 0.1.2 ###
* Major patch for re-rendering layouts that would lose events
* Added new API method detach
### 0.1.1 ###
* Minor patch release (that removes an undocumented feature)
* Fixed issue with events not being registered correctly within lists
### 0.1.0 ###
* Lots of bug fixes!
* Ability to insert views dynamically using the new `view.insert` method.
Useful for collections.
* Setting/resetting sub views possible with new `view.setViews` method.
* All views now have the `view/setViews` methods.
* Updates to allow LayoutManager to be extended easier, along with `events`
being bound automatically during initialization.
### 0.0.4 ###
* Adding views turned into a reusable function called `view`.
* Templates no longer are required to be a string, this allows passing of
compiled template functions.
### 0.0.3 ###
* View renders are internally wrapped to expose a new `render()` method that
when called, re-renders.
* Nested views are possible by adding a `views` sub property which is an object
that contains nested views.
### 0.0.2 ###
* Changed layout `name` property to `template` for consistency.
* Internal second deferred replaces the `viewDeferred` to determine when an
element enters the DOM.
### 0.0.1 ###
* Open sourced on GitHub.
* Initial unit tests.
* Released introduction screencast.
+74
View File
@@ -0,0 +1,74 @@
## Contributing to LayoutManager ##
### Filing an issue ###
You're using LayoutManager and something doesn't appear to function the way
it's described or you're thinking something could be done better. Please let
us know. Issues are how the project moves forward; by letting us know what's
bothering you.
* Search the [issues
list](https://github.com/tbranyen/backbone.layoutmanager/issues)
for existing similar issues. Consider adding to an existing issue if you
find one.
* Choose an applicable title. This will be used for a corresponding unit test.
* Provide a unit test or snippet that illustrates the problem. This small
gesture goes a long way in a speedy patch.
### Sending a pull request ###
If you feel confident that you can correct a bug or add a new feature, feel
free to submit a pull request with your changes. Everyone helping makes the
project community instead of a sole proprietorship.
* Link to an existing issue if applicable, create one to start discussion to
ensure everyone is on board with the change and so you don't spend time
writing a fantastic patch we cannot accept.
* Provide a description of what the patch is/does.
* Provide unit tests in the correct file:
+ `test/configure.js` for configuration changes.
+ `test/dom.js` for DOM specific changes.
+ `test/expose.js` for code exposure in various environments.
+ `test/setup.js` for changes that impact `Backbone.View` and
`Backbone.Layout` mirroring eachother.
+ `test/view.js` for all changes that impact the API of LayoutManager
Views.
* Make sure you open the pull request onto the `wip` branch and not `master`
for requests that break the API or add significant functionality changes.
* Open pull requests on `master` only with bug fixes and patch related updates.
### Code style ###
I am very sensitive to maintaining a holistic codebase and that includes a
single code style. Pull requests may be rejected or modified to ensure this
code style is maintained.
* Follow close to [BSD KNF
style](http://en.wikipedia.org/wiki/Indent_style#BSD_KNF_style).
* Use two space, expanded/soft tabs. Use `\t` if you need a tab character in a
string.
* No trailing whitespace, except in markdown files where a linebreak must be
forced.
* Don't go overboard with the whitespace.
* No more than one assignment per var statement.
* Delimit strings with double-quotes ", not single-quotes '.
* Comments must always contain proper punctuation and end with a correct
sentence terminator. Put before the line of code, not at the end of the
line.
* Prefer if and else to "clever" uses of ? : conditional or ||, && logical
operators.
* When in doubt, follow the conventions you see used in the source already.
### Documentation ###
We strive to make the project as easy to consume and use as possible which
means having consistent and up-to-date documentation. If you notice something
is outdated or incorrect, please file an issue, pull request, or make the
change yourself in the Wiki.
* Add documentation to the
[Wiki](https://github.com/tbranyen/backbone.layoutmanager/wiki) if
applicable.
* Release notes are added to the
[readme.md](https://github.com/tbranyen/backbone.layoutmanager/blob/master/README.md)
if applicable.
+11
View File
@@ -0,0 +1,11 @@
module.exports = ->
@loadTasks "build/tasks"
@registerTask "default", [
"clean"
"jscs"
"jshint"
"browserify"
"qunit"
"nodequnit"
]
+11 -11
View File
@@ -1,19 +1,19 @@
Copyright (c) 2011 Tim Branyen
Copyright (c) 2016 Tim Branyen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+63 -571
View File
@@ -1,584 +1,76 @@
backbone.layoutmanager
=======================
LayoutManager
-------------
Created by Tim Branyen [@tbranyen](http://twitter.com/tbranyen) with contributions from [@nedcampion](https://github.com/nedcampion)
## No longer maintained (7/31/18)
Provides a logical structure for assembling layouts with Backbone Views.
Designed to be adaptive and configurable for painless integration.
If you have an existing application that has an issue with LayoutManager, or
wish to champion ownership, please contact
[@tbranyen](https://github.com/tbranyen/backbone.layoutmanager).
Depends on Underscore, Backbone and jQuery. You can swap out the
jQuery dependency completely with a custom configuration.
---
## Tutorials, Screencasts, & Examples ##
[![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Code coverage][coveralls-image]][coveralls-url]
* [Initial Screencast](http://vimeo.com/32765088)
* Example Application: [Demo](http://dev.tbranyen.com/LayoutManager/) & [Source](http://github.com/tbranyen/layoutmanager-example)
## Have a problem? Come chat with us! ##
## Download & Include ##
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tbranyen/backbone.layoutmanager?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Development is fully commented source, Production is minified and stripped of
all comments except for license/credits.
Maintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen), Mike
Pennisi [@jugglinmike](http://twitter.com/jugglinmike), Simon Boudrias
[@SBoudrias](http://twitter.com/Vaxilart), and
[@ssafejava](https://github.com/ssafejava) with help from [awesome
contributors](https://github.com/tbranyen/backbone.layoutmanager/contributors)!
* [Development](https://raw.github.com/tbranyen/backbone.layoutmanager/master/backbone.layoutmanager.js)
* [Production](https://raw.github.com/tbranyen/backbone.layoutmanager/master/dist/backbone.layoutmanager.min.js)
Provides a logical foundation for assembling layouts and views within Backbone.
Designed to be adaptive and configurable for painless integration. Well
tested, with full code coverage, in both the browser and Node.js environments.
Include in your application *after* jQuery, Underscore, and Backbone have been included.
Depends on Underscore, Backbone, and jQuery. You can swap out the dependencies
with a custom configuration.
``` html
<script src="/js/jquery.js"></script>
<script src="/js/underscore.js"></script>
<script src="/js/backbone.js"></script>
#### Documentation ####
<script src="/js/backbone.layoutmanager.js"></script>
http://layoutmanager.org/
#### Migrating from 0.8 ####
http://layoutmanager.org/From-0.8-to-0.9
#### Release notes ####
* Backbone 1.2.0 support
* Ensures cancelAnimationFrame does not exist before polyfilling
[Full Release
Log](https://github.com/tbranyen/backbone.layoutmanager/blob/master/CHANGELOG.md)
#### Contributing ####
Please read and follow the [contribution
guide](https://github.com/tbranyen/backbone.layoutmanager/blob/master/CONTRIBUTING.md)
before contributing.
#### Running the unit tests ####
Open `test/index.html` in your browser to run the test suite.
**Headless:**
Install [Node.js](http://nodejs.org), [Grunt.js 0.4](http://gruntjs.com), and
run `npm install -q` inside the project directory.
Make sure you've installed `grunt-cli` globally with:
``` bash
npm install grunt-cli -gq
```
## Usage ##
This example renders a View into a template which is injected into a layout.
### Create and render a layout ###
This code typically resides in a route callback. If you want to provide a
custom object for your template engine to the layout, use the `serialize`
property.
``` javascript
// Create a new layout using the #main template.
var main = new Backbone.LayoutManager({
template: "#main-layout",
// In the secondary column, put a new Login View.
views: {
".secondary": new LoginView()
}
});
// Render into <body>.
main.render(function(el) {
$("body").html(el);
});
```
Views may also be alternatively defined later:
``` javascript
main.view(".header", new HeaderView);
main.view(".footer", new FooterView);
```
Use the above syntax to change out views at a later time as well, remember to
call the View's `render` method after swapping out to have it displayed.
The `view` method shown above is available on all layout and template views.
### Nested Views ###
You may have a situation where a View is defined that encapsulates other nested
Views. In these cases you should use nested views inside your LayoutManager
View assignments.
Check out this example to see how easy this is:
``` javascript
var main = new Backbone.LayoutManager({
template: "#some-layout",
views: {
".partial": new PartialView({
views: {
".inner": new InnerView()
}
})
}
});
```
You can nest Views infinitely.
#### Alternative method of assigning nested views ####
You may be writing an application that uses a shared LayoutManager, you may
find the `setViews` method handy. This is identical to how views are being
assigned above, it can be used in the following way:
Note: `setViews` is available on all layout and template views.
``` javascript
var main = new Backbone.LayoutManager({
template: "#some-layout"
});
// Bulk reset of all sub views
main.setViews({
".partial": new PartialView({
views: {
".inner": new InnerView()
}
})
});
```
### Structuring a View ###
Each View needs to have a template associated, via the `template` property.
This name by default is a jQuery selector, but if you have a custom
configuration this could potentially be a filename or JST function name.
``` javascript
var LoginView = Backbone.View.extend({
// Tell LayoutManager what template to associate with this View.
template: "#login-template",
// The render function will be called internally by LayoutManager.
render: function(layout) {
// Wrap the layout with this View and call render.
return layout(this).render();
}
});
```
Optionally, you can extend from `LayoutManager.View` and omit the `render`
method. If you need to do custom logic in `render`, you should use the
other pattern above.
``` javascript
var LoginView = Backbone.LayoutManager.View.extend({
template: "#login-template"
});
```
#### Re-rendering Views ####
Instead of re-rendering the entire layout after data in a single View changes,
you can simply call `render()` on the View and it will automatically update
the DOM. You **cannot** bind to the initial render reference, like so
*Assume that you have a model that when changed, causes a redraw.*
``` javascript
var MyView = Backbone.LayoutManager.View.extend({
initialize: function() {
this.model.bind("change", this.render, this);
}
});
```
You must use this syntax instead, calling it from a function:
``` javascript
var MyView = Backbone.LayoutManager.View.extend({
initialize: function() {
this.model.bind("change", function() {
this.render();
}, this);
}
});
```
This necessity may be alleviated in a future version.
#### Rendering consecutive views ####
There are many times in which you will end up with a list of nested views
that result from either iterating a `Backbone.Collection` or array
and will need to dynamically add these nested views into a main view.
LayoutManager solves this by exposing a method to change the insert mode
from replacing the `innerHTML` to `appendChild` instead. Whenever you
use the `insert` method inside a render function you will put the
nested view into this special mode.
All sub views are inserted in order, regardless if the `fetch` method has
been overwritten to be asynchronous.
An example will illustrate the pattern easier:
``` javascript
// An example item View
// You may find it easier to have Backbone render the LI/TD/etc element
// instead of including this in your template. This is purely convention
// use what works for you.
var SomeItem = Backbone.LayoutManager.View.extend({
template: "#list",
// In this case we'll say the item is an <LI>
tagName: "li"
});
// The view that contains the <ul> <table> w/e is used to contain your element.
//
// Since this method is used inside a custom render method, LayoutManager.View
// isn't useful for rendering a collection list.
var SomeList = Backbone.View.extend({
template: "#item",
render: function(layout) {
// Assign the layout view custom object to the view variable
var view = layout(this);
// Iterate over the passed collection and create a view for each item
this.collection.each(function(model) {
// Pass the model to the new SomeItem view
view.insert("ul", new SomeItem({
model: model
}));
});
// You still must return this view to render, works identical to the
// existing functionality.
return view.render();
}
});
```
#### Working with context ####
Template engines bind data to a template. The term context refers to the
data object passed.
`LayoutManager` will look for a `serialize` method or object automatically:
``` javascript
var LoginView = Backbone.LayoutManager.View.extend({
template: "#login-template",
// Provide data to the template
serialize: function() {
return this.model.toJSON();
}
});
```
You can also pass the context object inside the `render` method:
``` javascript
var LoginView = Backbone.View.extend({
template: "#login-template",
render: function(layout) {
// Provide data to the template
return layout(this).render(this.model.toJSON());
}
});
```
### Defining the layout and template ###
These example templates are defined using a common pattern which leverages
how browsers treat `<script></script>` tags with custom `type` attributes.
This is how `LayoutManager` expects templates to be defined by default (using script tags).
#### Main layout ####
``` plain
<script id="main-layout" type="layout">
<section class="content twelve columns"></section>
<!-- Template below will be injected here -->
<aside class="secondary four columns"></aside>
</script>
```
#### Login template ####
``` plain
<script id="login-template" type="template">
<form class="login">
<p><label for="user">Username</label><input type="text" name="user"></p>
<p><label for="pass">Password</label><input type="text" name="pass"></p>
<p><input class="loginBtn" type="submit" value="Login"></p>
</form>
</script>
```
## Using jQuery Plugins ##
Attaching jQuery plugins should happen inside the `render` methods. You can
attach at either the layout render or the view render. To attach in the
layout render:
``` javascript
main.render(function(el) {
$(el).find(".some-element").somePlugin();
$(".container").html(el);
});
```
In the above example its entirely possible the elements are not in the DOM yet.
This happens when you fetch templates asynchronously. Using the following
method, elements will be added into the DOM. To attach in the layout render,
you will need to override the `render` method like so:
``` javascript
render: function(layout) {
return layout(this).render().then(function(el) {
$(el).find(".some-element").somePlugin();
});
}
```
This is a very cool example of the power in using deferreds. =)
## Configuration ##
Overriding `LayoutManager` options has been designed to work just like
`Backbone.sync`. You can override at a global level using
`LayoutManager.configure` or you can specify when instantiating a
`LayoutManager` instance.
### Global level ###
Lets say you wanted to use `Handlebars` for templating in all your Views.
``` javascript
Backbone.LayoutManager.configure({
// Override render to use Handlebars
render: function(template, context) {
return Handlebars.compile(template)(context);
}
});
```
### Instance level ###
In this specific layout, define custom prefixed paths for template paths.
``` javascript
var main = new Backbone.LayoutManager({
template: "#main",
// Custom paths for this layout
paths: {
template: "/assets/templates/"
}
});
```
### Defaults ###
* __Paths__:
An empty object. Two valid property names: `template` and `layout`.
``` javascript
paths: {}
```
* __Deferred__:
Uses jQuery deferreds for internal operation, this may be overridden to use
a different Promises/A compliant deferred.
``` javascript
deferred: function() {
return $.Deferred();
}
```
* __Fetch__:
Uses jQuery to find a selector and returns its `innerHTML` content.
``` javascript
fetch: function(path) {
return $(path).html();
}
```
* __Partial__:
Uses jQuery to find the View's location and inserts the rendered
element there. The append property determines if the View should
append, defaults to replace via innerHTML.
``` javascript
partial: function(layout, name, template, append) {
if (append) {
this.append($(layout).find(name), template);
} else {
this.html($(layout).find(name), template);
}
}
```
* __HTML__:
Override this with a custom HTML method, passed a root element and an
element to replace the innerHTML with.
``` javascript
html: function(root, el) {
$(root).html(el);
}
```
* __Append__:
Very similar to HTML except this one will appendChild.
``` javascript
append: function(root, el) {
$(root).append(el);
}
```
* __Detach__:
Remove an element from the DOM, but maintain events.
``` javascript
detach: function(el) {
$(el).detach();
}
```
* __Render__:
Renders a template with Underscore.
``` javascript
render: function(template, context) {
return _.template(template)(context);
}
```
### Asynchronous & Synchronous fetching ###
The `fetch` method is overridden to get the contents of layouts and templates.
If you can instantly get the contents (DOM/JST) you can return the
contents inside the function.
``` javascript
Backbone.LayoutManager.configure({
fetch: function(name) {
return $("script#" + name).html();
}
});
```
If you need to fetch the contents asynchronously, you will need to put the
method into "asynchronous mode". To do this, assign `this.async()`
to a variable and call that variable with the contents when you are done.
``` javascript
Backbone.LayoutManager.configure({
fetch: function(name) {
var done = this.async();
$.get(name, function(contents) {
done(contents);
});
}
});
```
## Sample Configurations ##
You may need to combine a mix of **Engines** and **Transports** to integrate.
### Engines (Mustache, Handlebars, etc.) ###
Custom templating engines can be used by overriding `render`.
#### Underscore ####
``` plain
No configuration necessary for this engine.
```
#### Mustache ####
``` javascript
Backbone.LayoutManager.configure({
render: function(template, context) {
return Mustache.to_html(template, context);
}
});
```
#### Handlebars ####
``` javascript
Backbone.LayoutManager.configure({
render: function(template, context) {
return Handlebars.compile(template)(context);
}
});
```
### Transports (DOM, AJAX, etc.) ###
You can swap out how templates are loaded by overriding `fetch`.
#### DOM ####
``` plain
No configuration necessary for this transport.
```
#### AJAX ####
``` javascript
Backbone.LayoutManager.configure({
fetch: function(path) {
var done = this.async();
$.get(path, function(contents) {
done(contents);
});
}
});
```
### Using an Engine and Transport Override for JST ###
Whatever you decide to return as a template in `fetch`, can be used in the
`render` method.
``` javascript
Backbone.LayoutManager.configure({
fetch: function(name) {
return window.JST[name];
},
render: function(template, context) {
return template(context);
}
});
```
## Release History ##
### 0.1.2 ###
* Major patch for re-rendering layouts that would lose events
* Added new API method detach
### 0.1.1 ###
* Minor patch release (that removes an undocumented feature)
* Fixed issue with events not being registered correctly within lists
### 0.1.0 ###
* Lots of bug fixes!
* Ability to insert views dynamically using the new `view.insert` method. Useful for collections.
* Setting/resetting sub views possible with new `view.setViews` method.
* All views now have the `view/setViews` methods.
* Updates to allow LayoutManager to be extended easier, along with `events`
being bound automatically during initialization.
### 0.0.4 ###
* Adding views turned into a reusable function called `view`.
* Templates no longer are required to be a string, this allows passing of compiled template functions.
### 0.0.3 ###
* View renders are internally wrapped to expose a new `render()` method that when called, re-renders.
* Nested views are possible by adding a `views` sub property which is an object that contains nested views.
### 0.0.2 ###
* Changed layout `name` property to `template` for consistency.
* Internal second deferred replaces the `viewDeferred` to determine when an element enters the DOM.
### 0.0.1 ###
* Open sourced on GitHub.
* Initial unit tests.
* Released introduction screencast.
Run `grunt` inside a terminal in the project directory to run the tests in both
a headless browser and Node.js environment.
[travis-url]: http://travis-ci.org/tbranyen/backbone.layoutmanager
[travis-image]: https://img.shields.io/travis/tbranyen/backbone.layoutmanager.svg
[npm-url]: https://npmjs.org/package/backbone.layoutmanager
[npm-image]: https://img.shields.io/npm/v/backbone.layoutmanager.svg
[coveralls-url]: https://coveralls.io/r/tbranyen/backbone.layoutmanager
[coveralls-image]: https://img.shields.io/coveralls/tbranyen/backbone.layoutmanager.svg
+1050 -405
View File
File diff suppressed because it is too large Load Diff
+10
View File
@@ -0,0 +1,10 @@
{
"name": "layoutmanager",
"version": "1.0.0",
"main": "backbone.layoutmanager.js",
"dependencies": {
"jquery": ">=1.6",
"underscore": ">=1.5",
"backbone": "~1.2"
}
}
+10
View File
@@ -0,0 +1,10 @@
module.exports = ->
#@loadNpmTasks "grunt-benchmark"
@config "benchmark",
options:
displayResults: true
all:
src: ["test/benchmark/*.js"]
dest: "test/report/benchmark_results.csv"
+12
View File
@@ -0,0 +1,12 @@
module.exports = ->
@loadNpmTasks "grunt-browserify"
@config "browserify",
dist:
options:
browserifyOptions:
standalone: 'browserifyLM'
src: 'backbone.layoutmanager.js',
dest: 'test/tmp/backbone.layoutmanager.browserify.js'
+6
View File
@@ -0,0 +1,6 @@
module.exports = ->
@loadNpmTasks "grunt-contrib-clean"
@config "clean", [
"test/report"
]
+5
View File
@@ -0,0 +1,5 @@
module.exports = ->
@loadNpmTasks "grunt-jscs"
@config "jscs",
src: "backbone.layoutmanager.js"
+37
View File
@@ -0,0 +1,37 @@
module.exports = ->
@loadNpmTasks "grunt-contrib-jshint"
@config "jshint",
files: ["backbone.layoutmanager.js"]
options: @file.readJSON ".jshintrc"
node:
files:
src: ["node/index.js"]
options:
node: true
test:
files:
src: ["test/spec/*.js", "test/util/*.js"]
options:
maxlen: false
globals:
global: true
$: true
Backbone: true
_: true
require: true
QUnit: true
start: true
stop: true
ok: true
equal: true
deepEqual: true
notEqual: true
asyncTest: true
test: true
expect: true
testUtil: true
+10
View File
@@ -0,0 +1,10 @@
module.exports = ->
@loadNpmTasks "grunt-nodequnit"
@config "nodequnit",
files: ["test/spec/*.js", "!test/spec/dom.js"]
options:
deps: ["test/util/util.js"]
code: "."
testsDir: "test/spec/"
+16
View File
@@ -0,0 +1,16 @@
module.exports = ->
@loadNpmTasks "grunt-qunit-istanbul"
@config "qunit",
options:
"--web-security": "no"
coverage:
src: ["backbone.layoutmanager.js"]
instrumentedFiles: "test/tmp/coverage"
htmlReport: "test/report/coverage"
coberturaReport: "test/report"
lcovReport: "test/report"
linesThresholdPct: 85
files: ["test/index.html"]
-1
View File
@@ -1 +0,0 @@
(function(a,b,c){function g(a){b.each(a,function(a,b){this.view(b,a)},this)}function h(a,c){function i(a){var b=f.deferred();return b.async=function(){return b._isAsync=!0,a},b.partial=f.deferred(),b}function j(a){function n(b,e){d.cache(c,e),f.html(a.el,f.render(e,b)),j.partial.resolve(a.el),l(a,a.views)}var c,j,k,m;return a.views={},{insert:function(b,c){var d=a.views,e=d[b]=d[b]||[];return e.push(c),c.view=h,c.setViews=g,c},render:function(g){return!g&&b.isFunction(a.serialize)?g=a.serialize.call(a):!g&&b.isObject(a.serialize)&&(g=a.serialize),j=i(b.bind(n,e,g)),k=f.paths&&f.paths.template||"",b.isString(a.template)&&(c=k+a.template),(m=d.cache(c))?(n(g,m,c),j):(b.isString(a.template)?m=f.fetch.call(j,k+a.template):m=f.fetch.call(j,a.template),j._isAsync||n(g,m),j)}}}function k(a,c,d){var e,g=d.render;return function(){var h=g.call(d,j);return e?(b.isObject(d.options.views)&&l(d,d.options.views),h.partial.then(function(a){return h.resolve(a)}),h):(h.partial.then(function(g){f.partial(a.el,c,g,d.options.append),e=!0,h.resolve(d.el),b.isObject(d.options.views)&&l(d,d.options.views)}),h)}}function l(a,c){function d(b,c,d){b.remove(),b.render._wrapped||(b.render=k(a,c,b),b.render._wrapped=!0),b.render().then(d).then(function(){b.delegateEvents()})}b.each(c,function(a,c){function e(a){var b=a.shift();b.options.append=!0,d(b,c,function(){a.length&&e(a)})}b.isArray(a)?e(b.clone(a)):d(a,c)})}var e=this,f=b.extend({},this.options,d.prototype.options);return c.render._wrapped||(c.render=k(e,a,c),c.render._wrapped=!0),c.view=h,c.setViews=g,this.views[a]=c}var d,e,f;d=a.LayoutManager=a.View.extend({initialize:function(){var c,d,e={},f=this;b.isFunction(this.options.views)?(b.extend(e,this.options.views.call(this)),delete this.options.views):b.isObject(this.options.views)&&(b.extend(e,this.options.views),delete this.options.views),this.views={},b.each(e,function(a,b){f.view(b,a)}),this.options=b.extend({},a.LayoutManager,this.options),b.isFunction(this.options.initialize)&&this.options.initialize.apply(this,arguments),b.bindAll(this),b.each(["template","serialize"],function(a){!this.options[a]&&this[a]&&(this.options[a]=this[a])},this),this.options.events&&(this.events=this.options.events,delete this.options.events,b.each(this.events,function(a){this[a]=this.options[a],delete this.options[a]},this),this.delegateEvents())},view:h,setViews:g,render:function(a){function j(a){var b=i.deferred();return b.async=function(){return b._isAsync=!0,a},b.partial=i.deferred(),b}function k(c){var e={};d.cache(f,c),b.isFunction(i.serialize)?e=i.serialize.call(h):b.isObject(i.serialize)&&(e=i.serialize),i.html(h.el,i.render(c,e)),i.detach(h.el),b.each(h.views,function(a){a.render()}),a(h.el)}var c,e,f,g,h=this,i=this.options;e=i.paths&&i.paths.layout||"",b.isString(i.template)?f=e+i.template:f=i.template;if(c=d.cache(f))return k(c);g=j(k),c=i.fetch.call(g,f),g._isAsync||k(c)}},{_cache:{},cache:function(a,b){if(a in this._cache)return this._cache[a];if(a!=null&&b!=null)return this._cache[a]=b},configure:function(c){var d=a.LayoutManager.prototype.options;b.isObject(c)&&b.extend(d,c)},View:a.View.extend({render:function(a){return a(this).render()}})}),a.LayoutManager.prototype.options={paths:{},deferred:function(){return c.Deferred()},fetch:function(a){return c(a).html()},partial:function(a,b,d,e){e?this.append(c(a).find(b),d):this.html(c(a).find(b),d)},html:function(a,b){c(a).html(b)},append:function(a,b){c(a).append(b)},detach:function(a){c(a).detach()},render:function(a,c){return b.template(a)(c)}}})(this.Backbone,this._,this.jQuery)
+45
View File
@@ -0,0 +1,45 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>01.Layout</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Layout template. -->
<script class="template" type="template" id="layout">
<h1>Hello world!</h1>
<p></p>
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Create a new Layout.
var layout = new Backbone.Layout({
// Attach the Layout to the main container.
el: ".main",
// Use the previous defined template.
template: "#layout"
});
// Render the Layout.
layout.render();
</script>
<h3><a href="02.View.html">Next example: Add a nested View.</a></h3>
</body>
</html>
+60
View File
@@ -0,0 +1,60 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>02.View</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Layout template. -->
<script class="template" type="template" id="layout">
<h1>Hello world!</h1>
<p></p>
</script>
<!-- View template -->
<script class="template" type="template" id="view">
This is some content...
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Create a View to be used with the Layout below.
var View = Backbone.Layout.extend({
template: "#view"
});
// Create a new Layout.
var layout = new Backbone.Layout({
// Attach the Layout to the main container.
el: ".main",
// Use the previous defined template.
template: "#layout",
// Declaratively bind a nested View to the Layout.
views: {
"p": new View()
}
});
// Render the Layout.
layout.render();
</script>
<h3><a href="03.Events.html">Next example: Adding events.</a></h3>
</body>
</html>
+69
View File
@@ -0,0 +1,69 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>03.Events</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Layout template. -->
<script class="template" type="template" id="layout">
<h1>Hello world!</h1>
<p></p>
</script>
<!-- View template -->
<script class="template" type="template" id="view">
This is some content...
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Create a View to be used with the Layout below.
var View = Backbone.Layout.extend({
template: "#view",
// When you click the View contents, it will wrap them in a bold tag.
events: {
"click": "wrapElement"
},
wrapElement: function() {
this.$el.wrap("<b>");
}
});
// Create a new Layout.
var layout = new Backbone.Layout({
// Attach the Layout to the main container.
el: ".main",
// Use the previous defined template.
template: "#layout",
// Declaratively bind a nested View to the Layout.
views: {
"p": new View()
}
});
// Render the Layout.
layout.render();
</script>
<h3><a href="04.Append.html">Next example: Appending a View.</a></h3>
</body>
</html>
+89
View File
@@ -0,0 +1,89 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>04.Append</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Layout template. -->
<script class="template" type="template" id="layout">
<h1>Hello world!</h1>
<p></p>
</script>
<!-- View template -->
<script class="template" type="template" id="view">
This is some content...
</script>
<!-- Display template. -->
<script class="template" type="template" id="display">
What a twist!
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
var DisplayView = Backbone.View.extend({
manage: true,
template: "#display"
});
// Create a View to be used with the Layout below.
var View = Backbone.Layout.extend({
template: "#view",
// When you click the View contents, it will wrap them in a bold tag.
events: {
"click": "wrapElement",
"mouseenter": "insertElement",
"mouseleave": "removeElement"
},
wrapElement: function() {
this.$el.wrap("<b>");
},
insertElement: function() {
this.insertView(new DisplayView()).render();
},
removeElement: function() {
// Removes the inserted DisplayView.
this.removeView("");
}
});
// Create a new Layout.
var layout = new Backbone.Layout({
// Attach the Layout to the main container.
el: ".main",
// Use the previous defined template.
template: "#layout",
// Declaratively bind a nested View to the Layout.
views: {
"p": new View()
}
});
// Render the Layout.
layout.render();
</script>
</body>
</html>
@@ -0,0 +1,57 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>01.Augment</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Content template. -->
<script class="template" type="template" id="content">
This is some content...
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Setting this option augments `Backbone.View` to work like `Layout`.
Backbone.Layout.configure({ manage: true });
// Now you can create a nested View that is managed by LayoutManager and
// has all the benefits.
var View = Backbone.View.extend({
template: "#content",
// Override the render method with a custom syntax.
render: function(template, context) {
return template(context);
},
// Once the View has finished render, stick it in the Document.
afterRender: function() {
this.$el.appendTo(".main");
}
});
// Initialize the View.
var view = new View();
// Render it!
view.render();
</script>
<h3><a href="02.Swap_Layout.html">Next example: Swap Layout.</a></h3>
</body>
</html>
@@ -0,0 +1,93 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>02.Swap Layouts</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Content template. -->
<script class="template" type="template" id="content">
This is some content...
</script>
<!-- Layout template. -->
<script class="layout" type="template" id="hello">
<h1>Hello</h1>
<p></p>
<button>Swap</button>
</script>
<!-- Another Layout template. -->
<script class="layout" type="template" id="goodbye">
<h1>Goodbye</h1>
<p></p>
<button>Swap back</button>
</script>
<!-- Content template. -->
<script class="template" type="template" id="item">
Heyo
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Setting this option augments `Backbone.View` to work like `Layout`.
Backbone.Layout.configure({ manage: true });
// This will be inserted into both Layouts.
var ContentView = Backbone.View.extend({
template: "#content"
});
// The Layout that swaps between templates.
var layout = new Backbone.Layout({
template: "#hello",
// Insert the nested View into the paragraph tag.
views: {
p: new ContentView()
},
events: {
"click button": "swap"
},
swap: function(ev) {
// Toggle the layout template.
if (this.template === "#hello") {
this.template = "#goodbye";
} else {
this.template = "#hello";
}
// Re-render with the new template.
this.render();
}
});
// Attach the Layout to the main container.
layout.$el.appendTo(".main");
// Initially render the Layout.
layout.render();
</script>
<h3><a href="03.Remove_View_Element.html">Next example: Remove View Element.</a></h3>
</body>
</html>
@@ -0,0 +1,80 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>03.Remove View Element</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Click on this to remove the View from the Document. -->
<button>Remove View</button>
<!-- Content template. -->
<script class="template" type="template" id="content">
<!-- Example comment. -->
<h1>My super important list...</h1>
<p>Sup</p>
Example Text Node
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Setting this option augments `Backbone.View` to work like `Layout`.
Backbone.Layout.configure({ manage: true });
// This will be inserted into both Layouts.
var ContentView = Backbone.View.extend({
template: "#content",
events: {
"click": "clicked"
},
clicked: function() {
this.$el.fadeOut().fadeIn();
},
// Dynamically create a View without a container element.
views: {
p: new Backbone.Layout({
template: _.template("<span>My Test</span><b>lol</b>"),
el: false
})
}
});
var contentView = new ContentView();
// Attach the View to the main container.
contentView.$el.appendTo(".main");
// Initially render the Content View.
contentView.render();
// When the button is clicked, remove the nested View.
$("button").click(function() {
contentView.getView("p").remove();
// Remove this as well.
$(this).remove();
});
</script>
<h3><a href="04.jQuery_Plugins.html">Next example: jQuery Plugins.</a></h3>
</body>
</html>
@@ -0,0 +1,85 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>04.jQuery Plugins</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Layout template. -->
<script class="layout" type="template" id="layout">
<h1>Hello</h1>
<p></p>
</script>
<!-- Content template. -->
<script class="template" type="template" id="content">
<span></span>
</script>
<!-- Sub Content template. -->
<script class="template" type="template" id="sub-content">
<span>I'm sub-content!</span>
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Setting this option augments `Backbone.View` to work like `Layout`.
Backbone.Layout.configure({ manage: true });
// This will be inserted into both Layouts.
var ContentView = Backbone.View.extend({
template: "#content",
// Initialize your jQuery plugins here.
afterRender: function() {
console.log("Content width: " + $(this.el).width());
}
});
var SubContentView = Backbone.View.extend({
template: "#sub-content",
afterRender: function() {
console.log("Sub-content width: " + $(this.el).width());
}
});
// Create a new Layout with a sub view for content.
var layout = new Backbone.Layout({
template: "#layout",
// This will place the contents of the ContentView into the Layout's
// `<p>`.
views: {
p: new ContentView({
views: {
span: new SubContentView()
}
})
}
});
// Attach the Layout to the main container.
layout.$el.appendTo(".main");
// Initially render the Layout.
layout.render();
</script>
<h3><a href="05.No_Template.html">Next example: No Template.</a></h3>
</body>
</html>
@@ -0,0 +1,47 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>05.No Template</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
var Layout = Backbone.Layout.extend({
// Use the `.main` element.
el: ".main",
// Change the content in `beforeRender`.
beforeRender: function() {
this.$el.html("Hello World!");
},
// Change the content *after* rendering.
afterRender: function() {
this.$el.append(" How ya doin'?");
}
});
var layout = new Layout();
// Render the Layout.
layout.render();
</script>
<h3><a href="06.Override_Render.html">Next example: Override Render.</a></h3>
</body>
</html>
@@ -0,0 +1,64 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>06.Override Render</title>
<link rel="stylesheet" href="../_assets/theme.css">
</head>
<body>
<!-- Layout will be inserted here. -->
<div class="main"></div>
<!-- Layout template. -->
<script class="layout" type="template" id="layout">
<h1>Hello</h1>
<p></p>
</script>
<!-- Content template. -->
<script class="template" type="template" id="content">
This is some content...
</script>
<!-- Dependencies. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/underscore/underscore.js"></script>
<script src="../../bower_components/backbone/backbone.js"></script>
<!-- LayoutManager library. -->
<script src="../../backbone.layoutmanager.js"></script>
<!-- Example code. -->
<script contenteditable="true">
// Create a Content view to be used with the Layout below.
var ContentView = Backbone.Layout.extend({
template: "#content"
});
// Create a new Layout with a sub view for content.
var layout = new Backbone.Layout({
template: "#layout",
// This will place the contents of the Content View into the main
// Layout's <p></p>.
views: {
// Appending a new content view using the array syntax
p: new ContentView({
// Custom render function that reverses everything.
render: function(template, context) {
return template(context).split("").reverse().join("");
}
})
}
});
// Attach the Layout to the main container.
layout.$el.appendTo(".main");
// Render the Layout.
layout.render();
</script>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
<h1>This is my header!</h1>
+25
View File
@@ -0,0 +1,25 @@
// If you installed LayoutManager globally, you would do:
// var LayoutManager = require("backbone.layoutmanager");
// Since we want this to run without having to install LayoutManager...
var LayoutManager = require("../../node");
// Create a header View and notice that simply providing a path to a template
// will automatically load it.
var Header = Backbone.Layout.extend({
template: "header"
});
var layout = new Backbone.Layout({
template: "test",
views: {
"header": new Header({ el: false })
}
});
// Render the layout and echo out the contents.
layout.render().promise().then(function() {
// Should echo out: <header><h1>This is my header!</h1></header>
console.log(this.$el.html());
});
+1
View File
@@ -0,0 +1 @@
<header></header>
+40
View File
@@ -0,0 +1,40 @@
body {
padding: 20px;
}
script[contenteditable=true], script.template {
display: block;
white-space: pre;
border: 1px solid #CCC;
padding: 20px;
outline: none;
background: #000;
color: #FFF;
font-family: Courier New;
font-size: 16px;
padding-left: 0px;
border-radius: 10px;
max-width: 50%;
min-width: 820px;
position: relative;
margin-top: 70px;
}
script[contenteditable=true]:before {
content: "Source:";
position: absolute;
top: -30px;
z-index: 10;
color: #000;
font-family: Helvetica, Arial;
}
/* Hide templates by default. */
script.template:before {
content: "Template:";
position: absolute;
top: -30px;
z-index: 10;
color: #000;
font-family: Helvetica, Arial;
}
-32
View File
@@ -1,32 +0,0 @@
/*global config:true, task:true*/
config.init({
lint: {
files: ["grunt.js", "backbone.layoutmanager.js"]
},
min: {
"dist/backbone.layoutmanager.min.js": "backbone.layoutmanager.js"
},
watch: {
files: "<config:lint.files>",
tasks: "lint test"
},
jshint: {
options: {
boss: true,
curly: true,
eqeqeq: true,
immed: false,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
eqnull: true,
node: true
},
globals: {}
}
});
// Default task.
task.registerTask("default", "lint min");
+3
View File
@@ -0,0 +1,3 @@
{
"node": true
}
+72
View File
@@ -0,0 +1,72 @@
var fs = require("fs");
// Common dependencies to get LayoutManager running.
var Backbone = require("backbone");
var _ = require("underscore");
// Using Cheerio instead of jQuery, because Cheerio emulates a loosely
// compatible API that we further augment to ensure unit tests pass. It is
// also much faster than jsdom.
var $ = require("cheerio");
// Add cheerio hooks
Backbone.View.prototype._createElement = function(tagName) {
var tag = "<" + tagName + ">" + "</" + tagName + ">";
return $.load(tag).root()[0].children[0];
};
// This is to avoid unwanted errors thrown when using
// `Backbone.View#setElement`.
$.prototype.unbind = $.prototype.off = function() { return this; };
// Since jQuery is not being used and LayoutManager depends on a Promise
// implementation close to jQuery, we use `underscore.deferred` here which
// matches jQuery's Deferred API exactly. This is mixed into Cheerio to make
// it more seamless.
_.extend($, require("underscore.deferred"));
// Get Backbone and _ into the global scope.
_.defaults(global, { Backbone: Backbone, _: _ });
// Set the Backbone DOM library to be Cheerio.
Backbone.$ = $;
// Include the LayoutManager source, without eval.
require("../backbone.layoutmanager");
// Configure LayoutManager with some very useful defaults for Node.js
// environments. This allows the end user to simply consume instead of
// fighting with the desirable configuration.
Backbone.Layout.configure({
// Sensible default for Node.js is to load templates from the filesystem.
// This is similar to how we default to script tags in browser-land.
fetchTemplate: function(template) {
// Automatically add the `.html` extension.
template = template + ".html";
// Put this fetch into `async` mode to work better in the Node environment.
var done = this.async();
// By default read in the file from the filesystem relative to the code
// being executed.
fs.readFile(template, function(err, contents) {
// Ensure the contents are a String.
contents = String(contents);
// Any errors should be reported.
if (err) {
console.error("Unable to load file " + template + " : " + err);
return done(null);
}
// Pass the template contents back up.
done(_.template(contents));
});
},
// In Node, we likely want templates to render as quickly as possible - using
// requestAnimationFrame doesn't make much sense in a Node context.
useRAF: false
});
module.exports = Backbone.Layout;
+62
View File
@@ -0,0 +1,62 @@
{
"author": "Tim Branyen (@tbranyen)",
"name": "backbone.layoutmanager",
"description": "A layout and template manager for Backbone.js applications.",
"version": "1.0.0",
"homepage": "http://layoutmanager.org/",
"repository": {
"type": "git",
"url": "git://github.com/tbranyen/backbone.layoutmanager.git"
},
"main": "node/index",
"files": [
"backbone.layoutmanager.js",
"node/index.js",
"test/"
],
"browser": "./backbone.layoutmanager.js",
"engines": {
"node": ">=0.8"
},
"dependencies": {
"backbone": "1.2.3",
"underscore.deferred": "^0.4.0",
"cheerio": "^0.19.0",
"underscore": "^1.8.3",
"lodash": "^3.9.3"
},
"peerDependencies": {
"jquery": "*"
},
"devDependencies": {
"bluebird": "^2.9.34",
"browserify": "^10.2.4",
"colors": "^1.1.2",
"coveralls": "^2.11.2",
"grunt": "^0.4.5",
"grunt-benchmark": "^0.3.0",
"grunt-browserify": "^3.8.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jshint": "^0.11.2",
"grunt-jscs": "^1.8.0",
"grunt-nodequnit": "^0.2.0",
"grunt-qunit-istanbul": "^0.4.7",
"jquery": "^2.1.4",
"qunitjs": "^1.18.0",
"requirejs": "^2.1.18"
},
"scripts": {
"test": "grunt"
},
"jam": {
"dependencies": {
"underscore": ">=1.5",
"backbone": "~1.2",
"jquery": ">=1.6"
},
"include": [
"backbone.layoutmanager.js"
],
"main": "backbone.layoutmanager.js"
}
}
+34
View File
@@ -0,0 +1,34 @@
{
"maxlen": 120,
"globals": {
"Backbone" : true,
"QUnit" : true,
"asyncTest" : true,
"deepEqual" : true,
"equal" : true,
"expect" : true,
"global" : true,
"module" : true,
"notDeepEqual" : true,
"notEqual" : true,
"notStrictEqual" : true,
"ok" : true,
"QUnit" : true,
"raises" : true,
"start" : true,
"stop" : true,
"strictEqual" : true,
"test" : true,
"_" : true
},
"browser": true,
"boss": true,
"immed": false,
"eqnull": true,
"es3": true,
"curly": true,
"quotmark": "double",
"trailing": true,
"unused": true,
"undef": true
}
+20
View File
@@ -0,0 +1,20 @@
exports.name = "Collection rendering";
exports.tests = {
"10 models": {
maxTime: 2,
defer: true,
setup: function() {
},
fn: function(deferred) {
setTimeout(function() {
deferred.resolve();
}, 500);
}
}
};
-42
View File
@@ -1,42 +0,0 @@
module("configure", {
setup: function() {
this.options = Backbone.LayoutManager.prototype.options;
},
teardown: function() {
this.options.paths = {};
}
});
test("defaults", function() {
deepEqual(this.options.paths, {}, "No paths");
});
test("invalid", function() {
Backbone.LayoutManager.configure("key", "val");
equal(this.options.key, undefined, "Invalid assignment");
});
test("global", function() {
Backbone.LayoutManager.configure({
paths: {
template: "/templates/"
}
});
equal(this.options.paths.template, "/templates/", "Override paths globally");
});
test("instance", function() {
var main = new Backbone.LayoutManager({
template: "main-layout",
paths: {
layout: "/layouts/"
}
});
equal(main.options.paths.layout, "/layouts/", "Override paths locally");
notEqual(this.options.paths.template, "/templates/", "Do not override globals");
});
+33 -27
View File
@@ -1,18 +1,40 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>backbone.layoutmanager Test Suite</title>
<link rel="stylesheet" href="qunit/qunit.css">
<script src="qunit/qunit.js"></script>
<script src="vendor/jquery.js"></script>
<script src="vendor/underscore.js"></script>
<script src="vendor/backbone.js"></script>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../node_modules/jquery/dist/jquery.js"></script>
<script src="../node_modules/underscore/underscore.js"></script>
<script src="../node_modules/lodash/index.js"></script>
<script>
var lodash = _.noConflict();
var underscore = _;
</script>
<script src="../node_modules/backbone/backbone.js"></script>
<script src="../node_modules/bluebird/js/browser/bluebird.js"></script>
<script src="../backbone.layoutmanager.js"></script>
<script src="../node_modules/requirejs/require.js"></script>
<!-- Util scripts -->
<script src="util/util.js"></script>
<!-- Test scripts -->
<script src="configure.js"></script>
<script src="views.js"></script>
<script src="spec/expose.js"></script>
<script src="spec/configure.js"></script>
<script src="spec/setup.js"></script>
<script src="spec/views.js"></script>
<script src="spec/dom.js"></script>
<script type="text/template" id="dom-template">
This template lives in the <b>DOM</b>
</script>
<script type="text/template" id="test">
Sample template.
</script>
</head>
<body>
<h1 id="qunit-header">backbone.layoutmanager Test Suite</h1>
@@ -24,24 +46,8 @@
<div id="container" style="display:none"></div>
<!-- Layouts -->
<script id="main" type="layout">
<div class="left">Left</div>
<div class="right"></div>
</script>
<!-- Templates -->
<script id="test" type="template">
<span class="inner-left"><%=text%></span>
<span class="inner-right"></span>
</script>
<script id="test-sub" type="template">
<%=text%>
</script>
<script id="list" type="template">
<ul></ul>
</script>
<div id="prefilled" style="display:none">
<span class="test"></span>
</div>
</body>
</html>
-226
View File
@@ -1,226 +0,0 @@
/**
* QUnit - A JavaScript Unit Testing Framework
*
* http://docs.jquery.com/QUnit
*
* Copyright (c) 2011 John Resig, Jörn Zaefferer
* Dual licensed under the MIT (MIT-LICENSE.txt)
* or GPL (GPL-LICENSE.txt) licenses.
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #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-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699a4;
background-color: #0d3349;
font-size: 1.5em;
line-height: 1em;
font-weight: normal;
border-radius: 15px 15px 0 0;
-moz-border-radius: 15px 15px 0 0;
-webkit-border-top-right-radius: 15px;
-webkit-border-top-left-radius: 15px;
}
#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests ol {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
box-shadow: inset 0px 2px 13px #999;
-moz-box-shadow: inset 0px 2px 13px #999;
-webkit-box-shadow: inset 0px 2px 13px #999;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}
#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
margin: 0.5em;
padding: 0.4em 0.5em 0.4em 0.5em;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #5E740B;
background-color: #fff;
border-left: 26px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 26px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 15px 15px;
-moz-border-radius: 0 0 15px 15px;
-webkit-border-bottom-right-radius: 15px;
-webkit-border-bottom-left-radius: 15px;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-bottom: 1px solid white;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
}
-1510
View File
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
{
"browser": true,
"boss": true,
"immed": false,
"eqnull": true,
"maxlen": 80,
"es3": true,
"curly": true,
"quotmark": "double",
"trailing": true,
"unused": true,
"undef": true,
"node": true,
"globals": {
"asyncTest" : true
"deepEqual" : true
"equal" : true
"expect" : true
"module" : true
"notDeepEqual" : true
"notEqual" : true
"notStrictEqual" : true
"ok" : true
"QUnit" : true
"raises" : true
"start" : true
"stop" : true
"strictEqual" : true
"test" : true
}
}
+395
View File
@@ -0,0 +1,395 @@
(function(window) {
"use strict";
/*
* Test Module: Configure
* Ensures that configuration settings have correct defaults, initialization,
* overriding, and functionality.
*
*/
QUnit.module("configure", {
setup: function() {
// Backbone.Layout constructor.
this.Layout = Backbone.Layout;
// Normal Backbone.View.
this.View = Backbone.View.extend({
initialize: function(options) {
// Set up this View with Layout.
Backbone.Layout.setupView(this, options);
}
});
// Save a copy of console.warn.
this.warn = window.console.warn;
},
teardown: function() {
// Ensure the prefix object is restored correctly.
this.Layout.prototype.prefix = "";
// Remove `manage: true`.
delete this.Layout.prototype.manage;
delete Backbone.View.prototype.manage;
// Remove `el: false`.
delete this.Layout.prototype.el;
delete Backbone.View.prototype.el;
// Remove `supressWarnings: true`.
delete this.Layout.prototype.suppressWarnings;
delete Backbone.View.prototype.suppressWarnings;
// Not necessary for our testing purposes.
window.console.trace = function() {};
// Restore console.warn.
window.console.warn = this.warn;
delete this.warn;
}
});
// Ensure the correct defaults are set for all Layout and View options.
test("defaults", 20, function() {
// Create a new Layout to test.
var layout = new this.Layout();
// Create a new Layout to test.
var view = new this.View();
// Paths should be an empty object.
deepEqual(layout.prefix, "", "Layout: No prefix");
// The deferred property should be a function.
ok(_.isFunction(layout.deferred), "Layout: deferred is a function");
// The fetchTemplate property should be a function.
ok(_.isFunction(layout.fetchTemplate), "Layout: fetchTemplate is a function");
// The renderTemplate property should be a function.
ok(_.isFunction(layout.renderTemplate), "Layout: renderTemplate is a function");
// The partial property should be a function.
ok(_.isFunction(layout.partial), "Layout: partial is a function");
// The html property should be a function.
ok(_.isFunction(layout.html), "Layout: html is a function");
// The insert property should be a function.
ok(_.isFunction(layout.insert), "Layout: insert is a function");
// The append property should be a function.
ok(_.isFunction(layout.insert), "Layout: append is a function");
// The when property should be a function.
ok(_.isFunction(layout.when), "Layout: when is a function");
// Paths should be an empty object.
deepEqual(view.prefix, "", "View: No prefix");
// The deferred property should be a function.
ok(_.isFunction(view.deferred), "View: deferred is a function");
// The fetchTemplate property should be a function.
ok(_.isFunction(view.fetchTemplate), "View: fetchTemplate is a function");
// The renderTemplate property should be a function.
ok(_.isFunction(view.renderTemplate), "View: renderTemplate is a function");
// The partial property should be a function.
ok(_.isFunction(view.partial), "View: partial is a function");
// The html property should be a function.
ok(_.isFunction(view.html), "View: html is a function");
// The insert property should be a function.
ok(_.isFunction(view.insert), "View: insert is a function");
// The append property should be a function.
ok(_.isFunction(view.insert), "View: append is a function");
// The when property should be a function.
ok(_.isFunction(view.when), "View: when is a function");
// The serialize property should be a function.
ok(_.isFunction(view.serialize), "View: serialize is a function");
// RequestAnimationFrame should be used by default, except in node.
var isNode = typeof global !== "undefined" &&
{}.toString.call(global) == "[object global]";
ok(view.useRAF !== isNode, "View: UseRAF should be true in the browser, false in Node.");
});
// Test overriding a single property to ensure propagation works as expected.
test("global", 4, function() {
// Configure prefix property globally.
Backbone.Layout.configure({
prefix: "/templates/",
manage: true
});
// Create a new Layout to test.
var layout = new this.Layout();
// Create a new View to test.
var view = new this.View();
// The template property set inside prefix should be default for all new
// Layouts.
equal(layout.prefix, "/templates/",
"Layout: Override paths globally for Layouts");
// The template property set inside paths should be default for all new
// Views.
equal(view.prefix, "/templates/",
"View: Override paths globally for Views");
// Ensure the global configuration was updated to reflect this update.
equal(this.Layout.prototype.prefix, "/templates/",
"Override globals");
// Ensure that `manage: true` works.
ok(this.Layout.prototype.manage, "Manage was set.");
});
// Ensure that options can be overwritten at an instance level and make sure
// that this does not impact the global configuration.
test("override at invocation", 3, function() {
// Create a new Layout to test.
var layout = new this.Layout({
prefix: "/templates/layouts/"
});
// Create a new View to test.
var view = new this.View({
prefix: "/templates/raw/"
});
// The prefix property should be successfully overwritten for the
// Layout instance.
equal(layout.prefix, "/templates/layouts/",
"Override paths locally");
// The paths.template property should be successfully overwritten for the
// View instance.
equal(view.prefix, "/templates/raw/",
"Override paths locally");
// Ensure the global configuration was NOT updated, local change only.
notEqual(Backbone.Layout.prototype.prefix,
"/templates/", "Do not override globals");
});
// Render broke in 0.5.1 so this test will ensure this always works.
asyncTest("override renderTemplate", 1, function() {
var hit = false;
var layout = new Backbone.Layout({
template: _.template(testUtil.templates.main),
fetchTemplate: _.identity,
renderTemplate: function() {
hit = true;
}
});
layout.render().promise().then(function() {
ok(hit, "The renderTemplate method was hit correctly");
start();
});
});
asyncTest("Fetch works on a View during definition", 1, function() {
var hit = false;
var View = Backbone.Layout.extend({
// A template is required to hit fetchTemplate.
template: "a",
fetchTemplate: function() {
hit = true;
}
});
new View().render().promise().then(function() {
ok(hit, "Fetch gets called on a View.");
start();
});
});
asyncTest("Fetch works on a View during invocation", 1, function() {
var hit = false;
new Backbone.Layout({
// A template is required to hit fetchTemplate.
template: "a",
fetchTemplate: function() {
hit = true;
}
}).render().promise().then(function() {
ok(hit, "Fetch gets called on a View.");
start();
});
});
test("Collection should exist on the View", 1, function() {
var m = new Backbone.Collection();
var D = Backbone.Layout.extend({
initialize: function() {
this.collection.reset([]);
ok(true, "This works!");
}
});
var V = Backbone.Layout.extend({
template: "<p></p>",
fetchTemplate: function(path) { return _.template(path); },
initialize: function() {
this.setViews({
p: new D({ collection: this.collection })
});
}
});
var v = new V({
collection: m
});
v.render();
});
asyncTest("Custom template function", 1, function() {
var T = Backbone.Layout.extend({
template: function(contents) {
return contents;
},
serialize: "hi"
});
new T().render().promise().done(function() {
equal(testUtil.trim(this.$el.text()), "hi", "Correct text");
start();
});
});
asyncTest("Default `serialize` implementation", 2, function() {
var T = Backbone.Layout.extend({
fetchTemplate: function(t) { return t; }
});
var t = new T({
template: _.template("bar")
});
var t2 = new T({
model: new Backbone.Model({ name : "foo" }),
template: _.template("<%= name %>")
});
t.when([
t.render().promise().then(function() {
equal(t.$el.html(), "bar", "Should not break rendering if no model is in use");
}),
t2.render().promise().then(function() {
equal(t2.$el.html(), "foo", "Should pass model attributes to the template");
})
]).then(start);
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/201
test("Options passed at instance level overwritten by class level options.", 2, function() {
var layout = new Backbone.Layout();
var TestView = Backbone.View.extend({
template: "template-one",
lol: "test",
manage: true
});
layout.setView("", new TestView({ template: "template-two", lol: "hi" }));
equal(layout.getView("").options.template, "template-two", "Property overwritten properly");
equal(layout.getView("").options.lol, "hi", "Property overwritten properly");
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/209
asyncTest("If you use 'data' as a variable in a view it won't render", 1, function() {
var Test = Backbone.View.extend({
manage: true,
data: {},
serialize: { name: "test" },
fetchTemplate: _.identity,
template: _.template("<%=name%>")
});
new Test().render().promise().done(function() {
equal(this.$el.html(), "test", "Correct property set.");
start();
});
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/237
asyncTest("View `serialize` not used", 1, function() {
// Configure options.
Backbone.Layout.configure({
serialize: { top: true }
});
// Setup View.
var View = Backbone.Layout.extend({
template: _.template("<%=top%>"),
fetchTemplate: _.identity,
serialize: { top: false },
renderTemplate: function(template, context) {
equal(context.top, false, "Local serialize should override configure");
start();
}
});
// Render the View.
new View().render();
});
test("Setting `el: false` globally works as expected", 2, function() {
Backbone.Layout.configure({ el: false });
var l = new Backbone.Layout();
equal(l.__manager__.noel, true, "No element was triggered");
var m = new Backbone.Layout({ el: true });
ok(!m.__manager__.noel, "No element was overwritten");
});
test("Setting `suppressWarnings: true` works as expected", 5, function() {
// Start by testing that warn works.
var l = new Backbone.Layout({
template: _.template("<h1></h1><b></b>"),
el: false,
useRAF: false
});
// Nothing errors if trace is undefined.
window.console.trace = undefined;
window.console.warn = function() { ok(true, "warn should be called"); };
l.render();
// Nothing errors if warn is undefined.
window.console.trace = undefined;
window.console.warn = undefined;
l.render();
window.console.warn = function() { ok(true, "warn should be called"); };
window.console.trace = function() { ok(true, "trace should be called"); };
l.render();
ok(!l.__manager__.suppressWarnings, "New Views do not suppress warnings by default");
// Globally configure.
Backbone.Layout.configure({ suppressWarnings: true });
// Now test warn suppression.
var m = new Backbone.Layout({
template: _.template("<h1></h1><b></b>"),
el: false,
suppressWarnings: true
});
window.console.warn = function() { ok(false, "warn should not be called"); };
window.console.trace = function() { ok(false, "trace should not be called"); };
m.render();
ok(m.__manager__.suppressWarnings, "After globally configured, Views suppress warnings.");
});
test("ensure `insertViews` sets a single View correctly", 2, function() {
var view = new Backbone.Layout();
view.insertViews({
"": new Backbone.Layout({ test: "property" })
});
ok(_.isArray(view.views[""]), "Ensure the section is an array");
equal(view.views[""][0].options.test, "property", "Correct View");
});
})(typeof global !== "undefined" ? global : this);
+457
View File
@@ -0,0 +1,457 @@
(function() {
"use strict";
QUnit.module("dom", {
setup: function() {
this.LM = Backbone.Layout.extend();
this.SubView = Backbone.Layout.extend({
template: _.template(testUtil.templates.testSub),
fetchTemplate: _.identity,
serialize: function() {
return { text: "Right" };
}
});
}
});
asyncTest("test default fetchTemplate implementation", 1, function() {
// Create a new layout with a sample template.
var layout = new this.LM({ template: "#test" });
// Render and check.
layout.render().promise().then(function() {
equal(this.$el.html().trim(), "Sample template.", "Correct render output.");
start();
});
});
asyncTest("use layout without a template property", function() {
expect(1);
var main = new Backbone.Layout({
el: "#prefilled"
});
main.setViews({
".test": new this.SubView()
});
main.render().promise().then(function() {
equal(testUtil.trim( this.$(".test").text() ), "Right",
"Able to use an existing DOM element");
start();
});
});
asyncTest("afterRender inside Document", function() {
var inDocument = false;
var ProblemView = Backbone.Layout.extend({
template: "not-real",
fetchTemplate: function() {
setTimeout(this.async(), 10);
},
afterRender: function() {
var doc = document.body;
inDocument = this.contains(doc, this.el);
ok(inDocument, "element in is in the page Document");
start();
}
});
var NestedView = Backbone.Layout.extend({
template: "not-real",
fetchTemplate: function() {
setTimeout(this.async(), 10);
},
beforeRender: function() {
this.insertView(new ProblemView());
}
});
var NewView = Backbone.Layout.extend({
template: "not-even-close-to-real",
fetchTemplate: function() {
setTimeout(this.async(), 20);
}
});
var newView = new NewView();
$("body").append(newView.el);
newView.insertView(new NestedView());
newView.render();
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/118
asyncTest("events not correctly bound", 1, function() {
var hit = false;
var m = new Backbone.Model();
var EventView = Backbone.Layout.extend({
events: {
click: "myFunc"
},
myFunc: function() {
hit = true;
},
cleanup: function() {
this.model.off(null, null, this);
},
initialize: function() {
this.model.on("change", this.render, this);
}
});
var Layout = Backbone.Layout.extend({
template: "<p></p>",
fetchTemplate: function(name) {
return _.template(name);
},
beforeRender: function() {
this.insertView("p", new EventView({
model: m
}));
}
});
var view = new Layout();
view.$el.appendTo("#container");
view.render().promise().then(function() {
view.views.p[0].$el.click();
ok(hit, "Event was fired");
start();
});
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/126
asyncTest("render works when called late", 1, function() {
var hit = false;
var A = Backbone.Model.extend({});
var ACollection = Backbone.Collection.extend({ model: A });
var View = Backbone.Layout.extend({
template: "<div>Click Here</div>",
className: "hitMe",
fetchTemplate: function(path) {
return _.template(path);
},
events: {
click: "onClick"
},
initialize: function() {
this.collection.on("reset", function() {
this.render();
}, this);
},
onClick: function() {
hit = true;
}
});
var collection = new ACollection([]);
var layout = new Backbone.Layout({
template: "<div class='button'></div>",
fetchTemplate: function(path) {
return _.template(path);
},
views: {
".button": new View({ collection: collection })
}
});
layout.render().promise().then(function(){
layout.getView(".button").once("afterRender", function(){
// Simulate click.
layout.$(".hitMe").click();
ok(hit, "render works as expected when called late");
start();
});
collection.reset();
});
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/126
asyncTest("render works when assigned early", 1, function() {
var hit = false;
var A = Backbone.Model.extend({});
var ACollection = Backbone.Collection.extend({ model: A });
var View = Backbone.Layout.extend({
template: "<div>Click Here</div>",
className: "hitMe",
fetchTemplate: function(path) {
return _.template(path);
},
events: {
click: "onClick"
},
initialize: function() {
this.collection.on("reset", this.render, this);
},
onClick: function() {
hit = true;
}
});
var collection = new ACollection([]);
var layout = new Backbone.Layout({
template: "<div class='button'></div>",
fetchTemplate: function(path) {
return _.template(path);
},
views: {
".button": new View({ collection: collection })
}
});
layout.render().promise().then(function(){
layout.getView(".button").once("afterRender", function(){
// Simulate click.
layout.$(".hitMe").click();
ok(hit, "render works as expected when assigned early");
start();
});
collection.reset();
});
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/134
asyncTest("Ensure events are copied over properly", 1, function() {
var hit = false;
var layout = new Backbone.Layout({
template: "<p></p>",
fetchTemplate: function(path) { return _.template(path); },
events: {
"click p": "test"
},
test: function() {
hit = true;
}
});
layout.render().promise().then(function(){
layout.$("p").click();
ok(hit, "Events were bound and triggered correctly");
start();
});
});
// https://github.com/tbranyen/backbone.layoutmanager/issues/134
// https://github.com/tbranyen/backbone.layoutmanager/issues/139
asyncTest("events are bound correctly", 1, function() {
var hit = 0;
var l = new Backbone.Layout({
template: "<p></p>",
fetchTemplate: function(path) { return _.template(path); }
});
l.render();
var V = Backbone.Layout.extend({
keep: true,
template: "<span>hey</span>",
fetchTemplate: function(path) { return _.template(path); },
events: {
click: "hit"
},
hit: function() {
hit++;
}
});
// Insert two views.
l.insertView("p", new V());
l.insertView("p", new V());
// Render twice.
l.render();
l.render().promise().then(function() {
l.$("p div").trigger("click");
equal(hit, 2, "Event handler is bound and fired correctly");
start();
});
});
asyncTest("more events issues", 1, function() {
var hit = 0;
var V = Backbone.Layout.extend({
template: "<span>hey</span>",
fetchTemplate: function(path) { return _.template(path); },
events: {
click: "hit"
},
hit: function() {
hit++;
}
});
var S = Backbone.Layout.extend({
template: "<p></p>",
fetchTemplate: function(path) { return _.template(path); },
beforeRender: function() {
// Insert two views.
this.insertView("p", new V());
this.insertView("p", new V());
},
reset: function() {
this.render();
}
});
// Create a sub-layout.
var s = new S();
// Create a main layout.
var l = new Backbone.Layout({
views: {
"": s
}
});
// Render the layout.
l.render().promise().then(function(){
s.once("afterRender", function(){
l.$("p div").trigger("click");
equal(hit, 2, "Event handler is bound and fired correctly");
start();
});
// Re-render.
s.reset();
});
});
// Explicitly excersize the default `fetchTemplate` implementation (most tests override
// that functionality to use in-memory templates)
asyncTest("default `fetchTemplate` method retrieves template from element specified by DOM selector", 1, function() {
var vyou = new Backbone.Layout({
template: "#dom-template"
});
var expected, actual;
vyou.render().promise().then(function(){
expected = "This template lives in the <b>DOM</b>";
actual = testUtil.trim(vyou.$el.html());
equal(actual, expected, "Correctly fetches template string from the DOM");
start();
});
});
asyncTest("events delegated correctly when managing your own view element", 1, function() {
var view = new Backbone.View({
manage: true, el: false,
events: { "click": "onClick" },
onClick: function() {
this.clicked = true;
},
template: _.template(testUtil.templates.item),
serialize: { text: "lol" }
});
view.render().promise().then(function() {
view.$el.click();
equal(view.clicked, true, "onClick event was fired");
start();
});
});
asyncTest("afterRender callback is triggered too early", 2, function() {
var inDocument = false;
var ProblemView = Backbone.Layout.extend({
template: "not-real",
fetchTemplate: function() {
setTimeout(this.async(), 10);
},
afterRender: function() {
var doc = document.body;
inDocument = $.contains(doc, this.el);
ok(inDocument, "element in is in the page Document");
}
});
var NewView = Backbone.Layout.extend({
template: "not-real",
fetchTemplate: function() {
setTimeout(this.async(), 10);
},
beforeRender: function() {
this.insertView(new ProblemView());
}
});
var newView = new NewView();
$("body").append(newView.el);
newView.render().promise().then(function() {
newView.render().promise().then(function() {
start();
});
});
});
})();
+83
View File
@@ -0,0 +1,83 @@
(function(window) {
"use strict";
/*
* Test Module: Expose
* Ensures that LayoutManager is exposed properly.
*
*/
QUnit.module("expose", {
setup: function() {
// Backbone.Layout constructor for convenience.
this.Layout = Backbone.Layout;
// Backbone.LayoutManager constructor for main usage.
this.LayoutManager = Backbone.LayoutManager;
}
});
asyncTest("AMD support", 1, function() {
var requirejs = require;
var useLM = true;
// Node
if (!window.define) {
requirejs = require("requirejs");
useLM = false;
}
requirejs.config({
baseUrl: "../",
paths: {
underscore: "node_modules/underscore/underscore",
jquery: "node_modules/jquery/dist/jquery",
backbone: "node_modules/backbone/backbone"
}
});
if (!useLM) {
requirejs.define("backbone.layoutmanager", function() {
return require("../../");
});
}
requirejs(["backbone.layoutmanager"], function(LayoutManager) {
ok(LayoutManager.VERSION, "Version property exists");
start();
});
});
// Ensure the correct defaults are set for all Layout and View options.
test("attached", 2, function() {
// Layout should be a function.
ok(_.isFunction(this.Layout), "Layout shortcut is a function");
// LayoutManager should be a function.
ok(!_.isFunction(this.LayoutManager),
"LayoutManager shortcut is not a function");
});
// Browser only - ensure browserified module can be loaded
if (window.define) {
asyncTest("Browserify support", 2, function() {
var requirejs = require;
// Ensure that the browserify-built LM version works.
requirejs(["test/tmp/backbone.layoutmanager.browserify"], function(LayoutManager) {
ok(LayoutManager.VERSION, "Version property exists");
// Create a new layout with a sample template.
var layout = new LayoutManager({
template: testUtil.templates.main
});
// Render and check.
layout.render().promise().then(function() {
equal(this.$el.html().trim(), "Left", "Correct render output.");
start();
});
});
});
}
})(typeof global !== "undefined" ? global : this);
+28
View File
@@ -0,0 +1,28 @@
(function() {
"use strict";
/*
* Test Module: Configure
* Ensures that configuration settings have correct defaults, initialization,
* overriding, and functionality.
*
*/
QUnit.module("configure", {
setup: function() {
this.LM = require("../../");
}
});
// Ensure the correct defaults are set for all Layout and View options.
asyncTest("can render a basic template", 1, function() {
// Create a new layout with a sample template.
var layout = new this.LM({ template: "test/templates/test" });
// Render and check.
layout.render().promise().then(function() {
equal(this.$el.html().trim(), "Sample template.", "Correct render output.");
start();
});
});
})();
+99
View File
@@ -0,0 +1,99 @@
(function() {
"use strict";
/*
* Test Module: Setup
* Ensures that Layouts and Views can be set up correctly to work with
* LayoutManager.
*
*/
QUnit.module("setup", {
setup: function() {
// Backbone.LayoutManager constructor.
this.Layout = Backbone.Layout;
// Enhanced Backbone.View.
this.View = Backbone.View.extend({
manage: true
});
// Normal Backbone.View.
this.NormalView = Backbone.View.extend();
// Shortcut the setupView function.
this.setupView = this.Layout.setupView;
}
});
test("layout constructor", 6, function() {
var layout = new this.Layout({
template: "test"
});
// Is a Backbone.View.
ok(layout instanceof Backbone.View, "Is a Backbone.View");
// Ensure the layout has a views object container.
ok(_.isObject(layout.views), "Contains a views object");
// Ensure the layout has a __manager__ object.
ok(_.isObject(layout.__manager__), "Contains a __manager__ object");
// Has the correct template property set.
equal(layout.options.template, "test", "Has the correct template property");
// Has the setViews function.
ok(_.isFunction(layout.setViews), "Has the setViews function");
// Has the view function.
ok(_.isFunction(layout.setView), "Has the setView function");
});
test("view setupView", 7, function() {
var view = new this.View({
template: "test"
});
// Is a Backbone.View.
ok(view instanceof Backbone.View, "Is a Backbone.View");
// Ensure the view has a views object container.
ok(_.isObject(view.views), "Contains a views object");
// Ensure the view has a sections object container
ok(_.isObject(view.sections), "Contains a sections object");
// Ensure the view has a __manager__ object.
ok(_.isObject(view.__manager__), "Contains a __manager__ object");
// Has the correct template property set.
equal(view.options.template, "test", "Has the correct template property");
// Has the setViews function.
ok(_.isFunction(view.setViews), "Has the setViews function");
// Has the view function.
ok(_.isFunction(view.setView), "Has the setView function");
});
test("setupView does not copy all options to instance", 1, function() {
var view = new Backbone.View({
test: "this"
});
Backbone.Layout.setupView(view);
notEqual(view.test, "this", "View should not have options copied to instance");
});
test("Error exception is properly raised when vanilla View is used", 1, function() {
var layout = new this.Layout({
template: "test"
});
var view = new this.NormalView();
try {
layout.insertView(view);
} catch (ex) {
equal(ex.message, "The argument associated with selector '' is defined and a View. Set `manage` property to true for Backbone.View instances.", "Correct message");
}
});
test("`setView` exists on `Backbone.View` with `manage:true` set", 1, function() {
var view = new Backbone.View({ manage: true });
equal(typeof view.setView, "function", "setView is a function");
});
})();
+2845
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
Sample template.
+41
View File
@@ -0,0 +1,41 @@
/*jshint node:true */
var testUtil = {
trim: function(str) {
return str ? str.replace(/^\s+|\s+$/g, "") : "";
},
templates: {
main: "<div class='left'>Left</div><div class='right'></div>",
test: "<span class='inner-left'><%=text%></span><span class" +
"='inner-right'></span>",
testSub: "<%=text%>",
list: "<ul></ul>",
item: "<li><%=text%></li>",
view0: "<div class='view0'>0</div>",
view1: "<div class='view1'>1</div>",
view2: "<div class='view2'>2</div>",
view3: "<div class='view3'>3</div>",
listItem: "<div class='listItem'><%= item %></div>"
},
inNodeJs: function() {
return typeof module !== "undefined" && module.exports;
},
// isDomNode
// Determine if the supplied object is a DOM node (in Node.js, DOM nodes are
// simulated by Cheerio objects)
isDomNode: function(obj) {
if (testUtil.inNodeJs()) {
return obj && "type" in obj && "children" in obj && "parent" in obj;
} else {
return obj && obj.nodeType != null;
}
}
};
// If this code is running as a Node.js module, attach the utilities to the
// module.
if (testUtil.inNodeJs()) {
exports.testUtil = testUtil;
exports.lodash = require("lodash");
exports.underscore = require("underscore");
exports.bluebird = require("bluebird");
}
-1231
View File
File diff suppressed because it is too large Load Diff
-8981
View File
File diff suppressed because it is too large Load Diff
-839
View File
@@ -1,839 +0,0 @@
// Underscore.js 1.1.7
// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
// For all details and documentation:
// http://documentcloud.github.com/underscore
(function() {
// Baseline setup
// --------------
// Establish the root object, `window` in the browser, or `global` on the server.
var root = this;
// Save the previous value of the `_` variable.
var previousUnderscore = root._;
// Establish the object that gets returned to break out of a loop iteration.
var breaker = {};
// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
// Create quick reference variables for speed access to core prototypes.
var slice = ArrayProto.slice,
unshift = ArrayProto.unshift,
toString = ObjProto.toString,
hasOwnProperty = ObjProto.hasOwnProperty;
// All **ECMAScript 5** native function implementations that we hope to use
// are declared here.
var
nativeForEach = ArrayProto.forEach,
nativeMap = ArrayProto.map,
nativeReduce = ArrayProto.reduce,
nativeReduceRight = ArrayProto.reduceRight,
nativeFilter = ArrayProto.filter,
nativeEvery = ArrayProto.every,
nativeSome = ArrayProto.some,
nativeIndexOf = ArrayProto.indexOf,
nativeLastIndexOf = ArrayProto.lastIndexOf,
nativeIsArray = Array.isArray,
nativeKeys = Object.keys,
nativeBind = FuncProto.bind;
// Create a safe reference to the Underscore object for use below.
var _ = function(obj) { return new wrapper(obj); };
// Export the Underscore object for **CommonJS**, with backwards-compatibility
// for the old `require()` API. If we're not in CommonJS, add `_` to the
// global object.
if (typeof module !== 'undefined' && module.exports) {
module.exports = _;
_._ = _;
} else {
// Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _;
}
// Current version.
_.VERSION = '1.1.7';
// Collection Functions
// --------------------
// The cornerstone, an `each` implementation, aka `forEach`.
// Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available.
var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return;
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) {
if (iterator.call(context, obj[key], key, obj) === breaker) return;
}
}
}
};
// Return the results of applying the iterator to each element.
// Delegates to **ECMAScript 5**'s native `map` if available.
_.map = function(obj, iterator, context) {
var results = [];
if (obj == null) return results;
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
each(obj, function(value, index, list) {
results[results.length] = iterator.call(context, value, index, list);
});
return results;
};
// **Reduce** builds up a single result from a list of values, aka `inject`,
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
var initial = memo !== void 0;
if (obj == null) obj = [];
if (nativeReduce && obj.reduce === nativeReduce) {
if (context) iterator = _.bind(iterator, context);
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
}
each(obj, function(value, index, list) {
if (!initial) {
memo = value;
initial = true;
} else {
memo = iterator.call(context, memo, value, index, list);
}
});
if (!initial) throw new TypeError("Reduce of empty array with no initial value");
return memo;
};
// The right-associative version of reduce, also known as `foldr`.
// Delegates to **ECMAScript 5**'s native `reduceRight` if available.
_.reduceRight = _.foldr = function(obj, iterator, memo, context) {
if (obj == null) obj = [];
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
if (context) iterator = _.bind(iterator, context);
return memo !== void 0 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
}
var reversed = (_.isArray(obj) ? obj.slice() : _.toArray(obj)).reverse();
return _.reduce(reversed, iterator, memo, context);
};
// Return the first value which passes a truth test. Aliased as `detect`.
_.find = _.detect = function(obj, iterator, context) {
var result;
any(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) {
result = value;
return true;
}
});
return result;
};
// Return all the elements that pass a truth test.
// Delegates to **ECMAScript 5**'s native `filter` if available.
// Aliased as `select`.
_.filter = _.select = function(obj, iterator, context) {
var results = [];
if (obj == null) return results;
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
each(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) results[results.length] = value;
});
return results;
};
// Return all the elements for which a truth test fails.
_.reject = function(obj, iterator, context) {
var results = [];
if (obj == null) return results;
each(obj, function(value, index, list) {
if (!iterator.call(context, value, index, list)) results[results.length] = value;
});
return results;
};
// Determine whether all of the elements match a truth test.
// Delegates to **ECMAScript 5**'s native `every` if available.
// Aliased as `all`.
_.every = _.all = function(obj, iterator, context) {
var result = true;
if (obj == null) return result;
if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
each(obj, function(value, index, list) {
if (!(result = result && iterator.call(context, value, index, list))) return breaker;
});
return result;
};
// Determine if at least one element in the object matches a truth test.
// Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`.
var any = _.some = _.any = function(obj, iterator, context) {
iterator = iterator || _.identity;
var result = false;
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function(value, index, list) {
if (result |= iterator.call(context, value, index, list)) return breaker;
});
return !!result;
};
// Determine if a given value is included in the array or object using `===`.
// Aliased as `contains`.
_.include = _.contains = function(obj, target) {
var found = false;
if (obj == null) return found;
if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
any(obj, function(value) {
if (found = value === target) return true;
});
return found;
};
// Invoke a method (with arguments) on every item in a collection.
_.invoke = function(obj, method) {
var args = slice.call(arguments, 2);
return _.map(obj, function(value) {
return (method.call ? method || value : value[method]).apply(value, args);
});
};
// Convenience version of a common use case of `map`: fetching a property.
_.pluck = function(obj, key) {
return _.map(obj, function(value){ return value[key]; });
};
// Return the maximum element or (element-based computation).
_.max = function(obj, iterator, context) {
if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
var result = {computed : -Infinity};
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed >= result.computed && (result = {value : value, computed : computed});
});
return result.value;
};
// Return the minimum element (or element-based computation).
_.min = function(obj, iterator, context) {
if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj);
var result = {computed : Infinity};
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed < result.computed && (result = {value : value, computed : computed});
});
return result.value;
};
// Sort the object's values by a criterion produced by an iterator.
_.sortBy = function(obj, iterator, context) {
return _.pluck(_.map(obj, function(value, index, list) {
return {
value : value,
criteria : iterator.call(context, value, index, list)
};
}).sort(function(left, right) {
var a = left.criteria, b = right.criteria;
return a < b ? -1 : a > b ? 1 : 0;
}), 'value');
};
// Groups the object's values by a criterion produced by an iterator
_.groupBy = function(obj, iterator) {
var result = {};
each(obj, function(value, index) {
var key = iterator(value, index);
(result[key] || (result[key] = [])).push(value);
});
return result;
};
// Use a comparator function to figure out at what index an object should
// be inserted so as to maintain order. Uses binary search.
_.sortedIndex = function(array, obj, iterator) {
iterator || (iterator = _.identity);
var low = 0, high = array.length;
while (low < high) {
var mid = (low + high) >> 1;
iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid;
}
return low;
};
// Safely convert anything iterable into a real, live array.
_.toArray = function(iterable) {
if (!iterable) return [];
if (iterable.toArray) return iterable.toArray();
if (_.isArray(iterable)) return slice.call(iterable);
if (_.isArguments(iterable)) return slice.call(iterable);
return _.values(iterable);
};
// Return the number of elements in an object.
_.size = function(obj) {
return _.toArray(obj).length;
};
// Array Functions
// ---------------
// Get the first element of an array. Passing **n** will return the first N
// values in the array. Aliased as `head`. The **guard** check allows it to work
// with `_.map`.
_.first = _.head = function(array, n, guard) {
return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
};
// Returns everything but the first entry of the array. Aliased as `tail`.
// Especially useful on the arguments object. Passing an **index** will return
// the rest of the values in the array from that index onward. The **guard**
// check allows it to work with `_.map`.
_.rest = _.tail = function(array, index, guard) {
return slice.call(array, (index == null) || guard ? 1 : index);
};
// Get the last element of an array.
_.last = function(array) {
return array[array.length - 1];
};
// Trim out all falsy values from an array.
_.compact = function(array) {
return _.filter(array, function(value){ return !!value; });
};
// Return a completely flattened version of an array.
_.flatten = function(array) {
return _.reduce(array, function(memo, value) {
if (_.isArray(value)) return memo.concat(_.flatten(value));
memo[memo.length] = value;
return memo;
}, []);
};
// Return a version of the array that does not contain the specified value(s).
_.without = function(array) {
return _.difference(array, slice.call(arguments, 1));
};
// Produce a duplicate-free version of the array. If the array has already
// been sorted, you have the option of using a faster algorithm.
// Aliased as `unique`.
_.uniq = _.unique = function(array, isSorted) {
return _.reduce(array, function(memo, el, i) {
if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) memo[memo.length] = el;
return memo;
}, []);
};
// Produce an array that contains the union: each distinct element from all of
// the passed-in arrays.
_.union = function() {
return _.uniq(_.flatten(arguments));
};
// Produce an array that contains every item shared between all the
// passed-in arrays. (Aliased as "intersect" for back-compat.)
_.intersection = _.intersect = function(array) {
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
return _.indexOf(other, item) >= 0;
});
});
};
// Take the difference between one array and another.
// Only the elements present in just the first array will remain.
_.difference = function(array, other) {
return _.filter(array, function(value){ return !_.include(other, value); });
};
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
var args = slice.call(arguments);
var length = _.max(_.pluck(args, 'length'));
var results = new Array(length);
for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i);
return results;
};
// If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
// we need this function. Return the position of the first occurrence of an
// item in an array, or -1 if the item is not included in the array.
// Delegates to **ECMAScript 5**'s native `indexOf` if available.
// If the array is large and already in sort order, pass `true`
// for **isSorted** to use binary search.
_.indexOf = function(array, item, isSorted) {
if (array == null) return -1;
var i, l;
if (isSorted) {
i = _.sortedIndex(array, item);
return array[i] === item ? i : -1;
}
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
return -1;
};
// Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
_.lastIndexOf = function(array, item) {
if (array == null) return -1;
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
var i = array.length;
while (i--) if (array[i] === item) return i;
return -1;
};
// Generate an integer Array containing an arithmetic progression. A port of
// the native Python `range()` function. See
// [the Python documentation](http://docs.python.org/library/functions.html#range).
_.range = function(start, stop, step) {
if (arguments.length <= 1) {
stop = start || 0;
start = 0;
}
step = arguments[2] || 1;
var len = Math.max(Math.ceil((stop - start) / step), 0);
var idx = 0;
var range = new Array(len);
while(idx < len) {
range[idx++] = start;
start += step;
}
return range;
};
// Function (ahem) Functions
// ------------------
// Create a function bound to a given object (assigning `this`, and arguments,
// optionally). Binding with arguments is also known as `curry`.
// Delegates to **ECMAScript 5**'s native `Function.bind` if available.
// We check for `func.bind` first, to fail fast when `func` is undefined.
_.bind = function(func, obj) {
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
var args = slice.call(arguments, 2);
return function() {
return func.apply(obj, args.concat(slice.call(arguments)));
};
};
// Bind all of an object's methods to that object. Useful for ensuring that
// all callbacks defined on an object belong to it.
_.bindAll = function(obj) {
var funcs = slice.call(arguments, 1);
if (funcs.length == 0) funcs = _.functions(obj);
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
return obj;
};
// Memoize an expensive function by storing its results.
_.memoize = function(func, hasher) {
var memo = {};
hasher || (hasher = _.identity);
return function() {
var key = hasher.apply(this, arguments);
return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
};
};
// Delays a function for the given number of milliseconds, and then calls
// it with the arguments supplied.
_.delay = function(func, wait) {
var args = slice.call(arguments, 2);
return setTimeout(function(){ return func.apply(func, args); }, wait);
};
// Defers a function, scheduling it to run after the current call stack has
// cleared.
_.defer = function(func) {
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
};
// Internal function used to implement `_.throttle` and `_.debounce`.
var limit = function(func, wait, debounce) {
var timeout;
return function() {
var context = this, args = arguments;
var throttler = function() {
timeout = null;
func.apply(context, args);
};
if (debounce) clearTimeout(timeout);
if (debounce || !timeout) timeout = setTimeout(throttler, wait);
};
};
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time.
_.throttle = function(func, wait) {
return limit(func, wait, false);
};
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds.
_.debounce = function(func, wait) {
return limit(func, wait, true);
};
// Returns a function that will be executed at most one time, no matter how
// often you call it. Useful for lazy initialization.
_.once = function(func) {
var ran = false, memo;
return function() {
if (ran) return memo;
ran = true;
return memo = func.apply(this, arguments);
};
};
// Returns the first function passed as an argument to the second,
// allowing you to adjust arguments, run code before and after, and
// conditionally execute the original function.
_.wrap = function(func, wrapper) {
return function() {
var args = [func].concat(slice.call(arguments));
return wrapper.apply(this, args);
};
};
// Returns a function that is the composition of a list of functions, each
// consuming the return value of the function that follows.
_.compose = function() {
var funcs = slice.call(arguments);
return function() {
var args = slice.call(arguments);
for (var i = funcs.length - 1; i >= 0; i--) {
args = [funcs[i].apply(this, args)];
}
return args[0];
};
};
// Returns a function that will only be executed after being called N times.
_.after = function(times, func) {
return function() {
if (--times < 1) { return func.apply(this, arguments); }
};
};
// Object Functions
// ----------------
// Retrieve the names of an object's properties.
// Delegates to **ECMAScript 5**'s native `Object.keys`
_.keys = nativeKeys || function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
return keys;
};
// Retrieve the values of an object's properties.
_.values = function(obj) {
return _.map(obj, _.identity);
};
// Return a sorted list of the function names available on the object.
// Aliased as `methods`
_.functions = _.methods = function(obj) {
var names = [];
for (var key in obj) {
if (_.isFunction(obj[key])) names.push(key);
}
return names.sort();
};
// Extend a given object with all the properties in passed-in object(s).
_.extend = function(obj) {
each(slice.call(arguments, 1), function(source) {
for (var prop in source) {
if (source[prop] !== void 0) obj[prop] = source[prop];
}
});
return obj;
};
// Fill in a given object with default properties.
_.defaults = function(obj) {
each(slice.call(arguments, 1), function(source) {
for (var prop in source) {
if (obj[prop] == null) obj[prop] = source[prop];
}
});
return obj;
};
// Create a (shallow-cloned) duplicate of an object.
_.clone = function(obj) {
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
};
// Invokes interceptor with the obj, and then returns obj.
// The primary purpose of this method is to "tap into" a method chain, in
// order to perform operations on intermediate results within the chain.
_.tap = function(obj, interceptor) {
interceptor(obj);
return obj;
};
// Perform a deep comparison to check if two objects are equal.
_.isEqual = function(a, b) {
// Check object identity.
if (a === b) return true;
// Different types?
var atype = typeof(a), btype = typeof(b);
if (atype != btype) return false;
// Basic equality test (watch out for coercions).
if (a == b) return true;
// One is falsy and the other truthy.
if ((!a && b) || (a && !b)) return false;
// Unwrap any wrapped objects.
if (a._chain) a = a._wrapped;
if (b._chain) b = b._wrapped;
// One of them implements an isEqual()?
if (a.isEqual) return a.isEqual(b);
if (b.isEqual) return b.isEqual(a);
// Check dates' integer values.
if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
// Both are NaN?
if (_.isNaN(a) && _.isNaN(b)) return false;
// Compare regular expressions.
if (_.isRegExp(a) && _.isRegExp(b))
return a.source === b.source &&
a.global === b.global &&
a.ignoreCase === b.ignoreCase &&
a.multiline === b.multiline;
// If a is not an object by this point, we can't handle it.
if (atype !== 'object') return false;
// Check for different array lengths before comparing contents.
if (a.length && (a.length !== b.length)) return false;
// Nothing else worked, deep compare the contents.
var aKeys = _.keys(a), bKeys = _.keys(b);
// Different object sizes?
if (aKeys.length != bKeys.length) return false;
// Recursive comparison of contents.
for (var key in a) if (!(key in b) || !_.isEqual(a[key], b[key])) return false;
return true;
};
// Is a given array or object empty?
_.isEmpty = function(obj) {
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
return true;
};
// Is a given value a DOM element?
_.isElement = function(obj) {
return !!(obj && obj.nodeType == 1);
};
// Is a given value an array?
// Delegates to ECMA5's native Array.isArray
_.isArray = nativeIsArray || function(obj) {
return toString.call(obj) === '[object Array]';
};
// Is a given variable an object?
_.isObject = function(obj) {
return obj === Object(obj);
};
// Is a given variable an arguments object?
_.isArguments = function(obj) {
return !!(obj && hasOwnProperty.call(obj, 'callee'));
};
// Is a given value a function?
_.isFunction = function(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
};
// Is a given value a string?
_.isString = function(obj) {
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
};
// Is a given value a number?
_.isNumber = function(obj) {
return !!(obj === 0 || (obj && obj.toExponential && obj.toFixed));
};
// Is the given value `NaN`? `NaN` happens to be the only value in JavaScript
// that does not equal itself.
_.isNaN = function(obj) {
return obj !== obj;
};
// Is a given value a boolean?
_.isBoolean = function(obj) {
return obj === true || obj === false;
};
// Is a given value a date?
_.isDate = function(obj) {
return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
};
// Is the given value a regular expression?
_.isRegExp = function(obj) {
return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
};
// Is a given value equal to null?
_.isNull = function(obj) {
return obj === null;
};
// Is a given variable undefined?
_.isUndefined = function(obj) {
return obj === void 0;
};
// Utility Functions
// -----------------
// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
// previous owner. Returns a reference to the Underscore object.
_.noConflict = function() {
root._ = previousUnderscore;
return this;
};
// Keep the identity function around for default iterators.
_.identity = function(value) {
return value;
};
// Run a function **n** times.
_.times = function (n, iterator, context) {
for (var i = 0; i < n; i++) iterator.call(context, i);
};
// Add your own custom functions to the Underscore object, ensuring that
// they're correctly added to the OOP wrapper as well.
_.mixin = function(obj) {
each(_.functions(obj), function(name){
addToWrapper(name, _[name] = obj[name]);
});
};
// Generate a unique integer id (unique within the entire client session).
// Useful for temporary DOM ids.
var idCounter = 0;
_.uniqueId = function(prefix) {
var id = idCounter++;
return prefix ? prefix + id : id;
};
// By default, Underscore uses ERB-style template delimiters, change the
// following template settings to use alternative delimiters.
_.templateSettings = {
evaluate : /<%([\s\S]+?)%>/g,
interpolate : /<%=([\s\S]+?)%>/g
};
// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
_.template = function(str, data) {
var c = _.templateSettings;
var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
'with(obj||{}){__p.push(\'' +
str.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
.replace(c.interpolate, function(match, code) {
return "'," + code.replace(/\\'/g, "'") + ",'";
})
.replace(c.evaluate || null, function(match, code) {
return "');" + code.replace(/\\'/g, "'")
.replace(/[\r\n\t]/g, ' ') + "__p.push('";
})
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n')
.replace(/\t/g, '\\t')
+ "');}return __p.join('');";
var func = new Function('obj', tmpl);
return data ? func(data) : func;
};
// The OOP Wrapper
// ---------------
// If Underscore is called as a function, it returns a wrapped object that
// can be used OO-style. This wrapper holds altered versions of all the
// underscore functions. Wrapped objects may be chained.
var wrapper = function(obj) { this._wrapped = obj; };
// Expose `wrapper.prototype` as `_.prototype`
_.prototype = wrapper.prototype;
// Helper function to continue chaining intermediate results.
var result = function(obj, chain) {
return chain ? _(obj).chain() : obj;
};
// A method to easily add functions to the OOP wrapper.
var addToWrapper = function(name, func) {
wrapper.prototype[name] = function() {
var args = slice.call(arguments);
unshift.call(args, this._wrapped);
return result(func.apply(_, args), this._chain);
};
};
// Add all of the Underscore functions to the wrapper object.
_.mixin(_);
// Add all mutator Array functions to the wrapper.
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
var method = ArrayProto[name];
wrapper.prototype[name] = function() {
method.apply(this._wrapped, arguments);
return result(this._wrapped, this._chain);
};
});
// Add all accessor Array functions to the wrapper.
each(['concat', 'join', 'slice'], function(name) {
var method = ArrayProto[name];
wrapper.prototype[name] = function() {
return result(method.apply(this._wrapped, arguments), this._chain);
};
});
// Start chaining a wrapped Underscore object.
wrapper.prototype.chain = function() {
this._chain = true;
return this;
};
// Extracts the result from a wrapped and chained object.
wrapper.prototype.value = function() {
return this._wrapped;
};
})();
-229
View File
@@ -1,229 +0,0 @@
function isNode(obj) {
if (obj && obj.nodeType != null) {
return true;
}
}
module("views", {
setup: function() {
var setup = this;
// Custom View
this.View = Backbone.LayoutManager.View.extend({
template: "#test",
serialize: function() {
return { text: this.msg };
},
initialize: function(opts) {
this.msg = opts.msg;
}
});
this.SubView = Backbone.LayoutManager.View.extend({
template: "#test-sub",
serialize: function() {
return { text: "Right" };
}
});
this.ListView = Backbone.View.extend({
template: "#list",
render: function(layout) {
var view = layout(this);
// Iterate over the passed collection and insert into the view
_.each(this.collection, function(model) {
view.insert("ul", new setup.ItemView({ model: model }));
}, this);
return view.render();
}
});
this.ItemView = Backbone.LayoutManager.View.extend({
template: "#test-sub",
tagName: "li",
serialize: function() {
return this.model;
}
});
}
});
asyncTest("render outside defined partial", function() {
var main = new Backbone.LayoutManager({
template: "#main"
});
main.view(".right", new this.View({ msg: "Right" }));
main.render(function(el) {
var trimmed = $.trim( $(el).find(".inner-left").html() );
ok(isNode(el), "Contents is a DOM Node");
equal(trimmed, "Right", "Correct render");
start();
});
});
asyncTest("render inside defined partial", function() {
var main = new Backbone.LayoutManager({
template: "#main",
views: {
".right": new this.View({ msg: "Right" })
}
});
main.render(function(el) {
var trimmed = $.trim( $(el).find(".inner-left").html() );
ok(isNode(el), "Contents is a DOM Node");
equal(trimmed, "Right", "Correct render");
start();
});
});
asyncTest("re-render a view defined after initialization", function(){
var trimmed;
var main = new Backbone.LayoutManager({
template: "#main"
});
main.view(".right", new this.View({ msg: "Right" }));
main.render(function(el) {
$('#container').html(el);
});
main.views[".right"].render();
trimmed = $.trim( $("#container .inner-left").html() );
equal(trimmed, "Right", "Correct re-render");
main.view(".right", new this.View({ msg: "Right Again" })).render();
trimmed = $.trim( $("#container .inner-left").html() );
equal(trimmed, "Right Again", "Correct re-render");
start();
})
asyncTest("nested views", function() {
var main = new Backbone.LayoutManager({
template: "#main",
views: {
".right": new this.View({
msg: "Left",
views: {
".inner-right": new this.SubView()
}
})
}
});
main.render(function(el) {
var trimmed = $.trim( $(el).find(".inner-right div").html() );
ok(isNode(el), "Contents is a DOM Node");
equal(trimmed, "Right", "Correct render");
start();
});
});
test("serialize on LayoutManager is a function", function() {
var testText = "test text";
var main = new Backbone.LayoutManager({
template: "#test-sub",
serialize: { text: "test text" }
});
main.render(function(el) {
equal($.trim( $(el).text() ), testText, "correct serialize");
});
});
test("serialize on LayoutManager is an object", function() {
var testText = "test text";
var main = new Backbone.LayoutManager({
template: "#test-sub",
serialize: { text: "test text" }
});
main.render(function(el) {
equal($.trim( $(el).text() ), testText, "correct serialize");
});
});
asyncTest("insert views", function() {
var main = new Backbone.LayoutManager({
template: "#main",
views: {
".right": new this.ListView({
collection: [{ text: "one" }, { text: "two" }]
})
}
});
main.render(function(el) {
ok(isNode(el), "Contents is a DOM Node");
equal($(el).find("ul li").length, 2, "Correct number of nested li's");
equal($.trim( $(el).find("ul li:eq(0)").html() ), "one", "Correct first li content");
equal($.trim( $(el).find("ul li:eq(1)").html() ), "two", "Correct second li content");
start();
});
});
asyncTest("nested views using setViews", function() {
var main = new Backbone.LayoutManager({
template: "#main"
});
main.setViews({
".right": new this.View({
msg: "Left",
views: {
".inner-right": new this.SubView()
}
})
});
main.render(function(el) {
var trimmed = $.trim( $(el).find(".inner-right div").html() );
ok(isNode(el), "Contents is a DOM Node");
equal(trimmed, "Right", "Correct render");
start();
});
});
test("extend layoutmanager", function() {
var testText = "test text";
var BaseLayout = Backbone.LayoutManager.extend({
template: "#test-sub",
serialize: { text: "test text" }
});
var main = new BaseLayout();
main.render(function(el) {
equal($.trim( $(el).text() ), testText, "correct serialize");
});
});