From 5e97132353843cec3048a6d70a1fcdb533abe198 Mon Sep 17 00:00:00 2001 From: yourilima Date: Tue, 9 Apr 2013 17:20:23 +0300 Subject: [PATCH 1/8] bindings and adding controll binded calendar config and event model. added and exposed of destroy and init controll --- src/calendar.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 52871f4..036f458 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -15,11 +15,18 @@ angular.module('ui.calendar', []) //returns calendar return { require: 'ngModel', - scope: true, + scope: {calendar:'=',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(){ + scope.calendar = elm.html(''); + } + scope.destroy(); + //scope.calendar = elm.html(''); var eventsFingerprint = function() { var fpn = ""; angular.forEach(sources, function(events) { @@ -36,11 +43,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, attrs.uiCalendar ? attrs.uiCalendar : {}); + angular.extend(options, uiCalendarConfig, scope.config ? scope.config : {}); + scope.calendar.fullCalendar(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,14 +112,14 @@ angular.module('ui.calendar', []) var sourcesTracker = changeTracker(sources); sourcesTracker.subscribe(scope); sourcesTracker.onAdded = function(source) { - calendar.fullCalendar('addEventSource', source); + scope.calendar.fullCalendar('addEventSource', source); }; sourcesTracker.onRemoved = function(source) { - calendar.fullCalendar('removeEventSource', source); + scope.calendar.fullCalendar('removeEventSource', source); }; scope.$watch(eventsFingerprint, function() { - calendar.fullCalendar('refetchEvents'); + scope.calendar.fullCalendar('refetchEvents'); }); } }; -}]); +}]); From 9b3f45bb1e6e46c227dc44770da07875146026c9 Mon Sep 17 00:00:00 2001 From: yourilima Date: Tue, 9 Apr 2013 17:30:41 +0300 Subject: [PATCH 2/8] semicolons --- src/calendar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 036f458..c99aec3 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -24,7 +24,7 @@ angular.module('ui.calendar', []) var sources = scope.ngModel;//scope.$eval(attrs.ngModel); scope.destroy = function(){ scope.calendar = elm.html(''); - } + }; scope.destroy(); //scope.calendar = elm.html(''); var eventsFingerprint = function() { @@ -49,7 +49,7 @@ angular.module('ui.calendar', []) //angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? attrs.uiCalendar : {}); angular.extend(options, uiCalendarConfig, scope.config ? scope.config : {}); scope.calendar.fullCalendar(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) { @@ -122,4 +122,4 @@ angular.module('ui.calendar', []) }); } }; -}]); +}]); From 8b1c585ce0132f0478350bff28f652b86815836c Mon Sep 17 00:00:00 2001 From: Youri Lima Date: Thu, 11 Apr 2013 11:04:39 +0200 Subject: [PATCH 3/8] test fixes --- test/calendar.spec.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/calendar.spec.js b/test/calendar.spec.js index 158f70c..57cdd96 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); From ef353d2e139d33c1ae0aea10d1eeef87da00416b Mon Sep 17 00:00:00 2001 From: Youri Lima Date: Thu, 11 Apr 2013 12:11:37 +0200 Subject: [PATCH 4/8] backward compatibility --- src/calendar.js | 4 ++-- test/calendar.spec.js | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index c99aec3..af980b7 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -15,7 +15,7 @@ angular.module('ui.calendar', []) //returns calendar return { require: 'ngModel', - scope: {calendar:'=',ngModel:'=',config:'='}, + scope: {calendar:'=',ngModel:'='}, restrict: 'A', controller:function($scope,$element){ @@ -47,7 +47,7 @@ angular.module('ui.calendar', []) var options = { eventSources: sources }; // not sure which would be more convenient //angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? attrs.uiCalendar : {}); - angular.extend(options, uiCalendarConfig, scope.config ? scope.config : {}); + angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? scope.$parent.$eval(attrs.uiCalendar) : {}); scope.calendar.fullCalendar(options); }; scope.init(); diff --git a/test/calendar.spec.js b/test/calendar.spec.js index 57cdd96..158f70c 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); From c4647a051473185cf43131e5ea014212af3b9787 Mon Sep 17 00:00:00 2001 From: yourilima Date: Thu, 11 Apr 2013 16:47:59 +0300 Subject: [PATCH 5/8] function name fix --- demo/calendarDemo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/calendarDemo.js b/demo/calendarDemo.js index e0e8342..0f8ce69 100644 --- a/demo/calendarDemo.js +++ b/demo/calendarDemo.js @@ -32,7 +32,7 @@ function CalendarCtrl($scope) { callback(events); }; /* alert on eventClick */ - $scope.addEventOnClick = function( date, allDay, jsEvent, view ){ + $scope.alertEventOnClick = function( date, allDay, jsEvent, view ){ $scope.$apply(function(){ $scope.alertMessage = ('Day Clicked ' + date); }); @@ -93,4 +93,4 @@ function CalendarCtrl($scope) { /* event sources array*/ $scope.eventSources = [$scope.events, $scope.eventSource, $scope.eventsF]; } -/* EOF */ \ No newline at end of file +/* EOF */ From c4a7c6868ece68c1aaf3b6edd201379969774174 Mon Sep 17 00:00:00 2001 From: Youri Lima Date: Thu, 11 Apr 2013 23:15:44 +0200 Subject: [PATCH 6/8] interface object to hide the actual fullcalendar object --- demo/index.html | 4 ++-- src/calendar.js | 35 +++++++++++++++++++++++++---------- test/calendar.spec.js | 25 +++++++++++++------------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/demo/index.html b/demo/index.html index 20fc5bd..1f864e8 100644 --- a/demo/index.html +++ b/demo/index.html @@ -13,7 +13,7 @@ - + @@ -82,7 +82,7 @@

