Some javascript code cleanup. Should make some pages lighter.

This commit is contained in:
James Cole 2016-01-29 17:49:02 +01:00
parent c38e4b86b4
commit f741552d91
4 changed files with 28 additions and 30 deletions

View File

@ -2,13 +2,11 @@
// Return a helper with preserved width of cells
var fixHelper = function(e, tr)
{
var fixHelper = function (e, tr) {
"use strict";
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function(index)
{
$helper.children().each(function (index) {
// Set helper cell sizes to match the original sizes
$(this).width($originals.eq(index).width());
});
@ -29,7 +27,23 @@ $(function () {
helper: fixHelper,
items: 'tr:not(.ignore)',
stop: sortStop,
handle: '.handle'
handle: '.handle',
start: function (event, ui) {
// Build a placeholder cell that spans all the cells in the row
var cellCount = 0;
$('td, th', ui.helper).each(function () {
// For each TD or TH try and get it's colspan attribute, and add that or 1 to the total
var colspan = 1;
var colspanAttr = $(this).attr('colspan');
if (colspanAttr > 1) {
colspan = colspanAttr;
}
cellCount += colspan;
});
// Add the placeholder UI - note that this is the item's content, so TD rather than TR
ui.placeholder.html('<td colspan="' + cellCount + '">&nbsp;</td>');
}
}
).disableSelection();
} else {
@ -38,7 +52,6 @@ $(function () {
});
function sortStop(event, ui) {
"use strict";
var current = $(ui.item);
@ -49,12 +62,8 @@ function sortStop(event, ui) {
if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {
// animate something with color:
current.animate({
backgroundColor: "#d9534f"
}, 200, function () {
$(this).animate({
backgroundColor: originalBG
}, 200);
current.animate({backgroundColor: "#d9534f"}, 200, function () {
$(this).animate({backgroundColor: originalBG}, 200);
});
return false;
@ -72,17 +81,7 @@ function sortStop(event, ui) {
// do extra animation when done?
$.post('/transaction/reorder', {items: submit, date: thisDate, _token: token});
current.animate({
backgroundColor: "#5cb85c"
}, 200, function () {
$(this).animate({
backgroundColor: originalBG
}, 200);
current.animate({backgroundColor: "#5cb85c"}, 200, function () {
$(this).animate({backgroundColor: originalBG}, 200);
});
//else update some order thing bla bla.
//check if the item above OR under this one have the same date
//if not. return false
}

File diff suppressed because one or more lines are too long

View File

@ -49,9 +49,5 @@
<script type="text/javascript">
var what = '{{ what }}';
</script>
<script type="text/javascript" src="js/Chart.min.js"></script>
<script type="text/javascript" src="js/charts.js"></script>
<script type="text/javascript" src="js/bootstrap-sortable.js"></script>
<script type="text/javascript" src="js/accounts.js"></script>
{% endblock %}

View File

@ -54,7 +54,8 @@
</script>
<script type="text/javascript" src="js/Chart.min.js"></script>
<script type="text/javascript" src="js/charts.js"></script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/accounts.js" type="text/javascript"></script>
<script src="js/lib/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/lib/jquery.color-2.1.2.min.js" type="text/javascript"></script>
<script src="js/accounts/show.js" type="text/javascript"></script>
{% endblock %}