|
@@ -59,7 +59,7 @@ function Calendar(element, instanceOptions) {
|
|
|
t.option = option;
|
|
t.option = option;
|
|
|
t.trigger = trigger;
|
|
t.trigger = trigger;
|
|
|
t.isValidViewType = isValidViewType;
|
|
t.isValidViewType = isValidViewType;
|
|
|
- t.getDefaultViewButtonText = getDefaultViewButtonText;
|
|
|
|
|
|
|
+ t.getViewButtonText = getViewButtonText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -69,7 +69,7 @@ function Calendar(element, instanceOptions) {
|
|
|
|
|
|
|
|
|
|
|
|
|
var localeData = createObject( // make a cheap copy
|
|
var localeData = createObject( // make a cheap copy
|
|
|
- getMomentLocaleData(options.lang)
|
|
|
|
|
|
|
+ getMomentLocaleData(options.lang) // will fall back to en
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
if (options.monthNames) {
|
|
if (options.monthNames) {
|
|
@@ -203,6 +203,14 @@ function Calendar(element, instanceOptions) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // Produces a human-readable string for the given duration.
|
|
|
|
|
+ // Side-effect: changes the locale of the given duration.
|
|
|
|
|
+ function humanizeDuration(duration) {
|
|
|
|
|
+ return (duration.locale || duration.lang).call(duration, options.lang) // works moment-pre-2.8
|
|
|
|
|
+ .humanize();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// Imports
|
|
// Imports
|
|
|
// -----------------------------------------------------------------------------------
|
|
// -----------------------------------------------------------------------------------
|
|
@@ -398,12 +406,15 @@ function Calendar(element, instanceOptions) {
|
|
|
|
|
|
|
|
// Gets information about how to create a view
|
|
// Gets information about how to create a view
|
|
|
function getViewSpec(requestedViewType) {
|
|
function getViewSpec(requestedViewType) {
|
|
|
- var hash = options.views || {};
|
|
|
|
|
|
|
+ var allDefaultButtonText = options.defaultButtonText || {};
|
|
|
|
|
+ var allButtonText = options.buttonText || {};
|
|
|
|
|
+ var hash = options.views || {}; // the `views` option object
|
|
|
var viewType = requestedViewType;
|
|
var viewType = requestedViewType;
|
|
|
var viewOptionsChain = [];
|
|
var viewOptionsChain = [];
|
|
|
var viewOptions;
|
|
var viewOptions;
|
|
|
var viewClass;
|
|
var viewClass;
|
|
|
- var duration;
|
|
|
|
|
|
|
+ var duration, unit, unitIsSingle = false;
|
|
|
|
|
+ var buttonText;
|
|
|
|
|
|
|
|
if (viewSpecCache[requestedViewType]) {
|
|
if (viewSpecCache[requestedViewType]) {
|
|
|
return viewSpecCache[requestedViewType];
|
|
return viewSpecCache[requestedViewType];
|
|
@@ -432,20 +443,33 @@ function Calendar(element, instanceOptions) {
|
|
|
|
|
|
|
|
if (viewClass) {
|
|
if (viewClass) {
|
|
|
|
|
|
|
|
- // options that are specified per the view's duration, like "week" or "day"
|
|
|
|
|
duration = viewOptions.duration || viewClass.duration;
|
|
duration = viewOptions.duration || viewClass.duration;
|
|
|
if (duration) {
|
|
if (duration) {
|
|
|
duration = moment.duration(duration);
|
|
duration = moment.duration(duration);
|
|
|
- $.each(intervalUnits, function(i, unit) {
|
|
|
|
|
- if (hash[unit] && computeIntervalAs(unit, duration) === 1) {
|
|
|
|
|
- viewOptions = $.extend({}, hash[unit], viewOptions); // lowest priority
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ unit = computeIntervalUnit(duration);
|
|
|
|
|
+ unitIsSingle = computeIntervalAs(unit, duration) === 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // options that are specified per the view's duration, like "week" or "day"
|
|
|
|
|
+ if (unitIsSingle && hash[unit]) {
|
|
|
|
|
+ viewOptions = $.extend({}, hash[unit], viewOptions); // lowest priority
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // compute the final text for the button representing this view
|
|
|
|
|
+ buttonText =
|
|
|
|
|
+ allButtonText[requestedViewType] || // init options, like "agendaWeek"
|
|
|
|
|
+ (unitIsSingle ? allButtonText[unit] : null) || // init options, like "week"
|
|
|
|
|
+ allDefaultButtonText[requestedViewType] || // lang data, like "agendaWeek"
|
|
|
|
|
+ (unitIsSingle ? allDefaultButtonText[unit] : null) || // lang data, like "week"
|
|
|
|
|
+ viewOptions.buttonText ||
|
|
|
|
|
+ viewClass.buttonText ||
|
|
|
|
|
+ (duration ? humanizeDuration(duration) : null) ||
|
|
|
|
|
+ requestedViewType;
|
|
|
|
|
+
|
|
|
return (viewSpecCache[requestedViewType] = {
|
|
return (viewSpecCache[requestedViewType] = {
|
|
|
'class': viewClass,
|
|
'class': viewClass,
|
|
|
- options: viewOptions
|
|
|
|
|
|
|
+ options: viewOptions,
|
|
|
|
|
+ buttonText: buttonText
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -457,15 +481,12 @@ function Calendar(element, instanceOptions) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- // Gets the text that should be displayed on a view's button in the header, by default.
|
|
|
|
|
- // Values in the global `buttonText` option will eventually override this value.
|
|
|
|
|
- function getDefaultViewButtonText(viewType) {
|
|
|
|
|
|
|
+ // Gets the text that should be displayed on a view's button in the header
|
|
|
|
|
+ function getViewButtonText(viewType) {
|
|
|
var spec = getViewSpec(viewType);
|
|
var spec = getViewSpec(viewType);
|
|
|
|
|
|
|
|
- if (spec) { // valid view?
|
|
|
|
|
- return smartProperty(options.defaultButtonText, viewType) || // takes precedence. defined by languages
|
|
|
|
|
- spec.options.buttonText || // defined by custom view options
|
|
|
|
|
- viewType; // last resort
|
|
|
|
|
|
|
+ if (spec) {
|
|
|
|
|
+ return spec.buttonText;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|