list.js-1.2.0/ 0000775 0000000 0000000 00000000000 12664333731 0013110 5 ustar 00root root 0000000 0000000 list.js-1.2.0/.gitignore 0000664 0000000 0000000 00000000055 12664333731 0015100 0 ustar 00root root 0000000 0000000 .DS_Store
lab/
components
build
node_modules
list.js-1.2.0/.jshintignore 0000664 0000000 0000000 00000000024 12664333731 0015610 0 ustar 00root root 0000000 0000000 src/utils/extend.js
list.js-1.2.0/Gruntfile.js 0000664 0000000 0000000 00000003413 12664333731 0015406 0 ustar 00root root 0000000 0000000 module.exports = function(grunt) {
"use strict";
grunt.initConfig({
pkg: require("./package.json"),
watch: {
scripts: {
files: ['src/*.js', 'src/utils/*.js', '*.js', 'test/*.html', 'test/*.js'],
tasks: ['test'],
options: {
spawn: false,
},
},
},
shell: {
mkdir: {
command: 'mkdir -p dist'
},
build: {
command: 'browserify index.js > dist/list.js',
options: {
stderr: true
}
},
remove: {
command: 'rm -fr node_modules dist'
}
},
jshint: {
code: {
src: ['Gruntfile.js', '*.js', 'src/*.js', 'src/utils/*.js'],
options: {
expr: true,
multistr: false,
globals: {
module: true
}
}
},
tests: {
src: ['test/(*|!mocha).js'],
options: {
expr: true,
multistr: true,
globals: {
jQuery: true,
module: true
}
}
}
},
uglify: {
target: {
files: {
'dist/list.min.js': ['dist/list.js']
}
}
},
mocha: {
cool: {
src: [ 'test/index.html' ],
options: {
run: true,
timeout: 10000,
bail: false,
log: true,
reporter: 'Nyan',
mocha: {
ignoreLeaks: false
}
}
}
}
});
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha');
grunt.registerTask('default', ['jshint:code', 'jshint:tests', 'shell:mkdir', 'shell:build']);
grunt.registerTask('dist', ['default', 'shell:mkdir', 'shell:build', 'uglify']);
grunt.registerTask('clean', ['shell:remove']);
grunt.registerTask('test', ['dist', 'mocha']);
return grunt;
};
list.js-1.2.0/History.md 0000664 0000000 0000000 00000022022 12664333731 0015071 0 ustar 00root root 0000000 0000000 # Changelog
### TODO
- Add tests for custom event handlers. 27e2d6fdeee7090eb1342a108013db898fc29b96
- Regex in search https://github.com/javve/list.js/issues/371
- Keep original order?
- Automatically add item in the right place if sort is active
- How to handle arrays?
- Implement debouncing in search?
- Better search https://github.com/javve/list.js/pull/312/files ?
- Investigate sort button defaults:
- https://github.com/javve/list.js/issues/316
- https://github.com/javve/list.js/pull/301
- Improve testability by decoupling things and make it possible to use require('') in tests
### 2016-02-27: 1.2.0
- **[Misc]** Move form Component to Browserify
[See commit →](https://github.com/javve/list.js/commit/58695c93849b78787d9cf78cbf9be20b01cdcc8a)
- **[Misc]** Add tests to make sure List.js works with require.js
[See commit →](https://github.com/javve/list.js/commit/360098a04b87e18afd1b09e293a01a8dc113a01e)
- **[Misc]** Update all dependencies to latest version
[See commit →](https://github.com/javve/list.js/commit/881991cd204a19af5ed3c62c1239c1206fa51e6c)
- **[Breaking]** set sort order with List.js not sort function.
[See commit →](https://github.com/javve/list.js/commit/81d1148489c99b8503e725805c2a6ce2bde47b11)
- **[Breaking]** set default page size to 10000 instead of 200 (because: page size is confusing for new users)
[See commit →](https://github.com/javve/list.js/commit/618565b203b61c34b868a9cb86eea899e75ea4b6)
- **[Breaking]** Rename list.helpers to list.utils
[See commit →](https://github.com/javve/list.js/commit/58695c93849b78787d9cf78cbf9be20b01cdcc8a)
- **[Feature]** Add support for data attributes and custom attributes ex. links and images. [See docs](http://listjs.com/).
[See commit →](https://github.com/javve/list.js/commit/a8e083dc0f642e90b7a3f3cc11b12f9bb353d3a0)
- **[Feature]** Add toJSON method.
[See commit →](https://github.com/javve/list.js/commit/570fd10e65fcf2e0d3d959ca42137625d9fd3b7c)
- **[Feature]** Add reIndex method that should be called if the html have been changed by something except List.js.
[See commit →](https://github.com/javve/list.js/commit/825b2b55d339de2bb78eb41145d56a8b27d3d888)
- **[Feature]** Add option searchColumns to defined default columns to search in.
[See commit →](https://github.com/javve/list.js/commit/b8b74f21f78c17f1c1842480084ffdb58edc26cd)
- **[Feature]** Support
in options.item
[See commit →](https://github.com/javve/list.js/commit/9700858168811b6559983d2cb792014213b817a6)
- **[Feature]** Make it possble to add event handlers on init `new List('listId', { searchComplete: function(list) {} })`.
[See commit →](https://github.com/javve/list.js/commit/b8b74f21f78c17f1c1842480084ffdb58edc26cd)
- **[Bugfix]** Don't throw error if searching in a empty list.
[See commit →](https://github.com/javve/list.js/commit/d805494732922024bb99090fb6521021189861e9)
- **[Bugfix]** Make it possible to use item.visible() on items not yet templated.
[See commit →](https://github.com/javve/list.js/commit/8e898b0e55a7d47a77ee27f109602bdb63183fda)
- **[Bugfix]** Include reference to List when initializing plugins. Fix for require.js which don't have a global reference to List.
[See commit →](https://github.com/javve/list.js/commit/40d3c5e5f98cf3bcb9624a5717d4435a0b6f49f6)
- **[Bugfix]** Fix index async. Fix #268
[See commit →](https://github.com/javve/list.js/commit/27e2d6fdeee7090eb1342a108013db898fc29b96)
- **[Bugfix]** Fix add async
[See commit →](https://github.com/javve/list.js/commit/237f926d3ea0036ffb8b255dd0da42387b6a653a)
- **[Bugfix]** Don't add empty item if empty list is initated with empty array.
[See commit →](https://github.com/javve/list.js/commit/607a176c12b2219fb5204a789cd44ef367a0025f)
- **[Bugfix]** Make sort case insensitive by default for the automatic buttons
[See commit →](https://github.com/javve/list.js/commit/44260b862f74dccd248d08ca1f7df2b422c8f439)
- **[Bugfix]** Clear all values from source item. Case: list.add({}) should not
get same values as first item in list
[See commit →](https://github.com/javve/list.js/commit/3a4733d52cff25ef99ee8a1326c0b54be81d64ca)
### 2014-02-03: 1.1.1
- **[Bugfix]** Update `javve/events` version which fixes critical bugs in Safari
for PC and PhantomJS (which makes the command line tests work again).
- **[Bugfix]** Clear search when clicking in the HTML5 clear button.
- **[Misc]** Add History.md file for changelog instead of having it at Listjs.com.
### 2014-02-03: 1.1.0
- **[Breaking]** The sorting API is update so it looks like this
`listObj.sort('name', { order: "asc "})` and `listObj.sort('name', { order: "desc "})`
instead or `listObj.sort('name', { desc: true/false })`.
- **[Feature]** Added support for default sort function `new List('id', { sortFunction: function(itemA, itemB) { .. }})`
- **[Feature]** Adding `data-order="asc/desc"` to a sort button makes that button only sort `asc` or `desc`, ie no to
- **[Bugfix]** Fix `grunt watch` bug.
- **[Bugfix]** Remove sorting when searching and filtering.
- **[Bugfix]** Fix sorting and search when using pagiation plugin
### 2014-01-17: 1.0.2
- **[Bugfix]** Fix error that broke the lib in IE8.
### 2013-11-12: 1.0.0
- **[Feature]** Add more events and enable to add them on initialization.
- **[Feature]** Add support for Component.js, Bower, RequireJS and CommonJS
- **[Feature]** Make it possible to remove event handlers by `.off('event', handler)`
- **[Improvement]** Many new tests
- **[Improvement]** Paging plugin default classes and structure now correspons to Twitter Bootstraps pagination.
- **[Improvement]** Make sorting case-insensitive (thanks @thomasklemm)
- **[Improvement]** Add item.\_values for direct access to a items values. Simplifies debugging. Note: Always use item.values() when interacting with the values.
- **[Bugfix]** `.add(items, callbak)` with `callback` set does no longer add an extra item.
- **[Bugfix]** `templater.set()` no longer is called twice in a `templater.get()` call.
- **[Bugfix]** Fix error when trying to sort `undefined,null,etc` values.
- **[Bugfix]** Fix error when trying to search `undefined,null,etc` values.
- **[Bugfix]** Fix issue #51, problems with filters/search + paging.
- **[Misc]** Almost completely rewritten codebase and started using Component
- **[Misc]** Moved the website into another repo called list-website
- **[Misc]** Add documentation for searching in specific columns.
- **[Change]** `listObj.get('valueName', value)` does now always returns an array. Previously it return an object if only one item matched and null if no match was found.
- **[Change]** The default sort order is now `asc` instead of `desc`.
- **[Change]** Syntax for searching in specific columns are now `.search('val', [ 'columnName', 'columnName2' ])` instead of `.search('val', { columnName: true, columnName2: true })`.
- **[Change]** Move plugins into seperated repos: github.com/javve/list.pagination.js and github.com/javve/list.fuzzysearch.js
- **[Change]** Plugin initiation have changed. See getting started with plugins
### 2012-04-24: 0.2.1
- Fuzzy Search plugin, `.filter()` changes and bug fixes *[Read more »](http://jonnystromberg.com/listjs-0-2-1-release-notes/)*
### 2012-01-23: 0.2.0
- Lots of updates and interesting features. *[Read more »](http://jonnystromberg.com/listjs-0-2-0-plugins-paging/)*
### 2011-12-15: 0.1.4
- `.filters()`, `.sort()` and `.search()` now deped on each other. If the list is filtered and then there is a search, the items hidden by the filters will stay hidden etc.
- `.filter()` is the only way to reset filter. `.filter(false)` does not work anymore.
### 2011-11-29: 0.1.3 release
- Added function `.clear()` that removes all items from the list
- Changed the sort function to be based on `data-sort` instead of `rel`
- When sorting one category, all sort-related classes will be removed from the other sort buttons
- Updated `.sort(valueName, sortFunction)` to `.sort(valueName, options)`, se more info in the documentation
### 2011-11-16: 0.1.2 release
- Sorting is now indicated by class `asc` or `desc` at sorting buttons
- Added three new small helper functions `hasClass(element, class)`, `addClass(element, class)``
and `removeClass(element, class)`
### 2011-10-20: 0.1.1 release
- Added possibility to reverse sort the list
### 2011-10-18: 0.1 release
- Examples at Listjs.com works in IE7,8,9 (IE6 is not tested, should work)
- More documentation
- Misc bug fixes
### 2011-10-15 Final alpha 0.3 release
- More documentation
- Only show 200 items at same time, huge speed increase
- Misc bug fixes
### 2011-08-08 Alpha 0.2 release
- Added asynchronous item adding
- Added asynchronous list indexing
- Improved (but incomplete) documentation
- Bugfixes and improved helper functions
- Show helper functions non-minified
### 2011-07-25 Alpha 0.1 release
list.js-1.2.0/LICENSE 0000664 0000000 0000000 00000002124 12664333731 0014114 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2011-2014 Jonny Strömberg, jonnystromberg.com
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 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.
list.js-1.2.0/README.md 0000664 0000000 0000000 00000011577 12664333731 0014402 0 ustar 00root root 0000000 0000000 # List.js
Perfect library for adding **search**, **sort**, **filters** and **flexibility** to
**tables**, **lists** and various HTML elements. Built to be invisible and work on existing HTML.
Really simple and easy to use!
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M7ZGHV75VSD2E)
### Core idea
- Simple and invisible
- Easy to apply to existing HTML
- No dependencies
- Fast
- Small
- Handle thousands of items
### Features
- Works both lists, tables and almost anything else. E.g. ``,`
`,``, etc.
- Search [Read more ›](http://listjs.com/docs/list-api#search)
- Sort [Read more ›](http://listjs.com/docs/list-api#sort)
- Filter [Read more ›](http://listjs.com/docs/list-api#filter)
- Simple templating system that adds possibility to add, edit, remove items [Read more ›](http://listjs.com/docs/list-api#add)
- Plugins [Read more ›](http://listjs.com/docs/plugins)
- Support for Chrome, Safari, Firefox, IE6+
### Download / Install
##### Via Bower
```
bower install list.js
```
##### Via Component
```
component install javve/list.js
```
##### Via CDNJS
```
```
##### Via Direct Download
- [Compressed list.js](https://raw.githubusercontent.com/javve/list.js/v1.1.1/dist/list.min.js)
- [Uncompressed list.js](https://raw.githubusercontent.com/javve/list.js/v1.1.1/dist/list.js)
### Demo / Examples
- [Existing list](http://listjs.com/examples/existing-list)
- [Existing list + add](http://listjs.com/examples/existing-list-add)
- [New list](http://listjs.com/examples/new-list)
- [Add, get, remove](http://listjs.com/examples/add-get-remove)
- [Fuzzy search](http://listjs.com/examples/fuzzy-search)
- [Pagination](http://listjs.com/examples/pagination)
- [Search in specific column](http://codepen.io/javve/pen/GpZpow)
- [Filter in range](http://codepen.io/javve/pen/wKGKWL)
- [Show message filter/search results in 0 items](http://codepen.io/javve/pen/VvavzG)
- [Only show list after search/filter](http://codepen.io/javve/pen/YyqyRg)
## Documentation
- [Getting started](http://listjs.com/docs)
- [Options](http://listjs.com/docs/options)
- [List API](http://listjs.com/docs/list-api)
- [Item API](http://listjs.com/docs/item-api)
- [Changelog](http://listjs.com/overview/changelog)
### Plugins
- [Introduction](http://listjs.com/docs/plugins)
- [Pagination](http://listjs.com/docs/plugins/pagination)
- [Fuzzy search](http://listjs.com/docs/plugins/fuzzysearch)
- [Build your own](http://listjs.com/docs/plugins/build)
### Known issues
- Sorting fails with some UTF8 characters. Example: `åä`, thinking that `ä` is before `å`.
## Contributors
* [javve](https://github.com/javve) / [Jonny Strömberg](http://jonnystromberg.com)
* [lusentis](https://github.com/lusentis) / [Simone Lusenti](http://www.plasticpanda.com)
* [dancrew32](https://github.com/dancrew32) / [Dan Masquelier](http://danmasq.com)
* [himynameisjonas](https://github.com/himynameisjonas) / [Jonas Forsberg](http://jonasforsberg.se)
* [LuukvE](https://github.com/LuukvE) [Luuk van Egeraat](http://luukvanegeraat.com/)
* [endorama](https://github.com/endorama) / Edoardo Tenani
* [sprynmr](https://github.com/sprynmr) / Bob Spryn
* [francescolaffi](https://github.com/francescolaffi)
* [ryantanner](https://github.com/ryantanner)
* [idlefella](https://github.com/idlefella)
* [julienbechade](https://github.com/julienbechade) / [Julien Béchade/](http://julienbechade.com/)
* [matthewheston](https://github.com/matthewheston)
* [gvido](https://github.com/gvido) / Gvido Glazers
* [karlwestin](https://github.com/karlwestin) / [Karl Westin](http://karlwestin.com)
* [joakin](https://github.com/joakin) / [Joaquin](http://chimeces.com/)
* [dancrew32](https://github.com/dancrew32) / [Dan Masquelier](http://danmasq.com/)
* [jkeyes](https://github.com/jkeyes) / [John Keyes](http://keyes.ie/)
* [samosad](https://github.com/samosad) / Alexey Tabakman
* [Page-](https://github.com/Page-)
* [urkle](https://github.com/urkle) / Edward Rudd
Built with [Component](https://github.com/component/component) which is created by [TJ Holowaychuk](https://github.com/visionmedia).
### Want to contribute?
- Read more at [listjs.com/overview/contribute](http://listjs.com/overview/contribute)
### Creator
| | Jonny Strömberg [@javve](http://twitter.com/javve) |
| ------------- | ------------- |
|  | I hope you like the lib. I’ve put a lot of hours into it! Feel free to follow me on [Twitter](http://twitter.com/javve) for news and [donate a coffee](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M7ZGHV75VSD2E) for good karma ;)
## License (MIT)
Copyright (c) 2012 Jonny Strömberg <[jonny.stromberg@gmail.com](mailto:jonny.stromberg@gmail.com)>
[http://jonnystromberg.com](http://jonnystromberg.com)
list.js-1.2.0/bower.json 0000664 0000000 0000000 00000001103 12664333731 0015114 0 ustar 00root root 0000000 0000000 {
"name": "list.js",
"main": "dist/list.js",
"homepage": "http://listjs.com",
"authors": [
"Jonny Strömberg "
],
"description": "The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML",
"keywords": [
"list",
"search",
"sort",
"table",
"dom",
"html",
"ui"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"components",
"test",
"tests"
]
}
list.js-1.2.0/dist/ 0000775 0000000 0000000 00000000000 12664333731 0014053 5 ustar 00root root 0000000 0000000 list.js-1.2.0/dist/list.js 0000664 0000000 0000000 00000103657 12664333731 0015400 0 ustar 00root root 0000000 0000000 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o self.page) ? true : false;
item = new Item(values[i], undefined, notCreate);
self.items.push(item);
added.push(item);
}
self.update();
return added;
};
this.show = function(i, page) {
this.i = i;
this.page = page;
self.update();
return self;
};
/* Removes object from list.
* Loops through the list and removes objects where
* property "valuename" === value
*/
this.remove = function(valueName, value, options) {
var found = 0;
for (var i = 0, il = self.items.length; i < il; i++) {
if (self.items[i].values()[valueName] == value) {
self.templater.remove(self.items[i], options);
self.items.splice(i,1);
il--;
i--;
found++;
}
}
self.update();
return found;
};
/* Gets the objects in the list which
* property "valueName" === value
*/
this.get = function(valueName, value) {
var matchedItems = [];
for (var i = 0, il = self.items.length; i < il; i++) {
var item = self.items[i];
if (item.values()[valueName] == value) {
matchedItems.push(item);
}
}
return matchedItems;
};
/*
* Get size of the list
*/
this.size = function() {
return self.items.length;
};
/*
* Removes all items from the list
*/
this.clear = function() {
self.templater.clear();
self.items = [];
return self;
};
this.on = function(event, callback) {
self.handlers[event].push(callback);
return self;
};
this.off = function(event, callback) {
var e = self.handlers[event];
var index = indexOf(e, callback);
if (index > -1) {
e.splice(index, 1);
}
return self;
};
this.trigger = function(event) {
var i = self.handlers[event].length;
while(i--) {
self.handlers[event][i](self);
}
return self;
};
this.reset = {
filter: function() {
var is = self.items,
il = is.length;
while (il--) {
is[il].filtered = false;
}
return self;
},
search: function() {
var is = self.items,
il = is.length;
while (il--) {
is[il].found = false;
}
return self;
}
};
this.update = function() {
var is = self.items,
il = is.length;
self.visibleItems = [];
self.matchingItems = [];
self.templater.clear();
for (var i = 0; i < il; i++) {
if (is[i].matching() && ((self.matchingItems.length+1) >= self.i && self.visibleItems.length < self.page)) {
is[i].show();
self.visibleItems.push(is[i]);
self.matchingItems.push(is[i]);
} else if (is[i].matching()) {
self.matchingItems.push(is[i]);
is[i].hide();
} else {
is[i].hide();
}
}
self.trigger('updated');
return self;
};
init.start();
};
// AMD support
if (typeof define === 'function' && define.amd) {
define(function () { return List; });
}
module.exports = List;
window.List = List;
})(window);
},{"./src/add-async":2,"./src/filter":3,"./src/item":4,"./src/parse":5,"./src/search":6,"./src/sort":7,"./src/templater":8,"./src/utils/classes":9,"./src/utils/events":10,"./src/utils/extend":11,"./src/utils/get-attribute":12,"./src/utils/get-by-class":13,"./src/utils/index-of":14,"./src/utils/natural-sort":15,"./src/utils/to-array":16,"./src/utils/to-string":17}],2:[function(require,module,exports){
module.exports = function(list) {
var addAsync = function(values, callback, items) {
var valuesToAdd = values.splice(0, 50);
items = items || [];
items = items.concat(list.add(valuesToAdd));
if (values.length > 0) {
setTimeout(function() {
addAsync(values, callback, items);
}, 1);
} else {
list.update();
callback(items);
}
};
return addAsync;
};
},{}],3:[function(require,module,exports){
module.exports = function(list) {
// Add handlers
list.handlers.filterStart = list.handlers.filterStart || [];
list.handlers.filterComplete = list.handlers.filterComplete || [];
return function(filterFunction) {
list.trigger('filterStart');
list.i = 1; // Reset paging
list.reset.filter();
if (filterFunction === undefined) {
list.filtered = false;
} else {
list.filtered = true;
var is = list.items;
for (var i = 0, il = is.length; i < il; i++) {
var item = is[i];
if (filterFunction(item)) {
item.filtered = true;
} else {
item.filtered = false;
}
}
}
list.update();
list.trigger('filterComplete');
return list.visibleItems;
};
};
},{}],4:[function(require,module,exports){
module.exports = function(list) {
return function(initValues, element, notCreate) {
var item = this;
this._values = {};
this.found = false; // Show if list.searched == true and this.found == true
this.filtered = false;// Show if list.filtered == true and this.filtered == true
var init = function(initValues, element, notCreate) {
if (element === undefined) {
if (notCreate) {
item.values(initValues, notCreate);
} else {
item.values(initValues);
}
} else {
item.elm = element;
var values = list.templater.get(item, initValues);
item.values(values);
}
};
this.values = function(newValues, notCreate) {
if (newValues !== undefined) {
for(var name in newValues) {
item._values[name] = newValues[name];
}
if (notCreate !== true) {
list.templater.set(item, item.values());
}
} else {
return item._values;
}
};
this.show = function() {
list.templater.show(item);
};
this.hide = function() {
list.templater.hide(item);
};
this.matching = function() {
return (
(list.filtered && list.searched && item.found && item.filtered) ||
(list.filtered && !list.searched && item.filtered) ||
(!list.filtered && list.searched && item.found) ||
(!list.filtered && !list.searched)
);
};
this.visible = function() {
return (item.elm && (item.elm.parentNode == list.list)) ? true : false;
};
init(initValues, element, notCreate);
};
};
},{}],5:[function(require,module,exports){
module.exports = function(list) {
var Item = require('./item')(list);
var getChildren = function(parent) {
var nodes = parent.childNodes,
items = [];
for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
items.push(nodes[i]);
}
}
return items;
};
var parse = function(itemElements, valueNames) {
for (var i = 0, il = itemElements.length; i < il; i++) {
list.items.push(new Item(valueNames, itemElements[i]));
}
};
var parseAsync = function(itemElements, valueNames) {
var itemsToIndex = itemElements.splice(0, 50); // TODO: If < 100 items, what happens in IE etc?
parse(itemsToIndex, valueNames);
if (itemElements.length > 0) {
setTimeout(function() {
parseAsync(itemElements, valueNames);
}, 1);
} else {
list.update();
list.trigger('parseComplete');
}
};
list.handlers.parseComplete = list.handlers.parseComplete || [];
return function() {
var itemsToIndex = getChildren(list.list),
valueNames = list.valueNames;
if (list.indexAsync) {
parseAsync(itemsToIndex, valueNames);
} else {
parse(itemsToIndex, valueNames);
}
};
};
},{"./item":4}],6:[function(require,module,exports){
module.exports = function(list) {
var item,
text,
columns,
searchString,
customSearch;
var prepare = {
resetList: function() {
list.i = 1;
list.templater.clear();
customSearch = undefined;
},
setOptions: function(args) {
if (args.length == 2 && args[1] instanceof Array) {
columns = args[1];
} else if (args.length == 2 && typeof(args[1]) == "function") {
customSearch = args[1];
} else if (args.length == 3) {
columns = args[1];
customSearch = args[2];
}
},
setColumns: function() {
if (list.items.length === 0) return;
if (columns === undefined) {
columns = (list.searchColumns === undefined) ? prepare.toArray(list.items[0].values()) : list.searchColumns;
}
},
setSearchString: function(s) {
s = list.utils.toString(s).toLowerCase();
s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"); // Escape regular expression characters
searchString = s;
},
toArray: function(values) {
var tmpColumn = [];
for (var name in values) {
tmpColumn.push(name);
}
return tmpColumn;
}
};
var search = {
list: function() {
for (var k = 0, kl = list.items.length; k < kl; k++) {
search.item(list.items[k]);
}
},
item: function(item) {
item.found = false;
for (var j = 0, jl = columns.length; j < jl; j++) {
if (search.values(item.values(), columns[j])) {
item.found = true;
return;
}
}
},
values: function(values, column) {
if (values.hasOwnProperty(column)) {
text = list.utils.toString(values[column]).toLowerCase();
if ((searchString !== "") && (text.search(searchString) > -1)) {
return true;
}
}
return false;
},
reset: function() {
list.reset.search();
list.searched = false;
}
};
var searchMethod = function(str) {
list.trigger('searchStart');
prepare.resetList();
prepare.setSearchString(str);
prepare.setOptions(arguments); // str, cols|searchFunction, searchFunction
prepare.setColumns();
if (searchString === "" ) {
search.reset();
} else {
list.searched = true;
if (customSearch) {
customSearch(searchString, columns);
} else {
search.list();
}
}
list.update();
list.trigger('searchComplete');
return list.visibleItems;
};
list.handlers.searchStart = list.handlers.searchStart || [];
list.handlers.searchComplete = list.handlers.searchComplete || [];
list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'keyup', function(e) {
var target = e.target || e.srcElement, // IE have srcElement
alreadyCleared = (target.value === "" && !list.searched);
if (!alreadyCleared) { // If oninput already have resetted the list, do nothing
searchMethod(target.value);
}
});
// Used to detect click on HTML5 clear button
list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'input', function(e) {
var target = e.target || e.srcElement;
if (target.value === "") {
searchMethod('');
}
});
return searchMethod;
};
},{}],7:[function(require,module,exports){
module.exports = function(list) {
list.sortFunction = list.sortFunction || function(itemA, itemB, options) {
options.desc = options.order == "desc" ? true : false; // Natural sort uses this format
return list.utils.naturalSort(itemA.values()[options.valueName], itemB.values()[options.valueName], options);
};
var buttons = {
els: undefined,
clear: function() {
for (var i = 0, il = buttons.els.length; i < il; i++) {
list.utils.classes(buttons.els[i]).remove('asc');
list.utils.classes(buttons.els[i]).remove('desc');
}
},
getOrder: function(btn) {
var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
if (predefinedOrder == "asc" || predefinedOrder == "desc") {
return predefinedOrder;
} else if (list.utils.classes(btn).has('desc')) {
return "asc";
} else if (list.utils.classes(btn).has('asc')) {
return "desc";
} else {
return "asc";
}
},
getInSensitive: function(btn, options) {
var insensitive = list.utils.getAttribute(btn, 'data-insensitive');
if (insensitive === "false") {
options.insensitive = false;
} else {
options.insensitive = true;
}
},
setOrder: function(options) {
for (var i = 0, il = buttons.els.length; i < il; i++) {
var btn = buttons.els[i];
if (list.utils.getAttribute(btn, 'data-sort') !== options.valueName) {
continue;
}
var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
if (predefinedOrder == "asc" || predefinedOrder == "desc") {
if (predefinedOrder == options.order) {
list.utils.classes(btn).add(options.order);
}
} else {
list.utils.classes(btn).add(options.order);
}
}
}
};
var sort = function() {
list.trigger('sortStart');
var options = {};
var target = arguments[0].currentTarget || arguments[0].srcElement || undefined;
if (target) {
options.valueName = list.utils.getAttribute(target, 'data-sort');
buttons.getInSensitive(target, options);
options.order = buttons.getOrder(target);
} else {
options = arguments[1] || options;
options.valueName = arguments[0];
options.order = options.order || "asc";
options.insensitive = (typeof options.insensitive == "undefined") ? true : options.insensitive;
}
buttons.clear();
buttons.setOrder(options);
options.sortFunction = options.sortFunction || list.sortFunction;
list.items.sort(function(a, b) {
var mult = (options.order === 'desc') ? -1 : 1;
return (options.sortFunction(a, b, options) * mult);
});
list.update();
list.trigger('sortComplete');
};
// Add handlers
list.handlers.sortStart = list.handlers.sortStart || [];
list.handlers.sortComplete = list.handlers.sortComplete || [];
buttons.els = list.utils.getByClass(list.listContainer, list.sortClass);
list.utils.events.bind(buttons.els, 'click', sort);
list.on('searchStart', buttons.clear);
list.on('filterStart', buttons.clear);
return sort;
};
},{}],8:[function(require,module,exports){
var Templater = function(list) {
var itemSource,
templater = this;
var init = function() {
itemSource = templater.getItemSource(list.item);
itemSource = templater.clearSourceItem(itemSource, list.valueNames);
};
this.clearSourceItem = function(el, valueNames) {
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
el.setAttribute('data-'+valueNames[i].data[j], '');
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(el, valueNames[i].name, true);
if (elm) {
elm.setAttribute(valueNames[i].attr, "");
}
} else {
elm = list.utils.getByClass(el, valueNames[i], true);
if (elm) {
elm.innerHTML = "";
}
}
elm = undefined;
}
return el;
};
this.getItemSource = function(item) {
if (item === undefined) {
var nodes = list.list.childNodes,
items = [];
for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
return nodes[i].cloneNode(true);
}
}
} else if (/^tr[\s>]/.exec(item)) {
var table = document.createElement('table');
table.innerHTML = item;
return table.firstChild;
} else if (item.indexOf("<") !== -1) {
var div = document.createElement('div');
div.innerHTML = item;
return div.firstChild;
} else {
var source = document.getElementById(list.item);
if (source) {
return source;
}
}
throw new Error("The list need to have at list one item on init otherwise you'll have to add a template.");
};
this.get = function(item, valueNames) {
templater.create(item);
var values = {};
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
values[valueNames[i].data[j]] = list.utils.getAttribute(item.elm, 'data-'+valueNames[i].data[j]);
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(item.elm, valueNames[i].name, true);
values[valueNames[i].name] = elm ? list.utils.getAttribute(elm, valueNames[i].attr) : "";
} else {
elm = list.utils.getByClass(item.elm, valueNames[i], true);
values[valueNames[i]] = elm ? elm.innerHTML : "";
}
elm = undefined;
}
return values;
};
this.set = function(item, values) {
var getValueName = function(name) {
for (var i = 0, il = list.valueNames.length; i < il; i++) {
if (list.valueNames[i].data) {
var data = list.valueNames[i].data;
for (var j = 0, jl = data.length; j < jl; j++) {
if (data[j] === name) {
return { data: name };
}
}
} else if (list.valueNames[i].attr && list.valueNames[i].name && list.valueNames[i].name == name) {
return list.valueNames[i];
} else if (list.valueNames[i] === name) {
return name;
}
}
};
var setValue = function(name, value) {
var elm;
var valueName = getValueName(name);
if (!valueName)
return;
if (valueName.data) {
item.elm.setAttribute('data-'+valueName.data, value);
} else if (valueName.attr && valueName.name) {
elm = list.utils.getByClass(item.elm, valueName.name, true);
if (elm) {
elm.setAttribute(valueName.attr, value);
}
} else {
elm = list.utils.getByClass(item.elm, valueName, true);
if (elm) {
elm.innerHTML = value;
}
}
elm = undefined;
};
if (!templater.create(item)) {
for(var v in values) {
if (values.hasOwnProperty(v)) {
setValue(v, values[v]);
}
}
}
};
this.create = function(item) {
if (item.elm !== undefined) {
return false;
}
/* If item source does not exists, use the first item in list as
source for new items */
var newItem = itemSource.cloneNode(true);
newItem.removeAttribute('id');
item.elm = newItem;
templater.set(item, item.values());
return true;
};
this.remove = function(item) {
if (item.elm.parentNode === list.list) {
list.list.removeChild(item.elm);
}
};
this.show = function(item) {
templater.create(item);
list.list.appendChild(item.elm);
};
this.hide = function(item) {
if (item.elm !== undefined && item.elm.parentNode === list.list) {
list.list.removeChild(item.elm);
}
};
this.clear = function() {
/* .innerHTML = ''; fucks up IE */
if (list.list.hasChildNodes()) {
while (list.list.childNodes.length >= 1)
{
list.list.removeChild(list.list.firstChild);
}
}
};
init();
};
module.exports = function(list) {
return new Templater(list);
};
},{}],9:[function(require,module,exports){
/**
* Module dependencies.
*/
var index = require('./index-of');
/**
* Whitespace regexp.
*/
var re = /\s+/;
/**
* toString reference.
*/
var toString = Object.prototype.toString;
/**
* Wrap `el` in a `ClassList`.
*
* @param {Element} el
* @return {ClassList}
* @api public
*/
module.exports = function(el){
return new ClassList(el);
};
/**
* Initialize a new ClassList for `el`.
*
* @param {Element} el
* @api private
*/
function ClassList(el) {
if (!el || !el.nodeType) {
throw new Error('A DOM element reference is required');
}
this.el = el;
this.list = el.classList;
}
/**
* Add class `name` if not already present.
*
* @param {String} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.add = function(name){
// classList
if (this.list) {
this.list.add(name);
return this;
}
// fallback
var arr = this.array();
var i = index(arr, name);
if (!~i) arr.push(name);
this.el.className = arr.join(' ');
return this;
};
/**
* Remove class `name` when present, or
* pass a regular expression to remove
* any which match.
*
* @param {String|RegExp} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.remove = function(name){
if ('[object RegExp]' == toString.call(name)) {
return this.removeMatching(name);
}
// classList
if (this.list) {
this.list.remove(name);
return this;
}
// fallback
var arr = this.array();
var i = index(arr, name);
if (~i) arr.splice(i, 1);
this.el.className = arr.join(' ');
return this;
};
/**
* Remove all classes matching `re`.
*
* @param {RegExp} re
* @return {ClassList}
* @api private
*/
ClassList.prototype.removeMatching = function(re){
var arr = this.array();
for (var i = 0; i < arr.length; i++) {
if (re.test(arr[i])) {
this.remove(arr[i]);
}
}
return this;
};
/**
* Toggle class `name`, can force state via `force`.
*
* For browsers that support classList, but do not support `force` yet,
* the mistake will be detected and corrected.
*
* @param {String} name
* @param {Boolean} force
* @return {ClassList}
* @api public
*/
ClassList.prototype.toggle = function(name, force){
// classList
if (this.list) {
if ("undefined" !== typeof force) {
if (force !== this.list.toggle(name, force)) {
this.list.toggle(name); // toggle again to correct
}
} else {
this.list.toggle(name);
}
return this;
}
// fallback
if ("undefined" !== typeof force) {
if (!force) {
this.remove(name);
} else {
this.add(name);
}
} else {
if (this.has(name)) {
this.remove(name);
} else {
this.add(name);
}
}
return this;
};
/**
* Return an array of classes.
*
* @return {Array}
* @api public
*/
ClassList.prototype.array = function(){
var className = this.el.getAttribute('class') || '';
var str = className.replace(/^\s+|\s+$/g, '');
var arr = str.split(re);
if ('' === arr[0]) arr.shift();
return arr;
};
/**
* Check if class `name` is present.
*
* @param {String} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.has =
ClassList.prototype.contains = function(name){
return this.list ? this.list.contains(name) : !! ~index(this.array(), name);
};
},{"./index-of":14}],10:[function(require,module,exports){
var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
prefix = bind !== 'addEventListener' ? 'on' : '',
toArray = require('./to-array');
/**
* Bind `el` event `type` to `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.bind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
el[i][bind](prefix + type, fn, capture || false);
}
};
/**
* Unbind `el` event `type`'s callback `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.unbind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
el[i][unbind](prefix + type, fn, capture || false);
}
};
},{"./to-array":16}],11:[function(require,module,exports){
/*
* Source: https://github.com/segmentio/extend
*/
module.exports = function extend (object) {
// Takes an unlimited number of extenders.
var args = Array.prototype.slice.call(arguments, 1);
// For each extender, copy their properties on our object.
for (var i = 0, source; source = args[i]; i++) {
if (!source) continue;
for (var property in source) {
object[property] = source[property];
}
}
return object;
};
},{}],12:[function(require,module,exports){
/**
* A cross-browser implementation of getAttribute.
* Source found here: http://stackoverflow.com/a/3755343/361337 written by Vivin Paliath
*
* Return the value for `attr` at `element`.
*
* @param {Element} el
* @param {String} attr
* @api public
*/
module.exports = function(el, attr) {
var result = (el.getAttribute && el.getAttribute(attr)) || null;
if( !result ) {
var attrs = el.attributes;
var length = attrs.length;
for(var i = 0; i < length; i++) {
if (attr[i] !== undefined) {
if(attr[i].nodeName === attr) {
result = attr[i].nodeValue;
}
}
}
}
return result;
};
},{}],13:[function(require,module,exports){
/**
* A cross-browser implementation of getElementsByClass.
* Heavily based on Dustin Diaz's function: http://dustindiaz.com/getelementsbyclass.
*
* Find all elements with class `className` inside `container`.
* Use `single = true` to increase performance in older browsers
* when only one element is needed.
*
* @param {String} className
* @param {Element} container
* @param {Boolean} single
* @api public
*/
module.exports = (function() {
if (document.getElementsByClassName) {
return function(container, className, single) {
if (single) {
return container.getElementsByClassName(className)[0];
} else {
return container.getElementsByClassName(className);
}
};
} else if (document.querySelector) {
return function(container, className, single) {
className = '.' + className;
if (single) {
return container.querySelector(className);
} else {
return container.querySelectorAll(className);
}
};
} else {
return function(container, className, single) {
var classElements = [],
tag = '*';
if (container === null) {
container = document;
}
var els = container.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+className+"(\\s|$)");
for (var i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
if (single) {
return els[i];
} else {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
};
}
})();
},{}],14:[function(require,module,exports){
var indexOf = [].indexOf;
module.exports = function(arr, obj){
if (indexOf) return arr.indexOf(obj);
for (var i = 0; i < arr.length; ++i) {
if (arr[i] === obj) return i;
}
return -1;
};
},{}],15:[function(require,module,exports){
/*
* Natural Sort algorithm for Javascript - Version 0.8 - Released under MIT license
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
*/
module.exports = function(a, b, opts) {
var re = /(^([+\-]?(?:\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[\da-fA-F]+$|\d+)/g,
sre = /^\s+|\s+$/g, // trim pre-post whitespace
snre = /\s+/g, // normalize all whitespace to single ' ' character
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre = /^0x[0-9a-f]+$/i,
ore = /^0/,
options = opts || {},
i = function(s) { return options.insensitive && (''+s).toLowerCase() || ''+s; },
// convert all to strings strip whitespace
x = i(a) || '',
y = i(b) || '',
// chunk/tokenize
xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
// numeric, hex or date detection
xD = parseInt(x.match(hre), 16) || (xN.length !== 1 && Date.parse(x)),
yD = parseInt(y.match(hre), 16) || xD && y.match(dre) && Date.parse(y) || null,
normChunk = function(s, l) {
// normalize spaces; find floats not starting with '0', string or 0 if not defined (Clint Priest)
return (!s.match(ore) || l == 1) && parseFloat(s) || s.replace(snre, ' ').replace(sre, '') || 0;
},
oFxNcL, oFyNcL;
// first try and sort Hex codes or Dates
if (yD) {
if ( xD < yD ) { return -1; }
else if ( xD > yD ) { return 1; }
}
// natural sorting through split numeric strings and default strings
for(var cLoc=0, xNl = xN.length, yNl = yN.length, numS=Math.max(xNl, yNl); cLoc < numS; cLoc++) {
oFxNcL = normChunk(xN[cLoc], xNl);
oFyNcL = normChunk(yN[cLoc], yNl);
// handle numeric vs string comparison - number < string - (Kyle Adams)
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; }
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
else if (typeof oFxNcL !== typeof oFyNcL) {
oFxNcL += '';
oFyNcL += '';
}
if (oFxNcL < oFyNcL) { return -1; }
if (oFxNcL > oFyNcL) { return 1; }
}
return 0;
};
},{}],16:[function(require,module,exports){
/**
* Source: https://github.com/timoxley/to-array
*
* Convert an array-like object into an `Array`.
* If `collection` is already an `Array`, then will return a clone of `collection`.
*
* @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
* @return {Array} Naive conversion of `collection` to a new `Array`.
* @api public
*/
module.exports = function toArray(collection) {
if (typeof collection === 'undefined') return [];
if (collection === null) return [null];
if (collection === window) return [window];
if (typeof collection === 'string') return [collection];
if (isArray(collection)) return collection;
if (typeof collection.length != 'number') return [collection];
if (typeof collection === 'function' && collection instanceof Function) return [collection];
var arr = [];
for (var i = 0; i < collection.length; i++) {
if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) {
arr.push(collection[i]);
}
}
if (!arr.length) return [];
return arr;
};
function isArray(arr) {
return Object.prototype.toString.call(arr) === "[object Array]";
}
},{}],17:[function(require,module,exports){
module.exports = function(s) {
s = (s === undefined) ? "" : s;
s = (s === null) ? "" : s;
s = s.toString();
return s;
};
},{}]},{},[1]);
list.js-1.2.0/index.js 0000664 0000000 0000000 00000014655 12664333731 0014570 0 ustar 00root root 0000000 0000000 /*
List.js 1.1.1
By Jonny Strömberg (www.jonnystromberg.com, www.listjs.com)
*/
(function( window, undefined ) {
"use strict";
var document = window.document,
getByClass = require('./src/utils/get-by-class'),
extend = require('./src/utils/extend'),
indexOf = require('./src/utils/index-of'),
events = require('./src/utils/events'),
toString = require('./src/utils/to-string'),
naturalSort = require('./src/utils/natural-sort'),
classes = require('./src/utils/classes'),
getAttribute = require('./src/utils/get-attribute'),
toArray = require('./src/utils/to-array');
var List = function(id, options, values) {
var self = this,
init,
Item = require('./src/item')(self),
addAsync = require('./src/add-async')(self);
init = {
start: function() {
self.listClass = "list";
self.searchClass = "search";
self.sortClass = "sort";
self.page = 10000;
self.i = 1;
self.items = [];
self.visibleItems = [];
self.matchingItems = [];
self.searched = false;
self.filtered = false;
self.searchColumns = undefined;
self.handlers = { 'updated': [] };
self.plugins = {};
self.valueNames = [];
self.utils = {
getByClass: getByClass,
extend: extend,
indexOf: indexOf,
events: events,
toString: toString,
naturalSort: naturalSort,
classes: classes,
getAttribute: getAttribute,
toArray: toArray
};
self.utils.extend(self, options);
self.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id;
if (!self.listContainer) { return; }
self.list = getByClass(self.listContainer, self.listClass, true);
self.parse = require('./src/parse')(self);
self.templater = require('./src/templater')(self);
self.search = require('./src/search')(self);
self.filter = require('./src/filter')(self);
self.sort = require('./src/sort')(self);
this.handlers();
this.items();
self.update();
this.plugins();
},
handlers: function() {
for (var handler in self.handlers) {
if (self[handler]) {
self.on(handler, self[handler]);
}
}
},
items: function() {
self.parse(self.list);
if (values !== undefined) {
self.add(values);
}
},
plugins: function() {
for (var i = 0; i < self.plugins.length; i++) {
var plugin = self.plugins[i];
self[plugin.name] = plugin;
plugin.init(self, List);
}
}
};
/*
* Re-parse the List, use if html have changed
*/
this.reIndex = function() {
self.items = [];
self.visibleItems = [];
self.matchingItems = [];
self.searched = false;
self.filtered = false;
self.parse(self.list);
};
this.toJSON = function() {
var json = [];
for (var i = 0, il = self.items.length; i < il; i++) {
json.push(self.items[i].values());
}
return json;
};
/*
* Add object to list
*/
this.add = function(values, callback) {
if (values.length === 0) {
return;
}
if (callback) {
addAsync(values, callback);
return;
}
var added = [],
notCreate = false;
if (values[0] === undefined){
values = [values];
}
for (var i = 0, il = values.length; i < il; i++) {
var item = null;
notCreate = (self.items.length > self.page) ? true : false;
item = new Item(values[i], undefined, notCreate);
self.items.push(item);
added.push(item);
}
self.update();
return added;
};
this.show = function(i, page) {
this.i = i;
this.page = page;
self.update();
return self;
};
/* Removes object from list.
* Loops through the list and removes objects where
* property "valuename" === value
*/
this.remove = function(valueName, value, options) {
var found = 0;
for (var i = 0, il = self.items.length; i < il; i++) {
if (self.items[i].values()[valueName] == value) {
self.templater.remove(self.items[i], options);
self.items.splice(i,1);
il--;
i--;
found++;
}
}
self.update();
return found;
};
/* Gets the objects in the list which
* property "valueName" === value
*/
this.get = function(valueName, value) {
var matchedItems = [];
for (var i = 0, il = self.items.length; i < il; i++) {
var item = self.items[i];
if (item.values()[valueName] == value) {
matchedItems.push(item);
}
}
return matchedItems;
};
/*
* Get size of the list
*/
this.size = function() {
return self.items.length;
};
/*
* Removes all items from the list
*/
this.clear = function() {
self.templater.clear();
self.items = [];
return self;
};
this.on = function(event, callback) {
self.handlers[event].push(callback);
return self;
};
this.off = function(event, callback) {
var e = self.handlers[event];
var index = indexOf(e, callback);
if (index > -1) {
e.splice(index, 1);
}
return self;
};
this.trigger = function(event) {
var i = self.handlers[event].length;
while(i--) {
self.handlers[event][i](self);
}
return self;
};
this.reset = {
filter: function() {
var is = self.items,
il = is.length;
while (il--) {
is[il].filtered = false;
}
return self;
},
search: function() {
var is = self.items,
il = is.length;
while (il--) {
is[il].found = false;
}
return self;
}
};
this.update = function() {
var is = self.items,
il = is.length;
self.visibleItems = [];
self.matchingItems = [];
self.templater.clear();
for (var i = 0; i < il; i++) {
if (is[i].matching() && ((self.matchingItems.length+1) >= self.i && self.visibleItems.length < self.page)) {
is[i].show();
self.visibleItems.push(is[i]);
self.matchingItems.push(is[i]);
} else if (is[i].matching()) {
self.matchingItems.push(is[i]);
is[i].hide();
} else {
is[i].hide();
}
}
self.trigger('updated');
return self;
};
init.start();
};
// AMD support
if (typeof define === 'function' && define.amd) {
define(function () { return List; });
}
module.exports = List;
window.List = List;
})(window);
list.js-1.2.0/package.json 0000664 0000000 0000000 00000001737 12664333731 0015406 0 ustar 00root root 0000000 0000000 {
"name": "list.js",
"version": "1.2.0",
"description": "The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML",
"keywords": [
"list",
"search",
"sort",
"table",
"dom",
"html",
"ui"
],
"author": "Jonny Strömberg ",
"repository": "git://github.com/javve/list.js.git",
"dependencies": {},
"devDependencies": {
"browserify": "^13.0.0",
"expect.js": "^0.3.1",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.12.0",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-mocha": "^0.4.15",
"grunt-shell": "^1.1.2",
"jquery": "^1.12.0"
},
"main": "index",
"engines": {
"node": ">= 0.10.21"
},
"npmName": "list.js",
"npmFileMap": [
{
"basePath": "/dist/",
"files": [
"*.js"
]
}
]
}
list.js-1.2.0/src/ 0000775 0000000 0000000 00000000000 12664333731 0013677 5 ustar 00root root 0000000 0000000 list.js-1.2.0/src/add-async.js 0000664 0000000 0000000 00000000632 12664333731 0016101 0 ustar 00root root 0000000 0000000 module.exports = function(list) {
var addAsync = function(values, callback, items) {
var valuesToAdd = values.splice(0, 50);
items = items || [];
items = items.concat(list.add(valuesToAdd));
if (values.length > 0) {
setTimeout(function() {
addAsync(values, callback, items);
}, 1);
} else {
list.update();
callback(items);
}
};
return addAsync;
};
list.js-1.2.0/src/filter.js 0000664 0000000 0000000 00000001373 12664333731 0015526 0 ustar 00root root 0000000 0000000 module.exports = function(list) {
// Add handlers
list.handlers.filterStart = list.handlers.filterStart || [];
list.handlers.filterComplete = list.handlers.filterComplete || [];
return function(filterFunction) {
list.trigger('filterStart');
list.i = 1; // Reset paging
list.reset.filter();
if (filterFunction === undefined) {
list.filtered = false;
} else {
list.filtered = true;
var is = list.items;
for (var i = 0, il = is.length; i < il; i++) {
var item = is[i];
if (filterFunction(item)) {
item.filtered = true;
} else {
item.filtered = false;
}
}
}
list.update();
list.trigger('filterComplete');
return list.visibleItems;
};
};
list.js-1.2.0/src/item.js 0000664 0000000 0000000 00000003125 12664333731 0015174 0 ustar 00root root 0000000 0000000 module.exports = function(list) {
return function(initValues, element, notCreate) {
var item = this;
this._values = {};
this.found = false; // Show if list.searched == true and this.found == true
this.filtered = false;// Show if list.filtered == true and this.filtered == true
var init = function(initValues, element, notCreate) {
if (element === undefined) {
if (notCreate) {
item.values(initValues, notCreate);
} else {
item.values(initValues);
}
} else {
item.elm = element;
var values = list.templater.get(item, initValues);
item.values(values);
}
};
this.values = function(newValues, notCreate) {
if (newValues !== undefined) {
for(var name in newValues) {
item._values[name] = newValues[name];
}
if (notCreate !== true) {
list.templater.set(item, item.values());
}
} else {
return item._values;
}
};
this.show = function() {
list.templater.show(item);
};
this.hide = function() {
list.templater.hide(item);
};
this.matching = function() {
return (
(list.filtered && list.searched && item.found && item.filtered) ||
(list.filtered && !list.searched && item.filtered) ||
(!list.filtered && list.searched && item.found) ||
(!list.filtered && !list.searched)
);
};
this.visible = function() {
return (item.elm && (item.elm.parentNode == list.list)) ? true : false;
};
init(initValues, element, notCreate);
};
};
list.js-1.2.0/src/parse.js 0000664 0000000 0000000 00000002367 12664333731 0015357 0 ustar 00root root 0000000 0000000 module.exports = function(list) {
var Item = require('./item')(list);
var getChildren = function(parent) {
var nodes = parent.childNodes,
items = [];
for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
items.push(nodes[i]);
}
}
return items;
};
var parse = function(itemElements, valueNames) {
for (var i = 0, il = itemElements.length; i < il; i++) {
list.items.push(new Item(valueNames, itemElements[i]));
}
};
var parseAsync = function(itemElements, valueNames) {
var itemsToIndex = itemElements.splice(0, 50); // TODO: If < 100 items, what happens in IE etc?
parse(itemsToIndex, valueNames);
if (itemElements.length > 0) {
setTimeout(function() {
parseAsync(itemElements, valueNames);
}, 1);
} else {
list.update();
list.trigger('parseComplete');
}
};
list.handlers.parseComplete = list.handlers.parseComplete || [];
return function() {
var itemsToIndex = getChildren(list.list),
valueNames = list.valueNames;
if (list.indexAsync) {
parseAsync(itemsToIndex, valueNames);
} else {
parse(itemsToIndex, valueNames);
}
};
};
list.js-1.2.0/src/search.js 0000664 0000000 0000000 00000006340 12664333731 0015505 0 ustar 00root root 0000000 0000000 module.exports = function(list) {
var item,
text,
columns,
searchString,
customSearch;
var prepare = {
resetList: function() {
list.i = 1;
list.templater.clear();
customSearch = undefined;
},
setOptions: function(args) {
if (args.length == 2 && args[1] instanceof Array) {
columns = args[1];
} else if (args.length == 2 && typeof(args[1]) == "function") {
customSearch = args[1];
} else if (args.length == 3) {
columns = args[1];
customSearch = args[2];
}
},
setColumns: function() {
if (list.items.length === 0) return;
if (columns === undefined) {
columns = (list.searchColumns === undefined) ? prepare.toArray(list.items[0].values()) : list.searchColumns;
}
},
setSearchString: function(s) {
s = list.utils.toString(s).toLowerCase();
s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"); // Escape regular expression characters
searchString = s;
},
toArray: function(values) {
var tmpColumn = [];
for (var name in values) {
tmpColumn.push(name);
}
return tmpColumn;
}
};
var search = {
list: function() {
for (var k = 0, kl = list.items.length; k < kl; k++) {
search.item(list.items[k]);
}
},
item: function(item) {
item.found = false;
for (var j = 0, jl = columns.length; j < jl; j++) {
if (search.values(item.values(), columns[j])) {
item.found = true;
return;
}
}
},
values: function(values, column) {
if (values.hasOwnProperty(column)) {
text = list.utils.toString(values[column]).toLowerCase();
if ((searchString !== "") && (text.search(searchString) > -1)) {
return true;
}
}
return false;
},
reset: function() {
list.reset.search();
list.searched = false;
}
};
var searchMethod = function(str) {
list.trigger('searchStart');
prepare.resetList();
prepare.setSearchString(str);
prepare.setOptions(arguments); // str, cols|searchFunction, searchFunction
prepare.setColumns();
if (searchString === "" ) {
search.reset();
} else {
list.searched = true;
if (customSearch) {
customSearch(searchString, columns);
} else {
search.list();
}
}
list.update();
list.trigger('searchComplete');
return list.visibleItems;
};
list.handlers.searchStart = list.handlers.searchStart || [];
list.handlers.searchComplete = list.handlers.searchComplete || [];
list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'keyup', function(e) {
var target = e.target || e.srcElement, // IE have srcElement
alreadyCleared = (target.value === "" && !list.searched);
if (!alreadyCleared) { // If oninput already have resetted the list, do nothing
searchMethod(target.value);
}
});
// Used to detect click on HTML5 clear button
list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'input', function(e) {
var target = e.target || e.srcElement;
if (target.value === "") {
searchMethod('');
}
});
return searchMethod;
};
list.js-1.2.0/src/sort.js 0000664 0000000 0000000 00000006127 12664333731 0015232 0 ustar 00root root 0000000 0000000 module.exports = function(list) {
list.sortFunction = list.sortFunction || function(itemA, itemB, options) {
options.desc = options.order == "desc" ? true : false; // Natural sort uses this format
return list.utils.naturalSort(itemA.values()[options.valueName], itemB.values()[options.valueName], options);
};
var buttons = {
els: undefined,
clear: function() {
for (var i = 0, il = buttons.els.length; i < il; i++) {
list.utils.classes(buttons.els[i]).remove('asc');
list.utils.classes(buttons.els[i]).remove('desc');
}
},
getOrder: function(btn) {
var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
if (predefinedOrder == "asc" || predefinedOrder == "desc") {
return predefinedOrder;
} else if (list.utils.classes(btn).has('desc')) {
return "asc";
} else if (list.utils.classes(btn).has('asc')) {
return "desc";
} else {
return "asc";
}
},
getInSensitive: function(btn, options) {
var insensitive = list.utils.getAttribute(btn, 'data-insensitive');
if (insensitive === "false") {
options.insensitive = false;
} else {
options.insensitive = true;
}
},
setOrder: function(options) {
for (var i = 0, il = buttons.els.length; i < il; i++) {
var btn = buttons.els[i];
if (list.utils.getAttribute(btn, 'data-sort') !== options.valueName) {
continue;
}
var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
if (predefinedOrder == "asc" || predefinedOrder == "desc") {
if (predefinedOrder == options.order) {
list.utils.classes(btn).add(options.order);
}
} else {
list.utils.classes(btn).add(options.order);
}
}
}
};
var sort = function() {
list.trigger('sortStart');
var options = {};
var target = arguments[0].currentTarget || arguments[0].srcElement || undefined;
if (target) {
options.valueName = list.utils.getAttribute(target, 'data-sort');
buttons.getInSensitive(target, options);
options.order = buttons.getOrder(target);
} else {
options = arguments[1] || options;
options.valueName = arguments[0];
options.order = options.order || "asc";
options.insensitive = (typeof options.insensitive == "undefined") ? true : options.insensitive;
}
buttons.clear();
buttons.setOrder(options);
options.sortFunction = options.sortFunction || list.sortFunction;
list.items.sort(function(a, b) {
var mult = (options.order === 'desc') ? -1 : 1;
return (options.sortFunction(a, b, options) * mult);
});
list.update();
list.trigger('sortComplete');
};
// Add handlers
list.handlers.sortStart = list.handlers.sortStart || [];
list.handlers.sortComplete = list.handlers.sortComplete || [];
buttons.els = list.utils.getByClass(list.listContainer, list.sortClass);
list.utils.events.bind(buttons.els, 'click', sort);
list.on('searchStart', buttons.clear);
list.on('filterStart', buttons.clear);
return sort;
};
list.js-1.2.0/src/templater.js 0000664 0000000 0000000 00000011746 12664333731 0016243 0 ustar 00root root 0000000 0000000 var Templater = function(list) {
var itemSource,
templater = this;
var init = function() {
itemSource = templater.getItemSource(list.item);
itemSource = templater.clearSourceItem(itemSource, list.valueNames);
};
this.clearSourceItem = function(el, valueNames) {
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
el.setAttribute('data-'+valueNames[i].data[j], '');
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(el, valueNames[i].name, true);
if (elm) {
elm.setAttribute(valueNames[i].attr, "");
}
} else {
elm = list.utils.getByClass(el, valueNames[i], true);
if (elm) {
elm.innerHTML = "";
}
}
elm = undefined;
}
return el;
};
this.getItemSource = function(item) {
if (item === undefined) {
var nodes = list.list.childNodes,
items = [];
for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
return nodes[i].cloneNode(true);
}
}
} else if (/^tr[\s>]/.exec(item)) {
var table = document.createElement('table');
table.innerHTML = item;
return table.firstChild;
} else if (item.indexOf("<") !== -1) {
var div = document.createElement('div');
div.innerHTML = item;
return div.firstChild;
} else {
var source = document.getElementById(list.item);
if (source) {
return source;
}
}
throw new Error("The list need to have at list one item on init otherwise you'll have to add a template.");
};
this.get = function(item, valueNames) {
templater.create(item);
var values = {};
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
values[valueNames[i].data[j]] = list.utils.getAttribute(item.elm, 'data-'+valueNames[i].data[j]);
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(item.elm, valueNames[i].name, true);
values[valueNames[i].name] = elm ? list.utils.getAttribute(elm, valueNames[i].attr) : "";
} else {
elm = list.utils.getByClass(item.elm, valueNames[i], true);
values[valueNames[i]] = elm ? elm.innerHTML : "";
}
elm = undefined;
}
return values;
};
this.set = function(item, values) {
var getValueName = function(name) {
for (var i = 0, il = list.valueNames.length; i < il; i++) {
if (list.valueNames[i].data) {
var data = list.valueNames[i].data;
for (var j = 0, jl = data.length; j < jl; j++) {
if (data[j] === name) {
return { data: name };
}
}
} else if (list.valueNames[i].attr && list.valueNames[i].name && list.valueNames[i].name == name) {
return list.valueNames[i];
} else if (list.valueNames[i] === name) {
return name;
}
}
};
var setValue = function(name, value) {
var elm;
var valueName = getValueName(name);
if (!valueName)
return;
if (valueName.data) {
item.elm.setAttribute('data-'+valueName.data, value);
} else if (valueName.attr && valueName.name) {
elm = list.utils.getByClass(item.elm, valueName.name, true);
if (elm) {
elm.setAttribute(valueName.attr, value);
}
} else {
elm = list.utils.getByClass(item.elm, valueName, true);
if (elm) {
elm.innerHTML = value;
}
}
elm = undefined;
};
if (!templater.create(item)) {
for(var v in values) {
if (values.hasOwnProperty(v)) {
setValue(v, values[v]);
}
}
}
};
this.create = function(item) {
if (item.elm !== undefined) {
return false;
}
/* If item source does not exists, use the first item in list as
source for new items */
var newItem = itemSource.cloneNode(true);
newItem.removeAttribute('id');
item.elm = newItem;
templater.set(item, item.values());
return true;
};
this.remove = function(item) {
if (item.elm.parentNode === list.list) {
list.list.removeChild(item.elm);
}
};
this.show = function(item) {
templater.create(item);
list.list.appendChild(item.elm);
};
this.hide = function(item) {
if (item.elm !== undefined && item.elm.parentNode === list.list) {
list.list.removeChild(item.elm);
}
};
this.clear = function() {
/* .innerHTML = ''; fucks up IE */
if (list.list.hasChildNodes()) {
while (list.list.childNodes.length >= 1)
{
list.list.removeChild(list.list.firstChild);
}
}
};
init();
};
module.exports = function(list) {
return new Templater(list);
};
list.js-1.2.0/src/utils/ 0000775 0000000 0000000 00000000000 12664333731 0015037 5 ustar 00root root 0000000 0000000 list.js-1.2.0/src/utils/classes.js 0000664 0000000 0000000 00000006335 12664333731 0017041 0 ustar 00root root 0000000 0000000 /**
* Module dependencies.
*/
var index = require('./index-of');
/**
* Whitespace regexp.
*/
var re = /\s+/;
/**
* toString reference.
*/
var toString = Object.prototype.toString;
/**
* Wrap `el` in a `ClassList`.
*
* @param {Element} el
* @return {ClassList}
* @api public
*/
module.exports = function(el){
return new ClassList(el);
};
/**
* Initialize a new ClassList for `el`.
*
* @param {Element} el
* @api private
*/
function ClassList(el) {
if (!el || !el.nodeType) {
throw new Error('A DOM element reference is required');
}
this.el = el;
this.list = el.classList;
}
/**
* Add class `name` if not already present.
*
* @param {String} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.add = function(name){
// classList
if (this.list) {
this.list.add(name);
return this;
}
// fallback
var arr = this.array();
var i = index(arr, name);
if (!~i) arr.push(name);
this.el.className = arr.join(' ');
return this;
};
/**
* Remove class `name` when present, or
* pass a regular expression to remove
* any which match.
*
* @param {String|RegExp} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.remove = function(name){
if ('[object RegExp]' == toString.call(name)) {
return this.removeMatching(name);
}
// classList
if (this.list) {
this.list.remove(name);
return this;
}
// fallback
var arr = this.array();
var i = index(arr, name);
if (~i) arr.splice(i, 1);
this.el.className = arr.join(' ');
return this;
};
/**
* Remove all classes matching `re`.
*
* @param {RegExp} re
* @return {ClassList}
* @api private
*/
ClassList.prototype.removeMatching = function(re){
var arr = this.array();
for (var i = 0; i < arr.length; i++) {
if (re.test(arr[i])) {
this.remove(arr[i]);
}
}
return this;
};
/**
* Toggle class `name`, can force state via `force`.
*
* For browsers that support classList, but do not support `force` yet,
* the mistake will be detected and corrected.
*
* @param {String} name
* @param {Boolean} force
* @return {ClassList}
* @api public
*/
ClassList.prototype.toggle = function(name, force){
// classList
if (this.list) {
if ("undefined" !== typeof force) {
if (force !== this.list.toggle(name, force)) {
this.list.toggle(name); // toggle again to correct
}
} else {
this.list.toggle(name);
}
return this;
}
// fallback
if ("undefined" !== typeof force) {
if (!force) {
this.remove(name);
} else {
this.add(name);
}
} else {
if (this.has(name)) {
this.remove(name);
} else {
this.add(name);
}
}
return this;
};
/**
* Return an array of classes.
*
* @return {Array}
* @api public
*/
ClassList.prototype.array = function(){
var className = this.el.getAttribute('class') || '';
var str = className.replace(/^\s+|\s+$/g, '');
var arr = str.split(re);
if ('' === arr[0]) arr.shift();
return arr;
};
/**
* Check if class `name` is present.
*
* @param {String} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.has =
ClassList.prototype.contains = function(name){
return this.list ? this.list.contains(name) : !! ~index(this.array(), name);
};
list.js-1.2.0/src/utils/events.js 0000664 0000000 0000000 00000001743 12664333731 0016706 0 ustar 00root root 0000000 0000000 var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
prefix = bind !== 'addEventListener' ? 'on' : '',
toArray = require('./to-array');
/**
* Bind `el` event `type` to `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.bind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
el[i][bind](prefix + type, fn, capture || false);
}
};
/**
* Unbind `el` event `type`'s callback `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.unbind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
el[i][unbind](prefix + type, fn, capture || false);
}
};
list.js-1.2.0/src/utils/extend.js 0000664 0000000 0000000 00000000736 12664333731 0016672 0 ustar 00root root 0000000 0000000 /*
* Source: https://github.com/segmentio/extend
*/
module.exports = function extend (object) {
// Takes an unlimited number of extenders.
var args = Array.prototype.slice.call(arguments, 1);
// For each extender, copy their properties on our object.
for (var i = 0, source; source = args[i]; i++) {
if (!source) continue;
for (var property in source) {
object[property] = source[property];
}
}
return object;
};
list.js-1.2.0/src/utils/get-attribute.js 0000664 0000000 0000000 00000001206 12664333731 0020154 0 ustar 00root root 0000000 0000000 /**
* A cross-browser implementation of getAttribute.
* Source found here: http://stackoverflow.com/a/3755343/361337 written by Vivin Paliath
*
* Return the value for `attr` at `element`.
*
* @param {Element} el
* @param {String} attr
* @api public
*/
module.exports = function(el, attr) {
var result = (el.getAttribute && el.getAttribute(attr)) || null;
if( !result ) {
var attrs = el.attributes;
var length = attrs.length;
for(var i = 0; i < length; i++) {
if (attr[i] !== undefined) {
if(attr[i].nodeName === attr) {
result = attr[i].nodeValue;
}
}
}
}
return result;
};
list.js-1.2.0/src/utils/get-by-class.js 0000664 0000000 0000000 00000003134 12664333731 0017670 0 ustar 00root root 0000000 0000000 /**
* A cross-browser implementation of getElementsByClass.
* Heavily based on Dustin Diaz's function: http://dustindiaz.com/getelementsbyclass.
*
* Find all elements with class `className` inside `container`.
* Use `single = true` to increase performance in older browsers
* when only one element is needed.
*
* @param {String} className
* @param {Element} container
* @param {Boolean} single
* @api public
*/
module.exports = (function() {
if (document.getElementsByClassName) {
return function(container, className, single) {
if (single) {
return container.getElementsByClassName(className)[0];
} else {
return container.getElementsByClassName(className);
}
};
} else if (document.querySelector) {
return function(container, className, single) {
className = '.' + className;
if (single) {
return container.querySelector(className);
} else {
return container.querySelectorAll(className);
}
};
} else {
return function(container, className, single) {
var classElements = [],
tag = '*';
if (container === null) {
container = document;
}
var els = container.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+className+"(\\s|$)");
for (var i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
if (single) {
return els[i];
} else {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
};
}
})();
list.js-1.2.0/src/utils/index-of.js 0000664 0000000 0000000 00000000307 12664333731 0017106 0 ustar 00root root 0000000 0000000 var indexOf = [].indexOf;
module.exports = function(arr, obj){
if (indexOf) return arr.indexOf(obj);
for (var i = 0; i < arr.length; ++i) {
if (arr[i] === obj) return i;
}
return -1;
};
list.js-1.2.0/src/utils/natural-sort.js 0000664 0000000 0000000 00000004533 12664333731 0020035 0 ustar 00root root 0000000 0000000 /*
* Natural Sort algorithm for Javascript - Version 0.8 - Released under MIT license
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
*/
module.exports = function(a, b, opts) {
var re = /(^([+\-]?(?:\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[\da-fA-F]+$|\d+)/g,
sre = /^\s+|\s+$/g, // trim pre-post whitespace
snre = /\s+/g, // normalize all whitespace to single ' ' character
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre = /^0x[0-9a-f]+$/i,
ore = /^0/,
options = opts || {},
i = function(s) { return options.insensitive && (''+s).toLowerCase() || ''+s; },
// convert all to strings strip whitespace
x = i(a) || '',
y = i(b) || '',
// chunk/tokenize
xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
// numeric, hex or date detection
xD = parseInt(x.match(hre), 16) || (xN.length !== 1 && Date.parse(x)),
yD = parseInt(y.match(hre), 16) || xD && y.match(dre) && Date.parse(y) || null,
normChunk = function(s, l) {
// normalize spaces; find floats not starting with '0', string or 0 if not defined (Clint Priest)
return (!s.match(ore) || l == 1) && parseFloat(s) || s.replace(snre, ' ').replace(sre, '') || 0;
},
oFxNcL, oFyNcL;
// first try and sort Hex codes or Dates
if (yD) {
if ( xD < yD ) { return -1; }
else if ( xD > yD ) { return 1; }
}
// natural sorting through split numeric strings and default strings
for(var cLoc=0, xNl = xN.length, yNl = yN.length, numS=Math.max(xNl, yNl); cLoc < numS; cLoc++) {
oFxNcL = normChunk(xN[cLoc], xNl);
oFyNcL = normChunk(yN[cLoc], yNl);
// handle numeric vs string comparison - number < string - (Kyle Adams)
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; }
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
else if (typeof oFxNcL !== typeof oFyNcL) {
oFxNcL += '';
oFyNcL += '';
}
if (oFxNcL < oFyNcL) { return -1; }
if (oFxNcL > oFyNcL) { return 1; }
}
return 0;
};
list.js-1.2.0/src/utils/to-array.js 0000664 0000000 0000000 00000002226 12664333731 0017135 0 ustar 00root root 0000000 0000000 /**
* Source: https://github.com/timoxley/to-array
*
* Convert an array-like object into an `Array`.
* If `collection` is already an `Array`, then will return a clone of `collection`.
*
* @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
* @return {Array} Naive conversion of `collection` to a new `Array`.
* @api public
*/
module.exports = function toArray(collection) {
if (typeof collection === 'undefined') return [];
if (collection === null) return [null];
if (collection === window) return [window];
if (typeof collection === 'string') return [collection];
if (isArray(collection)) return collection;
if (typeof collection.length != 'number') return [collection];
if (typeof collection === 'function' && collection instanceof Function) return [collection];
var arr = [];
for (var i = 0; i < collection.length; i++) {
if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) {
arr.push(collection[i]);
}
}
if (!arr.length) return [];
return arr;
};
function isArray(arr) {
return Object.prototype.toString.call(arr) === "[object Array]";
}
list.js-1.2.0/src/utils/to-string.js 0000664 0000000 0000000 00000000201 12664333731 0017314 0 ustar 00root root 0000000 0000000 module.exports = function(s) {
s = (s === undefined) ? "" : s;
s = (s === null) ? "" : s;
s = s.toString();
return s;
};
list.js-1.2.0/test/ 0000775 0000000 0000000 00000000000 12664333731 0014067 5 ustar 00root root 0000000 0000000 list.js-1.2.0/test/fixtures.js 0000664 0000000 0000000 00000002002 12664333731 0016270 0 ustar 00root root 0000000 0000000 var fixture = {
list: function(valueNames, items) {
var listHtml = $(''),
item = "";
item = "- ";
for (var i = 0; i < valueNames.length; i++) {
item += '';
}
item += "
";
$(document.body).append(listHtml);
items = items || [];
return new List('list', {
valueNames: valueNames,
item: item
}, items);
},
removeList: function() {
$('#list').remove();
},
jonny: {
name: "Jonny Strömberg",
born: '1986'
},
martina: {
name: "Martina Elm",
born: '1986'
},
angelica: {
name: "Angelica Abraham",
born: '1986'
},
sebastian: {
name: "Sebastian Höglund",
born: '1989'
},
imma: {
name: "Imma Grafström",
born: '1953'
},
hasse: {
name: "Hasse Strömberg",
born: '1955'
}
};
fixture.all = [
fixture.jonny,
fixture.martina,
fixture.angelica,
fixture.sebastian,
fixture.imma,
fixture.hasse
];
list.js-1.2.0/test/index.html 0000775 0000000 0000000 00000002547 12664333731 0016077 0 ustar 00root root 0000000 0000000
List.js Mocha Tests
list.js-1.2.0/test/test.add-get-remove.js 0000664 0000000 0000000 00000010265 12664333731 0020207 0 ustar 00root root 0000000 0000000 describe('Add, get, remove', function() {
var list;
before(function() {
list = fixture.list(['name'], [ { name: "Jonny" } ]);
});
after(function() {
fixture.removeList();
});
afterEach(function() {
list.clear();
list.add({ name: "Jonny" });
});
describe('Add', function() {
it('should add one item', function() {
list.add({ name: 'Jonas' });
expect(list.items.length).to.equal(2);
});
it('should add two items', function() {
list.add([
{ name: 'Martina' },
{ name: 'Angelica' }
]);
expect(list.items.length).to.equal(3);
});
it('should add async items', function(done) {
list.add([
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},
{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'},{name:'Sven'}
], function() {
expect(list.items.length).to.equal(91);
done();
});
});
it('should add async items to empty list', function(done) {
list.clear();
list.add([
{ name: 'Sven' }
], function() {
expect(list.items.length).to.equal(1);
done();
});
});
});
describe('Get', function() {
it('should return array with one item', function() {
var items = list.get('name', 'Jonny');
expect(items[0].values().name).to.equal('Jonny');
});
it('should return empty array', function() {
var items = list.get('name', 'jonny');
expect(items.length).to.be.zero;
});
it('should return two items', function() {
list.add({ name: 'Jonny' });
var items = list.get('name', 'Jonny');
expect(items.length).to.equal(2);
expect(items[0].values().name).to.equal('Jonny');
expect(items[1].values().name).to.equal('Jonny');
});
});
describe('Remove', function() {
it('should remove one item', function() {
list.add({ name: "Jonas" });
expect(list.items.length).to.equal(2);
var count = list.remove('name', 'Jonas');
expect(count).to.equal(1);
expect(list.items.length).to.equal(1);
});
it('should not remove anything due to case sensitivity', function() {
var count = list.remove('name', 'jonny');
expect(count).to.be.equal(0);
expect(list.items.length).to.equal(1);
});
it('should avoid node not found error', function() {
var item = list.get('name', 'Jonny')[0];
list.list.removeChild(item.elm);
var count = list.remove('name', 'Jonny');
expect(count).to.be.equal(1);
expect(list.items.length).to.equal(0);
});
it('should remove eight items', function() {
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
list.add({ name: 'Sven' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonas' });
list.add({ name: 'Jonny' });
list.add({ name: 'Jonny' });
expect(list.items.length).to.equal(10);
var count = list.remove('name', 'Jonny');
expect(count).to.equal(8);
expect(list.items.length).to.equal(2);
});
});
});
list.js-1.2.0/test/test.buttons.js 0000664 0000000 0000000 00000016436 12664333731 0017113 0 ustar 00root root 0000000 0000000 function fireKeyup(el) {
if (document.createEvent) {
var evObj;
if (window.KeyEvent) {
evObj = document.createEvent('KeyEvents');
evObj.initKeyEvent('keyup', true, true, window, false, false, false, false, 13, 0);
} else {
evObj = document.createEvent('UIEvents');
evObj.initUIEvent('keyup', true, true, window, 1);
}
el.dispatchEvent(evObj);
} else if( document.createEventObject ) {
el.fireEvent('onkeyup');
} else {
// IE 5.0, seriously? :)
}
}
// http://stackoverflow.com/questions/5658849/whats-the-equivalent-of-jquerys-trigger-method-without-jquery
function fireClick(el) {
var evt;
if (document.createEvent) {
evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
}
(evt) ? el.dispatchEvent(evt) : (el.click && el.click());
}
describe('Button', function() {
var list;
beforeEach(function() {
$('body').append($('\
\
Sort name\
Sort name asc\
Sort name desc\
\
'));
list = new List('parse-list', {
valueNames: ['name', 'born']
});
});
afterEach(function() {
$('#parse-list').remove();
});
describe('Sort', function() {
it('should trigger sortStart', function(done) {
list.on('sortComplete', function() {
done();
});
fireClick($('#sort-name')[0]);
});
it('should trigger sortComplete', function(done) {
list.on('sortComplete', function() {
done();
});
fireClick($('#sort-name')[0]);
});
it('should switch sorting order when clicking multiple times', function(done) {
this.timeout(5000);
var sortRun = 0;
list.on('sortComplete', function() {
sortRun++;
if (sortRun == 1) {
expect($('#sort-name').hasClass('asc')).to.be(true);
expect($('#sort-name').hasClass('desc')).to.be(false);
setTimeout(function() {
fireClick($('#sort-name')[0]);
}, 50);
} else if (sortRun == 2) {
expect($('#sort-name').hasClass('asc')).to.be(false);
expect($('#sort-name').hasClass('desc')).to.be(true);
setTimeout(function() {
fireClick($('#sort-name')[0]);
}, 50);
} else if (sortRun == 3) {
expect($('#sort-name').hasClass('asc')).to.be(true);
expect($('#sort-name').hasClass('desc')).to.be(false);
done();
}
});
expect($('#sort-name').hasClass('asc')).to.be(false);
expect($('#sort-name').hasClass('desc')).to.be(false);
fireClick($('#sort-name')[0]);
});
it('should sort with predefined order', function(done) {
this.timeout(10000);
var sortRun = 0;
list.on('sortComplete', function() {
sortRun++;
if (sortRun == 1) {
expect($('#sort-name').hasClass('asc')).to.be(true);
expect($('#sort-name').hasClass('desc')).to.be(false);
expect($('#sort-name-asc').hasClass('asc')).to.be(true);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(false);
setTimeout(function() {
fireClick($('#sort-name-asc')[0]);
}, 50);
} else if (sortRun == 2) {
expect($('#sort-name').hasClass('asc')).to.be(true);
expect($('#sort-name').hasClass('desc')).to.be(false);
expect($('#sort-name-asc').hasClass('asc')).to.be(true);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(false);
setTimeout(function() {
fireClick($('#sort-name-asc')[0]);
}, 50);
} else if (sortRun == 3) {
expect($('#sort-name').hasClass('asc')).to.be(true);
expect($('#sort-name').hasClass('desc')).to.be(false);
expect($('#sort-name-asc').hasClass('asc')).to.be(true);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(false);
setTimeout(function() {
fireClick($('#sort-name-desc')[0]);
}, 50);
} else if (sortRun == 4) {
expect($('#sort-name').hasClass('asc')).to.be(false);
expect($('#sort-name').hasClass('desc')).to.be(true);
expect($('#sort-name-asc').hasClass('asc')).to.be(false);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(true);
setTimeout(function() {
fireClick($('#sort-name-desc')[0]);
}, 50);
} else if (sortRun == 5) {
expect($('#sort-name').hasClass('asc')).to.be(false);
expect($('#sort-name').hasClass('desc')).to.be(true);
expect($('#sort-name-asc').hasClass('asc')).to.be(false);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(true);
done();
}
});
expect($('#sort-name').hasClass('asc')).to.be(false);
expect($('#sort-name').hasClass('desc')).to.be(false);
expect($('#sort-name-asc').hasClass('asc')).to.be(false);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(false);
fireClick($('#sort-name-asc')[0]);
});
it('buttons should change class when sorting programmatically', function(done) {
list.on('sortComplete', function() {
expect($('#sort-name').hasClass('asc')).to.be(true);
expect($('#sort-name').hasClass('desc')).to.be(false);
expect($('#sort-name-asc').hasClass('asc')).to.be(true);
expect($('#sort-name-asc').hasClass('desc')).to.be(false);
expect($('#sort-name-desc').hasClass('asc')).to.be(false);
expect($('#sort-name-desc').hasClass('desc')).to.be(false);
done();
});
list.sort('name', { order: "asc" });
})
});
describe('Search', function() {
it('should trigger searchStart', function(done) {
list.on('searchStart', function() {
done();
});
$('#parse-list .search').val('jon');
fireKeyup($('#parse-list .search')[0]);
});
it('should trigger searchComplete', function(done) {
list.on('searchComplete', function() {
done();
});
$('#parse-list .search').val('jon');
fireKeyup($('#parse-list .search')[0]);
});
});
});
list.js-1.2.0/test/test.create.js 0000664 0000000 0000000 00000023655 12664333731 0016661 0 ustar 00root root 0000000 0000000 describe('Create', function() {
describe('With HTML items', function() {
var listEl = $('');
$(document.body).append(listEl);
var list = new List('list', { valueNames: ['name'] });
it('should contain one item', function() {
expect(list.items.length).to.equal(1);
expect(listEl.find('li').size()).to.equal(1);
});
it('should contain two items', function() {
list.add({ name: 'Jonas' });
expect(list.items.length).to.equal(2);
expect(listEl.find('li').size()).to.equal(2);
});
listEl.remove();
});
describe('Without items and with string template', function() {
var listEl = $('');
$(document.body).append(listEl);
var list = new List('list', {
valueNames: ['name'],
item: ' '
}, [
{ name: 'Jonny' }
]);
it('should contain one item', function() {
expect(list.items.length).to.equal(1);
expect(listEl.find('li').size()).to.equal(1);
});
it('should contain two items', function() {
list.add({ name: 'Jonas' });
expect(list.items.length).to.equal(2);
expect(listEl.find('li').size()).to.equal(2);
});
listEl.remove();
});
describe('Without items and with HTML template', function() {
var listEl = $('');
var templateEl = $(' ');
$(document.body).append(listEl);
$(document.body).append(templateEl);
var list = new List('list', {
valueNames: ['name'],
item: 'template-item'
}, [
{ name: 'Jonny' }
]);
it('should contain one item', function() {
expect(list.items.length).to.equal(1);
expect(listEl.find('li').size()).to.equal(1);
});
it('should contain two items', function() {
list.add({ name: 'Jonas' });
expect(list.items.length).to.equal(2);
expect(listEl.find('li').size()).to.equal(2);
});
listEl.remove();
templateEl.remove();
});
describe('Asyn index with existing list', function() {
var listEl = $('');
it('should contain one item', function(done) {
$(document.body).append(listEl);
var list = new List('list', {
valueNames: ['name'],
indexAsync: true,
parseComplete: function(list) {
expect(listEl.find('li').size()).to.equal(162);
listEl.remove();
done();
}
});
});
});
});
list.js-1.2.0/test/test.defaults.js 0000664 0000000 0000000 00000004437 12664333731 0017222 0 ustar 00root root 0000000 0000000 describe('Defaults', function() {
var list;
before(function() {
list = fixture.list(['name'], [ { name: 'Jonny' }]);
});
after(function() {
fixture.removeList();
});
it('should have all default attributes', function() {
expect(list.items).to.be.an('array');
expect(list.visibleItems).to.be.an('array');
expect(list.matchingItems).to.be.an('array');
expect(list.handlers.updated).to.be.an('array');
expect(list.handlers.searchStart).to.be.an('array');
expect(list.handlers.searchComplete).to.be.an('array');
expect(list.handlers.sortStart).to.be.an('array');
expect(list.handlers.sortComplete).to.be.an('array');
expect(list.handlers.filterStart).to.be.an('array');
expect(list.handlers.filterComplete).to.be.an('array');
expect(list.searched).to.be(false);
expect(list.filtered).to.be(false);
expect(list.i).to.equal(1);
expect(list.page).to.equal(10000);
expect(list.listClass).to.equal('list');
expect(list.sortClass).to.equal('sort');
expect(list.searchClass).to.equal('search');
});
it('should have the right elements', function() {
expect(list.list).to.equal($('.list')[0]);
expect(list.listContainer).to.equal($('#list')[0]);
});
it('should have all default methods', function() {
expect(list.add).to.be.a('function');
expect(list.remove).to.be.a('function');
expect(list.get).to.be.a('function');
expect(list.sort).to.be.a('function');
expect(list.search).to.be.a('function');
expect(list.clear).to.be.a('function');
expect(list.filter).to.be.a('function');
expect(list.size).to.be.a('function');
expect(list.show).to.be.a('function');
expect(list.update).to.be.a('function');
expect(list.on).to.be.a('function');
});
it('should have all helper methods', function() {
expect(list.utils.classes).to.be.a('function');
expect(list.utils.getAttribute).to.be.a('function');
expect(list.utils.getByClass).to.be.a('function');
expect(list.utils.naturalSort).to.be.a('function');
expect(list.utils.events.bind).to.be.a('function');
expect(list.utils.events.unbind).to.be.a('function');
expect(list.utils.extend).to.be.a('function');
expect(list.utils.indexOf).to.be.a('function');
expect(list.utils.toString).to.be.a('function');
});
});
list.js-1.2.0/test/test.filter.js 0000664 0000000 0000000 00000006370 12664333731 0016676 0 ustar 00root root 0000000 0000000 describe('Filter', function() {
var list, jonny, martina, angelica, sebastian, imma, hasse;
before(function() {
list = fixture.list(['name', 'born'], fixture.all);
jonny = list.get('name', 'Jonny Strömberg')[0];
martina = list.get('name', 'Martina Elm')[0];
angelica = list.get('name', 'Angelica Abraham')[0];
sebastian = list.get('name', 'Sebastian Höglund')[0];
imma = list.get('name', 'Imma Grafström')[0];
hasse = list.get('name', 'Hasse Strömberg')[0];
});
after(function() {
fixture.removeList();
});
afterEach(function() {
list.filter();
list.show(1, 200);
});
describe('Basics', function() {
it('should return everyone born after 1988', function() {
var result = list.filter(function(item) {
return (item.values().born > 1988);
});
expect(result.length).to.equal(1);
expect(result[0]).to.eql(sebastian);
});
it('should return everyone born 1986', function() {
var result = list.filter(function(item) {
return (item.values().born == 1986);
});
expect(result.length).to.equal(3);
for (var i = 0; i < result.length; i++) {
expect(result[i].values().born).to.equal('1986');
}
});
});
describe('Show and pages', function() {
it('should return the visible items', function() {
list.show(1,2);
var result = list.filter(function(item) {
return (item.values().born > 1985);
});
expect(result).to.eql(list.visibleItems);
});
it('should return be 2 visible items and 3 matching', function() {
list.show(1,2);
var result = list.filter(function(item) {
return (item.values().born > 1985);
});
expect(result.length).to.equal(2);
expect(list.visibleItems.length).to.equal(2);
expect(list.matchingItems.length).to.equal(4);
});
describe('Specific items', function() {
beforeEach(function() {
list.show(1,2);
var result = list.filter(function(item) {
return (item.values().born > 1985);
});
});
it('should match jonny', function() {
expect(jonny.matching()).to.be(true);
expect(jonny.filtered).to.be(true);
expect(jonny.visible()).to.be(true);
});
it('should match martina', function() {
expect(martina.matching()).to.be(true);
expect(martina.filtered).to.be(true);
expect(martina.visible()).to.be(true);
});
it('should match but not show angelica', function() {
expect(angelica.matching()).to.be(true);
expect(angelica.filtered).to.be(true);
expect(angelica.visible()).to.be(false);
});
it('should match but not show sebastian', function() {
expect(sebastian.matching()).to.be(true);
expect(sebastian.filtered).to.be(true);
expect(sebastian.visible()).to.be(false);
});
it('should not match imma', function() {
expect(imma.matching()).to.be(false);
expect(imma.filtered).to.be(false);
expect(imma.visible()).to.be(false);
});
it('should not match hasse', function() {
expect(hasse.matching()).to.be(false);
expect(hasse.filtered).to.be(false);
expect(hasse.visible()).to.be(false);
});
});
});
});
list.js-1.2.0/test/test.item.js 0000664 0000000 0000000 00000010472 12664333731 0016345 0 ustar 00root root 0000000 0000000 describe('Item', function() {
var list, item;
before(function() {
list = fixture.list(['name', 'born', 'doin'], [{
name: "Jonny",
born: "1986",
doin: "Living the dream"
}]);
item = list.get('name', 'Jonny')[0];
});
beforeEach(function() {
list.search();
list.filter();
list.show(1,200);
});
after(function() {
fixture.removeList();
});
describe('Defaults', function() {
it('should have all default attributes', function() {
expect(item.found).to.be(false);
expect(item.filtered).to.be(false);
});
it('should have the right elements', function() {
expect(item.elm).to.equal($('#list li')[0]);
});
it('should have all default methods', function() {
expect(item.hide).to.be.a('function');
expect(item.show).to.be.a('function');
expect(item.values).to.be.a('function');
expect(item.matching).to.be.a('function');
expect(item.visible).to.be.a('function');
});
});
describe('Values()', function() {
it('should have the right values', function() {
expect(item.values()).to.eql({
name: 'Jonny',
born: '1986',
doin: 'Living the dream'
});
});
it('should be able to change one value', function() {
expect(item.values().name).to.be.equal('Jonny');
item.values({ name: 'Egon' });
expect(item.values().name).to.be.equal('Egon');
});
it('should be able to change many value', function() {
expect(item.values()).to.eql({
name: 'Egon',
born: '1986',
doin: 'Living the dream'
});
item.values({
name: 'Sven',
born: '1801',
doin: 'Is dead'
});
expect(item.values()).to.eql({
name: 'Sven',
born: '1801',
doin: 'Is dead'
});
});
});
describe('Hide, show, visible', function() {
it('should be hidden', function() {
expect($('#list li').size()).to.equal(1);
item.hide();
expect(item.visible()).to.be(false);
expect($('#list li').size()).to.equal(0);
});
it('should be visible', function() {
item.hide();
expect($('#list li').size()).to.equal(0);
item.show();
expect(item.visible()).to.be(true);
expect($('#list li').size()).to.equal(1);
});
});
describe('Matching, found, filtered', function() {
describe('Searching', function() {
it('should not be visible, match, found or filtered', function() {
list.search('Fredrik');
expect(item.matching()).to.be(false);
expect(item.found).to.be(false);
expect(item.filtered).to.be(false);
expect(item.visible()).to.be(false);
});
it('should be visble, match and found but not filterd', function() {
var result = list.search('Sven');
expect(item.matching()).to.be(true);
expect(item.found).to.be(true);
expect(item.filtered).to.be(false);
expect(item.visible()).to.be(true);
});
it('reset: should be visible and matching but not found or filtered', function() {
list.search();
expect(item.matching()).to.be(true);
expect(item.found).to.be(false);
expect(item.filtered).to.be(false);
expect(item.visible()).to.be(true);
});
});
describe('Filtering', function() {
it('should not be visble, match, found or filtered', function() {
list.filter(function(item) {
return (item.values().name == "Fredrik");
});
expect(item.matching()).to.be(false);
expect(item.found).to.be(false);
expect(item.filtered).to.be(false);
expect(item.visible()).to.be(false);
});
it('should be visble, match and filtered but not found', function() {
list.filter(function(item) {
return (item.values().name == "Sven");
});
expect(item.matching()).to.be(true);
expect(item.found).to.be(false);
expect(item.filtered).to.be(true);
expect(item.visible()).to.be(true);
});
it('reset: should be visble and match but not filtered or found', function() {
list.filter();
expect(item.matching()).to.be(true);
expect(item.found).to.be(false);
expect(item.filtered).to.be(false);
expect(item.visible()).to.be(true);
});
});
});
fixture.removeList();
});
list.js-1.2.0/test/test.off.js 0000664 0000000 0000000 00000002136 12664333731 0016157 0 ustar 00root root 0000000 0000000 describe('Off', function() {
var list;
before(function() {
list = fixture.list(['name', 'born'], fixture.all);
});
after(function() {
fixture.removeList();
});
describe('General', function() {
it('should be remove added handler', function(done) {
var updated = function(list) {
expect(list.handlers.updated.length).to.equal(1);
list.off('updated', updated);
expect(list.handlers.updated.length).to.equal(0);
done();
};
list.on('updated', updated);
list.search('jonny');
});
it('should not remove unnamed handlers', function(done) {
var searchComplete = function(list) {
expect(list.handlers.searchComplete.length).to.equal(3);
list.off('searchComplete', function() {});
list.off('searchComplete', searchComplete);
expect(list.handlers.searchComplete.length).to.equal(2);
done();
};
list.on('searchComplete', function() {});
list.on('searchComplete', searchComplete);
list.on('searchComplete', function() {});
list.search('jonny');
});
});
});
list.js-1.2.0/test/test.on.js 0000664 0000000 0000000 00000005424 12664333731 0016024 0 ustar 00root root 0000000 0000000 describe('On', function() {
var list;
beforeEach(function() {
list = fixture.list(['name', 'born'], fixture.all);
});
afterEach(function() {
fixture.removeList();
});
describe('Updated', function() {
it('should be triggered after search', function(done) {
list.on('updated', function(list) {
done();
});
list.search('jonny');
});
it('should be triggered after sort', function(done) {
list.on('updated', function(list) {
done();
});
list.sort('name');
});
it('should be triggered after filter', function(done) {
list.on('updated', function(list) {
done();
});
list.filter(function() {
return true;
});
});
it('should be triggered after show', function(done) {
list.on('updated', function(list) {
done();
});
list.show(1,10);
});
it('should be triggered after add', function(done) {
list.on('updated', function(list) {
done();
});
list.add({ name: 'Hej' });
});
it('should be triggered after remove', function(done) {
list.on('updated', function(list) {
done();
});
list.remove('name', 'Jonny');
});
});
describe('Multiple handlers', function() {
it('should be trigger both handlers', function(done) {
var done1 = false,
done2 = false,
isDone = function() {
if (done1 && done2) {
done();
}
};
list.on('updated', function(list) {
done1 = true;
isDone();
});
list.on('updated', function(list) {
done2 = true;
isDone();
});
list.search('jonny');
});
});
describe('Search', function() {
it('should be triggered before and after search', function(done) {
var done1 = false;
list.on('searchStart', function(list) {
done1 = true;
});
list.on('searchComplete', function(list) {
if (done1) {
done();
}
});
list.search('jonny');
});
});
describe('Sort', function() {
it('should be triggered before and after sort', function(done) {
var done1 = false;
list.on('sortStart', function(list) {
done1 = true;
});
list.on('sortComplete', function(list) {
if (done1) {
done();
}
});
list.sort('name');
});
});
describe('Filter', function() {
it('should be triggered before and after filter', function(done) {
var done1 = false;
list.on('filterStart', function(list) {
done1 = true;
});
list.on('filterComplete', function(list) {
if (done1) {
done();
}
});
list.filter(function() {
return true;
});
});
});
});
list.js-1.2.0/test/test.parse.js 0000664 0000000 0000000 00000010671 12664333731 0016522 0 ustar 00root root 0000000 0000000 describe('Parse', function() {
describe('Parse class', function() {
var list;
beforeEach(function() {
$('body').append($(''));
list = new List('parse-list', {
valueNames: ['name', 'born']
});
});
afterEach(function() {
$('#parse-list').remove();
});
it('should have two items', function() {
expect(list.items.length).to.equal(2);
expect(list.items[0].values().name).to.equal("Jonny");
expect(list.items[1].values().name).to.equal("Jocke");
});
it('should add item to parsed list', function() {
list.add({ name: "Sven", born: 1950 });
expect(list.items.length).to.equal(3);
expect(list.items[0].values().name).to.equal("Jonny");
expect(list.items[1].values().name).to.equal("Jocke");
expect(list.items[2].values().name).to.equal("Sven");
expect(list.items[0].values().born).to.equal("1986");
expect(list.items[2].values().born).to.equal(1950);
var el = $($('#parse-list').find('.list div')[2]);
expect(el.find('span').size()).to.equal(2);
expect(el.find('span.name').text()).to.equal('Sven');
expect(el.find('span.born').text()).to.equal('1950');
});
it('should parsed value always be string while added could be number', function() {
list.add({ name: "Sven", born: 1950 });
expect(list.items[0].values().born).to.equal("1986");
expect(list.items[0].values().born).not.to.equal(1986);
expect(list.items[2].values().born).not.to.equal("1950");
expect(list.items[2].values().born).to.equal(1950);
});
});
describe('Parse data', function() {
var list;
beforeEach(function() {
$('body').append($(''));
list = new List('parse-list', {
valueNames: [
'name',
'born',
{ data: [ 'id' ] },
{ attr: 'src', name: 'image'},
{ attr: 'href', name: 'link'},
{ attr: 'value', name: 'foo'},
{ attr: 'data-timestamp', name: 'timestamp' }
]
});
});
afterEach(function() {
$('#parse-list').remove();
});
it('should get values from class, data, src, value and child els data-attribute', function() {
expect(list.items.length).to.equal(2);
var jonny = list.items[0].values()
expect(jonny.name).to.equal("Jonny");
expect(jonny.born).to.equal("1986");
expect(jonny.id).to.equal("1");
expect(jonny.image).to.equal("jonny.jpg");
expect(jonny.timestamp).to.equal("54321");
expect(jonny.foo).to.equal("Bar");
});
it('should add item to list with class, data and src', function() {
list.add({ name: "Sven", born: 1950, id: 4, image: 'sven.gif', link: 'localhost', timestamp: '1337', foo: 'hej' });
expect(list.items.length).to.equal(3);
var sven = list.items[2].values();
expect(sven.name).to.equal("Sven");
expect(sven.born).to.equal(1950);
expect(sven.id).to.equal(4);
expect(sven.image).to.equal("sven.gif");
expect(sven.link).to.equal("localhost");
expect(sven.timestamp).to.equal("1337");
expect(sven.foo).to.equal("hej");
var el = $($('#parse-list').find('.list div')[2]);
expect(el.data('id')).to.equal(4);
expect(el.find('.name').text()).to.equal('Sven');
expect(el.find('.born').text()).to.equal('1950');
expect(el.find('.image').attr('src')).to.equal('sven.gif');
expect(el.find('.link').attr('href')).to.equal('localhost');
expect(el.find('.timestamp').data('timestamp')).to.equal(1337);
expect(el.find('.foo').val()).to.equal('hej');
});
});
});
list.js-1.2.0/test/test.re-index.js 0000664 0000000 0000000 00000002025 12664333731 0017115 0 ustar 00root root 0000000 0000000 describe('ReIndex', function() {
var list, jonny, martina, angelica, sebastian, imma, hasse;
before(function() {
list = fixture.list(['name', 'born'], fixture.all);
});
after(function() {
fixture.removeList();
});
afterEach(function() {
list.show(1, 200);
});
it('should return everyone born after 1988', function() {
expect(list.toJSON()).to.eql([
{ name: "Jonny Strömberg", born: '1986' },
{ name: "Martina Elm", born: '1986' },
{ name: "Angelica Abraham", born: '1986' },
{ name: "Sebastian Höglund", born: '1989' },
{ name: "Imma Grafström", born: '1953' },
{ name: "Hasse Strömberg", born: '1955' }
]);
var newHtml = '- Sven2013';
newHtml = newHtml + '
- Anna3043'
$(list.list).html(newHtml);
list.reIndex();
expect(list.toJSON()).to.eql([
{ name: "Sven", born: '2013' },
{ name: "Anna", born: '3043' }
]);
});
});
list.js-1.2.0/test/test.search-filter.js 0000664 0000000 0000000 00000004272 12664333731 0020140 0 ustar 00root root 0000000 0000000 describe('Search and filter', function() {
var list, jonny, martina, angelica, sebastian, imma, hasse;
before(function() {
list = fixture.list(['name', 'born'], fixture.all);
jonny = list.get('name', 'Jonny Strömberg')[0];
martina = list.get('name', 'Martina Elm')[0];
angelica = list.get('name', 'Angelica Abraham')[0];
sebastian = list.get('name', 'Sebastian Höglund')[0];
imma = list.get('name', 'Imma Grafström')[0];
hasse = list.get('name', 'Hasse Strömberg')[0];
});
after(function() {
fixture.removeList();
});
afterEach(function() {
list.search();
list.filter();
});
describe('Search with filter', function() {
it('should find everyone born 1986', function() {
list.filter(function(item) {
return (item.values().born == '1986');
});
expect(list.matchingItems.length).to.equal(3);
expect(jonny.matching()).to.be(true);
expect(martina.matching()).to.be(true);
expect(angelica.matching()).to.be(true);
expect(sebastian.matching()).to.be(false);
expect(imma.matching()).to.be(false);
expect(hasse.matching()).to.be(false);
});
it('should find everyone born 1986 and containes "ö"', function() {
list.filter(function(item) {
return (item.values().born == '1986');
});
list.search('ö');
expect(list.matchingItems.length).to.equal(1);
expect(jonny.matching()).to.be(true);
expect(martina.matching()).to.be(false);
expect(angelica.matching()).to.be(false);
expect(sebastian.matching()).to.be(false);
expect(imma.matching()).to.be(false);
expect(hasse.matching()).to.be(false);
});
it('should find everyone with a "ö"', function() {
list.filter(function(item) {
return (item.values().born == '1986');
});
list.search('ö');
list.filter();
expect(list.matchingItems.length).to.equal(4);
expect(jonny.matching()).to.be(true);
expect(martina.matching()).to.be(false);
expect(angelica.matching()).to.be(false);
expect(sebastian.matching()).to.be(true);
expect(imma.matching()).to.be(true);
expect(hasse.matching()).to.be(true);
});
});
});
list.js-1.2.0/test/test.search.js 0000664 0000000 0000000 00000012522 12664333731 0016652 0 ustar 00root root 0000000 0000000 describe('Search', function() {
var list, jonny, martina, angelica, sebastian, imma, hasse;
beforeEach(function() {
list = fixture.list(['name', 'born'], fixture.all);
jonny = list.get('name', 'Jonny Strömberg')[0];
martina = list.get('name', 'Martina Elm')[0];
angelica = list.get('name', 'Angelica Abraham')[0];
sebastian = list.get('name', 'Sebastian Höglund')[0];
imma = list.get('name', 'Imma Grafström')[0];
hasse = list.get('name', 'Hasse Strömberg')[0];
});
afterEach(function() {
fixture.removeList();
});
describe('Case-sensitive', function() {
it('should not be case-sensitive', function() {
var result = list.search('jonny');
expect(result.length).to.equal(1);
expect(result[0]).to.eql(jonny);
});
});
describe('Number of results', function() {
it('should find jonny, martina, angelice', function() {
var result = list.search('1986');
expect(result.length).to.equal(3); // 3!!
expect(jonny.matching()).to.be(true);
expect(martina.matching()).to.be(true);
expect(angelica.matching()).to.be(true);
expect(sebastian.matching()).to.be(false);
expect(imma.matching()).to.be(false);
expect(hasse.matching()).to.be(false);
});
it('should find all with utf-8 char ö', function() {
var result = list.search('ö');
expect(result.length).to.equal(4); // 4!!
expect(jonny.matching()).to.be(true);
expect(martina.matching()).to.be(false);
expect(angelica.matching()).to.be(false);
expect(sebastian.matching()).to.be(true);
expect(imma.matching()).to.be(true);
expect(hasse.matching()).to.be(true);
});
it('should not break with weird searches', function() {
expect(list.search).withArgs(undefined).to.not.throwException();
expect(list.search).withArgs(null).to.not.throwException();
expect(list.search).withArgs(0).to.not.throwException();
expect(list.search).withArgs(function() {}).to.not.throwException();
expect(list.search).withArgs({ foo: "bar" }).to.not.throwException();
});
it('should not break with weird values', function() {
jonny.values({ name: undefined });
martina.values({ name: null });
angelica.values({ name: 0 });
sebastian.values({ name: function() {} });
imma.values({ name: { foo: "bar" } });
expect(list.search).withArgs("jonny").to.not.throwException();
expect(list.search).withArgs(undefined).to.not.throwException();
expect(list.search).withArgs(null).to.not.throwException();
expect(list.search).withArgs(0).to.not.throwException();
expect(list.search).withArgs(function() {}).to.not.throwException();
expect(list.search).withArgs({ foo: "bar" }).to.not.throwException();
});
});
describe('Default search columns', function() {
it('should find in the default match column', function() {
list.searchColumns = ['name'];
var result = list.search('jonny');
expect(result.length).to.equal(1);
expect(result[0]).to.eql(jonny);
});
it('should not find in the default match column', function() {
list.searchColumns = ['born'];
var result = list.search('jonny');
expect(result.length).to.equal(0);
});
});
describe('Specfic columns', function() {
it('should find match in column', function() {
var result = list.search('jonny', [ 'name' ]);
expect(result.length).to.equal(1);
expect(result[0]).to.eql(jonny);
});
it('should not find match in column', function() {
var result = list.search('jonny', [ 'born' ]);
expect(result.length).to.equal(0);
});
it('should find match in column', function() {
var result = list.search('jonny', [ 'name' ]);
expect(result.length).to.equal(1);
expect(result[0]).to.eql(jonny);
});
it('should not find match in column', function() {
var result = list.search('jonny', [ 'born' ]);
expect(result.length).to.equal(0);
});
it('should work with columns that does not exist', function() {
var result = list.search('jonny', [ 'pet' ]);
expect(result.length).to.equal(0);
});
});
describe('Custom search function', function() {
var customSearchFunction = function(searchString, columns) {
for (var k = 0, kl = list.items.length; k < kl; k++) {
if (list.items[k].values().born > 1985) {
list.items[k].found = true;
}
}
};
it('should use custom function in third argument', function() {
var result = list.search('jonny', [ 'name' ], customSearchFunction);
expect(result.length).to.equal(4);
});
it('should use custom function in second argument', function() {
var result = list.search('jonny', customSearchFunction);
expect(result.length).to.equal(4);
});
});
//
// describe('Special characters', function() {
// it('should escape and handle special characters', function() {
// list.add([
// { name: 'Jonny&Jabba' },
// { name: 'Luke' },
// { name: '"Chewie"' },
// { name: "'Ewok'" }
// ]);
// var result = list.search('Leia');
// console.log(result);
// expect(result.length).to.equal(1);
// var result = list.search('<');
// console.log(result);
// expect(result.length).to.equal(1);
// });
// });
});
list.js-1.2.0/test/test.show.js 0000664 0000000 0000000 00000014772 12664333731 0016376 0 ustar 00root root 0000000 0000000 describe('Show', function() {
var list, a, b, c, d, e, f;
before(function() {
list = fixture.list(['id', 'id2'], [
{ id: "1", id2: "a" },
{ id: "2", id2: "a" },
{ id: "3", id2: "b" },
{ id: "4", id2: "b" },
{ id: "5", id2: "bc" },
{ id: "6", id2: "bc" }
]);
a = list.get('id', '1')[0];
b = list.get('id', '2')[0];
c = list.get('id', '3')[0];
d = list.get('id', '4')[0];
e = list.get('id', '5')[0];
f = list.get('id', '6')[0];
});
after(function() {
fixture.removeList();
});
afterEach(function() {
list.filter();
list.show(1, 200);
});
describe('Basics', function() {
it('should be 1, 2', function() {
list.show(1,2);
expect(list.visibleItems.length).to.equal(2);
expect(a.visible()).to.be(true);
expect(b.visible()).to.be(true);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(false);
expect(f.visible()).to.be(false);
});
it('should show item 6', function() {
list.show(6,2);
expect(list.visibleItems.length).to.equal(1);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(false);
expect(f.visible()).to.be(true);
});
it('should show item 1, 2, 3, 4, 5, 6', function() {
list.show(1,200);
expect(list.visibleItems.length).to.equal(6);
expect(a.visible()).to.be(true);
expect(b.visible()).to.be(true);
expect(c.visible()).to.be(true);
expect(d.visible()).to.be(true);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(true);
});
it('should show item 3, 4, 5', function() {
list.show(3,3);
expect(list.visibleItems.length).to.equal(3);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(true);
expect(d.visible()).to.be(true);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(false);
});
it('should show item 5, 6', function() {
list.show(5,3);
expect(list.visibleItems.length).to.equal(2);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(true);
});
});
describe('Search', function() {
afterEach(function() {
list.search();
});
it('should show 3, 4', function() {
list.search('b');
list.show(1,2);
expect(list.visibleItems.length).to.equal(2);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(true);
expect(d.visible()).to.be(true);
expect(e.visible()).to.be(false);
expect(f.visible()).to.be(false);
});
it('should show item 3,4,5,6', function() {
list.search('b');
list.show(1,4);
expect(list.visibleItems.length).to.equal(4);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(true);
expect(d.visible()).to.be(true);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(true);
});
it('should not show any items but match two', function() {
list.search('a');
list.show(3,2);
expect(list.visibleItems.length).to.equal(0);
expect(list.matchingItems.length).to.equal(2);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(false);
expect(f.visible()).to.be(false);
});
});
describe('Filter', function() {
afterEach(function() {
list.filter();
});
it('should show 3, 4', function() {
list.filter(function(item) {
return (item.values().id2 == 'b');
});
list.show(1,2);
expect(list.visibleItems.length).to.equal(2);
expect(list.matchingItems.length).to.equal(2);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(true);
expect(d.visible()).to.be(true);
expect(e.visible()).to.be(false);
expect(f.visible()).to.be(false);
});
it('should show item 3,4,5,6', function() {
list.filter(function(item) {
return (item.values().id2 == 'bc');
});
list.show(1,4);
expect(list.visibleItems.length).to.equal(2);
expect(list.matchingItems.length).to.equal(2);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(true);
});
it('should not show any items but match two', function() {
list.filter(function(item) {
return (item.values().id2 == 'b');
});
list.show(3,2);
expect(list.visibleItems.length).to.equal(0);
expect(list.matchingItems.length).to.equal(2);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(false);
expect(f.visible()).to.be(false);
});
});
describe('Filter and search', function() {
afterEach(function() {
list.filter();
});
it('should show 4, 5', function() {
list.show(1,2);
list.filter(function(item) {
return (item.values().id > '3');
});
list.search('b');
expect(list.visibleItems.length).to.equal(2);
expect(list.matchingItems.length).to.equal(3);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(true);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(false);
});
it('should show 5, 6', function() {
list.show(1,2);
list.filter(function(item) {
return (item.values().id > '3');
});
list.search('b');
list.show(2,2);
expect(list.visibleItems.length).to.equal(2);
expect(list.matchingItems.length).to.equal(3);
expect(a.visible()).to.be(false);
expect(b.visible()).to.be(false);
expect(c.visible()).to.be(false);
expect(d.visible()).to.be(false);
expect(e.visible()).to.be(true);
expect(f.visible()).to.be(true);
});
});
});
list.js-1.2.0/test/test.sort.js 0000664 0000000 0000000 00000033326 12664333731 0016401 0 ustar 00root root 0000000 0000000 describe('Sort', function() {
var list, i1, i2, i3, i4, i5, i6;
beforeEach(function() {
list = fixture.list(['id'], [
{ id: "1", val: "" },
{ id: "2", val: "" },
{ id: "3", val: "" },
{ id: "4", val: "" },
{ id: "5", val: "" },
{ id: "6", val: "" }
]);
i1 = list.get('id', '1')[0];
i2 = list.get('id', '2')[0];
i3 = list.get('id', '3')[0];
i4 = list.get('id', '4')[0];
i5 = list.get('id', '5')[0];
i6 = list.get('id', '6')[0];
});
afterEach(function() {
fixture.removeList();
});
describe('Basics', function() {
it('should sort letters asc', function() {
i1.values({ val: "b" });
i2.values({ val: "a" });
i3.values({ val: "c" });
i4.values({ val: "z" });
i5.values({ val: "s" });
i6.values({ val: "y" });
list.sort('val');
expect(list.items[0].values().val).to.be.equal("a");
expect(list.items[1].values().val).to.be.equal("b");
expect(list.items[2].values().val).to.be.equal("c");
expect(list.items[3].values().val).to.be.equal("s");
expect(list.items[4].values().val).to.be.equal("y");
expect(list.items[5].values().val).to.be.equal("z");
});
it('should sort letters desc', function() {
i1.values({ val: "b" });
i2.values({ val: "a" });
i3.values({ val: "c" });
i4.values({ val: "z" });
i5.values({ val: "s" });
i6.values({ val: "y" });
list.sort('val', { order: "desc" });
expect(list.items[0].values().val).to.be.equal("z");
expect(list.items[1].values().val).to.be.equal("y");
expect(list.items[2].values().val).to.be.equal("s");
expect(list.items[3].values().val).to.be.equal("c");
expect(list.items[4].values().val).to.be.equal("b");
expect(list.items[5].values().val).to.be.equal("a");
});
it('should fail to sort åäö desc (becomes äåö)', function() {
i1.values({ val: "a" });
i2.values({ val: "å" });
i3.values({ val: "ä" });
i4.values({ val: "ö" });
i5.values({ val: "o" });
i6.values({ val: "s" });
list.sort('val');
expect(list.items[0].values().val).to.be.equal("a");
expect(list.items[1].values().val).to.be.equal("o");
expect(list.items[2].values().val).to.be.equal("s");
expect(list.items[3].values().val).to.be.equal("ä");
expect(list.items[4].values().val).to.be.equal("å");
expect(list.items[5].values().val).to.be.equal("ö");
});
it('should fail to sort åäö asc (becomes öåä)', function() {
i1.values({ val: "a" });
i2.values({ val: "å" });
i3.values({ val: "ä" });
i4.values({ val: "ö" });
i5.values({ val: "o" });
i6.values({ val: "s" });
list.sort('val', { order: "desc" });
expect(list.items[0].values().val).to.be.equal("ö");
expect(list.items[1].values().val).to.be.equal("å");
expect(list.items[2].values().val).to.be.equal("ä");
expect(list.items[3].values().val).to.be.equal("s");
expect(list.items[4].values().val).to.be.equal("o");
expect(list.items[5].values().val).to.be.equal("a");
});
it('should handle case-insensitive by default', function() {
i1.values({ val: "e" });
i2.values({ val: "b" });
i4.values({ val: "F" });
i3.values({ val: "D" });
i5.values({ val: "A" });
i6.values({ val: "C" });
list.sort('val');
expect(list.items[0].values().val).to.be.equal("A");
expect(list.items[1].values().val).to.be.equal("b");
expect(list.items[2].values().val).to.be.equal("C");
expect(list.items[3].values().val).to.be.equal("D");
expect(list.items[4].values().val).to.be.equal("e");
expect(list.items[5].values().val).to.be.equal("F");
});
it('should disable insensitive', function() {
i1.values({ val: "e" });
i2.values({ val: "b" });
i4.values({ val: "F" });
i3.values({ val: "D" });
i5.values({ val: "A" });
i6.values({ val: "C" });
list.sort('val', { insensitive: false });
expect(list.items[0].values().val).to.be.equal("A");
expect(list.items[1].values().val).to.be.equal("C");
expect(list.items[2].values().val).to.be.equal("D");
expect(list.items[3].values().val).to.be.equal("F");
expect(list.items[4].values().val).to.be.equal("b");
expect(list.items[5].values().val).to.be.equal("e");
});
it('should sort dates', function() {
i1.values({ val: "10/12/2008" });
i2.values({ val: "10/11/2008" });
i3.values({ val: "10/11/2007" });
i4.values({ val: "10/12/2009" });
i5.values({ val: "4/01/2007" });
i6.values({ val: "10/12/2006" });
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("10/12/2006");
expect(list.items[1].values().val).to.be.equal("4/01/2007");
expect(list.items[2].values().val).to.be.equal("10/11/2007");
expect(list.items[3].values().val).to.be.equal("10/11/2008");
expect(list.items[4].values().val).to.be.equal("10/12/2008");
expect(list.items[5].values().val).to.be.equal("10/12/2009");
});
it('should sort file names', function() {
i1.values({ val: "car.mov" });
i2.values({ val: "01alpha.sgi" });
i3.values({ val: "001alpha.sgi" });
i4.values({ val: "my.string_41299.tif" });
i5.values({ val: "0003.zip" });
i6.values({ val: "0002.asp" });
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("0002.asp");
expect(list.items[1].values().val).to.be.equal("0003.zip");
expect(list.items[2].values().val).to.be.equal("001alpha.sgi");
expect(list.items[3].values().val).to.be.equal("01alpha.sgi");
expect(list.items[4].values().val).to.be.equal("car.mov");
expect(list.items[5].values().val).to.be.equal("my.string_41299.tif");
});
it('should sort floates', function() {
i1.values({ val: "10.0401" });
i2.values({ val: "10.022" });
i3.values({ val: "10.021999" });
i4.values({ val: "11.231" });
i5.values({ val: "0003.123" });
i6.values({ val: "09.2123" });
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("0003.123");
expect(list.items[1].values().val).to.be.equal("09.2123");
expect(list.items[2].values().val).to.be.equal("10.021999");
expect(list.items[3].values().val).to.be.equal("10.022");
expect(list.items[4].values().val).to.be.equal("10.0401");
expect(list.items[5].values().val).to.be.equal("11.231");
});
it('should sort IP addresses', function() {
i1.values({ val: "192.168.1.1" });
i2.values({ val: "192.168.0.100" });
i3.values({ val: "192.168.0.1" });
i4.values({ val: "192.168.1.3" });
i5.values({ val: "127.0.0.1" });
i6.values({ val: "192.168.1.2" });
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("127.0.0.1");
expect(list.items[1].values().val).to.be.equal("192.168.0.1");
expect(list.items[2].values().val).to.be.equal("192.168.0.100");
expect(list.items[3].values().val).to.be.equal("192.168.1.1");
expect(list.items[4].values().val).to.be.equal("192.168.1.2");
expect(list.items[5].values().val).to.be.equal("192.168.1.3");
});
it('should not break with weird values', function() {
i1.values({ val: undefined });
i2.values({ val: null });
i3.values({ val: 0 });
i4.values({ val: function() {} });
i5.values({ val: { foo: "bar" } });
expect(list.sort).withArgs('val').to.not.throwException();
expect(list.sort).withArgs('val').to.not.throwException();
expect(list.sort).withArgs('val').to.not.throwException();
expect(list.sort).withArgs('val').to.not.throwException();
expect(list.sort).withArgs('val').to.not.throwException();
expect(list.sort).withArgs('val').to.not.throwException();
});
/*
it('should show how random values are sorted', function() {
list.add({ id: '7', val: "" });
list.add({ id: '8', val: "" });
list.add({ id: '9', val: "" });
list.add({ id: '10', val: "" });
list.add({ id: '11', val: "" });
list.add({ id: '12', val: "" });
var i7 = list.get('id', '7')[0],
i8 = list.get('id', '8')[0],
i9 = list.get('id', '9')[0],
i10 = list.get('id', '10')[0],
i11 = list.get('id', '11')[0],
i12 = list.get('id', '12')[0];
i1.values({ val: undefined });
i2.values({ val: "" });
i3.values({ val: null });
i4.values({ val: "a" });
i5.values({ val: "0" });
i6.values({ val: true });
i7.values({ val: 0 });
i8.values({ val: "z" });
i9.values({ val: "!" });
i10.values({ val: "?" });
i11.values({ val: 100 });
i12.values({ val: false });
list.sort('val', { order: "asc" });
list.sort('val', { order: "desc" });
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("0");
expect(list.items[2].values().val).to.be.equal(0);
expect(list.items[3].values().val).to.be.equal(100);
expect(list.items[4].values().val).to.be.equal("!");
expect(list.items[5].values().val).to.be.equal("?");
expect(list.items[6].values().val).to.be.equal("a");
expect(list.items[7].values().val).to.be.equal(false);
expect(list.items[8].values().val).to.be.equal(null);
expect(list.items[9].values().val).to.be.equal(true);
expect(list.items[10].values().val).to.be.equal(undefined);
expect(list.items[11].values().val).to.be.equal("z");
});
it('should handle space and zero the same for desc and asc (random)', function() {
list.clear();
list.add({ val: "" });
list.add({ val: "0" });
list.add({ val: 0 });
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("0");
expect(list.items[2].values().val).to.be.equal(0);
list.sort('val', { order: "desc" });
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("0");
expect(list.items[2].values().val).to.be.equal(0);
list.sort('val', { order: "asc" });
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("0");
expect(list.items[2].values().val).to.be.equal(0);
});
*/
});
describe('Custom sort function', function() {
it('should use custom sort option', function() {
i1.values({ val: "" });
i2.values({ val: "" });
i3.values({ val: "" });
i4.values({ val: "" });
i5.values({ val: "" });
i6.values({ val: "" });
list.sort('val', {
sortFunction: function(itemA, itemB, options) {
options.desc = false;
return list.utils.naturalSort($(itemA.values()[options.valueName]).val(), $(itemB.values()[options.valueName]).val(), options);
}
});
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("");
expect(list.items[2].values().val).to.be.equal("");
expect(list.items[3].values().val).to.be.equal("");
expect(list.items[4].values().val).to.be.equal("");
expect(list.items[5].values().val).to.be.equal("");
});
it('should use default custom sort function', function() {
list.sortFunction = function(itemA, itemB, options) {
options.desc = false;
return list.utils.naturalSort($(itemA.values()[options.valueName]).val(), $(itemB.values()[options.valueName]).val(), options);
};
i1.values({ val: "" });
i2.values({ val: "" });
i3.values({ val: "" });
i4.values({ val: "" });
i5.values({ val: "" });
i6.values({ val: "" });
list.sort('val');
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("");
expect(list.items[2].values().val).to.be.equal("");
expect(list.items[3].values().val).to.be.equal("");
expect(list.items[4].values().val).to.be.equal("");
expect(list.items[5].values().val).to.be.equal("");
});
it('should use default custom sort function with options', function() {
list.sortFunction = function(itemA, itemB, options) {
options.desc = true;
return list.utils.naturalSort($(itemA.values()[options.valueName]).val(), $(itemB.values()[options.valueName]).val(), options);
};
i1.values({ val: "" });
i2.values({ val: "" });
i3.values({ val: "" });
i4.values({ val: "" });
i5.values({ val: "" });
i6.values({ val: "" });
list.sort('val', { order: "desc"});
expect(list.items[0].values().val).to.be.equal("");
expect(list.items[1].values().val).to.be.equal("");
expect(list.items[2].values().val).to.be.equal("");
expect(list.items[3].values().val).to.be.equal("");
expect(list.items[4].values().val).to.be.equal("");
expect(list.items[5].values().val).to.be.equal("");
});
});
});
list.js-1.2.0/test/test.trigger.js 0000664 0000000 0000000 00000000634 12664333731 0017051 0 ustar 00root root 0000000 0000000 describe('Trigger', function() {
var list;
before(function() {
list = fixture.list(['name', 'born'], fixture.all);
});
after(function() {
fixture.removeList();
});
describe('General', function() {
it('should be triggered by searchComplete', function(done) {
list.on('searchComplete', function() {
done();
});
list.trigger('searchComplete');
});
});
}); list.js-1.2.0/test/usage/ 0000775 0000000 0000000 00000000000 12664333731 0015173 5 ustar 00root root 0000000 0000000 list.js-1.2.0/test/usage/amd.html 0000664 0000000 0000000 00000001357 12664333731 0016630 0 ustar 00root root 0000000 0000000
-
Jonny Stromberg
1986
-
Jonas Arnklint
1985
-
Martina Elm
1986
-
Gustaf Lindqvist
1983
list.js-1.2.0/test/usage/boba.jpeg 0000664 0000000 0000000 00000006307 12664333731 0016753 0 ustar 00root root 0000000 0000000 JFIF
"" $(4,$&1'-=-157:::#+?D?8C49:7
7%%77777777777777777777777777777777777777777777777777 s \" 6 !1A"Qaq2#BRr3Cb $ !12"Aa# ? QZqgdXrt.]n5yr'ǰĦurA+*Jw Z &dHRUnBh<\J*[eaF{'H} I
+DAP
XI(
TnGަ;#^WPsZ@t9JM ta'0-gaM7hC;DMqWWt4\Q}8#o"
WQ,pICEv q.\`RRwRH@*P,ma
.4\:HBR'ʆq{39Ad!@@Gɩ+u6Tn&}3&>N={iuhLA!C~AOXeIˍ^X[eƖVnF cF5_g3Y6E8t6[ZNPKySHqJÈJd2S'euQEXB/m~:}6B
{Yg4t-É& JaP|Gnjϴ2`EV?]a}!NwO'EM\ɴ.%LX. h<SHp7lB\͗t6]# q'ЂAdzg>e[kv
RiK
26y4m`ז,ḉi]l6%F8槑3\qeۆPSs lÕ-fShNmi38) B@Ot}P]ۂ+yJR IzsM72d6+GB훶K#LvN[{x*J$VӞ*NwWMYVՂbZVt
R# ,PP$ā3]6m[X; K: ͫ}J ˘f&qPuRT^Q주28wXst͗QGq>S()ykIEXŎ` .ӡ%RwI11܉*r.'b8;!*nRT"yٚ1qF-4Ř>I7XF@eA)-G#?jvG$aksalV䧰ԙ靷q*OMKgl#}'{-Y;qscP\H`ɇm(5-^p#փ{VYXn"Ԕ_H'J؏PMw@"^uw.:F