Created
May 22, 2016 22:59
-
-
Save anonymous/3a79b7c05b1abbe72e6d2526c5436164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$('body').on('click', '.original tr', function (e) { | |
var r = $(e.currentTarget); | |
r.appendTo($('.selected')); | |
calculate(); | |
}); | |
$('body').on('click', '.selected tr', function (e) { | |
var r = $(e.currentTarget); | |
r.appendTo($('.original')); | |
calculate(); | |
}); | |
var calculate = function () { | |
var sum = $('.selected tr td:nth-child(2)').toArray().map(function (td) { | |
return $(td).text(); | |
}).reduce(function (sum, i) { | |
return sum + parseInt(i); | |
}, 0); | |
$('.total').text(sum); | |
}; | |
var t = $('table'); | |
t.addClass('original table table-hover').wrap('<div class="column">'); | |
var c = $('.column'); | |
c.prepend('<h4>All Monsters (Click rows to select them)</h4>'); | |
c.after('<div class="column"><h4>Selected Monsters</h4><table class="selected table table-hover"/><h3 class="go">Total Selected MP: <span class="total"></span></h3></div>'); | |
calculate(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment