diff --git a/app/assets/javascripts/calendar.js b/app/assets/javascripts/calendar.js index abb4b36..87be147 100644 --- a/app/assets/javascripts/calendar.js +++ b/app/assets/javascripts/calendar.js @@ -45,7 +45,7 @@ if(window.calendar_variable.date_type == 2){ window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); } window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); -window.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); +window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); window.calendar_variable.std_date_format = 'y-MM-d'; window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d"); $.fn.fullCalendar = function(args){ @@ -111,46 +111,45 @@ FullCalendar.Calendar.prototype.isAnOverlapEvent = function(eventStartDay, event } window.getDateString = function(date, format, is_chinese) { - var months = calendar_variable.months; - var week_days = calendar_variable.dayNames; - var getPaddedComp = function(comp) { - return ((parseInt(comp) < 10) ? ('0' + comp) : comp) - }, - formattedDate = format, - y = date.getFullYear(), - m = date.getMonth(), - d = date.getDate(), - H = date.getHours(), - M = date.getMinutes(), - s = date.getSeconds(), - S = date.getMilliseconds(), - month_name = months[m], - am_trans = (calendar_variable.is_chinese ? '上午' : 'AM'), - pm_trans = (calendar_variable.is_chinese ? '下午' : 'PM'), - o = { - "yy+": y, //raw year - "y+": y + (calendar_variable.is_chinese ? "年" : ""), // year - "MMM+": month_name, //month - "MM+": getPaddedComp(m + 1), //raw month - "M+": month_name.substring(0,3), //month - "dd+": getPaddedComp(d), //raw day - "d+": (calendar_variable.is_chinese ? (d + "日") : getPaddedComp(d)), //day - "W+": week_days[date.getDay()], //weekday - "w+": (calendar_variable.is_chinese ? week_days[date.getDay()].substr(-1, 1) : week_days[date.getDay()].substr(0, 3)), //weekday - "h+": getPaddedComp((H > 12) ? H % 12 : H), //hour - "H+": getPaddedComp(H), //hour - "m+": getPaddedComp(M), //minute - "s+": getPaddedComp(s), //second - "S+": getPaddedComp(S), //millisecond, - "b+": (H >= 12) ? pm_trans : am_trans - }; - - for (var k in o) { - if (new RegExp("(" + k + ")").test(format)) { - formattedDate = formattedDate.replace(RegExp.$1, o[k]); - } - } - return formattedDate; + var months = calendar_variable.months; + var week_days = calendar_variable.dayNames; + var getPaddedComp = function(comp) { + return ((parseInt(comp) < 10) ? ('0' + comp) : comp) + }, + formattedDate = format, + y = date.getFullYear(), + m = date.getMonth(), + d = date.getDate(), + H = date.getHours(), + M = date.getMinutes(), + s = date.getSeconds(), + S = date.getMilliseconds(), + month_name = months[m], + am_trans = (calendar_variable.is_chinese ? '上午' : 'AM'), + pm_trans = (calendar_variable.is_chinese ? '下午' : 'PM'), + o = { + "yy+": y, //raw year + "y+": y + (calendar_variable.is_chinese ? "年" : ""), // year + "MMM+": month_name, //month + "MM+": getPaddedComp(m + 1), //raw month + "M+": month_name.substring(0,3), //month + "dd+": getPaddedComp(d), //raw day + "d+": (calendar_variable.is_chinese ? (d + "日") : getPaddedComp(d)), //day + "W+": week_days[date.getDay()], //weekday + "w+": (calendar_variable.is_chinese ? week_days[date.getDay()].substr(-1, 1) : week_days[date.getDay()].substr(0, 3)), //weekday + "h+": getPaddedComp((H > 12) ? H % 12 : H), //hour + "H+": getPaddedComp(H), //hour + "m+": getPaddedComp(M), //minute + "s+": getPaddedComp(s), //second + "S+": getPaddedComp(S), //millisecond, + "b+": (H >= 12) ? pm_trans : am_trans + }; + for (var k in o) { + if (new RegExp("(" + k + ")").test(format)) { + formattedDate = formattedDate.replace(RegExp.$1, o[k]); + } + } + return formattedDate; }; var Calendar = function(dom){ @@ -581,8 +580,8 @@ var EventDialog = function(calendar,event){ } else { start_time = getDateString(_event._start,calendar_variable.date_format_with_short_month); end_time = getDateString(_event._end,calendar_variable.date_format_with_short_month); - var stime = getDateString(_event._start,time_format), - etime = getDateString(_event._end,time_format), + var stime = getDateString(_event._start,calendar_variable.time_format), + etime = getDateString(_event._end,calendar_variable.time_format), same = (start_time == end_time); if( same ){ time_string = "

