Coder Social home page Coder Social logo

jquery-simplerating's Introduction

SimpleRating

A simple JS file (using jQuery) to integrate a rating system with images to your website. When the user click on a rank, the rank is stored into a hidden input of your choice, easily useable by your server side's script. The click can also trigger a function of your choice, such as sending via AJAX the rank chosen to a server's side script.

Demo

Test it here : http://demo.charlymartins.fr/jquery-simplerating

Setup

Download the JS file then add it to your page

<script src="/assets/js/simplerating.js"></script>

Load jQuery if it's not already done

Add to your CSS :

.low-opacity {
    opacity: 0.4;
}
.img-rate:hover {
    cursor:pointer;
}

Create an empty div in your page, where you want to display the rating system

 <div id="rating-difficulty"></div>

An input hidden is automatically created to store the rank chosen by the user. You can create it by yourself, the script won't overwrite it, but don't forget the "autocomplete" attribute to avoid problem with Firefox. You provide the name of this input in the settings.

Usage

Into a script tag and when the document is loaded and ready

 $('#rating-difficulty').simplerating({
             rating_number: 5, // MAXIMUM RATING AVAILABLE THE USER
             image: 'star.png', // IMAGE USED FOR THE RATING SYSTEM
             hidden_input: 'rating_simplerating', // THE ID OF YOUR HIDDEN INPUT CONTAINING THE USER'S CHOICE
             image_width: '32px', // OPTIONNAL, IF YOU NEED TO RESIZE THE IMAGE
             initial_rating: 1, // OPTIONNAL, INITIAL RATING
             callback_on_click: 'sendRating', // OPTIONNAL, NAME OF THE FUNCTION WITHOUT () CALLED WHEN THE USER CLICK ON A RATING
			 rating_text: {0 : 'Worst', 1 : 'Poor', 2 : 'Correct', 3 : 'Not bad', 4 : 'Great', 5 : 'Awesome'} // OPTIONNAL, TEXT DISPLAYED ACCORDING TO THE RATING CHOSEN, THE "0" RATING IS OPTIONNAL
        });

Don't forget to check the rating chosen (into the hidden input) on your server side's script

Copyright

You are free to use and modify this script.

jquery-simplerating's People

Contributors

yosimitso avatar

Watchers

 avatar

Forkers

cdowebcast

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.