Merge branch 'mattstauffer-case-insensitive-order'

This commit is contained in:
An Phan 2015-12-15 20:26:41 +08:00
commit 73b5c89a85
2 changed files with 25 additions and 1 deletions

View file

@ -182,6 +182,30 @@
},
};
/**
* Modified version of orderBy that is case insensitive
*
* @source https://github.com/vuejs/vue/blob/dev/src/filters/array-filters.js
*/
Vue.filter('caseInsensitiveOrderBy', (arr, sortKey, reverse) => {
if (!sortKey) {
return arr;
}
var order = (reverse && reverse < 0) ? -1 : 1
// sort on a copy to avoid mutating original array
return arr.slice().sort((a, b) => {
a = Vue.util.isObject(a) ? Vue.parsers.path.getPath(a, sortKey) : a
b = Vue.util.isObject(b) ? Vue.parsers.path.getPath(b, sortKey) : b
a = a === undefined ? a : a.toLowerCase()
b = b === undefined ? b : b.toLowerCase()
return a === b ? 0 : a > b ? order : -order
});
});
// Register the global directives
Vue.directive('koel-focus', require('./directives/focus'));
</script>

View file

@ -31,7 +31,7 @@
<tbody>
<tr
v-for="item in items
| orderBy sortKey order
| caseInsensitiveOrderBy sortKey order
| filterBy q in 'title' 'album.name' 'album.artist.name'
| limitBy numOfItems"
is="song-item"