cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <html>
<head>
    <title>Mithril dispatch</title>
    <script src="https://unpkg.com/mithril/mithril.js" type="text/javascript"></script>
    <style type="text/css">
        html,body {margin:0; padding: 0; font-family: sans-serif; box-sizing: border-box;}

        button {
            background: -moz-linear-gradient(top, rgba(59,103,158,1) 0%, rgba(43,136,217,1) 50%, rgba(32,124,202,1) 51%, rgba(125,185,232,1) 100%);
            background: -webkit-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%);
            background: linear-gradient(to bottom, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); 
            font-size: 20px;
            padding: 0.5rem 1rem;
            color: #fff;
        }

        nav {padding: 12px; background: #5696ff;}
        nav > a {margin: 0 8px; color: #fff; text-decoration: none;}
        img {max-width: 100px}
        main{margin: 1rem;}
        .deadCenter {position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
        section {display: flex; align-items: center; justify-content: space-between; padding: 5px;} section > * {height: 250px; background: #5696ff; margin: 5px; flex: 1; color: #fff;}
        ul {list-style: none; align-content: space-around; justify-content: space-between; margin: 0; padding: 5px; display: flex; flex-wrap: wrap;}
        li {flex: 1 0 50px; padding: 8px; margin: 5px; cursor: pointer; position: relative; background: #5696ff; font-size: 20px; color: #fff;}
        li:hover {background: #3356dd;}
    </style>
</head>
<body>
    <div id="root"></div>
</body>
</html>

            
          
!
            
              // Transpiled from https://github.com/zyrolasting/mithril-dispatch

(function(FuseBox){FuseBox.$fuse$=FuseBox;
FuseBox.pkg("default", {}, function(___scope___){
___scope___.file("demo/demo.js", function(exports, require, module, __filename, __dirname){

"use strict";
exports.__esModule = true;
var index_1 = require("~/index");
var state_1 = require("./state");
var views_1 = require("./views");
function loggedin(fn) {
    return function (state, task) {
        if (!state.user) {
            m.route.set('/login');
        }
        else {
            return fn(state, task);
        }
    };
}
index_1.dispatch(document.getElementById('root'), '/error', state_1["default"], {
    '/': function () { return views_1.Login; },
    '/login': function () { return views_1.Login; },
    '/error': function () { return views_1.ErrorReport; },
    '/:tenant/widgets': loggedin(function (app, task) {
        task(function () { return app.selectTenant(app.spaRequest.tenant); })
            .then(function () { return task(app.loadWidgetListing); })
            .then(function () {
            return Promise.race([
                task(function () { return app.computeAnalytics(0); }),
                task(function () { return app.computeAnalytics(1); }),
                task(function () { return app.computeAnalytics(2); }),
            ]);
        });
        return {
            layout: views_1.Layout,
            comp: views_1.WidgetsOverview
        };
    }),
    '/:tenant/widgets/:id': loggedin(function (app, task) {
        var _a = app.spaRequest, id = _a.id, tenant = _a.tenant;
        app.focusedWidget = null;
        task(function () { return app.selectTenant(app.spaRequest.tenant)
            .then(function () { return app.loadWidget(id); }); });
        return {
            layout: views_1.Layout,
            comp: views_1.WidgetDetail
        };
    })
});

});
___scope___.file("index.js", function(exports, require, module, __filename, __dirname){

"use strict";
exports.__esModule = true;
function dispatch(root, errorRoute, state, spec) {
    // shallow copy protects caller from key mutation
    var routesToFn = Object.assign({}, spec);
    if (typeof routesToFn[errorRoute] !== 'function') {
        throw new Error(errorRoute + " must be defined in your route table.");
    }
    // Mithril treats '' and '/' as distinct. End users don't.
    if (routesToFn['']) {
        throw new Error('Empty routes are not allowed. Use / to specify a root route.');
    }
    if (routesToFn[''] !== routesToFn['/']) {
        routesToFn[''] = routesToFn['/'];
    }
    function task(promiseFactory) {
        try {
            return promiseFactory().then(function () { return m.redraw(); })["catch"](function (err) {
                state.err = err;
                m.route.set(errorRoute);
            });
        }
        catch (err) {
            state.err = err;
            m.route.set(errorRoute);
        }
    }
    var layout;
    var table = Object.keys(routesToFn).reduce(function (wipTable, route) {
        wipTable[route] = {
            onmatch: function (args, pendingRoute) {
                state.spaRequest = Object.assign(args, { pendingRoute: pendingRoute });
                var compOrLayoutWithComp = routesToFn[route](state, task) || {};
                layout = compOrLayoutWithComp.layout;
                var comp = compOrLayoutWithComp.comp || compOrLayoutWithComp;
                return { view: function () { return m(comp, state); } };
            },
            render: function (vnode) {
                return (layout)
                    ? m(layout, state, vnode)
                    : vnode;
            }
        };
        return wipTable;
    }, {});
    m.route(root, errorRoute, table);
}
exports.dispatch = dispatch;

});
___scope___.file("demo/state.js", function(exports, require, module, __filename, __dirname){

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
exports.__esModule = true;
// Artificial delay used to showcase progressive loading indicators.
var delay = function (fn, ms) {
    if (ms === void 0) { ms = 500; }
    return new Promise(function (r) { return setTimeout(function () { return r(fn()); }, ms); });
};
var state = {
    user: null,
    err: null,
    tenant: '',
    widgets: null,
    layout: null,
    focusedWidget: '',
    loadAvailableTenants: function () {
        return (state.tenants)
            ? Promise.resolve()
            : delay(function () { return state.tenants = {
                funzzy: [false, false, false],
                flubber: [false, false, false],
                snafu: [false, false, false]
            }; });
    },
    computeAnalytics: function (index) {
        return (state.tenants[state.tenant][index])
            ? Promise.resolve()
            : delay(function () {
                state.tenants[state.tenant][index] = true;
            }, 1000 + Math.floor(10000 * Math.random()));
    },
    selectTenant: function (tenant) {
        return delay(function () { return state.tenant = tenant; }, 0);
    },
    loadWidgetListing: function () {
        return delay(function () { return state.widgets = 'abcdefghijklmnopqrstuvwxyz'.split(''); });
    },
    loadWidget: function (id) {
        return delay(function () { return state.focusedWidget = id; });
    },
    onboard: function () {
        state.tenants[state.tenant] = true;
        m.route.set("/" + state.tenant + "/widgets");
    },
    logIn: function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        state.user = 'Joe Schmoe';
                        return [4 /*yield*/, state.loadAvailableTenants()];
                    case 1:
                        _a.sent();
                        m.route.set("/" + Object.keys(state.tenants)[0] + "/widgets");
                        return [2 /*return*/];
                }
            });
        });
    }
};
exports["default"] = state;

});
___scope___.file("demo/views.js", function(exports, require, module, __filename, __dirname){

"use strict";
exports.__esModule = true;
var Spinny = {
    view: function (_a) {
        var children = _a.children;
        return m('.deadCenter', { style: { 'text-align': 'center' } }, m('h3', children));
    }
};
exports.Layout = {
    view: function (_a) {
        var _b = _a.attrs, tenants = _b.tenants, tenant = _b.tenant, children = _a.children;
        return m('div', m('nav', Object.keys(tenants).map(function (t, key) {
            return m('a', {
                key: key,
                href: "/" + t + "/widgets",
                style: "text-decoration: " + ((t === tenant) ? 'underline' : 'none'),
                oncreate: m.route.link,
                onupdate: m.route.link
            }, t);
        })), m('main', children));
    }
};
exports.Login = {
    view: function (_a) {
        var _b = _a.attrs, user = _b.user, logIn = _b.logIn;
        return (user)
            ? m(Spinny, 'Logging in...')
            : m('button.deadCenter', { onclick: logIn }, 'Log In');
    }
};
exports.WidgetsOverview = {
    view: function (_a) {
        var _b = _a.attrs, tenant = _b.tenant, tenants = _b.tenants, widgets = _b.widgets, analytics = _b.analytics;
        if (!tenant || !widgets) {
            return m(Spinny, 'Fetching listing...');
        }
        return [
            m('section', tenants[tenant].map(function (done) {
                return m('div', { style: 'position:relative' }, (done)
                    ? m('.deadCenter', 'Done')
                    : m(Spinny, "Crunching for " + tenant + "..."));
            })),
            m('ul', widgets.map(function (l, key) {
                return m('li', {
                    key: key,
                    onclick: function () { return m.route.set("/" + tenant + "/widgets/" + l); }
                }, tenant + ':' + l);
            })),
        ];
    }
};
exports.ErrorReport = {
    view: function (_a) {
        var err = _a.attrs.err;
        return m('pre', (err || new Error('404')).stack);
    }
};
exports.WidgetDetail = {
    view: function (_a) {
        var _b = _a.attrs, tenant = _b.tenant, focusedWidget = _b.focusedWidget;
        return m('p', (focusedWidget)
            ? "Widget " + focusedWidget + " for " + tenant
            : m(Spinny, 'Loading widget...'));
    }
};

});
return ___scope___.entry = "demo/demo.ts";
});
FuseBox.target = "universal"

FuseBox.import("default/demo/demo.js");
FuseBox.main("default/demo/demo.js");
})
(function(e){function r(e){var r=e.charCodeAt(0),n=e.charCodeAt(1);if((p||58!==n)&&(r>=97&&r<=122||64===r)){if(64===r){var t=e.split("/"),i=t.splice(2,t.length).join("/");return[t[0]+"/"+t[1],i||void 0]}var o=e.indexOf("/");if(o===-1)return[e];var a=e.substring(0,o),u=e.substring(o+1);return[a,u]}}function n(e){return e.substring(0,e.lastIndexOf("/"))||"./"}function t(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var n=[],t=0,i=arguments.length;t<i;t++)n=n.concat(arguments[t].split("/"));for(var o=[],t=0,i=n.length;t<i;t++){var a=n[t];a&&"."!==a&&(".."===a?o.pop():o.push(a))}return""===n[0]&&o.unshift(""),o.join("/")||(o.length?"/":".")}function i(e){var r=e.match(/\.(\w{1,})$/);return r&&r[1]?e:e+".js"}function o(e){if(p){var r,n=document,t=n.getElementsByTagName("head")[0];/\.css$/.test(e)?(r=n.createElement("link"),r.rel="stylesheet",r.type="text/css",r.href=e):(r=n.createElement("script"),r.type="text/javascript",r.src=e,r.async=!0),t.insertBefore(r,t.firstChild)}}function a(e,r){for(var n in e)e.hasOwnProperty(n)&&r(n,e[n])}function u(e){return{server:require(e)}}function f(e,n){var o=n.path||"./",a=n.pkg||"default",f=r(e);if(f&&(o="./",a=f[0],n.v&&n.v[a]&&(a=a+"@"+n.v[a]),e=f[1]),e)if(126===e.charCodeAt(0))e=e.slice(2,e.length),o="./";else if(!p&&(47===e.charCodeAt(0)||58===e.charCodeAt(1)))return u(e);var s=g[a];if(!s){if(p&&"electron"!==x.target)throw"Package not found "+a;return u(a+(e?"/"+e:""))}e=e?e:"./"+s.s.entry;var l,c=t(o,e),d=i(c),v=s.f[d];return!v&&d.indexOf("*")>-1&&(l=d),v||l||(d=t(c,"/","index.js"),v=s.f[d],v||"."!==c||(d=s.s&&s.s.entry||"index.js",v=s.f[d]),v||(d=c+".js",v=s.f[d]),v||(v=s.f[c+".jsx"]),v||(d=c+"/index.jsx",v=s.f[d])),{file:v,wildcard:l,pkgName:a,versions:s.v,filePath:c,validPath:d}}function s(e,r,n){if(void 0===n&&(n={}),!p)return r(/\.(js|json)$/.test(e)?v.require(e):"");if(n&&n.ajaxed===e)return console.error(e,"does not provide a module");var i=new XMLHttpRequest;i.onreadystatechange=function(){if(4==i.readyState)if(200==i.status){var n=i.getResponseHeader("Content-Type"),o=i.responseText;/json/.test(n)?o="module.exports = "+o:/javascript/.test(n)||(o="module.exports = "+JSON.stringify(o));var a=t("./",e);x.dynamic(a,o),r(x.import(e,{ajaxed:e}))}else console.error(e,"not found on request"),r(void 0)},i.open("GET",e,!0),i.send()}function l(e,r){var n=h[e];if(n)for(var t in n){var i=n[t].apply(null,r);if(i===!1)return!1}}function c(e,r){if(void 0===r&&(r={}),58===e.charCodeAt(4)||58===e.charCodeAt(5))return o(e);var t=f(e,r);if(t.server)return t.server;var i=t.file;if(t.wildcard){var a=new RegExp(t.wildcard.replace(/\*/g,"@").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&").replace(/@@/g,".*").replace(/@/g,"[a-z0-9$_-]+"),"i"),u=g[t.pkgName];if(u){var d={};for(var m in u.f)a.test(m)&&(d[m]=c(t.pkgName+"/"+m));return d}}if(!i){var h="function"==typeof r,x=l("async",[e,r]);if(x===!1)return;return s(e,function(e){return h?r(e):null},r)}var _=t.pkgName;if(i.locals&&i.locals.module)return i.locals.module.exports;var y=i.locals={},w=n(t.validPath);y.exports={},y.module={exports:y.exports},y.require=function(e,r){return c(e,{pkg:_,path:w,v:t.versions})},p||!v.require.main?y.require.main={filename:"./",paths:[]}:y.require.main=v.require.main;var j=[y.module.exports,y.require,y.module,t.validPath,w,_];return l("before-import",j),i.fn.apply(0,j),l("after-import",j),y.module.exports}if(e.FuseBox)return e.FuseBox;var d="undefined"!=typeof WorkerGlobalScope,p="undefined"!=typeof window&&window.navigator||d,v=p?d?{}:window:global;p&&(v.global=d?{}:window),e=p&&"undefined"==typeof __fbx__dnm__?e:module.exports;var m=p?d?{}:window.__fsbx__=window.__fsbx__||{}:v.$fsbx=v.$fsbx||{};p||(v.require=require);var g=m.p=m.p||{},h=m.e=m.e||{},x=function(){function r(){}return r.global=function(e,r){return void 0===r?v[e]:void(v[e]=r)},r.import=function(e,r){return c(e,r)},r.on=function(e,r){h[e]=h[e]||[],h[e].push(r)},r.exists=function(e){try{var r=f(e,{});return void 0!==r.file}catch(e){return!1}},r.remove=function(e){var r=f(e,{}),n=g[r.pkgName];n&&n.f[r.validPath]&&delete n.f[r.validPath]},r.main=function(e){return this.mainFile=e,r.import(e,{})},r.expose=function(r){var n=function(n){var t=r[n].alias,i=c(r[n].pkg);"*"===t?a(i,function(r,n){return e[r]=n}):"object"==typeof t?a(t,function(r,n){return e[n]=i[r]}):e[t]=i};for(var t in r)n(t)},r.dynamic=function(r,n,t){this.pkg(t&&t.pkg||"default",{},function(t){t.file(r,function(r,t,i,o,a){var u=new Function("__fbx__dnm__","exports","require","module","__filename","__dirname","__root__",n);u(!0,r,t,i,o,a,e)})})},r.flush=function(e){var r=g.default;for(var n in r.f)e&&!e(n)||delete r.f[n].locals},r.pkg=function(e,r,n){if(g[e])return n(g[e].s);var t=g[e]={};return t.f={},t.v=r,t.s={file:function(e,r){return t.f[e]={fn:r}}},n(t.s)},r.addPlugin=function(e){this.plugins.push(e)},r.packages=g,r.isBrowser=p,r.isServer=!p,r.plugins=[],r}();return p||(v.FuseBox=x),e.FuseBox=x}(this))
            
          
!
999px
Loading ..................

Console