From bd6e7fc57003f9aea471ba523acae3fc79558a3f Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 17 Jun 2019 06:13:30 +0200 Subject: [PATCH] Initial commit --- autogrow.js | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 55 ++++++++++++++++++++++++++++++++++++++ script.js | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 autogrow.js create mode 100644 index.html create mode 100644 script.js diff --git a/autogrow.js b/autogrow.js new file mode 100644 index 00000000..a9699536 --- /dev/null +++ b/autogrow.js @@ -0,0 +1,76 @@ +(function($) +{ + /** + * Auto-growing textareas; technique ripped from Facebook + * + * + * http://github.com/jaz303/jquery-grab-bag/tree/master/javascripts/jquery.autogrow-textarea.js + */ + $.fn.autogrow = function(options) + { + return this.filter('textarea').each(function() + { + var self = this; + var $self = $(self); + var minHeight = $self.height(); + var noFlickerPad = $self.hasClass('autogrow-short') ? 0 : parseInt($self.css('lineHeight')) || 0; + var settings = $.extend({ + preGrowCallback: null, + postGrowCallback: null + }, options ); + + var shadow = $('
').css({ + position: 'absolute', + top: -10000, + left: -10000, + width: $self.width(), + fontSize: $self.css('fontSize'), + fontFamily: $self.css('fontFamily'), + fontWeight: $self.css('fontWeight'), + lineHeight: $self.css('lineHeight'), + resize: 'none', + 'word-wrap': 'break-word' + }).appendTo(document.body); + + var update = function(event) + { + var times = function(string, number) + { + for (var i=0, r=''; i/g, '>') + .replace(/\n$/, '
 ') + .replace(/\n/g, '
') + .replace(/ {2,}/g, function(space){ return times(' ', space.length - 1) + ' ' }); + + // Did enter get pressed? Resize in this keydown event so that the flicker doesn't occur. + if (event && event.data && event.data.event === 'keydown' && event.keyCode === 13) { + val += '
'; + } + + shadow.css('width', $self.width()); + shadow.html(val + (noFlickerPad === 0 ? '...' : '')); // Append '...' to resize pre-emptively. + + var newHeight=Math.max(shadow.height() + noFlickerPad, minHeight); + if(settings.preGrowCallback!=null){ + newHeight=settings.preGrowCallback($self,shadow,newHeight,minHeight); + } + + $self.height(newHeight); + + if(settings.postGrowCallback!=null){ + settings.postGrowCallback($self); + } + } + + $self.change(update).keyup(update).keydown({event:'keydown'},update); + $(window).resize(update); + + update(); + }); + }; +})(jQuery); diff --git a/index.html b/index.html new file mode 100644 index 00000000..0cb506e0 --- /dev/null +++ b/index.html @@ -0,0 +1,55 @@ + + + + + + Loot Table Generator + + + + +
+
+
+
+ +
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+ + + +
+
+
+
+ Rolls +
+ +
+
+
+
+ + + + + + + + diff --git a/script.js b/script.js new file mode 100644 index 00000000..c48aec81 --- /dev/null +++ b/script.js @@ -0,0 +1,47 @@ + +$("#source").val(''); + +let table = { + pools: [] +}; +addPool(); + +function addPool(el) { + table.pools.push({ + rolls: 1, + entries: [] + }); + let $pool = $('#poolTemplate').clone(); + $pool.removeAttr('id').attr('data-index', table.pools.length - 1); + $('#structure').append($pool); + invalidated(); +} + +function removePool(el) { + let $pool = $(el).parent().parent(); + table.pools.pop($pool.attr('data-index')); + $('#structure .pool').each((i, el) => { + if ($(el).attr('data-index') > $pool.attr('data-index')) { + $(el).attr('data-index', $(el).attr('data-index') - 1); + } + }); + $pool.remove(); + invalidated(); +} + +function updateRollsField(el) { + let $pool = $(el).parent().parent().parent(); + let value = parseInt($(el).val()); + table.pools[$pool.attr('data-index')].rolls = value; + invalidated(); +} + +function invalidated() { + $('#source').val(JSON.stringify(table, null, 2)); + $('#source').autogrow(); +} + +function copySource(el) { + $('#source').get()[0].select(); + document.execCommand('copy'); +}