Git Product home page Git Product logo

eustia-component's Introduction

eustia-component

Eustia plugin for translating html.

Note that this has nothing to do with web commponent, just provides an easy way to write eustia module with html and css.

Installation

npm install eustia-component

Usage

module.exports = {
    util: {
        files: 'index.html',
        extension: ['js', 'html'],
        transpiler: [
            {
                test: /\.html$/,
                handler: require('eustia-component')()
            }
        ]
    }
};

How it Works

It translates html format into pure javascript for later usage.

Source Html

<style>
    #msg-container {
        position: fixed;
        background: #ccc;
        top: 15px;
        left: 50%;
        width: 500px;
        margin-left: -250px;
        padding: 10px 0;
        text-align: center;
        border-radius: 5px;
        box-shadow: 0 0 2px rgba(0,0,0,.175);
        border: 1px solid #ccc;
    }
    #msg-container .content {
        color: #fff;
        font-size: 18px;
        font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    }
    #msg-container.hidden {
        display: none;
    }
</style>

<require>$insert $class $property $css evalCss defaults</require>

<template id="msgContainer">
    <div id="msg-container" class="hidden">
        <div class="content">Hello world!</div>
    </div>
</template>

<script>
var initialized = false;

function init()
{
    $insert.append('body', msgContainer);
    evalCss(style);

    initialized = true;
}

var defOpts = {
    duration: 3000,
    background: '#9e3c2f',
    delay: 0
};

function showMsg(str, options)
{
    $property.text('#msg-container .content', str);
    $class.remove('#msg-container', 'hidden');
    $css('#msg-container', 'background', options.background);

    if (options.duration === 0) return;

    setTimeout(function ()
    {
        $class.add('#msg-container', 'hidden');
    }, options.duration);
}

msg = function (str, options)
{
    options = options || {};
    defaults(options, defOpts);

    if (!initialized) init();

    setTimeout(function ()
    {
        showMsg(str, options);
    }, options.delay);

};
</script>

Generated Javascript

var style = ' #msg-container { position: fixed; background: #ccc; top: 15px; left: 50%; width: 500px; margin-left: -250px; padding: 10px 0; text-align: center; border-radius: 5px; box-shadow: 0 0 2px rgba(0,0,0,.175); border: 1px solid #ccc; } #msg-container .content { color: #fff; font-size: 18px; font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif; } #msg-container.hidden { display: none; }';

var msgContainer = '<div id=\"msg-container\" class=\"hidden\"> <div class=\"content\">Hello world!</div> </div>';

var initialized = false;

function init()
{
    $insert.append('body', msgContainer);
    evalCss(style);

    initialized = true;
}

var defOpts = {
    duration: 3000,
    background: '#9e3c2f',
    delay: 0
};

function showMsg(str, options)
{
    $property.text('#msg-container .content', str);
    $class.remove('#msg-container', 'hidden');
    $css('#msg-container', 'background', options.background);

    if (options.duration === 0) return;

    setTimeout(function ()
    {
        $class.add('#msg-container', 'hidden');
    }, options.duration);
}

msg = function (str, options)
{
    options = options || {};
    defaults(options, defOpts);

    if (!initialized) init();

    setTimeout(function ()
    {
        showMsg(str, options);
    }, options.delay);

};

eustia-component's People

Contributors

surunzi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.