Giter VIP home page Giter VIP logo

table-roller's Introduction

table-roller

This is a simple custom element for wrapping existing table elements (i.e. vanilla HTML), to add rolling capabilities to them.

I wrote this primarely for my RPG blog, to add some interactivity to my random tables. Usually, when I add random tables to a blog post, I edit the HTML to add some Javascript to it, but after having done that a couple of times, I thought I might as well do some proper programming.

Example

See example.htm for some basic examples, with some of the attributes you can use as well for the <table-roller> element.

Otherwise, here's a simple example, using an existing table

<table>
  <tr>
    <td>1d4</td>
    <td>Thing</td>
    <td>Of</td>
    <td>What</td>
  </tr>
  <tr>
    <td>1</td>
    <td>Sword</td>
    <td>with</td>
    <td>teeth</td>
  </tr>
  <tr>
    <td>2</td>
    <td>Axe</td>
    <td>from</td>
    <td>newt</td>
  </tr>
  <tr>
    <td>3</td>
    <td>Dagger</td>
    <td>of</td>
    <td>dullness</td>
  </tr>
  <tr>
    <td>4</td>
    <td>Fork</td>
    <td>of</td>
    <td>truth</td>
  </tr>
</table>

(In the example file, I call the first column for a "dice column". I believe there are better and more accurate words for it, but that's where we are now.)

By wrapping this table with <table-roller>, two buttons will appear beneath the table: Roll, and Clear.

<table-roller>
  <table>
    ...same as above...
  </table>
</table-roller>

And that's pretty much everything needed for this kind of table; the table-roller element defaults to this kind of layout (e.g. with headers and a "dice column"), but if your table for instance lacks a dice column, there are attributes that you can provide to the table-roller to ignore that.

How to use

I wanted to keep this little element as simple as possible, so there are no exeternal dependencies at all (it's just plain ECMAScript 6 e.g. ES6, with a class).

All you need to do is include the script table-roller.js in someway. Since the <table-roller> element is a custom element, nothing happens if - for some reason - the script can't be loaded (e.g. the page won't break).

Including the script can be done in multiple ways:

  • Include the entirety of the script file in your blog post, inside a script <script> tag
    • E.g. <script>(...full contents of table-roller.js here...)</script>
  • Download the file and host it yourself somewhere, and include with a <script> tag:
    • <script async defer src="(...your url...)/table-roller.js"></script>

Minified version

The file table-roller.min.js is a minified version of the same file, using Google Closure Compiler.

If you want to minify locally, you need to download the Google Closure Compiler JAR-file from the Maven repository, rename it to closure-compiler.jar, and then run minify.sh.

table-roller's People

Contributors

groffa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.