Skip to content

Commit e904e84

Browse files
committed
rewrite meetup widget as module and add new chapters
1 parent 58f2544 commit e904e84

File tree

3 files changed

+96
-50
lines changed

3 files changed

+96
-50
lines changed

www/_assets/images/pyladies_pdx.jpeg

-101 KB
Binary file not shown.

www/_assets/js/meetup_widget.js

+89-46
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,94 @@
1-
///Asks Meetup.com for any public event listing from one of the PyLadies chapters upcoming in the next week
2-
//Localized for use by any chapter--just copy file over to your location site and sub your meetup key for "meetup_key" and meetup group id (indicated as data id on locations index.html page) for "chapter_ids" in addUpcomingMeetups function.
3-
4-
//helper functions
5-
function create_urls(input) {
6-
return input
7-
.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '"$&" target="_blank"')
8-
.replace(/([^\/])(www[\S]+(\b|$))/gim, '"http://$2" target="_blank"');
9-
} //end url parsing helper
10-
11-
function convert_time_miliseconds_to_date(t) {
12-
var d = new Date(t); // The 0 there is the key, which sets the date to the epoch
13-
return String(d).slice(0, 11);
14-
} //end convert miliseconds_to_date
15-
16-
// functions
17-
function addUpcomingMeetups(chapter_ids) {
18-
var meetup_key = '70704f53354b686770246f68494e2637';
19-
20-
$.ajax( {
21-
url: 'http://api.meetup.com/2/events.json?key='+meetup_key+'&group_id='+chapter_ids+'&fields=group_photo&time=0m,1m&status=upcoming&sign=true',
22-
dataType: 'jsonp',
23-
success: function(data) {
24-
buildHtml(data);
25-
}, //end success
26-
error: function(data) {
27-
handleError(data);
28-
} //end error
29-
}); //end .ajax()
30-
return false;
31-
} //end addUpcomingMeetups function
32-
33-
function buildHtml(data) {
1+
/* Note: Updated to reflect JS Module pattern for encapsulation (v2)
2+
* To call: PyladiesMeetupWidget.addUpcomingMeetups(chapterIds)
3+
* Requests location meetups from Meetup.com coming up in the next month
4+
* and uses data to construct html entries for each event that are appended
5+
* to an '#upcomingMeetupsList' div in page's html.
6+
* Can be given any number of chapterIds.
7+
*/
8+
9+
var PyladiesMeetupWidget = (function() {
10+
var key = '70704f53354b686770246f68494e2637';
11+
12+
// Private methods //
13+
14+
_createUrls = function(url) {
15+
// creates <a href> links from urls for event clickthroughs
16+
return url
17+
.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '"$&" target="_blank"')
18+
.replace(/([^\/])(www[\S]+(\b|$))/gim, '"http://$2" target="_blank"');
19+
};
20+
21+
_convertMilisecondsToDate = function(ms) {
22+
// converts miliseconds since epoch to date format
23+
var date = new Date(ms);
24+
return String(date).slice(0, 11);
25+
};
26+
27+
_makeAjaxRequest = function(ids) {
28+
// fetch data
29+
$.ajax({
30+
url: 'http://api.meetup.com/2/events.json?key=' + key + '&group_id=' + ids +
31+
'&fields=group_photo&time=0m,1m&status=upcoming&sign=true',
32+
dataType: 'jsonp',
33+
success: function(data) {
34+
_buildHtml(data);
35+
},
36+
error: function(data) {
37+
_handleError(data);
38+
}
39+
});
40+
};
41+
42+
_getJSON = function(datum) {
43+
// {_buildHtml helper}
44+
// note: Not every meetup group event request returns a photo--not sure why, but
45+
// noticed that neither Taiwan or Bangalore's logos returned, so perhaps there
46+
// is some difference in data offered in parts of Asia?
47+
var json = {
48+
thumbLink: datum.group.group_photo ? datum.group.group_photo.thumb_link : "",
49+
groupName: datum.group.name,
50+
eventLink: _createUrls(datum.event_url),
51+
eventName: datum.name,
52+
eventDate: _convertMilisecondsToDate(datum.time)
53+
};
54+
55+
return json;
56+
};
57+
58+
_buildHtml = function(data) {
59+
var html;
60+
var datum;
61+
var json;
62+
63+
// remove any old meetup list still attached to dom and append new $ul
3464
$('#upcomingMeetupsList ul').remove();
3565
$('#upcomingMeetupsList').append('<ul></ul>');
36-
for (var key in data.results) {
37-
url_link = create_urls(data.results[key].event_url);
38-
event_date = convert_time_miliseconds_to_date(data.results[key].time);
39-
var html = '<img class="meetup_group_icon" src="'+data.results[key].group.group_photo.thumb_link+'" height="80" width="80" />';
40-
html += '<p class="meetup_listing_group">'+data.results[key].group.name+'</p>';
41-
html += '<p class="meetup_listing_event_title"><a href='+url_link+'>'+data.results[key].name+'</a></p>';
42-
html += '<p class="meetup_event_date">'+event_date+'</p>';
43-
$('#upcomingMeetupsList').find('ul').append('<li>'+html+'</li>');
66+
67+
for (var i = 0; i < data.results.length; i++) {
68+
datum = data.results[i];
69+
json = _getJSON(datum);
70+
71+
// todo(fw): pull this out into a template
72+
html = '<img class="meetup_group_icon" src="' + json.thumbLink + '" height="80" width="80" />';
73+
html += '<p class="meetup_listing_group">' + json.groupName + '</p>';
74+
html += '<p class="meetup_listing_event_title"><a href=' + json.eventLink + '>' + json.eventName + '</a></p>';
75+
html += '<p class="meetup_event_date">' + json.eventDate + '</p>';
76+
77+
$('#upcomingMeetupsList ul').append('<li>' + html + '</li>');
4478
}
45-
}
79+
};
4680

47-
function handleError(data) {
81+
_handleError = function(data) {
82+
// remove any stale list attached to dom and print error message
4883
$('#upcomingMeetupsList ul').remove();
49-
$('#upcomingMeetupsList').append('<ul></ul>');
50-
$('#upcomingMeetupsList').find('ul').append('<li>Sorry, we are unable to reach Meetup.com at this time</li>');
51-
}
84+
$('#upcomingMeetupsList')
85+
.append('<ul><li>Sorry, we are unable to reach Meetup.com at this time</li></ul>');
86+
};
87+
88+
return {
89+
// returns public method
90+
addUpcomingMeetups: function(chapterIds) {
91+
_makeAjaxRequest(chapterIds);
92+
}
93+
};
94+
})();

