From d8f8c149b59926285d77b69ed9bf8e5dc921f9ba Mon Sep 17 00:00:00 2001 From: Alexander Petkov Date: Sun, 2 Nov 2014 13:12:24 +0200 Subject: [PATCH 1/3] Basic Gruntfile tasks --- .gitignore | 2 ++ Gruntfile.js | 33 +++++++++++++++++++++++++++++++++ min/jquery.rateyo.min.css | 2 +- min/jquery.rateyo.min.js | 2 +- package.json | 23 +++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 Gruntfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index d045738..7d7dbf7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.swo *.swn *.swm +node_modules +.DS_Store diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..d98458c --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,33 @@ +module.exports = function(grunt) { + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + + var config = { + srcDir: 'src/' + , minDir: 'min/' + , name: 'jquery.rateyo' + }; + + grunt.initConfig({ + config: config + , pkg: grunt.file.readJSON('package.json') + + , uglify: { + minify: { + files: { + '<%= config.minDir %><%= config.name %>.min.js': ['<%= config.srcDir %><%= config.name %>.js'] + } + } + } + + , cssmin: { + minify: { + files: { + '<%= config.minDir %><%= config.name %>.min.css': ['<%= config.srcDir %><%= config.name %>.css'] + } + } + } + }); + + grunt.registerTask('build', ['uglify:minify', 'cssmin:minify']); + grunt.registerTask('default', 'build'); +}; diff --git a/min/jquery.rateyo.min.css b/min/jquery.rateyo.min.css index 1a4343c..94df434 100644 --- a/min/jquery.rateyo.min.css +++ b/min/jquery.rateyo.min.css @@ -1 +1 @@ -.jq-ry-container{position:relative;padding:0;line-height:0;display:block;padding-right:5px;padding-left:5px}.jq-ry-container>.jq-ry-group-wrapper{position:relative;width:100%;cursor:pointer}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group{position:relative;line-height:0;z-index:10;white-space:nowrap}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group>svg{display:inline}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group.jq-ry-normal-group{width:100%}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group.jq-ry-rated-group{width:0;z-index:11;position:absolute;top:0;left:0;overflow:hidden} \ No newline at end of file +.jq-ry-container{position:relative;padding:0 5px;line-height:0;display:block}.jq-ry-container>.jq-ry-group-wrapper{position:relative;width:100%;cursor:pointer}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group{position:relative;line-height:0;z-index:10;white-space:nowrap}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group>svg{display:inline}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group.jq-ry-normal-group{width:100%}.jq-ry-container>.jq-ry-group-wrapper>.jq-ry-group.jq-ry-rated-group{width:0;z-index:11;position:absolute;top:0;left:0;overflow:hidden} \ No newline at end of file diff --git a/min/jquery.rateyo.min.js b/min/jquery.rateyo.min.js index 9444694..13041a7 100644 --- a/min/jquery.rateyo.min.js +++ b/min/jquery.rateyo.min.js @@ -1 +1 @@ -(function($){"use strict";var t=''+''+''+"";var e={starWidth:"32px",normalFill:"gray",ratedFill:"#f39c12",numStars:5,minValue:0,maxValue:5,precision:1,rating:0,onChange:null,onSet:null};function r(t,e,r){if(t===e){t=e}else if(t===r){t=r}return t}function n(t,e,r){var n=t>=e&&t<=r;if(!n){throw Error("Invalid Rating, expected value between "+e+" and "+r)}return t}function i(t,e){var r;$.each(e,function(){if(t===this.node){r=this;return false}});return r}function o(t,e){$.each(e,function(r){if(t===this.node){var n=e.slice(0,r),i=e.slice(r+1,e.length);e=n.concat(i);return false}});return e}function a(e,i){this.$node=e;this.node=e.get(0);var s=this;var l=i.rating;i.starHeight=i.starWidth;var f=false,g=i.maxValue,p=i.minValue;if(typeof l==="string"){if(l[l.length-1]==="%"){f=true;l=l.substr(0,l.length-1);g=100;p=0}l=parseInt(l);n(l,p,g)}var u=parseInt(i.starWidth.replace("px","").trim());u=u*i.numStars;e.addClass("jq-ry-container").width(u);var h=$("
").addClass("jq-ry-group-wrapper").appendTo(e);var c=$("
").addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(h);var d=$("
").addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(h);for(var v=0;vn){o=g}else{o=(i-r)/(n-r)*(g-p);o=p+o}return o}function w(t){var n=m(t).toFixed(i.precision);n=r(parseFloat(n),p,g);y(n);e.trigger("rateyo.change",{rating:n})}function x(){y();e.trigger("rateyo.change",{rating:l})}function F(t){var e=m(t).toFixed(i.precision);e=parseFloat(e);s.setRating(e)}function C(t,e){if(i.onChange&&typeof i.onChange==="function"){i.onChange.apply(this,[e.rating,s])}}function j(t,e){if(i.onSet&&typeof i.onSet==="function"){i.onSet.apply(this,[e.rating,s])}}function S(){e.on("mousemove",w).on("mouseenter",w).on("mouseleave",x).on("click",F).on("rateyo.change",C).on("rateyo.set",j)}function q(){e.off("mousemove",w).off("mouseenter",w).off("mouseleave",x).off("click",F).off("rateyo.change",C).on("rateyo.set",j)}this.destroy=function(){q();a.prototype.collection=o(e.get(0),this.collection);e.removeClass("jq-ry-container").children().remove();return e};S();this.setRating(l)}a.prototype.collection=[];function s(t){var r=a.prototype.collection;var n={rating:{getter:"getRating",setter:"setRating"},destroy:{getter:"destroy"}};var o=$(this);if(o.length===0){return o}var s=Array.prototype.slice.apply(arguments,[]);if(s.length===0){t=s[0]={}}else if(s.length===1&&typeof s[0]==="object"){t=s[0]}else if(s.length>1&&s[0]==="method"){var l=s[1];if(!n[l]){throw Error("Invalid Option!")}var f=[];var g=s.length===2;var p;var u;if(g){p=i(o.get(o.length-1),r);if(!p){throw Error("Trying to get options before even initialization")}u=p[n[l].getter];if(!u){throw Error("Method "+l+" does not exist!")}return u.apply(p,[])}else{var h=s[2];$.each(o,function(t,e){var o=i($(e).get(0),r);if(!o){throw Error("Trying to set options before even initialization")}u=o[n[l].setter];if(!u){throw Error("Method "+l+" does not exist!")}u.apply(o,[h]);f.push(o.node)});return $(f)}}else{throw Error("Invalid Arguments")}t=$.extend(JSON.parse(JSON.stringify(e)),t);return $.each(o,function(){var e=i(this,r);if(e){return}r.push(new a($(this),t))})}function l(){return s.apply(this,Array.prototype.slice.apply(arguments,[]))}$.fn.rateYo=l})(jQuery); \ No newline at end of file +!function(a){"use strict";function b(a,b,c){return a===b?a=b:a===c&&(a=c),a}function c(a,b,c){var d=a>=b&&c>=a;if(!d)throw Error("Invalid Rating, expected value between "+b+" and "+c);return a}function d(b,c){var d;return a.each(c,function(){return b===this.node?(d=this,!1):void 0}),d}function e(b,c){return a.each(c,function(a){if(b===this.node){var d=c.slice(0,a),e=c.slice(a+1,c.length);return c=d.concat(e),!1}}),c}function f(d,g){function h(a){void 0===a&&(a=s);var b=(a-v)/(u-v)*100;z.css("width",b+"%")}function j(a){var b,c=y.offset(),d=c.left,e=d+y.width(),f=a.pageX;return d>f?b=v:f>e?b=u:(b=(f-d)/(e-d)*(u-v),b=v+b),b}function k(a){var c=j(a).toFixed(g.precision);c=b(parseFloat(c),v,u),h(c),d.trigger("rateyo.change",{rating:c})}function l(){h(),d.trigger("rateyo.change",{rating:s})}function m(a){var b=j(a).toFixed(g.precision);b=parseFloat(b),r.setRating(b)}function n(a,b){g.onChange&&"function"==typeof g.onChange&&g.onChange.apply(this,[b.rating,r])}function o(a,b){g.onSet&&"function"==typeof g.onSet&&g.onSet.apply(this,[b.rating,r])}function p(){d.on("mousemove",k).on("mouseenter",k).on("mouseleave",l).on("click",m).on("rateyo.change",n).on("rateyo.set",o)}function q(){d.off("mousemove",k).off("mouseenter",k).off("mouseleave",l).off("click",m).off("rateyo.change",n).on("rateyo.set",o)}this.$node=d,this.node=d.get(0);var r=this,s=g.rating;g.starHeight=g.starWidth;var t=!1,u=g.maxValue,v=g.minValue;"string"==typeof s&&("%"===s[s.length-1]&&(t=!0,s=s.substr(0,s.length-1),u=100,v=0),s=parseInt(s),c(s,v,u));var w=parseInt(g.starWidth.replace("px","").trim());w*=g.numStars,d.addClass("jq-ry-container").width(w);for(var x=a("
").addClass("jq-ry-group-wrapper").appendTo(d),y=a("
").addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(x),z=a("
").addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(x),A=0;A1&&"method"===h[0]){var i=h[1];if(!e[i])throw Error("Invalid Option!");var k,l,m=[],n=2===h.length;if(n){if(k=d(g.get(g.length-1),c),!k)throw Error("Trying to get options before even initialization");if(l=k[e[i].getter],!l)throw Error("Method "+i+" does not exist!");return l.apply(k,[])}var o=h[2];return a.each(g,function(b,f){var g=d(a(f).get(0),c);if(!g)throw Error("Trying to set options before even initialization");if(l=g[e[i].setter],!l)throw Error("Method "+i+" does not exist!");l.apply(g,[o]),m.push(g.node)}),a(m)}throw Error("Invalid Arguments")}b=h[0]}return b=a.extend(JSON.parse(JSON.stringify(j)),b),a.each(g,function(){var e=d(this,c);e||c.push(new f(a(this),b))})}function h(){return g.apply(this,Array.prototype.slice.apply(arguments,[]))}var i='',j={starWidth:"32px",normalFill:"gray",ratedFill:"#f39c12",numStars:5,minValue:0,maxValue:5,precision:1,rating:0,onChange:null,onSet:null};f.prototype.collection=[],a.fn.rateYo=h}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4287833 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "rateYo" + , "version": "1.0.0" + , "description": "A simple and flexible star rating plugin" + , "main": "js/jquery.rateyo.js" + , "repository": { + "type": "git" + , "url": "git://github.com/prrashi/rateYo.git" + } + , "author": "prashanth pamidi (https://github.com/prrashi)" + , "bugs": { + "url": "https://github.com/prrashi/rateYo/issues" + } + , "devDependencies": { + "grunt": "~0.4.5" + , "grunt-contrib-clean": "~0.6.0" + , "grunt-contrib-watch": "~0.6.1" + , "grunt-contrib-uglify": "~0.6.0" + , "grunt-contrib-cssmin": "~0.10.0" + , "matchdep": "~0.3.0" + } + , "homepage": "http://rateyo.fundoocode.ninja/" +} From 368effd5694b4b03f2f277261256d6e648020749 Mon Sep 17 00:00:00 2001 From: Alexander Petkov Date: Sun, 2 Nov 2014 13:12:46 +0200 Subject: [PATCH 2/3] Fix Readme typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df5434b..976d959 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ rateYo ====== -A simple and flexible, jQuery star rating Plugin, +A simple and flexible, jQuery star rating Plugin, it uses SVG to render rating, so no images required. @@ -13,4 +13,4 @@ just create a div, throw some styles, initialize and thats it!. http://prrashi.github.io/rateYo/ **Browser Support**" -Supported by all modren browsers from IE9 +Supported by all modern browsers from IE9 From 85e0233584bdae81e4da3d9baf0ab59f401a5ba9 Mon Sep 17 00:00:00 2001 From: Alexander Petkov Date: Sun, 2 Nov 2014 13:14:34 +0200 Subject: [PATCH 3/3] Minor CSS changes --- src/jquery.rateyo.css | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/jquery.rateyo.css b/src/jquery.rateyo.css index 372b352..66c72a1 100644 --- a/src/jquery.rateyo.css +++ b/src/jquery.rateyo.css @@ -1,10 +1,8 @@ .jq-ry-container { position: relative; - padding: 0px; - line-height: 0px; + padding: 0 5px; + line-height: 0; display: block; - padding-right: 5px; - padding-left: 5px; } .jq-ry-container > .jq-ry-group-wrapper { position: relative; @@ -13,7 +11,7 @@ } .jq-ry-container > .jq-ry-group-wrapper > .jq-ry-group { position: relative; - line-height: 0px; + line-height: 0; z-index: 10; white-space: nowrap; } @@ -24,10 +22,10 @@ width: 100%; } .jq-ry-container > .jq-ry-group-wrapper > .jq-ry-group.jq-ry-rated-group { - width: 0%; + width: 0; z-index: 11; position: absolute; - top: 0px; - left: 0px; + top: 0; + left: 0; overflow: hidden; }