Javascript Configuration
Implementing a Vote on your site follows these requirements:
Here's a simple example of how to include the Digital Research Vote in your site:
<script src="https://www.digitalresearch.uk/vote.js">
<script>
function voteDR() {
DigitalResearchModal.show({
title: "Rate this page?", // Heading
question: "How would you rate this page?", // Question
reference: "vote.php", // Reference passed back
buttonPair: "goodbad", // yesno, truefalse, thumbs, highlow, onoff, openclose, inout, lightdark, updown
uuid: "Y1gxd0pvWWdYdDFjZGdNaStVa0QyZzVTWVFEVDhJa04vc2Y3cVIvUlRoZ1NaSzRk", // Link generated for this vote
position: "center", // Position in the center of the screen
theme: "dark", // light, dark, blue, green, grey, contrast, pastel
onComplete: function(response, data) {
console.log("User selected: " + response);
console.log("Server response:", data);
}
});
}
</script>
The javascript call has a collection of parameters that need to be configured before it will work:
- title: Appears at the top of the dialogue as a header
- question: The question asked in the dialogue, e.g. "Did you like this story?"
- reference: A reference to the item being voted on, text alpha-numeric
- buttonPair: Choice of options:
- yesno: Yes and No
- truefalse: True and False
- thumbs: A HTML Thumbs up and thumbs down
- highlow: High and Low
- onoff: On and Off
- openclose: Open and Close
- inout: In and Out
- lightdark: Light and Dark
- updown: Up and Down
- A|B: A = 1 and B = 0
- uuid: Encoded UUID Link obtained from the API
- position: Left, Right, Top, Bottom, Middle
- theme: The Colour Scheme
- light: Normal Light Theme
- dark: Normal Dark Theme
- blue: Blues Theme
- green: Greens Theme
- grey: Greys Theme
- contrast: A Nice Pastel Theme
- onComplete: Boolean
The Button
Calling for a Vote
<div class="rate-this-page">
<button class="button is-rounded is-primary is-outlined is-small rate-button" onclick="voteDR()">
<span class="icon">
<i class="fas fa-star">
</span>
<span>Rate this page
</button>
</div>
The button can be any DOM object that can invoke javascript, and by simply calling voteDR() the vote will be shown, captured and uploaded to your account.
In this example we're using BULMA CSS but it really doesn't matter how you style it or implement it.