Showing preview only (453K chars total). Download the full file or copy to clipboard to get everything.
Repository: javve/list.js
Branch: master
Commit: 44ae2396072a
Files: 117
Total size: 424.5 KB
Directory structure:
gitextract_q4nl4_qg/
├── .browserslistrc
├── .circleci/
│ └── config.yml
├── .codecov.yml
├── .github/
│ └── workflows/
│ └── ci.yml
├── .gitignore
├── .npmignore
├── .nvmrc
├── .prettierignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── Release.md
├── WISHLIST.md
├── __test__/
│ ├── add-get-remove.test.js
│ ├── buttons.test.js
│ ├── create.test.js
│ ├── defaults.test.js
│ ├── filter.test.js
│ ├── fixtures-fuzzysearch.js
│ ├── fixtures-pagination.js
│ ├── fixtures.js
│ ├── fuzzysearch.test.js
│ ├── item.test.js
│ ├── off.test.js
│ ├── on.test.js
│ ├── pagination.test.js
│ ├── parse.test.js
│ ├── re-index.test.js
│ ├── search-filter.test.js
│ ├── search.test.js
│ ├── show.test.js
│ ├── sort.test.js
│ ├── trigger.test.js
│ ├── usage/
│ │ ├── amd.html
│ │ ├── classic.html
│ │ ├── fuzzy-search-pagination.html
│ │ ├── main.js
│ │ ├── require.js
│ │ └── style.css
│ ├── utils.classes.test.js
│ └── utils.get-by-class.test.js
├── bower.json
├── dist/
│ └── list.js
├── docs/
│ ├── .bundle/
│ │ └── config
│ ├── .ruby-version
│ ├── CNAME
│ ├── Gemfile
│ ├── README.md
│ ├── _config.yml
│ ├── _data/
│ │ └── pkg.json
│ ├── _examples/
│ │ ├── add-get-remove.html
│ │ ├── data-attributes-custom-attributes.html
│ │ ├── existing-list-add.html
│ │ ├── existing-list.html
│ │ ├── fuzzy-search.html
│ │ ├── new-list.html
│ │ ├── pagination.html
│ │ └── table.html
│ ├── _includes/
│ │ ├── author.html
│ │ ├── carbon.html
│ │ ├── codepen.html
│ │ ├── examples/
│ │ │ └── annotated-example.html
│ │ ├── javascripts/
│ │ │ └── vendor/
│ │ │ ├── bootstrap/
│ │ │ │ ├── tab.js
│ │ │ │ ├── tooltip.js
│ │ │ │ └── transition.js
│ │ │ └── highlight.pack.js
│ │ └── menu.html
│ ├── _layouts/
│ │ └── default.html
│ ├── _sass/
│ │ ├── _base.scss
│ │ ├── _carbonads.scss
│ │ ├── _docs.scss
│ │ ├── _menu.scss
│ │ ├── _mixins.scss
│ │ ├── _normalize.scss
│ │ └── vendor/
│ │ └── highlight/
│ │ └── xcode.scss
│ ├── api.html
│ ├── assets/
│ │ ├── css/
│ │ │ └── style.scss
│ │ └── javascripts/
│ │ └── main.js
│ ├── docs/
│ │ ├── fuzzysearch.html
│ │ ├── index.html
│ │ ├── item-api.html
│ │ ├── pagination.html
│ │ ├── plugins/
│ │ │ ├── build.html
│ │ │ ├── fuzzysearch.html
│ │ │ ├── index.html
│ │ │ └── pagination.html
│ │ └── search-sort.html
│ ├── faq.html
│ ├── feed.xml
│ ├── index.html
│ └── overview/
│ ├── changelog.html
│ ├── contribute.html
│ ├── download.html
│ ├── index.html
│ └── press.html
├── package.json
├── prettier.config.js
├── src/
│ ├── add-async.js
│ ├── filter.js
│ ├── fuzzy-search.js
│ ├── index.js
│ ├── item.js
│ ├── pagination.js
│ ├── parse.js
│ ├── search.js
│ ├── sort.js
│ ├── templater.js
│ └── utils/
│ ├── classes.js
│ ├── events.js
│ ├── extend.js
│ ├── fuzzy.js
│ ├── get-attribute.js
│ ├── get-by-class.js
│ ├── index-of.js
│ ├── to-array.js
│ └── to-string.js
└── webpack.config.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .browserslistrc
================================================
ie 9
================================================
FILE: .circleci/config.yml
================================================
version: 2.1
orbs:
node: circleci/node@4.1.0
jobs:
test:
executor:
name: node/default
parameters:
os:
type: string
node-version:
type: string
steps:
- checkout
- node/install-packages
- run: npm test
- run:
name: code-coverage
command: 'bash <(curl -s https://codecov.io/bash)'
workflows:
build:
jobs:
- test:
matrix:
parameters:
os:
- docker
node-version:
- '6.17.1'
- '8.17.0'
- '10.23.1'
- '12.20.1'
- '14.15.4'
================================================
FILE: .codecov.yml
================================================
codecov:
branch: master
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '14.15.1'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
================================================
FILE: .gitignore
================================================
.DS_Store
node_modules
docs/_site
docs/.sass-cache
docs/.jekyll-metadata
coverage
docs/vendor
================================================
FILE: .npmignore
================================================
docs
__test__
.circleci
WISHLIST.md
webpack.config.js
Release.md
prettier.config.js
.prettierignore
.codecov.yml
.browserslistrc
================================================
FILE: .nvmrc
================================================
14.15.1
================================================
FILE: .prettierignore
================================================
*.min.js
================================================
FILE: CHANGELOG.md
================================================
# Changelog
### 2.3.1 - 2021-01-17
- - **[Improvement]** #708 Support restored for Node 6, 8, 10 and 12.
### 2.3.0 - 2020-11-25
- **[Feature]** #682 Multiple word search
- **[Feature]** #683 Debounced keyup handler in search
- **[Improvement]** #679 Faster search
- **[Website]** #684 Add more documentation for automagical search and sort elements
### 2.1.0 - 2020-11-21
- **[Feature]** #634 Add item template function
- **[Feature]** #591 Support adding custom pagination item
- **[Bugfix]** #667 Fix `getAttribute` fallback method
- **[Bugfix]** #636 Aviod strange ie11 bug
- **[Bugfix]** #570 Don't empty original value array when adding items async
- **[Misc]** #637 Reuse iteration indices
### 2.0.0 - 2020-11-21 - Winter cleanup 🧹
- **[Breaking]** Drop support for IE6-8
- **[Misc]** Update dev dependencies to latest version: Webpack 3.12.0 -> 5.6.0, jest 23.3 -> 26.6.3, jquery 3.3.1 -> 3.5.1, Removed: jshint jshint-loader
- **[Misc]** Replace uglify-js with terser
- **[Misc]** Update Node for dev from 6.15 to 14.15.1
- **[Misc]** Prettier on everything
- **[Misc]** Make release script simpler
- **[Misc]** Rename History.md to CHANGELOG.md
- **[Misc]** Use `babal-loader` with `@babel/preset-env` for supporting IE9-11
- **[Misc]** Add source-maps to `/dist`
- **[Misc]** Added WISHLIST.md for feature requests to allow cleanup of issue list.
- **[Misc]** Update CircleCI from 1.0 to 2.0
- **[Website]** Update Jekyll to remove security warnings
- **[Website]** Fix all examples (sorry that they we're broken)
- **[Website]** Use https instead of http for listjs.com
- **[Website]** Update Contribute guidelines [See commit →](https://github.com/javve/list.js/commit/6242496de2ac5c07903fb1590a5cb5129f0887a7)
- **[Bugfix]** Use one event listener per pagination and select page via data attributes
[See commit →](https://github.com/javve/list.js/commit/7610c59039f3b39f52175cd1a200e935664869e8)
- **[Bugfix]** Don't break pagination if page=0
[See commit →](https://github.com/javve/list.js/commit/b3db0de731d436422e016b5e17f7ceab5941cd5d)
[See commit →](https://github.com/javve/list.js/commit/725bc188d7ba72c7d234bda1e09fc50b40661310)
### 2017-01-29 v1.5.0
- **[Feature]** Bundle fuzzySearch and pagination plugins into List.js
[See commit →](https://github.com/javve/list.js/commit/2f5322fd139ee6f30cef3bb5e15d382ff29f9489)
- **[Misc]** Switch from Grunt to Webpack and from Mocha to Jest
[See commit →](https://github.com/javve/list.js/commit/8376ef01b1da4b6e60a7457d628d97a803a82e14)
### 2017-01-19 v1.4.1
- **[Bugfix]** Move string-natural-compare to dependencies instead of devDependencies
[See commit →](https://github.com/javve/list.js/commit/c17162b26fd5093d3ddde01e11a3f748310d993c)
### 2017-01-15 v1.4.0
- **[Bugfix/Feature]** Change natural-sort library to support custom alphabets
and thereby handle JavaScripts unicode bugs like sorting ÅÄÖ in Swedish wrong.
[See commit →](https://github.com/javve/list.js/commit/81e1386bed88d1f932e729feca2b3649e489bdfe)
### 2016-10-23 v1.3.0
- **[Bugfix]** Make mkdir in build script OS agnostic
[See commit →](https://github.com/javve/list.js/commit/ba387125efddd7f5f4f8360bce516ae740cb5ae5)
- **[Bugfix]** Make it possible to reset search columns
[See commit →](https://github.com/javve/list.js/commit/37edc1b98bf63a684d633f29e2f52106c21eaf7d)
- **[Bugfix]** Allow empty list without template.
[See commit →](https://github.com/javve/list.js/commit/95329b945c64c0ad0693df120ef00547eac9b029)
- **[Bugfix]** Make it possible to use <tr> as string template
[See commit →](https://github.com/javve/list.js/commit/38583e097cb75e369779b46c6129e1b8b8324f24)
- **[Misc]** Update NaturalSort to 0.8.1
[See commit →](https://github.com/javve/list.js/commit/42d3db491801677c63238d5db3e0e9257087999a)
- **[Misc]** Use local Browserify
[See commit →](https://github.com/javve/list.js/commit/83f6502dcea428fa2de2513d19ac71f82905ecb8)
- **[Misc]** Add version to start of minified file
[See commit →](https://github.com/javve/list.js/commit/79daff8da51aa047aae5d31e0af12cb30b395048)
- **[Misc]** Switch to GitHub pages for listjs.com
[See commit →](https://github.com/javve/list.js/commit/1af94012de89fd6bcf8446c31305ad517507c44b)
### 2016-02-27: v1.2.0
It's been two years since the last update of List.js. That is absolutely not ok
and I'm very sorry that it has taken so long. I promise I'll do better in the future!
Anyways, this release introduces a bunch of bug fixes and improvements, but most
importantly: List.js now has support for data attributes PLUS all other attributes.
[See an example]() and [read the docs](https://www.listjs.com/docs#example-6).
Another noteworthy update is that I've left Component and moved back all utils
to the core lib. Instead I'm using Browserify as module handler.
I hope you'll like this update!
- **[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](https://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 <tr> 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 <a href="https://twitter.github.com/bootstrap/components.html#pagination">Twitter Bootstraps pagination</a>.
- **[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 <a href="https://github.com/component/component">Component</a>
- **[Misc]** Moved the website into another repo called <a href="https://github.com/javve/list-website">list-website</a>
- **[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: <a href="https://github.com/javve/list.pagination.js">github.com/javve/list.pagination.js</a> and <a href="https://github.com/javve/list.fuzzysearch.js">github.com/javve/list.fuzzysearch.js</a>
- **[Change]** Plugin initiation have changed. See <a href="/docs/plugins">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)`</li>
### 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
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2011-2018 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.
================================================
FILE: README.md
================================================
# 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)
[](https://badge.fury.io/js/list.js)
[](https://circleci.com/gh/javve/list.js/tree/master)
[](https://codecov.io/gh/javve/list.js)
[](https://www.jsdelivr.com/package/npm/list.js)
### 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. `<div>`,`<ul>`,`<table>`, etc.
- Search [Read more ›](https://listjs.com/docs/list-api#search)
- Sort [Read more ›](https://listjs.com/docs/list-api#sort)
- Filter [Read more ›](https://listjs.com/docs/list-api#filter)
- Simple templating system that adds possibility to add, edit, remove items [Read more ›](https://listjs.com/docs/list-api#add)
- Support for Chrome, Safari, Firefox, IE9+
### Download / Install
##### Via NPM
```
npm install list.js
```
##### Via Bower
```
bower install list.js
```
##### Via CDNJS
```html
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/2.3.1/list.min.js"></script>
```
##### Via Direct Download
- [Compressed list.js](https://raw.githubusercontent.com/javve/list.js/v2.3.1/dist/list.min.js)
- [Uncompressed list.js](https://raw.githubusercontent.com/javve/list.js/v2.3.1/dist/list.js)
### Questions / How to?
https://stackoverflow.com/questions/tagged/list.js
### Demo / Examples
- [Existing list](https://listjs.com/examples/existing-list)
- [Existing list + add](https://listjs.com/examples/existing-list-add)
- [New list](https://listjs.com/examples/new-list)
- [Add, get, remove](https://listjs.com/examples/add-get-remove)
- [Fuzzy search](https://listjs.com/examples/fuzzy-search)
- [Pagination](https://listjs.com/examples/pagination)
- [Search in specific column](https://codepen.io/javve/pen/GpZpow)
- [Filter in range](https://codepen.io/javve/pen/wKGKWL)
- [Show message filter/search results in 0 items](https://codepen.io/javve/pen/VvavzG)
- [Only show list after search/filter](https://codepen.io/javve/pen/YyqyRg)
## Documentation
- [Getting started](https://listjs.com/docs)
- [Options](https://listjs.com/docs/options)
- [List API](https://listjs.com/docs/list-api)
- [Item API](https://listjs.com/docs/item-api)
- [Changelog](https://github.com/javve/list.js/blob/master/CHANGELOG.md)
### Thanks to [all lovely contributors](https://github.com/javve/list.js/graphs/contributors)! Want to join them?
- Read more at [listjs.com/overview/contribute](https://listjs.com/overview/contribute)
### Creator
| | Jonny Strömberg [@javve](https://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) 2011-2020 Jonny Strömberg <[jonny.stromberg@gmail.com](mailto:jonny.stromberg@gmail.com)>
[javve.com](https://javve.com)
================================================
FILE: Release.md
================================================
# RELEASE
1. `npm version patch|minor|major` (depending on what kind of release it is)
2. `npm publish`
3. Update links in README.md with new version number
================================================
FILE: WISHLIST.md
================================================
# Wishlist
- Add tests for custom event handlers. 27e2d6fdeee7090eb1342a108013db898fc29b96
- Regex in search https://github.com/javve/list.js/issues/371
- Keep original order? + know
- Automatically add item in the right place if sort is active
- How to handle arrays?
- [Implement debouncing in search?](https://github.com/javve/list.js/issues/621)
- 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
- Add .remove() method to remove all listeners etc.
- Example of more advanced filtering
- Example with multiple lists
- Multiple filter functionality
- Activ search term, sort order, filter, etc
- [Smarter pagination window](https://github.com/javve/list.js/issues/599)
- [Handle input checkboxes in list](https://github.com/javve/list.js/pull/630)
- Use query-selector to support more than just ID for item and list initiation
# Known bugs
Pagination does not respect .show(i, page)
================================================
FILE: __test__/add-get-remove.test.js
================================================
const fixture = require('./fixtures')
describe('Add, get, remove', function () {
var list
beforeAll(function () {
list = fixture.list(['name'], [{ name: 'Jonny' }])
})
afterAll(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).toEqual(2)
})
it('should add two items', function () {
list.add([{ name: 'Martina' }, { name: 'Angelica' }])
expect(list.items.length).toEqual(3)
})
it('should add async items', function (done) {
var itemsToAdd = [
{ 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' },
]
list.add(itemsToAdd, function (items) {
expect(list.items.length).toEqual(91)
expect(items.length).toEqual(90)
expect(itemsToAdd.length).toEqual(90)
done()
})
})
it('should add async items to empty list', function (done) {
list.clear()
list.add([{ name: 'Sven' }], function () {
expect(list.items.length).toEqual(1)
done()
})
})
})
describe('Get', function () {
it('should return array with one item', function () {
var items = list.get('name', 'Jonny')
expect(items[0].values().name).toEqual('Jonny')
})
it('should return empty array', function () {
var items = list.get('name', 'jonny')
expect(items.length).toBe(0)
})
it('should return two items', function () {
list.add({ name: 'Jonny' })
var items = list.get('name', 'Jonny')
expect(items.length).toEqual(2)
expect(items[0].values().name).toEqual('Jonny')
expect(items[1].values().name).toEqual('Jonny')
})
})
describe('Remove', function () {
it('should remove one item', function () {
list.add({ name: 'Jonas' })
expect(list.items.length).toEqual(2)
var count = list.remove('name', 'Jonas')
expect(count).toEqual(1)
expect(list.items.length).toEqual(1)
})
it('should not remove anything due to case sensitivity', function () {
var count = list.remove('name', 'jonny')
expect(count).toBe(0)
expect(list.items.length).toEqual(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).toBe(1)
expect(list.items.length).toEqual(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).toEqual(10)
var count = list.remove('name', 'Jonny')
expect(count).toEqual(8)
expect(list.items.length).toEqual(2)
})
})
})
================================================
FILE: __test__/buttons.test.js
================================================
const $ = require('jquery'),
List = require('../src/index')
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(
$(
'<div id="parse-list">\
<input class="search" />\
<span class="sort" id="sort-name" data-sort="name">Sort name</span>\
<span class="sort" id="sort-name-asc" data-sort="name" data-order="asc">Sort name asc</span>\
<span class="sort" id="sort-name-desc" data-sort="name" data-order="desc">Sort name desc</span>\
<div class="list">\
<div><span class="name">Jonny</span><span class="born">1986</span></div>\
<div><span class="name">Jocke</span><span class="born">1985</span></div>\
</div>\
</div>'
)
)
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) {
var sortRun = 0
list.on('sortComplete', function () {
sortRun++
if (sortRun == 1) {
expect($('#sort-name').hasClass('asc')).toBe(true)
expect($('#sort-name').hasClass('desc')).toBe(false)
setTimeout(function () {
fireClick($('#sort-name')[0])
}, 50)
} else if (sortRun == 2) {
expect($('#sort-name').hasClass('asc')).toBe(false)
expect($('#sort-name').hasClass('desc')).toBe(true)
setTimeout(function () {
fireClick($('#sort-name')[0])
}, 50)
} else if (sortRun == 3) {
expect($('#sort-name').hasClass('asc')).toBe(true)
expect($('#sort-name').hasClass('desc')).toBe(false)
done()
}
})
expect($('#sort-name').hasClass('asc')).toBe(false)
expect($('#sort-name').hasClass('desc')).toBe(false)
fireClick($('#sort-name')[0])
})
it('should sort with predefined order', function (done) {
var sortRun = 0
list.on('sortComplete', function () {
sortRun++
if (sortRun == 1) {
expect($('#sort-name').hasClass('asc')).toBe(true)
expect($('#sort-name').hasClass('desc')).toBe(false)
expect($('#sort-name-asc').hasClass('asc')).toBe(true)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(false)
setTimeout(function () {
fireClick($('#sort-name-asc')[0])
}, 50)
} else if (sortRun == 2) {
expect($('#sort-name').hasClass('asc')).toBe(true)
expect($('#sort-name').hasClass('desc')).toBe(false)
expect($('#sort-name-asc').hasClass('asc')).toBe(true)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(false)
setTimeout(function () {
fireClick($('#sort-name-asc')[0])
}, 50)
} else if (sortRun == 3) {
expect($('#sort-name').hasClass('asc')).toBe(true)
expect($('#sort-name').hasClass('desc')).toBe(false)
expect($('#sort-name-asc').hasClass('asc')).toBe(true)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(false)
setTimeout(function () {
fireClick($('#sort-name-desc')[0])
}, 50)
} else if (sortRun == 4) {
expect($('#sort-name').hasClass('asc')).toBe(false)
expect($('#sort-name').hasClass('desc')).toBe(true)
expect($('#sort-name-asc').hasClass('asc')).toBe(false)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(true)
setTimeout(function () {
fireClick($('#sort-name-desc')[0])
}, 50)
} else if (sortRun == 5) {
expect($('#sort-name').hasClass('asc')).toBe(false)
expect($('#sort-name').hasClass('desc')).toBe(true)
expect($('#sort-name-asc').hasClass('asc')).toBe(false)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(true)
done()
}
})
expect($('#sort-name').hasClass('asc')).toBe(false)
expect($('#sort-name').hasClass('desc')).toBe(false)
expect($('#sort-name-asc').hasClass('asc')).toBe(false)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(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')).toBe(true)
expect($('#sort-name').hasClass('desc')).toBe(false)
expect($('#sort-name-asc').hasClass('asc')).toBe(true)
expect($('#sort-name-asc').hasClass('desc')).toBe(false)
expect($('#sort-name-desc').hasClass('asc')).toBe(false)
expect($('#sort-name-desc').hasClass('desc')).toBe(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])
})
})
})
================================================
FILE: __test__/create.test.js
================================================
const $ = require('jquery'),
List = require('../src/index')
describe('Create', function () {
describe('With HTML items', function () {
var listEl = $(
'<div id="list">\
<ul class="list">\
<li><span class="name">Jonny</span></li>\
</ul>\
</div>'
)
$(document.body).append(listEl)
var list = new List('list', { valueNames: ['name'] })
it('should contain one item', function () {
expect(list.items.length).toEqual(1)
expect(listEl.find('li').length).toEqual(1)
})
it('should contain two items', function () {
list.add({ name: 'Jonas' })
expect(list.items.length).toEqual(2)
expect(listEl.find('li').length).toEqual(2)
})
listEl.remove()
})
describe('With and element instead of id', function () {
var listEl = $(
'<div id="list">\
<ul class="list">\
<li><span class="name">Jonny</span></li>\
</ul>\
</div>'
)
$(document.body).append(listEl)
var el = document.getElementById('list')
var list = new List(el, { valueNames: ['name'] })
it('should contain one item', function () {
expect(list.items.length).toEqual(1)
expect(listEl.find('li').length).toEqual(1)
})
listEl.remove()
})
describe('Without items and with string template', function () {
var listEl = $('<div id="list">\
<ul class="list"></ul>\
</div>')
$(document.body).append(listEl)
var list = new List(
'list',
{
valueNames: ['name'],
item: '<li><span class="name"></span></li>',
},
[{ name: 'Jonny' }]
)
it('should contain one item', function () {
expect(list.items.length).toEqual(1)
expect(listEl.find('li').length).toEqual(1)
})
it('should contain two items', function () {
list.add({ name: 'Jonas' })
expect(list.items.length).toEqual(2)
expect(listEl.find('li').length).toEqual(2)
})
listEl.remove()
})
describe('Without items and with string template for table', function () {
var listEl = $('<div id="list">\
<table class="list"></table>\
</div>')
$(document.body).append(listEl)
var list = new List(
'list',
{
valueNames: ['name'],
item: '<tr><span class="name"></span></tr>',
},
[{ name: 'Jonny' }]
)
it('should contain one item', function () {
expect(list.items.length).toEqual(1)
expect(listEl.find('tr').length).toEqual(1)
})
it('should contain two items', function () {
list.add({ name: 'Jonas' })
expect(list.items.length).toEqual(2)
expect(listEl.find('tr').length).toEqual(2)
})
listEl.remove()
})
describe('Without items and with template function', function () {
var listEl = $('<div id="list">\
<ul class="list"></ul>\
</div>')
$(document.body).append(listEl)
var list = new List(
'list',
{
valueNames: ['name'],
item: function (values) {
return `<li data-template-fn-${values.name.toLowerCase()}><span class="name"></span></li>`
},
},
[{ name: 'Jonny' }]
)
it('should contain one item', function () {
expect(list.items.length).toEqual(1)
expect(listEl.find('li').length).toEqual(1)
})
it('should contain two items', function () {
list.add({ name: 'Jonas' })
expect(list.items.length).toEqual(2)
expect(listEl.find('li').length).toEqual(2)
})
it('should get values from items', function () {
list.add({ name: 'Egon' })
expect(listEl.find('li[data-template-fn-egon]').length).toEqual(1)
})
listEl.remove()
})
describe('without items and or template', function () {
it('should throw error on init', function () {
var listEl = $('<div id="list">\
<ul class="list"></ul>\
</div>')
$(document.body).append(listEl)
expect(function () {
var list = new List('list', {
valueNames: ['name'],
})
}).toThrow()
listEl.remove()
})
})
describe('Without items and with HTML template', function () {
var listEl = $('<div id="list">\
<ul class="list"></ul>\
</div>')
var templateEl = $('<li id="template-item"><span class="name"></span></li>')
$(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).toEqual(1)
expect(listEl.find('li').length).toEqual(1)
})
it('should contain two items', function () {
list.add({ name: 'Jonas' })
expect(list.items.length).toEqual(2)
expect(listEl.find('li').length).toEqual(2)
})
listEl.remove()
templateEl.remove()
})
describe('Asyn index with existing list', function () {
var listEl = $(
'<div id="list">\
<ul class="list">\
<li><span class="name">Jonny</span></li><li><span class="name">Sven</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
<li><span class="name">Anna</span></li><li><span class="name">Lisa</span></li>\
<li><span class="name">Egon</span></li><li><span class="name">Frida</span></li>\
<li><span class="name">Maj-britt</span></li><li><span class="name">Fredrik</span></li>\
<li><span class="name">Torbjorn</span></li><li><span class="name">Lolzor</span></li>\
<li><span class="name">Sandra</span></li><li><span class="name">Gottfrid</span></li>\
<li><span class="name">Tobias</span></li><li><span class="name">Martina</span></li>\
<li><span class="name">Johannes</span></li><li><span class="name">Ted</span></li>\
<li><span class="name">Malin</span></li><li><span class="name">Filippa</span></li>\
<li><span class="name">Imma</span></li><li><span class="name">Hasse</span></li>\
<li><span class="name">Robert</span></li><li><span class="name">Mona</span></li>\
</ul>\
</div>'
)
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').length).toEqual(162)
listEl.remove()
done()
},
})
})
})
})
================================================
FILE: __test__/defaults.test.js
================================================
const $ = require('jquery'),
fixture = require('./fixtures')
describe('Defaults', function () {
var list
beforeAll(function () {
list = fixture.list(['name'], [{ name: 'Jonny' }])
})
afterAll(function () {
fixture.removeList()
})
it('should have all default attributes', function () {
expect(list.items).toBeInstanceOf(Array)
expect(list.visibleItems).toBeInstanceOf(Array)
expect(list.matchingItems).toBeInstanceOf(Array)
expect(list.handlers.updated).toBeInstanceOf(Array)
expect(list.handlers.searchStart).toBeInstanceOf(Array)
expect(list.handlers.searchComplete).toBeInstanceOf(Array)
expect(list.handlers.sortStart).toBeInstanceOf(Array)
expect(list.handlers.sortComplete).toBeInstanceOf(Array)
expect(list.handlers.filterStart).toBeInstanceOf(Array)
expect(list.handlers.filterComplete).toBeInstanceOf(Array)
expect(list.searched).toBe(false)
expect(list.filtered).toBe(false)
expect(list.i).toEqual(1)
expect(list.page).toEqual(10000)
expect(list.listClass).toEqual('list')
expect(list.sortClass).toEqual('sort')
expect(list.searchClass).toEqual('search')
})
it('should have the right elements', function () {
expect(list.list).toEqual($('.list')[0])
expect(list.listContainer).toEqual($('#list')[0])
})
it('should have all default methods', function () {
expect(list.add).toBeInstanceOf(Function)
expect(list.remove).toBeInstanceOf(Function)
expect(list.get).toBeInstanceOf(Function)
expect(list.sort).toBeInstanceOf(Function)
expect(list.search).toBeInstanceOf(Function)
expect(list.clear).toBeInstanceOf(Function)
expect(list.filter).toBeInstanceOf(Function)
expect(list.size).toBeInstanceOf(Function)
expect(list.show).toBeInstanceOf(Function)
expect(list.update).toBeInstanceOf(Function)
expect(list.on).toBeInstanceOf(Function)
})
it('should have all helper methods', function () {
expect(list.utils.classes).toBeInstanceOf(Function)
expect(list.utils.getAttribute).toBeInstanceOf(Function)
expect(list.utils.getByClass).toBeInstanceOf(Function)
expect(list.utils.naturalSort).toBeInstanceOf(Function)
expect(list.utils.events.bind).toBeInstanceOf(Function)
expect(list.utils.events.unbind).toBeInstanceOf(Function)
expect(list.utils.extend).toBeInstanceOf(Function)
expect(list.utils.indexOf).toBeInstanceOf(Function)
expect(list.utils.toString).toBeInstanceOf(Function)
})
})
================================================
FILE: __test__/filter.test.js
================================================
const fixture = require('./fixtures')
describe('Filter', function () {
var list, jonny, martina, angelica, sebastian, imma, hasse
beforeAll(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]
})
afterAll(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).toEqual(1)
expect(result[0]).toEqual(sebastian)
})
it('should return everyone born 1986', function () {
var result = list.filter(function (item) {
return item.values().born == 1986
})
expect(result.length).toEqual(3)
for (var i = 0; i < result.length; i++) {
expect(result[i].values().born).toEqual('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).toEqual(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).toEqual(2)
expect(list.visibleItems.length).toEqual(2)
expect(list.matchingItems.length).toEqual(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()).toBe(true)
expect(jonny.filtered).toBe(true)
expect(jonny.visible()).toBe(true)
})
it('should match martina', function () {
expect(martina.matching()).toBe(true)
expect(martina.filtered).toBe(true)
expect(martina.visible()).toBe(true)
})
it('should match but not show angelica', function () {
expect(angelica.matching()).toBe(true)
expect(angelica.filtered).toBe(true)
expect(angelica.visible()).toBe(false)
})
it('should match but not show sebastian', function () {
expect(sebastian.matching()).toBe(true)
expect(sebastian.filtered).toBe(true)
expect(sebastian.visible()).toBe(false)
})
it('should not match imma', function () {
expect(imma.matching()).toBe(false)
expect(imma.filtered).toBe(false)
expect(imma.visible()).toBe(false)
})
it('should not match hasse', function () {
expect(hasse.matching()).toBe(false)
expect(hasse.filtered).toBe(false)
expect(hasse.visible()).toBe(false)
})
})
})
})
================================================
FILE: __test__/fixtures-fuzzysearch.js
================================================
const $ = require('jquery')
var fixtureFuzzysearch = {
list: function (valueNames) {
var listHtml = $('<div id="list-fuzzy-search"><input class="fuzzy-search" /><ul class="list"></ul></div>'),
item = ''
item = '<li>'
for (var i = 0; i < valueNames.length; i++) {
item += '<span class="' + valueNames[i] + '"</span>'
}
item += '</li>'
$(document.body).append(listHtml)
return item
},
removeList: function () {
$('#list-fuzzy-search').remove()
},
i1: { name: 'Guybrush Threepwood' },
i2: { name: 'Manny Calavera' },
i3: { name: 'Bernard Bernoulli' },
i4: { name: 'LeChuck' },
i5: { name: 'Elaine Marley-Threepwood' },
i6: { name: 'Purple Tentacle' },
i7: { name: 'Adrian Ripburger' },
i8: { name: 'Bobbin Threadbare' },
i9: { name: 'Murray the Demonic Skull' },
i10: { name: 'Zak McKracken' },
}
fixtureFuzzysearch.all = [
fixtureFuzzysearch.i1,
fixtureFuzzysearch.i2,
fixtureFuzzysearch.i3,
fixtureFuzzysearch.i4,
fixtureFuzzysearch.i5,
fixtureFuzzysearch.i6,
fixtureFuzzysearch.i7,
fixtureFuzzysearch.i8,
fixtureFuzzysearch.i9,
fixtureFuzzysearch.i10,
]
module.exports = fixtureFuzzysearch
================================================
FILE: __test__/fixtures-pagination.js
================================================
const $ = require('jquery')
var fixturePagination = {
list: function (valueNames) {
var listHtml = $('<div id="list-pagination"><ul class="list"></ul><ul class="pagination"></ul></div>'),
item = ''
item = '<li>'
for (var i = 0; i < valueNames.length; i++) {
item += '<span class="' + valueNames[i] + '"</span>'
}
item += '</li>'
$(document.body).append(listHtml)
return item
},
removeList: function () {
$('#list-pagination').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',
},
fredrik: {
name: 'Fredrik Martinsson',
born: '1987',
},
jonas: {
name: 'Jonas Arnklint',
born: '1987',
},
egon: {
name: 'Egon Östgren',
born: '1983',
},
lars: {
name: 'Lars Larsson',
born: '1992',
},
bertil: {
name: 'Bertil Cool',
born: '1943',
},
ture: {
name: 'Ture Tur',
born: '1965',
},
anders: {
name: 'Anders',
born: '1987',
},
anna: {
name: 'Anna',
born: '1987',
},
matilda: {
name: 'Matilda',
born: '1983',
},
li: {
name: 'Li',
born: '1992',
},
asa: {
name: 'Åsa',
born: '1943',
},
gun: {
name: 'Gun',
born: '1965',
},
}
fixturePagination.all = [
fixturePagination.jonny,
fixturePagination.martina,
fixturePagination.angelica,
fixturePagination.sebastian,
fixturePagination.imma,
fixturePagination.hasse,
fixturePagination.fredrik,
fixturePagination.jonas,
fixturePagination.egon,
fixturePagination.lars,
fixturePagination.bertil,
fixturePagination.ture,
fixturePagination.anders,
fixturePagination.anna,
fixturePagination.matilda,
fixturePagination.li,
fixturePagination.asa,
fixturePagination.gun,
]
module.exports = fixturePagination
================================================
FILE: __test__/fixtures.js
================================================
const $ = require('jquery'),
List = require('../src/index')
var fixture = {
list: function (valueNames, items) {
var listHtml = $('<div id="list"><ul class="list"></ul></div>'),
item = ''
item = '<li>'
for (var i = 0; i < valueNames.length; i++) {
item += '<span class="' + valueNames[i] + '"</span>'
}
item += '</li>'
$(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]
module.exports = fixture
================================================
FILE: __test__/fuzzysearch.test.js
================================================
const $ = require('jquery'),
fixtureFuzzysearch = require('./fixtures-fuzzysearch'),
List = require('../src/index')
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? :)
}
}
describe('Fuzzy Search', function () {
var list, itemHTML, pagination
beforeEach(function () {
itemHTML = fixtureFuzzysearch.list(['name', 'born'])
list = new List(
'list-fuzzy-search',
{
valueNames: ['name', 'born'],
item: itemHTML,
},
fixtureFuzzysearch.all
)
})
afterEach(function () {
fixtureFuzzysearch.removeList()
})
it('should have default attribute', function () {
expect(list.fuzzySearch).toBeInstanceOf(Function)
})
it('should find result', function () {
list.fuzzySearch('guybrush')
expect(list.matchingItems.length).toBe(1)
})
it('should find result', function () {
list.fuzzySearch('g thre')
expect(list.matchingItems.length).toBe(1)
})
it('should find result', function () {
list.fuzzySearch('thre')
expect(list.matchingItems.length).toBe(4)
})
describe('Search field', function () {
it('should trigger searchStart', function (done) {
list.on('searchStart', function () {
done()
})
$('#list-fuzzy-search .fuzzy-search').val('angelica')
fireKeyup($('#list-fuzzy-search .fuzzy-search')[0])
})
it('should trigger searchComplete', function (done) {
list.on('searchComplete', function () {
done()
})
$('#list-fuzzy-search .fuzzy-search').val('angelica')
fireKeyup($('#list-fuzzy-search .fuzzy-search')[0])
})
})
})
================================================
FILE: __test__/item.test.js
================================================
const $ = require('jquery'),
fixture = require('./fixtures')
describe('Item', function () {
var list, item
beforeAll(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)
})
afterAll(function () {
fixture.removeList()
})
describe('Defaults', function () {
it('should have all default attributes', function () {
expect(item.found).toBe(false)
expect(item.filtered).toBe(false)
})
it('should have the right elements', function () {
expect(item.elm).toEqual($('#list li')[0])
})
it('should have all default methods', function () {
expect(item.hide).toBeInstanceOf(Function)
expect(item.show).toBeInstanceOf(Function)
expect(item.values).toBeInstanceOf(Function)
expect(item.matching).toBeInstanceOf(Function)
expect(item.visible).toBeInstanceOf(Function)
})
})
describe('Values()', function () {
it('should have the right values', function () {
expect(item.values()).toEqual({
name: 'Jonny',
born: '1986',
doin: 'Living the dream',
})
})
it('should be able to change one value', function () {
expect(item.values().name).toBe('Jonny')
item.values({ name: 'Egon' })
expect(item.values().name).toBe('Egon')
})
it('should be able to change many value', function () {
expect(item.values()).toEqual({
name: 'Egon',
born: '1986',
doin: 'Living the dream',
})
item.values({
name: 'Sven',
born: '1801',
doin: 'Is dead',
})
expect(item.values()).toEqual({
name: 'Sven',
born: '1801',
doin: 'Is dead',
})
})
})
describe('Hide, show, visible', function () {
it('should be hidden', function () {
expect($('#list li').length).toEqual(1)
item.hide()
expect(item.visible()).toBe(false)
expect($('#list li').length).toEqual(0)
})
it('should be visible', function () {
item.hide()
expect($('#list li').length).toEqual(0)
item.show()
expect(item.visible()).toBe(true)
expect($('#list li').length).toEqual(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()).toBe(false)
expect(item.found).toBe(false)
expect(item.filtered).toBe(false)
expect(item.visible()).toBe(false)
})
it('should be visble, match and found but not filterd', function () {
var result = list.search('Sven')
expect(item.matching()).toBe(true)
expect(item.found).toBe(true)
expect(item.filtered).toBe(false)
expect(item.visible()).toBe(true)
})
it('reset: should be visible and matching but not found or filtered', function () {
list.search()
expect(item.matching()).toBe(true)
expect(item.found).toBe(false)
expect(item.filtered).toBe(false)
expect(item.visible()).toBe(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()).toBe(false)
expect(item.found).toBe(false)
expect(item.filtered).toBe(false)
expect(item.visible()).toBe(false)
})
it('should be visble, match and filtered but not found', function () {
list.filter(function (item) {
return item.values().name == 'Sven'
})
expect(item.matching()).toBe(true)
expect(item.found).toBe(false)
expect(item.filtered).toBe(true)
expect(item.visible()).toBe(true)
})
it('reset: should be visble and match but not filtered or found', function () {
list.filter()
expect(item.matching()).toBe(true)
expect(item.found).toBe(false)
expect(item.filtered).toBe(false)
expect(item.visible()).toBe(true)
})
})
})
fixture.removeList()
})
================================================
FILE: __test__/off.test.js
================================================
const fixture = require('./fixtures')
describe('Off', function () {
var list
beforeAll(function () {
list = fixture.list(['name', 'born'], fixture.all)
})
afterAll(function () {
fixture.removeList()
})
describe('General', function () {
it('should be remove added handler', function (done) {
var updated = function (list) {
expect(list.handlers.updated.length).toEqual(1)
list.off('updated', updated)
expect(list.handlers.updated.length).toEqual(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).toEqual(3)
list.off('searchComplete', function () {})
list.off('searchComplete', searchComplete)
expect(list.handlers.searchComplete.length).toEqual(2)
done()
}
list.on('searchComplete', function () {})
list.on('searchComplete', searchComplete)
list.on('searchComplete', function () {})
list.search('jonny')
})
})
})
================================================
FILE: __test__/on.test.js
================================================
const fixture = require('./fixtures')
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
})
})
})
})
================================================
FILE: __test__/pagination.test.js
================================================
const $ = require('jquery'),
fixturePagination = require('./fixtures-pagination'),
List = require('../src/index')
describe('Pagination', function () {
describe('Default settings, innerWindow: 2, outerWindow: 0, left: 0, right: 0', function () {
var list, itemHTML, pagination
beforeAll(function () {
itemHTML = fixturePagination.list(['name'])
list = new List(
'list-pagination',
{
valueNames: ['name'],
item: itemHTML,
page: 2,
pagination: true,
},
fixturePagination.all
)
pagination = $('.pagination')
})
afterAll(function () {
fixturePagination.removeList()
})
it('should have default settings', function () {
expect(pagination.find('a').length).toEqual(4)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('3')
expect(pagination.find('a').get(3).innerHTML).toEqual('...')
expect(pagination.find('a').get(4)).toEqual(undefined)
})
it('should show same pages for show(7,2) and show(8,2)', function () {
list.show(7, 2)
expect(pagination.find('a').length).toEqual(7)
expect(pagination.find('a').get(0).innerHTML).toEqual('...')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('3')
expect(pagination.find('a').get(3).innerHTML).toEqual('4')
expect(pagination.find('a').get(4).innerHTML).toEqual('5')
expect(pagination.find('a').get(5).innerHTML).toEqual('6')
expect(pagination.find('a').get(6).innerHTML).toEqual('...')
expect(pagination.find('a').get(7)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(false)
})
it('should show same pages for show(7,2) and show(8,2)', function () {
list.show(8, 2)
expect(pagination.find('a').length).toEqual(7)
expect(pagination.find('a').get(0).innerHTML).toEqual('...')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('3')
expect(pagination.find('a').get(3).innerHTML).toEqual('4')
expect(pagination.find('a').get(4).innerHTML).toEqual('5')
expect(pagination.find('a').get(5).innerHTML).toEqual('6')
expect(pagination.find('a').get(6).innerHTML).toEqual('...')
expect(pagination.find('a').get(7)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(false)
})
it('should test show(14,2)', function () {
list.show(14, 2)
expect(pagination.find('a').length).toEqual(6)
expect(pagination.find('a').get(0).innerHTML).toEqual('...')
expect(pagination.find('a').get(1).innerHTML).toEqual('5')
expect(pagination.find('a').get(2).innerHTML).toEqual('6')
expect(pagination.find('a').get(3).innerHTML).toEqual('7')
expect(pagination.find('a').get(4).innerHTML).toEqual('8')
expect(pagination.find('a').get(5).innerHTML).toEqual('9')
expect(pagination.find('a').get(6)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(false)
})
it('should show last page with show(17,2)', function () {
list.show(17, 2)
expect(pagination.find('a').length).toEqual(4)
expect(pagination.find('a').get(0).innerHTML).toEqual('...')
expect(pagination.find('a').get(1).innerHTML).toEqual('7')
expect(pagination.find('a').get(2).innerHTML).toEqual('8')
expect(pagination.find('a').get(3).innerHTML).toEqual('9')
expect(pagination.find('a').get(4)).toEqual(undefined)
expect($(pagination.find('li').get(1)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
})
it('should handle page = 0', function () {
expect(list.listContainer.style.display).toBe('')
list.show(0, 0)
expect(list.listContainer.style.display).toBe('none')
list.show(1, 1)
expect(list.listContainer.style.display).toBe('block')
})
})
describe('Custom settings, innerWindow: 1, outerWindow: 1, left: 0, right: 0', function () {
var list, itemHTML, pagination
beforeAll(function () {
itemHTML = fixturePagination.list(['name'])
list = new List(
'list-pagination',
{
valueNames: ['name'],
item: itemHTML,
page: 2,
pagination: {
innerWindow: 1,
outerWindow: 1,
},
},
fixturePagination.all
)
pagination = $('.pagination')
})
afterAll(function () {
fixturePagination.removeList()
})
it('should have default settings', function () {
expect(pagination.find('a').length).toEqual(4)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('...')
expect(pagination.find('a').get(3).innerHTML).toEqual('9')
expect(pagination.find('a').get(4)).toEqual(undefined)
})
it('should test show(7,2)', function () {
list.show(7, 2)
expect(pagination.find('a').length).toEqual(7)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('...')
expect(pagination.find('a').get(2).innerHTML).toEqual('3')
expect(pagination.find('a').get(3).innerHTML).toEqual('4')
expect(pagination.find('a').get(4).innerHTML).toEqual('5')
expect(pagination.find('a').get(5).innerHTML).toEqual('...')
expect(pagination.find('a').get(6).innerHTML).toEqual('9')
expect(pagination.find('a').get(7)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(false)
})
it('should test show(14,2)', function () {
list.show(14, 2)
expect(pagination.find('a').length).toEqual(6)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('...')
expect(pagination.find('a').get(2).innerHTML).toEqual('6')
expect(pagination.find('a').get(3).innerHTML).toEqual('7')
expect(pagination.find('a').get(4).innerHTML).toEqual('8')
expect(pagination.find('a').get(5).innerHTML).toEqual('9')
expect(pagination.find('a').get(6)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(false)
})
it('should show last page with show(17,2)', function () {
list.show(17, 2)
expect(pagination.find('a').length).toEqual(4)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('...')
expect(pagination.find('a').get(2).innerHTML).toEqual('8')
expect(pagination.find('a').get(3).innerHTML).toEqual('9')
expect(pagination.find('a').get(4)).toEqual(undefined)
expect($(pagination.find('li').get(1)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
})
})
describe('Custom settings, innerWindow: 1, outerWindow: 1, left: 2, right: 1', function () {
var list, itemHTML, pagination
beforeAll(function () {
itemHTML = fixturePagination.list(['name'])
list = new List(
'list-pagination',
{
valueNames: ['name'],
item: itemHTML,
page: 2,
pagination: {
innerWindow: 1,
outerWindow: 1,
left: 2,
right: 1,
},
},
fixturePagination.all
)
pagination = $('.pagination')
})
afterAll(function () {
fixturePagination.removeList()
})
it('should have default settings', function () {
expect(pagination.find('a').length).toEqual(4)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('...')
expect(pagination.find('a').get(3).innerHTML).toEqual('9')
expect(pagination.find('a').get(4)).toEqual(undefined)
})
it('should test show(7,2)', function () {
list.show(7, 2)
expect(pagination.find('a').length).toEqual(7)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('3')
expect(pagination.find('a').get(3).innerHTML).toEqual('4')
expect(pagination.find('a').get(4).innerHTML).toEqual('5')
expect(pagination.find('a').get(5).innerHTML).toEqual('...')
expect(pagination.find('a').get(6).innerHTML).toEqual('9')
expect(pagination.find('a').get(7)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(false)
})
it('should test show(12,2)', function () {
list.show(12, 2)
expect(pagination.find('a').length).toEqual(8)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('...')
expect(pagination.find('a').get(3).innerHTML).toEqual('5')
expect(pagination.find('a').get(4).innerHTML).toEqual('6')
expect(pagination.find('a').get(5).innerHTML).toEqual('7')
expect(pagination.find('a').get(6).innerHTML).toEqual('...')
expect(pagination.find('a').get(7).innerHTML).toEqual('9')
expect(pagination.find('a').get(8)).toEqual(undefined)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(true)
expect($(pagination.find('li').get(5)).hasClass('active')).toEqual(false)
})
it('should show last page with show(17,2)', function () {
list.show(17, 2)
expect(pagination.find('a').length).toEqual(5)
expect(pagination.find('a').get(0).innerHTML).toEqual('1')
expect(pagination.find('a').get(1).innerHTML).toEqual('2')
expect(pagination.find('a').get(2).innerHTML).toEqual('...')
expect(pagination.find('a').get(3).innerHTML).toEqual('8')
expect(pagination.find('a').get(4).innerHTML).toEqual('9')
expect(pagination.find('a').get(5)).toEqual(undefined)
expect($(pagination.find('li').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(3)).hasClass('active')).toEqual(false)
expect($(pagination.find('li').get(4)).hasClass('active')).toEqual(true)
})
})
describe('Custom settings, pagination: { item: "<button><span class=page></span></button>" }', function () {
var list, itemHTML, pagination
beforeAll(function () {
itemHTML = fixturePagination.list(['name'])
list = new List(
'list-pagination',
{
valueNames: ['name'],
item: itemHTML,
page: 2,
pagination: {
item: '<button><span class=page></span></button>',
},
},
fixturePagination.all
)
pagination = $('.pagination')
})
afterAll(function () {
fixturePagination.removeList()
})
it('should have default settings', function () {
expect(pagination.find('span').length).toEqual(4)
expect(pagination.find('span').get(0).innerHTML).toEqual('1')
expect(pagination.find('span').get(1).innerHTML).toEqual('2')
expect(pagination.find('span').get(2).innerHTML).toEqual('3')
expect(pagination.find('span').get(3).innerHTML).toEqual('...')
expect(pagination.find('span').get(4)).toEqual(undefined)
})
it('should show same pages for show(7,2) and show(8,2)', function () {
list.show(7, 2)
expect(pagination.find('span').length).toEqual(7)
expect(pagination.find('span').get(0).innerHTML).toEqual('...')
expect(pagination.find('span').get(1).innerHTML).toEqual('2')
expect(pagination.find('span').get(2).innerHTML).toEqual('3')
expect(pagination.find('span').get(3).innerHTML).toEqual('4')
expect(pagination.find('span').get(4).innerHTML).toEqual('5')
expect(pagination.find('span').get(5).innerHTML).toEqual('6')
expect(pagination.find('span').get(6).innerHTML).toEqual('...')
expect(pagination.find('span').get(7)).toEqual(undefined)
expect($(pagination.find('button').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('button').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('button').get(4)).hasClass('active')).toEqual(false)
})
it('should show same pages for show(7,2) and show(8,2)', function () {
list.show(8, 2)
expect(pagination.find('span').length).toEqual(7)
expect(pagination.find('span').get(0).innerHTML).toEqual('...')
expect(pagination.find('span').get(1).innerHTML).toEqual('2')
expect(pagination.find('span').get(2).innerHTML).toEqual('3')
expect(pagination.find('span').get(3).innerHTML).toEqual('4')
expect(pagination.find('span').get(4).innerHTML).toEqual('5')
expect(pagination.find('span').get(5).innerHTML).toEqual('6')
expect(pagination.find('span').get(6).innerHTML).toEqual('...')
expect(pagination.find('span').get(7)).toEqual(undefined)
expect($(pagination.find('button').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('button').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('button').get(4)).hasClass('active')).toEqual(false)
})
it('should test show(14,2)', function () {
list.show(14, 2)
expect(pagination.find('span').length).toEqual(6)
expect(pagination.find('span').get(0).innerHTML).toEqual('...')
expect(pagination.find('span').get(1).innerHTML).toEqual('5')
expect(pagination.find('span').get(2).innerHTML).toEqual('6')
expect(pagination.find('span').get(3).innerHTML).toEqual('7')
expect(pagination.find('span').get(4).innerHTML).toEqual('8')
expect(pagination.find('span').get(5).innerHTML).toEqual('9')
expect(pagination.find('span').get(6)).toEqual(undefined)
expect($(pagination.find('button').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('button').get(3)).hasClass('active')).toEqual(true)
expect($(pagination.find('button').get(4)).hasClass('active')).toEqual(false)
})
it('should show last page with show(17,2)', function () {
list.show(17, 2)
expect(pagination.find('span').length).toEqual(4)
expect(pagination.find('span').get(0).innerHTML).toEqual('...')
expect(pagination.find('span').get(1).innerHTML).toEqual('7')
expect(pagination.find('span').get(2).innerHTML).toEqual('8')
expect(pagination.find('span').get(3).innerHTML).toEqual('9')
expect(pagination.find('span').get(4)).toEqual(undefined)
expect($(pagination.find('button').get(1)).hasClass('active')).toEqual(false)
expect($(pagination.find('button').get(2)).hasClass('active')).toEqual(false)
expect($(pagination.find('button').get(3)).hasClass('active')).toEqual(true)
})
it('should handle page = 0', function () {
expect(list.listContainer.style.display).toBe('')
list.show(0, 0)
expect(list.listContainer.style.display).toBe('none')
list.show(1, 1)
expect(list.listContainer.style.display).toBe('block')
})
})
})
================================================
FILE: __test__/parse.test.js
================================================
const $ = require('jquery'),
List = require('../src/index')
describe('Parse', function () {
describe('Parse class', function () {
var list
beforeEach(function () {
$('body').append(
$(
'<div id="parse-list">\
<div class="list">\
<div><span class="name">Jonny</span><span class="born">1986</span></div>\
<div><span class="name">Jocke</span><span class="born">1985</span></div>\
</div>\
</div>'
)
)
list = new List('parse-list', {
valueNames: ['name', 'born'],
})
})
afterEach(function () {
$('#parse-list').remove()
})
it('should have two items', function () {
expect(list.items.length).toEqual(2)
expect(list.items[0].values().name).toEqual('Jonny')
expect(list.items[1].values().name).toEqual('Jocke')
})
it('should add item to parsed list', function () {
list.add({ name: 'Sven', born: 1950 })
expect(list.items.length).toEqual(3)
expect(list.items[0].values().name).toEqual('Jonny')
expect(list.items[1].values().name).toEqual('Jocke')
expect(list.items[2].values().name).toEqual('Sven')
expect(list.items[0].values().born).toEqual('1986')
expect(list.items[2].values().born).toEqual(1950)
var el = $($('#parse-list').find('.list div')[2])
expect(el.find('span').length).toEqual(2)
expect(el.find('span.name').text()).toEqual('Sven')
expect(el.find('span.born').text()).toEqual('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).toEqual('1986')
expect(list.items[0].values().born).not.toEqual(1986)
expect(list.items[2].values().born).not.toEqual('1950')
expect(list.items[2].values().born).toEqual(1950)
})
})
describe('Parse data', function () {
var list
beforeEach(function () {
$('body').append(
$(
'<div id="parse-list">\
<div class="list">\
<div data-id="1">\
<a href="http://lol.com" class="link name">Jonny</a>\
<span class="born timestamp" data-timestamp="54321">1986</span>\
<img class="image" src="usage/boba.jpeg">\
<input class="foo" value="Bar">\
</div>\
<div data-id="2">\
<a href="http://lol.com" class="link name">Jocke</a>\
<span class="born timestamp" data-timestamp="12345">1985</span>\
<img class="image" src="usage/leia.jpeg">\
<input class="foo child" value="Car">\
</div>\
</div>\
</div>'
)
)
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).toEqual(2)
var jonny = list.items[0].values()
expect(jonny.name).toEqual('Jonny')
expect(jonny.born).toEqual('1986')
expect(jonny.id).toEqual('1')
expect(jonny.image).toEqual('usage/boba.jpeg')
expect(jonny.timestamp).toEqual('54321')
expect(jonny.foo).toEqual('Bar')
})
it('should add item to list with class, data and src', function () {
list.add({
name: 'Sven',
born: 1950,
id: 4,
image: 'usage/rey.jpeg',
link: 'localhost',
timestamp: '1337',
foo: 'hej',
})
expect(list.items.length).toEqual(3)
var sven = list.items[2].values()
expect(sven.name).toEqual('Sven')
expect(sven.born).toEqual(1950)
expect(sven.id).toEqual(4)
expect(sven.image).toEqual('usage/rey.jpeg')
expect(sven.link).toEqual('localhost')
expect(sven.timestamp).toEqual('1337')
expect(sven.foo).toEqual('hej')
var el = $($('#parse-list').find('.list div')[2])
expect(el.data('id')).toEqual(4)
expect(el.find('.name').text()).toEqual('Sven')
expect(el.find('.born').text()).toEqual('1950')
expect(el.find('.image').attr('src')).toEqual('usage/rey.jpeg')
expect(el.find('.link').attr('href')).toEqual('localhost')
expect(el.find('.timestamp').data('timestamp')).toEqual(1337)
expect(el.find('.foo').val()).toEqual('hej')
})
})
})
================================================
FILE: __test__/re-index.test.js
================================================
const $ = require('jquery'),
fixture = require('./fixtures')
describe('ReIndex', function () {
var list, jonny, martina, angelica, sebastian, imma, hasse
beforeAll(function () {
list = fixture.list(['name', 'born'], fixture.all)
})
afterAll(function () {
fixture.removeList()
})
afterEach(function () {
list.show(1, 200)
})
it('should return everyone born after 1988', function () {
expect(list.toJSON()).toEqual([
{ 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 = '<li><span class="name">Sven</span><span class="born">2013</span>'
newHtml = newHtml + '<li><span class="name">Anna</span><span class="born">3043</span>'
$(list.list).html(newHtml)
list.reIndex()
expect(list.toJSON()).toEqual([
{ name: 'Sven', born: '2013' },
{ name: 'Anna', born: '3043' },
])
})
})
================================================
FILE: __test__/search-filter.test.js
================================================
const fixture = require('./fixtures')
describe('Search and filter', function () {
var list, jonny, martina, angelica, sebastian, imma, hasse
beforeAll(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]
})
afterAll(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).toEqual(3)
expect(jonny.matching()).toBe(true)
expect(martina.matching()).toBe(true)
expect(angelica.matching()).toBe(true)
expect(sebastian.matching()).toBe(false)
expect(imma.matching()).toBe(false)
expect(hasse.matching()).toBe(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).toEqual(1)
expect(jonny.matching()).toBe(true)
expect(martina.matching()).toBe(false)
expect(angelica.matching()).toBe(false)
expect(sebastian.matching()).toBe(false)
expect(imma.matching()).toBe(false)
expect(hasse.matching()).toBe(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).toEqual(4)
expect(jonny.matching()).toBe(true)
expect(martina.matching()).toBe(false)
expect(angelica.matching()).toBe(false)
expect(sebastian.matching()).toBe(true)
expect(imma.matching()).toBe(true)
expect(hasse.matching()).toBe(true)
})
})
})
================================================
FILE: __test__/search.test.js
================================================
const fixture = require('./fixtures')
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).toEqual(1)
expect(result[0]).toEqual(jonny)
})
})
describe('Number of results', function () {
it('should find jonny, martina, angelice', function () {
var result = list.search('1986')
expect(result.length).toEqual(3) // 3!!
expect(jonny.matching()).toBe(true)
expect(martina.matching()).toBe(true)
expect(angelica.matching()).toBe(true)
expect(sebastian.matching()).toBe(false)
expect(imma.matching()).toBe(false)
expect(hasse.matching()).toBe(false)
})
it('should find all with utf-8 char ö', function () {
var result = list.search('ö')
expect(result.length).toEqual(4) // 4!!
expect(jonny.matching()).toBe(true)
expect(martina.matching()).toBe(false)
expect(angelica.matching()).toBe(false)
expect(sebastian.matching()).toBe(true)
expect(imma.matching()).toBe(true)
expect(hasse.matching()).toBe(true)
})
it('should not break with weird searches', function () {
expect(function () {
list.search(undefined)
}).not.toThrow()
expect(function () {
list.search(null)
}).not.toThrow()
expect(function () {
list.search(0)
}).not.toThrow()
expect(function () {
list.search(function () {})
}).not.toThrow()
expect(function () {
list.search({ foo: 'bar' })
}).not.toThrow()
})
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(function () {
list.search('jonny')
}).not.toThrow()
expect(function () {
list.search(undefined)
}).not.toThrow()
expect(function () {
list.search(null)
}).not.toThrow()
expect(function () {
list.search(0)
}).not.toThrow()
expect(function () {
list.search(function () {})
}).not.toThrow()
expect(function () {
list.search({ foo: 'bar' })
}).not.toThrow()
})
})
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).toEqual(1)
expect(result[0]).toEqual(jonny)
})
it('should not find in the default match column', function () {
list.searchColumns = ['born']
var result = list.search('jonny')
expect(result.length).toEqual(0)
})
})
describe('Specific columns', function () {
it('should find match in column', function () {
var result = list.search('jonny', ['name'])
expect(result.length).toEqual(1)
expect(result[0]).toEqual(jonny)
})
it('should not find match in column', function () {
var result = list.search('jonny', ['born'])
expect(result.length).toEqual(0)
})
it('should find match in column', function () {
var result = list.search('jonny', ['name'])
expect(result.length).toEqual(1)
expect(result[0]).toEqual(jonny)
})
it('should not find match in column', function () {
var result = list.search('jonny', ['born'])
expect(result.length).toEqual(0)
})
it('should work with columns that do not exist', function () {
var result = list.search('jonny', ['pet'])
expect(result.length).toEqual(0)
})
it('should remove column option', function () {
var result = list.search('jonny', ['born'])
expect(result.length).toEqual(0)
result = list.search('jonny')
expect(result.length).toEqual(1)
})
})
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).toEqual(4)
})
it('should use custom function in second argument', function () {
var result = list.search('jonny', customSearchFunction)
expect(result.length).toEqual(4)
})
})
describe('Multiple word search', function () {
it('should find jonny, hasse', function () {
var result = list.search('berg str')
expect(result.length).toEqual(2)
expect(jonny.matching()).toBe(true)
expect(martina.matching()).toBe(false)
expect(angelica.matching()).toBe(false)
expect(sebastian.matching()).toBe(false)
expect(imma.matching()).toBe(false)
expect(hasse.matching()).toBe(true)
})
it('should find martina, angelica, sebastian, hasse', function () {
var result = list.search('a e')
expect(result.length).toEqual(4)
expect(jonny.matching()).toBe(false)
expect(martina.matching()).toBe(true)
expect(angelica.matching()).toBe(true)
expect(sebastian.matching()).toBe(true)
expect(imma.matching()).toBe(false)
expect(hasse.matching()).toBe(true)
})
it('stripping whitespace should find martina', function () {
var result = list.search('martina elm ')
expect(result.length).toEqual(1)
expect(result[0]).toEqual(martina)
})
})
describe('Quoted phrase searches', function () {
it('should find martina', function () {
var result = list.search('"a e"')
expect(result.length).toEqual(1)
expect(result[0]).toEqual(martina)
})
it('quoted phrase and multiple words should find jonny', function () {
var result = list.search('" str" 1986')
expect(result.length).toEqual(1)
expect(result[0]).toEqual(jonny)
})
})
//
// describe('Special characters', function() {
// it('should escape and handle special characters', function() {
// list.add([
// { name: 'Jonny&Jabba' },
// { name: '<Leia' },
// { name: '>Luke' },
// { name: '"Chewie"' },
// { name: "'Ewok'" }
// ]);
// var result = list.search('Leia');
// console.log(result);
// expect(result.length).toEqual(1);
// var result = list.search('<');
// console.log(result);
// expect(result.length).toEqual(1);
// });
// });
})
================================================
FILE: __test__/show.test.js
================================================
const fixture = require('./fixtures')
describe('Show', function () {
var list, a, b, c, d, e, f
beforeAll(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]
})
afterAll(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).toEqual(2)
expect(a.visible()).toBe(true)
expect(b.visible()).toBe(true)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(false)
expect(f.visible()).toBe(false)
})
it('should show item 6', function () {
list.show(6, 2)
expect(list.visibleItems.length).toEqual(1)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(false)
expect(f.visible()).toBe(true)
})
it('should show item 1, 2, 3, 4, 5, 6', function () {
list.show(1, 200)
expect(list.visibleItems.length).toEqual(6)
expect(a.visible()).toBe(true)
expect(b.visible()).toBe(true)
expect(c.visible()).toBe(true)
expect(d.visible()).toBe(true)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(true)
})
it('should show item 3, 4, 5', function () {
list.show(3, 3)
expect(list.visibleItems.length).toEqual(3)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(true)
expect(d.visible()).toBe(true)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(false)
})
it('should show item 5, 6', function () {
list.show(5, 3)
expect(list.visibleItems.length).toEqual(2)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(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).toEqual(2)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(true)
expect(d.visible()).toBe(true)
expect(e.visible()).toBe(false)
expect(f.visible()).toBe(false)
})
it('should show item 3,4,5,6', function () {
list.search('b')
list.show(1, 4)
expect(list.visibleItems.length).toEqual(4)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(true)
expect(d.visible()).toBe(true)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(true)
})
it('should not show any items but match two', function () {
list.search('a')
list.show(3, 2)
expect(list.visibleItems.length).toEqual(0)
expect(list.matchingItems.length).toEqual(2)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(false)
expect(f.visible()).toBe(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).toEqual(2)
expect(list.matchingItems.length).toEqual(2)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(true)
expect(d.visible()).toBe(true)
expect(e.visible()).toBe(false)
expect(f.visible()).toBe(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).toEqual(2)
expect(list.matchingItems.length).toEqual(2)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(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).toEqual(0)
expect(list.matchingItems.length).toEqual(2)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(false)
expect(f.visible()).toBe(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).toEqual(2)
expect(list.matchingItems.length).toEqual(3)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(true)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(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).toEqual(2)
expect(list.matchingItems.length).toEqual(3)
expect(a.visible()).toBe(false)
expect(b.visible()).toBe(false)
expect(c.visible()).toBe(false)
expect(d.visible()).toBe(false)
expect(e.visible()).toBe(true)
expect(f.visible()).toBe(true)
})
})
})
================================================
FILE: __test__/sort.test.js
================================================
const $ = require('jquery'),
fixture = require('./fixtures')
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).toBe('a')
expect(list.items[1].values().val).toBe('b')
expect(list.items[2].values().val).toBe('c')
expect(list.items[3].values().val).toBe('s')
expect(list.items[4].values().val).toBe('y')
expect(list.items[5].values().val).toBe('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).toBe('z')
expect(list.items[1].values().val).toBe('y')
expect(list.items[2].values().val).toBe('s')
expect(list.items[3].values().val).toBe('c')
expect(list.items[4].values().val).toBe('b')
expect(list.items[5].values().val).toBe('a')
})
it('should sort åäö desc', function () {
list.alphabet = 'ABCDEFGHIJKLMNOPQRSTUVXYZÅÄÖabcdefghijklmnopqrstuvxyzåäö'
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).toBe('ö')
expect(list.items[1].values().val).toBe('ä')
expect(list.items[2].values().val).toBe('å')
expect(list.items[3].values().val).toBe('s')
expect(list.items[4].values().val).toBe('o')
expect(list.items[5].values().val).toBe('a')
})
it('should sort åäö asc', function () {
list.alphabet = 'ABCDEFGHIJKLMNOPQRSTUVXYZÅÄÖabcdefghijklmnopqrstuvxyzåäö'
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: 'asc' })
expect(list.items[0].values().val).toBe('a')
expect(list.items[1].values().val).toBe('o')
expect(list.items[2].values().val).toBe('s')
expect(list.items[3].values().val).toBe('å')
expect(list.items[4].values().val).toBe('ä')
expect(list.items[5].values().val).toBe('ö')
})
it('should sort åäö desc case insensitive', function () {
list.alphabet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvXxYyZzÅåÄäÖö'
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).toBe('Ö')
expect(list.items[1].values().val).toBe('ä')
expect(list.items[2].values().val).toBe('Å')
expect(list.items[3].values().val).toBe('S')
expect(list.items[4].values().val).toBe('o')
expect(list.items[5].values().val).toBe('a')
})
it('should sort åäö asc case insensitive', function () {
list.alphabet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvXxYyZzÅåÄäÖö'
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: 'asc' })
expect(list.items[0].values().val).toBe('A')
expect(list.items[1].values().val).toBe('O')
expect(list.items[2].values().val).toBe('s')
expect(list.items[3].values().val).toBe('å')
expect(list.items[4].values().val).toBe('Ä')
expect(list.items[5].values().val).toBe('ö')
})
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).toBe('A')
expect(list.items[1].values().val).toBe('b')
expect(list.items[2].values().val).toBe('C')
expect(list.items[3].values().val).toBe('D')
expect(list.items[4].values().val).toBe('e')
expect(list.items[5].values().val).toBe('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).toBe('A')
expect(list.items[1].values().val).toBe('C')
expect(list.items[2].values().val).toBe('D')
expect(list.items[3].values().val).toBe('F')
expect(list.items[4].values().val).toBe('b')
expect(list.items[5].values().val).toBe('e')
})
it('should sort dates', function () {
i1.values({ val: '2008-12-10' })
i2.values({ val: '2008-11-10' })
i3.values({ val: '2007-11-10' })
i4.values({ val: '2009-12-10' })
i5.values({ val: '2007-01-4' })
i6.values({ val: '2006-12-10' })
list.sort('val', { order: 'asc' })
expect(list.items[0].values().val).toBe('2006-12-10')
expect(list.items[1].values().val).toBe('2007-01-4')
expect(list.items[2].values().val).toBe('2007-11-10')
expect(list.items[3].values().val).toBe('2008-11-10')
expect(list.items[4].values().val).toBe('2008-12-10')
expect(list.items[5].values().val).toBe('2009-12-10')
})
it('should sort file names (a bit wrong)', 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).toBe('01alpha.sgi')
expect(list.items[1].values().val).toBe('001alpha.sgi')
expect(list.items[2].values().val).toBe('0002.asp')
expect(list.items[3].values().val).toBe('0003.zip')
expect(list.items[4].values().val).toBe('car.mov')
expect(list.items[5].values().val).toBe('my.string_41299.tif')
})
it('should show order of sorted floates (a bit wrong)', 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).toBe('0003.123')
expect(list.items[1].values().val).toBe('09.2123')
expect(list.items[2].values().val).toBe('10.022')
expect(list.items[3].values().val).toBe('10.0401')
expect(list.items[4].values().val).toBe('10.021999')
expect(list.items[5].values().val).toBe('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).toBe('127.0.0.1')
expect(list.items[1].values().val).toBe('192.168.0.1')
expect(list.items[2].values().val).toBe('192.168.0.100')
expect(list.items[3].values().val).toBe('192.168.1.1')
expect(list.items[4].values().val).toBe('192.168.1.2')
expect(list.items[5].values().val).toBe('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(function () {
list.sort('val')
}).not.toThrow()
})
it('should handle values from issue 387', function () {
i1.values({ val: 'Test' })
i2.values({ val: 'Test1Test2' })
i3.values({ val: 'Bill-To Phone1 Extension' })
i4.values({ val: 'z' })
i5.values({ val: 's' })
i6.values({ val: 'y' })
list.sort('val', { order: 'asc' })
expect(list.items[0].values().val).toBe('Bill-To Phone1 Extension')
expect(list.items[1].values().val).toBe('s')
expect(list.items[2].values().val).toBe('Test')
expect(list.items[3].values().val).toBe('Test1Test2')
expect(list.items[4].values().val).toBe('y')
expect(list.items[5].values().val).toBe('z')
})
xit('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).toBe('')
expect(list.items[1].values().val).toBe('!')
expect(list.items[2].values().val).toBe(0)
expect(list.items[3].values().val).toBe('0')
expect(list.items[4].values().val).toBe(100)
expect(list.items[5].values().val).toBe('?')
expect(list.items[6].values().val).toBe('a')
expect(list.items[7].values().val).toBe(false)
expect(list.items[8].values().val).toBe(null)
expect(list.items[9].values().val).toBe(true)
expect(list.items[10].values().val).toBe(undefined)
expect(list.items[11].values().val).toBe('z')
})
it('should handle not longer (since 1.4.0) space and zero the same for desc and asc', 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).toBe('')
expect(list.items[1].values().val).toBe('0')
expect(list.items[2].values().val).toBe(0)
list.sort('val', { order: 'desc' })
expect(list.items[0].values().val).toBe('0')
expect(list.items[1].values().val).toBe(0)
expect(list.items[2].values().val).toBe('')
list.sort('val', { order: 'asc' })
expect(list.items[0].values().val).toBe('')
expect(list.items[1].values().val).toBe('0')
expect(list.items[2].values().val).toBe(0)
})
})
describe('Custom sort function', function () {
it('should use custom sort option', function () {
i1.values({ val: "<input value='b' />" })
i2.values({ val: "<input value='a' />" })
i3.values({ val: "<input value='c' />" })
i4.values({ val: "<input value='z' />" })
i5.values({ val: "<input value='s' />" })
i6.values({ val: "<input value='y' />" })
list.sort('val', {
sortFunction: function (itemA, itemB, options) {
return list.utils.naturalSort(
$(itemA.values()[options.valueName]).val(),
$(itemB.values()[options.valueName]).val()
)
},
})
expect(list.items[0].values().val).toBe("<input value='a' />")
expect(list.items[1].values().val).toBe("<input value='b' />")
expect(list.items[2].values().val).toBe("<input value='c' />")
expect(list.items[3].values().val).toBe("<input value='s' />")
expect(list.items[4].values().val).toBe("<input value='y' />")
expect(list.items[5].values().val).toBe("<input value='z' />")
})
it('should use default custom sort function', function () {
list.sortFunction = function (itemA, itemB, options) {
return list.utils.naturalSort(
$(itemA.values()[options.valueName]).val(),
$(itemB.values()[options.valueName]).val()
)
}
i1.values({ val: "<input value='b' />" })
i2.values({ val: "<input value='a' />" })
i3.values({ val: "<input value='c' />" })
i4.values({ val: "<input value='z' />" })
i5.values({ val: "<input value='s' />" })
i6.values({ val: "<input value='y' />" })
list.sort('val')
expect(list.items[0].values().val).toBe("<input value='a' />")
expect(list.items[1].values().val).toBe("<input value='b' />")
expect(list.items[2].values().val).toBe("<input value='c' />")
expect(list.items[3].values().val).toBe("<input value='s' />")
expect(list.items[4].values().val).toBe("<input value='y' />")
expect(list.items[5].values().val).toBe("<input value='z' />")
})
it('should use default custom sort function with order desc', function () {
list.sortFunction = function (itemA, itemB, options) {
return list.utils.naturalSort(
$(itemA.values()[options.valueName]).val(),
$(itemB.values()[options.valueName]).val()
)
}
i1.values({ val: "<input value='b' />" })
i2.values({ val: "<input value='a' />" })
i3.values({ val: "<input value='c' />" })
i4.values({ val: "<input value='z' />" })
i5.values({ val: "<input value='s' />" })
i6.values({ val: "<input value='y' />" })
list.sort('val', { order: 'desc' })
expect(list.items[0].values().val).toBe("<input value='z' />")
expect(list.items[1].values().val).toBe("<input value='y' />")
expect(list.items[2].values().val).toBe("<input value='s' />")
expect(list.items[3].values().val).toBe("<input value='c' />")
expect(list.items[4].values().val).toBe("<input value='b' />")
expect(list.items[5].values().val).toBe("<input value='a' />")
})
})
})
================================================
FILE: __test__/trigger.test.js
================================================
const fixture = require('./fixtures')
describe('Trigger', function () {
var list
beforeAll(function () {
list = fixture.list(['name', 'born'], fixture.all)
})
afterAll(function () {
fixture.removeList()
})
describe('General', function () {
it('should be triggered by searchComplete', function (done) {
list.on('searchComplete', function () {
done()
})
list.trigger('searchComplete')
})
})
})
================================================
FILE: __test__/usage/amd.html
================================================
<!DOCTYPE html>
<html>
<head>
<script data-main="main" src="require.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="users">
<input class="search" placeholder="Search" />
<button class="sort" data-sort="name">
Sort by name
</button>
<ul class="list">
<li>
<h3 class="name">Jonny Stromberg</h3>
<p class="born">1986</p>
</li>
<li>
<h3 class="name">Jonas Arnklint</h3>
<p class="born">1985</p>
</li>
<li>
<h3 class="name">Martina Elm</h3>
<p class="born">1986</p>
</li>
<li>
<h3 class="name">Gustaf Lindqvist</h3>
<p class="born">1983</p>
</li>
</ul>
</div>
</body>
</html>
================================================
FILE: __test__/usage/classic.html
================================================
<!DOCTYPE html>
<html>
<head>
<script src="../../dist/list.min.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="users">
<input class="search" placeholder="Search" />
<button class="sort" data-sort="name">
Sort by name
</button>
<ul class="list">
<li data-id="1">
<a href="https://twitter.com/javve" class="link name">Jonny Stromberg</a>
<p class="born timestamp" data-timestamp="12345">1986</p>
<img class="image" src="luke.jpeg">
</li>
<li data-id="2">
<a href="https://twitter.com/arnklint" class="link name">Jonas Arnklint</a>
<p class="born timestamp" data-timestamp="23456">1985</p>
<img class="image" src="darth.jpeg">
</li>
<li data-id="3">
<a href="https://twitter.com/martinaelm" class="link name">Martina Elm</a>
<p class="born timestamp" data-timestamp="34567">1986</p>
<img class="image" src="rey.jpeg">
</li>
<li data-id="4">
<a href="https://twitter.com/GLindqvist" class="link name">Gustaf Lindqvist</a>
<p class="born timestamp" data-timestamp="45678">1983</p>
<img class="image" src="boba.jpeg">
</li>
</ul>
</div>
<script>
var options = {
valueNames: [
'name',
'born',
{ data: ['id'] },
{ attr: 'src', name: 'image' },
{ attr: 'href', name: 'link' },
{ attr: 'data-timestamp', name: 'timestamp' }
]
};
var userList = new List('users', options);
userList.add({ name: 'Leia', born: '1954', image: 'leia.jpeg', id: 5, timestamp: '67893' });
</script>
</body>
</html>
================================================
FILE: __test__/usage/fuzzy-search-pagination.html
================================================
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Basic example</title>
</head>
<body>
<div id="test-list">
<input type="text" class="fuzzy-search" />
<ul class="pagination1"></ul>
<ul class="list">
<li><p class="name">Guybrush Threepwood</p></li>
<li><p class="name">Manny Calavera</p></li>
<li><p class="name">Bernard Bernoulli</p></li>
<li><p class="name">LeChuck</p></li>
<li><p class="name">Elaine Marley-Threepwood</p></li>
<li><p class="name">Purple Tentacle</p></li>
<li><p class="name">Adrian Ripburger</p></li>
<li><p class="name">Bobbin Threadbare</p></li>
<li><p class="name">Murray the Demonic Skull</p></li>
<li><p class="name">Zak McKracken</p></li>
</ul>
<ul class="pagination2"></ul>
</div>
<script src="../../dist/list.js"></script>
<script>
var options = {
valueNames: ['name'],
pagination: [{
paginationClass: 'pagination1',
innerWindow:1
},{
paginationClass: 'pagination2'
}],
page:3
};
var monkeyList = new List('test-list', options);
console.log(monkeyList);
</script>
</body>
</html>
================================================
FILE: __test__/usage/main.js
================================================
require(['../../dist/list', '../../dist/list.min'], function (List, ListMin) {
var options = {
valueNames: ['name', 'born'],
}
var userList = new List('users', options)
})
================================================
FILE: __test__/usage/require.js
================================================
/** vim: et:ts=4:sw=4:sts=4
* @license RequireJS 2.1.17 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
//Not using strict: uneven strict support in browsers, #392, and causes
//problems with requirejs.exec()/transpiler plugins that may not be strict.
/*jslint regexp: true, nomen: true, sloppy: true */
/*global window, navigator, document, importScripts, setTimeout, opera */
var requirejs, require, define
;(function (global) {
var req,
s,
head,
baseElement,
dataMain,
src,
interactiveScript,
currentlyAddingScript,
mainScript,
subPath,
version = '2.1.17',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
currDirRegExp = /^\.\//,
op = Object.prototype,
ostring = op.toString,
hasOwn = op.hasOwnProperty,
ap = Array.prototype,
apsp = ap.splice,
isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
//PS3 indicates loaded and complete, but need to wait for complete
//specifically. Sequence is 'loading', 'loaded', execution,
// then 'complete'. The UA check is unfortunate, but not sure how
//to feature test w/o causing perf issues.
readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ? /^complete$/ : /^(complete|loaded)$/,
defContextName = '_',
//Oh the tragedy, detecting opera. See the usage of isOpera for reason.
isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
contexts = {},
cfg = {},
globalDefQueue = [],
useInteractive = false
function isFunction(it) {
return ostring.call(it) === '[object Function]'
}
function isArray(it) {
return ostring.call(it) === '[object Array]'
}
/**
* Helper function for iterating over an array. If the func returns
* a true value, it will break out of the loop.
*/
function each(ary, func) {
if (ary) {
var i
for (i = 0; i < ary.length; i += 1) {
if (ary[i] && func(ary[i], i, ary)) {
break
}
}
}
}
/**
* Helper function for iterating over an array backwards. If the func
* returns a true value, it will break out of the loop.
*/
function eachReverse(ary, func) {
if (ary) {
var i
for (i = ary.length - 1; i > -1; i -= 1) {
if (ary[i] && func(ary[i], i, ary)) {
break
}
}
}
}
function hasProp(obj, prop) {
return hasOwn.call(obj, prop)
}
function getOwn(obj, prop) {
return hasProp(obj, prop) && obj[prop]
}
/**
* Cycles over properties in an object and calls a function for each
* property value. If the function returns a truthy value, then the
* iteration is stopped.
*/
function eachProp(obj, func) {
var prop
for (prop in obj) {
if (hasProp(obj, prop)) {
if (func(obj[prop], prop)) {
break
}
}
}
}
/**
* Simple function to mix in properties from source into target,
* but only if target does not already have a property of the same name.
*/
function mixin(target, source, force, deepStringMixin) {
if (source) {
eachProp(source, function (value, prop) {
if (force || !hasProp(target, prop)) {
if (
deepStringMixin &&
typeof value === 'object' &&
value &&
!isArray(value) &&
!isFunction(value) &&
!(value instanceof RegExp)
) {
if (!target[prop]) {
target[prop] = {}
}
mixin(target[prop], value, force, deepStringMixin)
} else {
target[prop] = value
}
}
})
}
return target
}
//Similar to Function.prototype.bind, but the 'this' object is specified
//first, since it is easier to read/figure out what 'this' will be.
function bind(obj, fn) {
return function () {
return fn.apply(obj, arguments)
}
}
function scripts() {
return document.getElementsByTagName('script')
}
function defaultOnError(err) {
throw err
}
//Allow getting a global that is expressed in
//dot notation, like 'a.b.c'.
function getGlobal(value) {
if (!value) {
return value
}
var g = global
each(value.split('.'), function (part) {
g = g[part]
})
return g
}
/**
* Constructs an error with a pointer to an URL with more information.
* @param {String} id the error ID that maps to an ID on a web page.
* @param {String} message human readable error.
* @param {Error} [err] the original error, if there is one.
*
* @returns {Error}
*/
function makeError(id, msg, err, requireModules) {
var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id)
e.requireType = id
e.requireModules = requireModules
if (err) {
e.originalError = err
}
return e
}
if (typeof define !== 'undefined') {
//If a define is already in play via another AMD loader,
//do not overwrite.
return
}
if (typeof requirejs !== 'undefined') {
if (isFunction(requirejs)) {
//Do not overwrite an existing requirejs instance.
return
}
cfg = requirejs
requirejs = undefined
}
//Allow for a require config object
if (typeof require !== 'undefined' && !isFunction(require)) {
//assume it is a config object.
cfg = require
require = undefined
}
function newContext(contextName) {
var inCheckLoaded,
Module,
context,
handlers,
checkLoadedTimeoutId,
config = {
//Defaults. Do not set a default for map
//config to speed up normalize(), which
//will run faster if there is no default.
waitSeconds: 7,
baseUrl: './',
paths: {},
bundles: {},
pkgs: {},
shim: {},
config: {},
},
registry = {},
//registry of just enabled modules, to speed
//cycle breaking code when lots of modules
//are registered, but not activated.
enabledRegistry = {},
undefEvents = {},
defQueue = [],
defined = {},
urlFetched = {},
bundlesMap = {},
requireCounter = 1,
unnormalizedCounter = 1
/**
* Trims the . and .. from an array of path segments.
* It will keep a leading path segment if a .. will become
* the first path segment, to help with module name lookups,
* which act like paths, but can be remapped. But the end result,
* all paths that use this function should look normalized.
* NOTE: this method MODIFIES the input array.
* @param {Array} ary the array of path segments.
*/
function trimDots(ary) {
var i, part
for (i = 0; i < ary.length; i++) {
part = ary[i]
if (part === '.') {
ary.splice(i, 1)
i -= 1
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
continue
} else if (i > 0) {
ary.splice(i - 1, 2)
i -= 2
}
}
}
}
/**
* Given a relative module name, like ./something, normalize it to
* a real name that can be mapped to a path.
* @param {String} name the relative name
* @param {String} baseName a real name that the name arg is relative
* to.
* @param {Boolean} applyMap apply the map config to the value. Should
* only be done if this normalization is for a dependency ID.
* @returns {String} normalized name
*/
function normalize(name, baseName, applyMap) {
var pkgMain,
mapValue,
nameParts,
i,
j,
nameSegment,
lastIndex,
foundMap,
foundI,
foundStarMap,
starI,
normalizedBaseParts,
baseParts = baseName && baseName.split('/'),
map = config.map,
starMap = map && map['*']
//Adjust any relative paths.
if (name) {
name = name.split('/')
lastIndex = name.length - 1
// If wanting node ID compatibility, strip .js from end
// of IDs. Have to do this here, and not in nameToUrl
// because node allows either .js or non .js to map
// to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '')
}
// Starts with a '.' so need the baseName
if (name[0].charAt(0) === '.' && baseParts) {
//Convert baseName to array, and lop off the last part,
//so that . matches that 'directory' and not name of the baseName's
//module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1)
name = normalizedBaseParts.concat(name)
}
trimDots(name)
name = name.join('/')
}
//Apply map config if available.
if (applyMap && map && (baseParts || starMap)) {
nameParts = name.split('/')
outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
nameSegment = nameParts.slice(0, i).join('/')
if (baseParts) {
//Find the longest baseName segment match in the config.
//So, do joins on the biggest to smallest lengths of baseParts.
for (j = baseParts.length; j > 0; j -= 1) {
mapValue = getOwn(map, baseParts.slice(0, j).join('/'))
//baseName segment has config, find if it has one for
//this name.
if (mapValue) {
mapValue = getOwn(mapValue, nameSegment)
if (mapValue) {
//Match, update name to the new value.
foundMap = mapValue
foundI = i
break outerLoop
}
}
}
}
//Check for a star map match, but just hold on to it,
//if there is a shorter segment match later in a matching
//config, then favor over this star map.
if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
foundStarMap = getOwn(starMap, nameSegment)
starI = i
}
}
if (!foundMap && foundStarMap) {
foundMap = foundStarMap
foundI = starI
}
if (foundMap) {
nameParts.splice(0, foundI, foundMap)
name = nameParts.join('/')
}
}
// If the name points to a package's name, use
// the package main instead.
pkgMain = getOwn(config.pkgs, name)
return pkgMain ? pkgMain : name
}
function removeScript(name) {
if (isBrowser) {
each(scripts(), function (scriptNode) {
if (
scriptNode.getAttribute('data-requiremodule') === name &&
scriptNode.getAttribute('data-requirecontext') === context.contextName
) {
scriptNode.parentNode.removeChild(scriptNode)
return true
}
})
}
}
function hasPathFallback(id) {
var pathConfig = getOwn(config.paths, id)
if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
//Pop off the first array value, since it failed, and
//retry
pathConfig.shift()
context.require.undef(id)
//Custom require that does not do map translation, since
//ID is "absolute", already mapped/resolved.
context.makeRequire(null, {
skipMap: true,
})([id])
return true
}
}
//Turns a plugin!resource to [plugin, resource]
//with the plugin being undefined if the name
//did not have a plugin prefix.
function splitPrefix(name) {
var prefix,
index = name ? name.indexOf('!') : -1
if (index > -1) {
prefix = name.substring(0, index)
name = name.substring(index + 1, name.length)
}
return [prefix, name]
}
/**
* Creates a module mapping that includes plugin prefix, module
* name, and path. If parentModuleMap is provided it will
* also normalize the name via require.normalize()
*
* @param {String} name the module name
* @param {String} [parentModuleMap] parent module map
* for the module name, used to resolve relative names.
* @param {Boolean} isNormalized: is the ID already normalized.
* This is true if this call is done for a define() module ID.
* @param {Boolean} applyMap: apply the map config to the ID.
* Should only be true if this map is for a dependency.
*
* @returns {Object}
*/
function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
var url,
pluginModule,
suffix,
nameParts,
prefix = null,
parentName = parentModuleMap ? parentModuleMap.name : null,
originalName = name,
isDefine = true,
normalizedName = ''
//If no name, then it means it is a require call, generate an
//internal name.
if (!name) {
isDefine = false
name = '_@r' + (requireCounter += 1)
}
nameParts = splitPrefix(name)
prefix = nameParts[0]
name = nameParts[1]
if (prefix) {
prefix = normalize(prefix, parentName, applyMap)
pluginModule = getOwn(defined, prefix)
}
//Account for relative paths if there is a base name.
if (name) {
if (prefix) {
if (pluginModule && pluginModule.normalize) {
//Plugin is loaded, use its normalize method.
normalizedName = pluginModule.normalize(name, function (name) {
return normalize(name, parentName, applyMap)
})
} else {
// If nested plugin references, then do not try to
// normalize, as it will not normalize correctly. This
// places a restriction on resourceIds, and the longer
// term solution is not to normalize until plugins are
// loaded and all normalizations to allow for async
// loading of a loader plugin. But for now, fixes the
// common uses. Details in #1131
normalizedName = name.indexOf('!') === -1 ? normalize(name, parentName, applyMap) : name
}
} else {
//A regular module.
normalizedName = normalize(name, parentName, applyMap)
//Normalized name may be a plugin ID due to map config
//application in normalize. The map config values must
//already be normalized, so do not need to redo that part.
nameParts = splitPrefix(normalizedName)
prefix = nameParts[0]
normalizedName = nameParts[1]
isNormalized = true
url = context.nameToUrl(normalizedName)
}
}
//If the id is a plugin id that cannot be determined if it needs
//normalization, stamp it with a unique ID so two matching relative
//ids that may conflict can be separate.
suffix = prefix && !pluginModule && !isNormalized ? '_unnormalized' + (unnormalizedCounter += 1) : ''
return {
prefix: prefix,
name: normalizedName,
parentMap: parentModuleMap,
unnormalized: !!suffix,
url: url,
originalName: originalName,
isDefine: isDefine,
id: (prefix ? prefix + '!' + normalizedName : normalizedName) + suffix,
}
}
function getModule(depMap) {
var id = depMap.id,
mod = getOwn(registry, id)
if (!mod) {
mod = registry[id] = new context.Module(depMap)
}
return mod
}
function on(depMap, name, fn) {
var id = depMap.id,
mod = getOwn(registry, id)
if (hasProp(defined, id) && (!mod || mod.defineEmitComplete)) {
if (name === 'defined') {
fn(defined[id])
}
} else {
mod = getModule(depMap)
if (mod.error && name === 'error') {
fn(mod.error)
} else {
mod.on(name, fn)
}
}
}
function onError(err, errback) {
var ids = err.requireModules,
notified = false
if (errback) {
errback(err)
} else {
each(ids, function (id) {
var mod = getOwn(registry, id)
if (mod) {
//Set error on module, so it skips timeout checks.
mod.error = err
if (mod.events.error) {
notified = true
mod.emit('error', err)
}
}
})
if (!notified) {
req.onError(err)
}
}
}
/**
* Internal method to transfer globalQueue items to this context's
* defQueue.
*/
function takeGlobalQueue() {
//Push all the globalDefQueue items into the context's defQueue
if (globalDefQueue.length) {
//Array splice in the values since the context code has a
//local var ref to defQueue, so cannot just reassign the one
//on context.
apsp.apply(defQueue, [defQueue.length, 0].concat(globalDefQueue))
globalDefQueue = []
}
}
handlers = {
require: function (mod) {
if (mod.require) {
return mod.require
} else {
return (mod.require = context.makeRequire(mod.map))
}
},
exports: function (mod) {
mod.usingExports = true
if (mod.map.isDefine) {
if (mod.exports) {
return (defined[mod.map.id] = mod.exports)
} else {
return (mod.exports = defined[mod.map.id] = {})
}
}
},
module: function (mod) {
if (mod.module) {
return mod.module
} else {
return (mod.module = {
id: mod.map.id,
uri: mod.map.url,
config: function () {
return getOwn(config.config, mod.map.id) || {}
},
exports: mod.exports || (mod.exports = {}),
})
}
},
}
function cleanRegistry(id) {
//Clean up machinery used for waiting modules.
delete registry[id]
delete enabledRegistry[id]
}
function breakCycle(mod, traced, processed) {
var id = mod.map.id
if (mod.error) {
mod.emit('error', mod.error)
} else {
traced[id] = true
each(mod.depMaps, function (depMap, i) {
var depId = depMap.id,
dep = getOwn(registry, depId)
//Only force things that have not completed
//being defined, so still in the registry,
//and only if it has not been matched up
//in the module already.
if (dep && !mod.depMatched[i] && !processed[depId]) {
if (getOwn(traced, depId)) {
mod.defineDep(i, defined[depId])
mod.check() //pass false?
} else {
breakCycle(dep, traced, processed)
}
}
})
processed[id] = true
}
}
function checkLoaded() {
var err,
usingPathFallback,
waitInterval = config.waitSeconds * 1000,
//It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && context.startTime + waitInterval < new Date().getTime(),
noLoads = [],
reqCalls = [],
stillLoading = false,
needCycleCheck = true
//Do not bother if this call was a result of a cycle break.
if (inCheckLoaded) {
return
}
inCheckLoaded = true
//Figure out the state of all the modules.
eachProp(enabledRegistry, function (mod) {
var map = mod.map,
modId = map.id
//Skip things that are not enabled or in error state.
if (!mod.enabled) {
return
}
if (!map.isDefine) {
reqCalls.push(mod)
}
if (!mod.error) {
//If the module should be executed, and it has not
//been inited and time is up, remember it.
if (!mod.inited && expired) {
if (hasPathFallback(modId)) {
usingPathFallback = true
stillLoading = true
} else {
noLoads.push(modId)
removeScript(modId)
}
} else if (!mod.inited && mod.fetched && map.isDefine) {
stillLoading = true
if (!map.prefix) {
//No reason to keep looking for unfinished
//loading. If the only stillLoading is a
//plugin resource though, keep going,
//because it may be that a plugin resource
//is waiting on a non-plugin cycle.
return (needCycleCheck = false)
}
}
}
})
if (expired && noLoads.length) {
//If wait time expired, throw error of unloaded modules.
err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads)
err.contextName = context.contextName
return onError(err)
}
//Not expired, check for a cycle.
if (needCycleCheck) {
each(reqCalls, function (mod) {
breakCycle(mod, {}, {})
})
}
//If still waiting on loads, and the waiting load is something
//other than a plugin resource, or there are still outstanding
//scripts, then just try back later.
if ((!expired || usingPathFallback) && stillLoading) {
//Something is still waiting to load. Wait for it, but only
//if a timeout is not already in effect.
if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
checkLoadedTimeoutId = setTimeout(function () {
checkLoadedTimeoutId = 0
checkLoaded()
}, 50)
}
}
inCheckLoaded = false
}
Module = function (map) {
this.events = getOwn(undefEvents, map.id) || {}
this.map = map
this.shim = getOwn(config.shim, map.id)
this.depExports = []
this.depMaps = []
this.depMatched = []
this.pluginMaps = {}
this.depCount = 0
/* this.exports this.factory
this.depMaps = [],
this.enabled, this.fetched
*/
}
Module.prototype = {
init: function (depMaps, factory, errback, options) {
options = options || {}
//Do not do more inits if already done. Can happen if there
//are multiple define calls for the same module. That is not
//a normal, common case, but it is also not unexpected.
if (this.inited) {
return
}
this.factory = factory
if (errback) {
//Register for errors on this module.
this.on('error', errback)
} else if (this.events.error) {
//If no errback already, but there are error listeners
//on this module, set up an errback to pass to the deps.
errback = bind(this, function (err) {
this.emit('error', err)
})
}
//Do a copy of the dependency array, so that
//source inputs are not modified. For example
//"shim" deps are passed in here directly, and
//doing a direct modification of the depMaps array
//would affect that config.
this.depMaps = depMaps && depMaps.slice(0)
this.errback = errback
//Indicate this module has be initialized
this.inited = true
this.ignore = options.ignore
//Could have option to init this module in enabled mode,
//or could have been previously marked as enabled. However,
//the dependencies are not known until init is called. So
//if enabled previously, now trigger dependencies as enabled.
if (options.enabled || this.enabled) {
//Enable this module and dependencies.
//Will call this.check()
this.enable()
} else {
this.check()
}
},
defineDep: function (i, depExports) {
//Because of cycles, defined callback for a given
//export can be called more than once.
if (!this.depMatched[i]) {
this.depMatched[i] = true
this.depCount -= 1
this.depExports[i] = depExports
}
},
fetch: function () {
if (this.fetched) {
return
}
this.fetched = true
context.startTime = new Date().getTime()
var map = this.map
//If the manager is for a plugin managed resource,
//ask the plugin to load it now.
if (this.shim) {
context.makeRequire(this.map, {
enableBuildCallback: true,
})(
this.shim.deps || [],
bind(this, function () {
return map.prefix ? this.callPlugin() : this.load()
})
)
} else {
//Regular dependency.
return map.prefix ? this.callPlugin() : this.load()
}
},
load: function () {
var url = this.map.url
//Regular dependency.
if (!urlFetched[url]) {
urlFetched[url] = true
context.load(this.map.id, url)
}
},
/**
* Checks if the module is ready to define itself, and if so,
* define it.
*/
check: function () {
if (!this.enabled || this.enabling) {
return
}
var err,
cjsModule,
id = this.map.id,
depExports = this.depExports,
exports = this.exports,
factory = this.factory
if (!this.inited) {
this.fetch()
} else if (this.error) {
this.emit('error', this.error)
} else if (!this.defining) {
//The factory could trigger another require call
//that would result in checking this module to
//define itself again. If already in the process
//of doing that, skip this work.
this.defining = true
if (this.depCount < 1 && !this.defined) {
if (isFunction(factory)) {
//If there is an error listener, favor passing
//to that instead of throwing an error. However,
//only do it for define()'d modules. require
//errbacks should not be called for failures in
//their callbacks (#699). However if a global
//onError is set, use that.
if ((this.events.error && this.map.isDefine) || req.onError !== defaultOnError) {
try {
exports = context.execCb(id, factory, depExports, exports)
} catch (e) {
err = e
}
} else {
exports = context.execCb(id, factory, depExports, exports)
}
// Favor return value over exports. If node/cjs in play,
// then will not have a return value anyway. Favor
// module.exports assignment over exports object.
if (this.map.isDefine && exports === undefined) {
cjsModule = this.module
if (cjsModule) {
exports = cjsModule.exports
} else if (this.usingExports) {
//exports already set the defined value.
exports = this.exports
}
}
if (err) {
err.requireMap = this.map
err.requireModules = this.map.isDefine ? [this.map.id] : null
err.requireType = this.map.isDefine ? 'define' : 'require'
return onError((this.error = err))
}
} else {
//Just a literal value
exports = factory
}
this.exports = exports
if (this.map.isDefine && !this.ignore) {
defined[id] = exports
if (req.onResourceLoad) {
req.onResourceLoad(context, this.map, this.depMaps)
}
}
//Clean up
cleanRegistry(id)
this.defined = true
}
//Finished the define stage. Allow calling check again
//to allow define notifications below in the case of a
//cycle.
this.defining = false
if (this.defined && !this.defineEmitted) {
this.defineEmitted = true
this.emit('defined', this.exports)
this.defineEmitComplete = true
}
}
},
callPlugin: function () {
var map = this.map,
id = map.id,
//Map already normalized the prefix.
pluginMap = makeModuleMap(map.prefix)
//Mark this as a dependency for this plugin, so it
//can be traced for cycles.
this.depMaps.push(pluginMap)
on(
pluginMap,
'defined',
bind(this, function (plugin) {
var load,
normalizedMap,
normalizedMod,
bundleId = getOwn(bundlesMap, this.map.id),
name = this.map.name,
parentName = this.map.parentMap ? this.map.parentMap.name : null,
localRequire = context.makeRequire(map.parentMap, {
enableBuildCallback: true,
})
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
if (this.map.unnormalized) {
//Normalize the ID if the plugin allows it.
if (plugin.normalize) {
name =
plugin.normalize(name, function (name) {
return normalize(name, parentName, true)
}) || ''
}
//prefix and name should already be normalized, no need
//for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name, this.map.parentMap)
on(
normalizedMap,
'defined',
bind(this, function (value) {
this.init(
[],
function () {
return value
},
null,
{
enabled: true,
ignore: true,
}
)
})
)
normalizedMod = getOwn(registry, normalizedMap.id)
if (normalizedMod) {
//Mark this as a dependency for this plugin, so it
//can be traced for cycles.
this.depMaps.push(normalizedMap)
if (this.events.error) {
normalizedMod.on(
'error',
bind(this, function (err) {
this.emit('error', err)
})
)
}
normalizedMod.enable()
}
return
}
//If a paths config, then just load that file instead to
//resolve the plugin, as it is built into that paths layer.
if (bundleId) {
this.map.url = context.nameToUrl(bundleId)
this.load()
return
}
load = bind(this, function (value) {
this.init(
[],
function () {
return value
},
null,
{
enabled: true,
}
)
})
load.error = bind(this, function (err) {
this.inited = true
this.error = err
err.requireModules = [id]
//Remove temp unnormalized modules for this module,
//since they will never be resolved otherwise now.
eachProp(registry, function (mod) {
if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
cleanRegistry(mod.map.id)
}
})
onError(err)
})
//Allow plugins to load other code without having to know the
//context or how to 'complete' the load.
load.fromText = bind(this, function (text, textAlt) {
/*jslint evil: true */
var moduleName = map.name,
moduleMap = makeModuleMap(moduleName),
hasInteractive = useInteractive
//As of 2.1.0, support just passing the text, to reinforce
//fromText only being called once per resource. Still
//support old style of passing moduleName but discard
//that moduleName in favor of the internal ref.
if (textAlt) {
text = textAlt
}
//Turn off interactive script matching for IE for any define
//calls in the text, then turn it back on at the end.
if (hasInteractive) {
useInteractive = false
}
//Prime the system by creating a module instance for
//it.
getModule(moduleMap)
//Transfer any config to this other module.
if (hasProp(config.config, id)) {
config.config[moduleName] = config.config[id]
}
try {
req.exec(text)
} catch (e) {
return onError(makeError('fromtexteval', 'fromText eval for ' + id + ' failed: ' + e, e, [id]))
}
if (hasInteractive) {
useInteractive = true
}
//Mark this as a dependency for the plugin
//resource
this.depMaps.push(moduleMap)
//Support anonymous modules.
context.completeLoad(moduleName)
//Bind the value of that module to the value for this
//resource ID.
localRequire([moduleName], load)
})
//Use parentName here since the plugin's name is not reliable,
//could be some weird string with no path that actually wants to
//reference the parentName's path.
plugin.load(map.name, localRequire, load, config)
})
)
context.enable(pluginMap, this)
this.pluginMaps[pluginMap.id] = pluginMap
},
enable: function () {
enabledRegistry[this.map.id] = this
this.enabled = true
//Set flag mentioning that the module is enabling,
//so that immediate calls to the defined callbacks
//for dependencies do not trigger inadvertent load
//with the depCount still being zero.
this.enabling = true
//Enable each dependency
each(
this.depMaps,
bind(this, function (depMap, i) {
var id, mod, handler
if (typeof depMap === 'string') {
//Dependency needs to be converted to a depMap
//and wired up to this module.
depMap = makeModuleMap(depMap, this.map.isDefine ? this.map : this.map.parentMap, false, !this.skipMap)
this.depMaps[i] = depMap
handler = getOwn(handlers, depMap.id)
if (handler) {
this.depExports[i] = handler(this)
return
}
this.depCount += 1
on(
depMap,
'defined',
bind(this, function (depExports) {
this.defineDep(i, depExports)
this.check()
})
)
if (this.errback) {
on(depMap, 'error', bind(this, this.errback))
} else if (this.events.error) {
// No direct errback on this module, but something
// else is listening for errors, so be sure to
// propagate the error correctly.
on(
depMap,
'error',
bind(this, function (err) {
this.emit('error', err)
})
)
}
}
id = depMap.id
mod = registry[id]
//Skip special modules like 'require', 'exports', 'module'
//Also, don't call enable if it is already enabled,
//important in circular dependency cases.
if (!hasProp(handlers, id) && mod && !mod.enabled) {
context.enable(depMap, this)
}
})
)
//Enable each plugin that is used in
//a dependency
eachProp(
this.pluginMaps,
bind(this, function (pluginMap) {
var mod = getOwn(registry, pluginMap.id)
if (mod && !mod.enabled) {
context.enable(pluginMap, this)
}
})
)
this.enabling = false
this.check()
},
on: function (name, cb) {
var cbs = this.events[name]
if (!cbs) {
cbs = this.events[name] = []
}
cbs.push(cb)
},
emit: function (name, evt) {
each(this.events[name], function (cb) {
cb(evt)
})
if (name === 'error') {
//Now that the error handler was triggered, remove
//the listeners, since this broken Module instance
//can stay around for a while in the registry.
delete this.events[name]
}
},
}
function callGetModule(args) {
//Skip modules already defined.
if (!hasProp(defined, args[0])) {
getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2])
}
}
function removeListener(node, func, name, ieName) {
//Favor detachEvent because of IE9
//issue, see attachEvent/addEventListener comment elsewhere
//in this file.
if (node.detachEvent && !isOpera) {
//Probably IE. If not it will throw an error, which will be
//useful to know.
if (ieName) {
node.detachEvent(ieName, func)
}
} else {
node.removeEventListener(name, func, false)
}
}
/**
* Given an event from a script node, get the requirejs info from it,
* and then removes the event listeners on the node.
* @param {Event} evt
* @returns {Object}
*/
function getScriptData(evt) {
//Using currentTarget instead of target for Firefox 2.0's sake. Not
//all old browsers will be supported, but this one was easy enough
//to support and still makes sense.
var node = evt.currentTarget || evt.srcElement
//Remove the listeners once here.
removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange')
removeListener(node, context.onScriptError, 'error')
return {
node: node,
id: node && node.getAttribute('data-requiremodule'),
}
}
function intakeDefines() {
var args
//Any defined modules in the global queue, intake them now.
takeGlobalQueue()
//Make sure any remaining defQueue items get properly processed.
while (defQueue.length) {
args = defQueue.shift()
if (args[0] === null) {
return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]))
} else {
//args are id, deps, factory. Should be normalized by the
//define() function.
callGetModule(args)
}
}
}
context = {
config: config,
contextName: contextName,
registry: registry,
defined: defined,
urlFetched: urlFetched,
defQueue: defQueue,
Module: Module,
makeModuleMap: makeModuleMap,
nextTick: req.nextTick,
onError: onError,
/**
* Set a configuration for the context.
* @param {Object} cfg config object to integrate.
*/
configure: function (cfg) {
//Make sure the baseUrl ends in a slash.
if (cfg.baseUrl) {
if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
cfg.baseUrl += '/'
}
}
//Save off the paths since they require special processing,
//they are additive.
var shim = config.shim,
objs = {
paths: true,
bundles: true,
config: true,
map: true,
}
eachProp(cfg, function (value, prop) {
if (objs[prop]) {
if (!config[prop]) {
config[prop] = {}
}
mixin(config[prop], value, true, true)
} else {
config[prop] = value
}
})
//Reverse map the bundles
if (cfg.bundles) {
eachProp(cfg.bundles, function (value, prop) {
each(value, function (v) {
if (v !== prop) {
bundlesMap[v] = prop
}
})
})
}
//Merge shim
if (cfg.shim) {
eachProp(cfg.shim, function (value, id) {
//Normalize the structure
if (isArray(value)) {
value = {
deps: value,
}
}
if ((value.exports || value.init) && !value.exportsFn) {
value.exportsFn = context.makeShimExports(value)
}
shim[id] = value
})
config.shim = shim
}
//Adjust packages if necessary.
if (cfg.packages) {
each(cfg.packages, function (pkgObj) {
var location, name
pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj
name = pkgObj.name
location = pkgObj.location
if (location) {
config.paths[name] = pkgObj.location
}
//Save pointer to main module ID for pkg name.
//Remove leading dot in main, so main paths are normalized,
//and remove any trailing .js, since different package
//envs have different conventions: some use a module name,
//some use a file name.
config.pkgs[name] =
pkgObj.name + '/' + (pkgObj.main || 'main').replace(currDirRegExp, '').replace(jsSuffixRegExp, '')
})
}
//If there are any "waiting to execute" modules in the registry,
//update the maps for them, since their info, like URLs to load,
//may have changed.
eachProp(registry, function (mod, id) {
//If module already has init called, since it is too
//late to modify them, and ignore unnormalized ones
//since they are transient.
if (!mod.inited && !mod.map.unnormalized) {
mod.map = makeModuleMap(id)
}
})
//If a deps array or a config callback is specified, then call
//require with those args. This is useful when require is defined as a
//config object before require.js is loaded.
if (cfg.deps || cfg.callback) {
context.require(cfg.deps || [], cfg.callback)
}
},
makeShimExports: function (value) {
function fn() {
var ret
if (value.init) {
ret = value.init.apply(global, arguments)
}
return ret || (value.exports && getGlobal(value.exports))
}
return fn
},
makeRequire: function (relMap, options) {
options = options || {}
function localRequire(deps, callback, errback) {
var id, map, requireMod
if (options.enableBuildCallback && callback && isFunction(callback)) {
callback.__requireJsBuild = true
}
if (typeof deps === 'string') {
if (isFunction(callback)) {
//Invalid call
return onError(makeError('requireargs', 'Invalid require call'), errback)
}
//If require|exports|module are requested, get the
//value for them from the special handlers. Caveat:
//this only works while module is being defined.
if (relMap && hasProp(handlers, deps)) {
return handlers[deps](registry[relMap.id])
}
//Synchronous access to one module. If require.get is
//available (as in the Node adapter), prefer that.
if (req.get) {
return req.get(context, deps, relMap, localRequire)
}
//Normalize module name, if it contains . or ..
map = makeModuleMap(deps, relMap, false, true)
id = map.id
if (!hasProp(defined, id)) {
return onError(
makeError(
'notloaded',
'Module name "' +
id +
'" has not been loaded yet for context: ' +
contextName +
(relMap ? '' : '. Use require([])')
)
)
}
return defined[id]
}
//Grab defines waiting in the global queue.
intakeDefines()
//Mark all the dependencies as needing to be loaded.
context.nextTick(function () {
//Some defines could have been added since the
//require call, collect them.
intakeDefines()
requireMod = getModule(makeModuleMap(null, relMap))
//Store if map config should be applied to this require
//call for dependencies.
requireMod.skipMap = options.skipMap
requireMod.init(deps, callback, errback, {
enabled: true,
})
checkLoaded()
})
return localRequire
}
mixin(localRequire, {
isBrowser: isBrowser,
/**
* Converts a module name + .extension into an URL path.
* *Requires* the use of a module name. It does not support using
* plain URLs like nameToUrl.
*/
toUrl: function (moduleNamePlusExt) {
var ext,
index = moduleNamePlusExt.lastIndexOf('.'),
segment = moduleNamePlusExt.split('/')[0],
isRelative = segment === '.' || segment === '..'
//Have a file extension alias, and it is not the
//dots from a relative path.
if (index !== -1 && (!isRelative || index > 1)) {
ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length)
moduleNamePlusExt = moduleNamePlusExt.substring(0, index)
}
return context.nameToUrl(normalize(moduleNamePlusExt, relMap && relMap.id, true), ext, true)
},
defined: function (id) {
return hasProp(defined, makeModuleMap(id, relMap, false, true).id)
},
specified: function (id) {
id = makeModuleMap(id, relMap, false, true).id
return hasProp(defined, id) || hasProp(registry, id)
},
})
//Only allow undef on top level require calls
if (!relMap) {
localRequire.undef = function (id) {
//Bind any waiting define() calls to this context,
//fix for #408
takeGlobalQueue()
var map = makeModuleMap(id, relMap, true),
mod = getOwn(registry, id)
removeScript(id)
delete defined[id]
delete urlFetched[map.url]
delete undefEvents[id]
//Clean queued defines too. Go backwards
//in array so that the splices do not
//mess up the iteration.
eachReverse(defQueue, function (args, i) {
if (args[0] === id) {
defQueue.splice(i, 1)
}
})
if (mod) {
//Hold on to listeners in case the
//module will be attempted to be reloaded
//using a different config.
if (mod.events.defined) {
undefEvents[id] = mod.events
}
cleanRegistry(id)
}
}
}
return localRequire
},
/**
* Called to enable a module if it is still in the registry
* awaiting enablement. A second arg, parent, the parent module,
* is passed in for context, when this method is overridden by
* the optimizer. Not shown here to keep code compact.
*/
enable: function (depMap) {
var mod = getOwn(registry, depMap.id)
if (mod) {
getModule(depMap).enable()
}
},
/**
* Internal method used by environment adapters to complete a load event.
* A load event could be a script load or just a load pass from a synchronous
* load call.
* @param {String} moduleName the name of the module to potentially complete.
*/
completeLoad: function (moduleName) {
var found,
args,
mod,
shim = getOwn(config.shim, moduleName) || {},
shExports = shim.exports
takeGlobalQueue()
while (defQueue.length) {
args = defQueue.shift()
if (args[0] === null) {
args[0] = moduleName
//If already found an anonymous module and bound it
//to this name, then this is some other anon module
//waiting for its completeLoad to fire.
if (found) {
break
}
found = true
} else if (args[0] === moduleName) {
//Found matching define call for this script!
found = true
}
callGetModule(args)
}
//Do this after the cycle of callGetModule in case the result
//of those calls/init calls changes the registry.
mod = getOwn(registry, moduleName)
if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) {
if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
if (hasPathFallback(moduleName)) {
return
} else {
return onError(makeError('nodefine', 'No define call for ' + moduleName, null, [moduleName]))
}
} else {
//A script that does not call define(), so just simulate
//the call for it.
callGetModule([moduleName, shim.deps || [], shim.exportsFn])
}
}
checkLoaded()
},
/**
* Converts a module name to a file path. Supports cases where
* moduleName may actually be just an URL.
* Note that it **does not** call normalize on the moduleName,
* it is assumed to have already been normalized. This is an
* internal API, not a public one. Use toUrl for the public API.
*/
nameToUrl: function (moduleName, ext, skipExt) {
var paths,
syms,
i,
parentModule,
url,
parentPath,
bundleId,
pkgMain = getOwn(config.pkgs, moduleName)
if (pkgMain) {
moduleName = pkgMain
}
bundleId = getOwn(bundlesMap, moduleName)
if (bundleId) {
return context.nameToUrl(bundleId, ext, skipExt)
}
//If a colon is in the URL, it indicates a protocol is used and it is just
//an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
//or ends with .js, then assume the user meant to use an url and not a module id.
//The slash is important for protocol-less URLs as well as full paths.
if (req.jsExtRegExp.test(moduleName)) {
//Just a plain path, not module name lookup, so just return it.
//Add extension if it is included. This is a bit wonky, only non-.js things pass
//an extension, this method probably needs to be reworked.
url = moduleName + (ext || '')
} else {
//A module that needs to be converted to a path.
paths = config.paths
syms = moduleName.split('/')
//For each module name segment, see if there is a path
//registered for it. Start with most specific name
//and work up from it.
for (i = syms.length; i > 0; i -= 1) {
parentModule = syms.slice(0, i).join('/')
parentPath = getOwn(paths, parentModule)
if (parentPath) {
//If an array, it means there are a few choices,
//Choose the one that is desired
if (isArray(parentPath)) {
parentPath = parentPath[0]
}
syms.splice(0, i, parentPath)
break
}
}
//Join the path parts together, then figure out if baseUrl is needed.
url = syms.join('/')
url += ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js')
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url
}
return config.urlArgs ? url + ((url.indexOf('?') === -1 ? '?' : '&') + config.urlArgs) : url
},
//Delegates to req.load. Broken out as a separate function to
//allow overriding in the optimizer.
load: function (id, url) {
req.load(context, id, url)
},
/**
* Executes a module callback function. Broken out as a separate function
* solely to allow the build system to sequence the files in the built
* layer in the right sequence.
*
* @private
*/
execCb: function (name, callback, args, exports) {
return callback.apply(exports, args)
},
/**
* callback for script loads, used to check status of loading.
*
* @param {Event} evt the event from the browser for the script
* that was loaded.
*/
onScriptLoad: function (evt) {
//Using currentTarget instead of target for Firefox 2.0's sake. Not
//all old browsers will be supported, but this one was easy enough
//to support and still makes sense.
if (evt.type === 'load' || readyRegExp.test((evt.currentTarget || evt.srcElement).readyState)) {
//Reset interactive script so a script node is not held onto for
//to long.
interactiveScript = null
//Pull out the name of the module and the context.
var data = getScriptData(evt)
context.completeLoad(data.id)
}
},
/**
* Callback for script errors.
*/
onScriptError: function (evt) {
var data = getScriptData(evt)
if (!hasPathFallback(data.id)) {
return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id]))
}
},
}
context.require = context.makeRequire()
return context
}
/**
* Main entry point.
*
* If the only argument to require is a string, then the module that
* is represented by that string is fetched for the appropriate context.
*
* If the first argument is an array, then it will be treated as an array
* of dependency string names to fetch. An optional function callback can
* be specified to execute when all of those dependencies are available.
*
* Make a local req variable to help Caja compliance (it assumes things
* on a require that are not standardized), and to give a short
* name for minification/local scope use.
*/
req = requirejs = function (deps, callback, errback, optional) {
//Find the right context, use default
var context,
config,
contextName = defContextName
// Determine if have config object in the call.
if (!isArray(deps) && typeof deps !== 'string') {
// deps is a config object
config = deps
if (isArray(callback)) {
// Adjust args if there are dependencies
deps = callback
callback = errback
errback = optional
} else {
deps = []
}
}
if (config && config.context) {
contextName = config.context
}
context = getOwn(contexts, contextName)
if (!context) {
context = contexts[contextName] = req.s.newContext(contextName)
}
if (config) {
context.configure(config)
}
return context.require(deps, callback, errback)
}
/**
* Support require.config() to make it easier to cooperate with other
* AMD loaders on globally agreed names.
*/
req.config = function (config) {
return req(config)
}
/**
* Execute something after the current tick
* of the event loop. Override for other envs
* that have a better solution than setTimeout.
* @param {Function} fn function to execute later.
*/
req.nextTick =
typeof setTimeout !== 'undefined'
? function (fn) {
setTimeout(fn, 4)
}
: function (fn) {
fn()
}
/**
* Export require as a global, but only if it does not already exist.
*/
if (!require) {
require = req
}
req.version = version
//Used to filter out dependencies that are already paths.
req.jsExtRegExp = /^\/|:|\?|\.js$/
req.isBrowser = isBrowser
s = req.s = {
contexts: contexts,
newContext: newContext,
}
//Create default context.
req({})
//Exports some context-sensitive methods on global require.
each(['toUrl', 'undef', 'defined', 'specified'], function (prop) {
//Reference from contexts instead of early binding to default context,
//so that during builds, the latest instance of the default context
//with its config gets used.
req[prop] = function () {
var ctx = contexts[defContextName]
return ctx.require[prop].apply(ctx, arguments)
}
})
if (isBrowser) {
head = s.head = document.getElementsByTagName('head')[0]
//If BASE tag is in play, using appendChild is a problem for IE6.
//When that browser dies, this can be removed. Details in this jQuery bug:
//http://dev.jquery.com/ticket/2709
baseElement = document.getElementsByTagName('base')[0]
if (baseElement) {
head = s.head = baseElement.parentNode
}
}
/**
* Any errors that require explicitly generates will be passed to this
* function. Intercept/override it if you want custom error handling.
* @param {Error} err the error object.
*/
req.onError = defaultOnError
/**
* Creates the node for the load command. Only used in browser envs.
*/
req.createNode = function (config, moduleName, url) {
var node = config.xhtml
? document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script')
: document.createElement('script')
node.type = config.scriptType || 'text/javascript'
node.charset = 'utf-8'
node.async = true
return node
}
/**
* Does the request to load a module for the browser case.
* Make this a separate function to allow other environments
* to override it.
*
* @param {Object} context the require context to find state.
* @param {String} moduleName the name of the module.
* @param {Object} url the URL to the module.
*/
req.load = function (context, moduleName, url) {
var config = (context && context.config) || {},
node
if (isBrowser) {
//In the browser so use a script tag
node = req.createNode(config, moduleName, url)
node.setAttribute('data-requirecontext', context.contextName)
node.setAttribute('data-requiremodule', moduleName)
//Set up load listener. Test attachEvent first because IE9 has
//a subtle issue in its addEventListener and script onload firings
//that do not match the behavior of all other browsers with
//addEventListener support, which fire the onload event for a
//script right after the script execution. See:
//https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
//UNFORTUNATELY Opera implements attachEvent but does not follow the script
//script execution mode.
if (
node.attachEvent &&
//Check if node.attachEvent is artificially added by custom script or
//natively supported by browser
//read https://github.com/jrburke/requirejs/issues/187
//if we can NOT find [native code] then it must NOT natively supported.
//in IE8, node.attachEvent does not have toString()
//Note the test for "[native code" with no closing brace, see:
//https://github.com/jrburke/requirejs/issues/273
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
!isOpera
) {
//Probably IE. IE (at least 6-8) do not fire
//script onload right after executing the script, so
//we cannot tie the anonymous define call to a name.
//However, IE reports the script as being in 'interactive'
//readyState at the time of the define call.
useInteractive = true
node.attachEvent('onreadystatechange', context.onScriptLoad)
//It would be great to add an error handler here to catch
//404s in IE9+. However, onreadystatechange will fire before
//the error handler, so that does not help. If addEventListener
//is used, then IE will fire error before load, but we cannot
//use that pathway given the connect.microsoft.com issue
//mentioned above about not doing the 'script execute,
//then fire the script load event listener before execute
//next script' that other browsers do.
//Best hope: IE10 fixes the issues,
//and then destroys all installs of IE 6-9.
//node.attachEvent('onerror', context.onScriptError);
} else {
node.addEventListener('load', context.onScriptLoad, false)
node.addEventListener('error', context.onScriptError, false)
}
node.src = url
//For some cache cases in IE 6-8, the script executes before the end
//of the appendChild execution, so to tie an anonymous define
//call to the module name (which is stored on the node), hold on
//to a reference to this node, but clear after the DOM insertion.
currentlyAddingScript = node
if (baseElement) {
head.insertbeforeAll(node, baseElement)
} else {
head.appendChild(node)
}
currentlyAddingScript = null
return node
} else if (isWebWorker) {
try {
//In a web worker, use importScripts. This is not a very
//efficient use of importScripts, importScripts will block until
//its script is downloaded and evaluated. However, if web workers
//are in play, the expectation that a build has been done so that
//only one script needs to be loaded anyway. This may need to be
//reevaluated if other use cases become common.
importScripts(url)
//Account for anonymous modules
context.completeLoad(moduleName)
} catch (e) {
context.onError(
makeError('importscripts', 'importScripts failed for ' + moduleName + ' at ' + url, e, [moduleName])
)
}
}
}
function getInteractiveScript() {
if (interactiveScript && interactiveScript.readyState === 'interactive') {
return interactiveScript
}
eachReverse(scripts(), function (script) {
if (script.readyState === 'interactive') {
return (interactiveScript = script)
}
})
return interactiveScript
}
//Look for a data-main script attribute, which could also adjust the baseUrl.
if (isBrowser && !cfg.skipDataMain) {
//Figure out baseUrl. Get it from the script tag with require.js in it.
eachReverse(scripts(), function (script) {
//Set the 'head' where we can append children by
//using the script's parent.
if (!head) {
head = script.parentNode
}
//Look for a data-main attribute to set main script for the page
//to load. If it is there, the path to data main becomes the
//baseUrl, if it is not already set.
dataMain = script.getAttribute('data-main')
if (dataMain) {
//Preserve dataMain in case it is a path (i.e. contains '?')
mainScript = dataMain
//Set final baseUrl if there is not already an explicit one.
if (!cfg.baseUrl) {
//Pull off the directory of data-main for use as the
//baseUrl.
src = mainScript.split('/')
mainScript = src.pop()
subPath = src.length ? src.join('/') + '/' : './'
cfg.baseUrl = subPath
}
//Strip off any trailing .js since mainScript is now
//like a module name.
mainScript = mainScript.replace(jsSuffixRegExp, '')
//If mainScript is still a path, fall back to dataMain
if (req.jsExtRegExp.test(mainScript)) {
mainScript = dataMain
}
//Put the data-main script in the files to load.
cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript]
return true
}
})
}
/**
* The function that handles definitions of modules. Differs from
* require() in that a string for the module should be the first argument,
* and the function to execute after dependencies are loaded should
* return a value to define the module corresponding to the first argument's
* name.
*/
define = function (name, deps, callback) {
var node, context
//Allow for anonymous modules
if (typeof name !== 'string') {
//Adjust args appropriately
callback = deps
deps = name
name = null
}
//This module may not have dependencies
if (!isArray(deps)) {
callback = deps
deps = null
}
//If no name, and callback is a function, then figure out if it a
//CommonJS thing with dependencies.
if (!deps && isFunction(callback)) {
deps = []
//Remove comments from the callback string,
//look for require calls, and pull them into the dependencies,
//but only if there are function args.
if (callback.length) {
callback
.toString()
.replace(commentRegExp, '')
.replace(cjsRequireRegExp, function (match, dep) {
deps.push(dep)
})
//May be a CommonJS thing even without require calls, but still
//could use exports, and module. Avoid doing exports and module
//work though if it just needs require.
//REQUIRES the function to expect the CommonJS variables in the
//order listed below.
deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps)
}
}
//If in IE 6-8 and hit an anonymous define() call, do the interactive
//work.
if (useInteractive) {
node = currentlyAddingScript || getInteractiveScript()
if (node) {
if (!name) {
name = node.getAttribute('data-requiremodule')
}
context = contexts[node.getAttribute('data-requirecontext')]
}
}
//Always save off evaluating the def call until the script onload handler.
//This allows multiple modules to be in a file without prematurely
//tracing dependencies, and allows for anonymous module support,
//where the module name is not known until the script onload event
//occurs. If no context, use the global queue, and get it processed
//in the onscript load callback.
;(context ? context.defQueue : globalDefQueue).push([name, deps, callback])
}
define.amd = {
jQuery: true,
}
/**
* Executes the text. Normally just uses eval, but can be modified
* to use a better, environment-specific call. Only used for transpiling
* loader plugins, not for plain JS modules.
* @param {String} text the text to execute/evaluate.
*/
req.exec = function (text) {
/*jslint evil: true */
return eval(text)
}
//Set up with config info.
req(cfg)
})(this)
================================================
FILE: __test__/usage/style.css
================================================
.list {
font-family:sans-serif;
margin:0;
padding:20px 0 0;
}
.list > li {
display:block;
background-color: #eee;
padding:10px;
box-shadow: inset 0 1px 0 #fff;
}
.avatar {
max-width
gitextract_q4nl4_qg/ ├── .browserslistrc ├── .circleci/ │ └── config.yml ├── .codecov.yml ├── .github/ │ └── workflows/ │ └── ci.yml ├── .gitignore ├── .npmignore ├── .nvmrc ├── .prettierignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Release.md ├── WISHLIST.md ├── __test__/ │ ├── add-get-remove.test.js │ ├── buttons.test.js │ ├── create.test.js │ ├── defaults.test.js │ ├── filter.test.js │ ├── fixtures-fuzzysearch.js │ ├── fixtures-pagination.js │ ├── fixtures.js │ ├── fuzzysearch.test.js │ ├── item.test.js │ ├── off.test.js │ ├── on.test.js │ ├── pagination.test.js │ ├── parse.test.js │ ├── re-index.test.js │ ├── search-filter.test.js │ ├── search.test.js │ ├── show.test.js │ ├── sort.test.js │ ├── trigger.test.js │ ├── usage/ │ │ ├── amd.html │ │ ├── classic.html │ │ ├── fuzzy-search-pagination.html │ │ ├── main.js │ │ ├── require.js │ │ └── style.css │ ├── utils.classes.test.js │ └── utils.get-by-class.test.js ├── bower.json ├── dist/ │ └── list.js ├── docs/ │ ├── .bundle/ │ │ └── config │ ├── .ruby-version │ ├── CNAME │ ├── Gemfile │ ├── README.md │ ├── _config.yml │ ├── _data/ │ │ └── pkg.json │ ├── _examples/ │ │ ├── add-get-remove.html │ │ ├── data-attributes-custom-attributes.html │ │ ├── existing-list-add.html │ │ ├── existing-list.html │ │ ├── fuzzy-search.html │ │ ├── new-list.html │ │ ├── pagination.html │ │ └── table.html │ ├── _includes/ │ │ ├── author.html │ │ ├── carbon.html │ │ ├── codepen.html │ │ ├── examples/ │ │ │ └── annotated-example.html │ │ ├── javascripts/ │ │ │ └── vendor/ │ │ │ ├── bootstrap/ │ │ │ │ ├── tab.js │ │ │ │ ├── tooltip.js │ │ │ │ └── transition.js │ │ │ └── highlight.pack.js │ │ └── menu.html │ ├── _layouts/ │ │ └── default.html │ ├── _sass/ │ │ ├── _base.scss │ │ ├── _carbonads.scss │ │ ├── _docs.scss │ │ ├── _menu.scss │ │ ├── _mixins.scss │ │ ├── _normalize.scss │ │ └── vendor/ │ │ └── highlight/ │ │ └── xcode.scss │ ├── api.html │ ├── assets/ │ │ ├── css/ │ │ │ └── style.scss │ │ └── javascripts/ │ │ └── main.js │ ├── docs/ │ │ ├── fuzzysearch.html │ │ ├── index.html │ │ ├── item-api.html │ │ ├── pagination.html │ │ ├── plugins/ │ │ │ ├── build.html │ │ │ ├── fuzzysearch.html │ │ │ ├── index.html │ │ │ └── pagination.html │ │ └── search-sort.html │ ├── faq.html │ ├── feed.xml │ ├── index.html │ └── overview/ │ ├── changelog.html │ ├── contribute.html │ ├── download.html │ ├── index.html │ └── press.html ├── package.json ├── prettier.config.js ├── src/ │ ├── add-async.js │ ├── filter.js │ ├── fuzzy-search.js │ ├── index.js │ ├── item.js │ ├── pagination.js │ ├── parse.js │ ├── search.js │ ├── sort.js │ ├── templater.js │ └── utils/ │ ├── classes.js │ ├── events.js │ ├── extend.js │ ├── fuzzy.js │ ├── get-attribute.js │ ├── get-by-class.js │ ├── index-of.js │ ├── to-array.js │ └── to-string.js └── webpack.config.js
SYMBOL INDEX (44 symbols across 12 files)
FILE: __test__/buttons.test.js
function fireKeyup (line 4) | function fireKeyup(el) {
function fireClick (line 23) | function fireClick(el) {
FILE: __test__/fuzzysearch.test.js
function fireKeyup (line 5) | function fireKeyup(el) {
FILE: __test__/usage/require.js
function isFunction (line 48) | function isFunction(it) {
function isArray (line 52) | function isArray(it) {
function each (line 60) | function each(ary, func) {
function eachReverse (line 75) | function eachReverse(ary, func) {
function hasProp (line 86) | function hasProp(obj, prop) {
function getOwn (line 90) | function getOwn(obj, prop) {
function eachProp (line 99) | function eachProp(obj, func) {
function mixin (line 114) | function mixin(target, source, force, deepStringMixin) {
function bind (line 141) | function bind(obj, fn) {
function scripts (line 147) | function scripts() {
function defaultOnError (line 151) | function defaultOnError(err) {
function getGlobal (line 157) | function getGlobal(value) {
function makeError (line 176) | function makeError(id, msg, err, requireModules) {
function newContext (line 208) | function newContext(contextName) {
function getInteractiveScript (line 1997) | function getInteractiveScript() {
FILE: dist/list.js
function ClassList (line 1261) | function ClassList(el) {
function match_bitapScore_ (line 1544) | function match_bitapScore_(e, x) {
function isArray (line 1826) | function isArray(arr) {
function isNumberCode (line 1866) | function isNumberCode(code) {
function naturalCompare (line 1870) | function naturalCompare(a, b) {
function __webpack_require__ (line 1994) | function __webpack_require__(moduleId) {
FILE: docs/_includes/javascripts/vendor/bootstrap/tab.js
function next (line 68) | function next() {
FILE: docs/_includes/javascripts/vendor/bootstrap/tooltip.js
function complete (line 263) | function complete() {
FILE: docs/_includes/javascripts/vendor/bootstrap/transition.js
function transitionEnd (line 26) | function transitionEnd() {
FILE: docs/_includes/javascripts/vendor/highlight.pack.js
function l (line 1) | function l(o){return o.replace(/&/gm,"&").replace(/</gm,"<").repl...
function b (line 1) | function b(p){for(var o=p.firstChild;o;o=o.nextSibling){if(o.nodeName=="...
function h (line 1) | function h(p,o){return Array.prototype.map.call(p.childNodes,function(q)...
function a (line 1) | function a(q){var p=(q.className+" "+(q.parentNode?q.parentNode.classNam...
function c (line 1) | function c(q){var o=[];(function p(r,s){for(var t=r.firstChild;t;t=t.nex...
function j (line 1) | function j(x,v,w){var p=0;var y="";var r=[];function t(){if(x.length&&v....
function f (line 1) | function f(r){function o(s){return(s&&s.source)||s}function p(t,s){retur...
function d (line 1) | function d(E,F,C){function o(r,N){for(var M=0;M<N.c.length;M++){var L=N....
function g (line 1) | function g(s){var o={keyword_count:0,r:0,value:l(s)};var q=o;for(var p i...
function i (line 1) | function i(q,p,o){if(p){q=q.replace(/^((<[^>]+>|\t)+)/gm,function(r,v,u,...
function m (line 1) | function m(r,u,p){var v=h(r,p);var t=a(r);if(t=="no-highlight"){return}v...
function n (line 1) | function n(){if(n.called){return}n.called=true;Array.prototype.map.call(...
function k (line 1) | function k(){window.addEventListener("DOMContentLoaded",n,false);window....
FILE: src/utils/classes.js
function ClassList (line 38) | function ClassList(el) {
FILE: src/utils/fuzzy.js
function match_bitapScore_ (line 34) | function match_bitapScore_(e, x) {
FILE: src/utils/to-array.js
function isArray (line 31) | function isArray(arr) {
FILE: webpack.config.js
constant PACKAGE (line 2) | const PACKAGE = require('./package.json')
Condensed preview — 117 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (459K chars).
[
{
"path": ".browserslistrc",
"chars": 4,
"preview": "ie 9"
},
{
"path": ".circleci/config.yml",
"chars": 668,
"preview": "version: 2.1\norbs:\n node: circleci/node@4.1.0\njobs:\n test:\n executor:\n name: node/default\n parameters:\n "
},
{
"path": ".codecov.yml",
"chars": 26,
"preview": "codecov:\n branch: master\n"
},
{
"path": ".github/workflows/ci.yml",
"chars": 427,
"preview": "name: CI\n\non:\n push:\n branches:\n - master\n pull_request:\n branches:\n - '**'\n\njobs:\n build:\n runs-o"
},
{
"path": ".gitignore",
"chars": 93,
"preview": ".DS_Store\nnode_modules\ndocs/_site\ndocs/.sass-cache\ndocs/.jekyll-metadata\ncoverage\ndocs/vendor"
},
{
"path": ".npmignore",
"chars": 128,
"preview": "docs\n__test__\n.circleci\nWISHLIST.md\nwebpack.config.js\nRelease.md\nprettier.config.js\n.prettierignore\n.codecov.yml\n.browse"
},
{
"path": ".nvmrc",
"chars": 7,
"preview": "14.15.1"
},
{
"path": ".prettierignore",
"chars": 8,
"preview": "*.min.js"
},
{
"path": "CHANGELOG.md",
"chars": 13436,
"preview": "# Changelog\n\n### 2.3.1 - 2021-01-17\n\n- - **[Improvement]** #708 Support restored for Node 6, 8, 10 and 12.\n\n### 2.3.0 - "
},
{
"path": "LICENSE",
"chars": 1107,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2011-2018 Jonny Strömberg, jonnystromberg.com\n\nPermission is hereby granted, free o"
},
{
"path": "README.md",
"chars": 4330,
"preview": "# List.js\n\nPerfect library for adding **search**, **sort**, **filters** and **flexibility** to\n**tables**, **lists** and"
},
{
"path": "Release.md",
"chars": 158,
"preview": "# RELEASE\n\n1. `npm version patch|minor|major` (depending on what kind of release it is)\n2. `npm publish`\n3. Update links"
},
{
"path": "WISHLIST.md",
"chars": 1126,
"preview": "# Wishlist\n\n- Add tests for custom event handlers. 27e2d6fdeee7090eb1342a108013db898fc29b96\n- Regex in search https://gi"
},
{
"path": "__test__/add-get-remove.test.js",
"chars": 5389,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Add, get, remove', function () {\n var list\n\n beforeAll(function () {\n"
},
{
"path": "__test__/buttons.test.js",
"chars": 7346,
"preview": "const $ = require('jquery'),\n List = require('../src/index')\n\nfunction fireKeyup(el) {\n if (document.createEvent) {\n "
},
{
"path": "__test__/create.test.js",
"chars": 12861,
"preview": "const $ = require('jquery'),\n List = require('../src/index')\n\ndescribe('Create', function () {\n describe('With HTML it"
},
{
"path": "__test__/defaults.test.js",
"chars": 2493,
"preview": "const $ = require('jquery'),\n fixture = require('./fixtures')\n\ndescribe('Defaults', function () {\n var list\n\n beforeA"
},
{
"path": "__test__/filter.test.js",
"chars": 3286,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Filter', function () {\n var list, jonny, martina, angelica, sebastian,"
},
{
"path": "__test__/fixtures-fuzzysearch.js",
"chars": 1187,
"preview": "const $ = require('jquery')\n\nvar fixtureFuzzysearch = {\n list: function (valueNames) {\n var listHtml = $('<div id=\"l"
},
{
"path": "__test__/fixtures-pagination.js",
"chars": 2104,
"preview": "const $ = require('jquery')\n\nvar fixturePagination = {\n list: function (valueNames) {\n var listHtml = $('<div id=\"li"
},
{
"path": "__test__/fixtures.js",
"chars": 1131,
"preview": "const $ = require('jquery'),\n List = require('../src/index')\n\nvar fixture = {\n list: function (valueNames, items) {\n "
},
{
"path": "__test__/fuzzysearch.test.js",
"chars": 2049,
"preview": "const $ = require('jquery'),\n fixtureFuzzysearch = require('./fixtures-fuzzysearch'),\n List = require('../src/index')\n"
},
{
"path": "__test__/item.test.js",
"chars": 4450,
"preview": "const $ = require('jquery'),\n fixture = require('./fixtures')\n\ndescribe('Item', function () {\n var list, item\n\n befor"
},
{
"path": "__test__/off.test.js",
"chars": 1143,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Off', function () {\n var list\n\n beforeAll(function () {\n list = fi"
},
{
"path": "__test__/on.test.js",
"chars": 2842,
"preview": "const fixture = require('./fixtures')\n\ndescribe('On', function () {\n var list\n\n beforeEach(function () {\n list = fi"
},
{
"path": "__test__/pagination.test.js",
"chars": 16824,
"preview": "const $ = require('jquery'),\n fixturePagination = require('./fixtures-pagination'),\n List = require('../src/index')\n\nd"
},
{
"path": "__test__/parse.test.js",
"chars": 4683,
"preview": "const $ = require('jquery'),\n List = require('../src/index')\n\ndescribe('Parse', function () {\n describe('Parse class',"
},
{
"path": "__test__/re-index.test.js",
"chars": 1105,
"preview": "const $ = require('jquery'),\n fixture = require('./fixtures')\n\ndescribe('ReIndex', function () {\n var list, jonny, mar"
},
{
"path": "__test__/search-filter.test.js",
"chars": 2205,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Search and filter', function () {\n var list, jonny, martina, angelica,"
},
{
"path": "__test__/search.test.js",
"chars": 7242,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Search', function () {\n var list, jonny, martina, angelica, sebastian,"
},
{
"path": "__test__/show.test.js",
"chars": 6499,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Show', function () {\n var list, a, b, c, d, e, f\n\n beforeAll(function"
},
{
"path": "__test__/sort.test.js",
"chars": 15053,
"preview": "const $ = require('jquery'),\n fixture = require('./fixtures')\n\ndescribe('Sort', function () {\n var list, i1, i2, i3, i"
},
{
"path": "__test__/trigger.test.js",
"chars": 452,
"preview": "const fixture = require('./fixtures')\n\ndescribe('Trigger', function () {\n var list\n\n beforeAll(function () {\n list "
},
{
"path": "__test__/usage/amd.html",
"chars": 751,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n <script data-main=\"main\" src=\"require.js\"></script>\n <link rel=\"stylesheet\" href=\"style"
},
{
"path": "__test__/usage/classic.html",
"chars": 1674,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n <script src=\"../../dist/list.min.js\"></script>\n <link rel=\"stylesheet\" href=\"style.css\""
},
{
"path": "__test__/usage/fuzzy-search-pagination.html",
"chars": 1185,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=utf-8 />\n <title>Basic example</title>\n</head>\n<body>\n\n <div id=\"test-li"
},
{
"path": "__test__/usage/main.js",
"chars": 182,
"preview": "require(['../../dist/list', '../../dist/list.min'], function (List, ListMin) {\n var options = {\n valueNames: ['name'"
},
{
"path": "__test__/usage/require.js",
"chars": 69111,
"preview": "/** vim: et:ts=4:sw=4:sts=4\n * @license RequireJS 2.1.17 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserve"
},
{
"path": "__test__/usage/style.css",
"chars": 1768,
"preview": " .list {\n font-family:sans-serif;\n margin:0;\n padding:20px 0 0;\n }\n .list > li {\n display:b"
},
{
"path": "__test__/utils.classes.test.js",
"chars": 1279,
"preview": "const classes = require('../src/utils/classes')\n\ndescribe('Classes', function () {\n var el\n\n beforeEach(function () {\n"
},
{
"path": "__test__/utils.get-by-class.test.js",
"chars": 794,
"preview": "const getByClass = require('../src/utils/get-by-class')\n\ndescribe('GetByClass', function () {\n var el\n\n beforeEach(fun"
},
{
"path": "bower.json",
"chars": 506,
"preview": "{\n \"name\": \"list.js\",\n \"main\": \"dist/list.js\",\n \"homepage\": \"https://listjs.com\",\n \"authors\": [\n \"Jonny Strömberg"
},
{
"path": "dist/list.js",
"chars": 56500,
"preview": "var List;List =\n/******/ (function() { // webpackBootstrap\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ \"./src/add-asyn"
},
{
"path": "docs/.bundle/config",
"chars": 33,
"preview": "---\nBUNDLE_PATH: \"vendor/bundle\"\n"
},
{
"path": "docs/.ruby-version",
"chars": 5,
"preview": "2.7.1"
},
{
"path": "docs/CNAME",
"chars": 10,
"preview": "listjs.com"
},
{
"path": "docs/Gemfile",
"chars": 80,
"preview": "source 'https://rubygems.org'\ngroup :jekyll_plugins do\n gem 'github-pages'\nend\n"
},
{
"path": "docs/README.md",
"chars": 13,
"preview": "# listjs.com\n"
},
{
"path": "docs/_config.yml",
"chars": 599,
"preview": "title: List.js\nemail: jonny.stromberg@gmail.com\ndescription: > # this means to ignore newlines until \"baseurl:\"\n Perfec"
},
{
"path": "docs/_data/pkg.json",
"chars": 1890,
"preview": "{\n \"name\": \"list.js\",\n \"version\": \"2.3.1\",\n \"description\": \"The perfect library for lists. Supports search, sort, fil"
},
{
"path": "docs/_examples/add-get-remove.html",
"chars": 187,
"preview": "---\nlayout: default\nname: Add, get, remove\ntitle: Example to showcase the add, get and remove methods.\nurl: https://code"
},
{
"path": "docs/_examples/data-attributes-custom-attributes.html",
"chars": 200,
"preview": "---\nlayout: default\nurl: https://codepen.io/javve/pen/GZREaN\nslug: GZREaN\ntitle: Use data attributes and other custom at"
},
{
"path": "docs/_examples/existing-list-add.html",
"chars": 167,
"preview": "---\nlayout: default\nurl: https://codepen.io/javve/pen/lAmCz\nslug: lAmCz\ntitle: Existing list and add items\nname: Existin"
},
{
"path": "docs/_examples/existing-list.html",
"chars": 164,
"preview": "---\nlayout: default\nurl: https://codepen.io/javve/pen/zpuKF\nslug: zpuKF\ntitle: Basic example with existing list\nname: Ex"
},
{
"path": "docs/_examples/fuzzy-search.html",
"chars": 176,
"preview": "---\nlayout: default\nname: Fuzzy search\ntitle: Example of how to use the fuzzy search plugin\nurl: https://codepen.io/javv"
},
{
"path": "docs/_examples/new-list.html",
"chars": 156,
"preview": "---\nlayout: default\nurl: https://codepen.io/javve/pen/yroGq\nslug: yroGq\ntitle: Basic example with a new list\nname: New l"
},
{
"path": "docs/_examples/pagination.html",
"chars": 172,
"preview": "---\nlayout: default\nname: Pagination\ntitle: Example of how to use the pagination plugin\nurl: https://codepen.io/javve/pe"
},
{
"path": "docs/_examples/table.html",
"chars": 166,
"preview": "---\nlayout: default\nurl: https://codepen.io/javve/pen/oEezp\nslug: oEezp\ntitle: Example of how to use a table with List.j"
},
{
"path": "docs/_includes/author.html",
"chars": 1433,
"preview": "<div class=\"misc\">\n\n <div class=\"misc-author\">\n <img src=\"http://1.gravatar.com/avatar/9f8130715cb4c452f1294eafa1b36"
},
{
"path": "docs/_includes/carbon.html",
"chars": 148,
"preview": "<script async type=\"text/javascript\" src=\"//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=listjscom\" i"
},
{
"path": "docs/_includes/codepen.html",
"chars": 608,
"preview": "<h2>{{ page.name }}</h2>\n<p>{{ page.title }}</p>\n\n\n<p class=\"codepen\" data-height=\"700\" data-theme-id=\"light\" data-defau"
},
{
"path": "docs/_includes/examples/annotated-example.html",
"chars": 4124,
"preview": "<div class=\"annotated-examples\">\n<h2>Basic examples</h2>\n<p>\n Here is an example of a list with List.js applied. List.j"
},
{
"path": "docs/_includes/javascripts/vendor/bootstrap/tab.js",
"chars": 3433,
"preview": "/* ========================================================================\n * Bootstrap: tab.js v3.0.0\n * http://twbs.g"
},
{
"path": "docs/_includes/javascripts/vendor/bootstrap/tooltip.js",
"chars": 11915,
"preview": "/* ========================================================================\n * Bootstrap: tooltip.js v3.0.0\n * http://ge"
},
{
"path": "docs/_includes/javascripts/vendor/bootstrap/transition.js",
"chars": 1971,
"preview": "/* ========================================================================\n * Bootstrap: transition.js v3.0.0\n * http:/"
},
{
"path": "docs/_includes/javascripts/vendor/highlight.pack.js",
"chars": 9258,
"preview": "var hljs=new function(){function l(o){return o.replace(/&/gm,\"&\").replace(/</gm,\"<\").replace(/>/gm,\">\")}functi"
},
{
"path": "docs/_includes/menu.html",
"chars": 1603,
"preview": "<div class=\"docs-menu\">\n\n <h4>Overview</h4>\n <ul>\n <li {% if page.path == \"/overview/download\" %}class=\"active\"{% e"
},
{
"path": "docs/_layouts/default.html",
"chars": 5740,
"preview": "<!doctype html>\n\n<!--[if lt IE 7 ]> <html lang=\"en\" class=\"no-js ie6\"> <![endif]-->\n<!--[if IE 7 ]> <html lang=\"en\" c"
},
{
"path": "docs/_sass/_base.scss",
"chars": 2977,
"preview": "/**\n * Basic styling\n */\nbody {\n font: $base-font-weight #{$base-font-size}/#{$base-line-height} $base-font-family;\n c"
},
{
"path": "docs/_sass/_carbonads.scss",
"chars": 1825,
"preview": "@keyframes fadein {\n from {\n transform: translateY(100%);\n opacity: 0;\n }\n to {\n opacity: 1;\n transform: "
},
{
"path": "docs/_sass/_docs.scss",
"chars": 1721,
"preview": ".docs {\n display: -webkit-flex;\n display: -ms-flexbox;\n display: flex;\n\n -webkit-flex-wrap: wrap;\n -ms-flex-wrap: w"
},
{
"path": "docs/_sass/_menu.scss",
"chars": 1279,
"preview": "@-webkit-keyframes pluse {\n\t0% {\n\t\t-webkit-transform: scale(1);\n\t}\n\t80% {\n\t\t-webkit-transform: scale(1.2);\n\t}\n 100% {\n "
},
{
"path": "docs/_sass/_mixins.scss",
"chars": 261,
"preview": "%clearfix {\n &:after {\n content: \"\";\n display: table;\n clear: both;\n }\n}\n\n@mixin media-query($device) {\n @me"
},
{
"path": "docs/_sass/_normalize.scss",
"chars": 7546,
"preview": "/*! normalize.css v2.1.3 | MIT License | git.io/normalize */\n\n/* ======================================================="
},
{
"path": "docs/_sass/vendor/highlight/xcode.scss",
"chars": 2182,
"preview": "/*\n\nXCode style (c) Angel Garcia <angelgarcia.mail@gmail.com>\n\n*/\n\npre code {\n display: block; padding: 0.5em;\n backgr"
},
{
"path": "docs/api.html",
"chars": 15680,
"preview": "---\nlayout: default\ntitle: List API\nredirect_from:\n - /docs/list-api\n - /docs/options\n---\n\n<h2>\n <a name=\"parameter"
},
{
"path": "docs/assets/css/style.scss",
"chars": 12221,
"preview": "---\n# Only the main Sass file needs front matter (the dashes are enough)\n---\n\n$blue: #28a8e0;\n$green: #6cd25e;\n$grey: #5"
},
{
"path": "docs/assets/javascripts/main.js",
"chars": 308,
"preview": "---\n---\n\n{% include javascripts/vendor/jquery-1.8.3.min.js %}\n{% include javascripts/vendor/highlight.pack.js %}\n\nhljs.i"
},
{
"path": "docs/docs/fuzzysearch.html",
"chars": 3381,
"preview": "---\nlayout: default\ntitle: Fuzzy search plugin\n---\n\n<h2>Fuzzy search</h2>\n\n<p><i>\n Note: The fuzzy search plugin is\n d"
},
{
"path": "docs/docs/index.html",
"chars": 4261,
"preview": "---\nlayout: default\ntitle: Really simple example\n---\n\n<h2>Really simple examples</h2>\n<p>You can use List.js on either e"
},
{
"path": "docs/docs/item-api.html",
"chars": 2932,
"preview": "---\nlayout: default\ntitle: Item API\n---\n\n<h2>\n<a name=\"item-api\" class=\"anchor\" href=\"#item-api\"><span class=\"octicon oc"
},
{
"path": "docs/docs/pagination.html",
"chars": 3699,
"preview": "---\nlayout: default\ntitle: Pagination\n---\n\n<h2>Pagination</h2>\n\n<p><i>\n Note: The pagination plugin is\n deprecated sin"
},
{
"path": "docs/docs/plugins/build.html",
"chars": 1580,
"preview": "---\nlayout: default\ntitle: Build your own plugin\n---\n\n <h2>Build your own plugin</h2>\n\n <p>A List.js plugin is bas"
},
{
"path": "docs/docs/plugins/fuzzysearch.html",
"chars": 4103,
"preview": "---\nlayout: default\ntitle: Fuzzy search plugin\n---\n\n <h2>Fuzzy search plugin</h2>\n\n <p style=\"padding:20px; backgr"
},
{
"path": "docs/docs/plugins/index.html",
"chars": 1405,
"preview": "---\nlayout: default\ntitle: Using Plugins\n---\n\n <h2>Using plugins</h2>\n\n <h3>Getting started</h3>\n <p>To use a p"
},
{
"path": "docs/docs/plugins/pagination.html",
"chars": 4714,
"preview": "---\nlayout: default\ntitle: Pagination plugin\n---\n\n <h2>Pagination plugin</h2>\n\n <p style=\"padding:20px; background"
},
{
"path": "docs/docs/search-sort.html",
"chars": 4450,
"preview": "---\nlayout: default\ntitle: Automagical Searching + Sorting\n---\n\n<h2>\n<a name=\"searching-sorting\" class=\"anchor\" href=\"#s"
},
{
"path": "docs/faq.html",
"chars": 684,
"preview": "---\nlayout: default\ntitle: List FAQ\n---\n\n<h2>List FAQ</h2>\n\n<h4>Questions</h4>\n<ul class=\"api-index\">\n <li><a href=\"#se"
},
{
"path": "docs/feed.xml",
"chars": 1291,
"preview": "---\nlayout: null\n---\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"
},
{
"path": "docs/index.html",
"chars": 2394,
"preview": "---\nlayout: default\ntitle: Search, sort, filters, flexibility to tables, list and more!\n---\n\n<div class=\"intro\">\n <div "
},
{
"path": "docs/overview/changelog.html",
"chars": 189,
"preview": "---\nlayout: default\ntitle: Read the changelog at Github\n---\n\n<h2>Changelog</h2>\n<p><a href=\"https://github.com/javve/lis"
},
{
"path": "docs/overview/contribute.html",
"chars": 1171,
"preview": "---\nlayout: default\ntitle: Contribute\n---\n\n <h2>Setup environment</h2>\n <h4>1. Install Node.js</h4>\n <p>Go to <"
},
{
"path": "docs/overview/download.html",
"chars": 1166,
"preview": "---\nlayout: default\ntitle: Download\n---\n\n<h2>Download</h2>\n\n<p>The core thing in List.js have always been simplicity. It"
},
{
"path": "docs/overview/index.html",
"chars": 1464,
"preview": "---\nlayout: default\ntitle: TL;DR / Features\n---\n\n<h2>TL;DR</h2>\n\n<p>Perfect library for adding search, sort, filters and"
},
{
"path": "docs/overview/press.html",
"chars": 4022,
"preview": "<h1>Press</h1>\n\n<div style=\"width:49%; float:left; margin-right:1%;\">\n <blockquote class=\"twitter-tweet\"><p>List.js: na"
},
{
"path": "package.json",
"chars": 1890,
"preview": "{\n \"name\": \"list.js\",\n \"version\": \"2.3.1\",\n \"description\": \"The perfect library for lists. Supports search, sort, fil"
},
{
"path": "prettier.config.js",
"chars": 75,
"preview": "module.exports = {\n semi: false,\n singleQuote: true,\n printWidth: 120,\n}"
},
{
"path": "src/add-async.js",
"chars": 403,
"preview": "module.exports = function (list) {\n var addAsync = function (values, callback, items) {\n var valuesToAdd = values.sp"
},
{
"path": "src/filter.js",
"chars": 748,
"preview": "module.exports = function (list) {\n // Add handlers\n list.handlers.filterStart = list.handlers.filterStart || []\n lis"
},
{
"path": "src/fuzzy-search.js",
"chars": 2017,
"preview": "var classes = require('./utils/classes'),\n events = require('./utils/events'),\n extend = require('./utils/extend'),\n "
},
{
"path": "src/index.js",
"chars": 6397,
"preview": "var naturalSort = require('string-natural-compare'),\n getByClass = require('./utils/get-by-class'),\n extend = require("
},
{
"path": "src/item.js",
"chars": 1602,
"preview": "module.exports = function (list) {\n return function (initValues, element, notCreate) {\n var item = this\n\n this._v"
},
{
"path": "src/pagination.js",
"chars": 3701,
"preview": "var classes = require('./utils/classes'),\n events = require('./utils/events'),\n List = require('./index')\n\nmodule.expo"
},
{
"path": "src/parse.js",
"chars": 1256,
"preview": "module.exports = function (list) {\n var Item = require('./item')(list)\n\n var getChildren = function (parent) {\n var"
},
{
"path": "src/search.js",
"chars": 4343,
"preview": "module.exports = function (list) {\n var item, text, columns, searchString, customSearch\n\n var prepare = {\n resetLis"
},
{
"path": "src/sort.js",
"chars": 3387,
"preview": "module.exports = function (list) {\n var buttons = {\n els: undefined,\n clear: function () {\n for (var i = 0, "
},
{
"path": "src/templater.js",
"chars": 5463,
"preview": "var Templater = function (list) {\n var createItem,\n templater = this\n\n var init = function () {\n var itemSource\n"
},
{
"path": "src/utils/classes.js",
"chars": 2859,
"preview": "/**\n * Module dependencies.\n */\n\nvar index = require('./index-of')\n\n/**\n * Whitespace regexp.\n */\n\nvar re = /\\s+/\n\n/**\n "
},
{
"path": "src/utils/events.js",
"chars": 1833,
"preview": "var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',\n unbind = window.removeEventListener ? 'remove"
},
{
"path": "src/utils/extend.js",
"chars": 444,
"preview": "/*\n * Source: https://github.com/segmentio/extend\n */\n\nmodule.exports = function extend(object) {\n // Takes an unlimite"
},
{
"path": "src/utils/fuzzy.js",
"chars": 4513,
"preview": "module.exports = function (text, pattern, options) {\n // Aproximately where in the text is the pattern expected to be f"
},
{
"path": "src/utils/get-attribute.js",
"chars": 645,
"preview": "/**\n * A cross-browser implementation of getAttribute.\n * Source found here: http://stackoverflow.com/a/3755343/361337 w"
},
{
"path": "src/utils/get-by-class.js",
"chars": 1870,
"preview": "/**\n * A cross-browser implementation of getElementsByClass.\n * Heavily based on Dustin Diaz's function: http://dustindi"
},
{
"path": "src/utils/index-of.js",
"chars": 205,
"preview": "var indexOf = [].indexOf\n\nmodule.exports = function(arr, obj){\n if (indexOf) return arr.indexOf(obj);\n for (var i = 0,"
},
{
"path": "src/utils/to-array.js",
"chars": 1171,
"preview": "/**\n * Source: https://github.com/timoxley/to-array\n *\n * Convert an array-like object into an `Array`.\n * If `collectio"
},
{
"path": "src/utils/to-string.js",
"chars": 121,
"preview": "module.exports = function (s) {\n s = s === undefined ? '' : s\n s = s === null ? '' : s\n s = s.toString()\n return s\n}"
},
{
"path": "webpack.config.js",
"chars": 966,
"preview": "const webpack = require('webpack')\nconst PACKAGE = require('./package.json')\nconst TerserPlugin = require('terser-webpac"
}
]
About this extraction
This page contains the full source code of the javve/list.js GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 117 files (424.5 KB), approximately 122.5k tokens, and a symbol index with 44 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.