]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Mapstraction/usermap.js
Explictly unbinding is unnecessary as jQuery's remove() takes care of it
[quix0rs-gnu-social.git] / plugins / Mapstraction / usermap.js
1 $(document).ready(function() {
2      var notices = [];
3      $(".notice").each(function(){
4         var notice = getNoticeFromElement($(this));
5         if(notice['geo'])
6             notices.push(notice);
7      });
8      if($("#map_canvas").length && notices.length>0)
9      {
10         showMapstraction($("#map_canvas"), notices);
11      }
12
13      $('.geo').click(function(){
14         var noticeElement = $(this).closest(".notice");
15         notice = getNoticeFromElement(noticeElement);
16
17         $.fn.jOverlay.options = {
18             color : '#000',
19             opacity : '0.6',
20             zIndex : 99,
21             center : false,
22             bgClickToClose : true,
23             autoHide : true,
24             css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
25         };
26         var html="<div id='map_canvas_popup' class='gray smallmap' style='width: 542px; height: 500px' />";
27         html+="<button class='close'>&#215;</button>";
28         html+=$("<div/>").append($(this).clone()).html();
29         $().jOverlay({ "html": html });
30         $('#jOverlayContent').show();
31         $('#jOverlayContent button').click($.closeOverlay);
32         
33         showMapstraction($("#map_canvas_popup"), notice);
34
35         return false;
36      });
37 });
38
39 function getMicroformatValue(element)
40 {
41     if(element[0].tagName.toLowerCase() == 'abbr'){
42         return element.attr('title');
43     }else{
44         return element.text();
45     }
46 }
47
48 function getNoticeFromElement(noticeElement)
49 {
50     var notice = {};
51     if(noticeElement.find(".geo").length){
52         var latlon = noticeElement.find(".geo").attr('title').split(";");
53         notice['geo']={'coordinates': [
54             parseFloat(latlon[0]),
55             parseFloat(latlon[1])] };
56     }
57     notice['user']={
58         'profile_image_url': noticeElement.find("img.avatar").attr('src'),
59         'profile_url': noticeElement.find(".author a.url").attr('href'),
60         'screen_name': noticeElement.find(".author .nickname").text()
61     };
62     notice['html']=noticeElement.find(".entry-content").html();
63     notice['url']=noticeElement.find("a.timestamp").attr('href');
64     notice['created_at']=noticeElement.find("abbr.published").text();
65     return notice;
66 }
67
68 function showMapstraction(element, notices) {
69      if(element instanceof jQuery) element = element[0];
70      if(! $.isArray(notices)) notices = [notices];
71      var mapstraction = new mxn.Mapstraction(element, _provider);
72
73      var minLat = 181.0;
74      var maxLat = -181.0;
75      var minLon = 181.0;
76      var maxLon = -181.0;
77
78      for (var i in notices)
79      {
80           var n = notices[i];
81
82           var lat = n['geo']['coordinates'][0];
83           var lon = n['geo']['coordinates'][1];
84
85           if (lat < minLat) {
86                minLat = lat;
87           }
88
89           if (lat > maxLat) {
90                maxLat = lat;
91           }
92
93           if (lon < minLon) {
94                minLon = lon;
95           }
96
97           if (lon > maxLon) {
98                maxLon = lon;
99           }
100
101           pt = new mxn.LatLonPoint(lat, lon);
102           mkr = new mxn.Marker(pt);
103
104           mkr.setIcon(n['user']['profile_image_url']);
105           mkr.setInfoBubble('<a href="'+ n['user']['profile_url'] + '">' + n['user']['screen_name'] + '</a>' + ' ' + n['html'] +
106                             '<br/><a href="'+ n['url'] + '">'+ n['created_at'] + '</a>');
107
108           mapstraction.addMarker(mkr);
109      }
110
111      bounds = new mxn.BoundingBox(minLat, minLon, maxLat, maxLon);
112
113      mapstraction.setBounds(bounds);
114 }