GithubHelp home page GithubHelp logo

emreimamoglu / poll-widget Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.35 MB

Poll Widget is an embeddable Javascript widget for creating polls.

TypeScript 0.36% JavaScript 0.11% CSS 96.64% HTML 1.24% SCSS 1.66%

poll-widget's Introduction

Embeddable Poll Widget

is a zero dependency lightweight poll widget. For more complex projects, lite frameworks like preact can be used. But it will increase the bundle size to 30+ kb which is around 2kb right now.

Demo

You can preview the widget by visiting following link

https://poll-widget.web.app/

Usage via CDN

refer this link for live usage : https://github.com/emreimamoglu/poll-widget/blob/main/demo2/index.html#L564-L591

<script>
// Initialization script
 (function (w, d, s, o, f, js, fjs) {
        w["PollManager"] = o;
        w[o] =
          w[o] ||
          function () {
            (w[o].q = w[o].q || []).push(arguments);
          };
        (js = d.createElement(s)), (fjs = d.getElementsByTagName(s)[0]);
        js.id = o;
        js.src = f;
        js.async = 1;
        js.type = "module"
        fjs.parentNode.insertBefore(js, fjs);
      })(window, document, "script", "pw", "https://unpkg.com/@emreimamoglu/[email protected]/dist/poll-widget.js");
      pw("init");


      pw("createpoll",{
        id : "poll-1",
        question : "What is your favorite color?",
        options : ["Red","Blue","Green"],
        element : document.getElementById("poll-container-1") // container that will render the poll
      })
</script>

Run Locally

Clone the project

  git clone https://github.com/emreimamoglu/poll-widget.git

Go to the project directory

  cd poll-widget

Install dependencies

  npm install

  or

  yarn

Build the project

  npm run build

  or 

  yarn build

after this step, you can visit the demo folders and launch index.html files to see widget in action.

API Reference

Initialize widget

  init

  pw("init")
Parameter Type Description

createpoll

  createpoll

  mw("createpoll", {
      id : "poll-id",
      question : "poll question",
      options : ["option 1", "option 2", "option 3",...],
      element : document.getElementById("container-id-to-host-poll")
  })
Parameter Type Description
id string Required. Id of the poll
question string Required. Poll question
options string[] Required. Poll answer options
element DOMNode Required. Poll host node

Running Tests

Embeddable poll widget uses vitest for unit tests.

To run the tests :

  npm run test

poll-widget's People

Contributors

emreimamoglu 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.