Hi Everyone,
This is my latest tutorial to enable multiple select while pressing shift key. It means after following this tutorial, if you will select a listing (or comment ) in admin dashboard and after that select another listing while pressing shift key than all in between listings will be selected automatically.
Same happen when you want to uncheck multiple listing via mouse and shift key.
I am running this code from 5 months and it is working fine but I may not guarantee if you will get electric shock while adding this code to your site.
So what you have to do? Just add this code to your functions.php file which you can find in your theme directory.
<?php function checkbox_admin_header() {
?>
<script type="text/javascript">
(function($){
function toggleSelected(element, shouldSelect) {
$(element).attr("checked", shouldSelect);
if(shouldSelect){
$(element).parents("tr").addClass("selected");
} else {
$(element).parents("tr").removeClass("selected");
}
}
$.fn.shiftSelectTable = function(){
var $table = $(this);
$table.find(":checkbox").click(function(event){
var last = $table.data("jquery-shift-select-table.last");
$table.data("jquery-shift-select-table.last", $(this).get());
if(last == null || !event.shiftKey) {
$(this).parents("tr").toggleClass("selected");
}
else {
var shouldSelect = $(this).attr("checked");
if(shouldSelect===undefined){
shouldSelect=null;
}
var $checkboxes = $table.find(":checkbox");
var currentIndex = $checkboxes.index(this);
var lastIndex = $checkboxes.index($(last));
var $checkboxesToChange = (currentIndex >= lastIndex) ? $checkboxes.slice(lastIndex, currentIndex+1) : $checkboxes.slice(currentIndex, lastIndex+1);
$checkboxesToChange.each(function(){
toggleSelected(this, shouldSelect);
});
}
});
this.find(":checked").parents("tr").toggleClass("selected");
return this;
};
})(jQuery);
$(function() {
$(".table").shiftSelectTable();
});
</script>
<?php }
osc_add_hook('admin_header', 'checkbox_admin_header');
?>
While pasting this code keep note of php start end tag : <?php ............... ?>
I hope you all will like it.
Regards
Navjot Tomer
PS: Tuffclassified theme user can add it to custom-functions.php via php editor included in theme dashboard. Or you can wait for next version I will include it in next version.