This repository has been archived by the owner on May 14, 2020. It is now read-only.
/
share.js
44 lines (44 loc) · 1.82 KB
/
share.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
/*jslint browser: true*/
window.jQuery(function ($) {
'use strict';
var url = 'https://www.missionbit.com/donate/',
encodedURL = encodeURIComponent(url),
title = encodeURIComponent('Free coding classes for SF public school students by @missionbit – '),
buttons = $.makeArray($('.actions button').data('clicked', 0)),
$percent = $('.progress .progress-bar'),
$number = $('.progress .number');
function clickFold(acc, el) {
return acc + $(el).data('clicked');
}
function popup(url) {
var w = 580,
h = 300,
left = (screen.width - w) / 2,
top = (screen.height - h) / 2,
opts = ['toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, copyhistory=0',
', width=', w,
', height=', h,
', top=', top,
', left=', left].join('');
window.open(url, '', opts);
}
$('.actions button').on('click', function buttonClick(event) {
event.preventDefault();
$(this).data('clicked', 1).blur();
var clicks = buttons.reduce(clickFold, 0),
percent = Math.min(100, Math.round(100 * (clicks / buttons.length)));
$percent.width(percent + '%').attr('area-valuenow', percent);
$number.text(percent + '%');
});
$('.actions button.facebook').on('click', function fbClick(event) {
popup('https://www.facebook.com/share.php?u=' + encodedURL);
});
$('.actions button.twitter').on('click', function twitterClick(event) {
popup(['https://twitter.com/share',
'?text=', title,
'&url=', encodedURL].join(''));
});
$('.actions button.play').on('click', function playClick(event) {
window.location.href = url;
});
});