-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare-overlay.js
72 lines (59 loc) · 1.71 KB
/
share-overlay.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
var TWEETING_KEY = 'shareOverlayTweeting';
var IMAGE_KEY = 'shareOverlayAttachedImage';
Template.shareOverlay.onCreated(function() {
Session.set(TWEETING_KEY, true);
Session.set(IMAGE_KEY, null);
});
Template.shareOverlay.helpers({
attachedImage: function() {
return Session.get(IMAGE_KEY);
},
avatar: function() {
return Meteor.user().services.twitter.profile_image_url_https;
},
tweeting: function() {
return Session.get(TWEETING_KEY);
}
});
Template.shareOverlay.events({
'click .js-attach-image': function() {
MeteorCamera.getPicture({width: 320}, function(error, data) {
if (error)
alert(error.reason);
else
Session.set(IMAGE_KEY, data);
});
},
'click .js-unattach-image': function() {
Session.set(IMAGE_KEY, null);
},
'change [name=tweeting]': function(event) {
Session.set(TWEETING_KEY, $(event.target).is(':checked'));
},
'submit': function(event, template) {
var self = this;
event.preventDefault();
var text = $(event.target).find('[name=text]').val();
var tweet = Session.get(TWEETING_KEY);
Meteor.call('createActivity', {
recipeName: self.name,
text: text,
image: Session.get(IMAGE_KEY)
}, tweet, Geolocation.currentLocation(), function(error, result) {
if (error) {
alert(error.reason);
} else {
Template.appBody.addNotification({
action: 'View',
title: 'Your photo was shared.',
callback: function() {
Router.go('recipe', { name: self.name },
{ query: { activityId: result } });
Template.recipe.setTab('feed');
}
});
}
});
Overlay.close();
}
});