Skip to content

Commit

Permalink
Merge branch '1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
javve committed Feb 27, 2016
2 parents 4884580 + 2854a31 commit ff508e5
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = function(grunt) {
grunt.registerTask('default', ['jshint:code', 'jshint:tests', 'shell:mkdir', 'shell:build']);
grunt.registerTask('dist', ['default', 'shell:mkdir', 'shell:build', 'uglify']);
grunt.registerTask('clean', ['shell:remove']);
grunt.registerTask('test', ['default', 'mocha']);
grunt.registerTask('test', ['dist', 'mocha']);

return grunt;
};
17 changes: 15 additions & 2 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
- Add tests for custom event handlers. 27e2d6fdeee7090eb1342a108013db898fc29b96
- Regex in search https://github.com/javve/list.js/issues/371
- Keep original order?

### 2016-02-05: 1.2.0
- Automatically add item in the right place if sort is active
- How to handle arrays?
- Implement debouncing in search?
- Better search https://github.com/javve/list.js/pull/312/files ?
- Investigate sort button defaults:
- https://github.com/javve/list.js/issues/316
- https://github.com/javve/list.js/pull/301
- Improve testability by decoupling things and make it possible to use require('') in tests

### 2016-02-27: 1.2.0
- **[Misc]** Move form Component to Browserify
[See commit →](https://github.com/javve/list.js/commit/58695c93849b78787d9cf78cbf9be20b01cdcc8a)
- **[Misc]** Add tests to make sure List.js works with require.js
Expand Down Expand Up @@ -42,6 +50,11 @@
[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
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"authors": [
"Jonny Strömberg <jonny.stromberg@gmail.com>"
],
"description": "Add search, sort and flexibility to plain HTML lists or tables with cross-browser native JavaScript.",
"description": "The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML",
"keywords": [
"list",
"search",
Expand Down
83 changes: 59 additions & 24 deletions dist/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var document = window.document,
toString = require('./src/utils/to-string'),
naturalSort = require('./src/utils/natural-sort'),
classes = require('./src/utils/classes'),
getAttribute = require('./src/utils/get-attribute');
getAttribute = require('./src/utils/get-attribute'),
toArray = require('./src/utils/to-array');

var List = function(id, options, values) {

Expand All @@ -38,6 +39,7 @@ var List = function(id, options, values) {
self.searchColumns = undefined;
self.handlers = { 'updated': [] };
self.plugins = {};
self.valueNames = [];
self.utils = {
getByClass: getByClass,
extend: extend,
Expand All @@ -46,10 +48,11 @@ var List = function(id, options, values) {
toString: toString,
naturalSort: naturalSort,
classes: classes,
getAttribute: getAttribute
getAttribute: getAttribute,
toArray: toArray
};

extend(self, options);
self.utils.extend(self, options);

self.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id;
if (!self.listContainer) { return; }
Expand Down Expand Up @@ -127,13 +130,8 @@ var List = function(id, options, values) {
}
for (var i = 0, il = values.length; i < il; i++) {
var item = null;
if (values[i] instanceof Item) {
item = values[i];
item.reload();
} else {
notCreate = (self.items.length > self.page) ? true : false;
item = new Item(values[i], undefined, notCreate);
}
notCreate = (self.items.length > self.page) ? true : false;
item = new Item(values[i], undefined, notCreate);
self.items.push(item);
added.push(item);
}
Expand Down Expand Up @@ -274,7 +272,7 @@ window.List = List;

})(window);

},{"./src/add-async":2,"./src/filter":3,"./src/item":4,"./src/parse":5,"./src/search":6,"./src/sort":7,"./src/templater":8,"./src/utils/classes":9,"./src/utils/events":10,"./src/utils/extend":11,"./src/utils/get-attribute":12,"./src/utils/get-by-class":13,"./src/utils/index-of":14,"./src/utils/natural-sort":15,"./src/utils/to-string":17}],2:[function(require,module,exports){
},{"./src/add-async":2,"./src/filter":3,"./src/item":4,"./src/parse":5,"./src/search":6,"./src/sort":7,"./src/templater":8,"./src/utils/classes":9,"./src/utils/events":10,"./src/utils/extend":11,"./src/utils/get-attribute":12,"./src/utils/get-by-class":13,"./src/utils/index-of":14,"./src/utils/natural-sort":15,"./src/utils/to-array":16,"./src/utils/to-string":17}],2:[function(require,module,exports){
module.exports = function(list) {
var addAsync = function(values, callback, items) {
var valuesToAdd = values.splice(0, 50);
Expand Down Expand Up @@ -346,6 +344,7 @@ module.exports = function(list) {
item.values(values);
}
};

this.values = function(newValues, notCreate) {
if (newValues !== undefined) {
for(var name in newValues) {
Expand All @@ -358,12 +357,15 @@ module.exports = function(list) {
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) ||
Expand All @@ -372,9 +374,11 @@ module.exports = function(list) {
(!list.filtered && !list.searched)
);
};

this.visible = function() {
return (item.elm && (item.elm.parentNode == list.list)) ? true : false;
};

init(initValues, element, notCreate);
};
};
Expand Down Expand Up @@ -576,10 +580,10 @@ module.exports = function(list) {
},
getInSensitive: function(btn, options) {
var insensitive = list.utils.getAttribute(btn, 'data-insensitive');
if (insensitive === "true") {
options.insensitive = true;
} else {
if (insensitive === "false") {
options.insensitive = false;
} else {
options.insensitive = true;
}
},
setOrder: function(options) {
Expand Down Expand Up @@ -641,35 +645,65 @@ module.exports = function(list) {

},{}],8:[function(require,module,exports){
var Templater = function(list) {
var itemSource = getItemSource(list.item),
var itemSource,
templater = this;

function getItemSource(item) {
var init = function() {
itemSource = templater.getItemSource(list.item);
itemSource = templater.clearSourceItem(itemSource, list.valueNames);
};

this.clearSourceItem = function(el, valueNames) {
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
el.setAttribute('data-'+valueNames[i].data[j], '');
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(el, valueNames[i].name, true);
if (elm) {
elm.setAttribute(valueNames[i].attr, "");
}
} else {
elm = list.utils.getByClass(el, valueNames[i], true);
if (elm) {
elm.innerHTML = "";
}
}
elm = undefined;
}
return el;
};

this.getItemSource = function(item) {
if (item === undefined) {
var nodes = list.list.childNodes,
items = [];

for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
return nodes[i];
return nodes[i].cloneNode(true);
}
}
return null;
} else if (/^tr[\s>]/.exec(item)) {
} else if (/^tr[\s>]/.exec(item)) {
var table = document.createElement('table');
table.innerHTML = item;
return table.firstChild;
} else if (item.indexOf("<") !== -1) { // Try create html element of list, do not work for tables!!
} else if (item.indexOf("<") !== -1) {
var div = document.createElement('div');
div.innerHTML = item;
return div.firstChild;
} else {
return document.getElementById(list.item);
var source = document.getElementById(list.item);
if (source) {
return source;
}
}
}
throw new Error("The list need to have at list one item on init otherwise you'll have to add a template.");
};

/* Get values from element */
this.get = function(item, valueNames) {
templater.create(item);
var values = {};
Expand All @@ -691,7 +725,6 @@ var Templater = function(list) {
return values;
};

/* Sets values at element */
this.set = function(item, values) {
var getValueName = function(name) {
for (var i = 0, il = list.valueNames.length; i < il; i++) {
Expand Down Expand Up @@ -773,6 +806,8 @@ var Templater = function(list) {
}
}
};

init();
};

module.exports = function(list) {
Expand Down
Loading

0 comments on commit ff508e5

Please sign in to comment.