-
Notifications
You must be signed in to change notification settings - Fork 0
/
monthpicker_1.0-min.js
executable file
·23 lines (23 loc) · 11.3 KB
/
monthpicker_1.0-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(function(a){a.fn.monthpicker=function(c){function l(c,b){if(!0==b.data("monthpicker-funckey"))return!1;switch(c){case 16:case 17:case 18:return b.data("monthpicker-funckey",!0),!1;case 13:return a("body").trigger("click.hideMonthpicker"),!1;case 9:case 20:return!1;case 112:case 113:case 114:case 115:case 116:case 117:case 118:case 119:case 120:case 121:case 122:case 123:return!1;default:return!0}}function i(f){maxYear=null!=c.maxPoint&&c.maxPoint.getFullYear()<(new Date).getFullYear()?c.maxPoint.getFullYear():
(new Date).getFullYear();var b=a('<div class="monthpicker-'+f+'"></div').css({"text-align":"center"});b.append('<input class="monthpicker-scroll prev" type="button" style="float:left;width:25px;padding:0" value="<<"/>').append('<input class="monthpicker-scroll next" type="button" style="float:right;width:25px;padding:0" value=">>"/>').append('<div class="curr" style="display:inline-block;width:35px;padding-top:5px;margin-left:auto;margin-right: auto;text-align:center;color:'+c.colorYearTxt+'">'+maxYear+
"</div>").append('<div class="months-'+f+'" style="clear:both"></div>').css({width:"270px"}).data("date",null);a.each("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),function(e,m){e==6&&b.find(".months-"+f).append("<br/>");var d=a('<span class="month-'+f+'">'+m+"</span>").css({display:"inline-block","background-color":c.colorDefault,width:"35px",cursor:"pointer",height:"16px",margin:"5px",color:c.colorMonthTxt,"text-align":"center"}).data({value:e+1,field:f}).hover(function(){!a(this).hasClass("selected")&&
!a(this).hasClass("out_of_range")&&a(this).css("background-color",c.colorHover)},function(){a(this).hasClass("selected")||a(this).css("background-color",c.colorDefault)});b.find(".months-"+f).append(d)});"to"==f&&(a('<input type="button" value="'+c.submitText+'"/>').click(function(){a(this).closest(".monthpicker-single,.monthpicker-range").trigger("close")}).appendTo(b),a('<input type="button" value="Clear"/>').click(function(){var b=a(this).closest(".monthpicker-single,.monthpicker-range");b.find('[class^="months"]').find('[class^="month"]').removeClass("selected").css({"background-color":c.colorDefault});
b.find(".monthpicker-to,.monthpicker-from").data("date",null).end().trigger("close")}).appendTo(b));b.find(".month-"+f).bind("click",n);b.find(".monthpicker-scroll").click(function(){var b=a(this).siblings(".curr");if(a(this).hasClass("next")&&(c.maxPoint==null||b.html()<c.maxPoint.getFullYear())){b.html(parseInt(b.html())+1);var f=a(this).parent().parent();if(f.hasClass("monthpicker-range")&&f.find(".monthpicker-to .curr").html()<b.html()){var d=f.find(".monthpicker-to");d.find(".curr").html(b.html());
d=d.data("date");d!=null&&d.setYear(b.html())}j.call(f)}else if(a(this).hasClass("prev")&&(c.minPoint==null||b.html()>c.minPoint.getFullYear())){b.html(parseInt(b.html())-1);f=a(this).parent().parent();if(f.hasClass("monthpicker-range")&&f.find(".monthpicker-from .curr").html()>b.html()){d=f.find(".monthpicker-from");d.find(".curr").html(b.html());d=d.data("date");d!=null&&d.setYear(b.html())}j.call(f)}f=a(this).parent().data("date");f!=null&&f.setYear(b.html());b=a(this).hasClass("next")?"next":
"prev";a(this).parent().find(".selected").trigger("click",[{simulated:true,direction:b}]);a(this).blur()});b.find("*").andSelf().mousedown(function(a){a.preventDefault()});b.find(".monthpicker-scroll").mousedown(function(a){a.stopPropagation()});b.find("*").andSelf().mouseup(function(a){a.stopPropagation()});return b}function o(c){if(9==c.which)a(document).trigger("click.hideMonthpicker"),a(":input:eq("+a(":input").index(a(this).data("input")[0])+1+")").focus();else return!1}function p(){var c=a(this),
b=c.data("input"),e=a(this).children(".monthpicker-to"),e=null!=e.data("date")?e.data("date").getMonth()+1+"/"+e.data("date").getFullYear():"";c.hasClass("monthpicker-single")?b.val(e):(c=a(this).children(".monthpicker-from"),c=null!=c.data("date")?c.data("date").getMonth()+1+"/"+c.data("date").getFullYear():"",""==c&&""==e?b.val(""):b.val(c+" - "+e));a(this).fadeOut(200,function(){a(this).data("ready",false)})}function n(f,b){var e=a(this).parent().parent().parent(),d=e.children(".monthpicker-to");
if(e.hasClass("monthpicker-single")){if(!h(a(this).data("value"),d.find(".curr").html()))return void 0!=b&&b.simulated&&("next"==b.direction?7==a(this).data("value")?a(this).prev().prev(".month-to").trigger("click",[{simulated:!0,direction:b.direction}]):a(this).prev(".month-to").trigger("click",[{simulated:!0,direction:b.direction}]):6==a(this).data("value")?a(this).next().next(".month-to").trigger("click",[{simulated:!0,direction:b.direction}]):a(this).next(".month-to").trigger("click",[{simulated:!0,
direction:b.direction}])),!1;a(this).siblings().removeClass("selected").css({"background-color":c.colorDefault});!a(this).hasClass("selected")||void 0!=b&&b.simulated?a(this).addClass("selected").css({"background-color":c.colorSelected}):a(this).removeClass("selected").css({"background-color":c.colorDefault});0<d.find(".selected").length?d.data("date",new Date(a(this).data("value")+"/1/"+d.find(".curr").html())):d.data("date",null)}else if(e=e.children(".monthpicker-from"),"from"==a(this).data("field")){if(!h(a(this).data("value"),
e.find(".curr").html()))return void 0!=b&&b.simulated&&("next"==b.direction?7==a(this).data("value")?a(this).prev().prev(".month-from").trigger("click",[{simulated:!0,direction:b.direction}]):a(this).prev(".month-from").trigger("click",[{simulated:!0,direction:b.direction}]):6==a(this).data("value")?a(this).next().next(".month-from").trigger("click",[{simulated:!0,direction:b.direction}]):a(this).next(".month-from").trigger("click",[{simulated:!0,direction:b.direction}])),!1;a(this).siblings().removeClass("selected").css({"background-color":c.colorDefault});
!a(this).hasClass("selected")||void 0!=b&&b.simulated?a(this).addClass("selected").css({"background-color":c.colorSelected}):a(this).removeClass("selected").css({"background-color":c.colorDefault});selectedTo=d.find(".month-to.selected");if(0<selectedTo.length&&d.find(".curr").html()==e.find(".curr").html()&&selectedTo.data("value")<a(this).data("value")){var g=d.find(".month-to");g.removeClass("selected").css({"background-color":c.colorDefault});a(g[a(this).data("value")-1]).addClass("selected").css({"background-color":c.colorSelected});
d.data("date",new Date(a(this).data("value")+"/1/"+d.find(".curr").html()))}0<e.find(".selected").length?e.data("date",new Date(a(this).data("value")+"/1/"+e.find(".curr").html())):e.data("date",null)}else{if(!h(a(this).data("value"),d.find(".curr").html()))return void 0!=b&&b.simulated&&("next"==b.direction?7==a(this).data("value")?a(this).prev().prev(".month-to").trigger("click",[{simulated:!0,direction:b.direction}]):a(this).prev(".month-to").trigger("click",[{simulated:!0,direction:b.direction}]):
6==a(this).data("value")?a(this).next().next(".month-to").trigger("click",[{simulated:!0,direction:b.direction}]):a(this).next(".month-to").trigger("click",[{simulated:!0,direction:b.direction}])),!1;a(this).siblings().removeClass("selected").css({"background-color":c.colorDefault});!a(this).hasClass("selected")||b.simulated?a(this).addClass("selected").css({"background-color":c.colorSelected}):a(this).removeClass("selected").css({"background-color":c.colorDefault});selectedFrom=e.find(".month-from.selected");
0<selectedFrom.length&&d.find(".curr").html()==e.find(".curr").html()&&selectedFrom.data("value")>a(this).data("value")&&(g=e.find(".month-from"),g.removeClass("selected").css({"background-color":c.colorDefault}),a(g[a(this).data("value")-1]).addClass("selected").css({"background-color":c.colorSelected}),e.data("date",new Date(a(this).data("value")+"/1/"+e.find(".curr").html())));0<d.find(".selected").length?d.data("date",new Date(a(this).data("value")+"/1/"+d.find(".curr").html())):d.data("date",
null)}}function j(){var c=a(this).find(".monthpicker-from"),b=a(this).find(".monthpicker-to");void 0!==c&&a(this).find('span[class^="month-from"]').each(function(){h(a(this).data("value"),c.find(".curr").html())?a(this).fadeTo(0,1).removeClass("out_of_range"):a(this).fadeTo(0,0.7).addClass("out_of_range")});a(this).find('span[class^="month-to"]').each(function(){h(a(this).data("value"),b.find(".curr").html())?a(this).fadeTo(0,1).removeClass("out_of_range"):a(this).fadeTo(0,0.7).addClass("out_of_range")})}
function k(a){if(void 0==a)return null;if("string"==typeof a&&2==a.split("/").length){var b=parseInt(a.split("/")[0]),a=parseInt(a.split("/")[1]);return isNaN(b)||isNaN(a)||12<Math.floor(b)||1>b||0>a?null:new Date(b+"/1/"+a)}return void 0!==a.getHours?a:"today"==a?(b=new Date,b.setDate(1),b.setHours(0),b.setMinutes(0),b.setSeconds(0),b.setMilliseconds(0),b):null}function h(a,b){var d=new Date(a+"/1/"+b);return null!=c.minPoint&&c.minPoint>d||null!=c.maxPoint&&c.maxPoint<d?!1:!0}"object"!=typeof c&&
(c={});validElems=this.filter("input");if("destroy"==c.destroy)return validElems.each(function(){a(this).data("monthpicker-widget",null).unbind("keydown.monthpicker")}),this;var d=a("<div></div>");d.css("color","#5A5A5A");d.css("color",c.colorDefault);c.colorDefault=d.css("color");d.css("color","#bebebe");d.css("color",c.colorHover);c.colorHover=d.css("color");d.css("color","#0099FF");d.css("color",c.colorSelected);c.colorSelected=d.css("color");d.css("color","#DDDDDD");d.css("color",c.colorBknd);
c.colorBknd=d.css("color");d.css("color","#FFFFFF");d.css("color",c.colorMonthTxt);c.colorMonthTxt=d.css("color");d.css("color","#000000");d.css("color",c.colorYearTxt);c.colorYearTxt=d.css("color");d.css("font-size","12px");d.css("font-size",c.fontSize);c.fontSize=d.css("font-size");d.css("font-family","sans-serif");d.css("font-family",c.font);c.font=d.css("font-family");"string"!=typeof c.submitText&&(c.submitText="Enter");c.minPoint=k(c.minPoint);c.maxPoint=k(c.maxPoint);null!=c.minPoint&&null!=
c.maxPoint&&c.minPoint>c.maxPoint&&(c.minPoint=null,c.maxPoint=null);validElems.each(function(){var d=a(this),b=a("<div></div>");b.data("input",d).css({display:"none",position:"absolute",border:"solid 1px #5A5A5A",padding:"5px","background-color":c.colorBknd,"font-family":c.font,"font-size":c.fontSize,"font-weight":"bold"});c.type=="range"?b.append(i("from").css("margin-bottom","10px")).append(i("to")).attr("class","monthpicker-range"):b.append(i("to")).attr("class","monthpicker-single");d.data("monthpicker-widget",
b).data("value","");b.bind("close",p).bind("keydown.monthpicker",o);a(this).focus(function(){var b=d.data("monthpicker-widget");j.call(b);b.appendTo("body").css({left:a(this).offset().left+"px",top:d.offset().top+d.height()+6+"px"}).click(function(a){a.stopPropagation();return false}).fadeIn(200,function(){d.data("ready",true)});a(document).bind("click.hideMonthpicker",function(b,c){if(b.button==2)return true;c===void 0&&a(document).unbind("click.hideMonthpicker");a('body>div[class*="monthpicker-"]').not(c).trigger("close")}).trigger("click.hideMonthpicker",
b[0])}).click(function(){!a(this).data("monthpicker-widget").is(":animated")&&!a(this).data("monthpicker-widget").is(":visible")&&a(this).focus()}).keydown(function(b){if(l(b.which,a(this)))return false;a(document).trigger("click.hideMonthpicker");return true}).keyup(function(b){switch(b.which){case 16:case 17:case 18:a(this).data("monthpicker-funckey",false)}return true}).click(function(b){a(this).data("monthpicker-widget").data("ready")!=true&&b.stopPropagation();a('body>div[class*="monthpicker-"]').each(function(){a(this).data("ready")&&
a(this).trigger("close")})})});return this}})(jQuery);