Skip to content

Commit

Permalink
Implement option for custom data source rendering.
Browse files Browse the repository at this point in the history
Add a style "custom". Add an option "customDataSourceRenderer" to use a
custom function for data source rendering.
  • Loading branch information
Paul-DS committed Jan 28, 2016
1 parent e554b4b commit b1733aa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
25 changes: 17 additions & 8 deletions js/bootstrap-year-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
disabledDays: opt.disabledDays instanceof Array ? opt.disabledDays : [],
roundRangeLimits: opt.roundRangeLimits != null ? opt.roundRangeLimits : false,
dataSource: opt.dataSource instanceof Array != null ? opt.dataSource : [],
style: $.type(opt.style) == 'function' ? opt.style : (opt.style == 'background' ? 'background' : 'border'),
style: opt.style == 'background' || opt.style == 'border' || opt.style == 'custom' ? opt.style : 'border',
enableContextMenu: opt.enableContextMenu != null ? opt.enableContextMenu : false,
contextMenuItems: opt.contextMenuItems instanceof Array ? opt.contextMenuItems : []
contextMenuItems: opt.contextMenuItems instanceof Array ? opt.contextMenuItems : [],
customDataSourceRenderer : $.isFunction(opt.customDataSourceRenderer) ? opt.customDataSourceRenderer : null
};

this._initializeDatasourceColors();
Expand Down Expand Up @@ -338,11 +339,6 @@
}
},
_renderDataSourceDay: function(elt, currentDate, events) {
if ( $.type(this.options.style) == 'function' ) {
this.options.style.call(this, elt, currentDate, events);
return;
}

switch(this.options.style)
{
case 'border':
Expand Down Expand Up @@ -425,6 +421,12 @@
}
}
break;

case 'custom':
if(this.options.customDataSourceRenderer) {
this.options.customDataSourceRenderer.call(this, elt, currentDate, events);
}
break;
}
},
_applyEvents: function () {
Expand Down Expand Up @@ -819,7 +821,7 @@
return this.options.style;
},
setStyle: function(style) {
this.options.style = $.type(style) == 'function' ? style : (style == 'background' ? 'background' : 'border');
this.options.style = style == 'background' || style == 'border' || style == 'custom' ? style : 'border';
this._render();
},
getAllowOverlap: function() {
Expand Down Expand Up @@ -877,6 +879,13 @@
this.options.contextMenuItems = contextMenuItems instanceof Array ? contextMenuItems : [];
this._render();
},
getCustomDataSourceRenderer: function() {
return this.options.customDataSourceRenderer;
},
setCustomDataSourceRenderer: function(customDataSourceRenderer) {
this.options.customDataSourceRenderer = $.isFunction(customDataSourceRenderer) ? customDataSourceRenderer : null;
this._render();
},
getLanguage: function() {
return this.options.language;
},
Expand Down
Loading

0 comments on commit b1733aa

Please sign in to comment.