관리-도구
편집 파일: jquery.barrating.min.js
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(v){var a=(t.prototype.init=function(t,e){return this.$elem=v(e),this.options=v.extend({},v.fn.barrating.defaults,t),this.options},t);function t(){function r(t){return v.isNumeric(t)&&(t=Math.floor(t)),v('option[value="'+t+'"]',m.$elem)}function o(t){var e=m.$elem.data("barrating");return void 0!==t?e[t]:e}function l(t,e){null!==e&&"object"==typeof e?m.$elem.data("barrating",e):m.$elem.data("barrating")[t]=e}function e(){var t=(a=m.options.initialRating,m.$elem.val(a),a?r(a):v("option:selected",m.$elem)),e=!(i=m.$elem.find('option[value="'+m.options.emptyValue+'"]')).length&&m.options.allowEmpty?(i=v("<option />",{value:m.options.emptyValue})).prependTo(m.$elem):i,n=t.val(),a=t.data("html")?t.data("html"):t.text(),i=null!==m.options.allowEmpty?m.options.allowEmpty:!!e.length,t=e.length?e.val():null,e=e.length?e.text():null;l(null,{userOptions:m.options,ratingValue:n,ratingText:a,originalRatingValue:n,originalRatingText:a,allowEmpty:i,emptyRatingValue:t,emptyRatingText:e,readOnly:m.options.readonly,ratingMade:!1})}function s(){return o("ratingText")}function u(){return o("ratingValue")}function i(){return o("userOptions").reverse?"nextAll":"prevAll"}function d(t){r(t).prop("selected",!0),o("userOptions").triggerChange&&m.$elem.change()}function g(t){(t=t||s())==o("emptyRatingText")&&(t=""),m.options.showSelectedRating&&m.$elem.parent().find(".br-current-rating").text(t)}function c(){m.$widget.find("a").removeClass(function(t,e){return(e.match(/(^|\s)br-\S+/g)||[]).join(" ")})}function p(){var t=m.$widget.find('a[data-rating-value="'+u()+'"]'),e=o("userOptions").initialRating,n=v.isNumeric(u())?u():0,a=(a=e,Math.round(Math.floor(10*a)/10%1*100));c(),t.addClass("br-selected br-current")[i()]().addClass("br-selected"),!o("ratingMade")&&v.isNumeric(e)&&(e<=n||!a||(n=m.$widget.find("a"),(n=t.length?t[o("userOptions").reverse?"prev":"next"]():n[o("userOptions").reverse?"last":"first"]()).addClass("br-fractional"),n.addClass("br-fractional-"+a)))}function n(t){t.on("click.barrating",function(t){var e,n,a=v(this),i=o("userOptions");return t.preventDefault(),e=a.attr("data-rating-value"),n=a.attr("data-rating-text"),a=a,!o("allowEmpty")||!o("userOptions").deselectable||u()!=a.attr("data-rating-value")||(e=o("emptyRatingValue"),n=o("emptyRatingText")),l("ratingValue",e),l("ratingText",n),l("ratingMade",!0),d(e),g(n),p(),i.onSelect.call(m,u(),s(),t),!1})}function a(t){n(t),m.options.hoverState&&(t.on("mouseenter.barrating",function(){var t=v(this);c(),t.addClass("br-active")[i()]().addClass("br-active"),g(t.attr("data-rating-text"))}),m.$widget.on("mouseleave.barrating blur.barrating",function(){g(),p()}))}function f(t){t.off(".barrating")}function h(t){var e=m.$widget.find("a");o("userOptions").fastClicks&&e.on("touchstart.barrating",function(t){t.preventDefault(),t.stopPropagation(),v(this).click()}),t?(f(e),e.on("click.barrating",function(t){t.preventDefault()})):a(e)}var m=this;this.show=function(){var a,t;o()||(t=["br-wrapper"],""!==m.options.theme&&t.push("br-theme-"+m.options.theme),m.$elem.wrap(v("<div />",{class:t.join(" ")})),e(),m.$widget=(a=v("<div />",{class:"br-widget"}),m.$elem.find("option").each(function(){var t,e,n=v(this).val();n!==o("emptyRatingValue")&&(e=v(this).text(),(t=v(this).data("html"))&&(e=t),e=v("<a />",{href:"#","data-rating-value":n,"data-rating-text":e,html:m.options.showValues?e:""}),a.append(e))}),m.options.showSelectedRating&&a.append(v("<div />",{text:"",class:"br-current-rating"})),m.options.reverse&&a.addClass("br-reverse"),m.options.readonly&&a.addClass("br-readonly"),a),m.$widget.insertAfter(m.$elem),p(),g(),h(m.options.readonly),m.$elem.hide())},this.readonly=function(t){"boolean"==typeof t&&o("readOnly")!=t&&(h(t),l("readOnly",t),m.$widget.toggleClass("br-readonly"))},this.set=function(t){var e=o("userOptions");0!==m.$elem.find('option[value="'+t+'"]').length&&(l("ratingValue",t),l("ratingText",m.$elem.find('option[value="'+t+'"]').text()),l("ratingMade",!0),d(u()),g(s()),p(),e.silent||e.onSelect.call(this,u(),s()))},this.clear=function(){var t=o("userOptions");l("ratingValue",o("originalRatingValue")),l("ratingText",o("originalRatingText")),l("ratingMade",!1),v("option",m.$elem).prop("selected",function(){return this.defaultSelected}),o("userOptions").triggerChange&&m.$elem.change(),g(s()),p(),t.onClear.call(this,u(),s())},this.destroy=function(){var t=u(),e=s(),n=o("userOptions");f(m.$widget.find("a")),m.$widget.remove(),m.$elem.removeData("barrating"),m.$elem.unwrap(),m.$elem.show(),n.onDestroy.call(this,t,e)}}v.fn.barrating=function(e,n){return this.each(function(){var t=new a;return v(this).is("select")||v.error("Sorry, this plugin only works with select fields."),t.hasOwnProperty(e)?(t.init(n,this),"show"===e?t.show(n):t.$elem.data("barrating")?(t.$widget=v(this).next(".br-widget"),t[e](n)):void 0):"object"!=typeof e&&e?void v.error("Method "+e+" does not exist on jQuery.barrating"):(n=e,t.init(n,this),t.show())})},v.fn.barrating.defaults={theme:"",initialRating:null,allowEmpty:null,emptyValue:"",showValues:!1,showSelectedRating:!0,deselectable:!0,reverse:!1,readonly:!1,fastClicks:!0,hoverState:!0,silent:!1,triggerChange:!0,onSelect:function(t,e,n){},onClear:function(t,e){},onDestroy:function(t,e){}},v.fn.barrating.BarRating=a});