v1.0.0

Polls

A lightweight, client-side voting widget: define a poll, render it into a container, and let visitors click to vote. Results are stored per-browser.

πŸ’‘ Site-only module. onigiri-polls.js ships with this documentation site (in static/js/), not the core framework repository.
Client-side only. Votes are stored in Onigiri.storage (falling back to nothing if unavailable) - they live in the visitor's own browser, not on a server. Two different visitors voting on the "same" poll do not see each other's votes, and votes are not tamper-proof against someone editing their own browser storage. For a real, shared voting feature, use this as the front-end and wire vote()/getResults() up to your own backend.

Quick Start

1. Include the Module

<script src="/static/js/onigiri-storage.js"></script>
<script src="/static/js/onigiri-polls.js"></script>

onigiri-storage.js is optional but recommended - without it, votes reset on every page load.

2. Add a Container

<div data-poll="favorite-feature"></div>

3. Create and Mount the Poll

Onigiri.polls.init();

Onigiri.polls.create('favorite-feature', {
    question: 'Which feature should we build next?',
    options: [
        { id: 'directives', label: 'Declarative directives' },
        { id: 'state', label: 'Shared state management' },
        { id: 'resource', label: 'REST resource models' }
    ]
});

Onigiri.polls.mount('favorite-feature');
βœ… That's it! Clicking an option casts a vote and re-renders the poll with live percentages.

API Reference

Configuration Options

OptionTypeDefaultDescription
storageKeyString'onigiri_poll_votes'Storage key used to persist votes
animationDurationNumber300Reserved for future use
allowMultipleVotesBooleanfalseAllow the same browser to vote more than once
showResultsBooleantrueReserved for future use - results currently always show once a vote is cast

Methods

Onigiri.polls.init(options)

Merges config, loads any previously stored votes, and binds a delegated click handler for .poll-vote-btn elements.

Onigiri.polls.create(id, options)

Registers a poll definition. options.options is an array of { id, label } objects.

Onigiri.polls.mount(id)

Renders the poll into the matching [data-poll="id"] container.

Onigiri.polls.vote(pollId, optionId)

Casts a vote. Returns false without recording anything if the poll doesn't exist or the visitor has already voted and allowMultipleVotes is off. Normally you won't call this directly - clicking a rendered option button does it for you.

Onigiri.polls.getResults(pollId)

Returns { total, options: [{ id, label, votes, percentage }] }, sorted by vote count descending.

Events

EventFired when
onigiri:poll:votedA vote is cast (detail: { pollId, optionId })

Security Notes

  • Poll questions and option labels are HTML-escaped before rendering (via Onigiri.security.sanitizeHTML when loaded). If you build poll definitions from a CMS field or translation file, this keeps an edited string from injecting markup.
  • Because voting is entirely client-side, treat results as informal/anecdotal rather than authoritative - see the note above.

βœ… Development Roadmap

Track the progress of OnigiriJS modules. Tasks are marked complete by the development team.

OnigiriJS Module Roadmap

Implementation progress of planned modules

6 / 21 completed (29%)
onigiri-state
Shared global & scoped state management
onigiri-directives
Declarative DOM bindings (o-show, o-model, etc.)
onigiri-resource
REST-style data models over AJAX
onigiri-observe
Intersection & Mutation observer helpers
onigiri-humhub-ui
Standard HumHub UI abstractions (modal, notify, confirm)
onigiri-lifecycle
Component lifecycle hooks
onigiri-guard
Debounce, throttle, single-run guards
onigiri-scroll
Scroll save/restore & helpers (PJAX-friendly)
onigiri-permission
Client-side permission awareness
onigiri-portal
DOM teleport / overlay mounting
onigiri-router
Micro router (non-SPA, PJAX-first)
onigiri-sanitize
HTML & input sanitization
onigiri-shortcut
Keyboard shortcut manager
onigiri-queue
Sequential async task runner
onigiri-gesture
Touch & swipe helpers
onigiri-devtools
Debugging & inspection helpers
onigiri-plugin
Plugin registration system
onigiri-time
Relative time & timezone utilities
onigiri-emojis
Emoji Picker and Manager
onigiri-tasks
Task Management
onigiri-polls
Polls creation and management
Note: Task completion is managed by the OnigiriJS development team.