| 1 |
- "use strict";var t,e=(t=require("jquery"))&&"object"==typeof t&&"default"in t?t.default: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){return(n="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 o(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(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 a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var s='<?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>',u={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},c="#c0392b",l="#f1c40f";function f(){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 p(t,e,r){return t===e?t=e:t===r&&(t=r),t}function d(t,e,r){if(!(t>=e&&t<=r))throw Error("Invalid Rating, expected value between "+e+" and "+r);return t}function h(t,e){return n(t)===e}function g(t){return void 0!==t}var m=function(t){return h(t,"function")},v=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function y(t){if(!v.test(t))return null;var e=v.exec(t);return{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}}function b(t,e,r){var n=r/100*(e-t);return 1===(n=Math.round(t+n).toString(16)).length&&(n="0"+n),n}function w(t,e,r){if(!t||!e)return null;r=g(r)?r:0,t=y(t),e=y(e);var n=b(t.r,e.r,r),o=b(t.b,e.b,r);return"#"+n+b(t.g,e.g,r)+o}var k={};function x(t){return k[t]||(k[t]=new String(t))}var S=new WeakMap;function O(t,e,r){r=x(r);var n=S.get(t);n||S.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}O.get=function(t,e,r){r=x(r);var n=S.get(t);if(!n)return e;var o=n.get(r);return o&&o.get(e)||e};var j=m(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},E=m(window.CustomEvent)?window.CustomEvent:(E.prototype=Object.create(j.prototype),E),C={trigger:function(t,e){var r={bubbles:!0};return g(e)?this.node.dispatchEvent(new E(t,a({detail:e},r))):this.node.dispatchEvent(new j(t,r)),this},on:function(t,e){return this.node.addEventListener(t,O(this.node,e,t)),this},off:function(t,e){return this.node.removeEventListener(t,O.get(this.node,e,t)),this}},F=/^rateyo(.+)$/;function P(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===P.add){if(i.hasOwnProperty(r))return;o.push(r)}else if(e===P.remove){if(!i.hasOwnProperty(r))return;o.splice(i[r],1)}t.className=o.join(" ")}function q(t){this.node=t}function A(t){var e=this;this.collection=[],Array.prototype.forEach.call(t,(function(t){e.collection.push(new q(t))}))}P.add="add",P.remove="remove",q.prototype={empty:function(){return this.node.innerHTML="",this},addClass:function(t){return P(this.node,P.add,t),this},removeClass:function(t){return P(this.node,P.remove,t),this},appendTo:function(t){return(q.isEl(t)?t.node:t).appendChild(this.node),this},css:function(t,e){return this.node.style[t]=e,this},width:function(t){if(!g(t))return this.node.getBoundingClientRect().width;this.css("width",t+(h(t,"number")?"px":""))},find:function(t){return V(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 V(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(F);if(!n)return e;var o=n[1];return e[o[0].toLowerCase()+o.slice(1)]=t[r],e}),{})}},q.prototype=a(a({},q.prototype),C),q.isEl=function(t){return t instanceof q},A.isCollection=function(t){return t instanceof A},A.prototype={};var z=function(t){if(!q.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 q.isEl(e)&&e[t].apply(e,r)})),this}};for(var I in q.prototype)z(I);var M=new DOMParser;function V(t){var e;return t=h(t,"string")&&(e=t,M.parseFromString(e.trim(),"text/html").body.childNodes)||t,q.isEl(t)||A.isCollection(t)?t:t instanceof NodeList?new A(t):new q(t)}V.El=q;var W=new WeakMap;function T(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(this instanceof T))return new T(t,e);if(W.has(t))return W.get(t);var r=this;this.node=t;var n=V(t);e=a(a(a({},u),e),n.dataAttrOptions()),n.empty().addClass("jq-ry-container");var o,i,h,m,v,y,b=V(document.createElement("div")).addClass("jq-ry-group-wrapper").appendTo(n),k=V(document.createElement("div")).addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(b),x=V(document.createElement("div")).addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(b),S=0,O=e.rating,j=!1;function E(t){g(t)||(t=e.rating),O=t;var r=t/o,n=r*h;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=i*e.numStars+m*(e.numStars-1),h=i/y*100,v=m/y*100,n.width(y),E()}function F(t){var r=e.starWidth=t;return i=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 q(t){return e.normalFill=t,(e.rtl?x:k).find("svg").attr({fill:e.normalFill}),n}var A=e.ratedFill;function z(t){if(e.multiColor){var r=(O-S)/e.maxValue*100,o=e.multiColor||{};t=w(o.startColor||c,o.endColor||l,r)}else A=t;return e.ratedFill=t,(e.rtl?k:x).find("svg").attr({fill:e.ratedFill}),n}function I(t){t=!!t,e.rtl=t,q(e.normalFill),E()}function M(t){e.multiColor=t,z(t||A)}function N(t){e.numStars=t,o=e.maxValue/e.numStars,k.empty(),x.empty();for(var r=0;r<e.numStars;r++)V(e.starSvg||s).appendTo(k),V(e.starSvg||s).appendTo(x);return F(e.starWidth),q(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>h?(s+=o,c-=h+v):(s+=c/h*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)),d(r,S,o),r=parseFloat(r.toFixed(e.precision)),p(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=p(parseFloat(r),S,o)),n.trigger("rateyo.change",{rating:r})}}function Q(){!f()&&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 g(t)?(X(t),n):e.rating},this.destroy=function(){return e.readOnly||nt(),W.delete(t),n.removeClass("jq-ry-container").children().remove(),n},this.method=function(t){if(!t)throw Error("Method name not specified!");if(!g(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(!g(t))return e;var n;switch(t){case"starWidth":n=F;break;case"numStars":n=N;break;case"normalFill":n=q;break;case"ratedFill":n=z;break;case"multiColor":n=M;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 g(r)?n(r):e[t]},N(e.numStars),H(e.readOnly),e.rtl&&I(e.rtl),W.set(t,this),this.rating(e.rating,!0),j=!0,n.trigger("rateyo.init",{rating:e.rating})}Object.defineProperty(T.prototype,"on",{value:function(t,e){return V(this.node).on(t,e),this}}),Object.defineProperty(T.prototype,"off",{value:function(t,e){return V(this.node).off(t,e),this}}),Object.defineProperty(T,"has",{value:function(t){return W.has(t)}}),Object.defineProperty(T,"get",{value:function(t){return W.get(t)}}),Object.defineProperty(T,"_$",{get:function(){return V}});var N=T._$,D=N.El.prototype.trigger;function L(t){var n=e(this);if(0===n.length)return n;var o=Array.prototype.slice.apply(arguments,[]);if(0===o.length)t=o[0]={};else{if(1!==o.length||"object"!==r(o[0])){if(o.length>=1&&"string"==typeof o[0]){var i=o[0],a=o.slice(1),s=[];return e.each(n,(function(t,e){var r=T.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")}t=o[0]}return e.each(n,(function(){return new T(this,e.extend({},t))}))}N.El.prototype.trigger=function(){for(var t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];D.apply(this,n),(t=e(this.node)).trigger.apply(t,n)},e.fn.rateYo=function(){return L.apply(this,Array.prototype.slice.apply(arguments,[]))};
|