diff --git a/bower.json b/bower.json index c209f72c..2c8e2c10 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-calendar", - "version": "0.2.3", + "version": "0.2.4", "main": [ "./js/language/en-GB.js", "./js/calendar.js", diff --git a/css/calendar.css b/css/calendar.css index 4e4cadb1..0de36a29 100755 --- a/css/calendar.css +++ b/css/calendar.css @@ -268,7 +268,6 @@ #cal-day-box #cal-day-panel { position: relative; padding-left: 60px; - z-index: 0; } #cal-day-box #cal-day-panel-hour { position: absolute; diff --git a/js/calendar.min.js b/js/calendar.min.js index 2a960c45..48f6c1b0 100644 --- a/js/calendar.min.js +++ b/js/calendar.min.js @@ -1,2 +1,2 @@ -/*! bootstrap-calendar - v0.2.3 - 2014-02-11 - https://github.com/Serhioromano/bootstrap-calendar */ -"use strict";Date.prototype.getWeek=function(){var t=new Date(this.getFullYear(),0,1);return Math.ceil(((this.getTime()-t.getTime())/864e5+t.getDay()+1)/7)},Date.prototype.getMonthFormatted=function(){var t=this.getMonth()+1;return 10>t?"0"+t:t},Date.prototype.getDateFormatted=function(){var t=this.getDate();return 10>t?"0"+t:t},String.prototype.format||(String.prototype.format=function(){var t=arguments;return this.replace(/{(\d+)}/g,function(e,a){return t[a]!==void 0?t[a]:e})}),String.prototype.formatNum||(String.prototype.formatNum=function(t){for(var e=""+this;t>e.length;)e="0"+e;return e}),function(t){function e(t,e){var a,o,i;i=t,a=0>t.indexOf("?")?"?":"&";for(o in e)i+=a+o+"="+encodeURIComponent(e[o]),a="&";return i}function a(e,a){var o=null!=e.options[a]?e.options[a]:null,i=null!=e.locale[a]?e.locale[a]:null;if("holidays"==a&&e.options.merge_holidays){var s={};return t.extend(!0,s,i?i:d.holidays),o&&t.extend(!0,s,o),s}return null!=o?o:null!=i?i:d[a]}function o(e,s){var n=[],l=a(e,"holidays");for(var d in l)n.push(d+":"+l[d]);if(n.push(s),n=n.join("|"),n in o.cache)return o.cache[n];var h=[];return t.each(l,function(e,a){var o=null,n=null,l=!1;if(t.each(e.split(">"),function(t,a){var d,h=null;if(d=/^(\d\d)-(\d\d)$/.exec(a))h=new Date(s,parseInt(d[2],10)-1,parseInt(d[1],10));else if(d=/^(\d\d)-(\d\d)-(\d\d\d\d)$/.exec(a))parseInt(d[3],10)==s&&(h=new Date(s,parseInt(d[2],10)-1,parseInt(d[1],10)));else if(d=/^easter(([+\-])(\d+))?$/.exec(a))h=r(s,d[1]?parseInt(d[1],10):0);else if(d=/^(\d\d)([+\-])([1-5])\*([0-6])$/.exec(a)){var p=parseInt(d[1],10)-1,c=d[2],u=parseInt(d[3]),m=parseInt(d[4]);switch(c){case"+":for(var y=new Date(s,p,-6);y.getDay()!=m;)y=new Date(y.getFullYear(),y.getMonth(),y.getDate()+1);h=new Date(y.getFullYear(),y.getMonth(),y.getDate()+7*u);break;case"-":for(var y=new Date(s,p+1,7);y.getDay()!=m;)y=new Date(y.getFullYear(),y.getMonth(),y.getDate()-1);h=new Date(y.getFullYear(),y.getMonth(),y.getDate()-7*u)}}if(!h)return i("Unknown holiday: "+e),l=!0,!1;switch(t){case 0:o=h;break;case 1:if(h.getTime()<=o.getTime())return i("Unknown holiday: "+e),l=!0,!1;n=h;break;default:return i("Unknown holiday: "+e),l=!0,!1}}),!l){var d=[];if(n)for(var p=new Date(o.getTime());p.getTime()<=n.getTime();p.setDate(p.getDate()+1))d.push(new Date(p.getTime()));else d.push(o);h.push({name:a,days:d})}}),o.cache[n]=h,o.cache[n]}function i(e){"object"==t.type(window.console)&&"function"==t.type(window.console.warn)&&window.console.warn("[Bootstrap-Calendar] "+e)}function s(e,a){return this.options=t.extend(!0,{position:{start:new Date,end:new Date}},l,e),this.setLanguage(this.options.language),this.context=a,a.css("width",this.options.width).addClass("cal-context"),this.view(),this}function n(e,a,o,i){e.stopPropagation();var a=t(a),s=a.closest(".cal-cell"),n=s.closest(".cal-before-eventlist"),r=s.data("cal-row");a.fadeOut("fast"),o.slideUp("fast",function(){var e=t(".events-list",s);o.html(i.options.templates["events-list"]({cal:i,events:i.getEventsBetween(parseInt(e.data("cal-start")),parseInt(e.data("cal-end")))})),n.after(o),i.activecell=t("[data-cal-date]",s).text(),t("#cal-slide-tick").addClass("tick"+r).show(),o.slideDown("fast",function(){t("body").one("click",function(){o.slideUp("fast"),i.activecell=0})})}),t("a.event-item").mouseenter(function(){t('a[data-event-id="'+t(this).data("event-id")+'"]').closest(".cal-cell1").addClass("day-highlight dh-"+t(this).data("event-class"))}),t("a.event-item").mouseleave(function(){t("div.cal-cell1").removeClass("day-highlight dh-"+t(this).data("event-class"))}),i._update_modal()}function r(t,e){var a=t%19,o=Math.floor(t/100),i=t%100,s=Math.floor(o/4),n=o%4,r=Math.floor((o+8)/25),l=Math.floor((o-r+1)/3),d=(19*a+o-s-l+15)%30,h=Math.floor(i/4),p=i%4,c=(32+2*n+2*h-d-p)%7,u=Math.floor((a+11*d+22*c)/451),m=d+c+7*u+114,y=Math.floor(m/31)-1,g=m%31+1;return new Date(t,y,g+(e?e:0),0,0,0)}var l={width:"100%",view:"month",day:"now",time_start:"06:00",time_end:"22:00",time_split:"30",events_source:"",tmpl_path:"tmpls/",tmpl_cache:!0,classes:{months:{inmonth:"cal-day-inmonth",outmonth:"cal-day-outmonth",saturday:"cal-day-weekend",sunday:"cal-day-weekend",holidays:"cal-day-holiday",today:"cal-day-today"},week:{workday:"cal-day-workday",saturday:"cal-day-weekend",sunday:"cal-day-weekend",holidays:"cal-day-holiday",today:"cal-day-today"}},modal:null,modal_type:"iframe",modal_title:null,views:{year:{slide_events:1,enable:1},month:{slide_events:1,enable:1},week:{enable:1},day:{enable:1}},merge_holidays:!1,onAfterEventsLoad:function(){},onBeforeEventsLoad:function(t){t()},onAfterViewLoad:function(){},events:[],templates:{year:"",month:"",week:"",day:""},stop_cycling:!1},d={first_day:2,holidays:{"01-01":"New Year's Day","01+3*1":"Birthday of Dr. Martin Luther King, Jr.","02+3*1":"Washington's Birthday","05-1*1":"Memorial Day","04-07":"Independence Day","09+1*1":"Labor Day","10+2*1":"Columbus Day","11-11":"Veterans Day","11+4*4":"Thanksgiving Day","25-12":"Christmas"}},h={error_noview:"Calendar: View {0} not found",error_dateformat:'Calendar: Wrong date format {0}. Should be either "now" or "yyyy-mm-dd"',error_loadurl:"Calendar: Event URL is not set",error_where:'Calendar: Wrong navigation direction {0}. Can be only "next" or "prev" or "today"',error_timedevide:"Calendar: Time split parameter should divide 60 without decimals. Something like 10, 15, 30",no_events_in_day:"No events in this day.",title_year:"{0}",title_month:"{0} {1}",title_week:"week {0} of {1}",title_day:"{0} {1} {2}, {3}",week:"Week {0}",all_day:"All day",time:"Time",events:"Events",before_time:"Ends before timeline",after_time:"Starts after timeline",m0:"January",m1:"February",m2:"March",m3:"April",m4:"May",m5:"June",m6:"July",m7:"August",m8:"September",m9:"October",m10:"November",m11:"December",ms0:"Jan",ms1:"Feb",ms2:"Mar",ms3:"Apr",ms4:"May",ms5:"Jun",ms6:"Jul",ms7:"Aug",ms8:"Sep",ms9:"Oct",ms10:"Nov",ms11:"Dec",d0:"Sunday",d1:"Monday",d2:"Tuesday",d3:"Wednesday",d4:"Thursday",d5:"Friday",d6:"Saturday"},p="";try{"object"==t.type(window.jstz)&&"function"==t.type(jstz.determine)&&(p=jstz.determine().name(),"string"!==t.type(p)&&(p=""))}catch(c){}o.cache={},s.prototype.setOptions=function(e){t.extend(this.options,e),"language"in e&&this.setLanguage(e.language),"modal"in e&&this._update_modal()},s.prototype.setLanguage=function(e){window.calendar_languages&&e in window.calendar_languages?(this.locale=t.extend(!0,{},h,calendar_languages[e]),this.options.language=e):(this.locale=h,delete this.options.language)},s.prototype._render=function(){this.context.html(""),this._loadTemplate(this.options.view),this.stop_cycling=!1;var t={};t.cal=this,t.day=1,t.months=1==a(this,"first_day")?[this.locale.d1,this.locale.d2,this.locale.d3,this.locale.d4,this.locale.d5,this.locale.d6,this.locale.d0]:[this.locale.d0,this.locale.d1,this.locale.d2,this.locale.d3,this.locale.d4,this.locale.d5,this.locale.d6];var e=parseInt(this.options.position.start.getTime()),o=parseInt(this.options.position.end.getTime());switch(t.events=this.getEventsBetween(e,o),this.options.view){case"month":break;case"week":this._calculate_hour_minutes(t);break;case"day":this._calculate_hour_minutes(t)}t.start=new Date(this.options.position.start.getTime()),t.lang=this.locale,this.context.append(this.options.templates[this.options.view](t)),this._update()},s.prototype._calculate_hour_minutes=function(e){var a=this;e.in_hour=60/parseInt(this.options.time_split),e.hour_split=parseInt(this.options.time_split),(!/^\d+$/.exec(e.in_hour)||this.options.time_split>30)&&t.error(this.locale.error_timedevide);var o=this.options.time_start.split(":"),s=this.options.time_end.split(":");e.hours=parseInt(s[0])-parseInt(o[0]);var n=e.hours*e.in_hour,r=6e4*parseInt(this.options.time_split),l=new Date(this.options.position.start.getTime());l.setHours(o[0]),l.setMinutes(o[1]);var d=new Date(this.options.position.start.getTime());d.setHours(s[0]),d.setMinutes(s[1]),e.all_day=[],e.by_hour=[],e.after_time=[],e.before_time=[],t.each(e.events,function(t,o){var s=new Date(parseInt(o.start)),h=new Date(parseInt(o.end));if(o.start_hour=(""+s.getHours()).formatNum(2)+":"+(""+s.getMinutes()).formatNum(2),o.end_hour=(""+h.getHours()).formatNum(2)+":"+(""+h.getMinutes()).formatNum(2),o.startd.getTime()&&(i(1),o.end_hour=h.getDate()+" "+a.locale["ms"+h.getMonth()]+" "+o.end_hour),o.startd.getTime())return e.all_day.push(o),void 0;if(o.endd.getTime())return e.after_time.push(o),void 0;var p=l.getTime()-o.start;o.top=p>=0?0:Math.abs(p)/r;var c=n-o.top,u=(o.end-o.start)/r;p>=0&&(u=(o.end-l.getTime())/r),o.lines=u,u>c&&(o.lines=c),e.by_hour.push(o)})},s.prototype._hour=function(t,e){var a=this.options.time_start.split(":"),t=""+(parseInt(a[0])+t),o=""+this.options.time_split*e;return t.formatNum(2)+":"+o.formatNum(2)},s.prototype._week=function(){this._loadTemplate("week-days");var e={},o=parseInt(this.options.position.start.getTime()),i=parseInt(this.options.position.end.getTime()),s=[],n=this,r=a(this,"first_day");return t.each(this.getEventsBetween(o,i),function(t,e){e.start_day=new Date(parseInt(e.start)).getDay(),1==r&&(e.start_day=(e.start_day+6)%7),e.days=864e5>=e.end-e.start?1:(e.end-e.start)/864e5,o>e.start&&(e.days=e.days-(o-e.start)/864e5,e.start_day=0),e.days=Math.ceil(e.days),e.start_day+e.days>7&&(e.days=7-e.start_day),s.push(e)}),e.events=s,e.cal=this,n.options.templates["week-days"](e)},s.prototype._month=function(t){this._loadTemplate("year-month");var e={cal:this},a=t+1;e.data_day=this.options.position.start.getFullYear()+"-"+(10>a?"0"+a:a)+"-"+"01",e.month_name=this.locale["m"+t];var o=new Date(this.options.position.start.getFullYear(),t,1,0,0,0);return e.start=parseInt(o.getTime()),e.end=parseInt(new Date(this.options.position.start.getFullYear(),t+1,1,0,0,0).getTime()),e.events=this.getEventsBetween(e.start,e.end),this.options.templates["year-month"](e)},s.prototype._day=function(e,o){this._loadTemplate("month-day");var i={tooltip:"",cal:this},s=this.options.classes.months.outmonth,n=this.options.position.start.getDay();2==a(this,"first_day")?n++:n=0==n?7:n,o=o-n+1;var r=new Date(this.options.position.start.getFullYear(),this.options.position.start.getMonth(),o,0,0,0);o>0&&(s=this.options.classes.months.inmonth);var l=new Date(this.options.position.end.getTime()-1).getDate();if(o+1>l&&(this.stop_cycling=!0),o>l&&(o-=l,s=this.options.classes.months.outmonth),s=t.trim(s+" "+this._getDayClass("months",r)),0>=o){var d=new Date(this.options.position.start.getFullYear(),this.options.position.start.getMonth(),0).getDate();o=d-Math.abs(o),s+=" cal-month-first-row"}var h=this._getHoliday(r);return h!==!1&&(i.tooltip=h),i.data_day=r.getFullYear()+"-"+r.getMonthFormatted()+"-"+(10>o?"0"+o:o),i.cls=s,i.day=o,i.start=parseInt(r.getTime()),i.end=parseInt(i.start+864e5),i.events=this.getEventsBetween(i.start,i.end),this.options.templates["month-day"](i)},s.prototype._getHoliday=function(e){var a=!1;return t.each(o(this,e.getFullYear()),function(){var o=!1;return t.each(this.days,function(){return this.toDateString()==e.toDateString()?(o=!0,!1):void 0}),o?(a=this.name,!1):void 0}),a},s.prototype._getHolidayName=function(t){var e=this._getHoliday(t);return e===!1?"":e},s.prototype._getDayClass=function(t,e){var a=this,o=function(e,o){var i;i=a.options.classes&&t in a.options.classes&&e in a.options.classes[t]?a.options.classes[t][e]:"","string"==typeof i&&i.length&&o.push(i)},i=[];e.toDateString()==(new Date).toDateString()&&o("today",i);var s=this._getHoliday(e);switch(s!==!1&&o("holidays",i),e.getDay()){case 0:o("sunday",i);break;case 6:o("saturday",i)}return i.join(" ")},s.prototype.view=function(t){if(t){if(!this.options.views[t].enable)return;this.options.view=t}this._init_position(),this._loadEvents(),this._render(),this.options.onAfterViewLoad.call(this,this.options.view)},s.prototype.navigate=function(e,a){var o=t.extend({},this.options.position);if("next"==e)switch(this.options.view){case"year":o.start.setFullYear(this.options.position.start.getFullYear()+1);break;case"month":o.start.setMonth(this.options.position.start.getMonth()+1);break;case"week":o.start.setDate(this.options.position.start.getDate()+7);break;case"day":o.start.setDate(this.options.position.start.getDate()+1)}else if("prev"==e)switch(this.options.view){case"year":o.start.setFullYear(this.options.position.start.getFullYear()-1);break;case"month":o.start.setMonth(this.options.position.start.getMonth()-1);break;case"week":o.start.setDate(this.options.position.start.getDate()-7);break;case"day":o.start.setDate(this.options.position.start.getDate()-1)}else"today"==e?o.start.setTime((new Date).getTime()):t.error(this.locale.error_where.format(e));this.options.day=o.start.getFullYear()+"-"+o.start.getMonthFormatted()+"-"+o.start.getDateFormatted(),this.view(),_.isFunction(a)&&a()},s.prototype._init_position=function(){var e,o,i;if("now"==this.options.day){var s=new Date;e=s.getFullYear(),o=s.getMonth(),i=s.getDate()}else if(this.options.day.match(/^\d{4}-\d{2}-\d{2}$/g)){var n=this.options.day.split("-");e=parseInt(n[0],10),o=parseInt(n[1],10)-1,i=parseInt(n[2],10)}else t.error(this.locale.error_dateformat.format(this.options.day));switch(this.options.view){case"year":this.options.position.start.setTime(new Date(e,0,1).getTime()),this.options.position.end.setTime(new Date(e+1,0,1).getTime());break;case"month":this.options.position.start.setTime(new Date(e,o,1).getTime()),this.options.position.end.setTime(new Date(e,o+1,1).getTime());break;case"day":this.options.position.start.setTime(new Date(e,o,i).getTime()),this.options.position.end.setTime(new Date(e,o,i+1).getTime());break;case"week":var r,l=new Date(e,o,i);r=1==a(this,"first_day")?l.getDate()-(l.getDay()+6)%7:l.getDate()-l.getDay(),this.options.position.start.setTime(new Date(e,o,r).getTime()),this.options.position.end.setTime(new Date(e,o,r+7).getTime());break;default:t.error(this.locale.error_noview.format(this.options.view))}return this},s.prototype.getTitle=function(){var t=this.options.position.start;switch(this.options.view){case"year":return this.locale.title_year.format(t.getFullYear());case"month":return this.locale.title_month.format(this.locale["m"+t.getMonth()],t.getFullYear());case"week":return this.locale.title_week.format(t.getWeek(),t.getFullYear());case"day":return this.locale.title_day.format(this.locale["d"+t.getDay()],t.getDate(),this.locale["m"+t.getMonth()],t.getFullYear())}},s.prototype.isToday=function(){var t=(new Date).getTime();return t>this.options.position.start&&this.options.position.end>t},s.prototype.getStartDate=function(){return this.options.position.start},s.prototype.getEndDate=function(){return this.options.position.end},s.prototype._loadEvents=function(){var a=this,o=null;"events_source"in this.options&&""!==this.options.events_source?o=this.options.events_source:"events_url"in this.options&&(o=this.options.events_url,i("The events_url option is DEPRECATED and it will be REMOVED in near future. Please use events_source instead."));var s;switch(t.type(o)){case"function":s=function(){return o(a.options.position.start,a.options.position.end,p)};break;case"array":s=function(){return[].concat(o)};break;case"string":o.length&&(s=function(){var i=[],s={from:a.options.position.start.getTime(),to:a.options.position.end.getTime()};return p.length&&(s.browser_timezone=p),t.ajax({url:e(o,s),dataType:"json",type:"GET",async:!1}).done(function(e){e.success||t.error(e.error),e.result&&(i=e.result)}),i})}s||t.error(this.locale.error_loadurl),this.options.onBeforeEventsLoad.call(this,function(){a.options.events=s(),a.options.events.sort(function(t,e){var a;return a=t.start-e.start,0==a&&(a=t.end-e.end),a}),a.options.onAfterEventsLoad.call(a,a.options.events)})},s.prototype._loadTemplate=function(e){if(!this.options.templates[e]){var a=this;t.ajax({url:this.options.tmpl_path+e+".html",dataType:"html",type:"GET",async:!1,cache:this.options.tmpl_cache}).done(function(t){a.options.templates[e]=_.template(t)})}},s.prototype._update=function(){var e=this;t('*[data-toggle="tooltip"]').tooltip({container:"body"}),t("*[data-cal-date]").click(function(){var a=t(this).data("cal-view");e.options.day=t(this).data("cal-date"),e.view(a)}),t(".cal-cell").dblclick(function(){var a=t("[data-cal-date]",this).data("cal-view");e.options.day=t("[data-cal-date]",this).data("cal-date"),e.view(a)}),this["_update_"+this.options.view](),this._update_modal()},s.prototype._update_modal=function(){var e=this;if(t("a[data-event-id]",this.context).unbind("click"),e.options.modal){var a=t(e.options.modal);if(a.length){var o=null;"iframe"==e.options.modal_type&&(o=t(document.createElement("iframe")).attr({width:"100%",frameborder:"0"})),t("a[data-event-id]",this.context).on("click",function(i){i.preventDefault(),i.stopPropagation();var s=t(this).attr("href"),n=t(this).data("event-id"),i=_.find(e.options.events,function(t){return t.id==n});"iframe"==e.options.modal_type&&(o.attr("src",s),t(".modal-body",a).html(o)),(!a.data("handled.bootstrap-calendar")||a.data("handled.bootstrap-calendar")&&a.data("handled.event-id")!=i.id)&&a.on("show.bs.modal",function(){var o=t(this).find(".modal-body");switch(e.options.modal_type){case"iframe":var n=o.height()-parseInt(o.css("padding-top"),10)-parseInt(o.css("padding-bottom"),10);t(this).find("iframe").height(Math.max(n,50));break;case"ajax":t.ajax({url:s,dataType:"html",async:!1,success:function(t){o.html(t)}});break;case"template":e._loadTemplate("modal"),o.html(e.options.templates.modal({event:i,calendar:e}))}_.isFunction(e.options.modal_title)&&a.find("h3").html(e.options.modal_title(i))}).data("handled.bootstrap-calendar",!0).data("handled.event-id",i.id),a.modal("show")})}}},s.prototype._update_day=function(){t("#cal-day-panel").height(t("#cal-day-panel-hour").height())},s.prototype._update_week=function(){},s.prototype._update_year=function(){this._update_month_year()},s.prototype._update_month=function(){this._update_month_year();var e=this,a=t(document.createElement("div")).attr("id","cal-week-box"),o=this.options.position.start.getFullYear()+"-"+this.options.position.start.getMonthFormatted()+"-";t(".cal-month-box .cal-row-fluid").on("mouseenter",function(){var i=new Date(e.options.position.start),s=t(".cal-cell1:first-child .cal-month-day",this),n=s.hasClass("cal-month-first-row")?1:t("[data-cal-date]",s).text();i.setDate(parseInt(n)),n=10>n?"0"+n:n,a.html(e.locale.week.format(i.getWeek())),a.attr("data-cal-week",o+n).show().appendTo(s)}).on("mouseleave",function(){a.hide()}),a.click(function(){e.options.day=t(this).data("cal-week"),e.view("week")}),t("a.event").mouseenter(function(){t('a[data-event-id="'+t(this).data("event-id")+'"]').closest(".cal-cell1").addClass("day-highlight dh-"+t(this).data("event-class"))}),t("a.event").mouseleave(function(){t("div.cal-cell1").removeClass("day-highlight dh-"+t(this).data("event-class"))})},s.prototype._update_month_year=function(){if(this.options.views[this.options.view].slide_events){var e=this,a=t(document.createElement("div")).attr("id","cal-day-tick").html('');t(".cal-month-day, .cal-year-box .span3").on("mouseenter",function(){0!=t(".events-list",this).length&&t(this).children("[data-cal-date]").text()!=e.activecell&&a.show().appendTo(this)}).on("mouseleave",function(){a.hide()}).on("click",function(i){0!=t(".events-list",this).length&&t(this).children("[data-cal-date]").text()!=e.activecell&&n(i,a,o,e)});var o=t(document.createElement("div")).attr("id","cal-slide-box");o.hide().click(function(t){t.stopPropagation()}),this._loadTemplate("events-list"),a.click(function(a){n(a,t(this),o,e)})}},s.prototype.getEventsBetween=function(e,a){var o=[];return t.each(this.options.events,function(){(a>parseInt(this.start)||null==this.start)&&(parseInt(this.end)>=e||null==this.end)&&o.push(this)}),o},t.fn.calendar=function(t){return new s(t,this)}}(jQuery); \ No newline at end of file +/*! bootstrap-calendar - v0.2.4 - 2014-07-01 - https://github.com/Serhioromano/bootstrap-calendar */ +"use strict";Date.prototype.getWeek=function(){var t=new Date(this.getFullYear(),0,1);return Math.ceil(((this.getTime()-t.getTime())/864e5+t.getDay()+1)/7)},Date.prototype.getMonthFormatted=function(){var t=this.getMonth()+1;return 10>t?"0"+t:t},Date.prototype.getDateFormatted=function(){var t=this.getDate();return 10>t?"0"+t:t},String.prototype.format||(String.prototype.format=function(){var t=arguments;return this.replace(/{(\d+)}/g,function(e,a){return t[a]!==void 0?t[a]:e})}),String.prototype.formatNum||(String.prototype.formatNum=function(t){for(var e=""+this;t>e.length;)e="0"+e;return e}),function(t){function e(t,e){var a,o,n;n=t,a=0>t.indexOf("?")?"?":"&";for(o in e)n+=a+o+"="+encodeURIComponent(e[o]),a="&";return n}function a(e,a){var o=null!=e.options[a]?e.options[a]:null,n=null!=e.locale[a]?e.locale[a]:null;if("holidays"==a&&e.options.merge_holidays){var i={};return t.extend(!0,i,n?n:d.holidays),o&&t.extend(!0,i,o),i}return null!=o?o:null!=n?n:d[a]}function o(e,i){var s=[],l=a(e,"holidays");for(var d in l)s.push(d+":"+l[d]);if(s.push(i),s=s.join("|"),s in o.cache)return o.cache[s];var h=[];return t.each(l,function(e,a){var o=null,s=null,l=!1;if(t.each(e.split(">"),function(t,a){var d,h=null;if(d=/^(\d\d)-(\d\d)$/.exec(a))h=new Date(i,parseInt(d[2],10)-1,parseInt(d[1],10));else if(d=/^(\d\d)-(\d\d)-(\d\d\d\d)$/.exec(a))parseInt(d[3],10)==i&&(h=new Date(i,parseInt(d[2],10)-1,parseInt(d[1],10)));else if(d=/^easter(([+\-])(\d+))?$/.exec(a))h=r(i,d[1]?parseInt(d[1],10):0);else if(d=/^(\d\d)([+\-])([1-5])\*([0-6])$/.exec(a)){var p=parseInt(d[1],10)-1,c=d[2],u=parseInt(d[3]),m=parseInt(d[4]);switch(c){case"+":for(var y=new Date(i,p,-6);y.getDay()!=m;)y=new Date(y.getFullYear(),y.getMonth(),y.getDate()+1);h=new Date(y.getFullYear(),y.getMonth(),y.getDate()+7*u);break;case"-":for(var y=new Date(i,p+1,7);y.getDay()!=m;)y=new Date(y.getFullYear(),y.getMonth(),y.getDate()-1);h=new Date(y.getFullYear(),y.getMonth(),y.getDate()-7*u)}}if(!h)return n("Unknown holiday: "+e),l=!0,!1;switch(t){case 0:o=h;break;case 1:if(h.getTime()<=o.getTime())return n("Unknown holiday: "+e),l=!0,!1;s=h;break;default:return n("Unknown holiday: "+e),l=!0,!1}}),!l){var d=[];if(s)for(var p=new Date(o.getTime());p.getTime()<=s.getTime();p.setDate(p.getDate()+1))d.push(new Date(p.getTime()));else d.push(o);h.push({name:a,days:d})}}),o.cache[s]=h,o.cache[s]}function n(e){"object"==t.type(window.console)&&"function"==t.type(window.console.warn)&&window.console.warn("[Bootstrap-Calendar] "+e)}function i(e,a){return this.options=t.extend(!0,{position:{start:new Date,end:new Date}},l,e),this.setLanguage(this.options.language),this.context=a,a.css("width",this.options.width).addClass("cal-context"),this.view(),this}function s(e,a,o,n){e.stopPropagation();var a=t(a),i=a.closest(".cal-cell"),s=i.closest(".cal-before-eventlist"),r=i.data("cal-row");a.fadeOut("fast"),o.slideUp("fast",function(){var e=t(".events-list",i);o.html(n.options.templates["events-list"]({cal:n,events:n.getEventsBetween(parseInt(e.data("cal-start")),parseInt(e.data("cal-end")))})),s.after(o),n.activecell=t("[data-cal-date]",i).text(),t("#cal-slide-tick").addClass("tick"+r).show(),o.slideDown("fast",function(){t("body").one("click",function(){o.slideUp("fast"),n.activecell=0})})}),t("a.event-item").mouseenter(function(){t('a[data-event-id="'+t(this).data("event-id")+'"]').closest(".cal-cell1").addClass("day-highlight dh-"+t(this).data("event-class"))}),t("a.event-item").mouseleave(function(){t("div.cal-cell1").removeClass("day-highlight dh-"+t(this).data("event-class"))}),setTimeout(function(){n._update_modal()},400)}function r(t,e){var a=t%19,o=Math.floor(t/100),n=t%100,i=Math.floor(o/4),s=o%4,r=Math.floor((o+8)/25),l=Math.floor((o-r+1)/3),d=(19*a+o-i-l+15)%30,h=Math.floor(n/4),p=n%4,c=(32+2*s+2*h-d-p)%7,u=Math.floor((a+11*d+22*c)/451),m=d+c+7*u+114,y=Math.floor(m/31)-1,g=m%31+1;return new Date(t,y,g+(e?e:0),0,0,0)}var l={width:"100%",view:"month",day:"now",time_start:"06:00",time_end:"22:00",time_split:"30",events_source:"",tmpl_path:"tmpls/",tmpl_cache:!0,classes:{months:{inmonth:"cal-day-inmonth",outmonth:"cal-day-outmonth",saturday:"cal-day-weekend",sunday:"cal-day-weekend",holidays:"cal-day-holiday",today:"cal-day-today"},week:{workday:"cal-day-workday",saturday:"cal-day-weekend",sunday:"cal-day-weekend",holidays:"cal-day-holiday",today:"cal-day-today"}},modal:null,modal_type:"iframe",modal_title:null,views:{year:{slide_events:1,enable:1},month:{slide_events:1,enable:1},week:{enable:1},day:{enable:1}},merge_holidays:!1,onAfterEventsLoad:function(){},onBeforeEventsLoad:function(t){t()},onAfterViewLoad:function(){},onAfterModalShown:function(){},onAfterModalHidden:function(){},events:[],templates:{year:"",month:"",week:"",day:""},stop_cycling:!1},d={first_day:2,holidays:{"01-01":"New Year's Day","01+3*1":"Birthday of Dr. Martin Luther King, Jr.","02+3*1":"Washington's Birthday","05-1*1":"Memorial Day","04-07":"Independence Day","09+1*1":"Labor Day","10+2*1":"Columbus Day","11-11":"Veterans Day","11+4*4":"Thanksgiving Day","25-12":"Christmas"}},h={error_noview:"Calendar: View {0} not found",error_dateformat:'Calendar: Wrong date format {0}. Should be either "now" or "yyyy-mm-dd"',error_loadurl:"Calendar: Event URL is not set",error_where:'Calendar: Wrong navigation direction {0}. Can be only "next" or "prev" or "today"',error_timedevide:"Calendar: Time split parameter should divide 60 without decimals. Something like 10, 15, 30",no_events_in_day:"No events in this day.",title_year:"{0}",title_month:"{0} {1}",title_week:"week {0} of {1}",title_day:"{0} {1} {2}, {3}",week:"Week {0}",all_day:"All day",time:"Time",events:"Events",before_time:"Ends before timeline",after_time:"Starts after timeline",m0:"January",m1:"February",m2:"March",m3:"April",m4:"May",m5:"June",m6:"July",m7:"August",m8:"September",m9:"October",m10:"November",m11:"December",ms0:"Jan",ms1:"Feb",ms2:"Mar",ms3:"Apr",ms4:"May",ms5:"Jun",ms6:"Jul",ms7:"Aug",ms8:"Sep",ms9:"Oct",ms10:"Nov",ms11:"Dec",d0:"Sunday",d1:"Monday",d2:"Tuesday",d3:"Wednesday",d4:"Thursday",d5:"Friday",d6:"Saturday"},p="";try{"object"==t.type(window.jstz)&&"function"==t.type(jstz.determine)&&(p=jstz.determine().name(),"string"!==t.type(p)&&(p=""))}catch(c){}o.cache={},i.prototype.setOptions=function(e){t.extend(this.options,e),"language"in e&&this.setLanguage(e.language),"modal"in e&&this._update_modal()},i.prototype.setLanguage=function(e){window.calendar_languages&&e in window.calendar_languages?(this.locale=t.extend(!0,{},h,calendar_languages[e]),this.options.language=e):(this.locale=h,delete this.options.language)},i.prototype._render=function(){this.context.html(""),this._loadTemplate(this.options.view),this.stop_cycling=!1;var t={};t.cal=this,t.day=1,t.months=1==a(this,"first_day")?[this.locale.d1,this.locale.d2,this.locale.d3,this.locale.d4,this.locale.d5,this.locale.d6,this.locale.d0]:[this.locale.d0,this.locale.d1,this.locale.d2,this.locale.d3,this.locale.d4,this.locale.d5,this.locale.d6];var e=parseInt(this.options.position.start.getTime()),o=parseInt(this.options.position.end.getTime());switch(t.events=this.getEventsBetween(e,o),this.options.view){case"month":break;case"week":this._calculate_hour_minutes(t);break;case"day":this._calculate_hour_minutes(t)}t.start=new Date(this.options.position.start.getTime()),t.lang=this.locale,this.context.append(this.options.templates[this.options.view](t)),this._update()},i.prototype._calculate_hour_minutes=function(e){var a=this,o=parseInt(this.options.time_split),i=60/o,s=Math.min(i,1);(i>=1&&0!=i%1||1>i&&0!=1440/o%1)&&t.error(this.locale.error_timedevide);var r=this.options.time_start.split(":"),l=this.options.time_end.split(":");e.hours=(parseInt(l[0])-parseInt(r[0]))*s;var d=e.hours*i-parseInt(r[1])/o,h=6e4*o,p=new Date(this.options.position.start.getTime());p.setHours(r[0]),p.setMinutes(r[1]);var c=new Date(this.options.position.start.getTime());c.setHours(l[0]),c.setMinutes(l[1]),e.all_day=[],e.by_hour=[],e.after_time=[],e.before_time=[],t.each(e.events,function(t,o){var i=new Date(parseInt(o.start)),s=new Date(parseInt(o.end));if(o.start_hour=(""+i.getHours()).formatNum(2)+":"+(""+i.getMinutes()).formatNum(2),o.end_hour=(""+s.getHours()).formatNum(2)+":"+(""+s.getMinutes()).formatNum(2),o.startc.getTime()&&(n(1),o.end_hour=s.getDate()+" "+a.locale["ms"+s.getMonth()]+" "+o.end_hour),o.startc.getTime())return e.all_day.push(o),void 0;if(o.endc.getTime())return e.after_time.push(o),void 0;var r=p.getTime()-o.start;o.top=r>=0?0:Math.abs(r)/h;var l=Math.abs(d-o.top),u=(o.end-o.start)/h;r>=0&&(u=(o.end-p.getTime())/h),o.lines=u,u>l&&(o.lines=l),e.by_hour.push(o)})},i.prototype._hour_min=function(t){var e=this.options.time_start.split(":"),a=parseInt(this.options.time_split),o=60/a;return 0==t?o-parseInt(e[1])/a:o},i.prototype._hour=function(t,e){var a=this.options.time_start.split(":"),o=parseInt(this.options.time_split),n=""+(parseInt(a[0])+t*Math.max(o/60,1)),i=""+(o*e+(0==t)?parseInt(a[1]):0);return n.formatNum(2)+":"+i.formatNum(2)},i.prototype._week=function(){this._loadTemplate("week-days");var e={},o=parseInt(this.options.position.start.getTime()),n=parseInt(this.options.position.end.getTime()),i=[],s=this,r=a(this,"first_day");return t.each(this.getEventsBetween(o,n),function(t,e){e.start_day=new Date(parseInt(e.start)).getDay(),1==r&&(e.start_day=(e.start_day+6)%7),e.days=864e5>=e.end-e.start?1:(e.end-e.start)/864e5,o>e.start&&(e.days=e.days-(o-e.start)/864e5,e.start_day=0),e.days=Math.ceil(e.days),e.start_day+e.days>7&&(e.days=7-e.start_day),i.push(e)}),e.events=i,e.cal=this,s.options.templates["week-days"](e)},i.prototype._month=function(t){this._loadTemplate("year-month");var e={cal:this},a=t+1;e.data_day=this.options.position.start.getFullYear()+"-"+(10>a?"0"+a:a)+"-"+"01",e.month_name=this.locale["m"+t];var o=new Date(this.options.position.start.getFullYear(),t,1,0,0,0);return e.start=parseInt(o.getTime()),e.end=parseInt(new Date(this.options.position.start.getFullYear(),t+1,1,0,0,0).getTime()),e.events=this.getEventsBetween(e.start,e.end),this.options.templates["year-month"](e)},i.prototype._day=function(e,o){this._loadTemplate("month-day");var n={tooltip:"",cal:this},i=this.options.classes.months.outmonth,s=this.options.position.start.getDay();2==a(this,"first_day")?s++:s=0==s?7:s,o=o-s+1;var r=new Date(this.options.position.start.getFullYear(),this.options.position.start.getMonth(),o,0,0,0);o>0&&(i=this.options.classes.months.inmonth);var l=new Date(this.options.position.end.getTime()-1).getDate();if(o+1>l&&(this.stop_cycling=!0),o>l&&(o-=l,i=this.options.classes.months.outmonth),i=t.trim(i+" "+this._getDayClass("months",r)),0>=o){var d=new Date(this.options.position.start.getFullYear(),this.options.position.start.getMonth(),0).getDate();o=d-Math.abs(o),i+=" cal-month-first-row"}var h=this._getHoliday(r);return h!==!1&&(n.tooltip=h),n.data_day=r.getFullYear()+"-"+r.getMonthFormatted()+"-"+(10>o?"0"+o:o),n.cls=i,n.day=o,n.start=parseInt(r.getTime()),n.end=parseInt(n.start+864e5),n.events=this.getEventsBetween(n.start,n.end),this.options.templates["month-day"](n)},i.prototype._getHoliday=function(e){var a=!1;return t.each(o(this,e.getFullYear()),function(){var o=!1;return t.each(this.days,function(){return this.toDateString()==e.toDateString()?(o=!0,!1):void 0}),o?(a=this.name,!1):void 0}),a},i.prototype._getHolidayName=function(t){var e=this._getHoliday(t);return e===!1?"":e},i.prototype._getDayClass=function(t,e){var a=this,o=function(e,o){var n;n=a.options.classes&&t in a.options.classes&&e in a.options.classes[t]?a.options.classes[t][e]:"","string"==typeof n&&n.length&&o.push(n)},n=[];e.toDateString()==(new Date).toDateString()&&o("today",n);var i=this._getHoliday(e);switch(i!==!1&&o("holidays",n),e.getDay()){case 0:o("sunday",n);break;case 6:o("saturday",n)}return o(e.toDateString(),n),n.join(" ")},i.prototype.view=function(t){if(t){if(!this.options.views[t].enable)return;this.options.view=t}this._init_position(),this._loadEvents(),this._render(),this.options.onAfterViewLoad.call(this,this.options.view)},i.prototype.navigate=function(e,a){var o=t.extend({},this.options.position);if("next"==e)switch(this.options.view){case"year":o.start.setFullYear(this.options.position.start.getFullYear()+1);break;case"month":o.start.setMonth(this.options.position.start.getMonth()+1);break;case"week":o.start.setDate(this.options.position.start.getDate()+7);break;case"day":o.start.setDate(this.options.position.start.getDate()+1)}else if("prev"==e)switch(this.options.view){case"year":o.start.setFullYear(this.options.position.start.getFullYear()-1);break;case"month":o.start.setMonth(this.options.position.start.getMonth()-1);break;case"week":o.start.setDate(this.options.position.start.getDate()-7);break;case"day":o.start.setDate(this.options.position.start.getDate()-1)}else"today"==e?o.start.setTime((new Date).getTime()):t.error(this.locale.error_where.format(e));this.options.day=o.start.getFullYear()+"-"+o.start.getMonthFormatted()+"-"+o.start.getDateFormatted(),this.view(),_.isFunction(a)&&a()},i.prototype._init_position=function(){var e,o,n;if("now"==this.options.day){var i=new Date;e=i.getFullYear(),o=i.getMonth(),n=i.getDate()}else if(this.options.day.match(/^\d{4}-\d{2}-\d{2}$/g)){var s=this.options.day.split("-");e=parseInt(s[0],10),o=parseInt(s[1],10)-1,n=parseInt(s[2],10)}else t.error(this.locale.error_dateformat.format(this.options.day));switch(this.options.view){case"year":this.options.position.start.setTime(new Date(e,0,1).getTime()),this.options.position.end.setTime(new Date(e+1,0,1).getTime());break;case"month":this.options.position.start.setTime(new Date(e,o,1).getTime()),this.options.position.end.setTime(new Date(e,o+1,1).getTime());break;case"day":this.options.position.start.setTime(new Date(e,o,n).getTime()),this.options.position.end.setTime(new Date(e,o,n+1).getTime());break;case"week":var r,l=new Date(e,o,n);r=1==a(this,"first_day")?l.getDate()-(l.getDay()+6)%7:l.getDate()-l.getDay(),this.options.position.start.setTime(new Date(e,o,r).getTime()),this.options.position.end.setTime(new Date(e,o,r+7).getTime());break;default:t.error(this.locale.error_noview.format(this.options.view))}return this},i.prototype.getTitle=function(){var t=this.options.position.start;switch(this.options.view){case"year":return this.locale.title_year.format(t.getFullYear());case"month":return this.locale.title_month.format(this.locale["m"+t.getMonth()],t.getFullYear());case"week":return this.locale.title_week.format(t.getWeek(),t.getFullYear());case"day":return this.locale.title_day.format(this.locale["d"+t.getDay()],t.getDate(),this.locale["m"+t.getMonth()],t.getFullYear())}},i.prototype.isToday=function(){var t=(new Date).getTime();return t>this.options.position.start&&this.options.position.end>t},i.prototype.getStartDate=function(){return this.options.position.start},i.prototype.getEndDate=function(){return this.options.position.end},i.prototype._loadEvents=function(){var a=this,o=null;"events_source"in this.options&&""!==this.options.events_source?o=this.options.events_source:"events_url"in this.options&&(o=this.options.events_url,n("The events_url option is DEPRECATED and it will be REMOVED in near future. Please use events_source instead."));var i;switch(t.type(o)){case"function":i=function(){return o(a.options.position.start,a.options.position.end,p)};break;case"array":i=function(){return[].concat(o)};break;case"string":o.length&&(i=function(){var n=[],i={from:a.options.position.start.getTime(),to:a.options.position.end.getTime()};return p.length&&(i.browser_timezone=p),t.ajax({url:e(o,i),dataType:"json",type:"GET",async:!1}).done(function(e){e.success||t.error(e.error),e.result&&(n=e.result)}),n})}i||t.error(this.locale.error_loadurl),this.options.onBeforeEventsLoad.call(this,function(){a.options.events=i(),a.options.events.sort(function(t,e){var a;return a=t.start-e.start,0==a&&(a=t.end-e.end),a}),a.options.onAfterEventsLoad.call(a,a.options.events)})},i.prototype._templatePath=function(t){return"function"==typeof this.options.tmpl_path?this.options.tmpl_path(t):this.options.tmpl_path+t+".html"},i.prototype._loadTemplate=function(e){if(!this.options.templates[e]){var a=this;t.ajax({url:a._templatePath(e),dataType:"html",type:"GET",async:!1,cache:this.options.tmpl_cache}).done(function(t){a.options.templates[e]=_.template(t)})}},i.prototype._update=function(){var e=this;t('*[data-toggle="tooltip"]').tooltip({container:"body"}),t("*[data-cal-date]").click(function(){var a=t(this).data("cal-view");e.options.day=t(this).data("cal-date"),e.view(a)}),t(".cal-cell").dblclick(function(){var a=t("[data-cal-date]",this).data("cal-view");e.options.day=t("[data-cal-date]",this).data("cal-date"),e.view(a)}),this["_update_"+this.options.view](),this._update_modal()},i.prototype._update_modal=function(){var e=this;if(t("a[data-event-id]",this.context).unbind("click"),e.options.modal){var a=t(e.options.modal);if(a.length){var o=null;"iframe"==e.options.modal_type&&(o=t(document.createElement("iframe")).attr({width:"100%",frameborder:"0"})),t("a[data-event-id]",this.context).on("click",function(n){n.preventDefault(),n.stopPropagation();var i=t(this).attr("href"),s=t(this).data("event-id"),n=_.find(e.options.events,function(t){return t.id==s});"iframe"==e.options.modal_type&&(o.attr("src",i),t(".modal-body",a).html(o)),(!a.data("handled.bootstrap-calendar")||a.data("handled.bootstrap-calendar")&&a.data("handled.event-id")!=n.id)&&a.on("show.bs.modal",function(){var o=t(this).find(".modal-body");switch(e.options.modal_type){case"iframe":var s=o.height()-parseInt(o.css("padding-top"),10)-parseInt(o.css("padding-bottom"),10);t(this).find("iframe").height(Math.max(s,50));break;case"ajax":t.ajax({url:i,dataType:"html",async:!1,success:function(t){o.html(t)}});break;case"template":e._loadTemplate("modal"),o.html(e.options.templates.modal({event:n,calendar:e}))}_.isFunction(e.options.modal_title)&&a.find("h3").html(e.options.modal_title(n))}).on("shown.bs.modal",function(){e.options.onAfterModalShown.call(e,e.options.events)}).on("hidden.bs.modal",function(){e.options.onAfterModalHidden.call(e,e.options.events)}).data("handled.bootstrap-calendar",!0).data("handled.event-id",n.id),a.modal("show")})}}},i.prototype._update_day=function(){t("#cal-day-panel").height(t("#cal-day-panel-hour").height())},i.prototype._update_week=function(){},i.prototype._update_year=function(){this._update_month_year()},i.prototype._update_month=function(){this._update_month_year();var e=this,a=t(document.createElement("div")).attr("id","cal-week-box"),o=this.options.position.start.getFullYear()+"-"+this.options.position.start.getMonthFormatted()+"-";t(".cal-month-box .cal-row-fluid").on("mouseenter",function(){var n=new Date(e.options.position.start),i=t(".cal-cell1:first-child .cal-month-day",this),s=i.hasClass("cal-month-first-row")?1:t("[data-cal-date]",i).text();n.setDate(parseInt(s)),s=10>s?"0"+s:s,a.html(e.locale.week.format(n.getWeek())),a.attr("data-cal-week",o+s).show().appendTo(i)}).on("mouseleave",function(){a.hide()}),a.click(function(){e.options.day=t(this).data("cal-week"),e.view("week")}),t("a.event").mouseenter(function(){t('a[data-event-id="'+t(this).data("event-id")+'"]').closest(".cal-cell1").addClass("day-highlight dh-"+t(this).data("event-class"))}),t("a.event").mouseleave(function(){t("div.cal-cell1").removeClass("day-highlight dh-"+t(this).data("event-class"))})},i.prototype._update_month_year=function(){if(this.options.views[this.options.view].slide_events){var e=this,a=t(document.createElement("div")).attr("id","cal-day-tick").html('');t(".cal-month-day, .cal-year-box .span3").on("mouseenter",function(){0!=t(".events-list",this).length&&t(this).children("[data-cal-date]").text()!=e.activecell&&a.show().appendTo(this)}).on("mouseleave",function(){a.hide()}).on("click",function(n){0!=t(".events-list",this).length&&t(this).children("[data-cal-date]").text()!=e.activecell&&s(n,a,o,e)});var o=t(document.createElement("div")).attr("id","cal-slide-box");o.hide().click(function(t){t.stopPropagation()}),this._loadTemplate("events-list"),a.click(function(a){s(a,t(this),o,e)})}},i.prototype.getEventsBetween=function(e,a){var o=[];return t.each(this.options.events,function(){if(null==this.start)return!0;var t=this.end||this.start;a>parseInt(this.start)&&parseInt(t)>=e&&o.push(this)}),o},t.fn.calendar=function(t){return new i(t,this)}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 4076123e..453d0bdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-calendar", - "version": "0.2.3", + "version": "0.2.4", "description": "Bootstrap full view calendar", "main": [ "./js/calendar.js"