| 1 |
- import t from"jquery";function e(t){return(e="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})(t)}function r(t){return(r="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})(t)}function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var a='<?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>',s={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},u="#c0392b",c="#f1c40f";function l(){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 f(t,e,r){return t===e?t=e:t===r&&(t=r),t}function p(t,e,r){if(!(t>=e&&t<=r))throw Error("Invalid Rating, expected value between "+e+" and "+r);return t}function d(t,e){return r(t)===e}function h(t){return void 0!==t}var g=function(t){return d(t,"function")},m=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function v(t){if(!m.test(t))return null;var e=m.exec(t);return{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}}function y(t,e,r){var n=r/100*(e-t);return 1===(n=Math.round(t+n).toString(16)).length&&(n="0"+n),n}function b(t,e,r){if(!t||!e)return null;r=h(r)?r:0,t=v(t),e=v(e);var n=y(t.r,e.r,r),o=y(t.b,e.b,r);return"#"+n+y(t.g,e.g,r)+o}var w={};function k(t){return w[t]||(w[t]=new String(t))}var x=new WeakMap;function S(t,e,r){r=k(r);var n=x.get(t);n||x.set(t,n=new WeakMap);var o=n.get(r);o||n.set(r,o=new Map);var i=o.get(e);if(i)return i;function a(r){var n=r.detail;e.call(t,r,n)}return o.set(e,a),a}S.get=function(t,e,r){r=k(r);var n=x.get(t);if(!n)return e;var o=n.get(r);return o&&o.get(e)||e};var O=g(window.Event)?window.Event:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.bubbles,n=void 0!==r&&r,o=e.cancelable,i=void 0!==o&&o,a=document.createEvent("Event");return a.initEvent(t,n,i),a},j=g(window.CustomEvent)?window.CustomEvent:(j.prototype=Object.create(O.prototype),j),E={trigger:function(t,e){var r={bubbles:!0};return h(e)?this.node.dispatchEvent(new j(t,i({detail:e},r))):this.node.dispatchEvent(new O(t,r)),this},on:function(t,e){return this.node.addEventListener(t,S(this.node,e,t)),this},off:function(t,e){return this.node.removeEventListener(t,S.get(this.node,e,t)),this}},C=/^rateyo(.+)$/;function F(t,e,r){var n=t.className.trim(),o=n&&n.split(/\s/)||[],i={};if(o=o.reduce((function(t,e,r){return i.hasOwnProperty(e)||(t.push(e),i[e]=r),t}),[]),e===F.add){if(i.hasOwnProperty(r))return;o.push(r)}else if(e===F.remove){if(!i.hasOwnProperty(r))return;o.splice(i[r],1)}t.className=o.join(" ")}function P(t){this.node=t}function A(t){var e=this;this.collection=[],Array.prototype.forEach.call(t,(function(t){e.collection.push(new P(t))}))}F.add="add",F.remove="remove",P.prototype={empty:function(){return this.node.innerHTML="",this},addClass:function(t){return F(this.node,F.add,t),this},removeClass:function(t){return F(this.node,F.remove,t),this},appendTo:function(t){return(P.isEl(t)?t.node:t).appendChild(this.node),this},css:function(t,e){return this.node.style[t]=e,this},width:function(t){if(!h(t))return this.node.getBoundingClientRect().width;this.css("width",t+(d(t,"number")?"px":""))},find:function(t){return M(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 M(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,r){var n=r.match(C);if(!n)return e;var o=n[1];return e[o[0].toLowerCase()+o.slice(1)]=t[r],e}),{})}},P.prototype=i(i({},P.prototype),E),P.isEl=function(t){return t instanceof P},A.isCollection=function(t){return t instanceof A},A.prototype={};var q=function(t){if(!P.prototype.hasOwnProperty(t))return"continue";A.prototype[t]=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return this.collection.forEach((function(e){return P.isEl(e)&&e[t].apply(e,r)})),this}};for(var z in P.prototype)q(z);var I=new DOMParser;function M(t){var e;return t=d(t,"string")&&(e=t,I.parseFromString(e.trim(),"text/html").body.childNodes)||t,P.isEl(t)||A.isCollection(t)?t:t instanceof NodeList?new A(t):new P(t)}M.El=P;var V=new WeakMap;function W(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(this instanceof W))return new W(t,e);if(V.has(t))return V.get(t);var r=this;this.node=t;var n=M(t);e=i(i(i({},s),e),n.dataAttrOptions()),n.empty().addClass("jq-ry-container");var o,d,g,m,v,y,w=M(document.createElement("div")).addClass("jq-ry-group-wrapper").appendTo(n),k=M(document.createElement("div")).addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(w),x=M(document.createElement("div")).addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(w),S=0,O=e.rating,j=!1;function E(t){h(t)||(t=e.rating),O=t;var r=t/o,n=r*g;r>1&&(n+=(Math.ceil(r)-1)*v),z(e.ratedFill),(n=e.rtl?100-n:n)<0?n=0:n>100&&(n=100),x.css("width",n+"%")}function C(){y=d*e.numStars+m*(e.numStars-1),g=d/y*100,v=m/y*100,n.width(y),E()}function F(t){var r=e.starWidth=t;return d=window.parseFloat(e.starWidth.replace("px","")),k.find("svg").attr({width:e.starWidth,height:r}),x.find("svg").attr({width:e.starWidth,height:r}),C(),n}function P(t){return e.spacing=t,m=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),C(),n}function A(t){return e.normalFill=t,(e.rtl?x:k).find("svg").attr({fill:e.normalFill}),n}var q=e.ratedFill;function z(t){if(e.multiColor){var r=(O-S)/e.maxValue*100,o=e.multiColor||{};t=b(o.startColor||u,o.endColor||c,r)}else q=t;return e.ratedFill=t,(e.rtl?k:x).find("svg").attr({fill:e.ratedFill}),n}function I(t){t=!!t,e.rtl=t,A(e.normalFill),E()}function T(t){e.multiColor=t,z(t||q)}function N(t){e.numStars=t,o=e.maxValue/e.numStars,k.empty(),x.empty();for(var r=0;r<e.numStars;r++)M(e.starSvg||a).appendTo(k),M(e.starSvg||a).appendTo(x);return F(e.starWidth),A(e.normalFill),P(e.spacing),E(),n}function D(t){return e.maxValue=t,o=e.maxValue/e.numStars,e.rating>t&&X(t),E(),n}function L(t){return e.precision=t,X(e.rating),n}function $(t){return e.halfStar=t,n}function _(t){return e.fullStar=t,n}function B(t){var r=t%o,n=o/2,i=e.halfStar,a=e.fullStar;return a||i?(a||i&&r>n?t+=o-r:(t-=r,r>0&&(t+=n)),t):t}function R(t){var r=k.offset().left,n=r+k.width(),i=e.maxValue,a=t.pageX,s=0;if(a<r)s=S;else if(a>n)s=i;else{var u=(a-r)/(n-r);if(m>0)for(var c=u*=100;c>0;)c>g?(s+=o,c-=g+v):(s+=c/g*o,c=0);else s=u*e.maxValue;s=B(s)}return e.rtl&&(s=i-s),parseFloat(s)}function H(t){return e.readOnly=t,n.attr({readonly:!0}),nt(),t||(n.removeAttr("readonly"),rt()),n}function X(t){var r=t,o=e.maxValue;return"string"==typeof r&&("%"===r[r.length-1]&&(r=r.substr(0,r.length-1),D(o=100)),r=parseFloat(r)),p(r,S,o),r=parseFloat(r.toFixed(e.precision)),f(parseFloat(r),S,o),e.rating=r,E(),j&&n.trigger("rateyo.set",{rating:r}),n}function Y(t){return e.onInit=t,n}function G(t){return e.onSet=t,n}function J(t){return e.onChange=t,n}function K(t){if(e.hover){var r=R(t).toFixed(e.precision),o=e.maxValue;E(r=f(parseFloat(r),S,o)),n.trigger("rateyo.change",{rating:r})}}function Q(){!l()&&e.hover&&(E(),n.trigger("rateyo.change",{rating:e.rating}))}function U(t){var n=R(t).toFixed(e.precision);n=parseFloat(n),r.rating(n)}function Z(t,n){e.onInit&&"function"==typeof e.onInit&&e.onInit.apply(this,[n.rating,r])}function tt(t,n){e.onChange&&"function"==typeof e.onChange&&e.onChange.apply(this,[n.rating,r])}function et(t,n){e.onSet&&"function"==typeof e.onSet&&e.onSet.apply(this,[n.rating,r])}function rt(){n.on("mousemove",K).on("mouseenter",K).on("mouseleave",Q).on("click",U).on("rateyo.init",Z).on("rateyo.change",tt).on("rateyo.set",et)}function nt(){n.off("mousemove",K).off("mouseenter",K).off("mouseleave",Q).off("click",U).off("rateyo.init",Z).off("rateyo.change",tt).off("rateyo.set",et)}this.rating=function(t){return h(t)?(X(t),n):e.rating},this.destroy=function(){return e.readOnly||nt(),V.delete(t),n.removeClass("jq-ry-container").children().remove(),n},this.method=function(t){if(!t)throw Error("Method name not specified!");if(!h(this[t]))throw Error("Method "+t+" doesn't exist!");var e=Array.prototype.slice.apply(arguments,[]),r=e.slice(1),n=this[t];return n.apply(this,r)},this.option=function(t,r){if(!h(t))return e;var n;switch(t){case"starWidth":n=F;break;case"numStars":n=N;break;case"normalFill":n=A;break;case"ratedFill":n=z;break;case"multiColor":n=T;break;case"maxValue":n=D;break;case"precision":n=L;break;case"rating":n=X;break;case"halfStar":n=$;break;case"fullStar":n=_;break;case"readOnly":n=H;break;case"spacing":n=P;break;case"rtl":n=I;break;case"onInit":n=Y;break;case"onSet":n=G;break;case"onChange":n=J;break;default:throw Error("No such option as "+t)}return h(r)?n(r):e[t]},N(e.numStars),H(e.readOnly),e.rtl&&I(e.rtl),V.set(t,this),this.rating(e.rating,!0),j=!0,n.trigger("rateyo.init",{rating:e.rating})}Object.defineProperty(W.prototype,"on",{value:function(t,e){return M(this.node).on(t,e),this}}),Object.defineProperty(W.prototype,"off",{value:function(t,e){return M(this.node).off(t,e),this}}),Object.defineProperty(W,"has",{value:function(t){return V.has(t)}}),Object.defineProperty(W,"get",{value:function(t){return V.get(t)}}),Object.defineProperty(W,"_$",{get:function(){return M}});var T=W._$,N=T.El.prototype.trigger;function D(r){var n=t(this);if(0===n.length)return n;var o=Array.prototype.slice.apply(arguments,[]);if(0===o.length)r=o[0]={};else{if(1!==o.length||"object"!==e(o[0])){if(o.length>=1&&"string"==typeof o[0]){var i=o[0],a=o.slice(1),s=[];return t.each(n,(function(t,e){var r=W.get(e);if(!r)throw Error("Trying to set options before even initialization");var n=r[i];if(!n)throw Error("Method "+i+" does not exist!");var o=n.apply(r,a);s.push(o)})),s=1===s.length?s[0]:s}throw Error("Invalid Arguments")}r=o[0]}return t.each(n,(function(){return new W(this,t.extend({},r))}))}T.El.prototype.trigger=function(){for(var e,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];N.apply(this,n),(e=t(this.node)).trigger.apply(e,n)},t.fn.rateYo=function(){return D.apply(this,Array.prototype.slice.apply(arguments,[]))};
|