Coder Social home page Coder Social logo

adlerjs's Introduction

AdlerJS

Adler is a simple HTML composable element system

Installation

Add a script tag in your HTML file

import createAdler from "./vendor/adler.js";

Usage

Create a template to be loaded in your main HTML document

var button =createAdler({
    content: p => `<button class="action1 adlerButton">${p.test} world</button><p class="action2">${p.test2} here</p>`,
    params:{
        data:{
            test:"Hello",
            test2:"click",
        },
        on:[
            [".action1","click", (event, data)=> alert("test "+ data.test)],
            [".action2","click", (event, data, instance)=> instance.setData({test:"barr"}) ],
        ]
    },
    css:`
        .adlerButton {
            background-color: blue;
            padding: 5px;
            border: none;
            color: white;
            margin: 3px;
        }
    `,
})
button.mount()

Components can be used in other Adler components as such

var hw =createAdler({
    content: p => `
        <p class="action1">${p.test} world</p>
        <p class="action2">hoover area</p>
        <div a-if="seen" adler="button" class="myAdlerButton"></div>
        <div data-test="ola" a-sync="test2:testSync" adler="button" class="myAdlerButton"></div>
        <div>A list comes here</div>
        <div>
            <div a-for="list" adler="button" class="myAdlerlist"></div>
        </div>
        <div>A controlable element comes here</div>
        <div>
            <div a-id="controlable" adler="button" class="myAdlerlist"></div>
        </div>
        <div>mount area comes here</div>
        <div>
            <div a-slot="mountPoint"></div>
        </div>
        `
        ,
    params:{
        data:{
            test:"Hello",
            testSync:"push",
            seen:true,
            list:[{test:"un"}, {test:"deux"}, {test:"trois"} ]
        },
        on:[
            [".action1","click", (event, data)=> alert("test "+ data.test)],
            [".action2","click", (event, data, instance)=> instance.setData({test:"barr"}) ],
        ]
    },
    components:{
        button: button
    }
})
hw.mount()

You can access a specific node by tagging it with a specific ID and using the following methods

console.log(hw.getNodes());
hw.getNodes().controlable.setData({test:"desdkosefsmelfesml"})
hw.getNodes().controlable.getData({test:"desdkosefsmelfesml"})

hw.setData({test:"foo", seen:false})

You can create mount points (slots) in the templates to dynamicaly mount another component and prevent it to be discarded on reload and upadates

hw.append(button.instance(),"mountPoint")
hw.clearSlot("mountPoint") //removing

Roadmap to 0.3

  • Add check and error message during import process.
  • Clean unused code

adlerjs's People

Contributors

shuart avatar

Watchers

 avatar

adlerjs's Issues

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.