saeedsq/django-fancy-cronfield

View on GitHub
fancy_cronfield/static/fancy_cronfield/js/jquery-gentleSelect.min.js

Summary

Maintainability
A
0 mins
Test Coverage
/*
 * jQuery gentleSelect plugin
 * http://shawnchin.github.com/jquery-gentleSelect
 *
 * Copyright (c) 2010 Shawn Chin.
 * Licensed under the MIT license.
 */
(function(c){function f(b){return"undefined"===typeof b?!1:!0}function q(b,a){return f(a.columns)&&f(a.rows)?(c.error("gentleSelect: You cannot supply both 'rows' and 'columns'"),!0):f(a.columns)&&!f(a.itemWidth)?(c.error("gentleSelect: itemWidth must be supplied if 'columns' is specified"),!0):f(a.rows)&&!f(a.itemWidth)?(c.error("gentleSelect: itemWidth must be supplied if 'rows' is specified"),!0):!f(a.openSpeed)||"number"!==typeof a.openSpeed&&"string"===typeof a.openSpeed&&"slow"!==a.openSpeed&&
"fast"!==a.openSpeed?(c.error('gentleSelect: openSpeed must be an integer or "slow" or "fast"'),!0):!f(a.closeSpeed)||"number"!==typeof a.closeSpeed&&"string"===typeof a.closeSpeed&&"slow"!==a.closeSpeed&&"fast"!==a.closeSpeed?(c.error('gentleSelect: closeSpeed must be an integer or "slow" or "fast"'),!0):!f(a.openEffect)||"fade"!==a.openEffect&&"slide"!==a.openEffect?(c.error("gentleSelect: openEffect must be either 'fade' or 'slide'!"),!0):!f(a.closeEffect)||"fade"!==a.closeEffect&&"slide"!==a.closeEffect?
(c.error("gentleSelect: closeEffect must be either 'fade' or 'slide'!"),!0):f(a.hideOnMouseOut)&&"boolean"===typeof a.hideOnMouseOut?!1:(c.error('gentleSelect: hideOnMouseOut must be supplied and either "true" or "false"!'),!0)}function r(b,a){b.attr("multiple")&&(a.hideOnMouseOut=!0)}function p(b,a){if(1>b.length)return a.prompt;var d;0!==a.maxDisplay&&b.length>a.maxDisplay?(d=b.slice(0,a.maxDisplay).map(function(){return c(this).text()}),d.push("...")):d=b.map(function(){return c(this).text()});
return d.get().join(", ")}var t={minWidth:100,itemWidth:void 0,columns:void 0,rows:void 0,title:void 0,prompt:gettext("Make A Selection"),maxDisplay:0,openSpeed:400,closeSpeed:400,openEffect:"slide",closeEffect:"slide",hideOnMouseOut:!0},h={init:function(b){b=c.extend({},t,b);if(q(this,b))return this;r(this,b);this.hide();var a=p(this.find(":selected"),b),a=c("<span class='gentleselect-label'>"+a+"</span>").insertBefore(this).bind("mouseenter.gentleselect",l.labelHoverIn).bind("mouseleave.gentleselect",
l.labelHoverOut).bind("click.gentleselect",l.labelClick).data("root",this);this.data("label",a).data("options",b);var d=c("<ul></ul>");this.find("option").each(function(){var a=c("<li>"+c(this).text()+"</li>").data("value",c(this).attr("value")).data("name",c(this).text()).appendTo(d);c(this).attr("selected")&&a.addClass("selected")});a=c("<div class='gentleselect-dialog'></div>").append(d).insertAfter(a).bind("click.gentleselect",l.dialogClick).bind("mouseleave.gentleselect",l.dialogHoverOut).data("label",
a).data("root",this);this.data("dialog",a);if(f(b.columns)||f(b.rows)){d.css("float","left").find("li").width(b.itemWidth).css("float","left");var e=d.find("li:first"),k=b.itemWidth,k=k+parseInt(e.css("padding-left")),k=k+parseInt(e.css("padding-right")),e=d.find("li").length,m,g;f(b.columns)?(m=parseInt(b.columns),g=Math.ceil(e/m)):(g=parseInt(b.rows),m=Math.ceil(e/g));a.width(k*m);for(k=0;k<g*m-e;k++)c("<li style='float:left' class='gentleselect-dummy'><span>&nbsp;</span></li>").appendTo(d);var h=
[],n=0;d.find("li").each(function(){if(n<g)h[n]=c(this);else{var a=n%g;c(this).insertAfter(h[a]);h[a]=c(this)}n++})}else"number"===typeof b.minWidth&&a.css("min-width",b.minWidth);f(b.title)&&c("<div class='gentleselect-title'>"+b.title+"</div>").prependTo(a);c(document).bind("keyup.gentleselect",l.keyUp);return this},update:function(){var b=this.data("options"),a=this.attr("multiple")?this.val():[this.val()];c("li",this.data("dialog")).each(function(){var b=c(this),e=-1!==c.inArray(b.data("value"),
a);b.toggleClass("selected",e)});b=p(this.find(":selected"),b);this.data("label").text(b);return this}},l={labelHoverIn:function(){c(this).addClass("gentleselect-label-highlight")},labelHoverOut:function(){c(this).removeClass("gentleselect-label-highlight")},labelClick:function(){var b=c(this),a=b.position(),d=b.data("root"),e=d.data("options"),b=d.data("dialog").css("top",a.top+b.height()).css("left",a.left+1);"fade"===e.openEffect?b.fadeIn(e.openSpeed):b.slideDown(e.openSpeed)},dialogHoverOut:function(){var b=
c(this);b.data("root").data("options").hideOnMouseOut&&b.hide()},dialogClick:function(b){var a=c(b.target),d=c(this);b=d.data("root");var e=b.data("options");b.attr("multiple")||("fade"===e.closeEffect?d.fadeOut(e.closeSpeed):d.slideUp(e.closeSpeed));if(a.is("li")&&!a.hasClass("gentleselect-dummy")){var f=a.data("value"),h=a.data("name"),g=d.data("label");d.data("root").attr("multiple")?(a.toggleClass("selected"),a=d.find("li.selected"),g.text(p(a,e)),e=a.map(function(){return c(this).data("value")}),
b.val(e.get()).trigger("change")):(d.find("li.selected").removeClass("selected"),a.addClass("selected"),g.text(h),b.val(f).trigger("change"))}},keyUp:function(b){27===b.keyCode&&c(".gentleselect-dialog").hide()}};c.fn.gentleSelect=function(b){if(h[b])return h[b].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof b&&b)c.error("Method "+b+" does not exist on jQuery.gentleSelect");else return h.init.apply(this,arguments)}})(jQuery_1_4_1);