-
Notifications
You must be signed in to change notification settings - Fork 2
/
doingthiswith.js
98 lines (86 loc) · 2.58 KB
/
doingthiswith.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
if (Meteor.isClient) {
var navbarActive = function(path) {
$('.navbar-nav li.active').removeClass('active');
$('.navbar-nav a[href="'+path+'"]').parent().addClass('active');
}
Router.configure({
layoutTemplate: 'layout',
onAfterAction: function() {
navbarActive(this.path);
},
onStop: function() {
if (this.handles)
for (key in this.handles) {
console.log('stop ' + key);
this.handles[key].stop();
}
}
});
UI.registerHelper('xEditableUpdate', function(selector, value) {
var el = $(selector);
var data = el.data();
// .editable() hasn't been run yet
if (!data || !data.editable)
return value;
console.log('data');
// this is used the first time the popup is opened
data.editable.value = value;
// this is used for all consequent lookups
if (data.editableContainer)
data.editableContainer.formOptions.value = value;
// since return value isn't used anymore
el.text(value);
// not actually used; innerText from x-editable breaks reactivity
return value;
});
Router.hooks.loginFirst = function(pause) {
if (!Meteor.userId()) {
this.render('loginFirst');
pause();
}
}
UI.registerHelper('userId', function() {
return this.userId || Meteor.userId();
});
UI.registerHelper('notLoggedIn', function() {
return !Meteor.userId();
});
UI.registerHelper('username', function(userId) {
var user = userId ? Meteor.users.findOne(userId) : Meteor.user();
return user && user.profile && user.profile.name;
});
UI.registerHelper('ownedByUser', function() {
return this.userId == Meteor.userId();
});
UI.registerHelper('itsMe', function() {
return this._id == Meteor.userId();
});
// temporary while we use autopublish
var allSubscriptionsReadyDep = new Deps.Dependency;
var allSubscriptionsReadyValue = false;
var allSubscriptionsReady = function() {
allSubscriptionsReadyDep.depend();
return allSubscriptionsReadyValue;
}
var allSubscriptionsReadyHandle = Meteor.setInterval(function() {
var current = DDP._allSubscriptionsReady();
if (allSubscriptionsReadyValue != current) {
allSubscriptionsReadyValue = current;
allSubscriptionsReadyDep.changed();
Meteor.clearInterval(allSubscriptionsReadyHandle);
}
}, 50);
Router.onBeforeAction(function(pause) {
if (!allSubscriptionsReady()) {
this.render('loading');
pause();
}
});
}
if (Meteor.isServer) {
AccountsExtra.init({
saveCreatedAt: true,
saveProfilePic: true,
saveServiceUsername: true
});
}