-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (67 loc) · 2.04 KB
/
app.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
(function() {
return {
defaultState: 'loading',
requests: {
getGeo: function(ip) {
return {
url: 'http://freegeoip.net/xml/' + ip,
type: 'GET',
dataType: 'xml'
};
},
getIP: function() {
return {
url: 'http://icanhazip.com/',
type: 'GET'
};
}
},
events: {
'app.activated': 'geoipstart',
'getIP.done': function(data) {
console.dir(data);
this.switchTo('iplist', {
ipadr: data.activeElement.childNodes[1].innerHTML.slice(0,data.activeElement.childNodes[1].innerHTML.indexOf(' '))
});
},
'getIP.fail': function(data) {
this.switchTo('getip_fail');
},
'getGeo.done': function(data) {
console.dir(data);
var latitude = data.getElementsByTagName("Latitude")[0].textContent;
var longitude = data.getElementsByTagName("Longitude")[0].textContent;
this.switchTo('geoloc', {
lon: latitude,
lat: longitude
});
},
'getGeo.fail': function() {
this.switchTo('getgeo_fail');
},
'addBookmark.always': function() {
this.ajax('fetchBookmarks');
},
'click .lookup': 'geolocate',
'click a[data-role="reload-bookmarks"]': 'requestBookmarks'
},
geolocate: function(data)
{
console.log('HELLO I AM ALSO A SCRIPT');
console.dir(data);
var temp_data = data;
var the_length = data.target.attributes[3].nodeValue.length;
console.log('Length is: ' + the_length);
var slash_pos = the_length - temp_data.target.attributes[3].nodeValue.split("").reverse().join("").indexOf('/');
console.log('Position of last slash: ' + slash_pos);
var the_ip = data.target.attributes[3].nodeValue.slice(slash_pos, the_length);
console.log('final ip string: ' + the_ip);
this.ajax('getGeo',the_ip);
},
geoipstart: function()
{
console.log('HELLO I AM A SCRIPT');
this.ajax('getIP');
}
};
}());