{"version":3,"file":"list.js","sources":["webpack://List/./src/add-async.js","webpack://List/./src/filter.js","webpack://List/./src/fuzzy-search.js","webpack://List/./src/index.js","webpack://List/./src/item.js","webpack://List/./src/pagination.js","webpack://List/./src/parse.js","webpack://List/./src/search.js","webpack://List/./src/sort.js","webpack://List/./src/templater.js","webpack://List/./src/utils/classes.js","webpack://List/./src/utils/events.js","webpack://List/./src/utils/extend.js","webpack://List/./src/utils/fuzzy.js","webpack://List/./src/utils/get-attribute.js","webpack://List/./src/utils/get-by-class.js","webpack://List/./src/utils/index-of.js","webpack://List/./src/utils/to-array.js","webpack://List/./src/utils/to-string.js","webpack://List/./node_modules/string-natural-compare/natural-compare.js","webpack://List/webpack/bootstrap","webpack://List/webpack/startup"],"sourcesContent":["module.exports = function (list) {\n var addAsync = function (values, callback, items) {\n var valuesToAdd = values.splice(0, 50)\n items = items || []\n items = items.concat(list.add(valuesToAdd))\n if (values.length > 0) {\n setTimeout(function () {\n addAsync(values, callback, items)\n }, 1)\n } else {\n list.update()\n callback(items)\n }\n }\n return addAsync\n}\n","module.exports = function (list) {\n // Add handlers\n list.handlers.filterStart = list.handlers.filterStart || []\n list.handlers.filterComplete = list.handlers.filterComplete || []\n\n return function (filterFunction) {\n list.trigger('filterStart')\n list.i = 1 // Reset paging\n list.reset.filter()\n if (filterFunction === undefined) {\n list.filtered = false\n } else {\n list.filtered = true\n var is = list.items\n for (var i = 0, il = is.length; i < il; i++) {\n var item = is[i]\n if (filterFunction(item)) {\n item.filtered = true\n } else {\n item.filtered = false\n }\n }\n }\n list.update()\n list.trigger('filterComplete')\n return list.visibleItems\n }\n}\n","var classes = require('./utils/classes'),\n events = require('./utils/events'),\n extend = require('./utils/extend'),\n toString = require('./utils/to-string'),\n getByClass = require('./utils/get-by-class'),\n fuzzy = require('./utils/fuzzy')\n\nmodule.exports = function (list, options) {\n options = options || {}\n\n options = extend(\n {\n location: 0,\n distance: 100,\n threshold: 0.4,\n multiSearch: true,\n searchClass: 'fuzzy-search',\n },\n options\n )\n\n var fuzzySearch = {\n search: function (searchString, columns) {\n // Substract arguments from the searchString or put searchString as only argument\n var searchArguments = options.multiSearch ? searchString.replace(/ +$/, '').split(/ +/) : [searchString]\n\n for (var k = 0, kl = list.items.length; k < kl; k++) {\n fuzzySearch.item(list.items[k], columns, searchArguments)\n }\n },\n item: function (item, columns, searchArguments) {\n var found = true\n for (var i = 0; i < searchArguments.length; i++) {\n var foundArgument = false\n for (var j = 0, jl = columns.length; j < jl; j++) {\n if (fuzzySearch.values(item.values(), columns[j], searchArguments[i])) {\n foundArgument = true\n }\n }\n if (!foundArgument) {\n found = false\n }\n }\n item.found = found\n },\n values: function (values, value, searchArgument) {\n if (values.hasOwnProperty(value)) {\n var text = toString(values[value]).toLowerCase()\n\n if (fuzzy(text, searchArgument, options)) {\n return true\n }\n }\n return false\n },\n }\n\n events.bind(\n getByClass(list.listContainer, options.searchClass),\n 'keyup',\n list.utils.events.debounce(function (e) {\n var target = e.target || e.srcElement // IE have srcElement\n list.search(target.value, fuzzySearch.search)\n }, list.searchDelay)\n )\n\n return function (str, columns) {\n list.search(str, columns, fuzzySearch.search)\n }\n}\n","var naturalSort = require('string-natural-compare'),\n getByClass = require('./utils/get-by-class'),\n extend = require('./utils/extend'),\n indexOf = require('./utils/index-of'),\n events = require('./utils/events'),\n toString = require('./utils/to-string'),\n classes = require('./utils/classes'),\n getAttribute = require('./utils/get-attribute'),\n toArray = require('./utils/to-array')\n\nmodule.exports = function (id, options, values) {\n var self = this,\n init,\n Item = require('./item')(self),\n addAsync = require('./add-async')(self),\n initPagination = require('./pagination')(self)\n\n init = {\n start: function () {\n self.listClass = 'list'\n self.searchClass = 'search'\n self.sortClass = 'sort'\n self.page = 10000\n self.i = 1\n self.items = []\n self.visibleItems = []\n self.matchingItems = []\n self.searched = false\n self.filtered = false\n self.searchColumns = undefined\n self.searchDelay = 0\n self.handlers = { updated: [] }\n self.valueNames = []\n self.utils = {\n getByClass: getByClass,\n extend: extend,\n indexOf: indexOf,\n events: events,\n toString: toString,\n naturalSort: naturalSort,\n classes: classes,\n getAttribute: getAttribute,\n toArray: toArray,\n }\n\n self.utils.extend(self, options)\n\n self.listContainer = typeof id === 'string' ? document.getElementById(id) : id\n if (!self.listContainer) {\n return\n }\n self.list = getByClass(self.listContainer, self.listClass, true)\n\n self.parse = require('./parse')(self)\n self.templater = require('./templater')(self)\n self.search = require('./search')(self)\n self.filter = require('./filter')(self)\n self.sort = require('./sort')(self)\n self.fuzzySearch = require('./fuzzy-search')(self, options.fuzzySearch)\n\n this.handlers()\n this.items()\n this.pagination()\n\n self.update()\n },\n handlers: function () {\n for (var handler in self.handlers) {\n if (self[handler] && self.handlers.hasOwnProperty(handler)) {\n self.on(handler, self[handler])\n }\n }\n },\n items: function () {\n self.parse(self.list)\n if (values !== undefined) {\n self.add(values)\n }\n },\n pagination: function () {\n if (options.pagination !== undefined) {\n if (options.pagination === true) {\n options.pagination = [{}]\n }\n if (options.pagination[0] === undefined) {\n options.pagination = [options.pagination]\n }\n for (var i = 0, il = options.pagination.length; i < il; i++) {\n initPagination(options.pagination[i])\n }\n }\n },\n }\n\n /*\n * Re-parse the List, use if html have changed\n */\n this.reIndex = function () {\n self.items = []\n self.visibleItems = []\n self.matchingItems = []\n self.searched = false\n self.filtered = false\n self.parse(self.list)\n }\n\n this.toJSON = function () {\n var json = []\n for (var i = 0, il = self.items.length; i < il; i++) {\n json.push(self.items[i].values())\n }\n return json\n }\n\n /*\n * Add object to list\n */\n this.add = function (values, callback) {\n if (values.length === 0) {\n return\n }\n if (callback) {\n addAsync(values.slice(0), callback)\n return\n }\n var added = [],\n notCreate = false\n if (values[0] === undefined) {\n values = [values]\n }\n for (var i = 0, il = values.length; i < il; i++) {\n var item = null\n notCreate = self.items.length > self.page ? true : false\n item = new Item(values[i], undefined, notCreate)\n self.items.push(item)\n added.push(item)\n }\n self.update()\n return added\n }\n\n this.show = function (i, page) {\n this.i = i\n this.page = page\n self.update()\n return self\n }\n\n /* Removes object from list.\n * Loops through the list and removes objects where\n * property \"valuename\" === value\n */\n this.remove = function (valueName, value, options) {\n var found = 0\n for (var i = 0, il = self.items.length; i < il; i++) {\n if (self.items[i].values()[valueName] == value) {\n self.templater.remove(self.items[i], options)\n self.items.splice(i, 1)\n il--\n i--\n found++\n }\n }\n self.update()\n return found\n }\n\n /* Gets the objects in the list which\n * property \"valueName\" === value\n */\n this.get = function (valueName, value) {\n var matchedItems = []\n for (var i = 0, il = self.items.length; i < il; i++) {\n var item = self.items[i]\n if (item.values()[valueName] == value) {\n matchedItems.push(item)\n }\n }\n return matchedItems\n }\n\n /*\n * Get size of the list\n */\n this.size = function () {\n return self.items.length\n }\n\n /*\n * Removes all items from the list\n */\n this.clear = function () {\n self.templater.clear()\n self.items = []\n return self\n }\n\n this.on = function (event, callback) {\n self.handlers[event].push(callback)\n return self\n }\n\n this.off = function (event, callback) {\n var e = self.handlers[event]\n var index = indexOf(e, callback)\n if (index > -1) {\n e.splice(index, 1)\n }\n return self\n }\n\n this.trigger = function (event) {\n var i = self.handlers[event].length\n while (i--) {\n self.handlers[event][i](self)\n }\n return self\n }\n\n this.reset = {\n filter: function () {\n var is = self.items,\n il = is.length\n while (il--) {\n is[il].filtered = false\n }\n return self\n },\n search: function () {\n var is = self.items,\n il = is.length\n while (il--) {\n is[il].found = false\n }\n return self\n },\n }\n\n this.update = function () {\n var is = self.items,\n il = is.length\n\n self.visibleItems = []\n self.matchingItems = []\n self.templater.clear()\n for (var i = 0; i < il; i++) {\n if (is[i].matching() && self.matchingItems.length + 1 >= self.i && self.visibleItems.length < self.page) {\n is[i].show()\n self.visibleItems.push(is[i])\n self.matchingItems.push(is[i])\n } else if (is[i].matching()) {\n self.matchingItems.push(is[i])\n is[i].hide()\n } else {\n is[i].hide()\n }\n }\n self.trigger('updated')\n return self\n }\n\n init.start()\n}\n","module.exports = function (list) {\n return function (initValues, element, notCreate) {\n var item = this\n\n this._values = {}\n\n this.found = false // Show if list.searched == true and this.found == true\n this.filtered = false // Show if list.filtered == true and this.filtered == true\n\n var init = function (initValues, element, notCreate) {\n if (element === undefined) {\n if (notCreate) {\n item.values(initValues, notCreate)\n } else {\n item.values(initValues)\n }\n } else {\n item.elm = element\n var values = list.templater.get(item, initValues)\n item.values(values)\n }\n }\n\n this.values = function (newValues, notCreate) {\n if (newValues !== undefined) {\n for (var name in newValues) {\n item._values[name] = newValues[name]\n }\n if (notCreate !== true) {\n list.templater.set(item, item.values())\n }\n } else {\n return item._values\n }\n }\n\n this.show = function () {\n list.templater.show(item)\n }\n\n this.hide = function () {\n list.templater.hide(item)\n }\n\n this.matching = function () {\n return (\n (list.filtered && list.searched && item.found && item.filtered) ||\n (list.filtered && !list.searched && item.filtered) ||\n (!list.filtered && list.searched && item.found) ||\n (!list.filtered && !list.searched)\n )\n }\n\n this.visible = function () {\n return item.elm && item.elm.parentNode == list.list ? true : false\n }\n\n init(initValues, element, notCreate)\n }\n}\n","var classes = require('./utils/classes'),\n events = require('./utils/events'),\n List = require('./index')\n\nmodule.exports = function (list) {\n var isHidden = false\n\n var refresh = function (pagingList, options) {\n if (list.page < 1) {\n list.listContainer.style.display = 'none'\n isHidden = true\n return\n } else if (isHidden) {\n list.listContainer.style.display = 'block'\n }\n\n var item,\n l = list.matchingItems.length,\n index = list.i,\n page = list.page,\n pages = Math.ceil(l / page),\n currentPage = Math.ceil(index / page),\n innerWindow = options.innerWindow || 2,\n left = options.left || options.outerWindow || 0,\n right = options.right || options.outerWindow || 0\n\n right = pages - right\n pagingList.clear()\n for (var i = 1; i <= pages; i++) {\n var className = currentPage === i ? 'active' : ''\n\n //console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className);\n\n if (is.number(i, left, right, currentPage, innerWindow)) {\n item = pagingList.add({\n page: i,\n dotted: false,\n })[0]\n if (className) {\n classes(item.elm).add(className)\n }\n item.elm.firstChild.setAttribute('data-i', i)\n item.elm.firstChild.setAttribute('data-page', page)\n } else if (is.dotted(pagingList, i, left, right, currentPage, innerWindow, pagingList.size())) {\n item = pagingList.add({\n page: '...',\n dotted: true,\n })[0]\n classes(item.elm).add('disabled')\n }\n }\n }\n\n var is = {\n number: function (i, left, right, currentPage, innerWindow) {\n return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow)\n },\n left: function (i, left) {\n return i <= left\n },\n right: function (i, right) {\n return i > right\n },\n innerWindow: function (i, currentPage, innerWindow) {\n return i >= currentPage - innerWindow && i <= currentPage + innerWindow\n },\n dotted: function (pagingList, i, left, right, currentPage, innerWindow, currentPageItem) {\n return (\n this.dottedLeft(pagingList, i, left, right, currentPage, innerWindow) ||\n this.dottedRight(pagingList, i, left, right, currentPage, innerWindow, currentPageItem)\n )\n },\n dottedLeft: function (pagingList, i, left, right, currentPage, innerWindow) {\n return i == left + 1 && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right)\n },\n dottedRight: function (pagingList, i, left, right, currentPage, innerWindow, currentPageItem) {\n if (pagingList.items[currentPageItem - 1].values().dotted) {\n return false\n } else {\n return i == right && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right)\n }\n },\n }\n\n return function (options) {\n var pagingList = new List(list.listContainer.id, {\n listClass: options.paginationClass || 'pagination',\n item: options.item || \"