Skip to content

Commit f4f7209

Browse files
committed
add attribute to pass CLNDR options
1 parent 40a5919 commit f4f7209

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

angular-clndr.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
var controller, scope;
1515
scope = {
1616
clndr: '=tienClndrObject',
17-
events: '=tienClndrEvents'
17+
events: '=tienClndrEvents',
18+
options: '=?tienClndrOptions'
1819
};
1920
controller = function($scope, $element, $attrs, $transclude) {
2021
return $transclude(function(clone, scope) {
21-
var render;
22+
var options, render;
2223
$element.append(clone);
2324
$scope.$watch('events', function(val) {
2425
if (val != null ? val.length : void 0) {
@@ -28,9 +29,10 @@
2829
render = function(data) {
2930
return angular.extend(scope, data);
3031
};
31-
return $scope.clndr = angular.element("<div/>").clndr({
32+
options = angular.extend($scope.options || {}, {
3233
render: render
3334
});
35+
return $scope.clndr = angular.element("<div/>").clndr(options);
3436
});
3537
};
3638
return {

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h2>Getting Started</h2>
4343
<div class="col-md-12" ng-controller="DemoCtrl">
4444
<h2>Demo</h2>
4545

46-
<tien-clndr class="clndr" tien-clndr-object="clndr" tien-clndr-events="events">
46+
<tien-clndr class="clndr" tien-clndr-object="clndr" tien-clndr-events="events" tien-clndr-options="options">
4747
<div class="clndr-controls">
4848
<div class="clndr-previous-button" ng-click="clndr.back()">
4949
&lsaquo;
@@ -80,6 +80,10 @@ <h2>Demo</h2>
8080
<script>
8181
app = angular.module('clndrApp', ['tien.clndr']);
8282
app.controller('DemoCtrl', function ($scope) {
83+
$scope.options = {
84+
weekOffset: 1,
85+
daysOfTheWeek: ['ZO', 'MA', 'DI', 'WO', 'DO', 'VR', 'ZA']
86+
};
8387
$scope.events = [
8488
{ date: moment().add(3, 'days').format(), title: "Happy days" },
8589
{ date: moment().subtract(5, 'days').format(), title: "Good old days" },
@@ -106,6 +110,12 @@ <h2>Usage</h2>
106110
to the directive with the <code>tien-clndr-events</code> attribute. Events are available
107111
on the scope at <code>day.events</code>, as shown in the example below:
108112
</p>
113+
<p>
114+
To pass additional options on initialization of CLNDR, provide an options object to the
115+
<code>tien-clndr-options</code> attribute. See <a href="https://github.com/kylestetz/CLNDR#usage">CLNDR Usage</a>
116+
for all possible settings. Heads up: the <code>tien-clndr-options</code> object is only read
117+
once during transclusion!
118+
</p>
109119
<pre><code>&lt;tien-clndr class=&quot;clndr&quot; tien-clndr-object=&quot;clndr&quot; tien-clndr-events=&quot;events&quot;&gt;
110120
&lt;div class=&quot;clndr-controls&quot;&gt;
111121
&lt;div class=&quot;clndr-previous-button&quot; ng-click=&quot;clndr.back()&quot;&gt;

src/angular-clndr.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TienClndrDirective = ->
1010
scope =
1111
clndr: '=tienClndrObject'
1212
events: '=tienClndrEvents'
13+
options: '=?tienClndrOptions'
1314

1415
controller = ($scope, $element, $attrs, $transclude) ->
1516
$transclude (clone, scope) ->
@@ -23,9 +24,11 @@ TienClndrDirective = ->
2324
render = (data) ->
2425
angular.extend(scope, data)
2526

27+
# create options object for optional CLNDR settings
28+
options = angular.extend($scope.options || {}, render: render)
29+
2630
# init CLNDR in virtual DOM-element
27-
$scope.clndr = angular.element("<div/>").clndr
28-
render: render
31+
$scope.clndr = angular.element("<div/>").clndr(options)
2932

3033
return {restrict: 'E', replace: true, transclude: true, scope: scope, controller: controller}
3134

0 commit comments

Comments
 (0)