www/_templates/site.html

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
<script type="text/javascript" src="{{ get_asset('js/meetup_widget.js') }}"></script>
1818
<script type="text/javascript">
1919
$(document).ready(function() {
20-
// meetup group_ids in order: portland, san francisco, la, nyc, dc, atlanta, seattle, austin, brno/cz, san diego, toronto, vienna, stockholm
21-
var chapter_ids = '4808882,3604052,2288171,4576312,2292131,4507652,5411282,5947662,5160912,5089102,6488102,7538042,7660062,8160762';
22-
addUpcomingMeetups(chapter_ids);
23-
});//end doc.ready
20+
// meetup group_ids in order: portland, san francisco, la, nyc, dc, atlanta, seattle,
21+
// austin, brno/cz, san diego, toronto, vienna, stockholm, amsterdam, bangalore,
22+
// berlin, boston, charleston, helsinki, india, montreal, salt lake city, seoul, taiwan,
23+
// london, dublin, ann arbor, barcelona, san antonio
24+
var meetupIds = '4808882,3604052,2288171,4576312,2292131,4507652,5411282,5947662,5160912,5089102,6488102,7538042,7660062,8160762,9301202,9206152,8623152,8401402,13995752,9042722,14872062,8161032,10708842,14748112,13106102,13320732,10841992,10496402,12994802,14129372';
25+
PyladiesMeetupWidget.addUpcomingMeetups(meetupIds);
26+
});
2427
</script>
2528
{% endblock %}
2629
{% block style %}

0 commit comments

Comments
 (0)