├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── bower.json
├── karma.conf.js
├── knockout-js-infinite-scroll.js
├── package.json
└── tests.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/*
2 | bower_components/*
3 | coverage/*
4 | .idea*
5 | /*.project
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - "0.10"
5 |
6 | install:
7 | - npm install -g brunch bower
8 | - bower install
9 | - npm install
10 |
11 | script:
12 | - ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Baz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Knockout JS (KO) Infinite Scroll
2 | ===========================
3 |
4 | [](https://travis-ci.org/thinkloop/knockout-js-infinite-scroll)
5 | [](https://coveralls.io/r/thinkloop/knockout-js-infinite-scroll?branch=master)
6 |
7 | This is a KnockoutJS extender that provides infinite scroll functionality to an observable array by automatically filtering it down to only the items visible on screen. It was developed to display and scroll various long lists of complex items on [OppositeofOpposite.com](http://www.oppositeofopposite.com/), such as the main items list, the friends list and the categories list.
8 |
9 | ###Example Fiddle: http://jsfiddle.net/thinkloop/7MqJ2/###
10 |
11 | The example fiddle shows the simplest implmentation of this component, see the next sections for important in-practice tips.
12 |
13 | ###Scale to Thousands of Items###
14 | There is an important technique that allows this to scale to many thousands of complex items. Say we were working with a Pinterest style layout, where items with heavy content are floated next to each other forever. When items scroll out of view, we can unload their expensive contents (images, comments, styling, etc.), while keeping the top-level containers to maintain document structure:
15 |
16 | ```html
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | ````
25 |
26 | We compare $index to firstVisibleIndex and only render the contents of items that are actually visible on screen. This way users can scroll through many thousands of items without any performance issues, since the majority of the containers will be empty and light-weight.
27 |
28 |
29 | ###Bower
30 |
31 | - `bower install git://github.com/thinkloop/knockout-js-infinite-scroll.git`
32 |
33 | ###Run tests
34 |
35 | Install dependencies:
36 | - install [node.js](nodejs.org)
37 | - `npm install -g bower`
38 | - `bower install`
39 | - `npm install`
40 |
41 | Run tests: `npm test`
42 |
43 | coverage report in html is in *coverage/*
44 |
45 | ---
46 |
47 | #####Don't hesitate to ask questions in issues, or star the repo if you like it!###
48 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "knockout-js-infinite-scroll",
3 | "description": "Knockout JS (KO) extender that provides infinite scroll functionality to an observable array by automatically filtering it down to only the items visible on screen.",
4 | "homepage": "https://github.com/thinkloop/knockout-js-infinite-scroll",
5 | "authors": [
6 | "Baz "
7 | ],
8 | "license": "MIT",
9 | "keywords": [
10 | "knockout",
11 | "ko",
12 | "infinite",
13 | "scroll"
14 | ],
15 | "version": "0.1.0",
16 | "main": "knockout-js-infinite-scroll.js",
17 | "dependencies": {
18 | "knockout": "~3.2.0"
19 | },
20 | "devDependencies": {
21 | "mocha": "~1.18",
22 | "chai": "~1.9",
23 | "sinon": "1.8.2",
24 | "sinon-chai": "2.5.0",
25 | "commonjs-require-definition": "~0.1.2"
26 | },
27 | "ignore": [
28 | "**/.*",
29 | "node_modules",
30 | "bower_components",
31 | "test",
32 | "tests",
33 | ".gitignore",
34 | "README.md"
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration
2 | // Generated on Wed Feb 26 2014 09:39:36 GMT+0100 (CET)
3 |
4 | module.exports = function(config) {
5 | config.set({
6 |
7 | // base path that will be used to resolve all patterns (eg. files, exclude)
8 | basePath: '',
9 |
10 | // frameworks to use
11 | frameworks: ['mocha'],
12 |
13 | // list of files / patterns to load in the browser
14 | files: [
15 | 'bower_components/commonjs-require-definition/require.js',
16 | 'bower_components/knockout/dist/knockout.js',
17 | 'bower_components/mocha/mocha.js',
18 | 'bower_components/chai/chai.js',
19 | 'bower_components/sinon-chai/lib/sinon-chai.js',
20 | 'bower_components/sinon/lib/sinon.js',
21 | 'knockout-js-infinite-scroll.js',
22 | 'tests.js'
23 | ],
24 |
25 | // list of files to exclude
26 | exclude: [
27 |
28 | ],
29 |
30 | // test results reporter to use
31 | // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
32 | reporters: ['progress', 'coverage', 'coveralls'],
33 |
34 | // preprocess matching files before serving them to the browser
35 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
36 | preprocessors: {
37 | 'knockout-js-infinite-scroll.js': 'coverage'
38 | },
39 |
40 | // test results reporter to use
41 | // possible values: 'dots', 'progress'
42 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter
43 | coverageReporter: {
44 | reporters: [
45 | {type: 'html', dir: 'coverage/'},
46 | {type: 'lcov', dir: 'coverage/'}
47 | ]
48 | },
49 |
50 | coverallsReporter: {
51 | repoToken: "BMoZLkpnTVMTl8BzixWMIdxYavV5xPl3G"
52 | },
53 |
54 | // web server port
55 | port: 9876,
56 |
57 | // enable / disable colors in the output (reporters and logs)
58 | colors: true,
59 |
60 |
61 | // level of logging
62 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
63 | logLevel: config.LOG_INFO,
64 |
65 | // enable / disable watching file and executing tests whenever any file changes
66 | autoWatch: true,
67 |
68 | // start these browsers
69 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
70 | browsers: ['PhantomJS'],
71 |
72 | // If browser does not capture in given timeout [ms], kill it
73 | captureTimeout: 60000,
74 |
75 | // Continuous Integration mode
76 | // if true, Karma captures browsers, runs the tests and exits
77 | singleRun: true
78 | });
79 | };
80 |
--------------------------------------------------------------------------------
/knockout-js-infinite-scroll.js:
--------------------------------------------------------------------------------
1 | (function (factory) {
2 | // Module systems magic dance.
3 |
4 | /* istanbul ignore next - (code coverage ignore) */
5 | if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
6 | // CommonJS or Node: hard-coded dependency on "knockout"
7 | factory(require("knockout"), exports);
8 | } else if (typeof define === "function" && define["amd"]) {
9 | // AMD anonymous module with hard-coded dependency on "knockout"
10 | define(["knockout", "exports"], factory);
11 | } else {
12 | //