JSFiddle - React, Tailwind, and code Playground

by mqchen

HTML

<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<div class="reactions formline">
    <label>Reaksjoner</label>
    <div class="tools">
        <label>Kontrollspørsmål</label>
        <div class="buttonbar">
            <button class="activebutton">Vis alle</button>
            <button class="">Skjul alle</button>
        </div>
    </div>
    <div class="fields">
        <div class="paleggsection">
            <div class="palegg" data-analysisreact-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-analysisreact-role="ktrspm">
                <div class="ktrspmcontainer">
                    <h2 class="ktrspmtitle">
                        <a href="#" class="icon-b" data-icon="&#x00a3;" data-analysisreact-role="ktrspmtoggle">Utfører skolen konkurranser?</a>
                    </h2>
                    <div class="assessment">
                        <div class="buttonbar">
                            <button class="icon" data-icon="&#x004a;" data-analysisreact-role="thumbsup" value="0">Ingen funn</button>
                            <button class="icon" data-icon="&#x006a;" data-analysisreact-role="thumbsdown" value="1">Bekymrende</button>
                            <button class="icon" data-icon="&#x002f;" data-analysisreact-role="irrelevant" value="2">Irrelevant</button>
                        </div>
                        <input type="hidden" data-analyisreact-role="assessmentdata" />
                    </div>
                    
                    <p class="ktrspmdesc">
                        Første: En lengre beskrivelse av kontrollspørsmålet kommer her. Feks. så...

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.buttonValueSetter = function(b, o) {
    var options = {
        "eventNS" : ".buttonvalue",
        "targetAttr" : "data-buttonvalue-target",
        "valueAttr" : "value",
        "buttonSelector" : "button",
        "activeClass" : "activebutton"
    };
    var buttonbar = null;
    var buttons = [];
    var target = null;

    var methods = {
        init : function(bb, opt) {
            $.extend(true, options, opt);
            
            var buttonbar = $(bb);
            
            // Get target
            var targetStr = buttonbar.attr(options.targetAttr);
            target = $("[name='" + targetStr + "']");
            
            // Get buttons
            buttons = $(options.buttonSelector, buttonbar);
            
            // Add events to buttons
            methods._addEvents();
            
            // Set initial value
            methods._processTargetValue();
        },
        
        _addEvents : function() {
            buttons.each(function(index, button) {
                var $button = $(button);
                
                $button.bind("click" + options.eventNS, function(e) {
                    e.preventDefault();
                    var buttonValue = $button.attr(options.valueAttr);
                    methods.setValue(buttonValue);
                });
            });
            
            // Listen to changes in target
            target.bind("change" + options.eventNS, methods._processTargetValue);
            target.bind("keyup" + options.eventNS, methods._processTargetValue);
        },
        
        _processTargetValue : function() {
            var initValue = target.val();
            methods.setValue(initValue);
        },
        
        
        setValue : function(value) {
            // Get button which matches this value
            buttons.each(function(index, button) {
                var $button = $(button);
               ...