| 1 |
- "use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function r(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach((function(n){e(t,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}var o='<?xml version="1.0" encoding="utf-8"?><svg version="1.1"xmlns="http://www.w3.org/2000/svg"viewBox="0 12.705 512 486.59"x="0px" y="0px"xml:space="preserve"><polygon points="256.814,12.705 317.205,198.566 512.631,198.566 354.529,313.435 414.918,499.295 256.814,384.427 98.713,499.295 159.102,313.435 1,198.566 196.426,198.566 "/></svg>',i={starWidth:"32px",normalFill:"gray",ratedFill:"#f39c12",numStars:5,maxValue:5,precision:1,rating:0,fullStar:!1,halfStar:!1,hover:!0,readOnly:!1,spacing:"0px",rtl:!1,multiColor:null,onInit:null,onChange:null,onSet:null,starSvg:null},a="#c0392b",s="#f1c40f";function c(){var t,e=!1;return t=navigator.userAgent||navigator.vendor||window.opera,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4)))&&(e=!0),e}function u(t,e,n){return t===e?t=e:t===n&&(t=n),t}function l(t,e,n){if(!(t>=e&&t<=n))throw Error("Invalid Rating, expected value between "+e+" and "+n);return t}function f(e,n){return t(e)===n}function p(t){return void 0!==t}var d=function(t){return f(t,"function")},h=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function m(t){if(!h.test(t))return null;var e=h.exec(t);return{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}}function g(t,e,n){var r=n/100*(e-t);return 1===(r=Math.round(t+r).toString(16)).length&&(r="0"+r),r}function v(t,e,n){if(!t||!e)return null;n=p(n)?n:0,t=m(t),e=m(e);var r=g(t.r,e.r,n),o=g(t.b,e.b,n);return"#"+r+g(t.g,e.g,n)+o}var y={};function b(t){return y[t]||(y[t]=new String(t))}var w=new WeakMap;function k(t,e,n){n=b(n);var r=w.get(t);r||w.set(t,r=new WeakMap);var o=r.get(n);o||r.set(n,o=new Map);var i=o.get(e);if(i)return i;function a(n){var r=n.detail;e.call(t,n,r)}return o.set(e,a),a}k.get=function(t,e,n){n=b(n);var r=w.get(t);if(!r)return e;var o=r.get(n);return o&&o.get(e)||e};var x=d(window.Event)?window.Event:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.bubbles,r=void 0!==n&&n,o=e.cancelable,i=void 0!==o&&o,a=document.createEvent("Event");return a.initEvent(t,r,i),a},O=d(window.CustomEvent)?window.CustomEvent:(O.prototype=Object.create(x.prototype),O),S={trigger:function(t,e){var n={bubbles:!0};return p(e)?this.node.dispatchEvent(new O(t,r({detail:e},n))):this.node.dispatchEvent(new x(t,n)),this},on:function(t,e){return this.node.addEventListener(t,k(this.node,e,t)),this},off:function(t,e){return this.node.removeEventListener(t,k.get(this.node,e,t)),this}},j=/^rateyo(.+)$/;function C(t,e,n){var r=t.className.trim(),o=r&&r.split(/\s/)||[],i={};if(o=o.reduce((function(t,e,n){return i.hasOwnProperty(e)||(t.push(e),i[e]=n),t}),[]),e===C.add){if(i.hasOwnProperty(n))return;o.push(n)}else if(e===C.remove){if(!i.hasOwnProperty(n))return;o.splice(i[n],1)}t.className=o.join(" ")}function E(t){this.node=t}function F(t){var e=this;this.collection=[],Array.prototype.forEach.call(t,(function(t){e.collection.push(new E(t))}))}C.add="add",C.remove="remove",E.prototype={empty:function(){return this.node.innerHTML="",this},addClass:function(t){return C(this.node,C.add,t),this},removeClass:function(t){return C(this.node,C.remove,t),this},appendTo:function(t){return(E.isEl(t)?t.node:t).appendChild(this.node),this},css:function(t,e){return this.node.style[t]=e,this},width:function(t){if(!p(t))return this.node.getBoundingClientRect().width;this.css("width",t+(f(t,"number")?"px":""))},find:function(t){return z(this.node.querySelectorAll(t))},attr:function(t){for(var e in t)t.hasOwnProperty(e)&&this.node.setAttribute(e,t[e]);return this},removeAttr:function(t){return this.node.removeAttribute(t),this},children:function(){return z(this.node.childNodes)},remove:function(){return this.node.remove()},offset:function(){var t=this.node.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}},dataAttrOptions:function(){var t=this.node.dataset;return Object.keys(t).reduce((function(e,n){var r=n.match(j);if(!r)return e;var o=r[1];return e[o[0].toLowerCase()+o.slice(1)]=t[n],e}),{})}},E.prototype=r(r({},E.prototype),S),E.isEl=function(t){return t instanceof E},F.isCollection=function(t){return t instanceof F},F.prototype={};var P=function(t){if(!E.prototype.hasOwnProperty(t))return"continue";F.prototype[t]=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.collection.forEach((function(e){return E.isEl(e)&&e[t].apply(e,n)})),this}};for(var q in E.prototype)P(q);var A=new DOMParser;function z(t){var e;return t=f(t,"string")&&(e=t,A.parseFromString(e.trim(),"text/html").body.childNodes)||t,E.isEl(t)||F.isCollection(t)?t:t instanceof NodeList?new F(t):new E(t)}z.El=E;var I=new WeakMap;function M(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(this instanceof M))return new M(t,e);if(I.has(t))return I.get(t);var n=this;this.node=t;var f=z(t);e=r(r(r({},i),e),f.dataAttrOptions()),f.empty().addClass("jq-ry-container");var d,h,m,g,y,b,w=z(document.createElement("div")).addClass("jq-ry-group-wrapper").appendTo(f),k=z(document.createElement("div")).addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(w),x=z(document.createElement("div")).addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(w),O=0,S=e.rating,j=!1;function C(t){p(t)||(t=e.rating),S=t;var n=t/d,r=n*m;n>1&&(r+=(Math.ceil(n)-1)*y),V(e.ratedFill),(r=e.rtl?100-r:r)<0?r=0:r>100&&(r=100),x.css("width",r+"%")}function E(){b=h*e.numStars+g*(e.numStars-1),m=h/b*100,y=g/b*100,f.width(b),C()}function F(t){var n=e.starWidth=t;return h=window.parseFloat(e.starWidth.replace("px","")),k.find("svg").attr({width:e.starWidth,height:n}),x.find("svg").attr({width:e.starWidth,height:n}),E(),f}function P(t){return e.spacing=t,g=parseFloat(e.spacing.replace("px","")),k.find("svg:not(:first-child)").css("margin-left",t),x.find("svg:not(:first-child)").css("margin-left",t),E(),f}function q(t){return e.normalFill=t,(e.rtl?x:k).find("svg").attr({fill:e.normalFill}),f}var A=e.ratedFill;function V(t){if(e.multiColor){var n=(S-O)/e.maxValue*100,r=e.multiColor||{};t=v(r.startColor||a,r.endColor||s,n)}else A=t;return e.ratedFill=t,(e.rtl?k:x).find("svg").attr({fill:e.ratedFill}),f}function W(t){t=!!t,e.rtl=t,q(e.normalFill),C()}function T(t){e.multiColor=t,V(t||A)}function N(t){e.numStars=t,d=e.maxValue/e.numStars,k.empty(),x.empty();for(var n=0;n<e.numStars;n++)z(e.starSvg||o).appendTo(k),z(e.starSvg||o).appendTo(x);return F(e.starWidth),q(e.normalFill),P(e.spacing),C(),f}function D(t){return e.maxValue=t,d=e.maxValue/e.numStars,e.rating>t&&X(t),C(),f}function L(t){return e.precision=t,X(e.rating),f}function B(t){return e.halfStar=t,f}function R(t){return e.fullStar=t,f}function $(t){var n=t%d,r=d/2,o=e.halfStar,i=e.fullStar;return i||o?(i||o&&n>r?t+=d-n:(t-=n,n>0&&(t+=r)),t):t}function _(t){var n=k.offset().left,r=n+k.width(),o=e.maxValue,i=t.pageX,a=0;if(i<n)a=O;else if(i>r)a=o;else{var s=(i-n)/(r-n);if(g>0)for(var c=s*=100;c>0;)c>m?(a+=d,c-=m+y):(a+=c/m*d,c=0);else a=s*e.maxValue;a=$(a)}return e.rtl&&(a=o-a),parseFloat(a)}function H(t){return e.readOnly=t,f.attr({readonly:!0}),rt(),t||(f.removeAttr("readonly"),nt()),f}function X(t){var n=t,r=e.maxValue;return"string"==typeof n&&("%"===n[n.length-1]&&(n=n.substr(0,n.length-1),D(r=100)),n=parseFloat(n)),l(n,O,r),n=parseFloat(n.toFixed(e.precision)),u(parseFloat(n),O,r),e.rating=n,C(),j&&f.trigger("rateyo.set",{rating:n}),f}function G(t){return e.onInit=t,f}function J(t){return e.onSet=t,f}function K(t){return e.onChange=t,f}function Q(t){if(e.hover){var n=_(t).toFixed(e.precision),r=e.maxValue;C(n=u(parseFloat(n),O,r)),f.trigger("rateyo.change",{rating:n})}}function U(){!c()&&e.hover&&(C(),f.trigger("rateyo.change",{rating:e.rating}))}function Y(t){var r=_(t).toFixed(e.precision);r=parseFloat(r),n.rating(r)}function Z(t,r){e.onInit&&"function"==typeof e.onInit&&e.onInit.apply(this,[r.rating,n])}function tt(t,r){e.onChange&&"function"==typeof e.onChange&&e.onChange.apply(this,[r.rating,n])}function et(t,r){e.onSet&&"function"==typeof e.onSet&&e.onSet.apply(this,[r.rating,n])}function nt(){f.on("mousemove",Q).on("mouseenter",Q).on("mouseleave",U).on("click",Y).on("rateyo.init",Z).on("rateyo.change",tt).on("rateyo.set",et)}function rt(){f.off("mousemove",Q).off("mouseenter",Q).off("mouseleave",U).off("click",Y).off("rateyo.init",Z).off("rateyo.change",tt).off("rateyo.set",et)}this.rating=function(t){return p(t)?(X(t),f):e.rating},this.destroy=function(){return e.readOnly||rt(),I.delete(t),f.removeClass("jq-ry-container").children().remove(),f},this.method=function(t){if(!t)throw Error("Method name not specified!");if(!p(this[t]))throw Error("Method "+t+" doesn't exist!");var e=Array.prototype.slice.apply(arguments,[]),n=e.slice(1),r=this[t];return r.apply(this,n)},this.option=function(t,n){if(!p(t))return e;var r;switch(t){case"starWidth":r=F;break;case"numStars":r=N;break;case"normalFill":r=q;break;case"ratedFill":r=V;break;case"multiColor":r=T;break;case"maxValue":r=D;break;case"precision":r=L;break;case"rating":r=X;break;case"halfStar":r=B;break;case"fullStar":r=R;break;case"readOnly":r=H;break;case"spacing":r=P;break;case"rtl":r=W;break;case"onInit":r=G;break;case"onSet":r=J;break;case"onChange":r=K;break;default:throw Error("No such option as "+t)}return p(n)?r(n):e[t]},N(e.numStars),H(e.readOnly),e.rtl&&W(e.rtl),I.set(t,this),this.rating(e.rating,!0),j=!0,f.trigger("rateyo.init",{rating:e.rating})}Object.defineProperty(M.prototype,"on",{value:function(t,e){return z(this.node).on(t,e),this}}),Object.defineProperty(M.prototype,"off",{value:function(t,e){return z(this.node).off(t,e),this}}),Object.defineProperty(M,"has",{value:function(t){return I.has(t)}}),Object.defineProperty(M,"get",{value:function(t){return I.get(t)}}),Object.defineProperty(M,"_$",{get:function(){return z}}),module.exports=M;
|