-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfarfesh.js
116 lines (105 loc) · 3.49 KB
/
farfesh.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
Stories = new Mongo.Collection("Stories");
Router.route('/', function () {
this.render('main');
});
Router.route('/post', function () {
this.render('post');
});
if (Meteor.isClient) {
Meteor.startup(function() {
$('body').attr('align', 'right');
});
Template.main.helpers({
stories: function () {
return Stories.find({}, {sort: {createdAt: -1}});
}
/*count_faces: function () {
for (var i; i < votes.length; i++) {
if (votes[i].faceType == "face1value") {
face1value++;
} else if (votes[i].faceType == "face2value") {
face2value++;
} else if (votes[i].faceType == "face3value") {
face3value++;
} else if (votes[i].faceType == "face4value") {
face4value++;
}
}
},*/
});
Template.main.events({
'click .face': function(event){
var face=event.target.value;
}
});
Template.story.events({
'click .face':function(event){
var value = $(event.target).attr("value");
if(value == "face1")
{
Stories.update(this._id,{$inc:{"face1value":1}});
}
else if(value == "face2")
{
Stories.update(this._id,{$inc:{"face2value":1}});
}
else if(value == "face3")
{
Stories.update(this._id,{$inc:{"face3value":1}});
}
else if(value == "face4")
{
Stories.update(this._id,{$inc:{"face4value":1}});
}
}
});
Template.post.rendered = function() {
$('select').material_select();
};
Template.main.rendered = function() {
$('.button-collapse').sideNav({
menuWidth: 400, // Default is 240
edge: 'left', // Choose the horizontal origin
closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor
}
);
};
Template.post.events({
'submit .newStory' : function(event) {
event.preventDefault();
var story = event.target.storyText.value;
var age = event.target.age.value;
var language = event.target.languageType.value;
var timeSince = new Date();
var ipAddress = function () {
if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", "http://api.hostip.info/get_html.php", false);
xmlhttp.send();
hostipInfo = xmlhttp.responseText.split("\n");
for (var i = 0; hostipInfo.length >= i; i++) {
var ipAdd = hostipInfo[i].split(":");
if (ipAdd[0] == "IP") return ipAddress[1];
}
};
Stories.insert({
storyText: story,
ipAddress: ipAddress,
age: age,
language: language,
createdAt: new Date(),
country: "UAE",
face1value:0,
face2value:0,
face3value:0,
face4value:0
});
Router.go('/');
}
})
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}