-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
159 lines (152 loc) · 5.55 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
(function() {
angular.module('mpx-frontend-module-thumbor', []);
}).call(this);
(function() {
angular.module("mpx-frontend-module-thumbor").directive('thumbor', function() {
return {
restrict: 'A',
controller: ["$scope", "$parse", function($scope, $parse) {
return {
init: function(attrs) {
var keepWatching, unwatch;
this.attrs = attrs;
this.watchers = [];
keepWatching = !!attrs.allowChange;
return unwatch = $scope.$watch(attrs.image, (function(_this) {
return function(image) {
if (_.isEmpty(image)) {
return;
}
if (!keepWatching) {
unwatch();
}
_this.originalUrl = $parse(attrs.image + ".url")($scope);
_this.signingKey = $parse(attrs.image + ".signing_key")($scope);
_this.distributionUrl = $parse(attrs.image + ".distribution_url")($scope);
return _.each(_this.callbacks, function(cb) {
return cb();
});
};
})(this));
},
registerListener: function(cb) {
this.callbacks || (this.callbacks = []);
return this.callbacks.push(cb);
},
parseDimensions: function(dimensions) {
return dimensions.split('x');
},
generateUrl: function(width, height, method) {
var call, token;
width || (width = '0');
height || (height = '0');
method = method && (method + "/") || '';
call = "" + method + width + "x" + height + "/" + this.originalUrl;
token = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(call, this.signingKey));
token = token.replace(/\+/g, '-');
token = token.replace(/\//g, '_');
return this.distributionUrl + "/" + token + "/" + call;
}
};
}],
link: function(scope, element, attrs, ctrl) {
return ctrl.init(attrs);
}
};
});
angular.module("mpx-frontend-module-thumbor").directive('thumborImage', function() {
return {
restrict: 'E',
replace: true,
template: "<img></img>",
require: 'thumbor',
link: function(scope, element, attrs, ctrl) {
var onReady;
onReady = function() {
var height, ref1, url, width;
ref1 = ctrl.parseDimensions(attrs.thumborDimensions), width = ref1[0], height = ref1[1];
url = ctrl.generateUrl(width, height, attrs.thumborMethod);
element.attr('src', url);
return element.removeAttr('url signing-key distribution-url');
};
return ctrl.registerListener(onReady);
}
};
});
angular.module("mpx-frontend-module-thumbor").directive('thumborBackground', function() {
return {
restrict: 'A',
require: 'thumbor',
link: function(scope, element, attrs, ctrl) {
var onReady;
onReady = function() {
var height, ref1, url, width;
ref1 = ctrl.parseDimensions(attrs.thumborDimensions), width = ref1[0], height = ref1[1];
url = ctrl.generateUrl(width, height, attrs.thumborMethod);
element.css({
'background-image': "url(" + url + ")"
});
element.css({
'background-size': "contain"
});
element.css({
'background-repeat': "no-repeat"
});
element.css({
'background-position': "center center"
});
return element.removeAttr('url signing-key distribution-url');
};
return ctrl.registerListener(onReady);
}
};
});
angular.module("mpx-frontend-module-thumbor").directive('thumborTooltip', function() {
return {
restrict: 'A',
require: 'thumbor',
link: function(scope, element, attrs, ctrl) {
var onReady;
onReady = function() {
var height, preload, ref1, url, width;
ref1 = ctrl.parseDimensions(attrs.thumborTooltipDimensions), width = ref1[0], height = ref1[1];
url = ctrl.generateUrl(width, height, attrs.thumborTooltipMethod);
preload = new Image();
preload.onload = function() {
return element.tooltip({
placement: 'right',
html: true,
title: "<img width='" + preload.width + "' height='" + preload.height + "' src='" + url + "' />",
template: '<div class="tooltip thumbor-tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
});
};
return preload.src = url;
};
return ctrl.registerListener(onReady);
}
};
});
angular.module('mpx-frontend-module-thumbor').directive('thumborWrapper', function() {
return {
restrict: 'A',
require: ['thumbor', 'thumborWrapper'],
controllerAs: 'thumborWrapper',
controller: angular.noop,
link: function(scope, element, attrs, ctrls) {
var onReady, thumbor, vm;
thumbor = ctrls[0];
vm = ctrls[1];
onReady = function() {
var height, ref, url, width;
ref = thumbor.parseDimensions(attrs.thumborDimensions);
width = ref[0];
height = ref[1];
url = thumbor.generateUrl(width, height, attrs.thumborMethod);
vm._src = url;
return element.removeAttr('url signing-key distribution-url');
};
return thumbor.registerListener(onReady);
}
};
});
}).call(this);