Why?

-
+
diff --git a/src/calendar.js b/src/calendar.js index af980b7..005778c 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -10,20 +10,35 @@ angular.module('ui.calendar', []) .constant('uiCalendarConfig', {}) -.directive('uiCalendar', ['uiCalendarConfig', '$parse', function(uiCalendarConfig) { +.value('calendar',{ + _calendar:null,//this will become the fullcalendar object when loaded + _call:function(call,args){//interface to fullcalendars functions + return this._calendar.fullCalendar(call,args); + }, + refetchEvents:function(){//refetchEvents... this way an interface can be made to all functionality and add more controll. + return this._call('refetchEvents'); + }, + init:function(options){//the creation of the fullcalendar. + return this._call(options); + }, + fullCalendar:function(call,args){//backwards compatibility + return this._call(call,args); + } +}) +.directive('uiCalendar', ['uiCalendarConfig', 'calendar' , '$parse', function(uiCalendarConfig,calendar) { uiCalendarConfig = uiCalendarConfig || {}; //returns calendar return { require: 'ngModel', - scope: {calendar:'=',ngModel:'='}, + scope: {calendar:'=',ngModel:'=',config:'='}, restrict: 'A', - controller:function($scope,$element){ - + controller:function($scope,$element,calendar){ + $scope.calendar = calendar; }, link: function(scope, elm, attrs,calCtrl) { var sources = scope.ngModel;//scope.$eval(attrs.ngModel); scope.destroy = function(){ - scope.calendar = elm.html(''); + scope.calendar._calendar = elm.html(''); }; scope.destroy(); //scope.calendar = elm.html(''); @@ -46,9 +61,9 @@ angular.module('ui.calendar', []) scope.init = function(){ var options = { eventSources: sources }; // not sure which would be more convenient - //angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? attrs.uiCalendar : {}); + //angular.extend(options, uiCalendarConfig, scope.config ? scope.config : {}); angular.extend(options, uiCalendarConfig, attrs.uiCalendar ? scope.$parent.$eval(attrs.uiCalendar) : {}); - scope.calendar.fullCalendar(options); + 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 @@ -112,13 +127,13 @@ angular.module('ui.calendar', []) var sourcesTracker = changeTracker(sources); sourcesTracker.subscribe(scope); sourcesTracker.onAdded = function(source) { - scope.calendar.fullCalendar('addEventSource', source); + scope.calendar.addEventSource(source); }; sourcesTracker.onRemoved = function(source) { - scope.calendar.fullCalendar('removeEventSource', source); + scope.calendar.removeEventSource(source); }; scope.$watch(eventsFingerprint, function() { - scope.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); }); + }); From b67c36b88d171b38b69b8749cdcc2a853a3a2313 Mon Sep 17 00:00:00 2001 From: Youri Lima Date: Fri, 12 Apr 2013 00:37:17 +0200 Subject: [PATCH 7/8] changed the calendar object to be provided by a factory --- src/calendar.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 005778c..13f330e 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -10,35 +10,36 @@ angular.module('ui.calendar', []) .constant('uiCalendarConfig', {}) -.value('calendar',{ - _calendar:null,//this will become the fullcalendar object when loaded - _call:function(call,args){//interface to fullcalendars functions - return this._calendar.fullCalendar(call,args); - }, - refetchEvents:function(){//refetchEvents... this way an interface can be made to all functionality and add more controll. - return this._call('refetchEvents'); - }, - init:function(options){//the creation of the fullcalendar. - return this._call(options); - }, - fullCalendar:function(call,args){//backwards compatibility - return this._call(call,args); - } +.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.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) { +.directive('uiCalendar', ['uiCalendarConfig', 'Calendar' , '$parse', function(uiCalendarConfig,Calendar) { uiCalendarConfig = uiCalendarConfig || {}; //returns calendar return { require: 'ngModel', scope: {calendar:'=',ngModel:'=',config:'='}, restrict: 'A', - controller:function($scope,$element,calendar){ - $scope.calendar = calendar; + controller:function($scope,$element){ }, link: function(scope, elm, attrs,calCtrl) { var sources = scope.ngModel;//scope.$eval(attrs.ngModel); scope.destroy = function(){ - scope.calendar._calendar = elm.html(''); + scope.calendar = new Calendar(elm.html('')); }; scope.destroy(); //scope.calendar = elm.html(''); From 23775dabe2db3db25725eb55a27995a1798591e6 Mon Sep 17 00:00:00 2001 From: Youri Lima Date: Fri, 12 Apr 2013 01:12:58 +0200 Subject: [PATCH 8/8] calendar attribute now optional --- src/calendar.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 13f330e..9e5541e 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -16,6 +16,7 @@ angular.module('ui.calendar', []) 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'); }; @@ -32,14 +33,18 @@ angular.module('ui.calendar', []) //returns calendar return { require: 'ngModel', - scope: {calendar:'=',ngModel:'=',config:'='}, + scope: {ngModel:'=',config:'='}, restrict: 'A', controller:function($scope,$element){ }, link: function(scope, elm, attrs,calCtrl) { var sources = scope.ngModel;//scope.$eval(attrs.ngModel); scope.destroy = function(){ - scope.calendar = new Calendar(elm.html('')); + 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('');