diff --git a/build/raty.amd.min.js b/build/raty.amd.min.js index 3e9e13c..0b3da5a 100644 --- a/build/raty.amd.min.js +++ b/build/raty.amd.min.js @@ -1 +1 @@ -define(["exports"],function(t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=class{constructor(t,e={}){this.element=t,this.opt={...this.defaultOptions(),...e,...this._parseOptions(t.dataset)}}defaultOptions(){return{cancelButton:!1,cancelClass:"raty-cancel",cancelHint:"Cancel this rating!",cancelOff:"cancel-off.png",cancelOn:"cancel-on.png",cancelPlace:"left",click:void 0,half:!1,halfShow:!0,hints:["bad","poor","regular","good","gorgeous"],iconRange:void 0,iconRangeSame:!1,mouseout:void 0,mouseover:void 0,noRatedMsg:"Not rated yet!",number:5,numberMax:20,path:void 0,precision:!1,readOnly:!1,round:{down:.25,full:.6,up:.76},score:void 0,scoreName:"score",single:!1,space:!0,starHalf:"star-half.png",starOff:"star-off.png",starOn:"star-on.png",starType:"img",target:void 0,targetFormat:"{score}",targetKeep:!1,targetScore:void 0,targetText:"",targetType:"hint"}}cancel(t){this._isReadOnly()||(this[t?"click":"score"](null),this.scoreField.removeAttribute("value"))}click(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this.opt.click&&this.opt.click.call(this,t,this.element),this._target(t))}move(t){var e=parseInt(t,10),t=this._getDecimal(t,1),s=(e>=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5)&&s++),s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.offsetLeft)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5))&&s++,s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.getBoundingClientRect().x)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5)&&s++),s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.offsetLeft)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5))&&s++,s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.getBoundingClientRect().x)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5 { value.addEventListener('click', evt => { @@ -247,7 +240,6 @@ class Raty { }); }); } - _bindClickCancel() { this.cancelButton.addEventListener('click', evt => { this.scoreField.removeAttribute('value'); @@ -256,7 +248,6 @@ class Raty { } }); } - _bindOut() { this.element.addEventListener('mouseleave', evt => { const score = +this.scoreField.value || undefined; @@ -268,7 +259,6 @@ class Raty { } }); } - _bindOutCancel() { this.cancelButton.addEventListener('mouseleave', evt => { let icon = this.opt.cancelOff; @@ -282,7 +272,6 @@ class Raty { } }); } - _bindOver() { const action = this.opt.half ? 'mousemove' : 'mouseover'; this.stars.forEach(value => { @@ -301,7 +290,6 @@ class Raty { }); }); } - _bindOverCancel() { this.cancelButton.addEventListener('mouseover', evt => { if (this._isReadOnly()) { @@ -326,7 +314,6 @@ class Raty { } }); } - _buildScoreField() { const input = document.createElement('input'); input.name = this.opt.scoreName; @@ -334,7 +321,6 @@ class Raty { this.element.appendChild(input); return input; } - _createCancel() { const button = document.createElement(this.opt.starType); const icon = this.opt.path + this.opt.cancelOff; @@ -345,7 +331,6 @@ class Raty { button.setAttribute('src', icon); } else { button.classList.add(icon); - button.setAttribute('data-alt', 'x'); } if (this.opt.cancelPlace === 'left') { @@ -357,7 +342,6 @@ class Raty { } this.cancelButton = button; } - _createScore() { this.scoreField = document.querySelector(this.opt.targetScore) || this._buildScoreField(); } @@ -375,7 +359,6 @@ class Raty { } this.stars = this.element.querySelectorAll(this.opt.starType); } - _error(message) { throw new Error(message); } @@ -392,7 +375,6 @@ class Raty { } } } - _fill(score) { let hash = 0; if (this.opt.iconRangeSame && this.opt.iconRange) { @@ -430,21 +412,18 @@ class Raty { } return result; } - _getRangeIcon(irange, turnOn) { return turnOn ? irange.on || this.opt.starOn : irange.off || this.opt.starOff; } - _getScoreByPosition(evt, icon) { let score = parseInt(icon.alt || icon.getAttribute('data-alt'), 10); if (this.opt.half) { const size = this._getWidth(); - const percent = parseFloat((evt.pageX - icon.offsetLeft) / size); + const percent = parseFloat((evt.pageX - icon.getBoundingClientRect().x) / size); score = score - 1 + percent; } return score; } - _getHint(score, evt) { if (score !== 0 && !score) { return this.opt.noRatedMsg; @@ -465,7 +444,6 @@ class Raty { } return hint === '' ? '' : hint || score; } - _getWidth() { const width = parseFloat(this.stars[0].offsetWidth) || 16; if (!width) { @@ -478,7 +456,6 @@ class Raty { true: true }[this.element.dataset.readOnly] || false; } - _lock() { const hint = this._getHint(this.scoreField.value); this.element.style.pointerEvents = 'none'; @@ -495,7 +472,6 @@ class Raty { _nameForIndex(i) { return this.opt.score && this.opt.score >= i ? 'starOn' : 'starOff'; } - _resetTitle() { for (let i = 0; i < this.opt.number; i++) { this.stars[i].title = this._getHint(i + 1); @@ -515,7 +491,6 @@ class Raty { return acc; }, {}); } - _roundHalfScore(score) { const integer = parseInt(score, 10); let decimal = this._getDecimal(score, 1); @@ -524,7 +499,6 @@ class Raty { } return integer + decimal; } - _roundStars(score, evt) { const name = this._starName(score, evt); if (name) { @@ -533,7 +507,6 @@ class Raty { star && this._setIcon(star, icon); } } - _setIcon(star, icon) { star[this.opt.starType === 'img' ? 'src' : 'className'] = this.opt.path + icon; } @@ -543,7 +516,6 @@ class Raty { this.opt.path += '/'; } } - _setTarget(target, score) { if (score) { score = this.opt.targetFormat.toString().replace('{score}', score); @@ -554,7 +526,6 @@ class Raty { target.textContent = score; } } - _setTitle(score, evt) { if (score) { const integer = parseInt(Math.ceil(score), 10); @@ -578,7 +549,6 @@ class Raty { } return 'starOn'; } - _target(score, evt) { if (this.opt.target) { const target = document.querySelector(this.opt.target); @@ -604,11 +574,9 @@ class Raty { this._setTarget(target, score); } } - _turnOn(i, score) { return this.opt.single ? i === score : i <= score; } - _unlock() { this.element.style.cursor = 'pointer'; this.element.style.pointerEvents = 'auto'; diff --git a/build/raty.min.js b/build/raty.min.js index a21dd33..9f90892 100644 --- a/build/raty.min.js +++ b/build/raty.min.js @@ -1 +1 @@ -"use strict";class Raty{constructor(t,e={}){this.element=t,this.opt={...this.defaultOptions(),...e,...this._parseOptions(t.dataset)}}defaultOptions(){return{cancelButton:!1,cancelClass:"raty-cancel",cancelHint:"Cancel this rating!",cancelOff:"cancel-off.png",cancelOn:"cancel-on.png",cancelPlace:"left",click:void 0,half:!1,halfShow:!0,hints:["bad","poor","regular","good","gorgeous"],iconRange:void 0,iconRangeSame:!1,mouseout:void 0,mouseover:void 0,noRatedMsg:"Not rated yet!",number:5,numberMax:20,path:void 0,precision:!1,readOnly:!1,round:{down:.25,full:.6,up:.76},score:void 0,scoreName:"score",single:!1,space:!0,starHalf:"star-half.png",starOff:"star-off.png",starOn:"star-on.png",starType:"img",target:void 0,targetFormat:"{score}",targetKeep:!1,targetScore:void 0,targetText:"",targetType:"hint"}}cancel(t){this._isReadOnly()||(this[t?"click":"score"](null),this.scoreField.removeAttribute("value"))}click(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this.opt.click&&this.opt.click.call(this,t,this.element),this._target(t))}move(t){var e=parseInt(t,10),t=this._getDecimal(t,1),s=(e>=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5)&&s++),s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.offsetLeft)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5))&&s++,s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.getBoundingClientRect().x)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5)&&s++),s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.offsetLeft)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5))&&s++,s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.getBoundingClientRect().x)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5)&&s++),s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.offsetLeft)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(a=this.opt.iconRange[i],t=this._getRangeIcon(a,r),e<=a.range&&this._setIcon(o,t),e===a.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(o,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5))&&s++,s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.getBoundingClientRect().x)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),a=s;return this.opt.precision?(e&&(i=0===i?9:i-1),a=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(o=this.opt.iconRange[i],t=this._getRangeIcon(o,r),e<=o.range&&this._setIcon(a,t),e===o.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(a,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5)&&s++),s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.offsetLeft)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),o=s;return this.opt.precision?(e&&(i=0===i?9:i-1),o=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5=this.opt.number&&(e=this.opt.number-1,t=10),this._getWidth()),e=this.stars[e],s=e.offsetLeft+s/10*t,t=new Event("mousemove");t.pageX=s,this.isMove=!0,e.dispatchEvent(t),this.isMove=!1}readOnly(t){this._isReadOnly()!==t&&(t?this._lock():(this._binds(),this._unlock()),this.element.dataset.readOnly=t)}score(){return arguments.length?this.setScore(arguments[0]):this.getScore()}setScore(t){this._isReadOnly()||(t=this._adjustedScore(t),this._apply(t),this._target(t))}getScore(){var t=[],e=this.scoreField.value;return t.push(e?+e:void 0),1{i.addEventListener("click",s=>{if(!this._isReadOnly()){let t,e=this.opt.half||this.opt.precision?this.element.dataset.score:i.alt||i.dataset.alt;this.opt.half&&!this.opt.precision&&(e=this._roundHalfScore(e)),!(t=this.opt.click?this.opt.click.call(this,+e,this.element,s):t)&&void 0!==t||this._apply(+e)}})})}_bindClickCancel(){this.cancelButton.addEventListener("click",t=>{this.scoreField.removeAttribute("value"),this.opt.click&&this.opt.click.call(this,null,this.element,t)})}_bindOut(){this.element.addEventListener("mouseleave",t=>{var e=+this.scoreField.value||void 0;this._apply(e),this._target(e,t),this._resetTitle(),this.opt.mouseout&&this.opt.mouseout.call(this,e,this.element,t)})}_bindOutCancel(){this.cancelButton.addEventListener("mouseleave",t=>{let e=this.opt.cancelOff;var s;"img"!==this.opt.starType&&(e=this.opt.cancelClass+" "+e),this._setIcon(this.cancelButton,e),this.opt.mouseout&&(s=+this.scoreField.value||void 0,this.opt.mouseout.call(this,s,this.element,t))})}_bindOver(){const t=this.opt.half?"mousemove":"mouseover";this.stars.forEach(s=>{s.addEventListener(t,t=>{var e=this._getScoreByPosition(t,s);this._fill(e),this.opt.half&&(this._roundStars(e,t),this._setTitle(e,t),this.element.dataset.score=e),this._target(e,t),this.opt.mouseover&&this.opt.mouseover.call(this,e,this.element,t)})})}_bindOverCancel(){this.cancelButton.addEventListener("mouseover",e=>{if(!this._isReadOnly()){const s=this.opt.path+this.opt.starOff;let t=this.opt.cancelOn;"img"===this.opt.starType?this.stars.forEach(t=>{t.src=s}):(t=this.opt.cancelClass+" "+t,this.stars.forEach(t=>{t.className=s})),this._setIcon(this.cancelButton,t),this._target(null,e),this.opt.mouseover&&this.opt.mouseover.call(this,null,this.element,e)}})}_buildScoreField(){var t=document.createElement("input");return t.name=this.opt.scoreName,t.type="hidden",this.element.appendChild(t),t}_createCancel(){var t=document.createElement(this.opt.starType),e=this.opt.path+this.opt.cancelOff;t.setAttribute("class",this.opt.cancelClass),t.setAttribute("title",this.opt.cancelHint),"img"===this.opt.starType?(t.setAttribute("alt","x"),t.setAttribute("src",e)):(t.classList.add(e),t.setAttribute("data-alt","x")),"left"===this.opt.cancelPlace?(this.element.prepend(" "),this.element.prepend(t)):(this.element.append(" "),this.element.appendChild(t)),this.cancelButton=t}_createScore(){this.scoreField=document.querySelector(this.opt.targetScore)||this._buildScoreField()}_createStars(){for(let t=1;t<=this.opt.number;t++){var e=this._attributesForIndex(t),s=document.createElement(this.opt.starType);for(const i in e)s.setAttribute(i,e[i]);this.element.appendChild(s),this.opt.space&&ti?(o=this.opt.iconRange[i],t=this._getRangeIcon(o,r),e<=o.range&&this._setIcon(a,t),e===o.range&&i++):(t=this.opt[r?"starOn":"starOff"],this._setIcon(a,t))}}_getDecimal(t,e){t=t.toString().split(".")[1];let s=0;return t&&(s=parseInt(t.slice(0,e),10),"9999"===t.slice(1,5))&&s++,s}_getRangeIcon(t,e){return e?t.on||this.opt.starOn:t.off||this.opt.starOff}_getScoreByPosition(t,e){let s=parseInt(e.alt||e.getAttribute("data-alt"),10);var i;return this.opt.half&&(i=this._getWidth(),t=parseFloat((t.pageX-e.getBoundingClientRect().x)/i),s=s-1+t),s}_getHint(t,e){if(0!==t&&!t)return this.opt.noRatedMsg;var s=Math.ceil(t),s=this.opt.hints[(s||1)-1],e=!e||this.isMove;let i=this._getDecimal(t,1),o=s;return this.opt.precision?(e&&(i=0===i?9:i-1),o=s[i]):(this.opt.halfShow||this.opt.half)&&(i=e&&0===i||5{t.title=e}),this.cancelButton&&(this.cancelButton.style.display="none"),this.element.dataset.readOnly=!0}_nameForIndex(t){return this.opt.score&&this.opt.score>=t?"starOn":"starOff"}_resetTitle(){for(let t=0;t{let s={true:!0,false:!1}[i[e]];return s=null!==s&&void 0!==s?s:i[e],!isNaN(s)&&Number.isInteger(parseFloat(s))&&(s=Number(s)),t[e]=s,t},{})}_roundHalfScore(t){var e=parseInt(t,10);let s=this._getDecimal(t,1);return e+(s=0!==s?5