Coder Social home page Coder Social logo

akempes / angular-rateit Goto Github PK

View Code? Open in Web Editor NEW
50.0 8.0 19.0 108 KB

This directive was inspired by the jQuery (star)rating plugin RateIt. However this package will work without jQuery.

License: MIT License

JavaScript 54.00% CSS 5.17% HTML 40.83%

angular-rateit's Introduction

angular-rateit

This directive was inspired by the jQuery (star)rating plugin RateIt. However this package will work without jQuery and is very light weight.

ng-rate-it

Live demo

Getting Started

You can install an angular-rateit package easily using Bower:

bower install angular-rateit

And add the files to your index page:

<link rel="stylesheet" href="angular-rateit/dist/ng-rateit.css" />
<script src="angular-rateit/dist/ng-rateit.js"></script>

Finally add 'ngRateIt' to your main module's list of dependencies:

angular.module('myApp', [
	...
    'ngRateIt',
    ...
]);

How to use

To get it working simply add this block of code to your view:

<ng-rate-it ng-model="test.rateit"></ng-rate-it>

N.B. When using angular 1.2.* use <div ng-rate-it ng-model="test.rateit"></div>

For more advanced functionality you can add a couple attributes:

<ng-rate-it 
	ng-model = "String, Number, Array"
	min = "Double"
	max = "Double"
	step = "Double"
	read-only = "Boolean"
	pristine = "Boolean"
	resetable = "Boolean"
	star-width = "Integer"
	star-height = "Integer"
	rated = "Function(rating)"
	reset = "Function(rating)"
	before-rated = "Function(newRating): return promise"
	before-reset = "Function(rating): return promise"
	>
</ng-rate-it>

Attributes

Attribute Description Value Default
ng-model Object bound to control. (Required) String, Number, Array -
min Minimal value. Double 0
max Maximal value. The difference between min and max will provide the number of stars. Double 5
step Step size. Double 0.5
read-only Whether or not is readonly. Boolean false
pristine Whether or not the current value is the initial value. Boolean true
resetable When not readonly, whether to show the reset button. Boolean true
star-width Width of the star picture. Integer 16
star-height Height of the star picture. Integer 16
cancel-width Width of the cancel icon. Integer star-width
cancel-height Height of the cancel icon. Integer star-height
rated Fired when a rating happened. (Obtain the rated value by the model) Function -
reset Fired when the reset button was clicked. Function -
before-rated Fired before the item is actually rated. By rejecting the promise it is possible to cancel the rating. Function: return promise -
before-reset Fired before the item is actually reset. By rejecting the promise it is possible to cancel the reset. Function: return promise -

Customization

You can easily add your own star style via css. You can use the star-width and star-height attributes to make the 'stars' bigger if necessary.

<style>
	.custom.ngrateit .ngrateit-star{
		background-image: url('custom.png');
	}
</style>
<ng-rate-it ng-model="model.custom" class="custom"></ng-rate-it>

Release Note:

V4.0.0

  • BREAKING: The callback function binding has changed form two-way to method binding. This will allow you to pass your own variables to the callback function AND the current rating is passed in the rating parameter:
<ng-rate-it ng-model="model.basic" rated="myCallback(rating, 'Your own var')"></ng-rate-it>
$scope.myCallback = function (rating, cusotmVar) {
	console.log(rating, customVar);
}

To upgrade from v3 to v4, just add () after your function name.

V3.0.0

  • BREAKING: The over callback is removed.
  • BREAKING: If you're using your own template, you need to update it.
  • Template and CSS file are refactored in order to support mobile divices.
  • Moved calculations from template to controller.

MIT License

Copyright (c) 2017 Arjan Kempes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

angular-rateit's People

Contributors

akempes avatar krydos avatar maximemaillet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-rateit's Issues

Exception when Hovering

I have a very simple HTML page

  <ng-rate-it ng-model="rateIt" step="1" readonly="true"></ng-rate-it>
  $scope.rateIt = 1;

It renders without any problem. However, when I have the mouse pointer hovering the stars, I got the following exceptions in Javascript console:

