JSFiddle - React, Tailwind, and code Playground

by mqchen

HTML

<div class="reactions formline">
    <label>Reaksjoner</label>
    <div class="tools">
        <label>Kontrollspørsmål</label>
        <div class="buttonbar">
            <button class="activebutton" data-react-role="showallktrspm">Vis alle</button>
            <button class="" data-react-role="hideallktrspm">Skjul alle</button>
        </div>
        <div class="buttonbar">
            <button class="icon" data-icon="&#x004d;" data-react-role="expandallktrspm">Expand all</button>
            <button class="icon" data-icon="&#x005e;" data-react-role="collapseallktrspm">Collapse all</button>
        </div>
    </div>
    <div class="fields">
        <div class="paleggsection">
            <div class="palegg" data-react-role="palegg">
                <span class="type icon-b" data-icon="&#x0022;">Pålegg</span>
                <p class="paleggtext icon-b" data-icon="&#x0058">Skolens styre må sørge for at reglementet bare inneholder regler for prioritering ut fra saklige hensyn jf. privatskoleloven § 3-1 tredje ledd annet punktum.</p>
            </div>
            <div class="ktrspm ktrspmshow" data-react-role="ktrspm">
                <div class="ktrspmcontainer">
                    <h2 class="ktrspmtitle">
                        <a href="#" class="icon-b" data-icon="&#x00a3;" data-react-role="ktrspmtoggle">Utfører skolen konkurranser?</a>
                    </h2>
                    <div class="assessment">
                        <div class="buttonbar" data-buttonvalue-target="ktrspm0">
                            <button class="icon" data-icon="&#x004a;" value="thumbsup">Ingen funn</button>
                            <button class="icon" data-icon="&#x006a;" value="thumbsdown">Bekymrende</button>
                            <button class="icon" data-icon="&#x002f;" value="irrelevant">Irrelevant</button>
                        </div>
                    </div>
                    <input type="hidden" name="ktrspm0" data-react-role="assessmentdata" value=""...

CSS

body {
    padding: 40px;
    font-family: Arial, sans-serif;
}

/** Icons */
@font-face {
    font-family: 'Entypo';
    src: url('https://dl.dropbox.com/s/uydr0f8lcx81brq/entypo-webfont.woff?dl=1') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'IcoMoon';
    src: url('https://dl.dropbox.com/s/gfwrdxu3asuhiel/IcoMoon.woff?dl=1') format('woff');
    font-weight: normal;
    font-style: normal;
}

.icon-b, .icon-a, .icon {
    position: relative;
}
.icon-b:before, .icon-a:after, .icon:after {
    text-indent: 0;
    text-transform: none;
    font-weight: normal;
    content: attr(data-icon);
    font-family: 'IcoMoon';
    line-height: inherit;
    position: absolute;
    display: block;
    top: 50%;
    margin: -20% 0 0 0;
}
.icon-b {
    padding-left: 28px;
}
.icon-b:before {
    left: 10px;
}
.icon-a {
    padding-right: 28px;
}
.icon-a:after {
    right: 10px;
}
.icon {
    text-indent: -999px;
    overflow: hidden;
}
.icon:after {
    left: 10px;
}

/** Entypo */
.icon-entypo.icon-b:before, .icon-entypo.icon-a:after, .icon-entypo.icon:after {
    font-family: 'Entypo';
    margin: -45% 0 0 0;
}
button.icon-entypo.icon-b:before, button.icon-entypo.icon-a:after, button.icon-entypo.icon:after {
    font-size: 2em;
}

/** IcoMoon */
.icon-icomoon.icon-b:before, .icon-icomoon.icon-a:after, .icon-icomoon.icon:after {
    font-family: 'IcoMoon';
    margin: -20% 0 0 0;
}



/** Button bar */
.buttonbar {
    float: left;
    margin: 0 10px 20px 10px;
}

.buttonbar button {
    border-radius: 0;
    position: relative;
    margin-left: -1px;
    white-space: nowrap;
}
.buttonbar button:first-child,
.buttonbar button.visiblebutton {
    -webkit-border-top-left-radius: 3px;
    -webkit-border-bottom-left-radius: 3px;
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
}
.buttonbar button:last-child,
.buttonbar button.visiblebutton {
    -webkit-border-top-right-radius: 3px;
   ...

JavaScript

if(Udir === undefined) {
    var Udir = {};
}

Udir.mediator = function () {
    var ctor = function () {

        var getEventName = function (key, type) {
            if (key) return key + "_" + type;
            return type;
        };
        this.handlers = [];

        this.register = function (type, handler) {
            trace("Listener added to " + type);
            var name = (type);
            this.handlers[name] = this.handlers[name] || [];
            this.handlers[name].push(handler);
        };

        this.registerWithKey = function (key, type, handler) {
            return this.register(getEventName(key, type), handler);
        };

        this.handle = function (type, data) {
            if (!this.handlers[type]) {
                trace("Event " + type + " raised, but no one is listening.");
                return false;
            }
            var count = this.handlers[type].length;
            trace("Event " + type + " raised for " + count + " listeners.");
            for (var i = 0; i < count; i++) {
                if (this.handlers[type][i] != null)
                    this.handlers[type][i](data);
            }
            return count;
        };
        this.handleWithKey = function (key, type, data) {
            return this.handle(getEventName(key, type), data);
        };
        this.startTrace = function (doTrace) {
            traceFunc = doTrace;
            if (doTrace) trace("Trace started.");
        };

        var traceFunc;
        var trace = function (msg) {
            if (traceFunc) {
                if (typeof traceFunc === "function") {
                    traceFunc(msg);
                } else if (console) {
                    console.log(msg);
                }
            }
        };

        return this;
    };
    var mediator = new ctor();
    mediator.create = function () { return new ctor(); };
    return mediator;
} ();


Udir.buttonValueSetter = function(b, o) {
    var options = {
        "eventNS"...