-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
110 lines (97 loc) · 3.18 KB
/
index.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
var items = [];
var count = 0;
var createDivs = function(){
'use strict';
$(".projects").remove();
if(items['projects'].count > (count+1)*24){
var more = document.getElementById("more");
more.style.visibility = "visible";
}
for(var i = count*24; i < (count+1)*24 && i < items['projects'].count; i++){
if(i % 8 == 0){
var div = document.createElement('div');
div.className = "projects";
document.getElementById("container").appendChild(div);
}
var p = document.createElement('p');
var h1 = document.createElement('h1');
var h2 = document.createElement('h1');
var h3 = document.createElement('h1');
var h4 = document.createElement('h1');
h3.className = "bids";
h4.className = "bids";
h1.className = "sub_projects";
h2.className = "desc";
p.className = "link";
h1.innerHTML = items['projects'].items[i].name;
h2.innerHTML = items['projects'].items[i].short_descr;
h3.innerHTML = "Bids : " + items['projects'].items[i].bid_stats['count'] + " ";
var avg = items['projects'].items[i].bid_stats['avg'] == false ? "N/A" : items['projects'].items[i].bid_stats['avg'];
h4.innerHTML = "Avg bid : " + avg;
var a = document.createElement('a');
a.href = items['projects'].items[i].url;
a.appendChild(h1);
p.appendChild(a);
p.appendChild(h2);
p.appendChild(h3);
p.appendChild(h4);
div.appendChild(p);
}
count++;
if(items['projects'].count < (count*24)){
var more = document.getElementById("more");
more.style.visibility = "hidden";
}
}
var mouseDown = function(){
'use strict';
var search = document.getElementById("search");
search.style['padding'] = "2% 2.5% 2.5% 2.5%";
}
var mouseUp = function(){
'use strict';
var search = document.getElementById("search");
search.style['padding'] = "2.5%";
}
$("#container").ajaxStart(function(){
var div = document.createElement('div');
div.id = "img";
var img = document.createElement('img');
img.src = "ajax-loader.gif";
div.appendChild(img);
document.getElementById("container").appendChild(div);
});
$("#container").ajaxStop(function(){
$('#img').remove();
});
var search = function(){
'use strict';
$('#loading').show();
var keyword = document.getElementById("search_text").value;
var url = "http://api.freelancer.com/Project/Search.json?keyword=" + keyword + "&aff=karthickdoosra&count=100&callback=?";
$.getJSON(url,function(data){
$('#loading').hide();
var string = JSON.stringify(data);
items = JSON.parse(string);
console.log(items);
if(items['projects'].count>0){
createDivs();
}
else{
alert("Sorry your search returned no results");
}
});
}
window.onload = function(){
'use strict';
if(document.getElementById("search").addEventListener){
document.getElementById("search").addEventListener('click',search,false);
document.getElementById("search").addEventListener('mousedown',mouseDown,false);
document.getElementById("search").addEventListener('mouseup',mouseUp,false);
document.getElementById("more").addEventListener('click',createDivs,false);
}
else if(document.getElementById("search").attachEvent){
document.getElementById("search").attachEvent('onclick',search,false);
document.getElementById("more").attachEvent('onclick',createDivs,false);
}
}