-
+
diff --git a/src/calendar.js b/src/calendar.js
index 52871f4..9e5541e 100644
--- a/src/calendar.js
+++ b/src/calendar.js
@@ -10,16 +10,44 @@
angular.module('ui.calendar', [])
.constant('uiCalendarConfig', {})
-.directive('uiCalendar', ['uiCalendarConfig', '$parse', function(uiCalendarConfig) {
+.factory('Calendar',function(){
+ return function(elem){
+ var calendar = elem;//this will become the fullcalendar object when loaded
+ var call = function(call,args){//interface to fullcalendars functions
+ return calendar.fullCalendar(call,args);
+ };
+ this.test = 'works';
+ this.refetchEvents = function(){//refetchEvents... this way an interface can be made to all functionality and add more controll.
+ return call('refetchEvents');
+ };
+ this.init = function(options){//the creation of the fullcalendar.
+ return call(options);
+ };
+ this.fullCalendar = function(call,args){//backwards compatibility
+ return call(call,args);
+ };
+ };
+})
+.directive('uiCalendar', ['uiCalendarConfig', 'Calendar' , '$parse', function(uiCalendarConfig,Calendar) {
uiCalendarConfig = uiCalendarConfig || {};
//returns calendar
return {
require: 'ngModel',
- scope: true,
+ scope: {ngModel:'=',config:'='},
restrict: 'A',
- link: function(scope, elm, attrs) {
- var sources = scope.$eval(attrs.ngModel);
- var calendar = elm.html('');
+ controller:function($scope,$element){
+ },
+ link: function(scope, elm, attrs,calCtrl) {
+ var sources = scope.ngModel;//scope.$eval(attrs.ngModel);
+ scope.destroy = function(){
+ if(attrs.calendar){
+ scope.calendar = scope.$parent[attrs.calendar] = new Calendar(elm.html(''));
+ }else{
+ scope.calendar = new Calendar(elm.html(''));
+ }
+ };
+ scope.destroy();
+ //scope.calendar = elm.html('');
var eventsFingerprint = function() {
var fpn = "";
angular.forEach(sources, function(events) {
@@ -36,11 +64,14 @@ angular.module('ui.calendar', [])
});
return fpn;
};
-
- var options = { eventSources: sources };
- angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? scope.$eval(attrs.uiCalendar) : {});
- calendar.fullCalendar(options);
-
+ scope.init = function(){
+ var options = { eventSources: sources };
+ // not sure which would be more convenient
+ //angular.extend(options, uiCalendarConfig, scope.config ? scope.config : {});
+ angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? scope.$parent.$eval(attrs.uiCalendar) : {});
+ scope.calendar.init(options);
+ };
+ scope.init();
// Track changes in array by assigning numeric ids to each element and watching the scope for changes in those ids
var changeTracker = function(array) {
var self;
@@ -102,13 +133,13 @@ angular.module('ui.calendar', [])
var sourcesTracker = changeTracker(sources);
sourcesTracker.subscribe(scope);
sourcesTracker.onAdded = function(source) {
- calendar.fullCalendar('addEventSource', source);
+ scope.calendar.addEventSource(source);
};
sourcesTracker.onRemoved = function(source) {
- calendar.fullCalendar('removeEventSource', source);
+ scope.calendar.removeEventSource(source);
};
scope.$watch(eventsFingerprint, function() {
- calendar.fullCalendar('refetchEvents');
+ scope.calendar.refetchEvents();
});
}
};
diff --git a/test/calendar.spec.js b/test/calendar.spec.js
index 158f70c..688509a 100644
--- a/test/calendar.spec.js
+++ b/test/calendar.spec.js
@@ -80,44 +80,44 @@ describe('uiCalendar', function () {
/* test the calendar's events length */
it('should excpect to load 4 events to scope', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toBe(4);
});
/* test to check the title of the first event. */
it('should excpect to be All Day Event', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][0].title).toBe('All Day Event');
});
/* test to make sure the event has a url assigned to it. */
it('should expect the url to = http://www.angularjs.org', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][0].url).toBe('http://www.angularjs.org');
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[1][0].url).toBe('http://www.atlantacarlocksmith.com');
});
/* test the 3rd events' allDay field. */
it('should expect the fourth Events all Day field to equal true', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][3].allDay).toNotBe(false);
});
/* Tests the height of the calendar. */
it('should expect the calendar attribute height to be 200', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].height).toEqual(200);
});
/* Tests the weekends boolean of the calendar. */
it('should expect the calendar attribute weekends to be false', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].weekends).toEqual(false);
});
/* Test to make sure that when an event is added to the calendar everything is updated with the new event. */
it('should expect the scopes events to increase by 2', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(4);
scope.addChild(scope.events);
scope.addChild(scope.events);
@@ -126,7 +126,7 @@ describe('uiCalendar', function () {
/* Test to make sure the calendar is updating itself on changes to events length. */
it('should expect the calendar to update itself with new events', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
expect(clientEventsLength).toEqual(4);
//remove an event from the scope.
@@ -143,7 +143,7 @@ describe('uiCalendar', function () {
header: {center: 'title'}
}
};
- $compile('')(scope);
+ $compile('')(scope);
expect($.fn.fullCalendar.mostRecentCall.args[0].hasOwnProperty('header')).toEqual(true);
var header = $.fn.fullCalendar.mostRecentCall.args[0].header;
expect(header).toEqual({center: 'title'});
@@ -151,7 +151,7 @@ describe('uiCalendar', function () {
/* Test to see if calendar is watching all eventSources for changes. */
it('should update the calendar if any eventSource array contains a delta', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
var clientEventsLength2 = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[1].length;
expect(clientEventsLength).toEqual(4);
@@ -170,7 +170,7 @@ describe('uiCalendar', function () {
/* Test to see if calendar is updating when a new eventSource is added. */
it('should update the calendar if an eventSource is Added', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
var clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources.length;
expect(clientEventSources).toEqual(2);
//add new source to calendar
@@ -186,7 +186,7 @@ describe('uiCalendar', function () {
/* Test to see if calendar is updating when an eventSource replaces another with an equal length. */
it('should update the calendar if an eventSource has same length as prior eventSource', function () {
spyOn($.fn, 'fullCalendar');
- $compile('')(scope);
+ $compile('')(scope);
var clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
expect(clientEventsLength).toEqual(4);
@@ -206,6 +206,7 @@ describe('uiCalendar', function () {
expect(clientEventsLength).toEqual(3);
});
+
});