-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnepali.datepicker.v2.2.min.js
74 lines (74 loc) · 14.6 KB
/
nepali.datepicker.v2.2.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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function getCalendarDivString(t){var e='<div id="ndp-nepali-box" class="ndp-corner-all" style="display:none">'
return e+='<span id="ndp-target-id" style="display:none"></span>',e+='<div class="ndp-corner-all ndp-header">',e+='<a href="javascript:void(0)" id="prev" title="Previous Month" class="ndp-prev"></a>',e+='<a href="javascript:void(0)" id="next" title="Next Month" class="ndp-next"></a>',e+='<span id="currentMonth"></span>',e+="</div>",e+='<div id="npd-table-div">',e+="<table>",e+='<tr class="ndp-days">',e+="<th>आ</th>",e+="<th>सो</th>",e+="<th>मं</th>",e+="<th>बु</th>",e+="<th>बि</th>",e+="<th>शु</th>",e+="<th>श</th>",e+="</tr>",e+="</table>",e+="</div>",e+="</div>"}function showNdpCalendarBox(t){if(npdCalendarVisible)hideCalendarBox(!1)
else{ndpData[t]&&(ndpAttr=ndpData[t])
var e=$("#"+t).val()
$("#ndp-target-id").html(t)
var n=$("#"+t).offset()
$("#ndp-nepali-box").css("top",n.top+$("#"+t).outerHeight()),$("#ndp-nepali-box").css("left",n.left),showCalendar(e),npdCalendarVisible=!0}}function setSelectedDay(t){var e=$("#ndp-target-id").html()
$("#"+e).val(t),ndpAttr.ndpEnglishInput&&$("#"+ndpAttr.ndpEnglishInput).val(BS2AD(t)),hideCalendarBox()}function showCalendar(t){$("#ndp-nepali-box table").find("tr:gt(0)").remove(),""===t?$("#ndp-nepali-box table").append(getDateTable("")):$("#ndp-nepali-box table").append(getDateTable(t)),"block"==$("#ndp-nepali-box").css("display")&&$("#ndp-nepali-box").hide(),$("#ndp-nepali-box").fadeIn(100)}function getDateTable(t){var e="",n=""
if(""===t){var a=getNepaliDate()
return e=getMonthParameters(a),n=getDateRows(e[0],e[1],e[2],e[3],e[4])}return e=getMonthParameters(t),n=getDateRows(e[0],e[1],e[2],e[3],e[4])}function performSelectMonth(t){showCalendar((ndpAttr.npdYear?$("#npd-year-select").val():t)+"-"+$("#npd-month-select").val()+"-01")}function performSelectYear(t){showCalendar($("#npd-year-select").val()+"-"+(ndpAttr.npdMonth?$("#npd-month-select").val():t)+"-01")}function getMonthSelect(t,e){var n=getNepaliMonthsInNepali(),a='<select id="npd-month-select" onchange="performSelectMonth('+e+')">'
return n.forEach(function(e,n){a+='<option value="'+(n+1)+'"'+(n+1==t?" selected":"")+">"+e+"<li>"}),a+="<select>"}function getYearSelect(t,e,n){var a='<select id="npd-year-select" onchange="performSelectYear('+t+')">'
for(i=Math.round(n/2)>0&&parseInt(e)-Math.round(n/2)>=2e3?parseInt(e)-Math.round(n/2):2e3;i<=(Math.round(n/2)>0&&parseInt(e)+Math.round(n/2)<=2090?parseInt(e)+Math.round(n/2):2090);i++)a+='<option value="'+i+'"'+(e==i?" selected":"")+">"+englishNo2Nep(i)+"<li>"
return a+="<select>"}function getMonthParameters(t){var e=t.split("-"),n=e[0],a=e[1],s=ndpAttr.npdYearCount||0
ndpAttr.npdMonth&&ndpAttr.npdYear?$("#currentMonth").html(getMonthSelect(a,n)+getYearSelect(a,n,s)):ndpAttr.npdMonth?$("#currentMonth").html(getMonthSelect(a,n)+" "+englishNo2Nep(n)):ndpAttr.npdYear?$("#currentMonth").html(getNepaliMonth(a-1)+" "+getYearSelect(a,n,s)):$("#currentMonth").html(getNepaliMonth(a-1)+" "+englishNo2Nep(n)),nYear=pYear=n,nMonth=parseInt(a,10)+1,nMonth>12&&(nYear++,nMonth="01"),pMonth=parseInt(a,10)-1,pMonth<1&&(pYear--,pMonth="12"),$("#prev").attr("onclick","showCalendar('"+pYear+"-"+pMonth+"-01')"),$("#next").attr("onclick","showCalendar('"+nYear+"-"+nMonth+"-01')")
var r=e[2],i=numberOfBsDays(n,a-1),d=new NepaliDateConverter,o=a+"/1/"+n,h=d.bs2ad(o),p=h.split("-"),l=p[0],u=p[1],b=p[2],c=new Date(l,u-1,b),g=c.getDay()
return[g,i,n,a,r]}function getDateRows(t,e,n,a,s){for(var r=getNepaliDate(),i=r.split("-"),d=i[0],o=get2DigitNo(i[1]),h=get2DigitNo(i[2]),p="",l=0;t+e>l;l++){l%7===0&&(p+="<tr>")
var u=l-t+1,b=""+n+"-"+get2DigitNo(a)+"-"+get2DigitNo(u),c=""
c=n==d&&get2DigitNo(a)==o&&h==get2DigitNo(u)?"ndp-selected":u==s?"ndp-current":"ndp-date",ndpAttr.disableDaysBefore&&parseInt(ndpAttr.disableDaysBefore)>0&&(ndpAttr.disableBefore=getNepaliFormat(BsAddDays(getNepaliFormat(getNepaliDate()),-1*parseInt(ndpAttr.disableDaysBefore)))),ndpAttr.disableDaysAfter&&parseInt(ndpAttr.disableDaysAfter)>0&&(ndpAttr.disableAfter=getNepaliFormat(BsAddDays(getNepaliFormat(getNepaliDate()),parseInt(ndpAttr.disableDaysAfter)))),t>l?p+="<td></td>\n":(p+="<td class='"+c+"'>",p+=ndpAttr.disableAfter&&BsDatesDiff(ndpAttr.disableAfter,getNepaliFormat(b))>0||ndpAttr.disableBefore&&BsDatesDiff(ndpAttr.disableBefore,getNepaliFormat(b))<0?"<a class=\"ndp-disabled\" href='javascript:void(0)'>"+englishNo2Nep(u)+"</a>":"<a href='javascript:void(0)' onclick=\"setSelectedDay('"+b+"')\">"+englishNo2Nep(u)+"</a>",p+="</td>\n"),l%7==6&&(p+="</tr>\n")}return p}function hideCalendarBox(t){t=void 0!==t?t:!0,$("#ndp-nepali-box").fadeOut(100),npdCalendarVisible=!1,t&&ndpAttr.onChange&&ndpAttr.onChange()}function BsAddDays(t,e){var n=new NepaliDateConverter
return n.add_bs_days(t,e)}function BsDatesDiff(t,e){var n=new NepaliDateConverter
return n.count_bs_days(t,e)+2}function get2DigitNo(t){return t=parseInt(t,10),10>t?"0"+t:""+t}function getMonths(){var t=["January","February","March","April","May","June","July","August","September","October","November","December"]
return t}function getNepaliMonths(){var t=["Baisakh","Jestha","Ashar","Shrawan","Bhadra","Ashoj","Kartik","Mangsir","Poush","Magh","Falgun","Chaitra"]
return t}function getNepaliDaysShort(){var t=["आ","सो","मं","बु","बि","शु","श"]
return t}function getNepaliMonthsInNepali(){return["बैशाख","जेठ","अषाढ","श्रावण","भाद्र","आश्विन","कार्तिक","मङ्सिर","पौष","माघ","फाल्गुन","चैत्र"]}function getNepaliMonth(t){t=parseInt(t,10)
var e=getNepaliMonthsInNepali()
return e[t]}function getCurrentDayName(){var t=new Date,e=t.getDay(),n=Array(7)
return n[0]="Sunday",n[1]="Monday",n[2]="Tuesday",n[3]="Wednesday",n[4]="Thursday",n[5]="Friday",n[6]="Saturday",n[e]}function getDayFromDate(t){var e=t.split("-"),n=e[2],a=e[1],s=e[0],r=new Date(s,a-1,n),i=r.getDay(),d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
return d[i]}function numberOfBsDays(t,e){var n=new NepaliDateConverter
return n.bs[t][e]}function numberOfDays(t,e){var n=new Date(t,e,0)
return n.getDate()}function AD2BS(t){var e=new NepaliDateConverter
return e.ad2bs(getNepaliFormat(t))}function BS2AD(t){var e=new NepaliDateConverter
return e.bs2ad(getNepaliFormat(t))}function getNepaliDate(){var t=new NepaliDateConverter
return t.ad2bs(getDateInNo("/"))}function getDateInWords(){var t=getMonths(),e=new Date,n=e.getDate(),a=e.getMonth()+1,s=e.getYear(),r=1e3>s?s+1900:s
return n+" "+t[a]+", "+r}function getDateInNo(t){var e=new Date,n=e.getDate(),a=e.getMonth()+1,s=e.getFullYear()
return a+t+n+t+s}function getNepaliFormat(t){var e=t.split("-"),n=e[2],a=e[1],s=e[0]
return a+"/"+n+"/"+s}function getAdDateInWords(t){var e=getMonths(),n=t.split("-"),a=n[2],s=n[1],r=n[0]
return a+" "+e[s]+", "+r}function getNepaliDateInWords(t){var e=getNepaliMonths(),n=t.split("-"),a=n[2],s=n[1],r=n[0]
return a+" "+e[s]+", "+r}function getCurrentYear(){var t=new Date,e=t.getFullYear()
return e}function getCurrentMonth(){var t=new Date,e=t.getMonth()+1
return e}function getCurrentDay(){var t=new Date,e=t.getDate()
return e}function makeArray(){for(i=0;i<makeArray.arguments.length;i++)this[i+1]=makeArray.arguments[i]}function englishNo2Nep(t){t=""+t
for(var e="",n=0;n<t.length;n++)e+=convertNos(t[n])
return e}function convertNos(t){switch(t){case"०":return 0
case"१":return 1
case"२":return 2
case"३":return 3
case"४":return 4
case"५":return 5
case"६":return 6
case"७":return 7
case"८":return 8
case"९":return 9
case"0":return"०"
case"1":return"१"
case"2":return"२"
case"3":return"३"
case"4":return"४"
case"5":return"५"
case"6":return"६"
case"7":return"७"
case"8":return"८"
case"9":return"९"}}function NepaliDateConverter(){this.bs_date_eq="09/17/2000",this.ad_date_eq="01/01/1944",this.bs=[],this.bs[2e3]=[30,32,31,32,31,30,30,30,29,30,29,31],this.bs[2001]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2002]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2003]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2004]=[30,32,31,32,31,30,30,30,29,30,29,31],this.bs[2005]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2006]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2007]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2008]=[31,31,31,32,31,31,29,30,30,29,29,31],this.bs[2009]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2010]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2011]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2012]=[31,31,31,32,31,31,29,30,30,29,30,30],this.bs[2013]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2014]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2015]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2016]=[31,31,31,32,31,31,29,30,30,29,30,30],this.bs[2017]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2018]=[31,32,31,32,31,30,30,29,30,29,30,30],this.bs[2019]=[31,32,31,32,31,30,30,30,29,30,29,31],this.bs[2020]=[31,31,31,32,31,31,30,29,30,29,30,30],this.bs[2021]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2022]=[31,32,31,32,31,30,30,30,29,29,30,30],this.bs[2023]=[31,32,31,32,31,30,30,30,29,30,29,31],this.bs[2024]=[31,31,31,32,31,31,30,29,30,29,30,30],this.bs[2025]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2026]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2027]=[30,32,31,32,31,30,30,30,29,30,29,31],this.bs[2028]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2029]=[31,31,32,31,32,30,30,29,30,29,30,30],this.bs[2030]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2031]=[30,32,31,32,31,30,30,30,29,30,29,31],this.bs[2032]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2033]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2034]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2035]=[30,32,31,32,31,31,29,30,30,29,29,31],this.bs[2036]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2037]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2038]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2039]=[31,31,31,32,31,31,29,30,30,29,30,30],this.bs[2040]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2041]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2042]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2043]=[31,31,31,32,31,31,29,30,30,29,30,30],this.bs[2044]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2045]=[31,32,31,32,31,30,30,29,30,29,30,30],this.bs[2046]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2047]=[31,31,31,32,31,31,30,29,30,29,30,30],this.bs[2048]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2049]=[31,32,31,32,31,30,30,30,29,29,30,30],this.bs[2050]=[31,32,31,32,31,30,30,30,29,30,29,31],this.bs[2051]=[31,31,31,32,31,31,30,29,30,29,30,30],this.bs[2052]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2053]=[31,32,31,32,31,30,30,30,29,29,30,30],this.bs[2054]=[31,32,31,32,31,30,30,30,29,30,29,31],this.bs[2055]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2056]=[31,31,32,31,32,30,30,29,30,29,30,30],this.bs[2057]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2058]=[30,32,31,32,31,30,30,30,29,30,29,31],this.bs[2059]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2060]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2061]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2062]=[30,32,31,32,31,31,29,30,29,30,29,31],this.bs[2063]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2064]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2065]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2066]=[31,31,31,32,31,31,29,30,30,29,29,31],this.bs[2067]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2068]=[31,31,32,32,31,30,30,29,30,29,30,30],this.bs[2069]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2070]=[31,31,31,32,31,31,29,30,30,29,30,30],this.bs[2071]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2072]=[31,32,31,32,31,30,30,29,30,29,30,30],this.bs[2073]=[31,32,31,32,31,30,30,30,29,29,30,31],this.bs[2074]=[31,31,31,32,31,31,30,29,30,29,30,30],this.bs[2075]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2076]=[31,32,31,32,31,30,30,30,29,29,30,30],this.bs[2077]=[31,32,31,32,31,30,30,30,29,30,29,31],this.bs[2078]=[31,31,31,32,31,31,30,29,30,29,30,30],this.bs[2079]=[31,31,32,31,31,31,30,29,30,29,30,30],this.bs[2080]=[31,32,31,32,31,30,30,30,29,29,30,30],this.bs[2081]=[31,31,32,32,31,30,30,30,29,30,30,30],this.bs[2082]=[30,32,31,32,31,30,30,30,29,30,30,30],this.bs[2083]=[31,31,32,31,31,30,30,30,29,30,30,30],this.bs[2084]=[31,31,32,31,31,30,30,30,29,30,30,30],this.bs[2085]=[31,32,31,32,30,31,30,30,29,30,30,30],this.bs[2086]=[30,32,31,32,31,30,30,30,29,30,30,30],this.bs[2087]=[31,31,32,31,31,31,30,30,29,30,30,30],this.bs[2088]=[30,31,32,32,30,31,30,30,29,30,30,30],this.bs[2089]=[30,32,31,32,31,30,30,30,29,30,30,30],this.bs[2090]=[30,32,31,32,31,30,30,30,29,30,30,30],this.count_ad_days=count_ad_days,this.count_bs_days=count_bs_days,this.add_bs_days=add_bs_days,this.add_ad_days=add_ad_days,this.bs2ad=bs2ad,this.ad2bs=ad2bs}function count_ad_days(t,e){var n=864e5,a=t.split("/"),s=e.split("/")
a[2]=+a[2],a[1]=+a[1],a[0]=+a[0],s[2]=+s[2],s[1]=+s[1],s[0]=+s[0]
var r=new Date(a[2],a[0]-1,a[1]),i=new Date(s[2],s[0]-1,s[1]),d=Math.ceil((i.getTime()-r.getTime())/n)
return d}function count_bs_days(t,e){var n=t.split("/"),a=e.split("/"),s=+n[2],r=+n[0],i=+n[1],d=+a[2],o=+a[0],h=+a[1],p=0,l=0
for(l=s;d>=l;l++)p+=arraySum(this.bs[l])
for(l=0;r>l;l++)p-=this.bs[s][l]
for(p+=this.bs[s][11],l=o-1;12>l;l++)p-=this.bs[d][l]
return p-=i+1,p+=h-1}function add_ad_days(t,e){var n=new Date(t)
return n.setDate(n.getDate()+e),ad_month=n.getMonth()+1,ad_day=n.getDate(),n.getFullYear()+"-"+(ad_month<10?"0"+ad_month:ad_month)+"-"+(ad_day<10?"0"+ad_day:ad_day)}function add_bs_days(t,e){var n=t.split("/"),a=+n[2],s=+n[0],r=+n[1]
for(r+=e;r>this.bs[a][s-1];)r-=this.bs[a][s-1],s++,s>12&&(s=1,a++)
return a+"-"+(10>s?"0"+s:s)+"-"+(10>r?"0"+r:r)}function bs2ad(t){return days_count=this.count_bs_days(this.bs_date_eq,t),this.add_ad_days(this.ad_date_eq,days_count)}function ad2bs(t){return days_count=this.count_ad_days(this.ad_date_eq,t),this.add_bs_days(this.bs_date_eq,days_count)}ndpAttr={},npdCalendarVisible="",npdIgnoreMouseUp=!1,ndpData=[],function(t){t.fn.nepaliDatePicker=function(e){e=void 0!==e?e:{},ndpAttr=e,this.each(function(){var n=t(this).attr("id")
t(this).addClass("ndp-nepali-calendar"),ndpData[n]=e,ndpAttr.onFocus!==!1&&t(this).attr("onfocus","showNdpCalendarBox('"+n+"')"),ndpAttr.ndpTriggerButton&&t(this).after('<button type="button" class="ndp-click-trigger '+(ndpAttr.ndpTriggerButtonClass?ndpAttr.ndpTriggerButtonClass:"")+'" onclick="showNdpCalendarBox("'+n+'")">'+(ndpAttr.ndpTriggerButtonText?ndpAttr.ndpTriggerButtonText:"Pick Date")+"</button>")}),t("body").append(getCalendarDivString(ndpAttr)),t(".ndp-nepali-calendar, #ndp-nepali-box").hover(function(){mouse_is_inside=!0},function(){mouse_is_inside=!1}),t("html").mouseup(function(e){t(e.target).is(".ndp-click-trigger")||npdCalendarVisible&&!mouse_is_inside&&hideCalendarBox(!1)})}}(jQuery)
var mouse_is_inside=!1
arraySum=function(t){for(var e=0,n=t.length;n;e+=t[--n]);return e}