]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Mapstraction/usermap.js
Merge remote-tracking branch 'upstream/master' into social-master
[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 getNoticeFromElement(noticeElement)
32 {
33     var notice = {};
34
35     if(noticeElement.find(".geo").length) {
36         var latlon = noticeElement.find(".geo").attr('title').split(";");
37         notice['geo']={'coordinates': [
38             parseFloat(latlon[0]),
39             parseFloat(latlon[1])] };
40     }
41
42     notice['html'] = noticeElement.find(".e-content").html();
43     notice['url'] = noticeElement.find("a.timestamp").attr('href');
44     notice['created_at'] = noticeElement.find("abbr.published").text();
45
46     return notice;
47 }
48
49 function getUserFromElement(noticeElement)
50 {
51      var avatarURL = noticeElement.find("img.avatar").attr('src');
52      var profileURL = noticeElement.find(".author a.url").attr('href');
53      var nickname =  noticeElement.find(".author .nickname").text();
54
55      return {
56           'profile_image_url': avatarURL,
57           'profile_url': profileURL,
58           'screen_name': nickname
59     };
60 }
61
62 function showMapstraction(element, notices) {
63      if(element instanceof jQuery) element = element[0];
64      if(! $.isArray(notices)) notices = [notices];
65      var mapstraction = new mxn.Mapstraction(element, _provider);
66
67      var minLat = 181.0;
68      var maxLat = -181.0;
69      var minLon = 181.0;
70      var maxLon = -181.0;
71
72      for (var i in notices)
73      {
74           var n = notices[i];
75
76           var lat = n['geo']['coordinates'][0];
77           var lon = n['geo']['coordinates'][1];
78
79           if (lat < minLat) {
80                minLat = lat;
81           }
82
83           if (lat > maxLat) {
84                maxLat = lat;
85           }
86
87           if (lon < minLon) {
88                minLon = lon;
89           }
90
91           if (lon > maxLon) {
92                maxLon = lon;
93           }
94
95           pt = new mxn.LatLonPoint(lat, lon);
96           mkr = new mxn.Marker(pt);
97
98           mkr.setIcon(n['user']['profile_image_url'], [24, 24]);
99           mkr.setInfoBubble('<a href="'+ n['user']['profile_url'] + '">' + n['user']['screen_name'] + '</a>' + ' ' + n['html'] +
100                             '<br/><a href="'+ n['url'] + '">'+ n['created_at'] + '</a>');
101
102           mapstraction.addMarker(mkr);
103      }
104
105      bounds = new mxn.BoundingBox(minLat, minLon, maxLat, maxLon);
106
107      mapstraction.setBounds(bounds);
108 }