Gazelle/static/functions/release_sort.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2012-10-27 08:00:09 +00:00
//Couldn't use an associative array because javascript sorting is stupid http://dev-answers.blogspot.com/2012/03/javascript-object-keys-being-sorted-in.html
2012-11-16 08:00:21 +00:00
jQuery(document).ready(function ($) {
var serialize = function () {
var a = [];
$('#sortable input').each(function () {
a.push($(this).attr('id'));
});
$('#sorthide').val(JSON.stringify(a));
};
2012-10-27 08:00:09 +00:00
serialize();
2012-11-16 08:00:21 +00:00
$('#sortable')
.on('click', 'input', function () {
// the + converts the boolean to either 1 or 0
var c = +$(this).is(':checked'),
old_id = $(this).attr('id'),
new_id = old_id.slice(0, -1) + c;
$(this).attr('id', new_id);
serialize();
})
.sortable({
placeholder: 'ui-state-highlight',
update: serialize
});
$('#toggle_sortable').click(function (e) {
e.preventDefault();
$('#sortable_container').slideToggle(function () {
$('#toggle_sortable').text($(this).is(':visible') ? 'Collapse' : 'Expand');
2012-10-27 08:00:09 +00:00
});
});
2012-11-16 08:00:21 +00:00
$('#reset_sortable').click(function (e) {
e.preventDefault();
$('#sortable').html(sortable_list_default); // var sortable_list_default is found on edit.php
2012-10-30 08:00:18 +00:00
serialize();
});
2012-11-16 08:00:21 +00:00
});