Small improvments in sorting.

This commit is contained in:
Lars Jung 2012-10-28 02:55:57 +02:00
parent a447502703
commit 3a92606e0c
4 changed files with 17 additions and 19 deletions

View file

@ -1,7 +1,8 @@
modulejs.define('core/event', ['_'], function (_) {
var subscriptions = {},
var slice = Array.prototype.slice,
subscriptions = {},
sub = function (topic, callback) {
@ -24,7 +25,7 @@ modulejs.define('core/event', ['_'], function (_) {
pub = function (topic, data) {
var args = Array.prototype.slice.call(arguments, 1);
var args = slice.call(arguments, 1);
// console.log('EVENT PUB', topic, args);
if (_.isString(topic) && subscriptions[topic]) {

View file

@ -14,15 +14,9 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
defaultMetric = decimalMetric,
defaultDateFormat = 'YYYY-MM-DD HH:mm',
setDefaultMetric = function (metric) {
setDefaultMetric = function (useBinaryMetric) {
if (!metric) {
defaultMetric = decimalMetric;
} else if (metric === true) {
defaultMetric = binaryMetric;
} else {
defaultMetric = metric;
}
defaultMetric = useBinaryMetric ? binaryMetric : decimalMetric;
},
formatSize = function (size, metric) {
@ -48,13 +42,9 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
defaultDateFormat = dateFormat;
},
formatDate = function (millis, dateFormat) {
formatDate = function (millis) {
if (!_.isNumber(millis) || !millis) {
return '';
}
return moment(millis).format(dateFormat || defaultDateFormat);
return _.isNumber(millis) && millis ? moment(millis).format(defaultDateFormat) : '';
};
return {

View file

@ -65,7 +65,14 @@ modulejs.define('ext/sort', ['_', '$', 'core/settings', 'core/resource', 'core/e
$all.removeClass('ascending').removeClass('descending');
order.head.addClass(order.clas);
$('#items .item').detach().sort(order.fn).appendTo('#items');
var current = $('#items .item');
var sorted = $('#items .item').sort(order.fn);
for (var i = 0, l = current.length; i < l; i += 1) {
if (current[i] !== sorted[i]) {
sorted.detach().sort(order.fn).appendTo('#items');
break;
}
}
},
onContentChanged = function (item) {

View file

@ -16,7 +16,7 @@ modulejs.define('view/items', ['_', '$', 'core/settings', 'core/resource', 'core
'</a>' +
'</li>',
hintTemplate = '<span class="hint"/>',
itemsTemplate = '<ul id="items">' +
itemsTemplate = '<ul id="items" class="clearfix">' +
'<li class="header">' +
'<a class="icon"/>' +
'<a class="label" href="#"><span class="l10n-name"/></a>' +
@ -25,7 +25,7 @@ modulejs.define('view/items', ['_', '$', 'core/settings', 'core/resource', 'core
'</li>' +
'</ul>',
emptyTemplate = '<div class="empty l10n-empty"/>',
contentTemplate = '<div id="content"><div id="extended" class="clearfix"/></div>',
contentTemplate = '<div id="content"><div id="extended"/></div>',
// updates this single item
update = function (item, force) {