Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit af8cf03

Browse files
committed
fix(calendar): not hacking the accessibility of mulitple calendars
Signed-off-by: Josh Kurz <josh.kurz@turner.com>
1 parent 0d904ae commit af8cf03

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

bower.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"angular": "~1.2.x",
20-
"fullcalendar": "~2.x"
19+
"angular": "1.2.26",
20+
"jquery": "2.x",
21+
"fullcalendar": "2.1.1",
22+
"moment": "2.*"
2123
},
2224
"devDependencies": {
2325
"angular-mocks": "~1.x",
24-
"bootstrap-css": "2.3.1",
25-
"jquery-ui": "~1.10.3"
26+
"bootstrap-css": "2.3.1"
27+
},
28+
"resolutions": {
29+
"jquery": "~2.x",
30+
"angular": "1.2.26"
2631
}
2732
}

src/calendar.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
*/
1010

1111
angular.module('ui.calendar', [])
12-
.constant('uiCalendarConfig', {})
13-
.controller('uiCalendarCtrl', ['$scope', '$timeout', '$locale', function($scope, $timeout, $locale){
12+
.constant('uiCalendarConfig', {calendars: {}})
13+
.controller('uiCalendarCtrl', ['$scope',
14+
'$timeout',
15+
'$locale', function(
16+
$scope,
17+
$timeout,
18+
$locale){
1419

1520
var sourceSerialId = 1,
1621
eventSerialId = 1,
@@ -198,6 +203,7 @@ angular.module('ui.calendar', [])
198203

199204
var sources = scope.eventSources,
200205
sourcesChanged = false,
206+
calendar,
201207
eventSourcesWatcher = controller.changeWatcher(sources, controller.sourcesFingerprint),
202208
eventsWatcher = controller.changeWatcher(controller.allEvents, controller.eventsFingerprint),
203209
options = null;
@@ -210,9 +216,10 @@ angular.module('ui.calendar', [])
210216

211217
var localeFullCalendarConfig = controller.getLocaleConfig(fullCalendarConfig);
212218
angular.extend(localeFullCalendarConfig, fullCalendarConfig);
213-
214219
options = { eventSources: sources };
215220
angular.extend(options, localeFullCalendarConfig);
221+
//remove calendars from options
222+
options.calendars = null;
216223

217224
var options2 = {};
218225
for(var o in options){
@@ -224,44 +231,44 @@ angular.module('ui.calendar', [])
224231
}
225232

226233
scope.destroy = function(){
227-
if(scope.calendar && scope.calendar.fullCalendar){
228-
scope.calendar.fullCalendar('destroy');
234+
if(calendar && calendar.fullCalendar){
235+
calendar.fullCalendar('destroy');
229236
}
230237
if(attrs.calendar) {
231-
scope.calendar = scope.$parent[attrs.calendar] = $(elm).html('');
238+
calendar = uiCalendarConfig.calendars[attrs.calendar] = $(elm).html('');
232239
} else {
233-
scope.calendar = $(elm).html('');
240+
calendar = $(elm).html('');
234241
}
235242
};
236243

237244
scope.init = function(){
238-
scope.calendar.fullCalendar(options);
245+
calendar.fullCalendar(options);
239246
};
240247

241248
eventSourcesWatcher.onAdded = function(source) {
242-
scope.calendar.fullCalendar('addEventSource', source);
249+
calendar.fullCalendar('addEventSource', source);
243250
sourcesChanged = true;
244251
};
245252

246253
eventSourcesWatcher.onRemoved = function(source) {
247-
scope.calendar.fullCalendar('removeEventSource', source);
254+
calendar.fullCalendar('removeEventSource', source);
248255
sourcesChanged = true;
249256
};
250257

251258
eventsWatcher.onAdded = function(event) {
252-
scope.calendar.fullCalendar('renderEvent', event);
259+
calendar.fullCalendar('renderEvent', event);
253260
};
254261

255262
eventsWatcher.onRemoved = function(event) {
256-
scope.calendar.fullCalendar('removeEvents', function(e) {
263+
calendar.fullCalendar('removeEvents', function(e) {
257264
return e._id === event._id;
258265
});
259266
};
260267

261268
eventsWatcher.onChanged = function(event) {
262269
event._start = $.fullCalendar.moment(event.start);
263270
event._end = $.fullCalendar.moment(event.end);
264-
scope.calendar.fullCalendar('updateEvent', event);
271+
calendar.fullCalendar('updateEvent', event);
265272
};
266273

267274
eventSourcesWatcher.subscribe(scope);

test/calendar.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
describe('uiCalendar', function () {
33
'use strict';
44

5-
var scope, $compile, $locale, $controller;
5+
var scope, $compile, $locale, $controller, config;
66

77
//Date Objects needed for event
88
var date = new Date();
@@ -11,11 +11,12 @@ describe('uiCalendar', function () {
1111
var y = date.getFullYear();
1212

1313
beforeEach(module('ui.calendar'));
14-
beforeEach(inject(function (_$rootScope_, _$compile_, _$locale_,_$controller_) {
14+
beforeEach(inject(function (_$rootScope_, _$compile_, _$locale_,_$controller_,uiCalendarConfig) {
1515
scope = _$rootScope_.$new();
1616
$compile = _$compile_;
1717
$locale = _$locale_;
1818
$controller = _$controller_;
19+
config = uiCalendarConfig;
1920

2021
// create an array of events, to pass into the directive.
2122
scope.events = [
@@ -293,17 +294,17 @@ describe('uiCalendar', function () {
293294
});
294295
});
295296

296-
describe('Testing the ability to add calendars to the scope', function(){
297+
describe('Testing the ability to add calendars to the calendarConfig', function(){
297298

298299
beforeEach(function(){
299300
spyOn($.fn, 'fullCalendar');
300-
expect(scope.myCalendar).toBe(undefined);
301+
expect(config.calendars.myCalendar).toBe(undefined);
301302
$compile('<div ui-calendar="uiConfig.calendar" calendar="myCalendar" ng-model="eventSources"></div>')(scope);
302303
scope.$apply();
303304
});
304305

305-
it('should make sure the calendar sets the myCalendar object to the defining scope', function () {
306-
expect(scope.myCalendar).not.toBe(undefined);
306+
it('should make sure the calendar sets the myCalendar object to the calendarConfig', function () {
307+
expect(config.calendars.myCalendar).not.toBe(undefined);
307308
});
308309
});
309310

0 commit comments

Comments
 (0)