1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-29 10:50:51 +02:00

Refactored sort module

This commit is contained in:
Max Guglielmi 2016-05-20 17:14:05 +10:00
parent c849418e2f
commit f3fb49bd3d
4 changed files with 61 additions and 70 deletions

View file

@ -4445,8 +4445,6 @@ return /******/ (function(modules) { // webpackBootstrap
var _sort = __webpack_require__(17); var _sort = __webpack_require__(17);
var _sort2 = _interopRequireDefault(_sort);
var _event = __webpack_require__(1); var _event = __webpack_require__(1);
var _event2 = _interopRequireDefault(_event); var _event2 = _interopRequireDefault(_event);
@ -4664,9 +4662,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (tf.sortSlc && !this.isCustom) { if (tf.sortSlc && !this.isCustom) {
if (!matchCase) { if (!matchCase) {
this.opts.sort(_sort2.default.ignoreCase); this.opts.sort(_sort.ignoreCase);
if (excludedOpts) { if (excludedOpts) {
excludedOpts.sort(_sort2.default.ignoreCase); excludedOpts.sort(_sort.ignoreCase);
} }
} else { } else {
this.opts.sort(); this.opts.sort();
@ -4679,12 +4677,12 @@ return /******/ (function(modules) { // webpackBootstrap
//asc sort //asc sort
if (tf.sortNumAsc.indexOf(colIndex) !== -1) { if (tf.sortNumAsc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(_sort2.default.numSortAsc); this.opts.sort(_sort.numSortAsc);
if (excludedOpts) { if (excludedOpts) {
excludedOpts.sort(_sort2.default.numSortAsc); excludedOpts.sort(_sort.numSortAsc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(_sort2.default.numSortAsc); this.optsTxt.sort(_sort.numSortAsc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'ascending')); throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'ascending'));
@ -4693,12 +4691,12 @@ return /******/ (function(modules) { // webpackBootstrap
//desc sort //desc sort
if (tf.sortNumDesc.indexOf(colIndex) !== -1) { if (tf.sortNumDesc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(_sort2.default.numSortDesc); this.opts.sort(_sort.numSortDesc);
if (excludedOpts) { if (excludedOpts) {
excludedOpts.sort(_sort2.default.numSortDesc); excludedOpts.sort(_sort.numSortDesc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(_sort2.default.numSortDesc); this.optsTxt.sort(_sort.numSortDesc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'ascending')); throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'ascending'));
@ -4880,32 +4878,29 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ }, /***/ },
/* 17 */ /* 17 */
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports) {
'use strict'; "use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
/**
* Sorting utilities
*/
var _string = __webpack_require__(5); var ignoreCase = exports.ignoreCase = function ignoreCase(a, b) {
var x = a.toLowerCase();
var y = b.toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
};
var _string2 = _interopRequireDefault(_string); var numSortAsc = exports.numSortAsc = function numSortAsc(a, b) {
return a - b;
};
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var numSortDesc = exports.numSortDesc = function numSortDesc(a, b) {
return b - a;
exports.default = {
ignoreCase: function ignoreCase(a, b) {
var x = _string2.default.lower(a);
var y = _string2.default.lower(b);
return x < y ? -1 : x > y ? 1 : 0;
},
numSortAsc: function numSortAsc(a, b) {
return a - b;
},
numSortDesc: function numSortDesc(a, b) {
return b - a;
}
}; };
/***/ }, /***/ },
@ -4933,8 +4928,6 @@ return /******/ (function(modules) { // webpackBootstrap
var _sort = __webpack_require__(17); var _sort = __webpack_require__(17);
var _sort2 = _interopRequireDefault(_sort);
var _event = __webpack_require__(1); var _event = __webpack_require__(1);
var _event2 = _interopRequireDefault(_event); var _event2 = _interopRequireDefault(_event);
@ -5158,9 +5151,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (tf.sortSlc && !this.isCustom) { if (tf.sortSlc && !this.isCustom) {
if (!tf.matchCase) { if (!tf.matchCase) {
this.opts.sort(_sort2.default.ignoreCase); this.opts.sort(_sort.ignoreCase);
if (this.excludedOpts) { if (this.excludedOpts) {
this.excludedOpts.sort(_sort2.default.ignoreCase); this.excludedOpts.sort(_sort.ignoreCase);
} }
} else { } else {
this.opts.sort(); this.opts.sort();
@ -5172,12 +5165,12 @@ return /******/ (function(modules) { // webpackBootstrap
//asc sort //asc sort
if (tf.sortNumAsc.indexOf(colIndex) !== -1) { if (tf.sortNumAsc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(_sort2.default.numSortAsc); this.opts.sort(_sort.numSortAsc);
if (this.excludedOpts) { if (this.excludedOpts) {
this.excludedOpts.sort(_sort2.default.numSortAsc); this.excludedOpts.sort(_sort.numSortAsc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(_sort2.default.numSortAsc); this.optsTxt.sort(_sort.numSortAsc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'ascending')); throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'ascending'));
@ -5186,12 +5179,12 @@ return /******/ (function(modules) { // webpackBootstrap
//desc sort //desc sort
if (tf.sortNumDesc.indexOf(colIndex) !== -1) { if (tf.sortNumDesc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(_sort2.default.numSortDesc); this.opts.sort(_sort.numSortDesc);
if (this.excludedOpts) { if (this.excludedOpts) {
this.excludedOpts.sort(_sort2.default.numSortDesc); this.excludedOpts.sort(_sort.numSortDesc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(_sort2.default.numSortDesc); this.optsTxt.sort(_sort.numSortDesc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'descending')); throw new Error(SORT_ERROR.replace('{0}', colIndex).replace('{1}', 'descending'));

View file

@ -2,7 +2,7 @@ import {Feature} from '../feature';
import Dom from '../dom'; import Dom from '../dom';
import {has} from '../array'; import {has} from '../array';
import Str from '../string'; import Str from '../string';
import Sort from '../sort'; import {ignoreCase, numSortAsc, numSortDesc} from '../sort';
import Event from '../event'; import Event from '../event';
import {isEmpty} from '../types'; import {isEmpty} from '../types';
import {CHECKLIST, NONE} from '../const'; import {CHECKLIST, NONE} from '../const';
@ -214,9 +214,9 @@ export class CheckList extends Feature {
if (tf.sortSlc && !this.isCustom) { if (tf.sortSlc && !this.isCustom) {
if (!tf.matchCase) { if (!tf.matchCase) {
this.opts.sort(Sort.ignoreCase); this.opts.sort(ignoreCase);
if (this.excludedOpts) { if (this.excludedOpts) {
this.excludedOpts.sort(Sort.ignoreCase); this.excludedOpts.sort(ignoreCase);
} }
} else { } else {
this.opts.sort(); this.opts.sort();
@ -228,12 +228,12 @@ export class CheckList extends Feature {
//asc sort //asc sort
if (tf.sortNumAsc.indexOf(colIndex) !== -1) { if (tf.sortNumAsc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(Sort.numSortAsc); this.opts.sort(numSortAsc);
if (this.excludedOpts) { if (this.excludedOpts) {
this.excludedOpts.sort(Sort.numSortAsc); this.excludedOpts.sort(numSortAsc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(Sort.numSortAsc); this.optsTxt.sort(numSortAsc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex) throw new Error(SORT_ERROR.replace('{0}', colIndex)
@ -243,12 +243,12 @@ export class CheckList extends Feature {
//desc sort //desc sort
if (tf.sortNumDesc.indexOf(colIndex) !== -1) { if (tf.sortNumDesc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(Sort.numSortDesc); this.opts.sort(numSortDesc);
if (this.excludedOpts) { if (this.excludedOpts) {
this.excludedOpts.sort(Sort.numSortDesc); this.excludedOpts.sort(numSortDesc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(Sort.numSortDesc); this.optsTxt.sort(numSortDesc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex) throw new Error(SORT_ERROR.replace('{0}', colIndex)

View file

@ -2,7 +2,7 @@ import {Feature} from '../feature';
import Dom from '../dom'; import Dom from '../dom';
import {has} from '../array'; import {has} from '../array';
import Str from '../string'; import Str from '../string';
import Sort from '../sort'; import {ignoreCase, numSortAsc, numSortDesc} from '../sort';
import Event from '../event'; import Event from '../event';
import {SELECT, MULTIPLE, NONE} from '../const'; import {SELECT, MULTIPLE, NONE} from '../const';
@ -214,9 +214,9 @@ export class Dropdown extends Feature {
if (tf.sortSlc && !this.isCustom) { if (tf.sortSlc && !this.isCustom) {
if (!matchCase) { if (!matchCase) {
this.opts.sort(Sort.ignoreCase); this.opts.sort(ignoreCase);
if (excludedOpts) { if (excludedOpts) {
excludedOpts.sort(Sort.ignoreCase); excludedOpts.sort(ignoreCase);
} }
} else { } else {
this.opts.sort(); this.opts.sort();
@ -227,12 +227,12 @@ export class Dropdown extends Feature {
//asc sort //asc sort
if (tf.sortNumAsc.indexOf(colIndex) !== -1) { if (tf.sortNumAsc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(Sort.numSortAsc); this.opts.sort(numSortAsc);
if (excludedOpts) { if (excludedOpts) {
excludedOpts.sort(Sort.numSortAsc); excludedOpts.sort(numSortAsc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(Sort.numSortAsc); this.optsTxt.sort(numSortAsc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex) throw new Error(SORT_ERROR.replace('{0}', colIndex)
@ -242,12 +242,12 @@ export class Dropdown extends Feature {
//desc sort //desc sort
if (tf.sortNumDesc.indexOf(colIndex) !== -1) { if (tf.sortNumDesc.indexOf(colIndex) !== -1) {
try { try {
this.opts.sort(Sort.numSortDesc); this.opts.sort(numSortDesc);
if (excludedOpts) { if (excludedOpts) {
excludedOpts.sort(Sort.numSortDesc); excludedOpts.sort(numSortDesc);
} }
if (this.isCustom) { if (this.isCustom) {
this.optsTxt.sort(Sort.numSortDesc); this.optsTxt.sort(numSortDesc);
} }
} catch (e) { } catch (e) {
throw new Error(SORT_ERROR.replace('{0}', colIndex) throw new Error(SORT_ERROR.replace('{0}', colIndex)

View file

@ -1,15 +1,13 @@
import Str from './string'; /**
* Sorting utilities
*/
export default { export const ignoreCase = (a, b) => {
ignoreCase(a, b){ let x = a.toLowerCase();
let x = Str.lower(a); let y = b.toLowerCase();
let y = Str.lower(b); return ((x < y) ? -1 : ((x > y) ? 1 : 0));
return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
},
numSortAsc(a, b){ export const numSortAsc = (a, b) => (a - b);
return (a - b);
}, export const numSortDesc = (a, b) => (b - a);
numSortDesc(a, b){
return (b - a);
}
};