-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyouiestbox.sjs
254 lines (234 loc) · 8.81 KB
/
youiestbox.sjs
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
run the app by adding
<script src='http://dl.dropbox.com/u/1545014/curea/youieststart.js'/></script>
to any page. This file is hosted on drop box and simply points to the other parts of the app hosted on github etc.
*/
var debugging=true;
if (debugging){ var c=require('apollo:debug').console(); };
//require('wibes')};
require("apollo:jquery-binding").install();
loadjscssfile("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/smoothness/jquery-ui.css", "css");
//https://github.com/furf/jquery-ui-touch-punch/blob/master/jquery.ui.touch-punch.min.js
require('apollo:http').script("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js");
if(navigator.userAgent.match(/iPad/i) !== null || navigator.userAgent.match(/android/i) !== null ){require('github:furf/jquery-ui-touch-punch/master/jquery.ui.touch-punch.min.js')};
// trouble on android, run touch library on ipad only for now. ipad\|android
//require('github:furf/jquery-ui-touch-punch/master/jquery.ui.touch-punch.min.js')
loadjscssfile("http://dl.dropbox.com/u/1545014/curea/fatc.css", "css") ;
var common = require("apollo:common");
var http = require("apollo:http");
if ($('#youiest').attr('twitter_user')){var twitter_user=$('#youiest').attr('twitter_user')}
else{var twitter_user='wiber'};
var you = require('apollo:twitter').get(twitter_user);
var lastID=you[you.length-1].id;
log('lastID'+lastID);
var cyclespeed=10;
var voter=333;
var howmany =3;
var votehash = new Array;
var wibes = new Array;
var connections= new Array;
var youtrix = new Array;
var shown= new Array;
function popsimple(tweetstack){
if (!tweetstack.length || howmany==0){
log('no length');
$('.tweet_wrapper').dialog('destroy');
alert('Thanks! Log in for more.');
//showTweet(tweetstack.shift(),false);
//tweetstack = replenish();
//require('apollo:twitter').get(twitter_user);
return tweetstack;
}
else {
var toPop=tweetstack.shift();
shown[toPop.id]=toPop;
showTweet(toPop,false);
howmany-= 1;
log("tweetstack.length"+tweetstack.length+"howmany"+howmany)
return tweetstack;
}
;
};
function start(){
log(you);
popsimple(you);
};
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
function loadjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", filename);
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", filename);
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref);
}
function log(tobelogged){
if (debugging){
c.log(arguments);
//c.log(arguments.constructor);
//c.log(arguments.toString());
//c.log(arguments.callee);
c.log(arguments.callee.caller);
//c.dir(arguments);
(function(){
console.dir(arguments);
})(tobelogged)
c.log(tobelogged);
};
};
function showTweet(tweet, append) {
shown.push(tweet);
var date = new Date(tweet.created_at.replace(/^\w+ (\w+) (\d+) ([\d:]+) \+0000 (\d+)$/,
"$1 $2 $4 $3 UTC"));
var elapsed = Math.round(((new Date()).getTime() - date.getTime()) / 60000);
if (elapsed < 60) {
var date_string = elapsed + " minutes";
}
else if (elapsed < 60*24) {
var date_string = Math.round(elapsed / 60) + " hours";
}
else {
var date_string = date.getDate() + "/" + date.getMonth();
}
if (tweet.entities && tweet.entities.urls) {
for (var i = tweet.entities.urls.length - 1, entity; entity = tweet.entities.urls[i]; --i) {
tweet.text = common.supplant("{a}<a target='_blank' href='{b}'>{b}</a>{c}", {
a: tweet.text.substring(0, entity.indices[0]),
b: entity.url,
c: tweet.text.substring(entity.indices[1])
});
}
}
// Construct the html for the tweet. Note how we can use
// multiline strings in StratifiedJS. We also use the
// 'supplant' function from the 'common' module for getting
// values into our string:
// calls append or prepend function of dom elelment, if..? it it doesn't have append, do prepend. (ie if it has no len
$("body")[append ? "append" : "prepend"](common.supplant("\
</div>
<div class='timeline_item user_{screenname}'>
<div class='tweet_wrapper' tweetid='{tweetid}' id='{tweetid}'>
<span class='tweet_thumb'>
<img src='{image}' width='48' height='48' style='float: left;'/>
</span>
<span class='tweet_body'>
<span class='screenname'>{screenname}</span>
<span class='content'>{text}</span>
<span class='meta'>{meta}</span>
</span>
</div>
</div>
", {
tweetid: tweet.id,
text: tweet.text,
image: tweet.user.profile_image_url,
screenname: tweet.user.screen_name,
meta: date_string
})
);
wibes[tweet.id]=tweet;
//log(wibes);
$( "#"+tweet.id ).dialog({
title:tweet.user.screen_name+" - "+date_string +' [ DRAG ME! ]',
position: ['right','middle'],
autoOpen:true,
dialogClass: 'wibe',
width:500,
dragStart:function(event, ui) {
dragging=true;
$('.tweet_box').dialog('close');
$(this).parent().removeClass('snapmoved');
},
open: function(event, ui) {
$(this).parent().css("opacity","1");
hold(1.6*cyclespeed*1000); //stack them at the top instead of where new spawn
if(!$(this).parent().hasClass('moved')){
$(this).dialog('option', 'position', ['right','top']);
$(this).parent().addClass('snapmoved');
}
},
dragStop:function(event, ui) {
var dragging=false;
$(this).parent().css("opacity","1");
var voteint=parseInt($(this).dialog( "option", "title" )[29]);
postNodester($(this).attr('id'),voteint);
var thisID=$(this).attr('tweetid');
tweet.connectionsIN=new Array;
//if(!votehash[thisID]){log('not in hash, creating')}
//if(!wibes[thisID].connectionsIN[voter]){log('not in wibes')};
//votehash[thisID]=voteint
//tweet.vote=[voter,voteint]; //we want hash
tweet.connectionsIN[voter]=[voteint];
wibes[thisID]=tweet
//wibes[thisID,tweet]=voteint
// post wibes to server as they happen, if server responds with low load condition, else wait till done and do all at once, with twitter user object as well
//log(wibes); log(wibes.length);
//log(wibes[thisID].connectionsIN[voter]);
connections[voter+'.'+thisID]=voteint; //works!
//log (connections); log('<<connections')
/*
var dual = new Array; dual=[voter,thisID];
var matrix = new Array;
matrix[dual]=voteint;
log (matrix); log(matrix[voter,thisID]); */
youtrix[parseFloat(voter+'.'+thisID)]=voteint;
log(youtrix);
log(youtrix.sort()+'sorted');
//log(parseFloat(voter+'.'+thisID)-10); //works..
// log(votehash);
//for (key in youtrix){log(key.split('.'))} log('split keys <<');
if (!(voteint>1)) {
$(this).dialog('destroy');
}
if(!$(this).parent().hasClass('moved')){
$(this).parent().addClass('moved');
you=popsimple(you)
};
},
drag:function(event, ui) {
var scrolled = $(document).scrollTop()
var window=winH//.84*winH//$(window).height()
var dragposition = ui.offset.top
percentage = 1000+Math.round(Math.max(Math.min(100*( ( (window-1.2*(dragposition-scrolled))/(window) )),99),0),2) ;
var bigdigit= "<span style='font-size:32px'>"+percentage.toString()[2]+"</span>" ;// explains the link between 0-9 vote and percentages/percentiles..
$("#"+tweet.id ).dialog('option', 'title', bigdigit+""+percentage.toString()[3]+"%" );
$(this).parent().css("opacity",Math.abs(1.4*(percentage-1000)/100-0.07)+.05);
dragging=true;
},
close:function(event,ui){
$('.moved').dialog('destroy');
}
});
$('.wibe').css({position:"fixed"});
return true;
}
function postNodester (droppedTweetId,vote){
//log(droppedTweetId+' '+vote+' '+shown[droppedTweetId]+' to send, >> a tweet?');
log(shown[droppedTweetId]);
var response = http.post("http://youiestthumb.nodester.com/upload", droppedTweetId);
log(response)
//log("server replied: "+ response);
//showTweet(response);
}
start();