diff --git a/ui/data.js b/ui/data.js index affdb318..de0a29bb 100755 --- a/ui/data.js +++ b/ui/data.js @@ -189,11 +189,11 @@ function imageDateCmp(a, b, get, data){ function imageNameCmp(a, b, get, data){ data = data == null ? IMAGES : data if(get == null){ - a = data[b].path.split('/').pop() - b = data[a].path.split('/').pop() + a = data[a].path.split('/').pop() + b = data[b].path.split('/').pop() } else { - a = data[get(b)].path.split('/').pop() - b = data[get(a)].path.split('/').pop() + a = data[get(a)].path.split('/').pop() + b = data[get(b)].path.split('/').pop() } if(a == b){ return 0 @@ -485,6 +485,18 @@ function getBestPreview(gid, size){ } +// Resort the ribbons by DATA.order and re-render... +// +// NOTE: due to how the format is structured, to sort the images one +// only needs to sort DATA.order and call this. +function updateRibbonOrder(){ + for(var i=0; i < DATA.ribbons.length; i++){ + DATA.ribbons[i].sort(imageOrderCmp) + } + loadData() +} + + /********************************************************************** * Constructors @@ -953,16 +965,33 @@ function loadSettings(){ * Actions... */ -// XXX revise... -function reverseImages(){ +function reverseImageOrder(){ DATA.order.reverse() - for(var i=0; i < DATA.ribbons.length; i++){ - DATA.ribbons[i].reverse() - } - loadData() + updateRibbonOrder() } +// NOTE: using imageOrderCmp as a cmp function here will yield odd +// results -- in-place sorting a list based on relative element +// positions within itself is fun ;) +function sortImages(cmp, reverse){ + cmp = cmp == null ? imageDateCmp : cmp + DATA.order.sort(cmp) + if(reverse){ + DATA.order.reverse() + } + updateRibbonOrder() +} + + +// shirt-hands... +function sortImagesByDate(reverse){ + return sortImages(reverse) +} +function sortImagesByName(reverse){ + return sortImages(imageNameCmp, reverse) +} + /********************************************************************** diff --git a/ui/keybindings.js b/ui/keybindings.js index 0b20b7fc..3efc9c70 100755 --- a/ui/keybindings.js +++ b/ui/keybindings.js @@ -276,7 +276,7 @@ var KEYBOARD_CONFIG = { default: doc('Rotate image right', function(){ rotateRight() }), ctrl: doc('Reverse image order', - function(){ reverseImages() }), + function(){ reverseImageOrder() }), },