Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-browser use #96

Open
zuzanna-maria opened this issue Feb 9, 2023 · 1 comment
Open

In-browser use #96

zuzanna-maria opened this issue Feb 9, 2023 · 1 comment

Comments

@zuzanna-maria
Copy link

Hi,

have you tried/had success with adapting this package for in-browser use?

lzear added a commit that referenced this issue Mar 25, 2023
@lzear lzear mentioned this issue Mar 25, 2023
lzear added a commit that referenced this issue Mar 25, 2023
@lzear
Copy link
Owner

lzear commented Mar 26, 2023

Hi @zuzanna-maria
First of all, sorry I didn't notice your issue for so long 😔

If you use Webpack or similar tools, you would add the library to your npm dependencies, import it and get it compiled with your code. That's what I did in (https://www.elzear.de/poll/Uug62KMX) and https://rank-votes.vercel.app (code source is here: https://github.com/lzear/votes/tree/master/demo). It's used like the example in the readme: https://github.com/lzear/votes#%EF%B8%8F-use

If you want to import the library without using a bundler, it is now doable by importing the IIFE module compiled at /dist/index.global.js for example from https://cdn.jsdelivr.net/npm/[email protected]/dist/index.global.js. It will set votes in the window object.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.global.js"></script>
<script>
  console.log(window.votes)
  // shows
  // {
  // AbsoluteMajority: (...)
  // Approbation: (...)
  // Baldwin: (...)
  // Borda: (...)
  // BottomTwoRunoff: (...)
  // Coombs: (...)
  // Copeland: (...)
  // FirstPastThePost: (...)
  // InstantRunoff: (...)
  // Kemeny: (...)
  // MajorityJudgment: (...)
  // MaximalLotteries: (...)
  // Minimax: (...)
  // MinimaxTD: (...)
  // MinimaxVariant: (...)
  // Nanson: (...)
  // RandomCandidates: (...)
  // RandomDictator: (...)
  // RandomizedCondorcet: (...)
  // RankedPairs: (...)
  // Schulze: (...)
  // Smith: (...)
  // TwoRoundRunoff: (...)
  // VotingSystem: (...)
  // isBallotMethod: (...)
  // isBallotSystem: (...)
  // isMatrixMethod: (...)
  // isMatrixSystem: (...)
  // isRandomMethod: (...)
  // isRandomSystem: (...)
  // methods: (...)
  // utils: (...)
  // }
</script>

Here is an example: https://codesandbox.io/s/votes-iife-demo-gv6vz7?file=/index.html:233-294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants