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 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 in options.item [See commit →](https://github.com/javve/list.js/commit/9700858168811b6559983d2cb792014213b817a6) - **[Feature]** Make it possble to add event handlers on init `new List('listId', { searchComplete: function(list) {} })`. [See commit →](https://github.com/javve/list.js/commit/b8b74f21f78c17f1c1842480084ffdb58edc26cd) - **[Bugfix]** Don't throw error if searching in a empty list. [See commit →](https://github.com/javve/list.js/commit/d805494732922024bb99090fb6521021189861e9) - **[Bugfix]** Make it possible to use item.visible() on items not yet templated. [See commit →](https://github.com/javve/list.js/commit/8e898b0e55a7d47a77ee27f109602bdb63183fda) - **[Bugfix]** Include reference to List when initializing plugins. Fix for require.js which don't have a global reference to List. [See commit →](https://github.com/javve/list.js/commit/40d3c5e5f98cf3bcb9624a5717d4435a0b6f49f6) - **[Bugfix]** Fix index async. Fix #268 [See commit →](https://github.com/javve/list.js/commit/27e2d6fdeee7090eb1342a108013db898fc29b96) - **[Bugfix]** Fix add async [See commit →](https://github.com/javve/list.js/commit/237f926d3ea0036ffb8b255dd0da42387b6a653a) - **[Bugfix]** Don't add empty item if empty list is initated with empty array. [See commit →](https://github.com/javve/list.js/commit/607a176c12b2219fb5204a789cd44ef367a0025f) - **[Bugfix]** Make sort case insensitive by default for the automatic buttons [See commit →](https://github.com/javve/list.js/commit/44260b862f74dccd248d08ca1f7df2b422c8f439) - **[Bugfix]** Clear all values from source item. Case: list.add({}) should not get same values as first item in list [See commit →](https://github.com/javve/list.js/commit/3a4733d52cff25ef99ee8a1326c0b54be81d64ca) ### 2014-02-03: 1.1.1 - **[Bugfix]** Update `javve/events` version which fixes critical bugs in Safari for PC and PhantomJS (which makes the command line tests work again). - **[Bugfix]** Clear search when clicking in the HTML5 clear button. - **[Misc]** Add History.md file for changelog instead of having it at Listjs.com. ### 2014-02-03: 1.1.0 - **[Breaking]** The sorting API is update so it looks like this `listObj.sort('name', { order: "asc "})` and `listObj.sort('name', { order: "desc "})` instead or `listObj.sort('name', { desc: true/false })`. - **[Feature]** Added support for default sort function `new List('id', { sortFunction: function(itemA, itemB) { .. }})` - **[Feature]** Adding `data-order="asc/desc"` to a sort button makes that button only sort `asc` or `desc`, ie no to - **[Bugfix]** Fix `grunt watch` bug. - **[Bugfix]** Remove sorting when searching and filtering. - **[Bugfix]** Fix sorting and search when using pagiation plugin ### 2014-01-17: 1.0.2 - **[Bugfix]** Fix error that broke the lib in IE8. ### 2013-11-12: 1.0.0 - **[Feature]** Add more events and enable to add them on initialization. - **[Feature]** Add support for Component.js, Bower, RequireJS and CommonJS - **[Feature]** Make it possible to remove event handlers by `.off('event', handler)` - **[Improvement]** Many new tests - **[Improvement]** Paging plugin default classes and structure now correspons to Twitter Bootstraps pagination. - **[Improvement]** Make sorting case-insensitive (thanks @thomasklemm) - **[Improvement]** Add item.\_values for direct access to a items values. Simplifies debugging. Note: Always use item.values() when interacting with the values. - **[Bugfix]** `.add(items, callbak)` with `callback` set does no longer add an extra item. - **[Bugfix]** `templater.set()` no longer is called twice in a `templater.get()` call. - **[Bugfix]** Fix error when trying to sort `undefined,null,etc` values. - **[Bugfix]** Fix error when trying to search `undefined,null,etc` values. - **[Bugfix]** Fix issue #51, problems with filters/search + paging. - **[Misc]** Almost completely rewritten codebase and started using Component - **[Misc]** Moved the website into another repo called list-website - **[Misc]** Add documentation for searching in specific columns. - **[Change]** `listObj.get('valueName', value)` does now always returns an array. Previously it return an object if only one item matched and null if no match was found. - **[Change]** The default sort order is now `asc` instead of `desc`. - **[Change]** Syntax for searching in specific columns are now `.search('val', [ 'columnName', 'columnName2' ])` instead of `.search('val', { columnName: true, columnName2: true })`. - **[Change]** Move plugins into seperated repos: github.com/javve/list.pagination.js and github.com/javve/list.fuzzysearch.js - **[Change]** Plugin initiation have changed. See getting started with plugins ### 2012-04-24: 0.2.1 - Fuzzy Search plugin, `.filter()` changes and bug fixes _[Read more »](http://jonnystromberg.com/listjs-0-2-1-release-notes/)_ ### 2012-01-23: 0.2.0 - Lots of updates and interesting features. _[Read more »](http://jonnystromberg.com/listjs-0-2-0-plugins-paging/)_ ### 2011-12-15: 0.1.4 - `.filters()`, `.sort()` and `.search()` now deped on each other. If the list is filtered and then there is a search, the items hidden by the filters will stay hidden etc. - `.filter()` is the only way to reset filter. `.filter(false)` does not work anymore. ### 2011-11-29: 0.1.3 release - Added function `.clear()` that removes all items from the list - Changed the sort function to be based on `data-sort` instead of `rel` - When sorting one category, all sort-related classes will be removed from the other sort buttons - Updated `.sort(valueName, sortFunction)` to `.sort(valueName, options)`, se more info in the documentation ### 2011-11-16: 0.1.2 release - Sorting is now indicated by class `asc` or `desc` at sorting buttons - Added three new small helper functions `hasClass(element, class)`, ` addClass(element, class)`` and `removeClass(element, class)` ### 2011-10-20: 0.1.1 release - Added possibility to reverse sort the list ### 2011-10-18: 0.1 release - Examples at Listjs.com works in IE7,8,9 (IE6 is not tested, should work) - More documentation - Misc bug fixes ### 2011-10-15 Final alpha 0.3 release - More documentation - Only show 200 items at same time, huge speed increase - Misc bug fixes ### 2011-08-08 Alpha 0.2 release - Added asynchronous item adding - Added asynchronous list indexing - Improved (but incomplete) documentation - Bugfixes and improved helper functions - Show helper functions non-minified ### 2011-07-25 Alpha 0.1 release ================================================ 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! [![Donate](https://s3.amazonaws.com/listjs/donate-coffee.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M7ZGHV75VSD2E) [![npm version](https://badge.fury.io/js/list.js.svg)](https://badge.fury.io/js/list.js) [![CircleCI](https://circleci.com/gh/javve/list.js/tree/master.svg?style=shield)](https://circleci.com/gh/javve/list.js/tree/master) [![codecov](https://codecov.io/gh/javve/list.js/branch/master/graph/badge.svg)](https://codecov.io/gh/javve/list.js) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/list.js/badge?style=rounded)](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. `
`,`
') $(document.body).append(listEl) var list = new List( 'list', { valueNames: ['name'], item: '', }, [{ 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 = $('
\ \
') $(document.body).append(listEl) var list = new List( 'list', { valueNames: ['name'], item: function (values) { return `
  • ` }, }, [{ 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 = $('
    \ \
    ') $(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 = $('
    \ \
    ') var templateEl = $('
  • ') $(document.body).append(listEl) $(document.body).append(templateEl) var list = new List( 'list', { valueNames: ['name'], item: 'template-item', }, [{ name: 'Jonny' }] ) it('should contain one item', function () { expect(list.items.length).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 = $( '
    \ \
    ' ) 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 = $(''), item = '' item = '
  • ' for (var i = 0; i < valueNames.length; i++) { item += '' } item += '
  • ' $(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 = $('
    '), item = '' item = '
  • ' for (var i = 0; i < valueNames.length; i++) { item += '' } item += '
  • ' $(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 = $('
    '), item = '' item = '
  • ' for (var i = 0; i < valueNames.length; i++) { item += '' } item += '
  • ' $(document.body).append(listHtml) items = items || [] return new List( 'list', { valueNames: valueNames, item: item, }, items ) }, removeList: function () { $('#list').remove() }, jonny: { name: 'Jonny Strömberg', born: '1986', }, martina: { name: 'Martina Elm', born: '1986', }, angelica: { name: 'Angelica Abraham', born: '1986', }, sebastian: { name: 'Sebastian Höglund', born: '1989', }, imma: { name: 'Imma Grafström', born: '1953', }, hasse: { name: 'Hasse Strömberg', born: '1955', }, } fixture.all = [fixture.jonny, fixture.martina, fixture.angelica, fixture.sebastian, fixture.imma, fixture.hasse] 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: "" }', function () { var list, itemHTML, pagination beforeAll(function () { itemHTML = fixturePagination.list(['name']) list = new List( 'list-pagination', { valueNames: ['name'], item: itemHTML, page: 2, pagination: { item: '', }, }, 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( $( '
    \
    \
    Jonny1986
    \
    Jocke1985
    \
    \
    ' ) ) 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( $( '
    \
    \
    \ Jonny\ 1986\ \ \
    \
    \ Jocke\ 1985\ \ \
    \
    \
    ' ) ) 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 = '
  • Sven2013' newHtml = newHtml + '
  • Anna3043' $(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: '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: "" }) i2.values({ val: "" }) i3.values({ val: "" }) i4.values({ val: "" }) i5.values({ val: "" }) i6.values({ val: "" }) 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("") expect(list.items[1].values().val).toBe("") expect(list.items[2].values().val).toBe("") expect(list.items[3].values().val).toBe("") expect(list.items[4].values().val).toBe("") expect(list.items[5].values().val).toBe("") }) 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: "" }) i2.values({ val: "" }) i3.values({ val: "" }) i4.values({ val: "" }) i5.values({ val: "" }) i6.values({ val: "" }) list.sort('val') 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("") expect(list.items[4].values().val).toBe("") expect(list.items[5].values().val).toBe("") }) 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: "" }) i2.values({ val: "" }) i3.values({ val: "" }) i4.values({ val: "" }) i5.values({ val: "" }) i6.values({ val: "" }) list.sort('val', { order: 'desc' }) expect(list.items[0].values().val).toBe("") expect(list.items[1].values().val).toBe("") expect(list.items[2].values().val).toBe("") expect(list.items[3].values().val).toBe("") expect(list.items[4].values().val).toBe("") expect(list.items[5].values().val).toBe("") }) }) }) ================================================ 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 ================================================
    • Jonny Stromberg

      1986

    • Jonas Arnklint

      1985

    • Martina Elm

      1986

    • Gustaf Lindqvist

      1983

    ================================================ FILE: __test__/usage/classic.html ================================================
    ================================================ FILE: __test__/usage/fuzzy-search-pagination.html ================================================ Basic example
      • Guybrush Threepwood

      • Manny Calavera

      • Bernard Bernoulli

      • LeChuck

      • Elaine Marley-Threepwood

      • Purple Tentacle

      • Adrian Ripburger

      • Bobbin Threadbare

      • Murray the Demonic Skull

      • Zak McKracken

        ================================================ 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: 150px; } img { max-width: 100%; } h3 { font-size: 16px; margin:0 0 0.3rem; font-weight: normal; font-weight:bold; } p { margin:0; } input { border:solid 1px #ccc; border-radius: 5px; padding:7px 14px; margin-bottom:10px } input:focus { outline:none; border-color:#aaa; } .sort { padding:8px 30px; border-radius: 6px; border:none; display:inline-block; color:#fff; text-decoration: none; background-color: #28a8e0; height:30px; } .sort:hover { text-decoration: none; background-color:#1b8aba; } .sort:focus { outline:none; } .sort:after { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 5px solid transparent; content:""; position: relative; top:-10px; right:-5px; } .sort.asc:after { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid #fff; content:""; position: relative; top:13px; right:-5px; } .sort.desc:after { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 5px solid #fff; content:""; position: relative; top:-10px; right:-5px; } ================================================ FILE: __test__/utils.classes.test.js ================================================ const classes = require('../src/utils/classes') describe('Classes', function () { var el beforeEach(function () { el = document.createElement('div') document.body.appendChild(el) }) afterEach(function () { document.body.removeChild(el) }) it('should add', function () { classes(el).add('show') expect(el.getAttribute('class')).toBe('show') }) it('should remove', function () { el.setAttribute('class', 'show') expect(el.getAttribute('class')).toBe('show') classes(el).remove('show') expect(el.getAttribute('class')).toBe('') }) it('should toggle', function () { classes(el).toggle('show') expect(el.getAttribute('class')).toBe('show') classes(el).toggle('show') expect(el.getAttribute('class')).toBe('') }) it('should array', function () { el.setAttribute('class', 'foo bar') expect(classes(el).array()).toEqual(['foo', 'bar']) }) it('should has', function () { expect(classes(el).has('show')).toBe(false) el.setAttribute('class', 'show') expect(classes(el).has('show')).toBe(true) }) it('should contains', function () { expect(classes(el).contains('show')).toBe(false) el.setAttribute('class', 'show') expect(classes(el).contains('show')).toBe(true) }) }) ================================================ FILE: __test__/utils.get-by-class.test.js ================================================ const getByClass = require('../src/utils/get-by-class') describe('GetByClass', function () { var el beforeEach(function () { el = document.createElement('div') el.setAttribute('class', 'foo') document.body.appendChild(el) }) afterEach(function () { document.body.removeChild(el) }) it('should use getElementsByClassName', function () { expect(getByClass(document.body, 'foo', false, { test: true, getElementsByClassName: true }).length).toBe(1) }) it('should use getElementsByClassName', function () { expect(getByClass(document.body, 'foo', false, { test: true, querySelector: true }).length).toBe(1) }) it('should toggle', function () { expect(getByClass(document.body, 'foo', false, { test: true, polyfill: true }).length).toBe(1) }) }) ================================================ FILE: bower.json ================================================ { "name": "list.js", "main": "dist/list.js", "homepage": "https://listjs.com", "authors": [ "Jonny Strömberg " ], "description": "The perfect library for lists. Supports search, sort, filters and flexibility. Built to be invisible and work on existing HTML", "keywords": [ "list", "search", "sort", "table", "dom", "html", "ui" ], "license": "MIT", "ignore": [ "**/.*", "node_modules", "__test__", "docs" ] } ================================================ FILE: dist/list.js ================================================ var List;List = /******/ (function() { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./src/add-async.js": /*!**************************!*\ !*** ./src/add-async.js ***! \**************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (list) { var addAsync = function addAsync(values, callback, items) { var valuesToAdd = values.splice(0, 50); items = items || []; items = items.concat(list.add(valuesToAdd)); if (values.length > 0) { setTimeout(function () { addAsync(values, callback, items); }, 1); } else { list.update(); callback(items); } }; return addAsync; }; /***/ }), /***/ "./src/filter.js": /*!***********************!*\ !*** ./src/filter.js ***! \***********************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (list) { // Add handlers list.handlers.filterStart = list.handlers.filterStart || []; list.handlers.filterComplete = list.handlers.filterComplete || []; return function (filterFunction) { list.trigger('filterStart'); list.i = 1; // Reset paging list.reset.filter(); if (filterFunction === undefined) { list.filtered = false; } else { list.filtered = true; var is = list.items; for (var i = 0, il = is.length; i < il; i++) { var item = is[i]; if (filterFunction(item)) { item.filtered = true; } else { item.filtered = false; } } } list.update(); list.trigger('filterComplete'); return list.visibleItems; }; }; /***/ }), /***/ "./src/fuzzy-search.js": /*!*****************************!*\ !*** ./src/fuzzy-search.js ***! \*****************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /*! CommonJS bailout: module.exports is used directly at 8:0-14 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { var classes = __webpack_require__(/*! ./utils/classes */ "./src/utils/classes.js"), events = __webpack_require__(/*! ./utils/events */ "./src/utils/events.js"), extend = __webpack_require__(/*! ./utils/extend */ "./src/utils/extend.js"), toString = __webpack_require__(/*! ./utils/to-string */ "./src/utils/to-string.js"), getByClass = __webpack_require__(/*! ./utils/get-by-class */ "./src/utils/get-by-class.js"), fuzzy = __webpack_require__(/*! ./utils/fuzzy */ "./src/utils/fuzzy.js"); module.exports = function (list, options) { options = options || {}; options = extend({ location: 0, distance: 100, threshold: 0.4, multiSearch: true, searchClass: 'fuzzy-search' }, options); var fuzzySearch = { search: function search(searchString, columns) { // Substract arguments from the searchString or put searchString as only argument var searchArguments = options.multiSearch ? searchString.replace(/ +$/, '').split(/ +/) : [searchString]; for (var k = 0, kl = list.items.length; k < kl; k++) { fuzzySearch.item(list.items[k], columns, searchArguments); } }, item: function item(_item, columns, searchArguments) { var found = true; for (var i = 0; i < searchArguments.length; i++) { var foundArgument = false; for (var j = 0, jl = columns.length; j < jl; j++) { if (fuzzySearch.values(_item.values(), columns[j], searchArguments[i])) { foundArgument = true; } } if (!foundArgument) { found = false; } } _item.found = found; }, values: function values(_values, value, searchArgument) { if (_values.hasOwnProperty(value)) { var text = toString(_values[value]).toLowerCase(); if (fuzzy(text, searchArgument, options)) { return true; } } return false; } }; events.bind(getByClass(list.listContainer, options.searchClass), 'keyup', list.utils.events.debounce(function (e) { var target = e.target || e.srcElement; // IE have srcElement list.search(target.value, fuzzySearch.search); }, list.searchDelay)); return function (str, columns) { list.search(str, columns, fuzzySearch.search); }; }; /***/ }), /***/ "./src/index.js": /*!**********************!*\ !*** ./src/index.js ***! \**********************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /*! CommonJS bailout: module.exports is used directly at 11:0-14 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { var naturalSort = __webpack_require__(/*! string-natural-compare */ "./node_modules/string-natural-compare/natural-compare.js"), getByClass = __webpack_require__(/*! ./utils/get-by-class */ "./src/utils/get-by-class.js"), extend = __webpack_require__(/*! ./utils/extend */ "./src/utils/extend.js"), indexOf = __webpack_require__(/*! ./utils/index-of */ "./src/utils/index-of.js"), events = __webpack_require__(/*! ./utils/events */ "./src/utils/events.js"), toString = __webpack_require__(/*! ./utils/to-string */ "./src/utils/to-string.js"), classes = __webpack_require__(/*! ./utils/classes */ "./src/utils/classes.js"), getAttribute = __webpack_require__(/*! ./utils/get-attribute */ "./src/utils/get-attribute.js"), toArray = __webpack_require__(/*! ./utils/to-array */ "./src/utils/to-array.js"); module.exports = function (id, options, values) { var self = this, init, Item = __webpack_require__(/*! ./item */ "./src/item.js")(self), addAsync = __webpack_require__(/*! ./add-async */ "./src/add-async.js")(self), initPagination = __webpack_require__(/*! ./pagination */ "./src/pagination.js")(self); init = { start: function start() { self.listClass = 'list'; self.searchClass = 'search'; self.sortClass = 'sort'; self.page = 10000; self.i = 1; self.items = []; self.visibleItems = []; self.matchingItems = []; self.searched = false; self.filtered = false; self.searchColumns = undefined; self.searchDelay = 0; self.handlers = { updated: [] }; self.valueNames = []; self.utils = { getByClass: getByClass, extend: extend, indexOf: indexOf, events: events, toString: toString, naturalSort: naturalSort, classes: classes, getAttribute: getAttribute, toArray: toArray }; self.utils.extend(self, options); self.listContainer = typeof id === 'string' ? document.getElementById(id) : id; if (!self.listContainer) { return; } self.list = getByClass(self.listContainer, self.listClass, true); self.parse = __webpack_require__(/*! ./parse */ "./src/parse.js")(self); self.templater = __webpack_require__(/*! ./templater */ "./src/templater.js")(self); self.search = __webpack_require__(/*! ./search */ "./src/search.js")(self); self.filter = __webpack_require__(/*! ./filter */ "./src/filter.js")(self); self.sort = __webpack_require__(/*! ./sort */ "./src/sort.js")(self); self.fuzzySearch = __webpack_require__(/*! ./fuzzy-search */ "./src/fuzzy-search.js")(self, options.fuzzySearch); this.handlers(); this.items(); this.pagination(); self.update(); }, handlers: function handlers() { for (var handler in self.handlers) { if (self[handler] && self.handlers.hasOwnProperty(handler)) { self.on(handler, self[handler]); } } }, items: function items() { self.parse(self.list); if (values !== undefined) { self.add(values); } }, pagination: function pagination() { if (options.pagination !== undefined) { if (options.pagination === true) { options.pagination = [{}]; } if (options.pagination[0] === undefined) { options.pagination = [options.pagination]; } for (var i = 0, il = options.pagination.length; i < il; i++) { initPagination(options.pagination[i]); } } } }; /* * Re-parse the List, use if html have changed */ this.reIndex = function () { self.items = []; self.visibleItems = []; self.matchingItems = []; self.searched = false; self.filtered = false; self.parse(self.list); }; this.toJSON = function () { var json = []; for (var i = 0, il = self.items.length; i < il; i++) { json.push(self.items[i].values()); } return json; }; /* * Add object to list */ this.add = function (values, callback) { if (values.length === 0) { return; } if (callback) { addAsync(values.slice(0), callback); return; } var added = [], notCreate = false; if (values[0] === undefined) { values = [values]; } for (var i = 0, il = values.length; i < il; i++) { var item = null; notCreate = self.items.length > self.page ? true : false; item = new Item(values[i], undefined, notCreate); self.items.push(item); added.push(item); } self.update(); return added; }; this.show = function (i, page) { this.i = i; this.page = page; self.update(); return self; }; /* Removes object from list. * Loops through the list and removes objects where * property "valuename" === value */ this.remove = function (valueName, value, options) { var found = 0; for (var i = 0, il = self.items.length; i < il; i++) { if (self.items[i].values()[valueName] == value) { self.templater.remove(self.items[i], options); self.items.splice(i, 1); il--; i--; found++; } } self.update(); return found; }; /* Gets the objects in the list which * property "valueName" === value */ this.get = function (valueName, value) { var matchedItems = []; for (var i = 0, il = self.items.length; i < il; i++) { var item = self.items[i]; if (item.values()[valueName] == value) { matchedItems.push(item); } } return matchedItems; }; /* * Get size of the list */ this.size = function () { return self.items.length; }; /* * Removes all items from the list */ this.clear = function () { self.templater.clear(); self.items = []; return self; }; this.on = function (event, callback) { self.handlers[event].push(callback); return self; }; this.off = function (event, callback) { var e = self.handlers[event]; var index = indexOf(e, callback); if (index > -1) { e.splice(index, 1); } return self; }; this.trigger = function (event) { var i = self.handlers[event].length; while (i--) { self.handlers[event][i](self); } return self; }; this.reset = { filter: function filter() { var is = self.items, il = is.length; while (il--) { is[il].filtered = false; } return self; }, search: function search() { var is = self.items, il = is.length; while (il--) { is[il].found = false; } return self; } }; this.update = function () { var is = self.items, il = is.length; self.visibleItems = []; self.matchingItems = []; self.templater.clear(); for (var i = 0; i < il; i++) { if (is[i].matching() && self.matchingItems.length + 1 >= self.i && self.visibleItems.length < self.page) { is[i].show(); self.visibleItems.push(is[i]); self.matchingItems.push(is[i]); } else if (is[i].matching()) { self.matchingItems.push(is[i]); is[i].hide(); } else { is[i].hide(); } } self.trigger('updated'); return self; }; init.start(); }; /***/ }), /***/ "./src/item.js": /*!*********************!*\ !*** ./src/item.js ***! \*********************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (list) { return function (initValues, element, notCreate) { var item = this; this._values = {}; this.found = false; // Show if list.searched == true and this.found == true this.filtered = false; // Show if list.filtered == true and this.filtered == true var init = function init(initValues, element, notCreate) { if (element === undefined) { if (notCreate) { item.values(initValues, notCreate); } else { item.values(initValues); } } else { item.elm = element; var values = list.templater.get(item, initValues); item.values(values); } }; this.values = function (newValues, notCreate) { if (newValues !== undefined) { for (var name in newValues) { item._values[name] = newValues[name]; } if (notCreate !== true) { list.templater.set(item, item.values()); } } else { return item._values; } }; this.show = function () { list.templater.show(item); }; this.hide = function () { list.templater.hide(item); }; this.matching = function () { return list.filtered && list.searched && item.found && item.filtered || list.filtered && !list.searched && item.filtered || !list.filtered && list.searched && item.found || !list.filtered && !list.searched; }; this.visible = function () { return item.elm && item.elm.parentNode == list.list ? true : false; }; init(initValues, element, notCreate); }; }; /***/ }), /***/ "./src/pagination.js": /*!***************************!*\ !*** ./src/pagination.js ***! \***************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /*! CommonJS bailout: module.exports is used directly at 5:0-14 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { var classes = __webpack_require__(/*! ./utils/classes */ "./src/utils/classes.js"), events = __webpack_require__(/*! ./utils/events */ "./src/utils/events.js"), List = __webpack_require__(/*! ./index */ "./src/index.js"); module.exports = function (list) { var isHidden = false; var refresh = function refresh(pagingList, options) { if (list.page < 1) { list.listContainer.style.display = 'none'; isHidden = true; return; } else if (isHidden) { list.listContainer.style.display = 'block'; } var item, l = list.matchingItems.length, index = list.i, page = list.page, pages = Math.ceil(l / page), currentPage = Math.ceil(index / page), innerWindow = options.innerWindow || 2, left = options.left || options.outerWindow || 0, right = options.right || options.outerWindow || 0; right = pages - right; pagingList.clear(); for (var i = 1; i <= pages; i++) { var className = currentPage === i ? 'active' : ''; //console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className); if (is.number(i, left, right, currentPage, innerWindow)) { item = pagingList.add({ page: i, dotted: false })[0]; if (className) { classes(item.elm).add(className); } item.elm.firstChild.setAttribute('data-i', i); item.elm.firstChild.setAttribute('data-page', page); } else if (is.dotted(pagingList, i, left, right, currentPage, innerWindow, pagingList.size())) { item = pagingList.add({ page: '...', dotted: true })[0]; classes(item.elm).add('disabled'); } } }; var is = { number: function number(i, left, right, currentPage, innerWindow) { return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow); }, left: function left(i, _left) { return i <= _left; }, right: function right(i, _right) { return i > _right; }, innerWindow: function innerWindow(i, currentPage, _innerWindow) { return i >= currentPage - _innerWindow && i <= currentPage + _innerWindow; }, dotted: function dotted(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) { return this.dottedLeft(pagingList, i, left, right, currentPage, innerWindow) || this.dottedRight(pagingList, i, left, right, currentPage, innerWindow, currentPageItem); }, dottedLeft: function dottedLeft(pagingList, i, left, right, currentPage, innerWindow) { return i == left + 1 && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right); }, dottedRight: function dottedRight(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) { if (pagingList.items[currentPageItem - 1].values().dotted) { return false; } else { return i == right && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right); } } }; return function (options) { var pagingList = new List(list.listContainer.id, { listClass: options.paginationClass || 'pagination', item: options.item || "
      • ", valueNames: ['page', 'dotted'], searchClass: 'pagination-search-that-is-not-supposed-to-exist', sortClass: 'pagination-sort-that-is-not-supposed-to-exist' }); events.bind(pagingList.listContainer, 'click', function (e) { var target = e.target || e.srcElement, page = list.utils.getAttribute(target, 'data-page'), i = list.utils.getAttribute(target, 'data-i'); if (i) { list.show((i - 1) * page + 1, page); } }); list.on('updated', function () { refresh(pagingList, options); }); refresh(pagingList, options); }; }; /***/ }), /***/ "./src/parse.js": /*!**********************!*\ !*** ./src/parse.js ***! \**********************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { module.exports = function (list) { var Item = __webpack_require__(/*! ./item */ "./src/item.js")(list); var getChildren = function getChildren(parent) { var nodes = parent.childNodes, items = []; for (var i = 0, il = nodes.length; i < il; i++) { // Only textnodes have a data attribute if (nodes[i].data === undefined) { items.push(nodes[i]); } } return items; }; var parse = function parse(itemElements, valueNames) { for (var i = 0, il = itemElements.length; i < il; i++) { list.items.push(new Item(valueNames, itemElements[i])); } }; var parseAsync = function parseAsync(itemElements, valueNames) { var itemsToIndex = itemElements.splice(0, 50); // TODO: If < 100 items, what happens in IE etc? parse(itemsToIndex, valueNames); if (itemElements.length > 0) { setTimeout(function () { parseAsync(itemElements, valueNames); }, 1); } else { list.update(); list.trigger('parseComplete'); } }; list.handlers.parseComplete = list.handlers.parseComplete || []; return function () { var itemsToIndex = getChildren(list.list), valueNames = list.valueNames; if (list.indexAsync) { parseAsync(itemsToIndex, valueNames); } else { parse(itemsToIndex, valueNames); } }; }; /***/ }), /***/ "./src/search.js": /*!***********************!*\ !*** ./src/search.js ***! \***********************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (_list) { var item, text, columns, searchString, customSearch; var prepare = { resetList: function resetList() { _list.i = 1; _list.templater.clear(); customSearch = undefined; }, setOptions: function setOptions(args) { if (args.length == 2 && args[1] instanceof Array) { columns = args[1]; } else if (args.length == 2 && typeof args[1] == 'function') { columns = undefined; customSearch = args[1]; } else if (args.length == 3) { columns = args[1]; customSearch = args[2]; } else { columns = undefined; } }, setColumns: function setColumns() { if (_list.items.length === 0) return; if (columns === undefined) { columns = _list.searchColumns === undefined ? prepare.toArray(_list.items[0].values()) : _list.searchColumns; } }, setSearchString: function setSearchString(s) { s = _list.utils.toString(s).toLowerCase(); s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&'); // Escape regular expression characters searchString = s; }, toArray: function toArray(values) { var tmpColumn = []; for (var name in values) { tmpColumn.push(name); } return tmpColumn; } }; var search = { list: function list() { // Extract quoted phrases "word1 word2" from original searchString // searchString is converted to lowercase by List.js var words = [], phrase, ss = searchString; while ((phrase = ss.match(/"([^"]+)"/)) !== null) { words.push(phrase[1]); ss = ss.substring(0, phrase.index) + ss.substring(phrase.index + phrase[0].length); } // Get remaining space-separated words (if any) ss = ss.trim(); if (ss.length) words = words.concat(ss.split(/\s+/)); for (var k = 0, kl = _list.items.length; k < kl; k++) { var item = _list.items[k]; item.found = false; if (!words.length) continue; for (var i = 0, il = words.length; i < il; i++) { var word_found = false; for (var j = 0, jl = columns.length; j < jl; j++) { var values = item.values(), column = columns[j]; if (values.hasOwnProperty(column) && values[column] !== undefined && values[column] !== null) { var text = typeof values[column] !== 'string' ? values[column].toString() : values[column]; if (text.toLowerCase().indexOf(words[i]) !== -1) { // word found, so no need to check it against any other columns word_found = true; break; } } } // this word not found? no need to check any other words, the item cannot match if (!word_found) break; } item.found = word_found; } }, // Removed search.item() and search.values() reset: function reset() { _list.reset.search(); _list.searched = false; } }; var searchMethod = function searchMethod(str) { _list.trigger('searchStart'); prepare.resetList(); prepare.setSearchString(str); prepare.setOptions(arguments); // str, cols|searchFunction, searchFunction prepare.setColumns(); if (searchString === '') { search.reset(); } else { _list.searched = true; if (customSearch) { customSearch(searchString, columns); } else { search.list(); } } _list.update(); _list.trigger('searchComplete'); return _list.visibleItems; }; _list.handlers.searchStart = _list.handlers.searchStart || []; _list.handlers.searchComplete = _list.handlers.searchComplete || []; _list.utils.events.bind(_list.utils.getByClass(_list.listContainer, _list.searchClass), 'keyup', _list.utils.events.debounce(function (e) { var target = e.target || e.srcElement, // IE have srcElement alreadyCleared = target.value === '' && !_list.searched; if (!alreadyCleared) { // If oninput already have resetted the list, do nothing searchMethod(target.value); } }, _list.searchDelay)); // Used to detect click on HTML5 clear button _list.utils.events.bind(_list.utils.getByClass(_list.listContainer, _list.searchClass), 'input', function (e) { var target = e.target || e.srcElement; if (target.value === '') { searchMethod(''); } }); return searchMethod; }; /***/ }), /***/ "./src/sort.js": /*!*********************!*\ !*** ./src/sort.js ***! \*********************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (list) { var buttons = { els: undefined, clear: function clear() { for (var i = 0, il = buttons.els.length; i < il; i++) { list.utils.classes(buttons.els[i]).remove('asc'); list.utils.classes(buttons.els[i]).remove('desc'); } }, getOrder: function getOrder(btn) { var predefinedOrder = list.utils.getAttribute(btn, 'data-order'); if (predefinedOrder == 'asc' || predefinedOrder == 'desc') { return predefinedOrder; } else if (list.utils.classes(btn).has('desc')) { return 'asc'; } else if (list.utils.classes(btn).has('asc')) { return 'desc'; } else { return 'asc'; } }, getInSensitive: function getInSensitive(btn, options) { var insensitive = list.utils.getAttribute(btn, 'data-insensitive'); if (insensitive === 'false') { options.insensitive = false; } else { options.insensitive = true; } }, setOrder: function setOrder(options) { for (var i = 0, il = buttons.els.length; i < il; i++) { var btn = buttons.els[i]; if (list.utils.getAttribute(btn, 'data-sort') !== options.valueName) { continue; } var predefinedOrder = list.utils.getAttribute(btn, 'data-order'); if (predefinedOrder == 'asc' || predefinedOrder == 'desc') { if (predefinedOrder == options.order) { list.utils.classes(btn).add(options.order); } } else { list.utils.classes(btn).add(options.order); } } } }; var sort = function sort() { list.trigger('sortStart'); var options = {}; var target = arguments[0].currentTarget || arguments[0].srcElement || undefined; if (target) { options.valueName = list.utils.getAttribute(target, 'data-sort'); buttons.getInSensitive(target, options); options.order = buttons.getOrder(target); } else { options = arguments[1] || options; options.valueName = arguments[0]; options.order = options.order || 'asc'; options.insensitive = typeof options.insensitive == 'undefined' ? true : options.insensitive; } buttons.clear(); buttons.setOrder(options); // caseInsensitive // alphabet var customSortFunction = options.sortFunction || list.sortFunction || null, multi = options.order === 'desc' ? -1 : 1, sortFunction; if (customSortFunction) { sortFunction = function sortFunction(itemA, itemB) { return customSortFunction(itemA, itemB, options) * multi; }; } else { sortFunction = function sortFunction(itemA, itemB) { var sort = list.utils.naturalSort; sort.alphabet = list.alphabet || options.alphabet || undefined; if (!sort.alphabet && options.insensitive) { sort = list.utils.naturalSort.caseInsensitive; } return sort(itemA.values()[options.valueName], itemB.values()[options.valueName]) * multi; }; } list.items.sort(sortFunction); list.update(); list.trigger('sortComplete'); }; // Add handlers list.handlers.sortStart = list.handlers.sortStart || []; list.handlers.sortComplete = list.handlers.sortComplete || []; buttons.els = list.utils.getByClass(list.listContainer, list.sortClass); list.utils.events.bind(buttons.els, 'click', sort); list.on('searchStart', buttons.clear); list.on('filterStart', buttons.clear); return sort; }; /***/ }), /***/ "./src/templater.js": /*!**************************!*\ !*** ./src/templater.js ***! \**************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 216:0-14 */ /***/ (function(module) { var Templater = function Templater(list) { var createItem, templater = this; var init = function init() { var itemSource; if (typeof list.item === 'function') { createItem = function createItem(values) { var item = list.item(values); return getItemSource(item); }; return; } if (typeof list.item === 'string') { if (list.item.indexOf('<') === -1) { itemSource = document.getElementById(list.item); } else { itemSource = getItemSource(list.item); } } else { /* If item source does not exists, use the first item in list as source for new items */ itemSource = getFirstListItem(); } if (!itemSource) { throw new Error("The list needs to have at least one item on init otherwise you'll have to add a template."); } itemSource = createCleanTemplateItem(itemSource, list.valueNames); createItem = function createItem() { return itemSource.cloneNode(true); }; }; var createCleanTemplateItem = function createCleanTemplateItem(templateNode, valueNames) { var el = templateNode.cloneNode(true); el.removeAttribute('id'); for (var i = 0, il = valueNames.length; i < il; i++) { var elm = undefined, valueName = valueNames[i]; if (valueName.data) { for (var j = 0, jl = valueName.data.length; j < jl; j++) { el.setAttribute('data-' + valueName.data[j], ''); } } else if (valueName.attr && valueName.name) { elm = list.utils.getByClass(el, valueName.name, true); if (elm) { elm.setAttribute(valueName.attr, ''); } } else { elm = list.utils.getByClass(el, valueName, true); if (elm) { elm.innerHTML = ''; } } } return el; }; var getFirstListItem = function getFirstListItem() { var nodes = list.list.childNodes; for (var i = 0, il = nodes.length; i < il; i++) { // Only textnodes have a data attribute if (nodes[i].data === undefined) { return nodes[i].cloneNode(true); } } return undefined; }; var getItemSource = function getItemSource(itemHTML) { if (typeof itemHTML !== 'string') return undefined; if (/]/g.exec(itemHTML)) { var tbody = document.createElement('tbody'); tbody.innerHTML = itemHTML; return tbody.firstElementChild; } else if (itemHTML.indexOf('<') !== -1) { var div = document.createElement('div'); div.innerHTML = itemHTML; return div.firstElementChild; } return undefined; }; var getValueName = function getValueName(name) { for (var i = 0, il = list.valueNames.length; i < il; i++) { var valueName = list.valueNames[i]; if (valueName.data) { var data = valueName.data; for (var j = 0, jl = data.length; j < jl; j++) { if (data[j] === name) { return { data: name }; } } } else if (valueName.attr && valueName.name && valueName.name == name) { return valueName; } else if (valueName === name) { return name; } } }; var setValue = function setValue(item, name, value) { var elm = undefined, valueName = getValueName(name); if (!valueName) return; if (valueName.data) { item.elm.setAttribute('data-' + valueName.data, value); } else if (valueName.attr && valueName.name) { elm = list.utils.getByClass(item.elm, valueName.name, true); if (elm) { elm.setAttribute(valueName.attr, value); } } else { elm = list.utils.getByClass(item.elm, valueName, true); if (elm) { elm.innerHTML = value; } } }; this.get = function (item, valueNames) { templater.create(item); var values = {}; for (var i = 0, il = valueNames.length; i < il; i++) { var elm = undefined, valueName = valueNames[i]; if (valueName.data) { for (var j = 0, jl = valueName.data.length; j < jl; j++) { values[valueName.data[j]] = list.utils.getAttribute(item.elm, 'data-' + valueName.data[j]); } } else if (valueName.attr && valueName.name) { elm = list.utils.getByClass(item.elm, valueName.name, true); values[valueName.name] = elm ? list.utils.getAttribute(elm, valueName.attr) : ''; } else { elm = list.utils.getByClass(item.elm, valueName, true); values[valueName] = elm ? elm.innerHTML : ''; } } return values; }; this.set = function (item, values) { if (!templater.create(item)) { for (var v in values) { if (values.hasOwnProperty(v)) { setValue(item, v, values[v]); } } } }; this.create = function (item) { if (item.elm !== undefined) { return false; } item.elm = createItem(item.values()); templater.set(item, item.values()); return true; }; this.remove = function (item) { if (item.elm.parentNode === list.list) { list.list.removeChild(item.elm); } }; this.show = function (item) { templater.create(item); list.list.appendChild(item.elm); }; this.hide = function (item) { if (item.elm !== undefined && item.elm.parentNode === list.list) { list.list.removeChild(item.elm); } }; this.clear = function () { /* .innerHTML = ''; fucks up IE */ if (list.list.hasChildNodes()) { while (list.list.childNodes.length >= 1) { list.list.removeChild(list.list.firstChild); } } }; init(); }; module.exports = function (list) { return new Templater(list); }; /***/ }), /***/ "./src/utils/classes.js": /*!******************************!*\ !*** ./src/utils/classes.js ***! \******************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /*! CommonJS bailout: module.exports is used directly at 24:0-14 */ /***/ (function(module, __unused_webpack_exports, __webpack_require__) { /** * Module dependencies. */ var index = __webpack_require__(/*! ./index-of */ "./src/utils/index-of.js"); /** * Whitespace regexp. */ var re = /\s+/; /** * toString reference. */ var toString = Object.prototype.toString; /** * Wrap `el` in a `ClassList`. * * @param {Element} el * @return {ClassList} * @api public */ module.exports = function (el) { return new ClassList(el); }; /** * Initialize a new ClassList for `el`. * * @param {Element} el * @api private */ function ClassList(el) { if (!el || !el.nodeType) { throw new Error('A DOM element reference is required'); } this.el = el; this.list = el.classList; } /** * Add class `name` if not already present. * * @param {String} name * @return {ClassList} * @api public */ ClassList.prototype.add = function (name) { // classList if (this.list) { this.list.add(name); return this; } // fallback var arr = this.array(); var i = index(arr, name); if (!~i) arr.push(name); this.el.className = arr.join(' '); return this; }; /** * Remove class `name` when present, or * pass a regular expression to remove * any which match. * * @param {String|RegExp} name * @return {ClassList} * @api public */ ClassList.prototype.remove = function (name) { // classList if (this.list) { this.list.remove(name); return this; } // fallback var arr = this.array(); var i = index(arr, name); if (~i) arr.splice(i, 1); this.el.className = arr.join(' '); return this; }; /** * Toggle class `name`, can force state via `force`. * * For browsers that support classList, but do not support `force` yet, * the mistake will be detected and corrected. * * @param {String} name * @param {Boolean} force * @return {ClassList} * @api public */ ClassList.prototype.toggle = function (name, force) { // classList if (this.list) { if ('undefined' !== typeof force) { if (force !== this.list.toggle(name, force)) { this.list.toggle(name); // toggle again to correct } } else { this.list.toggle(name); } return this; } // fallback if ('undefined' !== typeof force) { if (!force) { this.remove(name); } else { this.add(name); } } else { if (this.has(name)) { this.remove(name); } else { this.add(name); } } return this; }; /** * Return an array of classes. * * @return {Array} * @api public */ ClassList.prototype.array = function () { var className = this.el.getAttribute('class') || ''; var str = className.replace(/^\s+|\s+$/g, ''); var arr = str.split(re); if ('' === arr[0]) arr.shift(); return arr; }; /** * Check if class `name` is present. * * @param {String} name * @return {ClassList} * @api public */ ClassList.prototype.has = ClassList.prototype.contains = function (name) { return this.list ? this.list.contains(name) : !!~index(this.array(), name); }; /***/ }), /***/ "./src/utils/events.js": /*!*****************************!*\ !*** ./src/utils/events.js ***! \*****************************/ /*! default exports */ /*! export bind [provided] [no usage info] [missing usage info prevents renaming] */ /*! export debounce [provided] [no usage info] [missing usage info prevents renaming] */ /*! export unbind [provided] [no usage info] [missing usage info prevents renaming] */ /*! other exports [not provided] [no usage info] */ /*! runtime requirements: __webpack_exports__, __webpack_require__ */ /***/ (function(__unused_webpack_module, exports, __webpack_require__) { var bind = window.addEventListener ? 'addEventListener' : 'attachEvent', unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent', prefix = bind !== 'addEventListener' ? 'on' : '', toArray = __webpack_require__(/*! ./to-array */ "./src/utils/to-array.js"); /** * Bind `el` event `type` to `fn`. * * @param {Element} el, NodeList, HTMLCollection or Array * @param {String} type * @param {Function} fn * @param {Boolean} capture * @api public */ exports.bind = function (el, type, fn, capture) { el = toArray(el); for (var i = 0, il = el.length; i < il; i++) { el[i][bind](prefix + type, fn, capture || false); } }; /** * Unbind `el` event `type`'s callback `fn`. * * @param {Element} el, NodeList, HTMLCollection or Array * @param {String} type * @param {Function} fn * @param {Boolean} capture * @api public */ exports.unbind = function (el, type, fn, capture) { el = toArray(el); for (var i = 0, il = el.length; i < il; i++) { el[i][unbind](prefix + type, fn, capture || false); } }; /** * Returns a function, that, as long as it continues to be invoked, will not * be triggered. The function will be called after it stops being called for * `wait` milliseconds. If `immediate` is true, trigger the function on the * leading edge, instead of the trailing. * * @param {Function} fn * @param {Integer} wait * @param {Boolean} immediate * @api public */ exports.debounce = function (fn, wait, immediate) { var timeout; return wait ? function () { var context = this, args = arguments; var later = function later() { timeout = null; if (!immediate) fn.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) fn.apply(context, args); } : fn; }; /***/ }), /***/ "./src/utils/extend.js": /*!*****************************!*\ !*** ./src/utils/extend.js ***! \*****************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 4:0-14 */ /***/ (function(module) { /* * Source: https://github.com/segmentio/extend */ module.exports = function extend(object) { // Takes an unlimited number of extenders. var args = Array.prototype.slice.call(arguments, 1); // For each extender, copy their properties on our object. for (var i = 0, source; source = args[i]; i++) { if (!source) continue; for (var property in source) { object[property] = source[property]; } } return object; }; /***/ }), /***/ "./src/utils/fuzzy.js": /*!****************************!*\ !*** ./src/utils/fuzzy.js ***! \****************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (text, pattern, options) { // Aproximately where in the text is the pattern expected to be found? var Match_Location = options.location || 0; //Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is 'distance' characters away from the fuzzy location would score as a complete mismatch. A distance of '0' requires the match be at the exact location specified, a threshold of '1000' would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. var Match_Distance = options.distance || 100; // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match (of both letters and location), a threshold of '1.0' would match anything. var Match_Threshold = options.threshold || 0.4; if (pattern === text) return true; // Exact match if (pattern.length > 32) return false; // This algorithm cannot be used // Set starting location at beginning text and initialise the alphabet. var loc = Match_Location, s = function () { var q = {}, i; for (i = 0; i < pattern.length; i++) { q[pattern.charAt(i)] = 0; } for (i = 0; i < pattern.length; i++) { q[pattern.charAt(i)] |= 1 << pattern.length - i - 1; } return q; }(); // Compute and return the score for a match with e errors and x location. // Accesses loc and pattern through being a closure. function match_bitapScore_(e, x) { var accuracy = e / pattern.length, proximity = Math.abs(loc - x); if (!Match_Distance) { // Dodge divide by zero error. return proximity ? 1.0 : accuracy; } return accuracy + proximity / Match_Distance; } var score_threshold = Match_Threshold, // Highest score beyond which we give up. best_loc = text.indexOf(pattern, loc); // Is there a nearby exact match? (speedup) if (best_loc != -1) { score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold); // What about in the other direction? (speedup) best_loc = text.lastIndexOf(pattern, loc + pattern.length); if (best_loc != -1) { score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold); } } // Initialise the bit arrays. var matchmask = 1 << pattern.length - 1; best_loc = -1; var bin_min, bin_mid; var bin_max = pattern.length + text.length; var last_rd; for (var d = 0; d < pattern.length; d++) { // Scan for the best match; each iteration allows for one more error. // Run a binary search to determine how far from 'loc' we can stray at this // error level. bin_min = 0; bin_mid = bin_max; while (bin_min < bin_mid) { if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) { bin_min = bin_mid; } else { bin_max = bin_mid; } bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min); } // Use the result from this iteration as the maximum for the next. bin_max = bin_mid; var start = Math.max(1, loc - bin_mid + 1); var finish = Math.min(loc + bin_mid, text.length) + pattern.length; var rd = Array(finish + 2); rd[finish + 1] = (1 << d) - 1; for (var j = finish; j >= start; j--) { // The alphabet (s) is a sparse hash, so the following line generates // warnings. var charMatch = s[text.charAt(j - 1)]; if (d === 0) { // First pass: exact match. rd[j] = (rd[j + 1] << 1 | 1) & charMatch; } else { // Subsequent passes: fuzzy match. rd[j] = (rd[j + 1] << 1 | 1) & charMatch | ((last_rd[j + 1] | last_rd[j]) << 1 | 1) | last_rd[j + 1]; } if (rd[j] & matchmask) { var score = match_bitapScore_(d, j - 1); // This match will almost certainly be better than any existing match. // But check anyway. if (score <= score_threshold) { // Told you so. score_threshold = score; best_loc = j - 1; if (best_loc > loc) { // When passing loc, don't exceed our current distance from loc. start = Math.max(1, 2 * loc - best_loc); } else { // Already passed loc, downhill from here on in. break; } } } } // No hope for a (better) match at greater error levels. if (match_bitapScore_(d + 1, loc) > score_threshold) { break; } last_rd = rd; } return best_loc < 0 ? false : true; }; /***/ }), /***/ "./src/utils/get-attribute.js": /*!************************************!*\ !*** ./src/utils/get-attribute.js ***! \************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 11:0-14 */ /***/ (function(module) { /** * A cross-browser implementation of getAttribute. * Source found here: http://stackoverflow.com/a/3755343/361337 written by Vivin Paliath * * Return the value for `attr` at `element`. * * @param {Element} el * @param {String} attr * @api public */ module.exports = function (el, attr) { var result = el.getAttribute && el.getAttribute(attr) || null; if (!result) { var attrs = el.attributes; var length = attrs.length; for (var i = 0; i < length; i++) { if (attrs[i] !== undefined) { if (attrs[i].nodeName === attr) { result = attrs[i].nodeValue; } } } } return result; }; /***/ }), /***/ "./src/utils/get-by-class.js": /*!***********************************!*\ !*** ./src/utils/get-by-class.js ***! \***********************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 53:0-14 */ /***/ (function(module) { /** * A cross-browser implementation of getElementsByClass. * Heavily based on Dustin Diaz's function: http://dustindiaz.com/getelementsbyclass. * * Find all elements with class `className` inside `container`. * Use `single = true` to increase performance in older browsers * when only one element is needed. * * @param {String} className * @param {Element} container * @param {Boolean} single * @api public */ var getElementsByClassName = function getElementsByClassName(container, className, single) { if (single) { return container.getElementsByClassName(className)[0]; } else { return container.getElementsByClassName(className); } }; var querySelector = function querySelector(container, className, single) { className = '.' + className; if (single) { return container.querySelector(className); } else { return container.querySelectorAll(className); } }; var polyfill = function polyfill(container, className, single) { var classElements = [], tag = '*'; var els = container.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp('(^|\\s)' + className + '(\\s|$)'); for (var i = 0, j = 0; i < elsLen; i++) { if (pattern.test(els[i].className)) { if (single) { return els[i]; } else { classElements[j] = els[i]; j++; } } } return classElements; }; module.exports = function () { return function (container, className, single, options) { options = options || {}; if (options.test && options.getElementsByClassName || !options.test && document.getElementsByClassName) { return getElementsByClassName(container, className, single); } else if (options.test && options.querySelector || !options.test && document.querySelector) { return querySelector(container, className, single); } else { return polyfill(container, className, single); } }; }(); /***/ }), /***/ "./src/utils/index-of.js": /*!*******************************!*\ !*** ./src/utils/index-of.js ***! \*******************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 3:0-14 */ /***/ (function(module) { var indexOf = [].indexOf; module.exports = function (arr, obj) { if (indexOf) return arr.indexOf(obj); for (var i = 0, il = arr.length; i < il; ++i) { if (arr[i] === obj) return i; } return -1; }; /***/ }), /***/ "./src/utils/to-array.js": /*!*******************************!*\ !*** ./src/utils/to-array.js ***! \*******************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 11:0-14 */ /***/ (function(module) { /** * Source: https://github.com/timoxley/to-array * * Convert an array-like object into an `Array`. * If `collection` is already an `Array`, then will return a clone of `collection`. * * @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList` * @return {Array} Naive conversion of `collection` to a new `Array`. * @api public */ module.exports = function toArray(collection) { if (typeof collection === 'undefined') return []; if (collection === null) return [null]; if (collection === window) return [window]; if (typeof collection === 'string') return [collection]; if (isArray(collection)) return collection; if (typeof collection.length != 'number') return [collection]; if (typeof collection === 'function' && collection instanceof Function) return [collection]; var arr = []; for (var i = 0, il = collection.length; i < il; i++) { if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) { arr.push(collection[i]); } } if (!arr.length) return []; return arr; }; function isArray(arr) { return Object.prototype.toString.call(arr) === '[object Array]'; } /***/ }), /***/ "./src/utils/to-string.js": /*!********************************!*\ !*** ./src/utils/to-string.js ***! \********************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 1:0-14 */ /***/ (function(module) { module.exports = function (s) { s = s === undefined ? '' : s; s = s === null ? '' : s; s = s.toString(); return s; }; /***/ }), /***/ "./node_modules/string-natural-compare/natural-compare.js": /*!****************************************************************!*\ !*** ./node_modules/string-natural-compare/natural-compare.js ***! \****************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module */ /*! CommonJS bailout: module.exports is used directly at 124:0-14 */ /***/ (function(module) { "use strict"; var alphabet; var alphabetIndexMap; var alphabetIndexMapLength = 0; function isNumberCode(code) { return code >= 48 && code <= 57; } function naturalCompare(a, b) { var lengthA = (a += '').length; var lengthB = (b += '').length; var aIndex = 0; var bIndex = 0; while (aIndex < lengthA && bIndex < lengthB) { var charCodeA = a.charCodeAt(aIndex); var charCodeB = b.charCodeAt(bIndex); if (isNumberCode(charCodeA)) { if (!isNumberCode(charCodeB)) { return charCodeA - charCodeB; } var numStartA = aIndex; var numStartB = bIndex; while (charCodeA === 48 && ++numStartA < lengthA) { charCodeA = a.charCodeAt(numStartA); } while (charCodeB === 48 && ++numStartB < lengthB) { charCodeB = b.charCodeAt(numStartB); } var numEndA = numStartA; var numEndB = numStartB; while (numEndA < lengthA && isNumberCode(a.charCodeAt(numEndA))) { ++numEndA; } while (numEndB < lengthB && isNumberCode(b.charCodeAt(numEndB))) { ++numEndB; } var difference = numEndA - numStartA - numEndB + numStartB; // numA length - numB length if (difference) { return difference; } while (numStartA < numEndA) { difference = a.charCodeAt(numStartA++) - b.charCodeAt(numStartB++); if (difference) { return difference; } } aIndex = numEndA; bIndex = numEndB; continue; } if (charCodeA !== charCodeB) { if ( charCodeA < alphabetIndexMapLength && charCodeB < alphabetIndexMapLength && alphabetIndexMap[charCodeA] !== -1 && alphabetIndexMap[charCodeB] !== -1 ) { return alphabetIndexMap[charCodeA] - alphabetIndexMap[charCodeB]; } return charCodeA - charCodeB; } ++aIndex; ++bIndex; } if (aIndex >= lengthA && bIndex < lengthB && lengthA >= lengthB) { return -1; } if (bIndex >= lengthB && aIndex < lengthA && lengthB >= lengthA) { return 1; } return lengthA - lengthB; } naturalCompare.caseInsensitive = naturalCompare.i = function(a, b) { return naturalCompare(('' + a).toLowerCase(), ('' + b).toLowerCase()); }; Object.defineProperties(naturalCompare, { alphabet: { get: function() { return alphabet; }, set: function(value) { alphabet = value; alphabetIndexMap = []; var i = 0; if (alphabet) { for (; i < alphabet.length; i++) { alphabetIndexMap[alphabet.charCodeAt(i)] = i; } } alphabetIndexMapLength = alphabetIndexMap.length; for (i = 0; i < alphabetIndexMapLength; i++) { if (alphabetIndexMap[i] === undefined) { alphabetIndexMap[i] = -1; } } }, }, }); module.exports = naturalCompare; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(__webpack_module_cache__[moduleId]) { /******/ return __webpack_module_cache__[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ // module exports must be returned from runtime so entry inlining is disabled /******/ // startup /******/ // Load entry module and return exports /******/ return __webpack_require__("./src/index.js"); /******/ })() ; //# sourceMappingURL=list.js.map ================================================ FILE: docs/.bundle/config ================================================ --- BUNDLE_PATH: "vendor/bundle" ================================================ FILE: docs/.ruby-version ================================================ 2.7.1 ================================================ FILE: docs/CNAME ================================================ listjs.com ================================================ FILE: docs/Gemfile ================================================ source 'https://rubygems.org' group :jekyll_plugins do gem 'github-pages' end ================================================ FILE: docs/README.md ================================================ # listjs.com ================================================ FILE: docs/_config.yml ================================================ title: List.js email: jonny.stromberg@gmail.com description: > # this means to ignore newlines until "baseurl:" 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. baseurl: "" # the subpath of your site, e.g. /blog url: "https://listjs.com" # the base hostname & protocol for your site twitter_username: javve github_username: javve permalink: pretty markdown: kramdown livereload: true plugins: - jekyll-coffeescript - jekyll-redirect-from collections: examples: output: true ================================================ FILE: docs/_data/pkg.json ================================================ { "name": "list.js", "version": "2.3.1", "description": "The perfect library for lists. Supports search, sort, filters and flexibility. Built to be invisible and work on existing HTML", "keywords": [ "list", "search", "sort", "table", "dom", "html", "ui" ], "author": { "name": "Jonny Strömberg", "email": "jonny.stromberg@gmail.com", "url": "https://javve.com" }, "homepage": "https://listjs.com", "repository": "git://github.com/javve/list.js.git", "license": "MIT", "bugs": { "url": "https://github.com/javve/list.js/issues" }, "dependencies": { "string-natural-compare": "^2.0.2" }, "devDependencies": { "@babel/core": "^7.12.7", "@babel/preset-env": "^7.12.7", "babel-loader": "^8.2.1", "jest": "^26.6.3", "jquery": "^3.5.1", "prettier": "^2.2.0", "webpack": "^5.6.0", "webpack-cli": "^4.2.0" }, "main": "src/index", "engines": { "node": "^6.0 || ^8.0 || ^10.0 || ^12.0 || >=14" }, "scripts": { "test": "npx jest", "build": "npx webpack", "watch": "npx webpack --watch", "watch-test": "npx jest --watch", "preversion": "npm test && npm run build && cp dist/list.min.js docs/assets/javascripts/list.min.js && cp dist/list.min.js.map docs/assets/javascripts/list.min.js.map && git add dist && git add docs/assets/javascripts", "postversion": "git push --follow-tags origin master && cp package.json docs/_data/pkg.json && git add docs/_data/pkg.json && git commit -m \"pkg.json update\"" }, "npmName": "list.js", "npmFileMap": [ { "basePath": "/dist/", "files": [ "*.js", "*.js.map" ] } ], "jest": { "coverageDirectory": "./coverage/", "collectCoverage": true, "collectCoverageFrom": [ "src/*.js", "src/utils/*.js" ], "testURL": "http://localhost/" } } ================================================ FILE: docs/_examples/add-get-remove.html ================================================ --- layout: default name: Add, get, remove title: Example to showcase the add, get and remove methods. url: https://codepen.io/javve/pen/cLdfw slug: cLdfw --- {% include codepen.html %} ================================================ FILE: docs/_examples/data-attributes-custom-attributes.html ================================================ --- layout: default url: https://codepen.io/javve/pen/GZREaN slug: GZREaN title: Use data attributes and other custom attributes as keys name: Data attributes + custom --- {% include codepen.html %} ================================================ FILE: docs/_examples/existing-list-add.html ================================================ --- layout: default url: https://codepen.io/javve/pen/lAmCz slug: lAmCz title: Existing list and add items name: Existing list and add --- {% include codepen.html %} ================================================ FILE: docs/_examples/existing-list.html ================================================ --- layout: default url: https://codepen.io/javve/pen/zpuKF slug: zpuKF title: Basic example with existing list name: Existing list --- {% include codepen.html %} ================================================ FILE: docs/_examples/fuzzy-search.html ================================================ --- layout: default name: Fuzzy search title: Example of how to use the fuzzy search plugin url: https://codepen.io/javve/pen/isInl slug: isInl --- {% include codepen.html %} ================================================ FILE: docs/_examples/new-list.html ================================================ --- layout: default url: https://codepen.io/javve/pen/yroGq slug: yroGq title: Basic example with a new list name: New list --- {% include codepen.html %} ================================================ FILE: docs/_examples/pagination.html ================================================ --- layout: default name: Pagination title: Example of how to use the pagination plugin url: https://codepen.io/javve/pen/bBfgD slug: bBfgD --- {% include codepen.html %} ================================================ FILE: docs/_examples/table.html ================================================ --- layout: default url: https://codepen.io/javve/pen/oEezp slug: oEezp title: Example of how to use a table with List.js name: Table --- {% include codepen.html %} ================================================ FILE: docs/_includes/author.html ================================================

        Hi! I'm Jonny and the author of List.js.

        I hope you like the lib. I’ve put a lot of hours into it! Feel free to follow me on Twitter and GitHub for news and donate a coffee for good karma ;)

        ================================================ FILE: docs/_includes/carbon.html ================================================ ================================================ FILE: docs/_includes/codepen.html ================================================

        {{ page.name }}

        {{ page.title }}

        See the Pen {{ page.url }} by Jonny Strömberg (@javve) on CodePen.

        ================================================ FILE: docs/_includes/examples/annotated-example.html ================================================

        Basic examples

        Here is an example of a list with List.js applied. List.js can be used in three different ways. It can be on existing HTML, it can create it's own HTML or a combination of both methods.

        Jonny Strömberg

        1990

        Jonas Arnklint

        1985

        Martina Elm

        1986

        Gustaf Lindqvist

        1983

        Apply List.js on existing HTML

        <div id="users">
        
        <!-- class="search" automagically makes an input a search field. -->
          <input class="search" placeholder="Search" />
        <!-- class="sort" automagically makes an element a sort buttons. The date-sort value decides what to sort by. -->
          <button class="sort" data-sort="name">
            Sort
          </button>
        
        <!-- Child elements of container with class="list" becomes list items -->
          <ul class="list">
            <li>
        <!-- The innerHTML of children with class="name" becomes this items "name" value -->
              <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>
        var options = {
          valueNames: [ 'name', 'born' ]
        };
        
        var userList = new List('users', options);

        Apply List.js on existing HTML and then add items

        <div id="users">
        
          <input class="search" placeholder="Search" />
          <button class="sort" data-sort="name">
            Sort
          </button>
        
          <ul class="list">
        <!-- This, the first element in the list, will be used as template for new items. -->
            <li>
              <h3 class="name">Jonny Stromberg</h3>
              <p class="born">1986</p>
            </li>
          </ul>
        
        </div>
        
        var options = {
          valueNames: [ 'name', 'born' ]
        };
        
        // These items will be added to the list on initialization.
        var values = [
          {
            name: 'Jonas Arnklint',
            born: 1985
          },
          {
            name: 'Martina Elm',
            born: 1986
          }
        ];
        
        var userList = new List('users', options, values);
        
        // It's possible to add items after list been initiated
        userList.add({
          name: 'Gustaf Lindqvist',
          born: 1983
        });

        Make List.js create a list from scratch

        <div id="users">
        
          <input class="search" placeholder="Search" />
          <button class="sort" data-sort="name">
            Sort
          </button>
        
          <ul class="list"></ul>
        
        </div>
        var options = {
          valueNames: [ 'name', 'born' ],
          // Since there are no elements in the list, this will be used as template.
          item: '<li><h3 class="name"></h3><p class="born"></p></li>'
        };
        
        var values = [
          {
            name: 'Jonny Strömberg',
            born: 1986
          },
          {
            name: 'Jonas Arnklint',
            born: 1985
          },
          {
            name: 'Martina Elm',
            born: 1986
          }
        ];
        
        var userList = new List('users', options, values);
        
        userList.add({
          name: 'Gustaf Lindqvist',
          born: 1983
        });
        
        ================================================ FILE: docs/_includes/javascripts/vendor/bootstrap/tab.js ================================================ /* ======================================================================== * Bootstrap: tab.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#tabs * ======================================================================== * Copyright 2013 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ======================================================================== */ +function ($) { "use strict"; // TAB CLASS DEFINITION // ==================== var Tab = function (element) { this.element = $(element) } Tab.prototype.show = function () { var $this = this.element var $ul = $this.closest('ul:not(.dropdown-menu)') var selector = $this.data('target') if (!selector) { selector = $this.attr('href') selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 } if ($this.parent('li').hasClass('active')) return var previous = $ul.find('.active:last a')[0] var e = $.Event('show.bs.tab', { relatedTarget: previous }) $this.trigger(e) if (e.isDefaultPrevented()) return var $target = $(selector) this.activate($this.parent('li'), $ul) this.activate($target, $target.parent(), function () { $this.trigger({ type: 'shown.bs.tab' , relatedTarget: previous }) }) } Tab.prototype.activate = function (element, container, callback) { var $active = container.find('> .active') var transition = callback && $.support.transition && $active.hasClass('fade') function next() { $active .removeClass('active') .find('> .dropdown-menu > .active') .removeClass('active') element.addClass('active') if (transition) { element[0].offsetWidth // reflow for transition element.addClass('in') } else { element.removeClass('fade') } if (element.parent('.dropdown-menu')) { element.closest('li.dropdown').addClass('active') } callback && callback() } transition ? $active .one($.support.transition.end, next) .emulateTransitionEnd(150) : next() $active.removeClass('in') } // TAB PLUGIN DEFINITION // ===================== var old = $.fn.tab $.fn.tab = function ( option ) { return this.each(function () { var $this = $(this) var data = $this.data('bs.tab') if (!data) $this.data('bs.tab', (data = new Tab(this))) if (typeof option == 'string') data[option]() }) } $.fn.tab.Constructor = Tab // TAB NO CONFLICT // =============== $.fn.tab.noConflict = function () { $.fn.tab = old return this } // TAB DATA-API // ============ $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { e.preventDefault() $(this).tab('show') }) }(window.jQuery); ================================================ FILE: docs/_includes/javascripts/vendor/bootstrap/tooltip.js ================================================ /* ======================================================================== * Bootstrap: tooltip.js v3.0.0 * http://getbootstrap.com/javascript/#tooltip * Inspired by the original jQuery.tipsy by Jason Frame * ======================================================================== * Copyright 2013 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ======================================================================== */ +function ($) { "use strict"; // TOOLTIP PUBLIC CLASS DEFINITION // =============================== var Tooltip = function (element, options) { this.type = this.options = this.enabled = this.timeout = this.hoverState = this.$element = null this.init('tooltip', element, options) } Tooltip.DEFAULTS = { animation: true , placement: 'top' , selector: false , template: '
        ' , trigger: 'hover focus' , title: '' , delay: 0 , html: false , container: false } Tooltip.prototype.init = function (type, element, options) { this.enabled = true this.type = type this.$element = $(element) this.options = this.getOptions(options) var triggers = this.options.trigger.split(' ') for (var i = triggers.length; i--;) { var trigger = triggers[i] if (trigger == 'click') { this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) } else if (trigger != 'manual') { var eventIn = trigger == 'hover' ? 'mouseenter' : 'focus' var eventOut = trigger == 'hover' ? 'mouseleave' : 'blur' this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) } } this.options.selector ? (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : this.fixTitle() } Tooltip.prototype.getDefaults = function () { return Tooltip.DEFAULTS } Tooltip.prototype.getOptions = function (options) { options = $.extend({}, this.getDefaults(), this.$element.data(), options) if (options.delay && typeof options.delay == 'number') { options.delay = { show: options.delay , hide: options.delay } } return options } Tooltip.prototype.getDelegateOptions = function () { var options = {} var defaults = this.getDefaults() this._options && $.each(this._options, function (key, value) { if (defaults[key] != value) options[key] = value }) return options } Tooltip.prototype.enter = function (obj) { var self = obj instanceof this.constructor ? obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) clearTimeout(self.timeout) self.hoverState = 'in' if (!self.options.delay || !self.options.delay.show) return self.show() self.timeout = setTimeout(function () { if (self.hoverState == 'in') self.show() }, self.options.delay.show) } Tooltip.prototype.leave = function (obj) { var self = obj instanceof this.constructor ? obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) clearTimeout(self.timeout) self.hoverState = 'out' if (!self.options.delay || !self.options.delay.hide) return self.hide() self.timeout = setTimeout(function () { if (self.hoverState == 'out') self.hide() }, self.options.delay.hide) } Tooltip.prototype.show = function () { var e = $.Event('show.bs.'+ this.type) if (this.hasContent() && this.enabled) { this.$element.trigger(e) if (e.isDefaultPrevented()) return var $tip = this.tip() this.setContent() if (this.options.animation) $tip.addClass('fade') var placement = typeof this.options.placement == 'function' ? this.options.placement.call(this, $tip[0], this.$element[0]) : this.options.placement var autoToken = /\s?auto?\s?/i var autoPlace = autoToken.test(placement) if (autoPlace) placement = placement.replace(autoToken, '') || 'top' $tip .detach() .css({ top: 0, left: 0, display: 'block' }) .addClass(placement) this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) var pos = this.getPosition() var actualWidth = $tip[0].offsetWidth var actualHeight = $tip[0].offsetHeight if (autoPlace) { var $parent = this.$element.parent() var orgPlacement = placement var docScroll = document.documentElement.scrollTop || document.body.scrollTop var parentWidth = this.options.container == 'body' ? window.innerWidth : $parent.outerWidth() var parentHeight = this.options.container == 'body' ? window.innerHeight : $parent.outerHeight() var parentLeft = this.options.container == 'body' ? 0 : $parent.offset().left placement = placement == 'bottom' && pos.top + pos.height + actualHeight - docScroll > parentHeight ? 'top' : placement == 'top' && pos.top - docScroll - actualHeight < 0 ? 'bottom' : placement == 'right' && pos.right + actualWidth > parentWidth ? 'left' : placement == 'left' && pos.left - actualWidth < parentLeft ? 'right' : placement $tip .removeClass(orgPlacement) .addClass(placement) } var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) this.applyPlacement(calculatedOffset, placement) this.$element.trigger('shown.bs.' + this.type) } } Tooltip.prototype.applyPlacement = function(offset, placement) { var replace var $tip = this.tip() var width = $tip[0].offsetWidth var height = $tip[0].offsetHeight // manually read margins because getBoundingClientRect includes difference var marginTop = parseInt($tip.css('margin-top'), 10) var marginLeft = parseInt($tip.css('margin-left'), 10) // we must check for NaN for ie 8/9 if (isNaN(marginTop)) marginTop = 0 if (isNaN(marginLeft)) marginLeft = 0 offset.top = offset.top + marginTop offset.left = offset.left + marginLeft $tip .offset(offset) .addClass('in') // check to see if placing tip in new offset caused the tip to resize itself var actualWidth = $tip[0].offsetWidth var actualHeight = $tip[0].offsetHeight if (placement == 'top' && actualHeight != height) { replace = true offset.top = offset.top + height - actualHeight } if (/bottom|top/.test(placement)) { var delta = 0 if (offset.left < 0) { delta = offset.left * -2 offset.left = 0 $tip.offset(offset) actualWidth = $tip[0].offsetWidth actualHeight = $tip[0].offsetHeight } this.replaceArrow(delta - width + actualWidth, actualWidth, 'left') } else { this.replaceArrow(actualHeight - height, actualHeight, 'top') } if (replace) $tip.offset(offset) } Tooltip.prototype.replaceArrow = function(delta, dimension, position) { this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + "%") : '') } Tooltip.prototype.setContent = function () { var $tip = this.tip() var title = this.getTitle() $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) $tip.removeClass('fade in top bottom left right') } Tooltip.prototype.hide = function () { var that = this var $tip = this.tip() var e = $.Event('hide.bs.' + this.type) function complete() { if (that.hoverState != 'in') $tip.detach() } this.$element.trigger(e) if (e.isDefaultPrevented()) return $tip.removeClass('in') $.support.transition && this.$tip.hasClass('fade') ? $tip .one($.support.transition.end, complete) .emulateTransitionEnd(150) : complete() this.$element.trigger('hidden.bs.' + this.type) return this } Tooltip.prototype.fixTitle = function () { var $e = this.$element if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') { $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') } } Tooltip.prototype.hasContent = function () { return this.getTitle() } Tooltip.prototype.getPosition = function () { var el = this.$element[0] return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : { width: el.offsetWidth , height: el.offsetHeight }, this.$element.offset()) } Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } } Tooltip.prototype.getTitle = function () { var title var $e = this.$element var o = this.options title = $e.attr('data-original-title') || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) return title } Tooltip.prototype.tip = function () { return this.$tip = this.$tip || $(this.options.template) } Tooltip.prototype.arrow = function () { return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow') } Tooltip.prototype.validate = function () { if (!this.$element[0].parentNode) { this.hide() this.$element = null this.options = null } } Tooltip.prototype.enable = function () { this.enabled = true } Tooltip.prototype.disable = function () { this.enabled = false } Tooltip.prototype.toggleEnabled = function () { this.enabled = !this.enabled } Tooltip.prototype.toggle = function (e) { var self = e ? $(e.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) : this self.tip().hasClass('in') ? self.leave(self) : self.enter(self) } Tooltip.prototype.destroy = function () { this.hide().$element.off('.' + this.type).removeData('bs.' + this.type) } // TOOLTIP PLUGIN DEFINITION // ========================= var old = $.fn.tooltip $.fn.tooltip = function (option) { return this.each(function () { var $this = $(this) var data = $this.data('bs.tooltip') var options = typeof option == 'object' && option if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) if (typeof option == 'string') data[option]() }) } $.fn.tooltip.Constructor = Tooltip // TOOLTIP NO CONFLICT // =================== $.fn.tooltip.noConflict = function () { $.fn.tooltip = old return this } }(window.jQuery); ================================================ FILE: docs/_includes/javascripts/vendor/bootstrap/transition.js ================================================ /* ======================================================================== * Bootstrap: transition.js v3.0.0 * http://getbootstrap.com/javascript/#transitions * ======================================================================== * Copyright 2013 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ======================================================================== */ +function ($) { "use strict"; // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) // ============================================================ function transitionEnd() { var el = document.createElement('bootstrap') var transEndEventNames = { 'WebkitTransition' : 'webkitTransitionEnd' , 'MozTransition' : 'transitionend' , 'OTransition' : 'oTransitionEnd otransitionend' , 'transition' : 'transitionend' } for (var name in transEndEventNames) { if (el.style[name] !== undefined) { return { end: transEndEventNames[name] } } } } // http://blog.alexmaccaw.com/css-transitions $.fn.emulateTransitionEnd = function (duration) { var called = false, $el = this $(this).one($.support.transition.end, function () { called = true }) var callback = function () { if (!called) $($el).trigger($.support.transition.end) } setTimeout(callback, duration) return this } $(function () { $.support.transition = transitionEnd() }) }(window.jQuery); ================================================ FILE: docs/_includes/javascripts/vendor/highlight.pack.js ================================================ var hljs=new function(){function l(o){return o.replace(/&/gm,"&").replace(//gm,">")}function b(p){for(var o=p.firstChild;o;o=o.nextSibling){if(o.nodeName=="CODE"){return o}if(!(o.nodeType==3&&o.nodeValue.match(/\s+/))){break}}}function h(p,o){return Array.prototype.map.call(p.childNodes,function(q){if(q.nodeType==3){return o?q.nodeValue.replace(/\n/g,""):q.nodeValue}if(q.nodeName=="BR"){return"\n"}return h(q,o)}).join("")}function a(q){var p=(q.className+" "+(q.parentNode?q.parentNode.className:"")).split(/\s+/);p=p.map(function(r){return r.replace(/^language-/,"")});for(var o=0;o"}while(x.length||v.length){var u=t().splice(0,1)[0];y+=l(w.substr(p,u.offset-p));p=u.offset;if(u.event=="start"){y+=s(u.node);r.push(u.node)}else{if(u.event=="stop"){var o,q=r.length;do{q--;o=r[q];y+=("")}while(o!=u.node);r.splice(q,1);while(q'+M[0]+""}else{r+=M[0]}O=A.lR.lastIndex;M=A.lR.exec(L)}return r+L.substr(O)}function z(){if(A.sL&&!e[A.sL]){return l(w)}var r=A.sL?d(A.sL,w):g(w);if(A.r>0){v+=r.keyword_count;B+=r.r}return''+r.value+""}function K(){return A.sL!==undefined?z():H()}function J(M,r){var L=M.cN?'':"";if(M.rB){x+=L;w=""}else{if(M.eB){x+=l(r)+L;w=""}else{x+=L;w=r}}A=Object.create(M,{parent:{value:A}})}function D(L,r){w+=L;if(r===undefined){x+=K();return 0}var N=o(r,A);if(N){x+=K();J(N,r);return N.rB?0:r.length}var O=s(A,r);if(O){var M=A;if(!(M.rE||M.eE)){w+=r}x+=K();do{if(A.cN){x+=""}B+=A.r;A=A.parent}while(A!=O.parent);if(M.eE){x+=l(r)}w="";if(O.starts){J(O.starts,"")}return M.rE?0:r.length}if(t(r,A)){throw new Error('Illegal lexem "'+r+'" for mode "'+(A.cN||"")+'"')}w+=r;return r.length||1}var G=e[E];f(G);var A=G;var w="";var B=0;var v=0;var x="";try{var u,q,p=0;while(true){A.t.lastIndex=p;u=A.t.exec(F);if(!u){break}q=D(F.substr(p,u.index-p),u[0]);p=u.index+q}D(F.substr(p));return{r:B,keyword_count:v,value:x,language:E}}catch(I){if(I.message.indexOf("Illegal")!=-1){return{r:0,keyword_count:0,value:l(F)}}else{throw I}}}function g(s){var o={keyword_count:0,r:0,value:l(s)};var q=o;for(var p in e){if(!e.hasOwnProperty(p)){continue}var r=d(p,s,false);r.language=p;if(r.keyword_count+r.r>q.keyword_count+q.r){q=r}if(r.keyword_count+r.r>o.keyword_count+o.r){q=o;o=r}}if(q.language){o.second_best=q}return o}function i(q,p,o){if(p){q=q.replace(/^((<[^>]+>|\t)+)/gm,function(r,v,u,t){return v.replace(/\t/g,p)})}if(o){q=q.replace(/\n/g,"
        ")}return q}function m(r,u,p){var v=h(r,p);var t=a(r);if(t=="no-highlight"){return}var w=t?d(t,v,true):g(v);t=w.language;var o=c(r);if(o.length){var q=document.createElement("pre");q.innerHTML=w.value;w.value=j(o,c(q),v)}w.value=i(w.value,u,p);var s=r.className;if(!s.match("(\\s|^)(language-)?"+t+"(\\s|$)")){s=s?(s+" "+t):t}r.innerHTML=w.value;r.className=s;r.result={language:t,kw:w.keyword_count,re:w.r};if(w.second_best){r.second_best={language:w.second_best.language,kw:w.second_best.keyword_count,re:w.second_best.r}}}function n(){if(n.called){return}n.called=true;Array.prototype.map.call(document.getElementsByTagName("pre"),b).filter(Boolean).forEach(function(o){m(o,hljs.tabReplace)})}function k(){window.addEventListener("DOMContentLoaded",n,false);window.addEventListener("load",n,false)}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=m;this.initHighlighting=n;this.initHighlightingOnLoad=k;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.BE={b:"\\\\[\\s\\S]",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE],r:0};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.REGEXP_MODE={cN:"regexp",b:/\//,e:/\/[gim]*/,i:/\n/,c:[this.BE,{b:/\[/,e:/\]/,r:0,c:[this.BE]}]};this.inherit=function(q,r){var o={};for(var p in q){o[p]=q[p]}if(r){for(var p in r){o[p]=r[p]}}return o}}();hljs.LANGUAGES.javascript=function(a){return{k:{keyword:"in if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const",literal:"true false null undefined NaN Infinity"},c:[a.ASM,a.QSM,a.CLCM,a.CBLCLM,a.CNM,{b:"("+a.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[a.CLCM,a.CBLCLM,a.REGEXP_MODE,{b:/;/,sL:"xml"}],r:0},{cN:"function",bWK:true,e:/{/,k:"function",c:[{cN:"title",b:/[A-Za-z$_][0-9A-Za-z$_]*/},{cN:"params",b:/\(/,e:/\)/,c:[a.CLCM,a.CBLCLM],i:/["'\(]/}],i:/\[|%/}]}}(hljs);hljs.LANGUAGES.css=function(a){var b="[a-zA-Z-][a-zA-Z0-9_-]*";var c={cN:"function",b:b+"\\(",e:"\\)",c:["self",a.NM,a.ASM,a.QSM]};return{cI:true,i:"[=/|']",c:[a.CBLCLM,{cN:"id",b:"\\#[A-Za-z0-9_-]+"},{cN:"class",b:"\\.[A-Za-z0-9_-]+",r:0},{cN:"attr_selector",b:"\\[",e:"\\]",i:"$"},{cN:"pseudo",b:":(:)?[a-zA-Z0-9\\_\\-\\+\\(\\)\\\"\\']+"},{cN:"at_rule",b:"@(font-face|page)",l:"[a-z-]+",k:"font-face page"},{cN:"at_rule",b:"@",e:"[{;]",c:[{cN:"keyword",b:/\S+/},{b:/\s/,eW:true,eE:true,r:0,c:[c,a.ASM,a.QSM,a.NM]}]},{cN:"tag",b:b,r:0},{cN:"rules",b:"{",e:"}",i:"[^\\s]",r:0,c:[a.CBLCLM,{cN:"rule",b:"[^\\s]",rB:true,e:";",eW:true,c:[{cN:"attribute",b:"[A-Z\\_\\.\\-]+",e:":",eE:true,i:"[^\\s]",starts:{cN:"value",eW:true,eE:true,c:[c,a.NM,a.QSM,a.ASM,a.CBLCLM,{cN:"hexcolor",b:"#[0-9A-Fa-f]+"},{cN:"important",b:"!important"}]}}]}]}]}}(hljs);hljs.LANGUAGES.xml=function(a){var c="[A-Za-z0-9\\._:-]+";var b={eW:true,r:0,c:[{cN:"attribute",b:c,r:0},{b:'="',rB:true,e:'"',c:[{cN:"value",b:'"',eW:true}]},{b:"='",rB:true,e:"'",c:[{cN:"value",b:"'",eW:true}]},{b:"=",c:[{cN:"value",b:"[^\\s/>]+"}]}]};return{cI:true,c:[{cN:"pi",b:"<\\?",e:"\\?>",r:10},{cN:"doctype",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},{cN:"comment",b:"",r:10},{cN:"cdata",b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"tag",b:"|$)",e:">",k:{title:"style"},c:[b],starts:{e:"",rE:true,sL:"css"}},{cN:"tag",b:"|$)",e:">",k:{title:"script"},c:[b],starts:{e:"<\/script>",rE:true,sL:"javascript"}},{b:"<%",e:"%}",sL:"vbscript"},{cN:"tag",b:"",r:0,c:[{cN:"title",b:"[^ /><]+"},b]}]}}(hljs);hljs.LANGUAGES.json=function(a){var e={literal:"true false null"};var d=[a.QSM,a.CNM];var c={cN:"value",e:",",eW:true,eE:true,c:d,k:e};var b={b:"{",e:"}",c:[{cN:"attribute",b:'\\s*"',e:'"\\s*:\\s*',eB:true,eE:true,c:[a.BE],i:"\\n",starts:c}],i:"\\S"};var f={b:"\\[",e:"\\]",c:[a.inherit(c,{cN:null})],i:"\\S"};d.splice(d.length,0,b,f);return{c:d,k:e,i:"\\S"}}(hljs); ================================================ FILE: docs/_includes/menu.html ================================================

        Overview

        Documentation

        Examples

        ================================================ FILE: docs/_layouts/default.html ================================================ {{ page.title }} - {{ site.title }}
        {% include menu.html %}
        {{ content }}
        {% include carbon.html %}
        ================================================ FILE: docs/_sass/_base.scss ================================================ /** * Basic styling */ body { font: $base-font-weight #{$base-font-size}/#{$base-line-height} $base-font-family; color: $text-color; background-color: $background-color; -webkit-text-size-adjust: 100%; -webkit-font-feature-settings: "kern" 1; -moz-font-feature-settings: "kern" 1; -o-font-feature-settings: "kern" 1; font-feature-settings: "kern" 1; font-kerning: normal; @include transition(background-color .2s ease-in-out); } /** * Set `margin-bottom` to maintain vertical rhythm */ h1, h2, h3, h4, h5, h6, p, blockquote, pre, ul, ol, dl, figure, %vertical-rhythm { margin-top:0; margin-bottom: $spacing-unit / 2; } /** * Images */ img { max-width: 100%; vertical-align: middle; } /** * Figures */ figure > img { display: block; } figcaption { font-size: $small-font-size; } /** * Lists */ ul, ol { margin-left: $spacing-unit; } li { > ul, > ol { margin-bottom: 0; } } /** * Headings */ h1, h2, h3, h4, h5, h6 { font-family: $headline-font-family; font-weight: $headline-font-weight; } /** * Links */ a { color: $brand-color; text-decoration: none; &:visited { color: darken($brand-color, 15%); } &:hover { color: $text-color; text-decoration: underline; } } /** * Blockquotes */ blockquote { color: $grey-color; border-left: 4px solid $grey-color-light; padding-left: $spacing-unit / 2; font-size: 18px; letter-spacing: -1px; font-style: italic; > :last-child { margin-bottom: 0; } } /** * Code formatting */ pre, code { font-size: 15px; border: 1px solid $grey-color-light; border-radius: 3px; background-color: #eef; } code { padding: 1px 5px; } pre { padding: 8px 12px; overflow-x: auto; > code { border: 0; padding-right: 0; padding-left: 0; } } /** * Wrapper */ .wrapper { max-width: -webkit-calc(#{$content-width} - (#{$spacing-unit} * 2)); max-width: calc(#{$content-width} - (#{$spacing-unit} * 2)); margin-right: auto; margin-left: auto; padding-right: $spacing-unit; padding-left: $spacing-unit; @extend %clearfix; @include media-query($on-laptop) { max-width: -webkit-calc(#{$content-width} - (#{$spacing-unit})); max-width: calc(#{$content-width} - (#{$spacing-unit})); padding-right: $spacing-unit / 2; padding-left: $spacing-unit / 2; } } .content-container { background-color: #fff; box-sizing: border-box; max-width: $content-width; margin:- $spacing-unit auto $spacing-unit; } .content { @include transition(all .2s ease-in-out); padding: $spacing-unit; @include media-query($on-laptop) { padding:$spacing-unit * 2; } &:after { content: ""; display: table; clear: both; } } .image-shadow-box { border: solid $spacing-unit / 2 #fff; box-shadow: 5px 10px 40px rgba(0,0,0,.3); } .image-right-50 { float:right; margin-left:$spacing-unit * 2; margin-bottom:$spacing-unit; max-width: 45%; } ================================================ FILE: docs/_sass/_carbonads.scss ================================================ @keyframes fadein { from { transform: translateY(100%); opacity: 0; } to { opacity: 1; transform: translateY(0); } } @-moz-keyframes fadein { from { transform: translateY(100%); opacity: 0; } to { opacity: 1; transform: translateY(0); } } @-webkit-keyframes fadein { from { transform: translateY(100%); opacity: 0; } to { opacity: 1; transform: translateY(0); } } @-ms-keyframes fadein { from { transform: translateY(100%); opacity: 0; } to { opacity: 1; transform: translateY(0); } } @-o-keyframes fadein { from { transform: translateY(100%); opacity: 0; } to { opacity: 1; transform: translateY(0); } } #carbonads { position: fixed; z-index: 10000; right: 0; bottom: 0; opacity: 0; transform: translateY(100%); -webkit-animation: fadein 1s 2s forwards; -moz-animation: fadein 1s 2s forwards; -ms-animation: fadein 1s 2s forwards; -o-animation: fadein 1s 2s forwards; animation: fadein 1s 2s forwards } #carbonads { display: block; overflow: hidden; padding: 1em; background-color: hsla(0, 0%, 100%, .88); max-width: 330px; box-shadow: 0 0 1px 0 hsla(0, 0%, 0%, .6); font-size: 14px; border-top-left-radius: 4px; line-height: 1.5; } #carbonads a { text-decoration: none; } #carbonads span { position: relative; display: block; overflow: hidden; } .carbon-img { float: left; margin-right: 1em; } .carbon-img img { display: block; } .carbon-text { display: block; float: left; max-width: calc(100% - 130px - 1em); text-align: left; } .carbon-poweredby { position: absolute; right: 0; bottom: 0; display: block; font-size: 10px; color: hsl(0, 0%, 60%); text-transform: uppercase; line-height: 1; letter-spacing: 1px; } ================================================ FILE: docs/_sass/_docs.scss ================================================ .docs { display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; flex-wrap: wrap; } .docs-menu { background-color:$blue; max-width: $menuWidth; position: relative; padding: 0 20px; box-sizing: border-box; flex: 1; a { transition: opacity .2s ease-in-out; color:#fff; text-decoration: none; &:hover { opacity: 0.7; color:#fff; } } ul { padding-left:20px; color:rgba(255,255,255,0.3); } li { margin-bottom:4px; &.active { font-weight: 700; color:#fff; } } } .docs-content { position: relative; color:#555; padding:30px; box-sizing: border-box; flex: 1; h2:first-child { margin-top: 0; } p, h1, h2, h3, h4, h5 { max-width: 500px; } p { line-height: 1.5; } ul { padding-left:30px; pre { margin-left:-60px; padding-left:60px; } ul pre { margin-left:-90px; padding-left:90px; } } strong, b { color:#222; font-weight: bold; } pre { background-color: $lightGrey; padding:20px 30px; margin:0 -30px 1px; code { background-color: transparent; } } li { margin-bottom:5px; } .api-index { -webkit-column-count: 3; -moz-column-count: 3; column-count: 3; margin:0; padding:0; li { list-style-type: none; margin-bottom: 0; } } } .docs-parameter-description { color:#999; font-size:80%; } .docs-top { display:none; border-bottom:solid 1px $lightGrey; padding:20px; .docs-top-title { font-size: 50px; font-size: 5rem; color:$orange; font-weight:700; margin:0; } } ================================================ FILE: docs/_sass/_menu.scss ================================================ @-webkit-keyframes pluse { 0% { -webkit-transform: scale(1); } 80% { -webkit-transform: scale(1.2); } 100% { -webkit-transform: scale(1); } } @keyframes pluse { 0% { transform: scale(1); } 80% { transform: scale(1.2); } 100% { transform: scale(1); } } .menu { padding:0 20px; z-index: 100; //margin-top:-80px; //margin-bottom:40px; margin:0; background-color: $black; .heart { -webkit-animation: pluse 1.4s infinite linear; animation: pluse 1.4s infinite linear; position:relative; top:2px; right:-3px; display: inline-block; } ul { display:block; margin:0; padding:0; } li { display:inline-block; margin:0 10px 0 0; } a { line-height:60px; display: inline-block; text-decoration: none; font-weight: 600; color:#fff; &:hover, &.active { color:#eee; } &.active { font-weight: 500; color:$black; } } } .menu-sub { margin:-40px 0 20px; color: #ccc; background-color:$lightGrey; font-size:14px; font-size:1.4rem; @extend %clearfix; ul { padding: 15px 0 13px; margin:0; } li { display: inline-block; margin-right:20px; &.active { a { color:#222; } } } } ================================================ FILE: docs/_sass/_mixins.scss ================================================ %clearfix { &:after { content: ""; display: table; clear: both; } } @mixin media-query($device) { @media screen and (min-width: $device) { @content; } } @mixin transition($value){ -webkit-transition: $value; transition: $value; } ================================================ FILE: docs/_sass/_normalize.scss ================================================ /*! normalize.css v2.1.3 | MIT License | git.io/normalize */ /* ========================================================================== HTML5 display definitions ========================================================================== */ /** * Correct `block` display not defined in IE 8/9. */ article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; } /** * Correct `inline-block` display not defined in IE 8/9. */ audio, canvas, video { display: inline-block; } /** * Prevent modern browsers from displaying `audio` without controls. * Remove excess height in iOS 5 devices. */ audio:not([controls]) { display: none; height: 0; } /** * Address `[hidden]` styling not present in IE 8/9. * Hide the `template` element in IE, Safari, and Firefox < 22. */ [hidden], template { display: none; } /* ========================================================================== Base ========================================================================== */ /** * 1. Set default font family to sans-serif. * 2. Prevent iOS text size adjust after orientation change, without disabling * user zoom. */ html { font-family: sans-serif; /* 1 */ -ms-text-size-adjust: 100%; /* 2 */ -webkit-text-size-adjust: 100%; /* 2 */ } /** * Remove default margin. */ body { margin: 0; } /* ========================================================================== Links ========================================================================== */ /** * Remove the gray background color from active links in IE 10. */ a { background: transparent; } /** * Address `outline` inconsistency between Chrome and other browsers. */ a:focus { outline: thin dotted; } /** * Improve readability when focused and also mouse hovered in all browsers. */ a:active, a:hover { outline: 0; } /* ========================================================================== Typography ========================================================================== */ /** * Address variable `h1` font-size and margin within `section` and `article` * contexts in Firefox 4+, Safari 5, and Chrome. */ h1 { font-size: 2em; margin: 0.67em 0; } /** * Address styling not present in IE 8/9, Safari 5, and Chrome. */ abbr[title] { border-bottom: 1px dotted; } /** * Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome. */ b, strong { font-weight: bold; } /** * Address styling not present in Safari 5 and Chrome. */ dfn { font-style: italic; } /** * Address differences between Firefox and other browsers. */ hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; } /** * Address styling not present in IE 8/9. */ mark { background: #ff0; color: #000; } /** * Correct font family set oddly in Safari 5 and Chrome. */ code, kbd, pre, samp { font-family: monospace, serif; font-size: 1em; } /** * Improve readability of pre-formatted text in all browsers. */ pre { white-space: pre-wrap; } /** * Set consistent quote types. */ q { quotes: "\201C" "\201D" "\2018" "\2019"; } /** * Address inconsistent and variable font size in all browsers. */ small { font-size: 80%; } /** * Prevent `sub` and `sup` affecting `line-height` in all browsers. */ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; } /* ========================================================================== Embedded content ========================================================================== */ /** * Remove border when inside `a` element in IE 8/9. */ img { border: 0; } /** * Correct overflow displayed oddly in IE 9. */ svg:not(:root) { overflow: hidden; } /* ========================================================================== Figures ========================================================================== */ /** * Address margin not present in IE 8/9 and Safari 5. */ figure { margin: 0; } /* ========================================================================== Forms ========================================================================== */ /** * Define consistent border, margin, and padding. */ fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } /** * 1. Correct `color` not being inherited in IE 8/9. * 2. Remove padding so people aren't caught out if they zero out fieldsets. */ legend { border: 0; /* 1 */ padding: 0; /* 2 */ } /** * 1. Correct font family not being inherited in all browsers. * 2. Correct font size not being inherited in all browsers. * 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome. */ button, input, select, textarea { font-family: inherit; /* 1 */ font-size: 100%; /* 2 */ margin: 0; /* 3 */ } /** * Address Firefox 4+ setting `line-height` on `input` using `!important` in * the UA stylesheet. */ button, input { line-height: normal; } /** * Address inconsistent `text-transform` inheritance for `button` and `select`. * All other form control elements do not inherit `text-transform` values. * Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+. * Correct `select` style inheritance in Firefox 4+ and Opera. */ button, select { text-transform: none; } /** * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` * and `video` controls. * 2. Correct inability to style clickable `input` types in iOS. * 3. Improve usability and consistency of cursor style between image-type * `input` and others. */ button, html input[type="button"], /* 1 */ input[type="reset"], input[type="submit"] { -webkit-appearance: button; /* 2 */ cursor: pointer; /* 3 */ } /** * Re-set default cursor for disabled elements. */ button[disabled], html input[disabled] { cursor: default; } /** * 1. Address box sizing set to `content-box` in IE 8/9/10. * 2. Remove excess padding in IE 8/9/10. */ input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ } /** * 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome. * 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome * (include `-moz` to future-proof). */ input[type="search"] { -webkit-appearance: textfield; /* 1 */ -moz-box-sizing: content-box; -webkit-box-sizing: content-box; /* 2 */ box-sizing: content-box; } /** * Remove inner padding and search cancel button in Safari 5 and Chrome * on OS X. */ input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; } /** * Remove inner padding and border in Firefox 4+. */ button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } /** * 1. Remove default vertical scrollbar in IE 8/9. * 2. Improve readability and alignment in all browsers. */ textarea { overflow: auto; /* 1 */ vertical-align: top; /* 2 */ } /* ========================================================================== Tables ========================================================================== */ /** * Remove most spacing between table cells. */ table { border-collapse: collapse; border-spacing: 0; } ================================================ FILE: docs/_sass/vendor/highlight/xcode.scss ================================================ /* XCode style (c) Angel Garcia */ pre code { display: block; padding: 0.5em; background: #fff; color: black; } pre .comment, pre .template_comment, pre .javadoc, pre .comment * { color: rgba(0, 0, 0, 0.27); } pre .keyword, pre .literal, pre .nginx .title { color: rgb(170,13,145); } pre .method, pre .list .title, pre .tag .title, pre .setting .value, pre .winutils, pre .tex .command, pre .http .title, pre .request, pre .status { color: #008; } pre .envvar, pre .tex .special { color: #660; } pre .string { color: rgb(196,26,22); } pre .tag .value, pre .cdata, pre .filter .argument, pre .attr_selector, pre .apache .cbracket, pre .date, pre .regexp { color: #080; } pre .sub .identifier, pre .pi, pre .tag, pre .tag .keyword, pre .decorator, pre .ini .title, pre .shebang, pre .prompt, pre .hexcolor, pre .rules .value, pre .css .value .number, pre .symbol, pre .symbol .string, pre .number, pre .css .function, pre .clojure .title, pre .clojure .built_in, pre .function .title, pre .coffeescript .attribute { color: rgb(28,0,207); } pre .class .title, pre .haskell .type, pre .smalltalk .class, pre .javadoctag, pre .yardoctag, pre .phpdoc, pre .typename, pre .tag .attribute, pre .doctype, pre .class .id, pre .built_in, pre .setting, pre .params, pre .clojure .attribute { color: rgb(92,38,153); } pre .variable { color: rgb(63,110,116); } pre .css .tag, pre .rules .property, pre .pseudo, pre .subst { color: #000; } pre .css .class, pre .css .id { color: #9B703F; } pre .value .important { color: #ff7700; font-weight: bold; } pre .rules .keyword { color: #C5AF75; } pre .annotation, pre .apache .sqbracket, pre .nginx .built_in { color: #9B859D; } pre .preprocessor, pre .preprocessor * { color: rgb(100,56,32); } pre .tex .formula { background-color: #EEE; font-style: italic; } pre .diff .header, pre .chunk { color: #808080; font-weight: bold; } pre .diff .change { background-color: #BCCFF9; } pre .addition { background-color: #BAEEBA; } pre .deletion { background-color: #FFC8BD; } pre .comment .yardoctag { font-weight: bold; } pre .method .id { color: #000; } ================================================ FILE: docs/api.html ================================================ --- layout: default title: List API redirect_from: - /docs/list-api - /docs/options ---

        List API

        Options

        Properties

        Methods

        Options

        Using List.js is pretty much plug and play, but you can change some options if you feel like it.

        new List(id/element, options, values);
        • id or element *required
          Id the element in which the list area should be initialized. OR the actual element itself.
        • options Object, default: undefined
          Some of the option parameters are required at some times

          • valueNames Array, default: null. *required
            If the list contains items on initialization, then this array has to contain the value names (class names) for the different values of each list item.

            <ul class="list">
                <li>
                    <span class="name">Jonny</span>
                    <span class="city">Sundsvall</span>
                </li>
            </ul>
            
            var valueNames = ['name', 'city'];
            
            <ul class="list">
             <li data-id="1">
               <a href="http://javve.com" class="link name">Jonny</a>
               <p class="born timestamp" data-timestamp="1234">1986</p>
               <img class="image" src="javve.jpg" />
             </li>
            </ul>
            
            var valueNames =  [
              'name',
              'born',
              { data: ['id'] },
              { name: 'timestamp', attr: 'data-timestamp' },
              { name: 'link', attr: 'href' },
              { name: 'image', attr: 'src' }
            ];
          • item String, default: undefined
            ID to item template element or a string of HTML. Can also be a function which receives a values object and which must return the complete item's HTML as a string.

            var options = {
                item: "<li><span class='name'></span><span class='city'></span></li>"
            }
            // or
            var options = {
                item: 'cool-item-id'
            };
            // or
            var options = {
                item: function(values) {
                  return `<li><span class='name'>${values.name}</span><span class='city'>${values.city}</span></li>`;
                }
            };
            
          • listClass String, default: "list"
            What is the class of the list-container?

          • searchClass String, default: "search"
            What is the class of the search field?

          • searchColumns Array of strings, default: undefined
            Restrict searching to just these column names? Default is to search all columns.

          • searchDelay Int default: 0
            Delay in milliseconds after last keypress in search field before search starts. 250→750 is good for very large lists.

          • sortClass String, default: "sort"
            What is the class of the sort buttons?

          • indexAsync Boolean, default: false
            If there are already items in the list to which the List.js-script is added, then should the indexing be done in a asynchronous way? Good for large lists (> 500 items).

          • page Int, default: 200
            Defines how many items that should be visible at the same time. This affects performance.

          • i Int, default: 1
            Which item should be shown as the first one.

          • pagination Boolean, default: undefined
            Read more here.

        • values Array of objects, default: undefined
          Values to add to the list on initialization.

        Properties

        • listContainer Element
          The element node that contains the entire list area.

        • list Element
          The element containing all items.

        • items Array
          An Array of all Item-objects in the list.

        • visibleItems Array
          The currently visible items in the list

        • matchingItems Array
          The items matching the currently active filter and search.

        • searched Boolean
          Returns true if the list is searched.

        • filtered Boolean
          Returns true if there is an active filter.

        Methods

        • add(values, callback)
          Adds one or more items to the list.

          listObj.add({ name: "Jonny", city: "Stockholm" });
          
          listObj.add([
          { name: "Gustaf", city: "Sundsvall" }
          , { name: "Jonas", city: "Berlin" }
          ]);

          If callback is set then items are added to the list in a asynchronous way, and the callback is called when all items are added. This is especially useful when adding very many items (200+ or something), or if you just like the asynchronous coding style.

          listObj.add(arrayWithManyManyItems, function(items) {
          console.log('All ' + items.length + ' were added!');
          });
        • remove(valueName, value)
          Removes items from the list where the value named valueName has value value. Returns the number of items that where removed.

          itemsInList = [
          { id: 1, name: "Jonny" }
          , { id: 2, name "Gustaf" }
          ];
          listObj.remove("id", 1); // return 1
        • get(valueName, value)
          Returns values from the list where the value named valueName has value value.

          itemsInList = [
          { id: 1, name: "Jonny" }
          , { id: 2, name "Gustaf" }
          ];
          listObj.get("id", 2); // return { id: 2, name "Gustaf" }
        • sort(valueName, {
            order: 'desc',
            alphabet: undefined,
            insensitive: true,
            sortFunction: undefined
          })

          Sorts the list based on values the in the column named valueName. The alphabet option is used when you have non-english alphabet where which JavaScript don't know how to sort some characters by default.

          The default sort function is found here https://github.com/nwoltman/string-natural-compare, if you want to use your own, read the code and check out the tests.

          listObj.sort('name', { order: "asc" }); // Sorts the list in abc-order based on names
          listObj.sort('name', { order: "desc" }); // Sorts the list in zxy-order based on names
          
          // Sort swedish characters correcly, case-insensitive.
          listObj.sort('name', { alphabet: "ABCDEFGHIJKLMNOPQRSTUVXYZÅÄÖabcdefghijklmnopqrstuvxyzåäö" });
          
          // Sort swedish characters correcly, case-sensitive.
          listObj.sort('name', { alphabet: "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvXxYyZzÅåÄäÖö" });
          
          // Alphabet could also be on the actual listObj via
          listObj.alphabet = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvXxYyZzÅåÄäÖö";
          
        • search(searchString, columns, searchFunction)
          Searches the list

          itemsInList = [
          { id: 1, name: "Jonny Stromberg", born: 1986 }
          , { id: 2, name "Jonas Arnklint", born: 1985 }
          , { id: 3, name "Martina Elm", born: 1986 }
          , { id: 4, name "Gustaf Lindqvist", born: 1983 }
          , { id: 5, name "Jonny Strandberg", born: 1990 }
          ];
          
          listObj.search('Jonny'); // Only items with name Jonny are shown (also returns these items)
          
          listObj.search(); // Show all items in list
          
          listObj.search('Jonny', ['name']); // Only search in the 'name' column

          Space-separated words match in any order using logical AND. Surround a phrase in quotes for exact matches:

          listObj.search('Jon 198'); // Items that match Jon AND 198
          
          listObj.search('"Jonny S" 1990'); // Items that match "Jonny S" AND 1990

          Optionally your own search function can be used:

          listObj.search('Jonny', searchFunction); // Custom search for Jonny
          
          listObj.search('Jonny', ['name'], searchFunction); // Custom search in the 'name' column
          
          function searchFunction(searchString, columns) {
            for (var k = 0, kl = listObj.items.length; k < kl; k++) {
               listObj.items[k].found = false;
               // Insert your custom search logic here, set found = true
          
            }
          };
        • clear()
          Removes all items from the list

        • filter(filterFunction)

          itemsInList = [
          { id: 1, name: "Jonny" }
          , { id: 2, name "Gustaf" }
          , { id: 3, name "Jonas" }
          ];
          
          listObj.filter(function(item) {
          if (item.values().id > 1) {
             return true;
          } else {
             return false;
          }
          }); // Only items with id > 1 are shown in list
          
          listObj.filter(); // Remove all filters
        • size()
          Returns the size of the list.

        • show(i, page)
          Shows page number of items from i. Use for paging etc.

          itemsInList = [
          { id: 1, name: "Jonny" }
          , { id: 2, name "Gustaf" }
          , { id: 3, name "Jonas" }
          , { id: 4, name "Egon" }
          , { id: 5, name "Frank" }
          , { id: 6, name "Ester" }
          ];
          
          listObj.show(4, 3); // Display item 4,5,6 
        • update()
          Updates the current state of the list. Meaning that if you for instance hides some items with the itemObj.hide() method then you have to call listObj.update() if you want the paging to update.

        • reIndex()
          Re-index list from HTML. Good to use if the HTML has been changed by something else than List.js.

        • fuzzySearch()
          Read more here

        • on(event, callback)
          Execute callback when list have been updated (triggered by update(), which is used by a lot of methods). Use updated as the event.

          Avaliable events

          • updated
          • searchStart
          • searchComplete
          • filterStart
          • filterComplete
          • sortStart
          • sortComplete
        ================================================ FILE: docs/assets/css/style.scss ================================================ --- # Only the main Sass file needs front matter (the dashes are enough) --- $blue: #28a8e0; $green: #6cd25e; $grey: #555; $orange: #f59621; $lightGrey: #edf4f4; $black: #2e2e2e; $menuWidth: 250px; @import "normalize"; @import "mixins"; @import "vendor/highlight/xcode"; @import "carbonads"; @import "menu"; @import "docs"; /* * * * * * * * * * * * * * * * * * * * * * General * * * * * * * * * * * * * * * * * * * * */ html { font-size: 62.5%; } body { background-color:#fff; font-size:16px; font:400 1.6rem/1.4 'source sans pro', 'helvetica neue', helvetica, arial; color:$grey; padding:0; //80px 0 150px; } a { color:$blue; &:hover { color:darken($blue, 10%); } } p { font-size: 16px; font-size:1.6rem; line-height:1.3; strong, b { color:darken($grey, 20%); font-weight: 500; } } h1 { font-size: 50px; font-size: 5rem; color:$orange; font-weight:400; margin:0 0 30px; } h2 { font-size: 30px; font-size:3rem; color:$black; font-weight:400; } h3 { font-weight:600; font-size:2rem; margin-bottom:10px; color:$black; } h4 { font-weight:600; font-size: 16px; font-size:1.6rem; margin-bottom:10px; color:$black; } .btn { font-size: 18px; font-size: 1.8rem; padding:8px 30px; border-radius: 6px; border:solid 2px $blue; display:inline-block; color:$blue; text-decoration: none; &.btn-primary { border-color:$blue; background-color: $blue; color:#fff; font-weight: 500; &:hover { background-color: darken($blue, 10%); color:#eee; } } } .btn:hover { text-decoration: none; color:darken($blue, 10%); border-color:darken($blue, 10%); } .donate-form { display:inline-block; margin-left:5px; } .donate { border:none; background:none; padding:0; margin:0 10px 0 0; float:left; span { // #gradient > .vertical(#fafafa, #eaeaea); border: 1px solid #b7b7b7; border-bottom-color: #888; display:block; padding: 2px 5px 2px 4px; color: #111; text-decoration: none; text-shadow: 0 1px 0 #fff; white-space: nowrap; cursor: pointer; border-radius: 3px; font: bold 11px/14px "Helvetica Neue",Helvetica,Arial,sans-serif; padding-left:20px; position:relative; &:hover { color:#fff; text-decoration: none; background-color:$blue; text-shadow: 0 1px 0 darken($blue, 20%); background-image:none; border-color:darken($blue, 10%); } &:before { content:" "; display: block; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDE0IDc5LjE1MTQ4MSwgMjAxMy8wMy8xMy0xMjowOToxNSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChNYWNpbnRvc2gpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjMyOUYyMjMyNTAzNDExRTM4RjkxRjY4OERCMDI3N0ZEIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjMyOUYyMjMzNTAzNDExRTM4RjkxRjY4OERCMDI3N0ZEIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6MzI5RjIyMzA1MDM0MTFFMzhGOTFGNjg4REIwMjc3RkQiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6MzI5RjIyMzE1MDM0MTFFMzhGOTFGNjg4REIwMjc3RkQiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6BnPLgAAAENklEQVR42tRVTUxjVRT+3usr7WtLy//wV0YIIFBLJwYNkChOnGCMCZMYEo2uTMRodKFxdi5cqUwMKxdG3ao4sxuTyWAwJIoybQBxhkmGQAoMM/xJSynQn9f29fndpyXMj8bNLDzJyXt9997vnvOd75xKhmHgYZiMh2TKvR80TauOx+PuWCxWmclkLJIk5elWukpbLS8vX3Y6nZLFYkn9J+Ctra1HQ6HQe0tLSy+n05rHZrfDoapQHQ5YrVbIkgRJlpDP5zN2m22+qanpemtr65jL5brM44l7gSXBcTAYfH109LuvVKcLrS0tKCku5kIOei6FXCYBxWKF010Kt6cMqsuNREpDOBzmehb9/f3nvF7vyH3Aa2trJz45f36rvs4Lh5zByo0gbi0vIBb5A6mshlwuL7bBYpGh2uyoqj2J9s4n0P3M89AMBalkQvf7/V8uLi4u2Gy2+q6uri9qamrWpWAo9NTFCxd/jqzewOK1n2Dk09AJlaNYstm7q0w2TLfSVacHz734GvxPnsby8rK5J5Vihrnc7aGhoReUvJ5HW2sTLvxyGdE4QY2/DjNI6Lr5+Du3Y+/cY0nGMRsK4sTJdtR7vR+fHRj4TNf1V4aHh0fm5uYSCjnOO1wefPr51/j+0iVM/HAFG2thxON7BDIgGyYODAEsW1BWVomGphY8ffoMfIEAZmd/g+8xf5gFztO/kWV5JJvNHiqVlRWYn78Om13Fu++fw1tvv4M7t29hZWUVWlrD4T4vkGS43B4U2YrAQsGuOnBwcIjV1RVmleNlvA2IRiKRwObmJnp7e8sV6lJUB3t7e6A+4XIVo8PnR+epxykx2cybEiPfWSQSScRiu9jd3eX7ockpQdHY2HiHmZeNj4+fKaaiOjs70woXbtI/2tnZ+aC0tJTRSWYUQrtsAgg5siBgsyCZTJouLiGf5tPn84kLuiYmJl6amZl5dnBwcKCqqmrT1PHCwoI0PT291tzcXF9SUgI7m6OoqOgIWACwI80IC+AHBwdgMGhrawtTFdsbGxuRnp6eN/v6+jaPGkTY2NiYO51OX6muru51sNsURTkCFtEJYOHcQxoSJh288GpFRcWHHo8nzaCm6+rqNGZs3NXSHR0d6cnJyeT6+rrJG8UOVvgIuECHiDoajWJ/fx/t7e3XyOePTF0EYSWMo9De0vGxydY+Rb/KaO2MxKSkAC6iFZFub2+bVLDbRgOBwKsClBnaeUbl3t0HTrfu7u7fOdW6WIRfOYw84psoolCFoEA4h44A/bahoeENqkgmIPHkDD113xASxjRlFsyU3tTUlEpgC+eIypQbSMUjXNNra2unOdWi1LLMSA23281BZ9MInnzgdCsYAWzkSiv8ZrUlMZO5Ryef5kY2gRjMQjViJnOampb9V+DjxkvMNbpdzH9RbboAEsM/W6j+P5n0v/vP+1OAAQAqLhyT7hjz3gAAAABJRU5ErkJggg==); background-repeat: no-repeat; background-size: 14px; width:14px; height:14px; z-index: 1; position: absolute; left:3px; top:3px; } } } .donate-pixel { position: absolute; } table { border-collapse:collapse; width:100%; margin-bottom:10px; } th { background-color:rgba(0,0,0,.1); border:solid 1px rgba(255,255,255,.1); padding:10px 10px; text-align:left; font-weight: bold; color:#ddd } td { padding:10px 10px; border:solid 1px rgba(255,255,255,.1); } .example-header { margin-bottom:15px; h1 { margin-bottom:0; } p { margin-top:10px; } } .continue { margin-top: 30px; border-top: solid 1px #eee; padding-top: 15px; text-align: right; font-weight: bold; color: #222; } .footer { //position: fixed; //bottom:0; clear:both; width:100%; height:20px; padding:20px 0; background-color:#111; text-align: center; a { color:#fff; &:hover { color:$lightGrey; } } .misc-share-button { display: inline-block; height: 20px; overflow: hidden; } .tweet { width:100px; } .facebook { width:90px; .fb_iframe_widget span { vertical-align: top !important; } } } /* * * * * * * * * * * * * * * * * * * * * * Start page * * * * * * * * * * * * * * * * * * * * */ .intro { @extend %clearfix; margin:0 auto; max-width: 900px; padding:80px; box-sizing: border-box; .intro-logo { text-align: center; img { max-width: 80%; } float: left; width:30%; } .intro-text { float: left; width:70%; h1 { font-size: 72px; font-size: 7.2rem; margin: 0 0 1px; small { font-size: 30px; font-size: 3rem; color:lighten($grey, 20%); } } h2 { font-size: 25px; font-size: 2.5rem; font-weight: 300; margin: 0 0 25px; color:lighten($grey, 20%); a { font-weight: 500; } em { color:darken($grey, 20%); } } .btn { margin-right:10px; } } } .misc { @extend %clearfix; clear:both; background-color:$lightGrey; padding:30px; margin:30px -30px; color:#333; h3 { margin:0 0 5px; } .misc-share { margin-bottom:5px; } .misc-author { .misc-author-pic { float:left; margin-right:20px; border-radius: 5px; } h4 { margin-top:0; margin-bottom: 4px; } p { font-size: 14px; font-size:1.4rem; color:lighten($black, 10%); margin-top:0; margin-bottom: 10px; } } } // .loaded .misc-carbon:before & { // content:"Everytime you hide an ad... An open source developer goes to go to bed instead of buying a coffee :'(\A <--- Cheat? Donate! :D"; // white-space: pre-wrap; // width:260px; // display: block; // text-align: center; // left:20px; // top:20px; // position: relative; // font-size: 12px; // font-size:1.2rem; // font-family: monaco, monospace; // } .startpage-quotes { @extend %clearfix; padding:60px 0; .startpage-quotes-quote { width:33%; float:left; padding: 0 10px; box-sizing: border-box; } } .startpage-more-examples { clear:both; ul { padding:0 !important; margin:0; } li { display:inline-block; margin-right:15px; } } .startpage-examples { .startpage-example { @extend %clearfix; display:none; &.active { display: block; } } } .annotated-examples { h3 { margin-top:50px; } } .columns { overflow: hidden; padding:0; margin:0 -30px 5px; display: -webkit-flex; display: -ms-flexbox; display: flex; overflow: hidden; .column { padding:20px 30px; flex: 1; background-color: $lightGrey; &:last-child { background-color: darken($lightGrey, 2%); } pre { background-color: transparent; margin:0; padding:0; } } } .annotated-list { box-sizing: border-box; @extend %clearfix; .list { padding-top:20px; & > div { padding:10px 0; border-top:solid 1px rgba(255,255,255,.1); } } .avatar { max-width: 150px; img { max-width: 100%; } } h3 { font-size:16px; font-size: 1.6rem; margin:0 0 3px; font-weight: bold; //color:#fff; } p { margin:0; //color:#eee; } input { border-radius: 25px; padding:7px 14px; background-color: transparent; border:solid 1px rgba(0,0,0,.2); width:200px; box-sizing: border-box; color:$black; margin-bottom:5px; } input:focus { outline:none; border-color:#aaa; } .sort { font-size:12px; font-size: 1.2rem; padding:5px 15px; border-radius: 25px; border:none; display:inline-block; color:$black; text-decoration: none; background-color: rgba(0,0,0,.05); margin:2px 0; } .sort:hover { text-decoration: none; background-color: rgba(0,0,0,.1); } .sort:focus { outline:none; } .sort:after { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 4px solid transparent; content:""; position: relative; top:-10px; right:-4px; } .sort.asc:after { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 4px solid $black; content:""; position: relative; top:11px; right:-4px; } .sort.desc:after { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 4px solid $black; content:""; position: relative; top:-9px; right:-4px; } } /* * * * * * * * * * * * * * * * * * * * * * Examples * * * * * * * * * * * * * * * * * * * * */ .nav-tabs { .active a { background-color: $lightGrey !important; } } /* * * * * * * * * * * * * * * * * * * * * * Paging * * * * * * * * * * * * * * * * * * * * */ .paging { padding-bottom:10px; clear:both; float:left; } .paging li { display:block; float:left; padding:10px 15px; border-radius:50%; } .paging li a { color:#999; text-decoration:none; display:inline-block; line-height:14px; } .paging li.active a { font-weight:bold; color:#eee; font-size:18px; margin:-1px; } .paging li a:hover { color:#eee; } code { background-color: $lightGrey; border: solid 1px darken($lightGrey, 5%); border-radius: 5px; padding: 1px 4px; } pre { padding:30px; margin:0; line-height:1.7; color:#666; } pre code { padding:0; border:none; background-color: transparent; border-radius: 0; } pre, code { font-family: monospace, 'monaco', sans-serif; font-size: 12px; font-size: 1.2rem; } pre code .annotation { background-color: $orange; color: #fff; padding: 2px 6px; border-radius: 11px; cursor:help; &:hover { background-color:darken($orange, 10%); } } ================================================ FILE: docs/assets/javascripts/main.js ================================================ --- --- {% include javascripts/vendor/jquery-1.8.3.min.js %} {% include javascripts/vendor/highlight.pack.js %} hljs.initHighlightingOnLoad(); $(window).load(function() { $('body').addClass('loaded'); }); var options = { valueNames: [ 'name', 'born' ] }; var userList = new List('users', options); ================================================ FILE: docs/docs/fuzzysearch.html ================================================ --- layout: default title: Fuzzy search plugin ---

        Fuzzy search

        Note: The fuzzy search plugin is deprecated since v1.5.0, it's now bundled into List.js. Read the old docs here.

        The difference between Fuzzy Search and List.js default search

        The default search will conduct a time efficient search for an exact match in the content searched, while the fuzzy search will render results depending on if they are included anywhere in the content.

        Basic example

        var items = [
            { character: "Guybrush Threepwood", game: "The Secret of Monkey Island" },
            { character: "Manny Calavera", game: "Grim Fandango" },
            { character: "Bernard Bernoulli", game: "Maniac Mansion" }
        ];
        
        list.search('gu thre'); // return none
        list.fuzzySearch('gu thre') // return 1 item
        

        Options

        All options are optional. Simplest implementation is:

        new List(id, { fuzzySearch: options });
        • searchClass String, default: fuzzy-search
          What is the class of the search field?
        • location Int, default: 0
          Approximately where in the text is the pattern expected to be found?
        • distance Int, default: 100
          Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is ‘distance’ characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match be at the exact location specified, a threshold of 1000 would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
        • threshold Int, default: 0.4
          At what point does the match algorithm give up. A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything.
        • multiSearch Boolean, default: true
          Subtract arguments from the searchString or put searchString as only argument

        Implementation

        <div id="list-id">
          <input class="fuzzy-search" />
          <ul class="list">
            / A bunch of items /
          </ul>
        </div>
        
        <script>
        
        var options = {
          valueNames: [ 'name', 'category' ],
          fuzzySearch: {
            searchClass: "fuzzy-search",
            location: 0,
            distance: 100,
            threshold: 0.4,
            multiSearch: true
          }
        };
        
        var listObj = new List('list-id', options);
        
        // Search manually
        listObj.fuzzySearch('my search');
        
        // Search manually on specific columns
        listObj.fuzzySearch('my search', [ 'name' ]);
        
        </script>
        

        A big thanks to LuukvE who made a commit from which I could create this Fuzzy Search plugin.

        ================================================ FILE: docs/docs/index.html ================================================ --- layout: default title: Really simple example ---

        Really simple examples

        You can use List.js on either existing HTML or create new with super simple templating.

        Example 1: Using existing list

        HTML
        <div id="hacker-list">
          <ul class="list">
            <li>
               <h3 class="name">Jonny</h3>
               <p class="city">Stockholm</p>
            </li>
            <li>
              <h3 class="name">Jonas</h3>
              <p class="city">Berlin</p>
            </li>
          </ul>
        </div>
        JavaScript
        var options = {
            valueNames: [ 'name', 'city' ]
        };
        
        var hackerList = new List('hacker-list', options);


        Example 2: Create list on initialization: Version 1

        HTML
        <div id="hacker-list">
            <ul class="list"></ul>
        </div>
        JavaScript
        var options = {
          valueNames: [ 'name', 'city' ],
          item: '<li><h3 class="name"></h3><p class="city"></p></li>'
        };
        
        var values = [
          { name: 'Jonny', city:'Stockholm' }
          , { name: 'Jonas', city:'Berlin' }
        ];
        
        var hackerList = new List('hacker-list', options, values);


        Example 3: Create list on initialization: Version 2

        HTML
        <div id="hacker-list">
          <ul class="list"></ul>
        </div>
        
        <div style="display:none;">
          <!-- A template element is needed when list is empty, TODO: needs a better solution -->
          <li id="hacker-item">
           <h3 class="name"></h3>
           <p class="city"></p>
          </li>
        </div>
        JavaScript
        var options = {
            item: 'hacker-item'
        };
        
        var values = [
            { name: 'Jonny', city:'Stockholm' }
            , { name: 'Jonas', city:'Berlin' }
        ];
        
        var hackerList = new List('hacker-list', options, values);


        Example 4: Index existing list and then add

        HTML
        <div id="hacker-list">
          <ul class="list">
           <li>
             <h3 class="name">Jonny</h3>
             <p class="city">Stockholm</p>
           </li>
          </ul>
        </div>
        JavaScript
        var options = {
          valueNames: ['name', 'city']
        };
        
        var hackerList = new List('hacker-list', options);
        
        hackerList.add( { name: 'Jonas', city:'Berlin' } );


        Example 5: Add automagic search and sort inputs and buttons

        HTML
        <div id="hacker-list">
        
          <input class="search" />
          <span class="sort" data-sort="name">Sort by name</span>
          <span class="sort" data-sort="city">Sort by city</span>
        
          <ul class="list">
           <li>
             <h3 class="name">Jonny</h3>
             <p class="city">Stockholm</p>
           </li>
           <li>
             <h3 class="name">Jonas</h3>
             <p class="city">Berlin</p>
           </li>
          </ul>
        </div>
        JavaScript (nothing special)
        var options = {
          valueNames: [ 'name', 'city' ]
        };
        
        var hackerList = new List('hacker-list', options);

        Read more here



        Example 6: Using data attributes and other custom attributes (introduced in v1.2.0)

        HTML
        <div id="hacker-list">
          <ul class="list">
           <li data-id="1">
             <a href="http://javve.com" class="link name">Jonny</a>
             <p class="born timestamp" data-timestamp="1234">1986</p>
             <img class="image" src="javve.jpg" />
           </li>
          </ul>
        </div>
        JavaScript
        var options = {
          valueNames: [
            'name',
            'born',
            { data: ['id'] },
            { name: 'timestamp', attr: 'data-timestamp' },
            { name: 'link', attr: 'href' },
            { name: 'image', attr: 'src' }
          ]
        };
        
        var hackerList = new List('hacker-list', options);
        
        hackerList.add({
          name: 'Jonas',
          born: '1985',
          id: 2,
          timestamp: '1337',
          link: 'http://arnklint.com'
          image: 'jonas.gif'
        });
        Next topic: Options ›
        ================================================ FILE: docs/docs/item-api.html ================================================ --- layout: default title: Item API ---

        Item API

        These methods are available for all Items that are returned by the list.

        Properties

        • elm Element
          The actual item DOM element
        • _values Array
          Direct access to the item's values. Simplifies debugging. Note: Always use item.values() when interacting with the values.

        Methods

        • values(newValues)

          • newValues optional
            If variable newValues are present the new values replaces the current item values and updates the list. If newValues are not present, the function returns the current values.

            item.values() // { name: "Jonny", age: 24, city: "Umeå" }
              item.values({
                  age: 25,
                  city: "Stockholm"
              });
              item.values() // { name: "Jonny", age: 25, city: "Stockholm" }
              
        • show()
          Shows the item

        • hide()
          Hides the item (removes the element from the list, and then when its shown it's appended again. The element will thereby change position in the list. A bug, but a good solution is yet to be found.)

        • matching() Boolean
          Returns boolean. True if the item matches the current filter and search. Visible items always matches, but matching items are not always visible.

        • visible() Boolean
          Returns boolean. True if the item is visible. Visible items always matches, but matching items are not always visible.

        ================================================ FILE: docs/docs/pagination.html ================================================ --- layout: default title: Pagination ---

        Pagination

        Note: The pagination plugin is deprecated since v1.5.0, it's now bundled into List.js. Read the old docs here.

        Basic example

        <div id="listId">
          <ul class="list">
              // A bunch of items
          </ul>
          <ul class="pagination"></ul>
        </div>
        
        <script>
          var options = {
            valueNames: [ 'name', 'category' ],
            page: 3,
            pagination: true
          };
        
          var listObj = new List('listId', options);
        </script>
        

        Options

        • paginationClass String, default: “pagination”
          The class that defines which ul that should contain the pagination (must be inside the list container)
        • innerWindow Int, default: 2
          How many pages should be visible on each side of the current page.
          innerWindow: 2 … 3 4 5 6 7 …
          innerWindow: 1 … 4 5 6 …
        • outerWindow Int, default: 0
          How many pages should be visible on from the beginning and from the end of the pagination.
          outerWindow: 0 … 3 4 5 6 7…
          outerWindow: 2 1 2 … 4 5 6 7 8 … 11 12
        • left Int, default: 0
          Same as outerWindow but only from left. outerWindow: 2 and left: 1 1 … 4 5 6 7 8 … 11 12
        • right Int, default: 0
          Same as left but from right.
        • item String, default <li><a class='page' href='#'></a></li>
          Template for the pagination items.

        Notice

        The number of items at each page are decided by the List.js own property page. To set this just add page: Number to the option object sent into the List.js constructor (as been done in both of the examples at this page).

        Generated output

        <div id="listId">
          <ul class="list">
              / A bunch of items /
          </ul>
          <ul class="pagination">
            <li>
              <a class="page active" href="javascript:function Z(){Z=""}Z()">1</a>
            </li>
            <li>
              <a class="page" href="javascript:function Z(){Z=""}Z()">2</a>
            </li>
            <li>
              …
            </li>
          </ul>
        </div>
        

        Double pagination

        <div id="listId">
          <ul class="paginationTop"></ul>
          <ul class="list">
            // A bunch of items
          </ul>
          <ul class="paginationBottom"></ul>
        </div>
        
        <script>
          var listOptions = {
            valueNames: [ 'name', 'category' ],
            page: 3,
            pagination: [{
              name: "paginationTop",
              paginationClass: "paginationTop",
              outerWindow: 2
            }, {
              paginationClass: "paginationBottom",
              innerWindow: 3,
              left: 2,
              right: 4
            }]
          };
        
          var listObj = new List('listId', listOptions);
        </script>
        ================================================ FILE: docs/docs/plugins/build.html ================================================ --- layout: default title: Build your own plugin ---

        Build your own plugin

        A List.js plugin is basically a function/class which returns a object on initialization.

        A basic example plugin

        The plugin code list.awesomething.js

        function ListAwesomething() {
          options = options || {};
          return {
            init: function(list) {
              // This method is called on initialization
            },
            name: options.name || "awesomething",
            customMethod: function() {
              return "cowabunga";
            }
          };
        };
        

        Using the plugin

        <script src="list.js"></script>
        <script src="list.awesomething.js"></script>
        <script>
          var myList = new List('my-list', {
            plugins: ListAwesomething()
          });
        
          myList.awesomething.customMethod(); // cowabunga
        </script>
        

        Requirements / Specifications

        • A plugin namned Awesome Thing have to be in a JavaScript file namned list.awesomething.js (no dash, camelcase or anything) and the function/class have to be namned ListAwesomeThing (camelcase but no dash anything else).
        • The plugin object must contain an init method.
        • The plugin object must contain an name attribute that defaults to the plugin name.

        Live example

        Check this out!

        <% locals.mediaTempleTerm = "plugin" %> ================================================ FILE: docs/docs/plugins/fuzzysearch.html ================================================ --- layout: default title: Fuzzy search plugin ---

        Fuzzy search plugin

        Note: The fuzzy search plugin is deprecated since v1.5.0, it's now bundled into List.js.

        To use the plugin you first need to download it:

        Via GitHub

        Download list.fuzzysearch.js

        Via Bower

        bower install list.fuzzysearch.js

        Via CDNJS

        <script src="//cdnjs.cloudflare.com/ajax/libs/list.fuzzysearch.js/0.1.0/list.fuzzysearch.min.js"></script>

        The difference between Fuzzy Search and List.js default search

        The default search will conduct a time efficient search for an exact match in the content searched, while the fuzzy search will render results depending on if they are included anywhere in the content.

        Basic example

        var items = [
            { character: "Guybrush Threepwood", game: "The Secret of Monkey Island" },
            { character: "Manny Calavera", game: "Grim Fandango" },
            { character: "Bernard Bernoulli", game: "Maniac Mansion" }
        ];
        
        list.search('gu thre'); // return none
        list.fuzzySearch.search('gu thre') // return 1 item
        

        Implementation

        <div id="list-id">
          <input class="fuzzy-search" />
          <ul class="list">
            / A bunch of items /
          </ul>
        </div>
        
        <script>
        
        var fuzzyOptions = {
          searchClass: "fuzzy-search",
          location: 0,
          distance: 100,
          threshold: 0.4,
            multiSearch: true
        };
        var options = {
          valueNames: [ 'name', 'category' ],
          plugins: [
            ListFuzzySearch(fuzzyOptions)
          ]
        };
        
        var listObj = new List('list-id', options);
        
        // Search manually
        listObj.fuzzySearch.search('my search');
        
        // Search manually on specific columns
        listObj.fuzzySearch.search('my search', { name: true });
        
        </script>
        

        Options

        All options are optional. Simplest implementation is:

        plugins: [ ListFuzzySearch() ]
        • location Int, default: 0
          Approximately where in the text is the pattern expected to be found?
        • distance Int, default: 100
          Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is ‘distance’ characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match be at the exact location specified, a threshold of 1000 would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
        • threshold Int, default: 0.4
          At what point does the match algorithm give up. A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything.
        • multiSearch Boolean, default: true
          Subtract arguments from the searchString or put searchString as only argument

        A big thanks to LuukvE who made a commit from which I could create this Fuzzy Search plugin.

        ================================================ FILE: docs/docs/plugins/index.html ================================================ --- layout: default title: Using Plugins ---

        Using plugins

        Getting started

        To use a plugin you need two things:

        1. Include the plugins .js-file at the page.
        2. Include it when you instantiate List.js

          new List('list-id', {
            plugins: [ ListPagination(), NameOfOtherPlugin(options) ]
          });

        Naming and accessing plugins

        It is also possible to add options and load multiple instances of the same plugins (if the plugin itself allows it).

        If the property name is added in the plugin option parameter does the plugin become accessible through listObj.namePropertyValue.This is useful when having multiple instances of the same plugin.

        var myList = new List('list-id', {
          plugins: [
            ListPagination({ name: "topPagination", paginationClass: "top-pagination" }),
            ListPagination({ name: "bottomPagination", paginationClass: "bottom-pagination" })
          ]
        });
        console.log(myList.topPagination);
        console.log(myList.bottomPagination);

        Build your own plugin

        Go to: /docs/plugins/build

        ================================================ FILE: docs/docs/plugins/pagination.html ================================================ --- layout: default title: Pagination plugin ---

        Pagination plugin

        Note: The pagination plugin is deprecated since v1.5.0, it's now bundled into List.js.

        To use the plugin you first need to download it:

        Via GitHub

        Download List.pagination.js

        Via Bower

        bower install list.pagination.js

        Via CDNJS

        <script src="//cdnjs.cloudflare.com/ajax/libs/list.pagination.js/0.1.1/list.pagination.min.js"></script>

        Basic example

        <div id="listId">
          <ul class="list">
              // A bunch of items
          </ul>
          <ul class="pagination"></ul>
        </div>
        
        <script>
          var options = {
            valueNames: [ 'name', 'category' ],
            page: 3,
            plugins: [
              ListPagination({})
            ]
          };
        
          var listObj = new List('listId', options);
        </script>
        

        Options

        • name String, default: “pagination”
          Default option for all plugins. Defines how to access the plugin from the list object listObj.pluginName.
        • paginationClass String, default: “pagination”
          The class that defines which ul that should contain the pagination (must be inside the list container)
        • innerWindow Int, default: 2
          How many pages should be visible on each side of the current page.
          innerWindow: 2 … 3 4 5 6 7 …
          innerWindow: 1 … 4 5 6 …
        • outerWindow Int, default: 0
          How many pages should be visible on from the beginning and from the end of the pagination.
          outerWindow: 0 … 3 4 5 6 7…
          outerWindow: 2 1 2 … 4 5 6 7 8 … 11 12
        • left Int, default: 0
          Same as outerWindow but only from left. outerWindow: 2 and left: 1 1 … 4 5 6 7 8 … 11 12
        • right Int, default: 0
          Same as left but from right.

        Notice

        The number of items at each page are decided by the List.js own property page. To set this just add page: Number to the option object sent into the List.js constructor (as been done in both of the examples at this page).

        Generated output

        <div id="listId">
          <ul class="list">
              / A bunch of items /
          </ul>
          <ul class="pagination">
            <li>
              <a class="page active" href="javascript:function Z(){Z=""}Z()">1</a>
            </li>
            <li>
              <a class="page" href="javascript:function Z(){Z=""}Z()">2</a>
            </li>
            <li>
              …
            </li>
          </ul>
        </div>
        

        Double pagination

        <div id="listId">
          <ul class="paginationTop"></ul>
          <ul class="list">
            // A bunch of items
          </ul>
          <ul class="paginationBottom"></ul>
        </div>
        
        <script>
          var paginationTopOptions = {
            name: "paginationTop",
            paginationClass: "paginationTop",
            outerWindow: 2
          };
          var paginationBottomOptions = {
            name: "paginationBottom",
            paginationClass: "paginationBottom",
            innerWindow: 3,
            left: 2,
            right: 4
          };
          var listOptions = {
            valueNames: [ 'name', 'category' ],
            page: 3,
            plugins: [
                ListPagination(paginationTopOptions),
                ListPagination(paginationBottomOptions)
            ]
          };
        
          var listObj = new List('listId', listOptions);
        </script>
        ================================================ FILE: docs/docs/search-sort.html ================================================ --- layout: default title: Automagical Searching + Sorting ---

        Automagical Searching + Sorting

        It is easy to add search input and sort buttons with just a few classes and attributes in your HTML. ‘Automagical’ because List.js registers the event handlers, searches/sorts and updates the list for you:

        Searching

        • class String. *required
          The default class search is how List.js finds your writable search field. If you change it also set options.searchClass.

          Alternatively, using fuzzy-search here will switch to the Fuzzy Search function.

        • type String. *required
          The default input type search is similar to using text, but web browsers may render it slightly differently: see https://developer.mozilla.org/.../input/search. Either type will work with List.js.

        
        <input type="search" class="search" placeholder="normal search"> or
        <input type="search" class="fuzzy-search" placeholder="fuzzy search!">
        

        Sorting

        • class String. *required
          The default class sort is how List.js finds clickable sort buttons. If you change it also set options.sortClass.

        • data-sort String. *required
          This attribute on a clickable sort button should match the column name passed to List.js in options.valueNames.

        • data-order String
          Set to asc or desc to enforce that sorting order for a column. The user won't be able to change the order, and any data-default-order attribute is ignored.

        • data-default-order String, default: "asc"
          Set to desc to change the initial sorting order for a column. Subsequent clicks will toggle the sorting order between ascending/descending, as usual.

        • data-insensitive Boolean, default: true
          Set to false for case-sensitive sorting of that column.

        
        Sort by: 
        <span class='sort' data-sort='name'>Name</span> or 
        <span class='sort' data-sort='born' data-default-order='desc'>Born in Year</span> or 
        <span class='sort' data-sort='city'>City</span>
        

        The CSS classes asc and desc are added when a sort button is clicked on, so List.js can show which column is currently sorted. For example, using this CSS sets a yellow background with ⬆ or ⬇ added after the button text:

        
        .sort.asc, .sort.desc {
          background-color: yellow;
          }
        .sort.asc::after {
          content: "\002B06";
          padding-left: 3px;
          }
        .sort.desc::after {
          content: "\002B07";
          padding-left: 3px
          }
        
        ================================================ FILE: docs/faq.html ================================================ --- layout: default title: List FAQ ---

        List FAQ

        Questions



        I want to have a search field outside the list container.

        <input id="search-field" />
        <div id="container"> ... </div>
        var listObj = new List('container', options);
        
        $('#search-field').on('keyup', function() {
          var searchString = $(this).val();
          listObj.search(searchString);
        });
        ================================================ FILE: docs/feed.xml ================================================ --- layout: null --- {{ site.title | xml_escape }} {{ site.description | xml_escape }} {{ site.url }}{{ site.baseurl }}/ {{ site.time | date_to_rfc822 }} {{ site.time | date_to_rfc822 }} Jekyll v{{ jekyll.version }} {% for post in site.posts limit:10 %} {{ post.title | xml_escape }} {{ post.content | xml_escape }} {{ post.date | date_to_rfc822 }} {{ post.url | prepend: site.baseurl | prepend: site.url }} {{ post.url | prepend: site.baseurl | prepend: site.url }} {% for tag in post.tags %} {{ tag | xml_escape }} {% endfor %} {% for cat in post.categories %} {{ cat | xml_escape }} {% endfor %} {% endfor %} ================================================ FILE: docs/index.html ================================================ --- layout: default title: Search, sort, filters, flexibility to tables, list and more! ---

        List.js v{{site.data.pkg.version}}

        Tiny, invisible and simple, yet powerful and incredibly fast vanilla JavaScript that adds search, sort, filters and flexibility to plain HTML lists, tables, or anything.

        {% include author.html %} {% include examples/annotated-example.html %}

        More examples

        ================================================ FILE: docs/overview/changelog.html ================================================ --- layout: default title: Read the changelog at Github ---

        Changelog

        Go to the changelog at GitHub

        ================================================ FILE: docs/overview/contribute.html ================================================ --- layout: default title: Contribute ---

        Setup environment

        1. Install Node.js

        Go to Nodejs.org

        2. Install dependencies

        npm install

        Compile and test

        Compile the script (webpack.config.js)

        npx webpack

        Watch and recompile when files change

        npx webpack --watch

        Run the test suite

        npx jest

        Run tests continuously when files change

        npx jest --watch

        Guidelines for making pull requests

        • Add tests if applicable.
        • Make sure all tests run. Preferably in IE7+
        • Do not include dist/list.js or dist/list.min.js. That file is only update for each release.
        • ONE feature per pull request
        • List.js is used in a lot of different ways on a lot of places, so please have understanding if your new special feature is not accepted :)
        ================================================ FILE: docs/overview/download.html ================================================ --- layout: default title: Download ---

        Download

        The core thing in List.js have always been simplicity. It should require as little effort as possible to use the script and it's features.

        Via GitHub

        Download compressed List.js   5KB with gzip
        Download uncompressed List.js

        Via NPM

        npm install list.js

        Via Bower

        bower install list.js

        Via CDNJS

        <script src="//cdnjs.cloudflare.com/ajax/libs/list.js/{{site.data.pkg.version}}/list.min.js"></script>
        ================================================ FILE: docs/overview/index.html ================================================ --- layout: default title: TL;DR / Features ---

        TL;DR

        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.

        Core idea

        • Simple and invisible
        • Easy to apply to existing HTML
        • No dependencies
        • Fast
        • Tiny (5KB minified&gzip)
        • Handle thousands of items

        Features

        Used by

        ================================================ FILE: docs/overview/press.html ================================================

        Press

        ================================================ FILE: package.json ================================================ { "name": "list.js", "version": "2.3.1", "description": "The perfect library for lists. Supports search, sort, filters and flexibility. Built to be invisible and work on existing HTML", "keywords": [ "list", "search", "sort", "table", "dom", "html", "ui" ], "author": { "name": "Jonny Strömberg", "email": "jonny.stromberg@gmail.com", "url": "https://javve.com" }, "homepage": "https://listjs.com", "repository": "git://github.com/javve/list.js.git", "license": "MIT", "bugs": { "url": "https://github.com/javve/list.js/issues" }, "dependencies": { "string-natural-compare": "^2.0.2" }, "devDependencies": { "@babel/core": "^7.12.7", "@babel/preset-env": "^7.12.7", "babel-loader": "^8.2.1", "jest": "^26.6.3", "jquery": "^3.5.1", "prettier": "^2.2.0", "webpack": "^5.6.0", "webpack-cli": "^4.2.0" }, "main": "src/index", "engines": { "node": "^6.0 || ^8.0 || ^10.0 || ^12.0 || >=14" }, "scripts": { "test": "npx jest", "build": "npx webpack", "watch": "npx webpack --watch", "watch-test": "npx jest --watch", "preversion": "npm test && npm run build && cp dist/list.min.js docs/assets/javascripts/list.min.js && cp dist/list.min.js.map docs/assets/javascripts/list.min.js.map && git add dist && git add docs/assets/javascripts", "postversion": "git push --follow-tags origin master && cp package.json docs/_data/pkg.json && git add docs/_data/pkg.json && git commit -m \"pkg.json update\"" }, "npmName": "list.js", "npmFileMap": [ { "basePath": "/dist/", "files": [ "*.js", "*.js.map" ] } ], "jest": { "coverageDirectory": "./coverage/", "collectCoverage": true, "collectCoverageFrom": [ "src/*.js", "src/utils/*.js" ], "testURL": "http://localhost/" } } ================================================ FILE: prettier.config.js ================================================ module.exports = { semi: false, singleQuote: true, printWidth: 120, } ================================================ FILE: src/add-async.js ================================================ module.exports = function (list) { var addAsync = function (values, callback, items) { var valuesToAdd = values.splice(0, 50) items = items || [] items = items.concat(list.add(valuesToAdd)) if (values.length > 0) { setTimeout(function () { addAsync(values, callback, items) }, 1) } else { list.update() callback(items) } } return addAsync } ================================================ FILE: src/filter.js ================================================ module.exports = function (list) { // Add handlers list.handlers.filterStart = list.handlers.filterStart || [] list.handlers.filterComplete = list.handlers.filterComplete || [] return function (filterFunction) { list.trigger('filterStart') list.i = 1 // Reset paging list.reset.filter() if (filterFunction === undefined) { list.filtered = false } else { list.filtered = true var is = list.items for (var i = 0, il = is.length; i < il; i++) { var item = is[i] if (filterFunction(item)) { item.filtered = true } else { item.filtered = false } } } list.update() list.trigger('filterComplete') return list.visibleItems } } ================================================ FILE: src/fuzzy-search.js ================================================ var classes = require('./utils/classes'), events = require('./utils/events'), extend = require('./utils/extend'), toString = require('./utils/to-string'), getByClass = require('./utils/get-by-class'), fuzzy = require('./utils/fuzzy') module.exports = function (list, options) { options = options || {} options = extend( { location: 0, distance: 100, threshold: 0.4, multiSearch: true, searchClass: 'fuzzy-search', }, options ) var fuzzySearch = { search: function (searchString, columns) { // Substract arguments from the searchString or put searchString as only argument var searchArguments = options.multiSearch ? searchString.replace(/ +$/, '').split(/ +/) : [searchString] for (var k = 0, kl = list.items.length; k < kl; k++) { fuzzySearch.item(list.items[k], columns, searchArguments) } }, item: function (item, columns, searchArguments) { var found = true for (var i = 0; i < searchArguments.length; i++) { var foundArgument = false for (var j = 0, jl = columns.length; j < jl; j++) { if (fuzzySearch.values(item.values(), columns[j], searchArguments[i])) { foundArgument = true } } if (!foundArgument) { found = false } } item.found = found }, values: function (values, value, searchArgument) { if (values.hasOwnProperty(value)) { var text = toString(values[value]).toLowerCase() if (fuzzy(text, searchArgument, options)) { return true } } return false }, } events.bind( getByClass(list.listContainer, options.searchClass), 'keyup', list.utils.events.debounce(function (e) { var target = e.target || e.srcElement // IE have srcElement list.search(target.value, fuzzySearch.search) }, list.searchDelay) ) return function (str, columns) { list.search(str, columns, fuzzySearch.search) } } ================================================ FILE: src/index.js ================================================ var naturalSort = require('string-natural-compare'), getByClass = require('./utils/get-by-class'), extend = require('./utils/extend'), indexOf = require('./utils/index-of'), events = require('./utils/events'), toString = require('./utils/to-string'), classes = require('./utils/classes'), getAttribute = require('./utils/get-attribute'), toArray = require('./utils/to-array') module.exports = function (id, options, values) { var self = this, init, Item = require('./item')(self), addAsync = require('./add-async')(self), initPagination = require('./pagination')(self) init = { start: function () { self.listClass = 'list' self.searchClass = 'search' self.sortClass = 'sort' self.page = 10000 self.i = 1 self.items = [] self.visibleItems = [] self.matchingItems = [] self.searched = false self.filtered = false self.searchColumns = undefined self.searchDelay = 0 self.handlers = { updated: [] } self.valueNames = [] self.utils = { getByClass: getByClass, extend: extend, indexOf: indexOf, events: events, toString: toString, naturalSort: naturalSort, classes: classes, getAttribute: getAttribute, toArray: toArray, } self.utils.extend(self, options) self.listContainer = typeof id === 'string' ? document.getElementById(id) : id if (!self.listContainer) { return } self.list = getByClass(self.listContainer, self.listClass, true) self.parse = require('./parse')(self) self.templater = require('./templater')(self) self.search = require('./search')(self) self.filter = require('./filter')(self) self.sort = require('./sort')(self) self.fuzzySearch = require('./fuzzy-search')(self, options.fuzzySearch) this.handlers() this.items() this.pagination() self.update() }, handlers: function () { for (var handler in self.handlers) { if (self[handler] && self.handlers.hasOwnProperty(handler)) { self.on(handler, self[handler]) } } }, items: function () { self.parse(self.list) if (values !== undefined) { self.add(values) } }, pagination: function () { if (options.pagination !== undefined) { if (options.pagination === true) { options.pagination = [{}] } if (options.pagination[0] === undefined) { options.pagination = [options.pagination] } for (var i = 0, il = options.pagination.length; i < il; i++) { initPagination(options.pagination[i]) } } }, } /* * Re-parse the List, use if html have changed */ this.reIndex = function () { self.items = [] self.visibleItems = [] self.matchingItems = [] self.searched = false self.filtered = false self.parse(self.list) } this.toJSON = function () { var json = [] for (var i = 0, il = self.items.length; i < il; i++) { json.push(self.items[i].values()) } return json } /* * Add object to list */ this.add = function (values, callback) { if (values.length === 0) { return } if (callback) { addAsync(values.slice(0), callback) return } var added = [], notCreate = false if (values[0] === undefined) { values = [values] } for (var i = 0, il = values.length; i < il; i++) { var item = null notCreate = self.items.length > self.page ? true : false item = new Item(values[i], undefined, notCreate) self.items.push(item) added.push(item) } self.update() return added } this.show = function (i, page) { this.i = i this.page = page self.update() return self } /* Removes object from list. * Loops through the list and removes objects where * property "valuename" === value */ this.remove = function (valueName, value, options) { var found = 0 for (var i = 0, il = self.items.length; i < il; i++) { if (self.items[i].values()[valueName] == value) { self.templater.remove(self.items[i], options) self.items.splice(i, 1) il-- i-- found++ } } self.update() return found } /* Gets the objects in the list which * property "valueName" === value */ this.get = function (valueName, value) { var matchedItems = [] for (var i = 0, il = self.items.length; i < il; i++) { var item = self.items[i] if (item.values()[valueName] == value) { matchedItems.push(item) } } return matchedItems } /* * Get size of the list */ this.size = function () { return self.items.length } /* * Removes all items from the list */ this.clear = function () { self.templater.clear() self.items = [] return self } this.on = function (event, callback) { self.handlers[event].push(callback) return self } this.off = function (event, callback) { var e = self.handlers[event] var index = indexOf(e, callback) if (index > -1) { e.splice(index, 1) } return self } this.trigger = function (event) { var i = self.handlers[event].length while (i--) { self.handlers[event][i](self) } return self } this.reset = { filter: function () { var is = self.items, il = is.length while (il--) { is[il].filtered = false } return self }, search: function () { var is = self.items, il = is.length while (il--) { is[il].found = false } return self }, } this.update = function () { var is = self.items, il = is.length self.visibleItems = [] self.matchingItems = [] self.templater.clear() for (var i = 0; i < il; i++) { if (is[i].matching() && self.matchingItems.length + 1 >= self.i && self.visibleItems.length < self.page) { is[i].show() self.visibleItems.push(is[i]) self.matchingItems.push(is[i]) } else if (is[i].matching()) { self.matchingItems.push(is[i]) is[i].hide() } else { is[i].hide() } } self.trigger('updated') return self } init.start() } ================================================ FILE: src/item.js ================================================ module.exports = function (list) { return function (initValues, element, notCreate) { var item = this this._values = {} this.found = false // Show if list.searched == true and this.found == true this.filtered = false // Show if list.filtered == true and this.filtered == true var init = function (initValues, element, notCreate) { if (element === undefined) { if (notCreate) { item.values(initValues, notCreate) } else { item.values(initValues) } } else { item.elm = element var values = list.templater.get(item, initValues) item.values(values) } } this.values = function (newValues, notCreate) { if (newValues !== undefined) { for (var name in newValues) { item._values[name] = newValues[name] } if (notCreate !== true) { list.templater.set(item, item.values()) } } else { return item._values } } this.show = function () { list.templater.show(item) } this.hide = function () { list.templater.hide(item) } this.matching = function () { return ( (list.filtered && list.searched && item.found && item.filtered) || (list.filtered && !list.searched && item.filtered) || (!list.filtered && list.searched && item.found) || (!list.filtered && !list.searched) ) } this.visible = function () { return item.elm && item.elm.parentNode == list.list ? true : false } init(initValues, element, notCreate) } } ================================================ FILE: src/pagination.js ================================================ var classes = require('./utils/classes'), events = require('./utils/events'), List = require('./index') module.exports = function (list) { var isHidden = false var refresh = function (pagingList, options) { if (list.page < 1) { list.listContainer.style.display = 'none' isHidden = true return } else if (isHidden) { list.listContainer.style.display = 'block' } var item, l = list.matchingItems.length, index = list.i, page = list.page, pages = Math.ceil(l / page), currentPage = Math.ceil(index / page), innerWindow = options.innerWindow || 2, left = options.left || options.outerWindow || 0, right = options.right || options.outerWindow || 0 right = pages - right pagingList.clear() for (var i = 1; i <= pages; i++) { var className = currentPage === i ? 'active' : '' //console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className); if (is.number(i, left, right, currentPage, innerWindow)) { item = pagingList.add({ page: i, dotted: false, })[0] if (className) { classes(item.elm).add(className) } item.elm.firstChild.setAttribute('data-i', i) item.elm.firstChild.setAttribute('data-page', page) } else if (is.dotted(pagingList, i, left, right, currentPage, innerWindow, pagingList.size())) { item = pagingList.add({ page: '...', dotted: true, })[0] classes(item.elm).add('disabled') } } } var is = { number: function (i, left, right, currentPage, innerWindow) { return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow) }, left: function (i, left) { return i <= left }, right: function (i, right) { return i > right }, innerWindow: function (i, currentPage, innerWindow) { return i >= currentPage - innerWindow && i <= currentPage + innerWindow }, dotted: function (pagingList, i, left, right, currentPage, innerWindow, currentPageItem) { return ( this.dottedLeft(pagingList, i, left, right, currentPage, innerWindow) || this.dottedRight(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) ) }, dottedLeft: function (pagingList, i, left, right, currentPage, innerWindow) { return i == left + 1 && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right) }, dottedRight: function (pagingList, i, left, right, currentPage, innerWindow, currentPageItem) { if (pagingList.items[currentPageItem - 1].values().dotted) { return false } else { return i == right && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right) } }, } return function (options) { var pagingList = new List(list.listContainer.id, { listClass: options.paginationClass || 'pagination', item: options.item || "
      • ", valueNames: ['page', 'dotted'], searchClass: 'pagination-search-that-is-not-supposed-to-exist', sortClass: 'pagination-sort-that-is-not-supposed-to-exist', }) events.bind(pagingList.listContainer, 'click', function (e) { var target = e.target || e.srcElement, page = list.utils.getAttribute(target, 'data-page'), i = list.utils.getAttribute(target, 'data-i') if (i) { list.show((i - 1) * page + 1, page) } }) list.on('updated', function () { refresh(pagingList, options) }) refresh(pagingList, options) } } ================================================ FILE: src/parse.js ================================================ module.exports = function (list) { var Item = require('./item')(list) var getChildren = function (parent) { var nodes = parent.childNodes, items = [] for (var i = 0, il = nodes.length; i < il; i++) { // Only textnodes have a data attribute if (nodes[i].data === undefined) { items.push(nodes[i]) } } return items } var parse = function (itemElements, valueNames) { for (var i = 0, il = itemElements.length; i < il; i++) { list.items.push(new Item(valueNames, itemElements[i])) } } var parseAsync = function (itemElements, valueNames) { var itemsToIndex = itemElements.splice(0, 50) // TODO: If < 100 items, what happens in IE etc? parse(itemsToIndex, valueNames) if (itemElements.length > 0) { setTimeout(function () { parseAsync(itemElements, valueNames) }, 1) } else { list.update() list.trigger('parseComplete') } } list.handlers.parseComplete = list.handlers.parseComplete || [] return function () { var itemsToIndex = getChildren(list.list), valueNames = list.valueNames if (list.indexAsync) { parseAsync(itemsToIndex, valueNames) } else { parse(itemsToIndex, valueNames) } } } ================================================ FILE: src/search.js ================================================ module.exports = function (list) { var item, text, columns, searchString, customSearch var prepare = { resetList: function () { list.i = 1 list.templater.clear() customSearch = undefined }, setOptions: function (args) { if (args.length == 2 && args[1] instanceof Array) { columns = args[1] } else if (args.length == 2 && typeof args[1] == 'function') { columns = undefined customSearch = args[1] } else if (args.length == 3) { columns = args[1] customSearch = args[2] } else { columns = undefined } }, setColumns: function () { if (list.items.length === 0) return if (columns === undefined) { columns = list.searchColumns === undefined ? prepare.toArray(list.items[0].values()) : list.searchColumns } }, setSearchString: function (s) { s = list.utils.toString(s).toLowerCase() s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&') // Escape regular expression characters searchString = s }, toArray: function (values) { var tmpColumn = [] for (var name in values) { tmpColumn.push(name) } return tmpColumn }, } var search = { list: function () { // Extract quoted phrases "word1 word2" from original searchString // searchString is converted to lowercase by List.js var words = [], phrase, ss = searchString while ((phrase = ss.match(/"([^"]+)"/)) !== null) { words.push(phrase[1]) ss = ss.substring(0, phrase.index) + ss.substring(phrase.index + phrase[0].length) } // Get remaining space-separated words (if any) ss = ss.trim() if (ss.length) words = words.concat(ss.split(/\s+/)) for (var k = 0, kl = list.items.length; k < kl; k++) { var item = list.items[k] item.found = false if (!words.length) continue for (var i = 0, il = words.length; i < il; i++) { var word_found = false for (var j = 0, jl = columns.length; j < jl; j++) { var values = item.values(), column = columns[j] if (values.hasOwnProperty(column) && values[column] !== undefined && values[column] !== null) { var text = typeof values[column] !== 'string' ? values[column].toString() : values[column] if (text.toLowerCase().indexOf(words[i]) !== -1) { // word found, so no need to check it against any other columns word_found = true break } } } // this word not found? no need to check any other words, the item cannot match if (!word_found) break } item.found = word_found } }, // Removed search.item() and search.values() reset: function () { list.reset.search() list.searched = false }, } var searchMethod = function (str) { list.trigger('searchStart') prepare.resetList() prepare.setSearchString(str) prepare.setOptions(arguments) // str, cols|searchFunction, searchFunction prepare.setColumns() if (searchString === '') { search.reset() } else { list.searched = true if (customSearch) { customSearch(searchString, columns) } else { search.list() } } list.update() list.trigger('searchComplete') return list.visibleItems } list.handlers.searchStart = list.handlers.searchStart || [] list.handlers.searchComplete = list.handlers.searchComplete || [] list.utils.events.bind( list.utils.getByClass(list.listContainer, list.searchClass), 'keyup', list.utils.events.debounce(function (e) { var target = e.target || e.srcElement, // IE have srcElement alreadyCleared = target.value === '' && !list.searched if (!alreadyCleared) { // If oninput already have resetted the list, do nothing searchMethod(target.value) } }, list.searchDelay) ) // Used to detect click on HTML5 clear button list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'input', function (e) { var target = e.target || e.srcElement if (target.value === '') { searchMethod('') } }) return searchMethod } ================================================ FILE: src/sort.js ================================================ module.exports = function (list) { var buttons = { els: undefined, clear: function () { for (var i = 0, il = buttons.els.length; i < il; i++) { list.utils.classes(buttons.els[i]).remove('asc') list.utils.classes(buttons.els[i]).remove('desc') } }, getOrder: function (btn) { var predefinedOrder = list.utils.getAttribute(btn, 'data-order') if (predefinedOrder == 'asc' || predefinedOrder == 'desc') { return predefinedOrder } else if (list.utils.classes(btn).has('desc')) { return 'asc' } else if (list.utils.classes(btn).has('asc')) { return 'desc' } else { return 'asc' } }, getInSensitive: function (btn, options) { var insensitive = list.utils.getAttribute(btn, 'data-insensitive') if (insensitive === 'false') { options.insensitive = false } else { options.insensitive = true } }, setOrder: function (options) { for (var i = 0, il = buttons.els.length; i < il; i++) { var btn = buttons.els[i] if (list.utils.getAttribute(btn, 'data-sort') !== options.valueName) { continue } var predefinedOrder = list.utils.getAttribute(btn, 'data-order') if (predefinedOrder == 'asc' || predefinedOrder == 'desc') { if (predefinedOrder == options.order) { list.utils.classes(btn).add(options.order) } } else { list.utils.classes(btn).add(options.order) } } }, } var sort = function () { list.trigger('sortStart') var options = {} var target = arguments[0].currentTarget || arguments[0].srcElement || undefined if (target) { options.valueName = list.utils.getAttribute(target, 'data-sort') buttons.getInSensitive(target, options) options.order = buttons.getOrder(target) } else { options = arguments[1] || options options.valueName = arguments[0] options.order = options.order || 'asc' options.insensitive = typeof options.insensitive == 'undefined' ? true : options.insensitive } buttons.clear() buttons.setOrder(options) // caseInsensitive // alphabet var customSortFunction = options.sortFunction || list.sortFunction || null, multi = options.order === 'desc' ? -1 : 1, sortFunction if (customSortFunction) { sortFunction = function (itemA, itemB) { return customSortFunction(itemA, itemB, options) * multi } } else { sortFunction = function (itemA, itemB) { var sort = list.utils.naturalSort sort.alphabet = list.alphabet || options.alphabet || undefined if (!sort.alphabet && options.insensitive) { sort = list.utils.naturalSort.caseInsensitive } return sort(itemA.values()[options.valueName], itemB.values()[options.valueName]) * multi } } list.items.sort(sortFunction) list.update() list.trigger('sortComplete') } // Add handlers list.handlers.sortStart = list.handlers.sortStart || [] list.handlers.sortComplete = list.handlers.sortComplete || [] buttons.els = list.utils.getByClass(list.listContainer, list.sortClass) list.utils.events.bind(buttons.els, 'click', sort) list.on('searchStart', buttons.clear) list.on('filterStart', buttons.clear) return sort } ================================================ FILE: src/templater.js ================================================ var Templater = function (list) { var createItem, templater = this var init = function () { var itemSource if (typeof list.item === 'function') { createItem = function (values) { var item = list.item(values) return getItemSource(item) } return } if (typeof list.item === 'string') { if (list.item.indexOf('<') === -1) { itemSource = document.getElementById(list.item) } else { itemSource = getItemSource(list.item) } } else { /* If item source does not exists, use the first item in list as source for new items */ itemSource = getFirstListItem() } if (!itemSource) { throw new Error("The list needs to have at least one item on init otherwise you'll have to add a template.") } itemSource = createCleanTemplateItem(itemSource, list.valueNames) createItem = function () { return itemSource.cloneNode(true) } } var createCleanTemplateItem = function (templateNode, valueNames) { var el = templateNode.cloneNode(true) el.removeAttribute('id') for (var i = 0, il = valueNames.length; i < il; i++) { var elm = undefined, valueName = valueNames[i] if (valueName.data) { for (var j = 0, jl = valueName.data.length; j < jl; j++) { el.setAttribute('data-' + valueName.data[j], '') } } else if (valueName.attr && valueName.name) { elm = list.utils.getByClass(el, valueName.name, true) if (elm) { elm.setAttribute(valueName.attr, '') } } else { elm = list.utils.getByClass(el, valueName, true) if (elm) { elm.innerHTML = '' } } } return el } var getFirstListItem = function () { var nodes = list.list.childNodes for (var i = 0, il = nodes.length; i < il; i++) { // Only textnodes have a data attribute if (nodes[i].data === undefined) { return nodes[i].cloneNode(true) } } return undefined } var getItemSource = function (itemHTML) { if (typeof itemHTML !== 'string') return undefined if (/]/g.exec(itemHTML)) { var tbody = document.createElement('tbody') tbody.innerHTML = itemHTML return tbody.firstElementChild } else if (itemHTML.indexOf('<') !== -1) { var div = document.createElement('div') div.innerHTML = itemHTML return div.firstElementChild } return undefined } var getValueName = function (name) { for (var i = 0, il = list.valueNames.length; i < il; i++) { var valueName = list.valueNames[i] if (valueName.data) { var data = valueName.data for (var j = 0, jl = data.length; j < jl; j++) { if (data[j] === name) { return { data: name } } } } else if (valueName.attr && valueName.name && valueName.name == name) { return valueName } else if (valueName === name) { return name } } } var setValue = function (item, name, value) { var elm = undefined, valueName = getValueName(name) if (!valueName) return if (valueName.data) { item.elm.setAttribute('data-' + valueName.data, value) } else if (valueName.attr && valueName.name) { elm = list.utils.getByClass(item.elm, valueName.name, true) if (elm) { elm.setAttribute(valueName.attr, value) } } else { elm = list.utils.getByClass(item.elm, valueName, true) if (elm) { elm.innerHTML = value } } } this.get = function (item, valueNames) { templater.create(item) var values = {} for (var i = 0, il = valueNames.length; i < il; i++) { var elm = undefined, valueName = valueNames[i] if (valueName.data) { for (var j = 0, jl = valueName.data.length; j < jl; j++) { values[valueName.data[j]] = list.utils.getAttribute(item.elm, 'data-' + valueName.data[j]) } } else if (valueName.attr && valueName.name) { elm = list.utils.getByClass(item.elm, valueName.name, true) values[valueName.name] = elm ? list.utils.getAttribute(elm, valueName.attr) : '' } else { elm = list.utils.getByClass(item.elm, valueName, true) values[valueName] = elm ? elm.innerHTML : '' } } return values } this.set = function (item, values) { if (!templater.create(item)) { for (var v in values) { if (values.hasOwnProperty(v)) { setValue(item, v, values[v]) } } } } this.create = function (item) { if (item.elm !== undefined) { return false } item.elm = createItem(item.values()) templater.set(item, item.values()) return true } this.remove = function (item) { if (item.elm.parentNode === list.list) { list.list.removeChild(item.elm) } } this.show = function (item) { templater.create(item) list.list.appendChild(item.elm) } this.hide = function (item) { if (item.elm !== undefined && item.elm.parentNode === list.list) { list.list.removeChild(item.elm) } } this.clear = function () { /* .innerHTML = ''; fucks up IE */ if (list.list.hasChildNodes()) { while (list.list.childNodes.length >= 1) { list.list.removeChild(list.list.firstChild) } } } init() } module.exports = function (list) { return new Templater(list) } ================================================ FILE: src/utils/classes.js ================================================ /** * Module dependencies. */ var index = require('./index-of') /** * Whitespace regexp. */ var re = /\s+/ /** * toString reference. */ var toString = Object.prototype.toString /** * Wrap `el` in a `ClassList`. * * @param {Element} el * @return {ClassList} * @api public */ module.exports = function (el) { return new ClassList(el) } /** * Initialize a new ClassList for `el`. * * @param {Element} el * @api private */ function ClassList(el) { if (!el || !el.nodeType) { throw new Error('A DOM element reference is required') } this.el = el this.list = el.classList } /** * Add class `name` if not already present. * * @param {String} name * @return {ClassList} * @api public */ ClassList.prototype.add = function (name) { // classList if (this.list) { this.list.add(name) return this } // fallback var arr = this.array() var i = index(arr, name) if (!~i) arr.push(name) this.el.className = arr.join(' ') return this } /** * Remove class `name` when present, or * pass a regular expression to remove * any which match. * * @param {String|RegExp} name * @return {ClassList} * @api public */ ClassList.prototype.remove = function (name) { // classList if (this.list) { this.list.remove(name) return this } // fallback var arr = this.array() var i = index(arr, name) if (~i) arr.splice(i, 1) this.el.className = arr.join(' ') return this } /** * Toggle class `name`, can force state via `force`. * * For browsers that support classList, but do not support `force` yet, * the mistake will be detected and corrected. * * @param {String} name * @param {Boolean} force * @return {ClassList} * @api public */ ClassList.prototype.toggle = function (name, force) { // classList if (this.list) { if ('undefined' !== typeof force) { if (force !== this.list.toggle(name, force)) { this.list.toggle(name) // toggle again to correct } } else { this.list.toggle(name) } return this } // fallback if ('undefined' !== typeof force) { if (!force) { this.remove(name) } else { this.add(name) } } else { if (this.has(name)) { this.remove(name) } else { this.add(name) } } return this } /** * Return an array of classes. * * @return {Array} * @api public */ ClassList.prototype.array = function () { var className = this.el.getAttribute('class') || '' var str = className.replace(/^\s+|\s+$/g, '') var arr = str.split(re) if ('' === arr[0]) arr.shift() return arr } /** * Check if class `name` is present. * * @param {String} name * @return {ClassList} * @api public */ ClassList.prototype.has = ClassList.prototype.contains = function (name) { return this.list ? this.list.contains(name) : !!~index(this.array(), name) } ================================================ FILE: src/utils/events.js ================================================ var bind = window.addEventListener ? 'addEventListener' : 'attachEvent', unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent', prefix = bind !== 'addEventListener' ? 'on' : '', toArray = require('./to-array') /** * Bind `el` event `type` to `fn`. * * @param {Element} el, NodeList, HTMLCollection or Array * @param {String} type * @param {Function} fn * @param {Boolean} capture * @api public */ exports.bind = function (el, type, fn, capture) { el = toArray(el) for (var i = 0, il = el.length; i < il; i++) { el[i][bind](prefix + type, fn, capture || false) } } /** * Unbind `el` event `type`'s callback `fn`. * * @param {Element} el, NodeList, HTMLCollection or Array * @param {String} type * @param {Function} fn * @param {Boolean} capture * @api public */ exports.unbind = function (el, type, fn, capture) { el = toArray(el) for (var i = 0, il = el.length; i < il; i++) { el[i][unbind](prefix + type, fn, capture || false) } } /** * Returns a function, that, as long as it continues to be invoked, will not * be triggered. The function will be called after it stops being called for * `wait` milliseconds. If `immediate` is true, trigger the function on the * leading edge, instead of the trailing. * * @param {Function} fn * @param {Integer} wait * @param {Boolean} immediate * @api public */ exports.debounce = function (fn, wait, immediate) { var timeout return wait ? function () { var context = this, args = arguments var later = function () { timeout = null if (!immediate) fn.apply(context, args) } var callNow = immediate && !timeout clearTimeout(timeout) timeout = setTimeout(later, wait) if (callNow) fn.apply(context, args) } : fn } ================================================ FILE: src/utils/extend.js ================================================ /* * Source: https://github.com/segmentio/extend */ module.exports = function extend(object) { // Takes an unlimited number of extenders. var args = Array.prototype.slice.call(arguments, 1) // For each extender, copy their properties on our object. for (var i = 0, source; (source = args[i]); i++) { if (!source) continue for (var property in source) { object[property] = source[property] } } return object } ================================================ FILE: src/utils/fuzzy.js ================================================ module.exports = function (text, pattern, options) { // Aproximately where in the text is the pattern expected to be found? var Match_Location = options.location || 0 //Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is 'distance' characters away from the fuzzy location would score as a complete mismatch. A distance of '0' requires the match be at the exact location specified, a threshold of '1000' would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. var Match_Distance = options.distance || 100 // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match (of both letters and location), a threshold of '1.0' would match anything. var Match_Threshold = options.threshold || 0.4 if (pattern === text) return true // Exact match if (pattern.length > 32) return false // This algorithm cannot be used // Set starting location at beginning text and initialise the alphabet. var loc = Match_Location, s = (function () { var q = {}, i for (i = 0; i < pattern.length; i++) { q[pattern.charAt(i)] = 0 } for (i = 0; i < pattern.length; i++) { q[pattern.charAt(i)] |= 1 << (pattern.length - i - 1) } return q })() // Compute and return the score for a match with e errors and x location. // Accesses loc and pattern through being a closure. function match_bitapScore_(e, x) { var accuracy = e / pattern.length, proximity = Math.abs(loc - x) if (!Match_Distance) { // Dodge divide by zero error. return proximity ? 1.0 : accuracy } return accuracy + proximity / Match_Distance } var score_threshold = Match_Threshold, // Highest score beyond which we give up. best_loc = text.indexOf(pattern, loc) // Is there a nearby exact match? (speedup) if (best_loc != -1) { score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold) // What about in the other direction? (speedup) best_loc = text.lastIndexOf(pattern, loc + pattern.length) if (best_loc != -1) { score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold) } } // Initialise the bit arrays. var matchmask = 1 << (pattern.length - 1) best_loc = -1 var bin_min, bin_mid var bin_max = pattern.length + text.length var last_rd for (var d = 0; d < pattern.length; d++) { // Scan for the best match; each iteration allows for one more error. // Run a binary search to determine how far from 'loc' we can stray at this // error level. bin_min = 0 bin_mid = bin_max while (bin_min < bin_mid) { if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) { bin_min = bin_mid } else { bin_max = bin_mid } bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min) } // Use the result from this iteration as the maximum for the next. bin_max = bin_mid var start = Math.max(1, loc - bin_mid + 1) var finish = Math.min(loc + bin_mid, text.length) + pattern.length var rd = Array(finish + 2) rd[finish + 1] = (1 << d) - 1 for (var j = finish; j >= start; j--) { // The alphabet (s) is a sparse hash, so the following line generates // warnings. var charMatch = s[text.charAt(j - 1)] if (d === 0) { // First pass: exact match. rd[j] = ((rd[j + 1] << 1) | 1) & charMatch } else { // Subsequent passes: fuzzy match. rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) | (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | last_rd[j + 1] } if (rd[j] & matchmask) { var score = match_bitapScore_(d, j - 1) // This match will almost certainly be better than any existing match. // But check anyway. if (score <= score_threshold) { // Told you so. score_threshold = score best_loc = j - 1 if (best_loc > loc) { // When passing loc, don't exceed our current distance from loc. start = Math.max(1, 2 * loc - best_loc) } else { // Already passed loc, downhill from here on in. break } } } } // No hope for a (better) match at greater error levels. if (match_bitapScore_(d + 1, loc) > score_threshold) { break } last_rd = rd } return best_loc < 0 ? false : true } ================================================ FILE: src/utils/get-attribute.js ================================================ /** * A cross-browser implementation of getAttribute. * Source found here: http://stackoverflow.com/a/3755343/361337 written by Vivin Paliath * * Return the value for `attr` at `element`. * * @param {Element} el * @param {String} attr * @api public */ module.exports = function (el, attr) { var result = (el.getAttribute && el.getAttribute(attr)) || null if (!result) { var attrs = el.attributes var length = attrs.length for (var i = 0; i < length; i++) { if (attrs[i] !== undefined) { if (attrs[i].nodeName === attr) { result = attrs[i].nodeValue } } } } return result } ================================================ FILE: src/utils/get-by-class.js ================================================ /** * A cross-browser implementation of getElementsByClass. * Heavily based on Dustin Diaz's function: http://dustindiaz.com/getelementsbyclass. * * Find all elements with class `className` inside `container`. * Use `single = true` to increase performance in older browsers * when only one element is needed. * * @param {String} className * @param {Element} container * @param {Boolean} single * @api public */ var getElementsByClassName = function (container, className, single) { if (single) { return container.getElementsByClassName(className)[0] } else { return container.getElementsByClassName(className) } } var querySelector = function (container, className, single) { className = '.' + className if (single) { return container.querySelector(className) } else { return container.querySelectorAll(className) } } var polyfill = function (container, className, single) { var classElements = [], tag = '*' var els = container.getElementsByTagName(tag) var elsLen = els.length var pattern = new RegExp('(^|\\s)' + className + '(\\s|$)') for (var i = 0, j = 0; i < elsLen; i++) { if (pattern.test(els[i].className)) { if (single) { return els[i] } else { classElements[j] = els[i] j++ } } } return classElements } module.exports = (function () { return function (container, className, single, options) { options = options || {} if ((options.test && options.getElementsByClassName) || (!options.test && document.getElementsByClassName)) { return getElementsByClassName(container, className, single) } else if ((options.test && options.querySelector) || (!options.test && document.querySelector)) { return querySelector(container, className, single) } else { return polyfill(container, className, single) } } })() ================================================ FILE: src/utils/index-of.js ================================================ var indexOf = [].indexOf module.exports = function(arr, obj){ if (indexOf) return arr.indexOf(obj); for (var i = 0, il = arr.length; i < il; ++i) { if (arr[i] === obj) return i; } return -1 } ================================================ FILE: src/utils/to-array.js ================================================ /** * Source: https://github.com/timoxley/to-array * * Convert an array-like object into an `Array`. * If `collection` is already an `Array`, then will return a clone of `collection`. * * @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList` * @return {Array} Naive conversion of `collection` to a new `Array`. * @api public */ module.exports = function toArray(collection) { if (typeof collection === 'undefined') return [] if (collection === null) return [null] if (collection === window) return [window] if (typeof collection === 'string') return [collection] if (isArray(collection)) return collection if (typeof collection.length != 'number') return [collection] if (typeof collection === 'function' && collection instanceof Function) return [collection] var arr = []; for (var i = 0, il = collection.length; i < il; i++) { if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) { arr.push(collection[i]) } } if (!arr.length) return [] return arr } function isArray(arr) { return Object.prototype.toString.call(arr) === '[object Array]' } ================================================ FILE: src/utils/to-string.js ================================================ module.exports = function (s) { s = s === undefined ? '' : s s = s === null ? '' : s s = s.toString() return s } ================================================ FILE: webpack.config.js ================================================ const webpack = require('webpack') const PACKAGE = require('./package.json') const TerserPlugin = require('terser-webpack-plugin') module.exports = { entry: { list: './src/index.js', 'list.min': './src/index.js', }, output: { path: __dirname + '/dist', filename: '[name].js', library: 'List', }, devtool: 'cheap-module-source-map', module: { rules: [ { test: /\.js$/, exclude: /(node_modules)/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], }, }, }, ], }, devServer: { inline: true, }, plugins: [], optimization: { minimize: true, minimizer: [ new TerserPlugin({ include: /\.min\.js$/, extractComments: false, terserOptions: { format: { comments: /^! List.js v.*/, }, mangle: true, }, }), ], }, }