Changeset View
Standalone View
webroot/rsrc/js/core/behavior-fancy-datepicker.js
/** | /** | ||||
* @provides javelin-behavior-fancy-datepicker | * @provides javelin-behavior-fancy-datepicker | ||||
* @requires javelin-behavior | * @requires javelin-behavior | ||||
* javelin-util | * javelin-util | ||||
* javelin-dom | * javelin-dom | ||||
* javelin-stratcom | * javelin-stratcom | ||||
* javelin-vector | * javelin-vector | ||||
*/ | */ | ||||
JX.behavior('fancy-datepicker', function(config, statics) { | JX.behavior('fancy-datepicker', function(config, statics) { | ||||
if (statics.initialized) { | if (statics.initialized) { | ||||
return; | return; | ||||
} | } | ||||
statics.initialized = true; | statics.initialized = true; | ||||
var pht = JX.phtize(config.pht); | |||||
var picker; | var picker; | ||||
var anchor_node; | var anchor_node; | ||||
var root; | var root; | ||||
var value_y; | var value_y; | ||||
var value_m; | var value_m; | ||||
var value_d; | var value_d; | ||||
▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | JX.behavior('fancy-datepicker', function(config, statics) { | ||||
// Render the top bar which allows you to pick a month and year. | // Render the top bar which allows you to pick a month and year. | ||||
var render_month = function() { | var render_month = function() { | ||||
var valid_date = getValidDate(); | var valid_date = getValidDate(); | ||||
var month = valid_date.getMonth(); | var month = valid_date.getMonth(); | ||||
var year = valid_date.getYear() + 1900; | var year = valid_date.getYear() + 1900; | ||||
var months = [ | var months = [ | ||||
'January', | pht('January'), | ||||
'February', | pht('February'), | ||||
'March', | pht('March'), | ||||
'April', | pht('April'), | ||||
'May', | pht('May'), | ||||
'June', | pht('June'), | ||||
'July', | pht('July'), | ||||
'August', | pht('August'), | ||||
'September', | pht('September'), | ||||
'October', | pht('October'), | ||||
'November', | pht('November'), | ||||
'December']; | pht('December')]; | ||||
var buttons = [ | var buttons = [ | ||||
cell('\u25C0', 'm:-1', false, 'lrbutton'), | cell('\u25C0', 'm:-1', false, 'lrbutton'), | ||||
cell(months[month] + ' ' + year, null), | cell(months[month] + ' ' + year, null), | ||||
cell('\u25B6', 'm:1', false, 'lrbutton')]; | cell('\u25B6', 'm:1', false, 'lrbutton')]; | ||||
return JX.$N( | return JX.$N( | ||||
'table', | 'table', | ||||
Show All 40 Lines | JX.behavior('fancy-datepicker', function(config, statics) { | ||||
// Render the day-of-week and calendar views. | // Render the day-of-week and calendar views. | ||||
var render_day = function() { | var render_day = function() { | ||||
var today = new Date(); | var today = new Date(); | ||||
var valid_date = getValidDate(); | var valid_date = getValidDate(); | ||||
var weeks = []; | var weeks = []; | ||||
// First, render the weekday names. | // First, render the weekday names. | ||||
var weekdays = 'SMTWTFS'; | var weekdays = pht('S|M|T|W|T|F|S').split('|'); | ||||
var weekday_names = []; | var weekday_names = []; | ||||
var week_start = parseInt(get_week_start(), 10); | var week_start = parseInt(get_week_start(), 10); | ||||
var week_end = weekdays.length + week_start; | var week_end = weekdays.length + week_start; | ||||
speck: This should be able to use `weekdays.length` again | |||||
Done Inline ActionsYes, but only for readabillity. Providing Stings wich do not split into 7 Parts will produce garbage anyways. Leon95: Yes, but only for readabillity. Providing Stings wich do not split into 7 Parts will produce… | |||||
Done Inline ActionsThis assumes that all the day abbreviations will be the same length. Would it be cleaner to use strings like "S|M|T|W|T|F|S" and "So|Mo|Di|Mi|Do|Fr|Sa" instead, which are easily split into an array? That way there's no need to do any manual substring extraction. 0: This assumes that all the day abbreviations will be the same length. Would it be cleaner to use… | |||||
Done Inline ActionsThis seems like a much saner approach to me too. This would also allow for strings with different lengths, which could be interesting for disambiguation. Something like this "S|M|T|W|TH|F|S" if wanted. It seems that across the Phorge repo there's no other scenario in which this is use, so it should have no side effects. So this would be setting a precedent for changes to follow. CSharp: This seems like a much saner approach to me too. This would also allow for strings with… | |||||
Done Inline Actions@Leon95 if this also makes sense to you would you be able to take a look at updating the day-of-week string to be delimited? speck: @Leon95 if this also makes sense to you would you be able to take a look at updating the day-of… | |||||
Done Inline ActionsWill take a look at it Leon95: Will take a look at it | |||||
for (var ii = week_start; ii < week_end; ii++) { | for (var ii = week_start; ii < week_end; ii++) { | ||||
var index = ii%7; | var index = ii%7; | ||||
weekday_names.push(cell(weekdays.charAt(index), null, false, 'day-name')); | weekday_names.push(cell(weekdays[index], null, false, 'day-name')); | ||||
} | } | ||||
weeks.push(JX.$N('tr', {}, weekday_names)); | weeks.push(JX.$N('tr', {}, weekday_names)); | ||||
// Render the calendar itself. NOTE: Javascript uses 0-based month indexes | // Render the calendar itself. NOTE: Javascript uses 0-based month indexes | ||||
// while we use 1-based month indexes, so we have to adjust for that. | // while we use 1-based month indexes, so we have to adjust for that. | ||||
var days = []; | var days = []; | ||||
var start = (new Date( | var start = (new Date( | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |
This should be able to use weekdays.length again