-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaved_search.js
205 lines (176 loc) · 4.61 KB
/
saved_search.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
198
199
200
201
202
203
204
users_searches = function()
{
}
users_searches.prototype =
{
get searches ()
{
if (!("_searches" in this))
this._searches = [];
return this._searches;
},
set searches ( x )
{
this._searches = x;
},
}
saved_search = function()
{
}
saved_search.prototype =
{
get saved_serch_id ()
{
if (!("_saved_serch_id" in this))
this._saved_serch_id = "";
return this._saved_serch_id;
},
set saved_serch_id ( x )
{
this._saved_serch_id = x;
},
get name ()
{
if (!("_name" in this))
this._name = "";
return this._name;
},
set name ( x )
{
this._name = x;
},
get query ()
{
if (!("_query" in this))
this._query = "";
return this._query;
},
set query ( x )
{
this._query = x;
},
get position ()
{
if (!("_position" in this))
this._position = "";
return this._position;
},
set position ( x )
{
this._position = x;
},
get created_at ()
{
if (!("_created_at" in this))
this._created_at = "";
return this._created_at;
},
set created_at ( x )
{
this._created_at = x;
},
}
get_saved_search = function()
{
eval( "saved_search=function(data){retreveSavedSearch(data);delete this;}" );
mbtweetOAuth.callAPI( "https://api.twitter.com/1/saved_searches.json" ,
"GET",
[
["callback" , "saved_search" ]
],
{ retry : true , auth : true }
);
}
retreveSavedSearch = function( data )
{
var new_users_search = new users_searches();
for( var i = 0 ; i < data.length ; i++ )
{
var searches_data = data[i];
var new_search = new list();
new_search.saved_serch_id = searches_data.id;
new_search.name = searches_data.name;
new_search.query = searches_data.query;
new_search.position = searches_data.position;
new_search.created_at = searches_data.created_at;
new_users_search.searches.push( new_search );
}
var search_menu = create_search_menu( new_users_search );
document.querySelector("#my_saved_search").insertBefore( search_menu , document.querySelector("#my_saved_search").firstChild );
}
create_search_menu = function( new_users_search )
{
var searches = new_users_search.searches;
var menu_wrapper = document.createElement("DIV");
menu_wrapper.className = "dock-menu";
menu_wrapper.id = "saved_search";
for( var i = 0 ; i < searches.length ; i++ )
{
menu_wrapper.appendChild( search_index( searches[i] ) );
}
return( menu_wrapper );
}
search_index = function( search )
{
var search_index = document.createElement("DIV");
search_index.className = "dock-menu-index";
search_index.id = "search_index_" + search.saved_search_id;
var search_anchor = document.createElement("A");
search_anchor.href = "http://twitter.com/" + search.query;
search_anchor.innerText = search.name;
if( search.name.length > 20 )
{
search_anchor.innerText = search.name.replace(/^(.{1,20}).*/ , "$1...");
}
search_anchor.target = "_blank";
search_anchor.mysearch = search;
search_anchor.addEventListener( "click" ,
function( event )
{
event.stopPropagation();
event.preventDefault();
var search_index = event.target;
if( !event.target.mysearch )
{
search_index = event.target.parentNode;
}
if( !event.shiftKey ) // Shift click openes Twitter Website
{
new_search_timeline( search_index.mysearch.query );
}
else
{
new_search_timeline( search_index.mysearch.query , mbtweet.user.language );
}
addClass( search_index , "active" );
setTimeout( function()
{
removeClass( search_index , "active" );
}, 500);
},
false );
if( mbtweet.user.country != "" )
{
var language_flag = document.createElement("IMG");
language_flag.className = "flag";
language_flag.src = "images/flags/" + mbtweet.user.country + ".gif";
language_flag.addEventListener( "click" ,
function( event )
{
event.stopPropagation();
event.preventDefault();
var search_index = event.target;
search_index = event.target.parentNode;
new_search_timeline( search_index.mysearch.query , mbtweet.user.language );
addClass( search_index , "active" );
setTimeout( function()
{
removeClass( search_index , "active" );
}, 500);
},
false );
search_anchor.appendChild( language_flag );
}
search_index.appendChild( search_anchor );
return( search_index );
}