From 91efd5940d733b377f49b3cf7c0afcd37f651463 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Tue, 22 Sep 2015 13:17:48 -0700 Subject: [PATCH] add facebook sharing to map on completed challenges remove twitter share from non-bonfire challenges --- client/main.js | 53 +++++++++++++++++++++++++ server/views/challengeMap/show.jade | 9 ++++- server/views/coursewares/showJS.jade | 4 -- server/views/coursewares/showVideo.jade | 6 --- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/client/main.js b/client/main.js index 6e6ce8c696..5128ddb5e4 100644 --- a/client/main.js +++ b/client/main.js @@ -1,3 +1,29 @@ +var mapShareKey = 'map-shares'; + +function getMapShares() { + var alreadyShared = JSON.parse(localStorage.getItem(mapShareKey) || '[]'); + if (!alreadyShared || !Array.isArray(alreadyShared)) { + localStorage.setItem(mapShareKey, JSON.stringify([])); + alreadyShared = []; + } + return alreadyShared; +} + +function setMapShare(id) { + var alreadyShared = getMapShares(); + var found = false; + alreadyShared.forEach(function(_id) { + if (_id === id) { + found = true; + } + }); + if (!found) { + alreadyShared.push(id); + } + localStorage.setItem(mapShareKey, JSON.stringify(alreadyShared)); + return alreadyShared; +} + $(document).ready(function() { var challengeName = typeof challengeName !== 'undefined' ? @@ -383,6 +409,33 @@ $(document).ready(function() { } }, false); } + + + // map sharing + var alreadyShared = getMapShares(); + alreadyShared.map(function(id) { + // find share button div and hide as camper has already shared + $('div[id="' + id + '"]').parent().parent().hide(); + }); + + // on map view + $('.map-challenge-block-share').on('click', function(e) { + e.preventDefault(); + var challengeBlockName = $(this).children().attr('id'); + var challengeBlockEscapedName = challengeBlockName.replace(/\s/, '%20'); + + var link = 'https://www.facebook.com/dialog/feed?' + + 'app_id=1644598365767721' + + '&display=page&' + + 'caption=I%20just%20completed%20' + + challengeBlockEscapedName + + '%20on%20Free%20Code%20Camp' + + '&link=http%3A%2F%2Ffreecodecamp.com' + + '&redirect_uri=http://freecodecamp.com/map'; + + setMapShare(challengeBlockName); + window.location.href = link; + }); }); function defCheck(a){ diff --git a/server/views/challengeMap/show.jade b/server/views/challengeMap/show.jade index 11d14bceee..a7408ada09 100644 --- a/server/views/challengeMap/show.jade +++ b/server/views/challengeMap/show.jade @@ -131,7 +131,14 @@ block content span= challenge.title span.sr-only= " Incomplete" - //#announcementModal.modal(tabindex='-1') + if (challengeBlock.completed === 100) + .button-spacer + .row + .col-xs-12.col-sm-8.col-md-6.col-sm-offset-3.col-md-offset-2 + a.btn.btn-lg.btn-block.signup-btn.map-challenge-block-share Section complete! Tell your friends. + .hidden(id="#{challengeBlock.name}") + + // #announcementModal.modal(tabindex='-1') // .modal-dialog.animated.fadeInUp.fast-animation // .modal-content // .modal-header.challenge-list-header Add us to your LinkedIn profile diff --git a/server/views/coursewares/showJS.jade b/server/views/coursewares/showJS.jade index 03d6b823e1..f4621b5b28 100644 --- a/server/views/coursewares/showJS.jade +++ b/server/views/coursewares/showJS.jade @@ -94,10 +94,6 @@ block content .row if (user) #submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge (ctrl + enter) - if (user.progressTimestamps.length > 2) - a.btn.btn-lg.btn-block.btn-twitter(target="_blank", href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript") - i.fa.fa-twitter   - = phrase else a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge include ../partials/challenge-modals diff --git a/server/views/coursewares/showVideo.jade b/server/views/coursewares/showVideo.jade index 30ad2d5f1a..bd7f42e5ed 100644 --- a/server/views/coursewares/showVideo.jade +++ b/server/views/coursewares/showVideo.jade @@ -69,12 +69,6 @@ block content a.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) I've completed this challenge (ctrl + enter) script. $('#complete-courseware-editorless-dialog').bind('keypress', modalControlEnterHandler); - - if (user.progressTimestamps.length > 2) - .button-spacer - a.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank") - i.fa.fa-twitter   - = phrase else a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) I've completed this challenge (ctrl + enter) script.