diff options
author | Arnaud Bos <arnaud.bos@aeon-consulting.fr> | 2012-10-20 02:52:02 +0200 |
---|---|---|
committer | Arnaud Bos <arnaud.bos@aeon-consulting.fr> | 2012-10-20 02:52:02 +0200 |
commit | 3ffd14fa4da0ca71e1f97a070973e4994bae8f61 (patch) | |
tree | dd7fea1a54417fc5df25eb559870c6ad06019ef1 /syte/static/js/libs/google+.js | |
parent | 01a8792a5116a305368d9d98fa366923086e0633 (diff) | |
download | pelican-themes-3ffd14fa4da0ca71e1f97a070973e4994bae8f61.tar.gz |
add client side social integration, use webassets
Diffstat (limited to 'syte/static/js/libs/google+.js')
-rw-r--r-- | syte/static/js/libs/google+.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/syte/static/js/libs/google+.js b/syte/static/js/libs/google+.js new file mode 100644 index 0000000..3647216 --- /dev/null +++ b/syte/static/js/libs/google+.js @@ -0,0 +1,86 @@ +/* +UI functions dedicated to the Google+ modal panel +*/ + +var gplus_api_user = 'https://www.googleapis.com/plus/v1/people/'; +var gplus_api_posts = '/activities/public?maxResults=20'; +var gplus_api_access = 'key=' + +var url = null; + +$('a[id^="Google-link"]').click(function (e) +{ + var url = prepare_link(e, this); + adjustSelection("Google-link"); + remove_modal(); + showGoogle(url, this); +}); + +function showGoogle(e, t) { + url = t.href; + var google_profile = $("#google-profile"); + if (google_profile.length > 0) { + google_profile.modal('show'); + } + else { + var spinner = (new Spinner(spin_opts)).spin(); + + $("#Google-link").append(spinner.el); + + $.get('/theme/templates/google-view.html', function(data) { + // Request succeeded, data contains HTML template, we can load data + var template = Handlebars.compile(data); + var google_data = {}; + var user_url = gplus_api_user+google_username+'?'+gplus_api_access+google_accesskey; + + try { + $.get(user_url, function(user) { + google_data['user'] = user + + var posts_url = gplus_api_user+google_username+gplus_api_posts+'&'+gplus_api_access+google_accesskey; + $.get(posts_url, function(data) { + var posts = data.items; + var index = 0; + while(index < posts.length) { + var post = posts[index]; + if(post.title == "") { + posts.splice(index,1) + } + else { + post.published = moment(post.published).fromNow(); + post.plusoners = numberWithCommas(post.object.plusoners.totalItems); + post.resharers = numberWithCommas(post.object.resharers.totalItems); + if(typeof post.placeName !== "undefined" && post.placeName != "") { + post.title = post.title+" (@"+post.placeName+")"; + } + index++; + } + } + google_data['posts'] = posts + + var html = template(google_data); + $('body').append(html); + $("#google-profile").modal(); + spinner.stop(); + }) + .error(function() { + window.location.href = url; + spinner.stop(); + }); + }) + .error(function() { + window.location.href = url; + spinner.stop(); + }); + } + catch (err) { + window.location.href = url; + spinner.stop(); + } + }) + .error(function() { + window.location.href = url; + spinner.stop(); + }); + } +} |