├── .DS_Store ├── .gitignore ├── CHANGELOG.md ├── Gruntfile.js ├── LICENSE.html ├── README.md ├── base.css ├── bower.json ├── dist ├── .DS_Store ├── backbone.collectionView.js └── backbone.collectionView.min.js ├── package.json ├── src └── backbone.collectionView.js ├── test ├── .DS_Store ├── index.html ├── lib │ ├── backbone.babysitter.js │ ├── backbone.js │ ├── jquery-1.9.1.js │ ├── jquery-ui.css │ ├── jquery-ui.js │ ├── qunit-1.11.0.css │ ├── qunit-1.11.0.js │ └── underscore.js └── tests.js └── zips └── Backbone.CollectionView.zip /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rotundasoftware/backbone.collectionView/63109a35255b91ca220c2b3988c964000f48477b/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .sass-cache 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | ### v1.2.0 4 | 5 | * Added 'click' event 6 | 7 | ### v0.11.0 8 | 9 | * Added `reuseModelViews` option. Set to false to completely recreate model views on each render. 10 | 11 | ### v0.10.1 12 | 13 | * Brought npm package version in sync with Bower package. How'd that happen? 14 | * Fixed issue that could surface when setting multiple models using collection.set (#50) 15 | 16 | ### v0.9.3 17 | 18 | * Fixed UMD wrapper. 19 | 20 | ### v0.9.2 21 | 22 | * Added UMD wrapper. 23 | 24 | ### v0.9.0 25 | 26 | * No longer re-render upon add() and remove() events in the collection. 27 | * Due to the above, "render" events no longer trigger during add() or remove() calls on a collection. 28 | * Made use of backbone.viewOptions by including it and updating the source to use it's facilities. 29 | 30 | ### v0.8.2 31 | 32 | * Patch for better bower support. 33 | 34 | ### v0.8.1 35 | 36 | * If a modelView's element is an
  • , don't wrap in an extra
  • when rendering 37 | * Fix accidental item removal after sort stop when rendering as table. 38 | * Add sortableOptions constructor option which is passed through to the created jQuery sortable. 39 | 40 | ### v0.8 41 | 42 | * data-item-id attribute has been changed to data-model-cid for clarity 43 | * selectableModelsFilter can no longer be a string. 44 | * After the collection view is reordered via dragging: if the collection has a comparator, sort after adding all the models in the visual order. 45 | * Never "rerender" the collection view unless it has already been rendered. For example, adding models to the collection should not render the collection view if it was not previously rendered. 46 | * Don't listen to events from old collection when setOptions( "collection", newCollection ) is called 47 | 48 | ### v0.7.1 49 | 50 | * Use css classes to keep track of and determine visibility of an item 51 | * Call remove() on views in viewManager when they are removed (so they stop listening to events) 52 | * Add `detachedRendering` option (defaults to `false`) to improve performance by rendering all modelViews before inserting into the DOM. 53 | 54 | ### v0.7.0 55 | 56 | * Fix to work with underscore.js 1.5.1 (remove `_.bindAll` and use `.bind` where necessary). 57 | * Listen for `mousedown` event instead of `click` when `clickToSelect` is enabled. 58 | * Hide empty list caption when dragging item into a `sortable` collection view. 59 | 60 | ### v0.6.5 61 | 62 | * Model views that represent a particular model are now reused between renders. 63 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | grunt.initConfig({ 4 | pkg: grunt.file.readJSON('package.json'), 5 | banner: '/*!\n' + 6 | '* Backbone.CollectionView, v<%= pkg.version %>\n' + 7 | '* Copyright (c)2013 Rotunda Software, LLC.\n' + 8 | '* Distributed under MIT license\n' + 9 | '* http://github.com/rotundasoftware/backbone-collection-view\n' + 10 | '*/\n\n', 11 | 12 | // Task configuration. 13 | concat: { 14 | options: { 15 | banner: '<%= banner %>', 16 | stripBanners: true 17 | }, 18 | js: { 19 | src: ['src/backbone.collectionView.js'], 20 | dest: 'dist/backbone.collectionView.js' 21 | } 22 | }, 23 | uglify: { 24 | options: { 25 | banner: '<%= banner %>' 26 | }, 27 | dist: { 28 | src: '<%= concat.js.dest %>', 29 | dest: 'dist/backbone.collectionView.min.js' 30 | } 31 | }, 32 | compress: { 33 | dist: { 34 | options: { 35 | archive: 'zips/Backbone.CollectionView.zip' 36 | }, 37 | expand: true, 38 | cwd: 'dist/', 39 | src: ['**/*'], 40 | dest: './' 41 | } 42 | }, 43 | jshint: { 44 | options: { 45 | curly: true, 46 | eqeqeq: true, 47 | immed: true, 48 | latedef: true, 49 | newcap: true, 50 | noarg: true, 51 | sub: true, 52 | undef: true, 53 | unused: true, 54 | boss: true, 55 | eqnull: true, 56 | browser: true, 57 | globals: { 58 | jQuery: true 59 | } 60 | }, 61 | library: { 62 | src: 'collectionView.js' 63 | } 64 | } 65 | }); 66 | 67 | grunt.loadNpmTasks('grunt-contrib-concat'); 68 | grunt.loadNpmTasks('grunt-contrib-uglify'); 69 | grunt.loadNpmTasks('grunt-contrib-jshint'); 70 | grunt.loadNpmTasks('grunt-contrib-compress'); 71 | 72 | grunt.registerTask('default', ['concat', 'uglify', 'compress']); 73 | 74 | }; 75 | -------------------------------------------------------------------------------- /LICENSE.html: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 David Beck, Rotunda Software 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backbone.CollectionView 2 | 3 | __For demos see [the Backbone.CollectionView home page](http://rotundasoftware.github.com/backbone.collectionView/).__ 4 | 5 | Depends on jQuery and jQueryUI for event handling and sorting, respectively. 6 | 7 | ## Benefits 8 | 9 | * Renders a collection of models, updating automatically when models are added or removed. 10 | * Keeps track of selected model(s) and fires events when the selection is changed. 11 | * Adds "selected" css class to selected model views for easy stying. 12 | * Supports single and multiple selection through meta-key and shift clicks. 13 | * Allows a user to reorder the collection by dragging and dropping. 14 | * Supports changing the currently selected model(s) through up and down arrow key presses. 15 | * Allows you to filter which models are visible, selectable, and sortable. 16 | * Integrates with [Backbone.Courier](https://github.com/rotundasoftware/backbone.courier) out of the box. 17 | 18 | ## Sample Usage 19 | ```javascript 20 | var myCollectionView = new Backbone.CollectionView( { 21 | el : $( "#listForCollection" ), // must be a 'ul' (i.e. unordered list) or 'table' element 22 | modelView : EmployeeView, // a View class to be used for rendering each model in the collection 23 | collection : employeeCollection 24 | } ); 25 | 26 | myCollectionView.render(); 27 | myCollectionView.setSelectedModel( employeeCollection.first() ); 28 | ``` 29 | 30 | ## Initialization Options 31 | * `el` : A `