JSFiddle - React, Tailwind, and code Playground

by nathan

JavaScript

var lib = (function () {
    "use strict";

    var writeableProperties = [
        'contentEditable',
        'id',
        'innerHTML',
        'style',
        'tabIndex',
        'textContent',
        'title'
    ];

    try {
        Object.defineProperty({}, 'prop', {
            get: noop(),
            set: noop()
        });
        lib.es5Props = true;
    } catch (e) {
        lib.es5Props = false;
    }
    try {
        ({}).__defineGetter__('prop', noop());
        ({}).__defineSetter__('prop', noop());
        lib.legacyGetSet = true;
    } catch (e) {
        lib.legacyGetSet = false;
    }

    lib.fn = Lib.prototype;
    return lib;

    function lib(nodelist) {
        if (!nodelist.hasOwnProperty('length')) {
            nodelist = [nodelist];
        }
        return new Lib(nodelist);
    }
    function Lib(nodelist) {
        var i;

        this.item = item;
        this.update = update;
        this.update();

        i = writeableProperties.length;
        while (i--) {
            carryHtmlProperty.call(this, writeableProperties[i]);
        }

        function item(n) {
            return nodelist[n];
        }
        function update() {
            var i = this.length = nodelist.length;
            while (i--) {
                this[i] = nodelist[i];
            }
        }
    }
    function carryHtmlProperty(prop) {
        Object.defineProperty(this, prop, {
            get : function () {
                this.item(0)[prop];
            },
            set : function (val) {
                this.forEach(function () {
                    this[prop] = val;
                });
            }
        });
    }
    function noop() {
        return function () {};
    }


}());

// Element retrieval methods

lib.querySelector = function (q) {
    return lib(document.querySelectorAll(q));
};
lib.querySelectorAll = lib.querySelector;

lib.getElementById = function (id) {
    return...