JSFiddle - React, Tailwind, and code Playground

by tcloninger

HTML

<div style="position:absolute;top:10px;right:4px;bottom:4px;left:22px;overflow-y:scroll;border:#ccc 1px solid;padding:10px;">
        <table>
            <colgroup>
                <col style="width:72px;">
                <col style="width:100%;">
                <col style="width:100px;">
                <col style="width:100px;">
                <col style="width:100px;">
            </colgroup>
            <thead>
                <tr>
                    <th></th>
                    <th>Organisation Title</th>
                    <th>Other Data</th>
                    <th>Other Data</th>
                    <th>Other Data</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <a class="buildMenu" data-id="organisation-options-201" style="cursor:pointer;">
                            Menu
                        </a>
                    </td>
                    <td>
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                    </td>
                    <td>
                        Data
                    </td>
                    <td>
                        Data
                    </td>
                    <td>
                        Data
                    </td>
                </tr>
                <tr>
                    <td>
                        <a class="buildMenu" data-id="organisation-options-202" style="cursor:pointer;">
                            Menu
                        </a>
                    </td>
                    <td>
      ...

CSS

* { margin: 0; padding: 0; list-style:none; }
            div.menu { width:300px; background:#ccc; padding: 5px; }
            div.menu.loading { background: red; }
            .buildMenu { display: inline-block; padding:0 5px; line-height: 32px; }
            .buildMenu.selected { background:#ccc; color: red; }
            body { overflow: hidden; }
            table
            {
                width: 100%;
                table-layout: fixed;
            }
            th
            {
                padding: 5px;
                text-align: left;
                background: #ccc;
            }
            td
            {
                padding: 5px;
                text-align: left;
                background: #eee;
            }

JavaScript

$(document).ready(function() {

    
    $('a.buildMenu').click(function(event) {

        // Prevent normal behaviour
        event.preventDefault();

        // Stops it bubbling to the document
        event.stopPropagation();

        var link = $(this);

        // If the menu already exists remove it and exit the request
        if ($(document).find('div#' + $(link).data('id')).length) {
            $('.buildMenu').removeClass('selected');
            $('.menu').remove();
            return false;
        }

        // Remove any other menus from the DOM
        $('.buildMenu').removeClass('selected');
        $('.menu').remove();

        // Get the position of the link
        var offset = link.offset();
        var top = offset.top;
        var left = offset.left;
        var bottom = top + link.height();
        var right = $(window).width() - link.width();

        top = top + link.height();

        bottom = bottom + link.height();

        // Append the menu to the DOM in position
        var menuInstance = $('<div class="menu loading">loading...</div>').appendTo('body').css({
            'position': 'absolute',
            'top': top,
            'left': left
        });

        // Add the instance id
        $(menuInstance).attr('id', $(link).data('id'));

        // Add class of selected to clicked link
        $(this).addClass('selected');

        // Request JSON data        
        data = {"menu": {"id": "organisation-201","class": "list","content": {"menuitem": [{"text": "New Journal Entry","title": "New Journal Entry","href": "/Organisations/201/NewJournalEntry","liClass": "","icon": "icon test"},{"text": "View People","title": "View People","href": "/Organisations/201/People","liClass": "","icon": "icon test"},{"text": "View People","title": "View People","href": "/Organisations/201/People","liClass": "","icon": "icon test"},{"text": "View People","title": "View People","href": "/Organisations/201/People","liClass": "","icon": "icon...