https://github.com/buren/poller
Client for poller-server.
https://github.com/buren/poller
Last synced: 7 months ago
JSON representation
Client for poller-server.
- Host: GitHub
- URL: https://github.com/buren/poller
- Owner: buren
- License: mit
- Created: 2015-10-11T12:03:49.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-12-02T09:11:25.000Z (almost 4 years ago)
- Last Synced: 2025-01-20T04:19:03.831Z (9 months ago)
- Language: JavaScript
- Size: 449 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Poller
Deploy [poller-server](https://github.com/buren/poller-server), in less than 2 minutes, to Heroku with one click.
[Poller](https://github.com/buren/poller#getting-started), get started with a couple of lines of HTML.
## Getting started
```html
var yourPollerServerUrl = 'https://throwawaypoll.herokuapp.com';
PollerConfig = { url: yourPollerServerUrl };```
If you want to use the HTML integration, add
```html```
## HTML
Create a poll that can be answered multiple times and display a Bar chart beneath that updates every 2 seconds.
```html
What do you think about the weather today?
Love it
Hate it
Indifferent
```__Answer__:
Any element can be used for the answer, the only thing required is to add a `data-answer` attribute. `Poller` then listens to the elements click event and will prevent default element behavior.
All of the below are valid
```html
```Points answers (x/y)
```html
Whats your name and age?
Submit
```You'll need to add a `data-points` attribute to the root poller element and `data-submit` to the element you want to have as a submit trigger.
__Chart__:
Simplest example
```html
```Refresh chart every 2 seconds
```html
```Render as line chart
```html
```_Available chart types_: Line, Pie, Column, Bar, Area, Scatter, Geo.
By default it will render a Column chart.
__Options__:
You can put components together how you like
```html
Answer
Answer 1
Answer 2
```Answers put in separate a `data-poller` will each be answerable once.
PollerConfig:
```js
var serverUrl = 'https://throwawaypoll.herokuapp.com';
PollerConfig = {
url: serverUrl, // Required: Server URL
onReady: true, // By default initialize HTML components on document ready
multiVote: false, // By default multiple votes is not allowed
voted: false // By default the user is assumed not to have voted
};
```Manually initialize PollerDOM components:
```js
PollerDOM.createAll();
```### JavaScript
If you don't want to use the HTML integration you can interact with the Poller server directly.
Simple poll
```js
var poller = new Poller({id: 'weather'});poll.submit('First answer'); // Submit answer
// By default only one submit is allowed, the rest will be ignored
poll.submit('First answer'); // Ignored
poll.result(function(result) {
console.log(result['First answer']); // 1
});
```Multi vote poll
```js
var poller = new Poller({id: 'weather', multiVote: true});poll.submit('First answer'); // Submit answer
poll.submit('First answer'); // Submit answer
poll.result(function(result) {
console.log(result['First answer']); // 2
});
```x/y poll
```js
var opts = {
id: 'person',
points: true, // It's a x/y form
multiVote: true
};
var poll = new Poller(opts);poll.submit({x: 'buren', y: 26}); // Submit answer
poll.submit({x: 'constance', y: 24}); // Submit answer// Get result
poll.result(function(result) {
console.log(result); // [['buren', '26'], ['constance', '24']]
});
```Enable Debug logger
```js
__POLLER__DEBUG__ = true;
```## License
[MIT-LICENSE](LICENSE)