File "jquery.selectlistactions.js"
Full Path: /home/analogde/www/MDPH/Work/jquery.selectlistactions.js
File size: 2.28 KB
MIME-type: text/plain
Charset: utf-8
/**
* jQuery.SelectListActions
* https://github.com/esausilva/jquery.selectlistactions.js
*
* (c) http://esausilva.com
*/
(function ($) {
//Moves selected item(s) from sourceList to destinationList
$.fn.moveToList = function (sourceList, destinationList) {
var opts = $(sourceList + ' option:selected');
if (opts.length == 0) {
alert("Nothing to move");
}
$(destinationList).append($(opts).clone());
};
//Moves all items from sourceList to destinationList
$.fn.moveAllToList = function (sourceList, destinationList) {
var opts = $(sourceList + ' option');
if (opts.length == 0) {
alert("Nothing to move");
}
$(destinationList).append($(opts).clone());
};
//Moves selected item(s) from sourceList to destinationList and deleting the
// selected item(s) from the source list
$.fn.moveToListAndDelete = function (sourceList, destinationList) {
var opts = $(sourceList + ' option:selected');
if (opts.length == 0) {
alert("Nothing to move");
}
$(opts).remove();
$(destinationList).append($(opts).clone());
};
//Moves all items from sourceList to destinationList and deleting
// all items from the source list
$.fn.moveAllToListAndDelete = function (sourceList, destinationList) {
var opts = $(sourceList + ' option');
if (opts.length == 0) {
alert("Nothing to move");
}
$(opts).remove();
$(destinationList).append($(opts).clone());
};
//Removes selected item(s) from list
$.fn.removeSelected = function (list) {
var opts = $(list + ' option:selected');
if (opts.length == 0) {
alert("Nothing to remove");
}
$(opts).remove();
};
//Moves selected item(s) up or down in a list
$.fn.moveUpDown = function (list, btnUp, btnDown) {
var opts = $(list + ' option:selected');
if (opts.length == 0) {
alert("Nothing to move");
}
if (btnUp) {
opts.first().prev().before(opts);
} else if (btnDown) {
opts.last().next().after(opts);
}
};
})(jQuery);