"Error: event.originalTarget is undefined
$scope.onEnter@http://localhost:3000/consumer_ui/www/scripts/vendors/angular-rateit/dist/ng-rateit.js:111:3
$parseFunctionCall@http://localhost:3000/consumer_ui/www/scripts/vendors/angular/angular.js:12404:15
ngEventHandler/</callback@http://localhost:3000/consumer_ui/www/scripts/vendors/angular/angular.js:21566:17
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost:3000/consumer_ui/www/scripts/vendors/angular/angular.js:14466:16
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:3000/consumer_ui/www/scripts/vendors/angular/angular.js:14565:18
ngEventHandler/<@http://localhost:3000/consumer_ui/www/scripts/vendors/angular/angular.js:21571:17
jQuery.event.special[orig].handle@http://localhost:3000/consumer_ui/www/scripts/vendors/jquery/dist/jquery.js:4765:11
jQuery.event.dispatch@http://localhost:3000/consumer_ui/www/scripts/vendors/jquery/dist/jquery.js:4434:15
jQuery.event.add/elemData.handle@http://localhost:3000/consumer_ui/www/scripts/vendors/jquery/dist/jquery.js:4121:6
"

Missing "ignore" entry in bower.json

I got the following warning/error when installing the latest release

$ bower install
bower angular-rateit#2.0.1  not-cached git://github.com/akempes/angular-rateit.git#2.0.1
bower angular-rateit#2.0.1     resolve git://github.com/akempes/angular-rateit.git#2.0.1
bower angular-rateit#2.0.1    download https://github.com/akempes/angular-rateit/archive/2.0.1.tar.gz
bower angular-rateit#2.0.1     extract archive.tar.gz
bower angular-rateit#2.0.1     invalid-meta angular-rateit is missing "ignore" entry in bower.json
bower angular-rateit#2.0.1         resolved git://github.com/akempes/angular-rateit.git#2.0.1
bower angular-rateit#2.0.1          install angular-rateit#2.0.1

Stars are kinda blurred

The stars look like this in some devices. I couldn't find why. Is it plugin-related or device-related?

Module conflict

Hi, i had problems when merging my scripts,

//angular-rateit
var module = angular.module('ngRateIt', ['ng']);

module
.directive('ngRateIt', ["$q", function( $q ) {

conflict with the module loader detection of some scripts like un malarkey

// https://github.com/yuanqing/malarkey/blob/master/dist/malarkey.js#L170
  /* istanbul ignore else */
  if (typeof module == 'object') {
    module.exports = Malarkey;
  } else {
    root.malarkey = Malarkey;
  }

or angular moment

// https://github.com/urish/angular-moment/blob/master/angular-moment.js#L729
	if (typeof define === 'function' && define.amd) {
		define(['angular', 'moment'], angularMoment);
	} else if (typeof module !== 'undefined' && module && module.exports) {
		angularMoment(angular, require('moment'));
		module.exports = 'angularMoment';
	} else {
		angularMoment(angular, (typeof global !== 'undefined' ? global : window).moment);
	}

( these two combinated are deadly ๐Ÿ˜ข )

I agree to say that my minification process don't isolate well my scripts.
But can we replace the module definition by

//angular-rateit
angular.module('ngRateIt', ['ng'])
.directive('ngRateIt', ["$q", function( $q ) {

To avoid global variable leaking ?

Thanks,
Nico.

Incompatible with other angular directives

I am using angular-rateit version 4.0.2, but it is incompatible with angular-animate version 1.5.8. Giving this error:
"TypeError: a is not a function"
Any leads would be appreciated.

Unable to set step size with in IE11

It seems like step size other than 1 doesn't work. The default step size of 0.5 shrinks the height of the stars. This bug is only in IE 11 but works fine in Chrome and Firefox.

Update: The issue was related to a custom SVG file I was using. The width and height have to be specifically set in the SVG. I set it to 16px and it worked!

Rated Function Fires on all instances

Hey just looking for some help here. I have this implemented in a ng-repeat and have the rated attribute pointing to a function on my controller, I.e. vm.postRating(item). When this fires it fires for every item in the collection of items that are contained within the my-repeat. Seems like it should just fire for the item that has just been rated. Not sure if I'm doing something wrong or not. Seems pretty straight forward.

2.0.4 broken while hovering over

Stars flicker when clicked on.

Not sure if this is something to do with how the stars backgrounds are coloured in but when i click on a star to set the rating they all seem to flicker for a second. Not a breaking issue but definitely some weird behaviour going on.

License

Hello! Could you please include the license file in your repo? What are the license terms of this plugin? Thank you!

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.