Re-ordering favourites?

  • Question
  • Updated 3 years ago
Is it possible to reorder the favourites somehow? I can easily think of a way of doing it with jQuery, but wondered if there might be a solution if users have javascript turned off?

Thanks!
Photo of Tim Jukes

Tim Jukes

  • 8 Posts
  • 0 Likes
  • hopeful

Posted 3 years ago

  • 1
Photo of Bjørn Børresen

Bjørn Børresen, Company Admin

  • 1127 Posts
  • 39 Likes
Hi Tim,

there are currently no EE tags for this - but it is certainly a good feature request. How would you see this working - a tag for moving a specific favourite up and one for moving a favourite down?
Photo of Tim Jukes

Tim Jukes

  • 8 Posts
  • 0 Likes
I was thinking just number text input fields but up/down would be good.

I'd most probably end up wanting to use jQueryUI Sortable - so would be great if there was a way to hook into that - just trying to work this out with the current code!
Photo of Tim Jukes

Tim Jukes

  • 8 Posts
  • 0 Likes
Mostly to remind myself but might be handy for someone - these are the tweaks I made to get things working with jQuery sortable:

Created callback to deal with the changed state:

function newOrder() {
var list = new cookieFavs();
var newitems = list.items();
newitems = new Array();
$('#custom_trail_venues li').each(function(index) {
var idarr = $(this).attr('id').split('-');
var entry_id = idarr[1];
newitems.push(entry_id);
});
list.reset(newitems);
}

$( "#custom_trail_venues" ).sortable({
axis: "y",
cursor: "move",
update: function() { newOrder(); }
});
$( "#custom_trail_venues" ).disableSelection();


Then added a 'reset' method to cookieFavs (and changed statements for 'null' into new Array() as Firebug had a problem with that )


var cookieFavs = function() {
var cookieName = "exp_cookie_favourites";
var cookie = $.cookie(cookieName);
var items = cookie ? cookie.split(/,/) : new Array();

return {
"add": function(val) {
items.push(val);
$.cookie(cookieName, items.join(','), {expires: 730, path: '/'});
},
"remove": function(val) {
items = $.grep(items, function(value) {
return value != val;
});
$.cookie(cookieName, items.join(','), {expires: 730, path: '/'});
},
"clear": function() {
items = new Array();
$.cookie(cookieName, items, {expires: 730, path: '/'});
},
"items": function() {
return items;
},
"reset":function(newitems){
$.cookie(cookieName, newitems.join(','), {expires: 730, path: '/'});
}
}
}

Then what finally tripped me up for ages was actually just to do with the Channel Module - had to make sure I set the channel order to:


fixed_order="{favourites_entry_ids}"
Photo of Bjørn Børresen

Bjørn Børresen, Company Admin

  • 1127 Posts
  • 39 Likes
Amazing stuff, Tim! :-) I've added EE tags for sorting on my todo for CookieFav so non-js fallback will be available in the next release.