-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathexport.js
197 lines (165 loc) · 6.72 KB
/
export.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Avatar object to be exported
Avatar = {
// Default functionality. You can override these options by calling
// Avater.setOptions (do not set Avatar.options directly)
options: {
// Determines the type of fallback to use when no image can be found via
// linked services (Gravatar included):
// "default image" (the default option, which will show either the image
// specified by defaultImageUrl, the package's default image, or a Gravatar
// default image)
// OR
// "initials" (show the user's initials).
fallbackType: '',
// This will replace the included default avatar image's URL
// ('packages/utilities_avatar/default.png'). It can be a relative path
// (relative to website's base URL, e.g. 'images/defaultAvatar.png').
defaultImageUrl: '',
// This property name will be used to fetch an avatar url from the user's profile
// (e.g. 'avatar'). If this property is set and a property of that name exists
// on the user's profile (e.g. user.profile.avatar) that property will be used
// as the avatar url.
customImageProperty: '',
// Gravatar default option to use (overrides default image URL)
// Options are available at:
// https://secure.gravatar.com/site/implement/images/#default-image
gravatarDefault: '',
// This property on the user object will be used for retrieving gravatars
// (useful when user emails are not published).
emailHashProperty: '',
// This property is used to prefix the CSS classes of the DOM elements.
// If no value is set, then the default CSS class assigned to all DOM elements are prefixed with 'avatar' as default.
// If a value is set to, 'foo' for example, the resulting CSS classes are prefixed with 'foo'.
cssClassPrefix: '',
// This property defines the various image sizes available
imageSizes: {
'large': 80,
'small': 30,
'extra-small': 20
},
// Default background color when displaying the initials.
// Can also be set to a function to map an user object to a background color.
backgroundColor: "#aaa",
// Default text color when displaying the initials.
// Can also be set to a function to map an user object to a text color.
textColor: "#fff",
// Generate the required CSS and include it in the head of your application.
// Setting this to false will exclude the generated CSS and leave the
// avatar unstyled by the package.
generateCSS: true
},
// Sets the Avatar options. You must use this setter function rather than assigning directly to
// Avatar.options, otherwise the stylesheet won't be generated.
setOptions: function(options) {
Avatar.options = _.extend(Avatar.options, options);
},
// Returns the cssClassPrefix property from options
getCssClassPrefix: function () {
return (Avatar.options.cssClassPrefix)? Avatar.options.cssClassPrefix: 'avatar';
},
// Returns a background color for initials
getBackgroundColor: function (user) {
if (_.isString(Avatar.options.backgroundColor))
return Avatar.options.backgroundColor;
else if (_.isFunction(Avatar.options.backgroundColor))
return Avatar.options.backgroundColor(user);
},
// Returns a text color for initials
getTextColor: function (user) {
if (_.isString(Avatar.options.textColor))
return Avatar.options.textColor;
else if (_.isFunction(Avatar.options.textColor))
return Avatar.options.textColor(user);
},
// Get the initials of the user
getInitials: function (user) {
var initials = '';
var name = '';
var parts = [];
if (user && user.profile && user.profile.firstName) {
initials = user.profile.firstName.charAt(0).toUpperCase();
if (user.profile.lastName) {
initials += user.profile.lastName.charAt(0).toUpperCase();
}
else if (user.profile.familyName) {
initials += user.profile.familyName.charAt(0).toUpperCase();
}
else if (user.profile.secondName) {
initials += user.profile.secondName.charAt(0).toUpperCase();
}
}
else {
if (user && user.profile && user.profile.name) {
name = user.profile.name;
}
else if (user && user.username) {
name = user.username;
}
parts = name.split(' ');
// Limit getInitials to first and last initial to avoid problems with
// very long multi-part names (e.g. "Jose Manuel Garcia Galvez")
initials = _.first(parts).charAt(0).toUpperCase();
if (parts.length > 1) {
initials += _.last(parts).charAt(0).toUpperCase();
}
}
return initials;
},
// Get the url of the user's avatar
// XXX: Avatar.getUrl is a reactive function only when no user argument is specified.
getUrl: function (user) {
// Default to the currently logged in user, unless otherwise specified.
if (!user) user = Meteor.user()
var url = '';
var defaultUrl, svc;
if (user) {
svc = getService(user);
if (svc === 'twitter') {
// use larger image (200x200 is smallest custom option)
url = user.services.twitter.profile_image_url_https.replace('_normal.', '_200x200.');
}
else if (svc === 'facebook') {
// use larger image (~200x200)
url = 'https://graph.facebook.com/' + user.services.facebook.id + '/picture/?type=large';
}
else if (svc === 'google') {
url = user.services.google.picture;
}
else if (svc === 'github') {
url = 'https://avatars.githubusercontent.com/' + user.services.github.username + '?s=200';
}
else if (svc === 'instagram') {
url = user.services.instagram.profile_picture;
}
else if (svc === 'linkedin') {
url = user.services.linkedin.pictureUrl;
}
else if (svc === "custom") {
url = getCustomUrl(user);
}
else if (svc === 'none') {
defaultUrl = Avatar.options.defaultImageUrl || '/packages/utilities_avatar/default.png';
// If it's a relative path (no '//' anywhere), complete the URL
if (defaultUrl.indexOf('//') === -1) {
// Strip starting slash if it exists
if (defaultUrl.charAt(0) === '/') defaultUrl = defaultUrl.slice(1);
// Then add the relative path to the server's base URL
defaultUrl = Meteor.absoluteUrl() + defaultUrl;
}
url = getGravatarUrl(user, defaultUrl);
}
}
return url;
},
// Create a Gravatar-compatible hash for a given email address
hash: function (email) {
return Gravatar.hash(email);
}
}
// Call createCSS to generate the default CSS depend on the option
Meteor.startup(function () {
if (Avatar.options.generateCSS)
createCSS();
});
// This will be replaced if the user calls setOptions in their own code
Avatar.setOptions({});