-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-addthisevent.js
63 lines (53 loc) · 1.43 KB
/
angular-addthisevent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
---
name: AddThisEvent Angularjs
license: MIT-style license
requires: [angular, addthisevent]
provides: [AddThisEvent]
...
*/
;;
(function(window, angular) {
'use strict';
// Module global settings.
var settings = {};
angular.module('angularAddThisEvent', [])
// Declare module settings value
.value('settings', settings)
.provider('AddThisEvent', [function () {
var initDeferred;
this.init = function(initSettings) {
if (angular.isObject(initSettings)) {
angular.extend(settings, initSettings);
}
};
this.$get = ['$q', '$window', function($q, $window) {
return {
init: function() {
initDeferred = $q.defer();
$window.addthisevent.settings(settings);
initDeferred.resolve();
},
refresh: function() {
if (!initDeferred) {
this.init();
}
return initDeferred.promise.then(function() {
$window.addthisevent.refresh();
});
}
}}]
}])
.directive('addToCalendar', ['AddThisEvent', '$timeout', function (AddThisEvent, $timeout){
return {
restrict: 'A',
scope: false,
link: function (scope, element) {
element.hide();
AddThisEvent.refresh().then(function(){
element.show();
});
}
};
}]);
})(window, angular);