Giter Site home page Giter Site logo

configjs's Introduction

configjs

A javascript configuration library.
You run things like addNumber("Image width",callback,5) and it will make an HTML number input element with a label that says "Image width: ", a callback and a value of 5.
You can then do setPropertyValue("Image width",7) and updateNumber("Image width") and it will update the input element's value.

Demo

<body>
    <h1>hello</h1>
    <div id="config"></div>
</body>
let coolNumber = 5;

// This will create an <input type="number"> element in the config <div>
// The callback function makes sure that the value is a valid number, and then sets coolValue to the value
addNumber("Cool number",(ev)=>{
    let value = parseFloat(ev.target.value);
    if (value != NaN) {
        coolNumber = value;
    }
},coolNumber, 0.5); // The last 2 arguments are the current value and the step size for the input element

addLineBreak();

// This makes a button with an onclick callback
addButton("Do some math",(ev)=>{
    alert(`Here's a different number: ${coolNumber*2 + 5}`);
})

Features

  • Variable types:
    • Numbers
    • Lists (textarea with JSON encoded lists, could possibly be used for non-list things)
    • Booleans (checkboxes)
    • Choices (Dropdown box)
  • Buttons
  • Non-input things:
    • Line breaks (<br>)
    • Seperators (<hr>)
    • Labels (<p>, probably should be called something else to avoid confusion with <label>)
      • Can be used to display a variable

Plans

  • Make the whole script into a class so you can have multiple config areas and to avoid variable name conflicts
  • Add custom attributes to the addXYZ() functions
    • You could set a certain element to have a certain class
  • Use identifiers for accessing properties, and have seperate "display names" be displayed (ex. image-width instead of Image width)
    • This would also let you set the identifier as the element's ID, for better accesability
  • Put each property in it's own <div> or other container
  • The ability to delete properties and their elements (becomes much easier with the last thing because you only need to delete the container)
  • Add more variable types
    • Strings, colors, dates
  • Put the callback argument at the end of each addXYZ() function instead of the second element
  • Publish to NPM and/or some other CDN. (Using GitHub Pages is probably a bad idea)

configjs's People

Contributors

calsch avatar

Watchers

 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.