Git Product home page Git Product logo

yombal-dom's Introduction

Yombal DOM

yombal-dom

A small extension adding methods to Elements and Document Object to write less code and do more.

Methods

Document Object

  • Document.createElementWithAttributes()
    Crée un nouvel élément avec des attributs.
    • params :
      1. tag ex: h1
      2. attributes (sous forme de paire key/value) ex : {'class':'btn', 'value':'send'}
  • Document.createElementWithText()
    Crée un nouvel élément avec du text.
    • params :
      1. tag ex: p
      2. textContent ex: "Lorem ipsum dolor, sit amet consectetur adipisicing elit. Itaque, debitis?"
  • Document.createElementWithChilds()
    Crée un nouvel élément avec des fils.
    • params :
      1. tag ex: form
      2. childs (list of element) ex : [input, button]
  • Document.createElementFromTemplate()
    Crée un nouvel élément depuis un template
    • params :
      1. idTemplate
      2. data as object
      • usage
        1. in html file :
        <template id="cardTemplate">
            <div class="card">
                <h1> {{ title }} </h1>
                <p> {{ content }} </p>
            </div>
        </template>
        1. in javascript file:
         let element = document.createElementFromTemplate("cardTemplate", {
            title: "the title",
            content: "the content"
        })
        • the returning element :
            <div class="card">
                <h1> the title </h1>
                <p> the content </p>
            </div>

Element Object

Element hérite des méthodes fournit par la classe parente Node et de sa classe parente avant elle : EventTarget.

  • Element.setAttributes()
    Définit les valeurs des attribut nommés pour le nœud courant.
    • params :
      1. paire key/value des attributs. ex : {'class':'btn', 'value':'send'}
  • Element.appendChilds()
    Ajoute les enfants spécifiés en argument comme enfant au noeud actuel.
    • params :
      1. childs (list of element) ex : [input, button]
  • Element.toggleClass()
    Ajoute ou supprime une classe (basculement)
    • params :
      1. value of class
  • Element.replaceMustachWithObjectValues()
    Ajoute ou supprime une classe (basculement)
    • params :
      • usage
        1. in html file :
        <div id="card">
            <h1> {{ title }} </h1>
            <p> {{ content }} </p>
        </div>
        1. in javascript file:
         let card = _("#card");
         card.replaceMustachWithObjectValues({
            title: "un titre",
            content: "Un contenu des.."
        })
        • result :
        <div class="card">
            <h1> un titre </h1>
            <p> Un contenu des.. </p>
        </div>
        

Shortcut

  • _ to select element like document.querySelector
  • __ to select element like document.querySelectorAll
  • $() like EventTarget.addEventListener()
    Enregistre un gestionnaire d'événements d'un type d'événement spécifique sur EventTarget.
    • params :
      1. target(or element)
      2. l'evenement
      3. L'objet qui recevra un évènement lorsqu'un évènement du type spécifié se produit. ex : callback function
      4. [option]

Guide 📥

Over a CDN

insert <script src="https://unpkg.com/[email protected]/utils.js" crossorigin="anonymous"></script> in head tag

Via NPM

  1. npm i yombal-dom
  2. insert <script src="node_modules/yombal-dom/utils.js"></script> in head tag before any script

Via GIT

  1. git clone https://github.com/honorableCon/yombal-dom.git
  2. copy utils.js to your project directory
  3. insert <script src="utils.js"></script> in head tag before any script

eNJOY !

Auteur

Created by Honorable Con, M.E.R.N Stack developer

Contribution

New methods suggestion or more.. You can tell me here or pull request.

License

This project is under the GPL V3 License

Jaajeuf! 🙏🏾

yombal-dom's People

Contributors

honorablecon avatar daoodaba975 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.