Comparing version 2.9.0 to 3.0.0
{ | ||
"authors": ["Washington Botelho <wbotelhos@gmail.com> (http://wbotelhos.com)"], | ||
"description": "jQuery Raty - A Star Rating Plugin", | ||
"authors": [ | ||
"Washington Botelho <wbotelhos@gmail.com> (https://www.wbotelhos.com)" | ||
], | ||
"description": "Raty - A Star Rating Plugin", | ||
"dependencies": { | ||
"jquery": "^3.3.1" | ||
"jquery": "^3.5.1" | ||
}, | ||
"homepage": "https://github.com/wbotelhos/raty", | ||
"ignore": ["**/.*", "node_modules", "spec", "vendor"], | ||
"keywords": ["classificacao", "classificar", "javascript", "jquery", "library", "plugin", "rating", "raty", "star", "staring", "votar", "voto"], | ||
"license": "MIT", | ||
"main": "lib/jquery.raty.js", | ||
"name": "raty", | ||
"version": "2.9.0" | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"spec", | ||
"vendor" | ||
], | ||
"keywords": [ | ||
"classificacao", | ||
"classificar", | ||
"javascript", | ||
"jquery", | ||
"library", | ||
"plugin", | ||
"rating", | ||
"raty", | ||
"star", | ||
"staring", | ||
"votar", | ||
"voto" | ||
], | ||
"license": "MIT", | ||
"main": "lib/jquery.raty.js", | ||
"name": "raty" | ||
} |
@@ -1,6 +0,23 @@ | ||
# jQuery Raty - A Star Rating Plugin - http://wbotelhos.com/raty | ||
## 3.0.0 | ||
### Break Change | ||
- Function `destroy` was removed; | ||
- Function `reload` was removed; | ||
- Function `set` was removed; | ||
- Functions now is accessed via `element.data('raty').FUNCTION_NAME()`; | ||
- Option `cancel` was renamed to `cancelButton`; | ||
### Bugfix | ||
- When using `single` options the click was not turning the star on; [#155](https://github.com/wbotelhos/raty/pull/155) by [henrikhannemose](https://github.com/henrikhannemose) | ||
### Update | ||
- Grammars fixes; [#217](https://github.com/wbotelhos/raty/pull/217) by [tfantina](https://github.com/tfantina) | ||
- All the code were migrated to pure Prototype. Vanilla JS coming soon!; | ||
## 2.9.0 | ||
### Changes | ||
### Update | ||
@@ -17,3 +34,3 @@ + Drops `engines` from `package.json` for a greater flexibility; | ||
### Fixes | ||
### Bugfix | ||
@@ -29,3 +46,3 @@ + Fix `readOnly` when using fonts; (Amaia Baigorri) | ||
### Fixes | ||
### Bugfix | ||
@@ -37,3 +54,3 @@ + Function `move` was losing precision with float with more then one digit; | ||
### Changes | ||
### Update | ||
@@ -49,3 +66,3 @@ + If you returns `false` into `click` callback, the action will be prevented; | ||
### Fixes | ||
### Bugfix | ||
@@ -57,3 +74,3 @@ + Target was not showing the score when `half` was enabled; (andersonba) | ||
### Changes | ||
### Update | ||
@@ -77,3 +94,3 @@ + `path` now is `undefined` by default; | ||
### Fixes | ||
### Bugfix | ||
@@ -92,3 +109,3 @@ The read-only indicator was not removing after the reset of configuration, blocking the `click` and `score` functions. | ||
### Changes | ||
### Update | ||
@@ -107,3 +124,3 @@ + Extracted the limit of stars to the option `numberMax`; | ||
### Fixes | ||
### Bugfix | ||
@@ -110,0 +127,0 @@ + The `click` function was not yielding the event. |
{ | ||
"description": "jQuery Raty - A Star Rating Plugin", | ||
"homepage": "https://github.com/wbotelhos/raty", | ||
"license": "MIT", | ||
"name": "wbotelhos/raty", | ||
"authors": [ | ||
{ "homepage": "http://wbotelhos.com", "name": "Washington Botelho" } | ||
], | ||
{ | ||
"homepage": "https://www.wbotelhos.com", | ||
"name": "Washington Botelho" | ||
} | ||
], | ||
"description": "Raty - A Star Rating Plugin", | ||
"homepage": "https://github.com/wbotelhos/raty", | ||
"keywords": [ | ||
@@ -24,3 +23,5 @@ "classificacao", | ||
"voto" | ||
] | ||
], | ||
"license": "MIT", | ||
"name": "wbotelhos/raty" | ||
} |
@@ -1,1 +0,471 @@ | ||
var AntiBOT={init:function(t){this.form=$(t),this.field=this.form.find(".not-human input"),this.bot=$("#bot"),this.label=this.form.find(".not-human label"),this.submit=this.form.find(":submit"),this.binds(),this.lock()},binds:function(){var t=this;t.field.on("change",function(){t.field.is(":checked")?(t.label.text("S\xe9rio?"),t.lock()):t.unlock()})},lock:function(){var t=this;t.bot.val(!0),t.submit.on("click",function(e){e.preventDefault(),t.label.text("Hey! Me desmarque."),t.field.focus()})},unlock:function(){var t=this;t.submit.off("click"),t.bot.removeAttr("value"),t.label.text("Humanos! <3")}},CommentResponder={init:function(){this.body=$("#comment_body"),this.comments=$(".comments"),this.parent=$("#comment_parent_id"),this.cancel=$("#replying-cancel"),this.replying=$("#replying-to"),this.binds()},binds:function(){var t=this;t.comments.on("click",".reply",function(){var e=$(this),i=e.data("id"),n=e.data("name");t.setParent(i),t.write(n+",\n\n"),t.showReplying(i,n),t.showCancel(),t.focuz()}),t.cancel.on("click",function(){t.replying.css("visibility","hidden"),t.body.val(""),t.cancel.css("visibility","hidden"),t.parent.removeAttr("value"),t.focuz()})},focuz:function(){this.body.blur().focus()},setParent:function(t){this.parent.val(t)},showCancel:function(){this.cancel.css("visibility","visible")},showReplying:function(t,e){var i="#comment-"+t,n="#"+t;this.replying.css("visibility","visible").children("strong").html('<a href="'+i+'">'+n+"</a> "+e)},write:function(t){this.body.val(t)}};$(function(){var t=$("#donations");$(".i-heart").on("click",function(){t.slideToggle("fast")})}),function(t){var e={init:function(i){return this.each(function(){this.opt=t.extend({},t.fn.taby.defaults,i);var n=t(this).off(".taby");e._adjustTab.call(this),e._bind.call(this),n.data({settings:this.opt,taby:!0})})},_adjustTab:function(){this.opt.tab="";for(var t=0;t<this.opt.space;t++)this.opt.tab+=" "},_backspace:function(){var e=t(this).data("settings"),i=this.selectionStart;e.backspace&&this.value.slice(i-e.tab.length,i)==e.tab&&(this.evt.preventDefault(),this.value=this.value.slice(0,i-e.tab.length)+this.value.slice(i),this.selectionStart=i-e.tab.length,this.selectionEnd=i-e.tab.length)},_bind:function(){t(this).on(e._eventName(),function(t){var i=t.keyCode||t.which;t.metaKey||(this.evt=t,9==i?t.shiftKey?e._shiftTab.call(this):e._tab.call(this):8==i?e._backspace.call(this):46==i?e._del.call(this):37==i?e._left.call(this):39==i&&e._right.call(this))})},_del:function(){var e=t(this).data("settings"),i=this.selectionStart,n=this.selectionEnd;e.del&&this.value.slice(i,i+e.tab.length)==e.tab&&(this.evt.preventDefault(),this.value=this.value.slice(0,i)+this.value.slice(i+e.tab.length),this.selectionStart=i,this.selectionEnd=n)},_eventName:function(){return e._isFirefox()?"keypress.taby":"keydown.taby"},_isFirefox:function(){return/firefox/.test(navigator.userAgent.toLowerCase())},_left:function(){var e=t(this).data("settings"),i=this.selectionStart,n=this.selectionEnd;if(this.evt.shiftKey||(i=n),e.left===!0&&this.value.slice(i-e.tab.length,i)==e.tab){this.evt.preventDefault();var s=e.tab.length,l=e.tab.length;this.evt.shiftKey&&(l=0),this.selectionStart=i-s,this.selectionEnd=n-l}},_right:function(){var e=t(this).data("settings"),i=this.selectionStart,n=this.selectionEnd;this.evt.shiftKey||(n=i),e.right===!0&&this.value.slice(n,n+e.tab.length)==e.tab&&(this.evt.preventDefault(),this.selectionStart=i+(this.evt.shiftKey?0:e.tab.length),this.selectionEnd=n+e.tab.length)},_shiftTab:function(){this.evt.preventDefault();var e=t(this).data("settings"),i=this.selectionStart,n=this.selectionEnd;if(preselection=this.value.slice(0,i),selection=this.value.slice(i,n),postselection=this.value.slice(n),isMultipleLine=selection.indexOf("\n")>=0,lineStart=preselection.lastIndexOf("\n"),lineEnd=n+postselection.indexOf("\n"),isFirst=0==i,previousCharacter=isFirst?"":this.value.slice(i-1,i),0>lineStart?lineStart=0:lineStart++,0>lineEnd&&(lineEnd=this.value.length),isMultipleLine){selection.lastIndexOf("\n")==selection.length-1&&(lineEnd=n-1,postselection="\n"+postselection);var s=this.value.slice(lineStart,lineEnd),l=s;if(l=l.replace(new RegExp("^"+e.tab),"").replace(new RegExp("\n"+e.tab,"g"),"\n"),s==l)return;this.value=this.value.slice(0,lineStart)+l+this.value.slice(lineEnd);var a=s.length-l.length,h=i,c=n-a;isFirst||"\n"==previousCharacter||(h-=e.tab.length),lineStart>h&&(h=lineStart);var o=0>h?0:h,r=0>c?0:c;this.selectionStart=o,this.selectionEnd=r}else{var s=this.value.slice(lineStart,lineEnd),l=s;if(0==s.indexOf(e.tab)&&(l=s.slice(e.tab.length)),s==l)return;this.value=this.value.slice(0,lineStart)+l+this.value.slice(lineEnd);var u=takedEnd=e.tab.length;i-lineStart<e.tab.length&&(u=i-lineStart,i==n&&(takedEnd=u)),this.selectionStart=i-u,this.selectionEnd=n-takedEnd}},_tab:function(){this.evt.preventDefault();var e=t(this).data("settings"),i=this.selectionStart,n=this.selectionEnd,s=this.value.slice(0,i),l=this.value.slice(i,n),a=this.value.slice(n),h=s.lastIndexOf("\n"),c=n+a.indexOf("\n"),o=0==i,r=n==this.value.length,u=o?"":this.value.slice(i-1,i),f=r?"":this.value.slice(n,n+1);if(0>h?h=0:h++,0>c&&(c=this.value.length),l.indexOf("\n")>=0){l.lastIndexOf("\n")==l.length-1&&(c=n-1,a="\n"+a);var v=this.value.slice(h,c),d=v;if(d=e.tab+d.replace(new RegExp("\n","g"),"\n"+e.tab),v==d)return;this.value=this.value.slice(0,h)+d+this.value.slice(c);var b=d.length-v.length,g=i,p=n+b;o||"\n"==u||(g+=e.tab.length),this.selectionStart=g,this.selectionEnd=p}else if(!o&&"\n"!=u||!r&&"\n"!=f||""==l)this.value=s+e.tab+a,this.selectionStart=i+e.tab.length,this.selectionEnd=i+e.tab.length;else{var v=this.value.slice(h,c);this.value=s+e.tab+v+a,this.selectionStart=i,this.selectionEnd=n+e.tab.length}},goTo:function(t){return this.each(function(){this.focus(),this.selectionStart=t,this.selectionEnd=t})},select:function(t,e){return this.each(function(){this.focus(),this.selectionStart=t,this.selectionEnd=void 0===e?this.value.length:e})},set:function(e){return this.each(function(){var i=t(this),n=i.data("settings"),s=t.extend({},n,e);i.taby(s)})}};t.fn.taby=function(i){return e[i]?e[i].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof i&&i?void t.error("Method "+i+" does not exist!"):e.init.apply(this,arguments)},t.fn.taby.defaults={backspace:!0,del:!0,left:!0,right:!0,space:2}}(jQuery); | ||
/*! | ||
* jQuery Taby - A Textarea Tabulator | ||
* ---------------------------------------------------------------- | ||
* | ||
* jQuery Taby is a plugin to enable tabulation in textarea fields. | ||
* | ||
* Licensed under The MIT License | ||
* | ||
* @version 1.0.0 | ||
* @since 2012.01.10 | ||
* @author Washington Botelho | ||
* @documentation wbotelhos.com/taby | ||
* | ||
* ---------------------------------------------------------------- | ||
* | ||
* $('textarea').taby(); | ||
* | ||
* <textarea></textarea> | ||
* | ||
*/ | ||
;(function($) { | ||
var methods = { | ||
init: function(settings) { | ||
return this.each(function() { | ||
this.opt = $.extend({}, $.fn.taby.defaults, settings); | ||
var $this = $(this).off('.taby'); | ||
methods._adjustTab.call(this); | ||
methods._bind.call(this); | ||
$this.data({ 'settings': this.opt, 'taby': true }); | ||
}); | ||
}, _adjustTab: function() { | ||
this.opt['tab'] = ''; | ||
for (var i = 0; i < this.opt.space; i++) { | ||
this.opt.tab += ' '; | ||
} | ||
}, _backspace: function() { | ||
var opt = $(this).data('settings'), | ||
start = this.selectionStart; | ||
if (opt.backspace && this.value.slice(start - opt.tab.length, start) == opt.tab) { | ||
this.evt.preventDefault(); | ||
this.value = this.value.slice(0, start - opt.tab.length) + this.value.slice(start); | ||
this.selectionStart = start - opt.tab.length; | ||
this.selectionEnd = start - opt.tab.length; | ||
} | ||
}, _bind: function() { | ||
$(this).on(methods._eventName(), function(evt) { | ||
var key = evt.keyCode || evt.which; | ||
if (evt.metaKey) { | ||
return; | ||
} | ||
this.evt = evt; | ||
if (key == 9) { | ||
if (evt.shiftKey) { | ||
methods._shiftTab.call(this); | ||
} else { | ||
methods._tab.call(this); | ||
} | ||
} else if (key == 8) { | ||
methods._backspace.call(this); | ||
} else if (key == 46) { | ||
methods._del.call(this); | ||
} else if (key == 37) { | ||
methods._left.call(this); | ||
} else if (key == 39) { | ||
methods._right.call(this); | ||
} | ||
}); | ||
}, _del: function() { | ||
var opt = $(this).data('settings'), | ||
start = this.selectionStart, | ||
end = this.selectionEnd; | ||
if (opt.del && this.value.slice(start, start + opt.tab.length) == opt.tab) { | ||
this.evt.preventDefault(); | ||
this.value = this.value.slice(0, start) + this.value.slice(start + opt.tab.length); | ||
this.selectionStart = start; | ||
this.selectionEnd = end; | ||
} | ||
}, _eventName: function() { | ||
return methods._isFirefox() ? 'keypress.taby' : 'keydown.taby' | ||
}, _isFirefox: function() { | ||
return /firefox/.test(navigator.userAgent.toLowerCase()); | ||
}, _left: function() { | ||
var opt = $(this).data('settings'), | ||
start = this.selectionStart, | ||
end = this.selectionEnd; | ||
if (!this.evt.shiftKey) { | ||
start = end; | ||
} | ||
if (opt.left === true && this.value.slice(start - opt.tab.length, start) == opt.tab) { | ||
this.evt.preventDefault(); | ||
var toStartTake = opt.tab.length, | ||
toEndTake = opt.tab.length; | ||
if (this.evt.shiftKey) { | ||
toEndTake = 0; | ||
} | ||
this.selectionStart = start - toStartTake; | ||
this.selectionEnd = end - toEndTake; | ||
} | ||
}, _right: function() { | ||
var opt = $(this).data('settings'), | ||
start = this.selectionStart, | ||
end = this.selectionEnd; | ||
if (!this.evt.shiftKey) { | ||
end = start; | ||
} | ||
if (opt.right === true && this.value.slice(end, end + opt.tab.length) == opt.tab) { | ||
this.evt.preventDefault(); | ||
this.selectionStart = start + (this.evt.shiftKey ? 0 : opt.tab.length); | ||
this.selectionEnd = end + opt.tab.length; | ||
} | ||
}, _shiftTab: function() { | ||
this.evt.preventDefault(); | ||
var opt = $(this).data('settings'), | ||
start = this.selectionStart, | ||
end = this.selectionEnd; | ||
preselection = this.value.slice(0, start), | ||
selection = this.value.slice(start, end), | ||
postselection = this.value.slice(end), | ||
isMultipleLine = selection.indexOf("\n") >= 0, | ||
lineStart = preselection.lastIndexOf("\n"), | ||
lineEnd = end + postselection.indexOf("\n"), | ||
isFirst = start == 0, | ||
previousCharacter = (isFirst) ? '' : this.value.slice(start - 1, start); | ||
if (lineStart < 0) { | ||
lineStart = 0; | ||
} else { | ||
lineStart++; | ||
} | ||
if (lineEnd < 0) { | ||
lineEnd = this.value.length; | ||
} | ||
if (isMultipleLine) { | ||
if (selection.lastIndexOf("\n") == selection.length - 1) { | ||
lineEnd = end - 1; | ||
postselection = "\n" + postselection; | ||
} | ||
var line = this.value.slice(lineStart, lineEnd), | ||
result = line; | ||
result = result.replace(new RegExp('^' + opt.tab), '').replace(new RegExp("\n" + opt.tab, 'g'), "\n"); | ||
if (line == result) { | ||
return; | ||
} | ||
this.value = this.value.slice(0, lineStart) + result + this.value.slice(lineEnd); | ||
var blankRemoved = line.length - result.length, | ||
startTaked = start, | ||
endTaked = end - blankRemoved; | ||
if (!isFirst && previousCharacter != "\n") { | ||
startTaked -= opt.tab.length; | ||
} | ||
if (startTaked < lineStart) { | ||
startTaked = lineStart; | ||
} | ||
var toStartTake = (startTaked < 0) ? 0 : startTaked, | ||
toEndTake = (endTaked < 0) ? 0 : endTaked; | ||
this.selectionStart = toStartTake; | ||
this.selectionEnd = toEndTake; | ||
} else { | ||
var line = this.value.slice(lineStart, lineEnd), | ||
result = line; | ||
if (line.indexOf(opt.tab) == 0) { | ||
result = line.slice(opt.tab.length); | ||
} | ||
if (line == result) { | ||
return; | ||
} | ||
this.value = this.value.slice(0, lineStart) + result + this.value.slice(lineEnd); | ||
var takedStart = takedEnd = opt.tab.length; | ||
if (start - lineStart < opt.tab.length) { | ||
takedStart = start - lineStart; | ||
if (start == end) { | ||
takedEnd = takedStart; | ||
} | ||
} | ||
this.selectionStart = start - takedStart; | ||
this.selectionEnd = end - takedEnd; | ||
} | ||
}, _tab: function() { | ||
this.evt.preventDefault(); | ||
var opt = $(this).data('settings'), | ||
start = this.selectionStart, | ||
end = this.selectionEnd, | ||
preselection = this.value.slice(0, start), | ||
selection = this.value.slice(start, end), | ||
postselection = this.value.slice(end), | ||
lineStart = preselection.lastIndexOf("\n"), | ||
lineEnd = end + postselection.indexOf("\n"), | ||
isFirst = start == 0, | ||
isLast = end == this.value.length, | ||
previousCharacter = (isFirst) ? '' : this.value.slice(start - 1, start), | ||
nextCharacter = (isLast) ? '' : this.value.slice(end, end + 1); | ||
if (lineStart < 0) { | ||
lineStart = 0; | ||
} else { | ||
lineStart++; | ||
} | ||
if (lineEnd < 0) { | ||
lineEnd = this.value.length; | ||
} | ||
if (selection.indexOf("\n") >= 0) { | ||
if (selection.lastIndexOf("\n") == selection.length - 1) { | ||
lineEnd = end - 1; | ||
postselection = "\n" + postselection; | ||
} | ||
var line = this.value.slice(lineStart, lineEnd), | ||
result = line; | ||
result = opt.tab + result.replace(new RegExp("\n", 'g'), "\n" + opt.tab); | ||
if (line == result) { | ||
return; | ||
} | ||
this.value = this.value.slice(0, lineStart) + result + this.value.slice(lineEnd); | ||
var blankAdded = result.length - line.length, | ||
startAdded = start, | ||
endAdded = end + blankAdded; | ||
if (!isFirst && previousCharacter != "\n") { | ||
startAdded += opt.tab.length; | ||
} | ||
this.selectionStart = startAdded; | ||
this.selectionEnd = endAdded; | ||
} else if ((isFirst || previousCharacter == "\n") && (isLast || nextCharacter == "\n") && selection != '') { | ||
var line = this.value.slice(lineStart, lineEnd); | ||
this.value = preselection + opt.tab + line + postselection; | ||
this.selectionStart = start; | ||
this.selectionEnd = end + opt.tab.length; | ||
} else { | ||
this.value = preselection + opt.tab + postselection; | ||
this.selectionStart = start + opt.tab.length; | ||
this.selectionEnd = start + opt.tab.length; | ||
} | ||
}, goTo: function(position) { | ||
return this.each(function() { | ||
this.focus(); | ||
this.selectionStart = position; | ||
this.selectionEnd = position; | ||
}); | ||
}, select: function(start, end) { | ||
return this.each(function() { | ||
this.focus(); | ||
this.selectionStart = start; | ||
this.selectionEnd = (end === undefined) ? this.value.length : end; | ||
}); | ||
}, set: function(settings) { | ||
return this.each(function() { | ||
var $this = $(this), | ||
actual = $this.data('settings'), | ||
news = $.extend({}, actual, settings); | ||
$this.taby(news); | ||
}); | ||
} | ||
}; | ||
$.fn.taby = function(method) { | ||
if (methods[method]) { | ||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
} else if (typeof method === 'object' || !method) { | ||
return methods.init.apply(this, arguments); | ||
} else { | ||
$.error('Method ' + method + ' does not exist!'); | ||
} | ||
}; | ||
$.fn.taby.defaults = { | ||
backspace : true, | ||
del : true, | ||
left : true, | ||
right : true, | ||
space : 2 | ||
}; | ||
})(jQuery); | ||
var AntiBOT = { // eslint-disable-line no-unused-vars | ||
init: function(form) { | ||
this.form = $(form); | ||
this.field = this.form.find('.not-human input'); | ||
this.bot = $('#bot'); | ||
this.label = this.form.find('.not-human label'); | ||
this.submit = this.form.find(':submit'); | ||
this.binds(); | ||
this.lock(); | ||
}, | ||
binds: function() { | ||
var that = this; | ||
that.field.on('change', function() { | ||
if (that.field.is(':checked')) { | ||
that.label.text('Sério?'); | ||
that.lock(); | ||
} else { | ||
that.unlock(); | ||
} | ||
}); | ||
}, | ||
lock: function() { | ||
var that = this; | ||
that.bot.val(true); | ||
that.submit.on('click', function(evt) { | ||
evt.preventDefault(); | ||
that.label.text('Hey! Me desmarque.'); | ||
that.field.focus(); | ||
}); | ||
}, | ||
unlock: function() { | ||
var that = this; | ||
that.submit.off('click'); | ||
that.bot.removeAttr('value'); | ||
that.label.text('Humanos! <3'); | ||
} | ||
}; | ||
var CommentResponder = { // eslint-disable-line no-unused-vars | ||
init: function() { | ||
this.body = $('#comment_body'); | ||
this.comments = $('.comments'); | ||
this.parent = $('#comment_parent_id'); | ||
this.cancel = $('.commenter__cancel'); | ||
this.replying = $('.commenter__replying'); | ||
this.binds(); | ||
}, | ||
binds: function() { | ||
var that = this; | ||
that.comments.on('click', '.comments__reply', function() { | ||
var self = $(this); | ||
var id = self.data('id'); | ||
var name = self.data('name'); | ||
that.setParent(id); | ||
that.write(name + ',\n\n'); | ||
that.showReplying(id, name); | ||
that.showCancel(); | ||
that.focuz(); | ||
}); | ||
that.cancel.on('click', function() { | ||
that.replying.css('visibility', 'hidden'); | ||
that.body.val(''); | ||
that.cancel.css('visibility', 'hidden'); | ||
that.parent.removeAttr('value'); | ||
that.focuz(); | ||
}); | ||
}, | ||
focuz: function() { | ||
this.body.trigger('blur').trigger('focus'); | ||
}, | ||
setParent: function(id) { | ||
this.parent.val(id); | ||
}, | ||
showCancel: function() { | ||
this.cancel.css('visibility', 'visible'); | ||
}, | ||
showReplying: function(id, name) { | ||
var anchor = '#comment-' + id; | ||
var text = '#' + id; | ||
this | ||
.replying | ||
.css('visibility', 'visible') | ||
.children('strong') | ||
.html('<a href="' + anchor + '">' + text + '</a> ' + name); | ||
}, | ||
write: function(text) { | ||
this.body.val(text); | ||
} | ||
}; | ||
$(function() { | ||
var donations = $('.donations'); | ||
$('.i-heart').on('click', function() { | ||
donations.slideToggle('fast'); | ||
}); | ||
}); | ||
var Expandy = { // eslint-disable-line no-unused-vars | ||
init: function(selector) { | ||
this.selector = selector; | ||
this.binds(); | ||
}, | ||
binds: function() { | ||
$(document) | ||
.one('focus.expandy', this.selector, function(){ | ||
var savedValue = this.value; | ||
this.baseScrollHeight = this.scrollHeight; | ||
this.value = ''; | ||
this.value = savedValue; | ||
}) | ||
.on('input.expandy', this.selector, function() { | ||
var minRows = parseInt(this.getAttribute('data-spandy-rows'), 10) || 0; var rows; | ||
this.rows = minRows; | ||
rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 17); | ||
this.rows = minRows + rows; | ||
}); | ||
} | ||
}; | ||
@@ -6,20 +6,17 @@ module.exports = function(config) { | ||
autoWatch: true, | ||
browsers: ['Firefox'], | ||
browsers: ['Chrome', 'Firefox'], | ||
files: [ | ||
'vendor/*.js', | ||
'node_modules/jquery/dist/jquery.min.js', | ||
'lib/*.css', | ||
'lib/*.js', | ||
'spec/lib/jasmine-jquery.js', | ||
'spec/vendor/jasmine-jquery.js', | ||
'spec/lib/helper.js', | ||
'spec/options_spec.js', | ||
'spec/*spec.js' | ||
'spec/**/*[sS]pec.js' | ||
], | ||
frameworks: ['jasmine'], | ||
logLevel: config.LOG_ERROR, | ||
port: 9876, | ||
reporters: ['dots'], | ||
logLevel: config.LOG_DISABLE, | ||
singleRun: true | ||
}); | ||
}; |
/*! | ||
* jQuery Raty - A Star Rating Plugin | ||
* Raty - A Star Rating Plugin | ||
* | ||
@@ -8,643 +8,712 @@ * The MIT License | ||
* github: wbotelhos/raty | ||
* version: 2.9.0 | ||
* version: 3.0.0 | ||
* | ||
*/ | ||
(function($) { | ||
(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define(['jquery'], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
module.exports = factory(require('jquery')); | ||
} else { | ||
factory(root.jQuery); | ||
} | ||
}(this, function($) { | ||
'use strict'; | ||
var methods = { | ||
init: function(options) { | ||
return this.each(function() { | ||
this.self = $(this); | ||
$.raty = { | ||
cancelButton: false, | ||
cancelClass: 'raty-cancel', | ||
cancelHint: 'Cancel this rating!', | ||
cancelOff: 'cancel-off.png', | ||
cancelOn: 'cancel-on.png', | ||
cancelPlace: 'left', | ||
click: undefined, | ||
half: false, | ||
halfShow: true, | ||
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous'], | ||
iconRange: undefined, | ||
mouseout: undefined, | ||
mouseover: undefined, | ||
noRatedMsg: 'Not rated yet!', | ||
number: 5, | ||
numberMax: 20, | ||
path: undefined, | ||
precision: false, | ||
readOnly: false, | ||
round: { down: 0.25, full: 0.6, up: 0.76 }, | ||
score: undefined, | ||
scoreName: 'score', | ||
single: false, | ||
space: true, | ||
starHalf: 'star-half.png', | ||
starOff: 'star-off.png', | ||
starOn: 'star-on.png', | ||
starType: 'img', | ||
target: undefined, | ||
targetFormat: '{score}', | ||
targetKeep: false, | ||
targetScore: undefined, | ||
targetText: '', | ||
targetType: 'hint' | ||
}; | ||
methods.destroy.call(this.self); | ||
$.fn.raty = function(options) { | ||
return this.each(function() { | ||
var instance = new $.raty.Raty(this, options); | ||
this.opt = $.extend(true, {}, $.fn.raty.defaults, options, this.self.data()); | ||
return instance._create(); | ||
}); | ||
}; | ||
methods._adjustCallback.call(this); | ||
methods._adjustNumber.call(this); | ||
methods._adjustHints.call(this); | ||
$.raty.Raty = (function() { | ||
var Raty = function(element, options) { | ||
this.element = element; | ||
this.self = $(element); | ||
this.opt = $.extend(true, {}, $.raty, options, this.self.data()); | ||
}; | ||
this.opt.score = methods._adjustedScore.call(this, this.opt.score); | ||
Raty.prototype = { | ||
_create: function() { | ||
this._executeCallbacks(); | ||
this._adjustNumber(); | ||
this._adjustHints(); | ||
this.opt.score = this._adjustedScore(this.opt.score); | ||
if (this.opt.starType !== 'img') { | ||
methods._adjustStarType.call(this); | ||
this._adjustStarName(); | ||
} | ||
methods._adjustPath.call(this); | ||
methods._createStars.call(this); | ||
this._setPath(); | ||
this._createStars(); | ||
if (this.opt.cancel) { | ||
methods._createCancel.call(this); | ||
if (this.opt.cancelButton) { | ||
this._createCancel(); | ||
} | ||
if (this.opt.precision) { | ||
methods._adjustPrecision.call(this); | ||
this._adjustPrecision(); | ||
} | ||
methods._createScore.call(this); | ||
methods._apply.call(this, this.opt.score); | ||
methods._setTitle.call(this, this.opt.score); | ||
methods._target.call(this, this.opt.score); | ||
this._createScore(); | ||
this._apply(this.opt.score); | ||
this._setTitle(this.opt.score); | ||
this._target(this.opt.score); | ||
if (this.opt.readOnly) { | ||
methods._lock.call(this); | ||
this._lock(); | ||
} else { | ||
this.style.cursor = 'pointer'; | ||
this.element.style.cursor = 'pointer'; | ||
methods._binds.call(this); | ||
this._binds(); | ||
} | ||
}); | ||
}, | ||
_adjustCallback: function() { | ||
var options = ['number', 'readOnly', 'score', 'scoreName', 'target', 'path']; | ||
this.self.data('raty', this); | ||
}, | ||
for (var i = 0; i < options.length; i++) { | ||
if (typeof this.opt[options[i]] === 'function') { | ||
this.opt[options[i]] = this.opt[options[i]].call(this); | ||
// TODO: model spec | ||
_adjustedScore: function(score) { | ||
if (score || score === 0) { | ||
return this._between(score, 0, this.opt.number); | ||
} | ||
} | ||
}, | ||
}, | ||
_adjustedScore: function(score) { | ||
if (!score) { | ||
return score; | ||
} | ||
_adjustHints: function() { | ||
if (!this.opt.hints) { | ||
this.opt.hints = []; | ||
} | ||
return methods._between(score, 0, this.opt.number); | ||
}, | ||
if (!this.opt.halfShow && !this.opt.half) { | ||
return; | ||
} | ||
_adjustHints: function() { | ||
if (!this.opt.hints) { | ||
this.opt.hints = []; | ||
} | ||
var steps = this.opt.precision ? 10 : 2; | ||
if (!this.opt.halfShow && !this.opt.half) { | ||
return; | ||
} | ||
for (var i = 0; i < this.opt.number; i++) { | ||
var group = this.opt.hints[i]; | ||
var steps = this.opt.precision ? 10 : 2; | ||
if (Object.prototype.toString.call(group) !== '[object Array]') { | ||
group = [group]; | ||
} | ||
for (var i = 0; i < this.opt.number; i++) { | ||
var group = this.opt.hints[i]; | ||
this.opt.hints[i] = []; | ||
if (Object.prototype.toString.call(group) !== '[object Array]') { | ||
group = [group]; | ||
for (var j = 0; j < steps; j++) { | ||
var hint = group[j]; | ||
var last = group[group.length - 1]; | ||
if (last === undefined) { | ||
last = null; | ||
} | ||
this.opt.hints[i][j] = hint === undefined ? last : hint; | ||
} | ||
} | ||
}, | ||
this.opt.hints[i] = []; | ||
_adjustNumber: function() { | ||
this.opt.number = this._between(this.opt.number, 1, this.opt.numberMax); | ||
}, | ||
for (var j = 0; j < steps; j++) { | ||
var | ||
hint = group[j], | ||
last = group[group.length - 1]; | ||
_adjustPrecision: function() { | ||
this.opt.half = true; | ||
}, | ||
if (last === undefined) { | ||
last = null; | ||
} | ||
_adjustStarName: function() { | ||
var replaces = ['cancelOff', 'cancelOn', 'starHalf', 'starOff', 'starOn']; | ||
this.opt.hints[i][j] = hint === undefined ? last : hint; | ||
this.opt.path = ''; | ||
for (var i = 0; i < replaces.length; i++) { | ||
this.opt[replaces[i]] = this.opt[replaces[i]].replace('.', '-'); | ||
} | ||
} | ||
}, | ||
}, | ||
_adjustNumber: function() { | ||
this.opt.number = methods._between(this.opt.number, 1, this.opt.numberMax); | ||
}, | ||
// TODO: model spec | ||
_apply: function(score) { | ||
this._fill(score); | ||
_adjustPath: function() { | ||
this.opt.path = this.opt.path || ''; | ||
if (score) { | ||
if (score > 0) { | ||
this.scoreField.val(score); | ||
} | ||
if (this.opt.path && this.opt.path.charAt(this.opt.path.length - 1) !== '/') { | ||
this.opt.path += '/'; | ||
} | ||
}, | ||
this._roundStars(score); | ||
} | ||
}, | ||
_adjustPrecision: function() { | ||
this.opt.half = true; | ||
}, | ||
_attributesForIndex: function(i) { | ||
var name = this._nameForIndex(i); | ||
var attributes = { alt: i, src: this.opt.path + this.opt[name] }; | ||
_adjustStarType: function() { | ||
var replaces = ['cancelOff', 'cancelOn', 'starHalf', 'starOff', 'starOn']; | ||
if (this.opt.starType !== 'img') { | ||
attributes = { 'data-alt': i, 'class': this.opt[name] }; | ||
} | ||
this.opt.path = ''; | ||
attributes.title = this._getHint(i); | ||
for (var i = 0; i < replaces.length; i++) { | ||
this.opt[replaces[i]] = this.opt[replaces[i]].replace('.', '-'); | ||
} | ||
}, | ||
return attributes; | ||
}, | ||
_apply: function(score) { | ||
methods._fill.call(this, score); | ||
_between: function(value, min, max) { | ||
return Math.min(Math.max(parseFloat(value), min), max); | ||
}, | ||
if (score) { | ||
if (score > 0) { | ||
this.score.val(score); | ||
// TODO: model spec | ||
_binds: function() { | ||
if (this.cancelButton) { | ||
this._bindOverCancel(); | ||
this._bindClickCancel(); | ||
this._bindOutCancel(); | ||
} | ||
methods._roundStars.call(this, score); | ||
} | ||
}, | ||
this._bindOver(); | ||
this._bindClick(); | ||
this._bindOut(); | ||
}, | ||
_between: function(value, min, max) { | ||
return Math.min(Math.max(parseFloat(value), min), max); | ||
}, | ||
// TODO: model spec | ||
_bindClick: function() { | ||
var that = this; | ||
_binds: function() { | ||
if (this.cancel) { | ||
methods._bindOverCancel.call(this); | ||
methods._bindClickCancel.call(this); | ||
methods._bindOutCancel.call(this); | ||
} | ||
this.stars.on('click.raty', function(evt) { | ||
if (that.self.data('readonly')) { | ||
return; | ||
} | ||
methods._bindOver.call(this); | ||
methods._bindClick.call(this); | ||
methods._bindOut.call(this); | ||
}, | ||
var execute = true; | ||
var score = (that.opt.half || that.opt.precision) ? that.self.data('score') : (this.alt || $(this).data('alt')); | ||
_bindClick: function() { | ||
var that = this; | ||
if (that.opt.half && !that.opt.precision) { | ||
score = that._roundHalfScore(score); | ||
} | ||
that.stars.on('click.raty', function(evt) { | ||
var | ||
execute = true, | ||
score = (that.opt.half || that.opt.precision) ? that.self.data('score') : (this.alt || $(this).data('alt')); | ||
if (that.opt.click) { | ||
execute = that.opt.click.call(that.element, +score, evt); | ||
} | ||
if (that.opt.click) { | ||
execute = that.opt.click.call(that, +score, evt); | ||
} | ||
if (execute || execute === undefined) { | ||
that._apply(+score); | ||
} | ||
}); | ||
}, | ||
if (execute || execute === undefined) { | ||
if (that.opt.half && !that.opt.precision) { | ||
score = methods._roundHalfScore.call(that, score); | ||
// TODO: model spec | ||
_bindClickCancel: function() { | ||
this.cancelButton.on('click.raty', function(evt) { | ||
this.scoreField.removeAttr('value'); | ||
if (this.opt.click) { | ||
this.opt.click.call(this.element, null, evt); | ||
} | ||
}.bind(this)); | ||
}, | ||
methods._apply.call(that, score); | ||
} | ||
}); | ||
}, | ||
// TODO: model spec | ||
_bindOut: function() { | ||
this.self.on('mouseleave.raty', function(evt) { | ||
var score = +this.scoreField.val() || undefined; | ||
_bindClickCancel: function() { | ||
var that = this; | ||
this._apply(score); | ||
this._target(score, evt); | ||
this._resetTitle(); | ||
that.cancel.on('click.raty', function(evt) { | ||
that.score.removeAttr('value'); | ||
if (this.opt.mouseout) { | ||
this.opt.mouseout.call(this.element, score, evt); | ||
} | ||
}.bind(this)); | ||
}, | ||
if (that.opt.click) { | ||
that.opt.click.call(that, null, evt); | ||
} | ||
}); | ||
}, | ||
// TODO: model spec | ||
_bindOutCancel: function() { | ||
var that = this; | ||
_bindOut: function() { | ||
var that = this; | ||
this.cancelButton.on('mouseleave.raty', function(evt) { | ||
var icon = that.opt.cancelOff; | ||
that.self.on('mouseleave.raty', function(evt) { | ||
var score = +that.score.val() || undefined; | ||
if (that.opt.starType !== 'img') { | ||
icon = that.opt.cancelClass + ' ' + icon; | ||
} | ||
methods._apply.call(that, score); | ||
methods._target.call(that, score, evt); | ||
methods._resetTitle.call(that); | ||
that._setIcon(this, icon); | ||
if (that.opt.mouseout) { | ||
that.opt.mouseout.call(that, score, evt); | ||
} | ||
}); | ||
}, | ||
if (that.opt.mouseout) { | ||
var score = +that.scoreField.val() || undefined; | ||
_bindOutCancel: function() { | ||
var that = this; | ||
that.opt.mouseout.call(that.element, score, evt); | ||
} | ||
}); | ||
}, | ||
that.cancel.on('mouseleave.raty', function(evt) { | ||
var icon = that.opt.cancelOff; | ||
// TODO: model spec | ||
_bindOver: function() { | ||
var that = this; | ||
var action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty'; | ||
if (that.opt.starType !== 'img') { | ||
icon = that.opt.cancelClass + ' ' + icon; | ||
} | ||
this.stars.on(action, function(evt) { | ||
var score = that._getScoreByPosition(evt, this); | ||
methods._setIcon.call(that, this, icon); | ||
that._fill(score); | ||
if (that.opt.mouseout) { | ||
var score = +that.score.val() || undefined; | ||
if (that.opt.half) { | ||
that._roundStars(score, evt); | ||
that._setTitle(score, evt); | ||
that.opt.mouseout.call(that, score, evt); | ||
} | ||
}); | ||
}, | ||
that.self.data('score', score); | ||
} | ||
_bindOver: function() { | ||
var | ||
that = this, | ||
action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty'; | ||
that._target(score, evt); | ||
that.stars.on(action, function(evt) { | ||
var score = methods._getScoreByPosition.call(that, evt, this); | ||
if (that.opt.mouseover) { | ||
that.opt.mouseover.call(that.element, score, evt); | ||
} | ||
}); | ||
}, | ||
methods._fill.call(that, score); | ||
// TODO: model spec | ||
_bindOverCancel: function() { | ||
var that = this; | ||
if (that.opt.half) { | ||
methods._roundStars.call(that, score, evt); | ||
methods._setTitle.call(that, score, evt); | ||
this.cancelButton.on('mouseover.raty', function(evt) { | ||
if (that.self.data('readonly')) { | ||
return; | ||
} | ||
that.self.data('score', score); | ||
} | ||
var starOff = that.opt.path + that.opt.starOff; | ||
var icon = that.opt.cancelOn; | ||
methods._target.call(that, score, evt); | ||
if (that.opt.starType === 'img') { | ||
that.stars.attr('src', starOff); | ||
} else { | ||
icon = that.opt.cancelClass + ' ' + icon; | ||
if (that.opt.mouseover) { | ||
that.opt.mouseover.call(that, score, evt); | ||
} | ||
}); | ||
}, | ||
that.stars.attr('class', starOff); | ||
} | ||
_bindOverCancel: function() { | ||
var that = this; | ||
that._setIcon(this, icon); | ||
that._target(null, evt); | ||
that.cancel.on('mouseover.raty', function(evt) { | ||
var | ||
starOff = that.opt.path + that.opt.starOff, | ||
icon = that.opt.cancelOn; | ||
if (that.opt.mouseover) { | ||
that.opt.mouseover.call(that.element, null); | ||
} | ||
}); | ||
}, | ||
if (that.opt.starType === 'img') { | ||
that.stars.attr('src', starOff); | ||
// TODO: model spec | ||
_buildScoreField: function() { | ||
return $('<input />', { name: this.opt.scoreName, type: 'hidden' }).appendTo(this.self); | ||
}, | ||
// TODO: model spec | ||
_createCancel: function() { | ||
var icon = this.opt.path + this.opt.cancelOff; | ||
var button = $('<' + this.opt.starType + ' />', { title: this.opt.cancelHint, 'class': this.opt.cancelClass }); | ||
if (this.opt.starType === 'img') { | ||
button.attr({ src: icon, alt: 'x' }); | ||
} else { | ||
icon = that.opt.cancelClass + ' ' + icon; | ||
that.stars.attr('class', starOff); | ||
// TODO: use $.data | ||
button.attr('data-alt', 'x').addClass(icon); | ||
} | ||
methods._setIcon.call(that, this, icon); | ||
methods._target.call(that, null, evt); | ||
if (that.opt.mouseover) { | ||
that.opt.mouseover.call(that, null); | ||
if (this.opt.cancelPlace === 'left') { | ||
this.self.prepend(' ').prepend(button); | ||
} else { | ||
this.self.append(' ').append(button); | ||
} | ||
}); | ||
}, | ||
_buildScoreField: function() { | ||
return $('<input />', { name: this.opt.scoreName, type: 'hidden' }).appendTo(this); | ||
}, | ||
this.cancelButton = button; | ||
}, | ||
_createCancel: function() { | ||
var | ||
icon = this.opt.path + this.opt.cancelOff, | ||
cancel = $('<' + this.opt.starType + ' />', { title: this.opt.cancelHint, 'class': this.opt.cancelClass }); | ||
// TODO: model spec | ||
_createScore: function() { | ||
var score = $(this.opt.targetScore); | ||
if (this.opt.starType === 'img') { | ||
cancel.attr({ src: icon, alt: 'x' }); | ||
} else { | ||
// TODO: use $.data | ||
cancel.attr('data-alt', 'x').addClass(icon); | ||
} | ||
this.scoreField = score.length ? score : this._buildScoreField(); | ||
}, | ||
if (this.opt.cancelPlace === 'left') { | ||
this.self.prepend(' ').prepend(cancel); | ||
} else { | ||
this.self.append(' ').append(cancel); | ||
} | ||
_createStars: function() { | ||
for (var i = 1; i <= this.opt.number; i++) { | ||
var attributes = this._attributesForIndex(i); | ||
this.cancel = cancel; | ||
}, | ||
$('<' + this.opt.starType + ' />', attributes).appendTo(this.element); | ||
_createScore: function() { | ||
var score = $(this.opt.targetScore); | ||
if (this.opt.space && i < this.opt.number) { | ||
this.self.append(' '); | ||
} | ||
} | ||
this.score = score.length ? score : methods._buildScoreField.call(this); | ||
}, | ||
this.stars = this.self.children(this.opt.starType); | ||
}, | ||
_createStars: function() { | ||
for (var i = 1; i <= this.opt.number; i++) { | ||
var | ||
name = methods._nameForIndex.call(this, i), | ||
attrs = { alt: i, src: this.opt.path + this.opt[name] }; | ||
// TODO: model spec | ||
_error: function(message) { | ||
$(this).text(message); | ||
if (this.opt.starType !== 'img') { | ||
attrs = { 'data-alt': i, 'class': attrs.src }; // TODO: use $.data. | ||
} | ||
$.error(message); | ||
}, | ||
attrs.title = methods._getHint.call(this, i); | ||
_executeCallbacks: function() { | ||
var options = ['number', 'readOnly', 'score', 'scoreName', 'target', 'path']; | ||
$('<' + this.opt.starType + ' />', attrs).appendTo(this); | ||
for (var i = 0; i < options.length; i++) { | ||
if (typeof this.opt[options[i]] === 'function') { | ||
var value = this.opt[options[i]].call(this.element); | ||
if (this.opt.space) { | ||
this.self.append(i < this.opt.number ? ' ' : ''); | ||
if (value) { | ||
this.opt[options[i]] = value; | ||
} else { | ||
delete this.opt[options[i]]; | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
this.stars = this.self.children(this.opt.starType); | ||
}, | ||
// TODO: model spec | ||
_fill: function(score) { | ||
var hash = 0; | ||
_error: function(message) { | ||
$(this).text(message); | ||
for (var i = 1; i <= this.stars.length; i++) { | ||
var icon; | ||
var star = this.stars[i - 1]; | ||
var turnOn = this._turnOn(i, score); | ||
$.error(message); | ||
}, | ||
if (this.opt.iconRange && this.opt.iconRange.length > hash) { | ||
var irange = this.opt.iconRange[hash]; | ||
_fill: function(score) { | ||
var hash = 0; | ||
icon = this._getRangeIcon(irange, turnOn); | ||
for (var i = 1; i <= this.stars.length; i++) { | ||
var | ||
icon, | ||
star = this.stars[i - 1], | ||
turnOn = methods._turnOn.call(this, i, score); | ||
if (i <= irange.range) { | ||
this._setIcon(star, icon); | ||
} | ||
if (this.opt.iconRange && this.opt.iconRange.length > hash) { | ||
var irange = this.opt.iconRange[hash]; | ||
if (i === irange.range) { | ||
hash++; | ||
} | ||
} else { | ||
icon = this.opt[turnOn ? 'starOn' : 'starOff']; | ||
icon = methods._getRangeIcon.call(this, irange, turnOn); | ||
if (i <= irange.range) { | ||
methods._setIcon.call(this, star, icon); | ||
this._setIcon(star, icon); | ||
} | ||
} | ||
}, | ||
if (i === irange.range) { | ||
hash++; | ||
_getDecimal: function(number, fractions) { | ||
var decimal = number.toString().split('.')[1]; | ||
var result = 0; | ||
if (decimal) { | ||
result = parseInt(decimal.slice(0, fractions), 10); | ||
if (decimal.slice(1, 5) === '9999') { | ||
result++; | ||
} | ||
} else { | ||
icon = this.opt[turnOn ? 'starOn' : 'starOff']; | ||
methods._setIcon.call(this, star, icon); | ||
} | ||
} | ||
}, | ||
_getFirstDecimal: function(number) { | ||
var | ||
decimal = number.toString().split('.')[1], | ||
result = 0; | ||
return result; | ||
}, | ||
if (decimal) { | ||
result = parseInt(decimal.charAt(0), 10); | ||
// TODO: model spec | ||
_getRangeIcon: function(irange, turnOn) { | ||
return turnOn ? irange.on || this.opt.starOn : irange.off || this.opt.starOff; | ||
}, | ||
if (decimal.slice(1, 5) === '9999') { | ||
result++; | ||
// TODO: model spec | ||
_getScoreByPosition: function(evt, icon) { | ||
var score = parseInt(icon.alt || icon.getAttribute('data-alt'), 10); | ||
if (this.opt.half) { | ||
var size = this._getWidth(); | ||
var percent = parseFloat((evt.pageX - $(icon).offset().left) / size); | ||
score = score - 1 + percent; | ||
} | ||
} | ||
return result; | ||
}, | ||
return score; | ||
}, | ||
_getRangeIcon: function(irange, turnOn) { | ||
return turnOn ? irange.on || this.opt.starOn : irange.off || this.opt.starOff; | ||
}, | ||
// TODO: model spec | ||
_getHint: function(score, evt) { | ||
if (score !== 0 && !score) { | ||
return this.opt.noRatedMsg; | ||
} | ||
_getScoreByPosition: function(evt, icon) { | ||
var score = parseInt(icon.alt || icon.getAttribute('data-alt'), 10); | ||
var decimal = this._getDecimal(score, 1); | ||
var integer = Math.ceil(score); | ||
var group = this.opt.hints[(integer || 1) - 1]; | ||
var hint = group; | ||
var set = !evt || this.isMove; | ||
if (this.opt.half) { | ||
var | ||
size = methods._getWidth.call(this), | ||
percent = parseFloat((evt.pageX - $(icon).offset().left) / size); | ||
if (this.opt.precision) { | ||
if (set) { | ||
decimal = decimal === 0 ? 9 : decimal - 1; | ||
} | ||
score = score - 1 + percent; | ||
} | ||
hint = group[decimal]; | ||
} else if (this.opt.halfShow || this.opt.half) { | ||
decimal = set && decimal === 0 ? 1 : decimal > 5 ? 1 : 0; | ||
return score; | ||
}, | ||
hint = group[decimal]; | ||
} | ||
_getHint: function(score, evt) { | ||
if (score !== 0 && !score) { | ||
return this.opt.noRatedMsg; | ||
} | ||
return hint === '' ? '' : hint || score; | ||
}, | ||
var | ||
decimal = methods._getFirstDecimal.call(this, score), | ||
integer = Math.ceil(score), | ||
group = this.opt.hints[(integer || 1) - 1], | ||
hint = group, | ||
set = !evt || this.move; | ||
// TODO: model spec | ||
_getWidth: function() { | ||
var width = this.stars[0].width || parseFloat(this.stars.eq(0).css('font-size')); | ||
if (this.opt.precision) { | ||
if (set) { | ||
decimal = decimal === 0 ? 9 : decimal - 1; | ||
if (!width) { | ||
this._error('Could not get the icon width!'); | ||
} | ||
hint = group[decimal]; | ||
} else if (this.opt.halfShow || this.opt.half) { | ||
decimal = set && decimal === 0 ? 1 : decimal > 5 ? 1 : 0; | ||
return width; | ||
}, | ||
hint = group[decimal]; | ||
} | ||
// TODO: model spec | ||
_lock: function() { | ||
var hint = this._getHint(this.scoreField.val()); | ||
return hint === '' ? '' : hint || score; | ||
}, | ||
this.element.style.cursor = ''; | ||
this.element.title = hint; | ||
_getWidth: function() { | ||
var width = this.stars[0].width || parseFloat(this.stars.eq(0).css('font-size')); | ||
this.scoreField.prop('readonly', true); | ||
this.stars.prop('title', hint); | ||
if (!width) { | ||
methods._error.call(this, 'Could not get the icon width!'); | ||
} | ||
if (this.cancelButton) { | ||
this.cancelButton.hide(); | ||
} | ||
return width; | ||
}, | ||
this.self.data('readonly', true); | ||
}, | ||
_lock: function() { | ||
var hint = methods._getHint.call(this, this.score.val()); | ||
_nameForIndex: function(i) { | ||
return this.opt.score && this.opt.score >= i ? 'starOn' : 'starOff'; | ||
}, | ||
this.style.cursor = ''; | ||
this.title = hint; | ||
// TODO: model spec | ||
_resetTitle: function() { | ||
for (var i = 0; i < this.opt.number; i++) { | ||
this.stars[i].title = this._getHint(i + 1); | ||
} | ||
}, | ||
this.score.prop('readonly', true); | ||
this.stars.prop('title', hint); | ||
// TODO: model spec | ||
_roundHalfScore: function(score) { | ||
var integer = parseInt(score, 10); | ||
var decimal = this._getDecimal(score, 1); | ||
if (this.cancel) { | ||
this.cancel.hide(); | ||
} | ||
if (decimal !== 0) { | ||
decimal = decimal > 5 ? 1 : 0.5; | ||
} | ||
this.self.data('readonly', true); | ||
}, | ||
return integer + decimal; | ||
}, | ||
_nameForIndex: function(i) { | ||
return this.opt.score && this.opt.score >= i ? 'starOn' : 'starOff'; | ||
}, | ||
// TODO: model spec | ||
_roundStars: function(score, evt) { | ||
var name = this._starName(score, evt); | ||
_resetTitle: function() { | ||
for (var i = 0; i < this.opt.number; i++) { | ||
this.stars[i].title = methods._getHint.call(this, i + 1); | ||
} | ||
}, | ||
if (name) { | ||
var icon = this.opt[name]; | ||
var star = this.stars[Math.ceil(score) - 1]; | ||
_roundHalfScore: function(score) { | ||
var | ||
integer = parseInt(score, 10), | ||
decimal = methods._getFirstDecimal.call(this, score); | ||
this._setIcon(star, icon); | ||
} // Full down: [x.00 .. x.25] | ||
}, | ||
if (decimal !== 0) { | ||
decimal = decimal > 5 ? 1 : 0.5; | ||
} | ||
// TODO: model spec | ||
_setIcon: function(star, icon) { | ||
star[this.opt.starType === 'img' ? 'src' : 'className'] = this.opt.path + icon; | ||
}, | ||
return integer + decimal; | ||
}, | ||
_setPath: function() { | ||
this.opt.path = this.opt.path || ''; | ||
_roundStars: function(score, evt) { | ||
var | ||
decimal = (score % 1).toFixed(2), | ||
name ; | ||
if (this.opt.path && this.opt.path.slice(-1)[0] !== '/') { | ||
this.opt.path += '/'; | ||
} | ||
}, | ||
if (evt || this.move) { | ||
name = decimal > 0.5 ? 'starOn' : 'starHalf'; | ||
} else if (decimal > this.opt.round.down) { // Up: [x.76 .. x.99] | ||
name = 'starOn'; | ||
// TODO: model spec | ||
_setTarget: function(target, score) { | ||
if (score) { | ||
score = this.opt.targetFormat.toString().replace('{score}', score); | ||
} | ||
if (this.opt.halfShow && decimal < this.opt.round.up) { // Half: [x.26 .. x.75] | ||
name = 'starHalf'; | ||
} else if (decimal < this.opt.round.full) { // Down: [x.00 .. x.5] | ||
name = 'starOff'; | ||
if (target.is(':input')) { | ||
target.val(score); | ||
} else { | ||
target.html(score); | ||
} | ||
} | ||
}, | ||
if (name) { | ||
var | ||
icon = this.opt[name], | ||
star = this.stars[Math.ceil(score) - 1]; | ||
// TODO: model spec | ||
_setTitle: function(score, evt) { | ||
if (score) { | ||
var integer = parseInt(Math.ceil(score), 10); | ||
var star = this.stars[integer - 1]; | ||
methods._setIcon.call(this, star, icon); | ||
} // Full down: [x.00 .. x.25] | ||
}, | ||
star.title = this._getHint(score, evt); | ||
} | ||
}, | ||
_setIcon: function(star, icon) { | ||
star[this.opt.starType === 'img' ? 'src' : 'className'] = this.opt.path + icon; | ||
}, | ||
_starName: function(score, evt) { | ||
var decimal = +(score % 1).toFixed(2); | ||
_setTarget: function(target, score) { | ||
if (score) { | ||
score = this.opt.targetFormat.toString().replace('{score}', score); | ||
} | ||
if (evt || this.isMove) { | ||
return decimal > 0.5 ? 'starOn' : 'starHalf'; | ||
} | ||
if (target.is(':input')) { | ||
target.val(score); | ||
} else { | ||
target.html(score); | ||
} | ||
}, | ||
if (decimal <= this.opt.round.down) { // Down: [x.00 ... x.25] | ||
return; | ||
} | ||
_setTitle: function(score, evt) { | ||
if (score) { | ||
var | ||
integer = parseInt(Math.ceil(score), 10), | ||
star = this.stars[integer - 1]; | ||
if (this.opt.halfShow && decimal < this.opt.round.up) { // Half: [x.26 ... x.75] | ||
return 'starHalf'; | ||
} | ||
star.title = methods._getHint.call(this, score, evt); | ||
} | ||
}, | ||
if (decimal < this.opt.round.full) { // Off: [x.26 .. x.6] | ||
return 'starOff'; | ||
} | ||
_target: function(score, evt) { | ||
if (this.opt.target) { | ||
var target = $(this.opt.target); | ||
return 'starOn'; // Up: [x.26 ...] || [x.6 ...] | ||
}, | ||
if (!target.length) { | ||
methods._error.call(this, 'Target selector invalid or missing!'); | ||
} | ||
// TODO: model spec | ||
_target: function(score, evt) { | ||
if (this.opt.target) { | ||
var target = $(this.opt.target); | ||
var mouseover = evt && evt.type === 'mouseover'; | ||
if (score === undefined) { | ||
score = this.opt.targetText; | ||
} else if (score === null) { | ||
score = mouseover ? this.opt.cancelHint : this.opt.targetText; | ||
} else { | ||
if (this.opt.targetType === 'hint') { | ||
score = methods._getHint.call(this, score, evt); | ||
} else if (this.opt.precision) { | ||
score = parseFloat(score).toFixed(1); | ||
if (!target.length) { | ||
this._error('Target selector invalid or missing!'); | ||
} | ||
var mousemove = evt && evt.type === 'mousemove'; | ||
var mouseover = evt && evt.type === 'mouseover'; | ||
if (!mouseover && !mousemove && !this.opt.targetKeep) { | ||
if (score === undefined) { | ||
score = this.opt.targetText; | ||
} else if (score === null) { | ||
score = mouseover ? this.opt.cancelHint : this.opt.targetText; | ||
} else { | ||
if (this.opt.targetType === 'hint') { | ||
score = this._getHint(score, evt); | ||
} else if (this.opt.precision) { | ||
score = parseFloat(score).toFixed(1); | ||
} | ||
var mousemove = evt && evt.type === 'mousemove'; | ||
if (!mouseover && !mousemove && !this.opt.targetKeep) { | ||
score = this.opt.targetText; | ||
} | ||
} | ||
this._setTarget(target, score); | ||
} | ||
}, | ||
methods._setTarget.call(this, target, score); | ||
} | ||
}, | ||
// TODO: model spec | ||
_turnOn: function(i, score) { | ||
return this.opt.single ? (i === score) : (i <= score); | ||
}, | ||
_turnOn: function(i, score) { | ||
return this.opt.single ? (i === score) : (i <= score); | ||
}, | ||
// TODO: model spec | ||
_unlock: function() { | ||
this.element.style.cursor = 'pointer'; | ||
this.element.removeAttribute('title'); | ||
_unlock: function() { | ||
this.style.cursor = 'pointer'; | ||
this.removeAttribute('title'); | ||
this.scoreField.removeAttr('readonly'); | ||
this.score.removeAttr('readonly'); | ||
this.self.data('readonly', false); | ||
this.self.data('readonly', false); | ||
this._resetTitle(); | ||
for (var i = 0; i < this.opt.number; i++) { | ||
this.stars[i].title = methods._getHint.call(this, i + 1); | ||
} | ||
if (this.cancelButton) { | ||
this.cancelButton.css('display', ''); | ||
} | ||
}, | ||
if (this.cancel) { | ||
this.cancel.css('display', ''); | ||
} | ||
}, | ||
// TODO: model spec | ||
cancel: function(click) { | ||
if (this.self.data('readonly') !== true) { | ||
this[click ? 'click' : 'score'].call(this, null); | ||
cancel: function(click) { | ||
return this.each(function() { | ||
var self = $(this); | ||
if (self.data('readonly') !== true) { | ||
methods[click ? 'click' : 'score'].call(self, null); | ||
this.score.removeAttr('value'); | ||
this.scoreField.removeAttr('value'); | ||
} | ||
}); | ||
}, | ||
}, | ||
click: function(score) { | ||
return this.each(function() { | ||
if ($(this).data('readonly') !== true) { | ||
score = methods._adjustedScore.call(this, score); | ||
// TODO: model spec | ||
click: function(score) { | ||
if (this.self.data('readonly') !== true) { | ||
score = this._adjustedScore(score); | ||
methods._apply.call(this, score); | ||
this._apply(score); | ||
if (this.opt.click) { | ||
this.opt.click.call(this, score, $.Event('click')); | ||
this.opt.click.call(this.element, score, $.Event('click')); | ||
} | ||
methods._target.call(this, score); | ||
this._target(score); | ||
} | ||
}); | ||
}, | ||
}, | ||
destroy: function() { | ||
return this.each(function() { | ||
var | ||
self = $(this), | ||
raw = self.data('raw'); | ||
// TODO: model spec | ||
getScore: function() { | ||
var score = []; | ||
var value ; | ||
if (raw) { | ||
self.off('.raty').empty().css({ cursor: raw.style.cursor }).removeData('readonly'); | ||
} else { | ||
self.data('raw', self.clone()[0]); | ||
} | ||
}); | ||
}, | ||
value = this.scoreField.val(); | ||
getScore: function() { | ||
var | ||
score = [], | ||
value ; | ||
this.each(function() { | ||
value = this.score.val(); | ||
score.push(value ? +value : undefined); | ||
}); | ||
return (score.length > 1) ? score : score[0]; | ||
}, | ||
return (score.length > 1) ? score : score[0]; | ||
}, | ||
move: function(score) { | ||
return this.each(function() { | ||
var | ||
integer = parseInt(score, 10), | ||
decimal = methods._getFirstDecimal.call(this, score); | ||
// TODO: model spec | ||
move: function(score) { | ||
var integer = parseInt(score, 10); | ||
var decimal = this._getDecimal(score, 1); | ||
@@ -656,110 +725,48 @@ if (integer >= this.opt.number) { | ||
var | ||
width = methods._getWidth.call(this), | ||
steps = width / 10, | ||
star = $(this.stars[integer]), | ||
percent = star.offset().left + steps * decimal, | ||
evt = $.Event('mousemove', { pageX: percent }); | ||
var width = this._getWidth(); | ||
var steps = width / 10; | ||
var star = $(this.stars[integer]); | ||
var percent = star.offset().left + steps * decimal; | ||
var evt = $.Event('mousemove', { pageX: percent }); | ||
this.move = true; | ||
this.isMove = true; | ||
star.trigger(evt); | ||
this.move = false; | ||
}); | ||
}, | ||
this.isMove = false; | ||
}, | ||
readOnly: function(readonly) { | ||
return this.each(function() { | ||
var self = $(this); | ||
if (self.data('readonly') !== readonly) { | ||
// TODO: model spec | ||
readOnly: function(readonly) { | ||
if (this.self.data('readonly') !== readonly) { | ||
if (readonly) { | ||
self.off('.raty').children(this.opt.starType).off('.raty'); | ||
this.self.off('.raty').children(this.opt.starType).off('.raty'); | ||
methods._lock.call(this); | ||
this._lock(); | ||
} else { | ||
methods._binds.call(this); | ||
methods._unlock.call(this); | ||
this._binds(); | ||
this._unlock(); | ||
} | ||
self.data('readonly', readonly); | ||
this.self.data('readonly', readonly); | ||
} | ||
}); | ||
}, | ||
}, | ||
reload: function() { | ||
return methods.set.call(this, {}); | ||
}, | ||
// TODO: model spec | ||
score: function() { | ||
return arguments.length ? this.setScore.apply(this, arguments) : this.getScore(); | ||
}, | ||
score: function() { | ||
var self = $(this); | ||
setScore: function(score) { | ||
if (this.self.data('readonly') !== true) { | ||
score = this._adjustedScore(score); | ||
return arguments.length ? methods.setScore.apply(self, arguments) : methods.getScore.call(self); | ||
}, | ||
set: function(options) { | ||
return this.each(function() { | ||
$(this).raty($.extend({}, this.opt, options)); | ||
}); | ||
}, | ||
setScore: function(score) { | ||
return this.each(function() { | ||
if ($(this).data('readonly') !== true) { | ||
score = methods._adjustedScore.call(this, score); | ||
methods._apply.call(this, score); | ||
methods._target.call(this, score); | ||
this._apply(score); | ||
this._target(score); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
}; | ||
$.fn.raty = function(method) { | ||
if (methods[method]) { | ||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
} else if (typeof method === 'object' || !method) { | ||
return methods.init.apply(this, arguments); | ||
} else { | ||
$.error('Method ' + method + ' does not exist!'); | ||
} | ||
}; | ||
$.fn.raty.defaults = { | ||
cancel: false, | ||
cancelClass: 'raty-cancel', | ||
cancelHint: 'Cancel this rating!', | ||
cancelOff: 'cancel-off.png', | ||
cancelOn: 'cancel-on.png', | ||
cancelPlace: 'left', | ||
click: undefined, | ||
half: false, | ||
halfShow: true, | ||
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous'], | ||
iconRange: undefined, | ||
mouseout: undefined, | ||
mouseover: undefined, | ||
noRatedMsg: 'Not rated yet!', | ||
number: 5, | ||
numberMax: 20, | ||
path: undefined, | ||
precision: false, | ||
readOnly: false, | ||
round: { down: 0.25, full: 0.6, up: 0.76 }, | ||
score: undefined, | ||
scoreName: 'score', | ||
single: false, | ||
space: true, | ||
starHalf: 'star-half.png', | ||
starOff: 'star-off.png', | ||
starOn: 'star-on.png', | ||
starType: 'img', | ||
target: undefined, | ||
targetFormat: '{score}', | ||
targetKeep: false, | ||
targetScore: undefined, | ||
targetText: '', | ||
targetType: 'hint' | ||
}; | ||
})(jQuery); | ||
return Raty; | ||
})(); | ||
})); |
@@ -7,3 +7,3 @@ { | ||
"contributors": [ | ||
"Washington Botelho <wbotelhos@gmail.com> (http://wbotelhos.com)" | ||
"Washington Botelho <wbotelhos@gmail.com> (https://www.wbotelhos.com)" | ||
], | ||
@@ -14,15 +14,12 @@ "demos": [ | ||
"dependencies": { | ||
"jquery": "^3.3.1" | ||
"jquery": "^3.5.1" | ||
}, | ||
"description": "jQuery Raty - A Star Rating Plugin", | ||
"description": "Raty - A Star Rating Plugin", | ||
"devDependencies": { | ||
"jasmine-core": "^2.99.1", | ||
"karma": "^1.7.1", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-ie-launcher": "^1.0.0", | ||
"karma-jasmine": "^1.1.2", | ||
"karma-opera-launcher": "^1.0.0", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-safari-launcher": "^1.0.0" | ||
"eslint": "^7.11.0", | ||
"jasmine-core": "^3.6.0", | ||
"karma": "^5.2.3", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-firefox-launcher": "^1.3.0", | ||
"karma-jasmine": "^4.0.1" | ||
}, | ||
@@ -51,3 +48,3 @@ "directories": { | ||
"maintainers": [ | ||
"Washington Botelho <wbotelhos@gmail.com> (http://wbotelhos.com)" | ||
"Washington Botelho <wbotelhos@gmail.com> (https://www.wbotelhos.com)" | ||
], | ||
@@ -62,3 +59,3 @@ "name": "raty-js", | ||
}, | ||
"version": "2.9.0" | ||
"version": "3.0.0" | ||
} |
105
README.md
@@ -1,7 +0,5 @@ | ||
# jQuery Raty - A Star Rating Plugin | ||
# Raty - A Star Rating Plugin | ||
[![Build Status](https://travis-ci.org/wbotelhos/raty.svg)](https://travis-ci.org/wbotelhos/raty) | ||
[![CI](https://github.com/wbotelhos/raty/workflows/CI/badge.svg?)](https://github.com/wbotelhos/raty/actions?query=workflow%3ACI) | ||
[![NPM Version](https://badge.fury.io/js/raty-js.svg)](https://badge.fury.io/js/raty-js) | ||
[![Dependency](https://david-dm.org/wbotelhos/raty.svg)](https://david-dm.org/wbotelhos/raty) | ||
[![Dev Dependency](https://david-dm.org/wbotelhos/raty/dev-status.svg)](https://david-dm.org/wbotelhos/raty#info=devDependencies) | ||
[![Code Climate](https://codeclimate.com/github/wbotelhos/raty.png)](https://codeclimate.com/github/wbotelhos/raty) | ||
@@ -49,59 +47,48 @@ [![Patreon](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://www.patreon.com/wbotelhos) | ||
```js | ||
cancel: false // Creates a cancel button to cancel the rating. | ||
cancelClass: 'raty-cancel' // Name of cancel's class. | ||
cancelHint: 'Cancel this rating!' // The cancel's button hint. | ||
cancelOff: 'cancel-off.png' // Icon used on active cancel. | ||
cancelOn: 'cancel-on.png' // Icon used inactive cancel. | ||
cancelPlace: 'left' // Cancel's button position. | ||
click: undefined // Callback executed on rating click. | ||
half: false // Enables half star selection. | ||
halfShow: true // Enables half star display. | ||
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous'] // Hints used on each star. | ||
iconRange: undefined // Object list with position and icon on and off to do a mixed icons. | ||
mouseout: undefined // Callback executed on mouseout. | ||
mouseover: undefined // Callback executed on mouseover. | ||
noRatedMsg: 'Not rated yet!' // Hint for no rated elements when it's readOnly. | ||
number: 5 // Number of stars that will be presented. | ||
numberMax: 20 // Max of star the option number can creates. | ||
path: undefined // A global locate where the icon will be looked. | ||
precision: false // Enables the selection of a precision score. | ||
readOnly: false // Turns the rating read-only. | ||
round: { down: .25, full: .6, up: .76 } // Included values attributes to do the score round math. | ||
score: undefined // Initial rating. | ||
scoreName: 'score' // Name of the hidden field that holds the score value. | ||
single: false // Enables just a single star selection. | ||
space: true // Puts space between the icons. | ||
starHalf: 'star-half.png' // The name of the half star image. | ||
starOff: 'star-off.png' // Name of the star image off. | ||
starOn: 'star-on.png' // Name of the star image on. | ||
target: undefined // Element selector where the score will be displayed. | ||
targetForma: '{score}' // Template to interpolate the score in. | ||
targetKeep: false // If the last rating value will be keeped after mouseout. | ||
targetScore: undefined // Element selector where the score will be filled, instead of creating a new hidden field (scoreName option). | ||
targetText: '' // Default text setted on target. | ||
targetType: 'hint' // Option to choose if target will receive hint o 'score' type. | ||
starType: 'img' // Element used to represent a star. | ||
``` | ||
| Property | Default |Description | | ||
|--------------|------------------------------------------------|-----------------------------------------------------------------| | ||
|`cancel` |`false` |Creates a cancel button to cancel the rating. | | ||
|`cancelClass` |`'raty-cancel'` |Name of cancel's class. | | ||
|`cancelHint` |`'Cancel this rating!'` |The cancel's button hint. | | ||
|`cancelOff` |`'cancel-off.png'` |Icon used on active cancel. | | ||
|`cancelOn` |`'cancel-on.png'` |Icon used inactive cancel. | | ||
|`cancelPlace` |`'left'` |Cancel's button position. | | ||
|`click` |`undefined` |Callback executed on rating click. | | ||
|`half` |`false` |Enables half star selection. | | ||
|`halfShow` |`true` |Enables half star display. | | ||
|`hints` |`['bad', 'poor', 'regular', 'good', 'gorgeous']`|Hints used on each star. | | ||
|`iconRange` |`undefined` |Object list with position and icon on and off to do a mixed icons| | ||
|`mouseout` |`undefined` |Callback executed on mouseout. | | ||
|`mouseover` |`undefined` |Callback executed on mouseover. | | ||
|`noRatedMsg` |`'Not rated yet!'` |Hint for non rated elements when it's readOnly. | | ||
|`number` |`5` |The number of stars that will be presented. | | ||
|`numberMax` |`20` |Max number of stars star the option number will create. | | ||
|`path` |`undefined` |A global path where the icon will be found. | | ||
|`precision` |`false` |Enables the selection of a precise score. | | ||
|`readOnly` |`false` |Turns the rating read-only. | | ||
|`round` |`{ down: .25, full: .6, up: .76 }` |Includes value attributes to do the score rounding math. | | ||
|`score` |`undefined` |Initial rating. | | ||
|`scoreName` |`'score'` |Name of the hidden field that holds the score value. | | ||
|`single` |`false` |Enables single star selection. | | ||
|`space` |`true` |Puts space between the icons. | | ||
|`starHalf` |`'star-half.png'` |The name of the half star image. | | ||
|`starOff` |`'star-off.png'` |Name of the star image off. | | ||
|`starOn` |`'star-on.png'` |Name of the star image on. | | ||
|`target` |`undefined` |Element selector where the score will be displayed. | | ||
|`targetFormat`|`'{score}'` |Template to interpolate the score in. | | ||
|`targetKeep` |`false` |If the last rating value will be kept on mouseout. | | ||
|`targetScore` |`undefined` |Score field target avoiding hidden field creation | | ||
|`targetText` |`''` |Default text in a target. | | ||
|`targetType` |`'hint'` |Choose if target will receive a hint or the score number | | ||
|`starType` |`'img'` |Element used to represent a star. | | ||
## Functions | ||
```js | ||
$('div').raty('score'); // Get the current score. | ||
$('div').raty('score', number); // Set the score. | ||
$('div').raty('click', number); // Click on some star. | ||
$('div').raty('readOnly', boolean); // Change the read-only state. | ||
$('div').raty('cancel', boolean); // Cancel the rating. The last param force the click callback. | ||
$('div').raty('reload'); // Reload the rating with the current configuration. | ||
$('div').raty('set', { option: value }); // Reset the rating with new configurations. | ||
$('div').raty('destroy'); // Destroy the bind and give you the raw element. | ||
$('div').raty('move', number); // Move the mouse to the given score point position. | ||
``` | ||
| Function | Description | | ||
|-----------------------------------------|-----------------------------------------------------------| | ||
|`$('div').data('raty).score();` |Get the current score. | | ||
|`$('div').data('raty).score(number);` |Set a score. | | ||
|`$('div').data('raty).click(number);` |Click on a star. | | ||
|`$('div').data('raty).readOnly(boolean);`|Change the read-only state. | | ||
|`$('div').data('raty).cancel(boolean);` |Cancel the rating. The last param force the click callback.| | ||
|`$('div').data('raty).move(number);` |Move the mouse to the given score point position. | |
@@ -1,4 +0,10 @@ | ||
isClear = true; | ||
function context(description, spec) { // eslint-disable-line no-redeclare, no-unused-vars | ||
describe(description, spec); | ||
} | ||
Helper = { | ||
afterEach(function() { | ||
$.raty.path = undefined; | ||
}); | ||
var Helper = { // eslint-disable-line no-redeclare, no-unused-vars | ||
_append: function(type, attrs) { | ||
@@ -47,4 +53,6 @@ return $('<' + type + '/>', attrs).appendTo('body'); | ||
clear: function() { | ||
for (var i = 0; i < this.ids.length; i++) { | ||
$(this.ids[i]).remove(); | ||
if (this.ids) { | ||
for (var i = 0; i < this.ids.length; i++) { | ||
$(this.ids[i]).remove(); | ||
} | ||
} | ||
@@ -56,4 +64,4 @@ }, | ||
var data = this._save(id), | ||
attrs = this._attrs(data, options); | ||
var data = this._save(id); | ||
var attrs = this._attrs(data, options); | ||
@@ -69,15 +77,14 @@ return this._append(type, attrs); | ||
mouseData: function(el, integer, decimal) { | ||
var | ||
stars = el.children('img:not(.raty-cancel)'), | ||
star = stars.eq(integer), | ||
width = star[0].width || parseFloat(star.css('font-size')); | ||
fraction = width / 10, | ||
left = star.offset().left, | ||
pageX = left + fraction * decimal + 0.1; | ||
var stars = el.children('img:not(.raty-cancel)'); | ||
var star = stars.eq(integer); | ||
var width = star[0].width || parseFloat(star.css('font-size')); | ||
var fraction = width / 10; | ||
var left = star.offset().left; | ||
var pageX = left + fraction * decimal + 0.1; | ||
if (console && console.log) { | ||
console.debug(integer + '.' + decimal, ':', 'left:', left, 'width:', width, 'fraction (width/10):', fraction, 'pageX:', pageX, 'fractions (decimal * fraction)', decimal * fraction); | ||
} | ||
// if (console && console.log) { | ||
// console.debug(integer + '.' + decimal, ':', 'left:', left, 'width:', width, 'fraction (width/10):', fraction, 'pageX:', pageX, 'fractions (decimal * fraction)', decimal * fraction); | ||
// } | ||
return { el: star, pageX: pageX } | ||
return { el: star, pageX: pageX }; | ||
}, | ||
@@ -87,4 +94,4 @@ | ||
var | ||
data = this.mouseData(el, integer, decimal), | ||
evt = $.Event(action, { pageX: data.pageX }); | ||
data = this.mouseData(el, integer, decimal); | ||
var evt = $.Event(action, { pageX: data.pageX }); | ||
@@ -101,4 +108,4 @@ data.el.trigger(evt); | ||
var data = this._save(id), | ||
attrs = this._attrs(data, options); | ||
var data = this._save(id); | ||
var attrs = this._attrs(data, options); | ||
@@ -112,47 +119,1 @@ if (type === 'select') { | ||
}; | ||
function context(description, spec) { | ||
describe(description, spec); | ||
} | ||
function build() { | ||
$('body').append('<div id="element"></div>'); | ||
} | ||
function buildDivTarget() { | ||
$('body').append('<div id="hint"></div>'); | ||
} | ||
function buildComboboxTarget() { | ||
$('body').append( | ||
'<select id="hint">' + | ||
'<option value="Cancel this rating!">cancel hint default</option>' + | ||
'<option value="cancel-hint-custom">cancel hint custom</option>' + | ||
'<option value="">cancel number default</option>' + | ||
'<option value="0">cancel number custom</option>' + | ||
'<option value="bad">bad hint imutable</option>' + | ||
'<option value="1">bad number imutable</option>' + | ||
'<option value="targetText">targetText is setted without targetKeep</option>' + | ||
'<option value="score: bad">targetFormat</option>' + | ||
'</select>' | ||
); | ||
} | ||
function buildTextareaTarget() { | ||
$('body').append('<textarea id="hint"></textarea>'); | ||
} | ||
function buildTextTarget() { | ||
$('body').append('<input id="hint" type="text" />'); | ||
} | ||
function clear() { | ||
if (isClear) { | ||
$('#element').remove(); | ||
$('#hint').remove(); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
101
498686
10689
94
1
Updatedjquery@^3.5.1