" + @@ -940,7 +939,7 @@ var AgendaView = function(calendar){ if(s.getDate() == e.getDate() && s.getMonth() == s.getMonth() && e.getFullYear() == e.getFullYear()){ datetimeFormat = getDateString(s, calendar_variable.short_day); if(!event.allDay){ - datetimeFormat += (' ' + getDateString(s,time_format) + ' - ' + getDateString(e,time_format)); + datetimeFormat += (' ' + getDateString(s,calendar_variable.time_format) + ' - ' + getDateString(e,calendar_variable.time_format)); } }else{ if(event.allDay){ diff --git a/app/assets/javascripts/calendar_frontend.js b/app/assets/javascripts/calendar_frontend.js index dda077c..088f9be 100644 --- a/app/assets/javascripts/calendar_frontend.js +++ b/app/assets/javascripts/calendar_frontend.js @@ -45,7 +45,7 @@ if(window.calendar_variable.date_type == 2){ window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); } window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); -window.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); +window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); window.calendar_variable.std_date_format = 'y-MM-d'; window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d"); $.fn.fullCalendar = function(args){ @@ -111,46 +111,45 @@ FullCalendar.Calendar.prototype.isAnOverlapEvent = function(eventStartDay, event } window.getDateString = function(date, format, is_chinese) { - var months = calendar_variable.months; - var week_days = calendar_variable.dayNames; - var getPaddedComp = function(comp) { - return ((parseInt(comp) < 10) ? ('0' + comp) : comp) - }, - formattedDate = format, - y = date.getFullYear(), - m = date.getMonth(), - d = date.getDate(), - H = date.getHours(), - M = date.getMinutes(), - s = date.getSeconds(), - S = date.getMilliseconds(), - month_name = months[m], - am_trans = (calendar_variable.is_chinese ? '上午' : 'AM'), - pm_trans = (calendar_variable.is_chinese ? '下午' : 'PM'), - o = { - "yy+": y, //raw year - "y+": y + (calendar_variable.is_chinese ? "年" : ""), // year - "MMM+": month_name, //month - "MM+": getPaddedComp(m + 1), //raw month - "M+": month_name.substring(0,3), //month - "dd+": getPaddedComp(d), //raw day - "d+": (calendar_variable.is_chinese ? (d + "日") : getPaddedComp(d)), //day - "W+": week_days[date.getDay()], //weekday - "w+": (calendar_variable.is_chinese ? week_days[date.getDay()].substr(-1, 1) : week_days[date.getDay()].substr(0, 3)), //weekday - "h+": getPaddedComp((H > 12) ? H % 12 : H), //hour - "H+": getPaddedComp(H), //hour - "m+": getPaddedComp(M), //minute - "s+": getPaddedComp(s), //second - "S+": getPaddedComp(S), //millisecond, - "b+": (H >= 12) ? pm_trans : am_trans - }; - - for (var k in o) { - if (new RegExp("(" + k + ")").test(format)) { - formattedDate = formattedDate.replace(RegExp.$1, o[k]); - } - } - return formattedDate; + var months = calendar_variable.months; + var week_days = calendar_variable.dayNames; + var getPaddedComp = function(comp) { + return ((parseInt(comp) < 10) ? ('0' + comp) : comp) + }, + formattedDate = format, + y = date.getFullYear(), + m = date.getMonth(), + d = date.getDate(), + H = date.getHours(), + M = date.getMinutes(), + s = date.getSeconds(), + S = date.getMilliseconds(), + month_name = months[m], + am_trans = (calendar_variable.is_chinese ? '上午' : 'AM'), + pm_trans = (calendar_variable.is_chinese ? '下午' : 'PM'), + o = { + "yy+": y, //raw year + "y+": y + (calendar_variable.is_chinese ? "年" : ""), // year + "MMM+": month_name, //month + "MM+": getPaddedComp(m + 1), //raw month + "M+": month_name.substring(0,3), //month + "dd+": getPaddedComp(d), //raw day + "d+": (calendar_variable.is_chinese ? (d + "日") : getPaddedComp(d)), //day + "W+": week_days[date.getDay()], //weekday + "w+": (calendar_variable.is_chinese ? week_days[date.getDay()].substr(-1, 1) : week_days[date.getDay()].substr(0, 3)), //weekday + "h+": getPaddedComp((H > 12) ? H % 12 : H), //hour + "H+": getPaddedComp(H), //hour + "m+": getPaddedComp(M), //minute + "s+": getPaddedComp(s), //second + "S+": getPaddedComp(S), //millisecond, + "b+": (H >= 12) ? pm_trans : am_trans + }; + for (var k in o) { + if (new RegExp("(" + k + ")").test(format)) { + formattedDate = formattedDate.replace(RegExp.$1, o[k]); + } + } + return formattedDate; }; var Calendar = function(dom,page_id,event_date=''){ @@ -418,8 +417,8 @@ var EventDialog = function(calendar,event){ } else { start_time = getDateString(_event._start,calendar_variable.date_format_with_short_month); end_time = getDateString(_event._end,calendar_variable.date_format_with_short_month); - var stime = getDateString(_event._start,time_format), - etime = getDateString(_event._end,time_format), + var stime = getDateString(_event._start,calendar_variable.time_format), + etime = getDateString(_event._end,calendar_variable.time_format), same = (start_time == end_time); if( same ){ time_string = "

" + @@ -771,7 +770,7 @@ var AgendaView = function(calendar){ if(s.getDate() == e.getDate() && s.getMonth() == s.getMonth() && e.getFullYear() == e.getFullYear()){ datetimeFormat = getDateString(s, calendar_variable.short_day); if(!event.allDay){ - datetimeFormat += (' ' + getDateString(s,time_format) + ' - ' + getDateString(e,time_format)); + datetimeFormat += (' ' + getDateString(s,calendar_variable.time_format) + ' - ' + getDateString(e,calendar_variable.time_format)); } }else{ console.log(event); diff --git a/app/assets/javascripts/calendar_widget.js b/app/assets/javascripts/calendar_widget.js index 8e36a0a..d562db3 100644 --- a/app/assets/javascripts/calendar_widget.js +++ b/app/assets/javascripts/calendar_widget.js @@ -1,9 +1,98 @@ - var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){ +if(window.calendar_variable == undefined){ + window.calendar_variable = {}; + window.calendar_variable.is_chinese = ( I18n && I18n.locale.indexOf('zh') != -1 ); + window.calendar_variable.date_type = 0; +}else{ + if(window.calendar_variable.date_type == 1){ + window.calendar_variable.is_chinese = false; + }else{ + window.calendar_variable.is_chinese = ( I18n && I18n.locale.indexOf('zh') != -1 ); + } +} +if(!(window.calendar_variable.dayNames)){ + if(window.calendar_variable.is_chinese){ + window.calendar_variable.dayNames = ['週日', '週一', '週二', '週三','週四', '週五', '週六']; + window.calendar_variable.dayNamesShort = ['日', '一', '二', '三','四', '五', '六']; + }else{ + window.calendar_variable.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday', 'Friday', 'Saturday']; + window.calendar_variable.dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed','Thu', 'Fri', 'Sat']; + } +} +if(window.calendar_variable.is_chinese){ + window.calendar_variable.months = []; + for(var i=0;i<12;i++){ + window.calendar_variable.months.push((i+1)+"月"); + } +}else{ + window.calendar_variable.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; +} +if(window.calendar_variable.date_type == 2){ + window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b'; + window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'yy/MM' : 'MM/yy'; + window.calendar_variable.date_format = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy'; + window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy'; + window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'yy/MM/dd (W)' : 'W, MM/dd/yy'; + window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MM/dd (W)" : "W, dd/MM"); + window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) b h:m" : "W, dd/MM h:m b"); +}else{ + window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b'; + window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'y MMM' : 'MMM y'; + window.calendar_variable.date_format = calendar_variable.is_chinese ? 'y MMM d' : 'd MMM, y'; + window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'y M d' : 'd M, y'; + window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'y MMM d (W)' : 'W, MMM d, y'; + window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM"); + window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); +} +window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); +window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); +window.calendar_variable.std_date_format = 'y-MM-d'; +window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d"); +var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){ + var getDateString = function(date, format, is_chinese) { + var months = calendar_variable.months; + var week_days = calendar_variable.dayNames; + var getPaddedComp = function(comp) { + return ((parseInt(comp) < 10) ? ('0' + comp) : comp) + }, + formattedDate = format, + y = date.getFullYear(), + m = date.getMonth(), + d = date.getDate(), + H = date.getHours(), + M = date.getMinutes(), + s = date.getSeconds(), + S = date.getMilliseconds(), + month_name = months[m], + am_trans = (calendar_variable.is_chinese ? '上午' : 'AM'), + pm_trans = (calendar_variable.is_chinese ? '下午' : 'PM'), + o = { + "yy+": y, //raw year + "y+": y + (calendar_variable.is_chinese ? "年" : ""), // year + "MMM+": month_name, //month + "MM+": getPaddedComp(m + 1), //raw month + "M+": month_name.substring(0,3), //month + "dd+": getPaddedComp(d), //raw day + "d+": (calendar_variable.is_chinese ? (d + "日") : getPaddedComp(d)), //day + "W+": week_days[date.getDay()], //weekday + "w+": (calendar_variable.is_chinese ? week_days[date.getDay()].substr(-1, 1) : week_days[date.getDay()].substr(0, 3)), //weekday + "h+": getPaddedComp((H > 12) ? H % 12 : H), //hour + "H+": getPaddedComp(H), //hour + "m+": getPaddedComp(M), //minute + "s+": getPaddedComp(s), //second + "S+": getPaddedComp(S), //millisecond, + "b+": (H >= 12) ? pm_trans : am_trans + }; + for (var k in o) { + if (new RegExp("(" + k + ")").test(format)) { + formattedDate = formattedDate.replace(RegExp.$1, o[k]); + } + } + return formattedDate; + }; _this = this; var events = {} var template = dom.find(".month_template"), - month_names = ["Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"], - monthNames = ['January','February','March','April','May','June','July','August','September','October','November','December'], + month_names = calendar_variable.months.map(function(m){ return m.substr(0,3);}), initialDate = date, subpartid = subpart, index_url = url, @@ -23,11 +112,8 @@ toggle_data; monthDom.html(template); var format_time = function(date){ - var hours = date.getHours(), - minutes = date.getMinutes(); - if (hours < 10) {hours = "0"+hours} - if (minutes < 10) {minutes = "0"+minutes} - return hours+':'+minutes; + date = new Date(date); + return getDateString(date, window.calendar_variable.time_format); } function rgb2hex(rgb) { rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); @@ -65,15 +151,11 @@ return '#'+comp } var format_date = function(date){ - var y = date.getFullYear(), - m = date.getMonth() + 1, - d = date.getDate(); - if (m < 10) {m = "0"+m} - if (d < 10) {d = "0"+d} - return y+'/'+m+'/'+d; + date = new Date(date); + return getDateString(date, window.calendar_variable.date_format); } var formate_datetime = function(date){ - date = new Date(date) + date = new Date(date); return [format_date(date),format_time(date)] } $(window).resize(function(){ @@ -182,7 +264,7 @@ } var renderMonth = function(){ var num_of_rows = getNumberOfRows(), - head_title = monthDom.find("h4 span.text"), + head_title = monthDom.find(".widget-title span.text"), table_body = monthDom.find("table.table tbody"); table_body.html(""); @@ -199,8 +281,8 @@ break; } table_body.append(tr); - head_title.text(monthNames[firstDay.getMonth()] + " " + firstDay.getFullYear()); - } + } + head_title.text(getDateString(firstDay, calendar_variable.month_year_format)); } var getNumberOfRows = function() { diff --git a/app/assets/javascripts/calendar_widget2.js b/app/assets/javascripts/calendar_widget2.js index 244a644..9fb40f1 100644 --- a/app/assets/javascripts/calendar_widget2.js +++ b/app/assets/javascripts/calendar_widget2.js @@ -1,9 +1,98 @@ - var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){ +if(window.calendar_variable == undefined){ + window.calendar_variable = {}; + window.calendar_variable.is_chinese = ( I18n && I18n.locale.indexOf('zh') != -1 ); + window.calendar_variable.date_type = 0; +}else{ + if(window.calendar_variable.date_type == 1){ + window.calendar_variable.is_chinese = false; + }else{ + window.calendar_variable.is_chinese = ( I18n && I18n.locale.indexOf('zh') != -1 ); + } +} +if(!(window.calendar_variable.dayNames)){ + if(window.calendar_variable.is_chinese){ + window.calendar_variable.dayNames = ['週日', '週一', '週二', '週三','週四', '週五', '週六']; + window.calendar_variable.dayNamesShort = ['日', '一', '二', '三','四', '五', '六']; + }else{ + window.calendar_variable.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday', 'Friday', 'Saturday']; + window.calendar_variable.dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed','Thu', 'Fri', 'Sat']; + } +} +if(window.calendar_variable.is_chinese){ + window.calendar_variable.months = []; + for(var i=0;i<12;i++){ + window.calendar_variable.months.push((i+1)+"月"); + } +}else{ + window.calendar_variable.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; +} +if(window.calendar_variable.date_type == 2){ + window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b'; + window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'yy/MM' : 'MM/yy'; + window.calendar_variable.date_format = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy'; + window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy'; + window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'yy/MM/dd (W)' : 'W, MM/dd/yy'; + window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MM/dd (W)" : "W, dd/MM"); + window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) b h:m" : "W, dd/MM h:m b"); +}else{ + window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b'; + window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'y MMM' : 'MMM y'; + window.calendar_variable.date_format = calendar_variable.is_chinese ? 'y MMM d' : 'd MMM, y'; + window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'y M d' : 'd M, y'; + window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'y MMM d (W)' : 'W, MMM d, y'; + window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM"); + window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b"); +} +window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd"); +window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b"); +window.calendar_variable.std_date_format = 'y-MM-d'; +window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d"); +var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){ + var getDateString = function(date, format, is_chinese) { + var months = calendar_variable.months; + var week_days = calendar_variable.dayNames; + var getPaddedComp = function(comp) { + return ((parseInt(comp) < 10) ? ('0' + comp) : comp) + }, + formattedDate = format, + y = date.getFullYear(), + m = date.getMonth(), + d = date.getDate(), + H = date.getHours(), + M = date.getMinutes(), + s = date.getSeconds(), + S = date.getMilliseconds(), + month_name = months[m], + am_trans = (calendar_variable.is_chinese ? '上午' : 'AM'), + pm_trans = (calendar_variable.is_chinese ? '下午' : 'PM'), + o = { + "yy+": y, //raw year + "y+": y + (calendar_variable.is_chinese ? "年" : ""), // year + "MMM+": month_name, //month + "MM+": getPaddedComp(m + 1), //raw month + "M+": month_name.substring(0,3), //month + "dd+": getPaddedComp(d), //raw day + "d+": (calendar_variable.is_chinese ? (d + "日") : getPaddedComp(d)), //day + "W+": week_days[date.getDay()], //weekday + "w+": (calendar_variable.is_chinese ? week_days[date.getDay()].substr(-1, 1) : week_days[date.getDay()].substr(0, 3)), //weekday + "h+": getPaddedComp((H > 12) ? H % 12 : H), //hour + "H+": getPaddedComp(H), //hour + "m+": getPaddedComp(M), //minute + "s+": getPaddedComp(s), //second + "S+": getPaddedComp(S), //millisecond, + "b+": (H >= 12) ? pm_trans : am_trans + }; + for (var k in o) { + if (new RegExp("(" + k + ")").test(format)) { + formattedDate = formattedDate.replace(RegExp.$1, o[k]); + } + } + return formattedDate; + }; _this = this; var events = {} var template = dom.find(".month_template"), - month_names = ["Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"], - monthNames = ['January','February','March','April','May','June','July','August','September','October','November','December'], + month_names = calendar_variable.months.map(function(m){ return m.substr(0,3);}), initialDate = date, subpartid = subpart, index_url = url, @@ -31,11 +120,8 @@ tp2; monthDom.html(template); var format_time = function(date){ - var hours = date.getHours(), - minutes = date.getMinutes(); - if (hours < 10) {hours = "0"+hours} - if (minutes < 10) {minutes = "0"+minutes} - return hours+':'+minutes; + date = new Date(date); + return getDateString(date, window.calendar_variable.time_format); } function rgb2hex(rgb) { rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); @@ -88,16 +174,12 @@ return '#'+comp } var format_date = function(date){ - var y = date.getFullYear(), - m = date.getMonth() + 1, - d = date.getDate(); - if (m < 10) {m = "0"+m} - if (d < 10) {d = "0"+d} - return y+'/'+m+'/'+d; + date = new Date(date); + return getDateString(date, window.calendar_variable.date_format); } - var formate_datetime = function(date){ + var format_datetime = function(date){ date = new Date(date) - return [format_date(date),format_time(date)] + return getDateString(date, window.calendar_variable.datetime_format); } $(window).resize(function(){ var window_w = $(window).width() @@ -138,20 +220,20 @@ var time_string = '' if(v.allDay) { var end_time - var start_time = formate_datetime(v.start)[0] + var start_time = format_date(v.start); if(v.end) - end_time = formate_datetime(v.end)[0] + end_time = format_date(v.end); else - end_time = start_time + end_time = start_time; time_string = (start_time==end_time ? "

" + start_time + "

" : " " + start_time + " " + end_time + "") }else{ - var st = formate_datetime(v.start), - et = formate_datetime(v.end), - start_time = st[0], - end_time = et[0], + var st = format_datetime(v.start), + et = format_datetime(v.end), + start_time = format_date(v.start), + end_time = format_date(v.end), same = (start_time==end_time), - etime = et[1], - stime = st[1] + etime = format_time(v.end), + stime = format_time(v.start) time_string = (same ? "

" + start_time + "

" + stime + " " + etime : "

" + start_time + "" + stime + "

" + end_time + "" + etime + "

"); } var modal_tp = (' - - - - - - - - + + @@ -47,7 +41,7 @@ tag.setAttribute("id", "calendar-widget_module"); tag.src = "<%= asset_path('calendar_widget.js') %>"; tag.onload = function(){ - $("div.widget-calendar-1[data-module=calendar]").each(function(index){ + $('div.widget-calendar-1[data-module=calendar][data-subpart-id="{{subpart-id}}"]').each(function(index){ var calendar = $(this), cmi = new CalendarModuleMonth1(new Date(), calendar,calendar.data("subpart-id"),"{{more_url}}",false); cmi.currentMonth(); diff --git a/modules/calendar/_calendar_widget2.html.erb b/modules/calendar/_calendar_widget2.html.erb index 8fc4ea8..f1fa761 100644 --- a/modules/calendar/_calendar_widget2.html.erb +++ b/modules/calendar/_calendar_widget2.html.erb @@ -4,7 +4,7 @@ {{widget_title}}
-

+

placeholder

@@ -20,14 +20,8 @@
SunMonTueWedThuFriSat
{{week_title}}
- - - - - - - - + + @@ -63,7 +57,7 @@ tag.setAttribute("id", "calendar-widget_module2"); tag.src = "<%= asset_path('calendar_widget2.js') %>"; tag.onload = function(){ - $("div.widget-calendar-2[data-module=calendar]").each(function(index){ + $('div.widget-calendar-2[data-module="calendar"][data-subpart-id="{{subpart-id}}"]').each(function(index){ var calendar = $(this), cmi = new CalendarModuleMonth2(new Date(), calendar,calendar.data("subpart-id"),"{{more_url}}",false); cmi.currentMonth(); diff --git a/modules/calendar/index2.html.erb b/modules/calendar/index2.html.erb index b929893..6ffa18b 100644 --- a/modules/calendar/index2.html.erb +++ b/modules/calendar/index2.html.erb @@ -2,7 +2,7 @@ {{style_tag}}
-

+

placeholder

@@ -18,14 +18,8 @@
SunMonTueWedThuFriSat
{{week_title}}
- - - - - - - - + +
SunMonTueWedThuFriSat
{{week_title}}