JSFiddle - React, Tailwind, and code Playground

by vince

HTML

<div id="section" class="section">
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>

CSS

.no-select ::-webkit-selection { background: transparent none repeat scroll 0 0; }
.no-select ::-moz-selection { background: transparent none repeat scroll 0 0; }
.no-select ::-o-selection { background: transparent none repeat scroll 0 0; }
.no-select ::-ms-selection { background: transparent none repeat scroll 0 0; }
.no-select ::selection { background: transparent none repeat scroll 0 0; }

JavaScript

// Prevents the user from selecting entire block of text on a triple click
// This Fiddle supports the StackOverflow topic here http://stackoverflow.com/questions/7081438/

function clearSelection() {
    var sel;
    if (document.selection && document.selection.empty) {
        document.selection.empty();
    } else if (window.getSelection) {
        sel = window.getSelection();
        if (sel && sel.removeAllRanges) {
            sel.removeAllRanges();
        }
    }
}


var obj = document.getElementById("section");
obj.addEventListener("click", function(e) { // listen for click
    if (e.detail) {
        if (e.detail === 1) { // if this is the first click
            obj.className = ""; // reset the class name
        } else if (e.detail > 1) { // if this is the 2nd click
            obj.className = "no-select"; // add no-select
        } else if (e.detail > 2) { // if more than 2 clicks
            clearSelection(e); // remove all selections
        }

    }
}, false);