Skip to content

Instantly share code, notes, and snippets.

@exit99
Created November 28, 2014 18:20
Show Gist options
  • Save exit99/1221634b59861149ef17 to your computer and use it in GitHub Desktop.
Save exit99/1221634b59861149ef17 to your computer and use it in GitHub Desktop.
$(function () {
$.fn.exchangePositionWith = function(selector) {
var other = $(selector);
this.after(other.clone());
other.after(this).remove();
};
$(document).on('click', '.fa-chevron-down', function () {
var ul = $(this).parents('ul'),
li_index = $(this).parents('li').index();
ul.children('li:eq(' + li_index + ')').exchangePositionWith(ul.children('li:eq(' + (li_index+2) + ')'))
});
$(document).on('click', '.fa-chevron-up', function () {
var ul = $(this).parents('ul'),
li_index = $(this).parents('li').index();
if (li_index > 1) {
ul.children('li:eq(' + li_index + ')').exchangePositionWith(ul.children('li:eq(' + (li_index-2) + ')'))
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment