]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Mapstraction/usermap.js
Localisation updates from http://translatewiki.net.
[quix0rs-gnu-social.git] / plugins / Mapstraction / usermap.js
1 function scrapeNotices(user)
2 {
3      var notices = [];
4      $(".notice").each(function(){
5           var notice = getNoticeFromElement($(this));
6           if (user) {
7                notice['user'] = user;
8           } else {
9                notice['user'] = getUserFromElement($(this));
10           }
11           if(notice['geo'])
12                notices.push(notice);
13      });
14
15      return notices;
16 }
17
18 function scrapeUser()
19 {
20      var avatarURL = $(".entity_profile .entity_depiction img.avatar").attr('src');
21      var profileURL = $(".entity_profile .entity_nickname .url").attr('href');
22      var nickname = $(".entity_profile .entity_nickname .nickname").text();
23
24      return {
25         'profile_image_url': avatarURL,
26         'profile_url': profileURL,
27         'screen_name': nickname
28      };
29 }
30
31 function getMicroformatValue(element)
32 {
33     if(element[0].tagName.toLowerCase() == 'abbr'){
34         return element.attr('title');
35     }else{
36         return element.text();
37     }
38 }
39
40 function getNoticeFromElement(noticeElement)
41 {
42     var notice = {};
43
44     if(noticeElement.find(".geo").length) {
45         var latlon = noticeElement.find(".geo").attr('title').split(";");
46         notice['geo']={'coordinates': [
47             parseFloat(latlon[0]),
48             parseFloat(latlon[1])] };
49     }
50
51     notice['html'] = noticeElement.find(".entry-content").html();
52     notice['url'] = noticeElement.find("a.timestamp").attr('href');
53     notice['created_at'] = noticeElement.find("abbr.published").text();
54
55     return notice;
56 }
57
58 function getUserFromElement(noticeElement)
59 {
60      var avatarURL = noticeElement.find("img.avatar").attr('src');
61      var profileURL = noticeElement.find(".author a.url").attr('href');
62      var nickname =  noticeElement.find(".author .nickname").text();
63
64      return {
65           'profile_image_url': avatarURL,
66           'profile_url': profileURL,
67           'screen_name': nickname
68     };
69 }
70
71 function showMapstraction(element, notices) {
72      if(element instanceof jQuery) element = element[0];
73      if(! $.isArray(notices)) notices = [notices];
74      var mapstraction = new mxn.Mapstraction(element, _provider);
75
76      var minLat = 181.0;
77      var maxLat = -181.0;
78      var minLon = 181.0;
79      var maxLon = -181.0;
80
81      for (var i in notices)
82      {
83           var n = notices[i];
84
85           var lat = n['geo']['coordinates'][0];
86           var lon = n['geo']['coordinates'][1];
87
88           if (lat < minLat) {
89                minLat = lat;
90           }
91
92           if (lat > maxLat) {
93                maxLat = lat;
94           }
95
96           if (lon < minLon) {
97                minLon = lon;
98           }
99
100           if (lon > maxLon) {
101                maxLon = lon;
102           }
103
104           pt = new mxn.LatLonPoint(lat, lon);
105           mkr = new mxn.Marker(pt);
106
107           mkr.setIcon(n['user']['profile_image_url'], [24, 24]);
108           mkr.setInfoBubble('<a href="'+ n['user']['profile_url'] + '">' + n['user']['screen_name'] + '</a>' + ' ' + n['html'] +
109                             '<br/><a href="'+ n['url'] + '">'+ n['created_at'] + '</a>');
110
111           mapstraction.addMarker(mkr);
112      }
113
114      bounds = new mxn.BoundingBox(minLat, minLon, maxLat, maxLon);
115
116      mapstraction.setBounds(bounds);
117 }