Show share button from last completed
This commit is contained in:
@ -1,4 +1,7 @@
|
|||||||
var mapShareKey = 'map-shares';
|
var mapShareKey = 'map-shares';
|
||||||
|
var lastCompleted = typeof lastCompleted !== 'undefined' ?
|
||||||
|
lastCompleted :
|
||||||
|
'';
|
||||||
|
|
||||||
function getMapShares() {
|
function getMapShares() {
|
||||||
var alreadyShared = JSON.parse(localStorage.getItem(mapShareKey) || '[]');
|
var alreadyShared = JSON.parse(localStorage.getItem(mapShareKey) || '[]');
|
||||||
@ -413,27 +416,34 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
// map sharing
|
// map sharing
|
||||||
var alreadyShared = getMapShares();
|
var alreadyShared = getMapShares();
|
||||||
alreadyShared.map(function(id) {
|
|
||||||
// find share button div and hide as camper has already shared
|
if (lastCompleted && alreadyShared.indexOf(lastCompleted) === -1) {
|
||||||
$('div[id="' + id + '"]').parent().parent().hide();
|
$('div[id="' + lastCompleted + '"]')
|
||||||
});
|
.parent()
|
||||||
|
.parent()
|
||||||
|
.removeClass('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
// on map view
|
// on map view
|
||||||
$('.map-challenge-block-share').on('click', function(e) {
|
$('.map-challenge-block-share').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var challengeBlockName = $(this).children().attr('id');
|
var challengeBlockName = $(this).children().attr('id');
|
||||||
var challengeBlockEscapedName = challengeBlockName.replace(/\s/, '%20');
|
var challengeBlockEscapedName = challengeBlockName.replace(/\s/, '%20');
|
||||||
var username = typeof window.username !== "undefined" ? window.username : "";
|
var username = typeof window.username !== 'undefined' ?
|
||||||
|
window.username :
|
||||||
|
'';
|
||||||
|
|
||||||
var link = 'https://www.facebook.com/dialog/feed?' +
|
var link = 'https://www.facebook.com/dialog/feed?' +
|
||||||
'app_id=1644598365767721' +
|
'app_id=1644598365767721' +
|
||||||
'&display=page&' +
|
'&display=page&' +
|
||||||
'caption=I%20just%20completed%20the%20' +
|
'caption=I%20just%20completed%20the%20' +
|
||||||
challengeBlockEscapedName +
|
challengeBlockEscapedName +
|
||||||
'%20section%20on%20Free%20Code%20Camp%2E%20Check%20out%20my%20portfolio%20so%20far%2E' +
|
'%20section%20on%20Free%20Code%20Camp%2E%20Check%20out' +
|
||||||
|
'%20my%20portfolio%20so%20far%2E' +
|
||||||
'&link=http%3A%2F%2Ffreecodecamp%2Ecom%2F' +
|
'&link=http%3A%2F%2Ffreecodecamp%2Ecom%2F' +
|
||||||
username +
|
username +
|
||||||
'&redirect_uri=http%3A%2F%2Ffreecodecamp%2Ecom%2Fmap';
|
'&redirect_uri=http%3A%2F%2Ffreecodecamp%2Ecom%2Fmap';
|
||||||
|
|
||||||
setMapShare(challengeBlockName);
|
setMapShare(challengeBlockName);
|
||||||
window.location.href = link;
|
window.location.href = link;
|
||||||
});
|
});
|
||||||
|
@ -134,7 +134,7 @@ block content
|
|||||||
if (challengeBlock.completed === 100)
|
if (challengeBlock.completed === 100)
|
||||||
.button-spacer
|
.button-spacer
|
||||||
.row
|
.row
|
||||||
.col-xs-12.col-sm-8.col-md-6.col-sm-offset-3.col-md-offset-2
|
.col-xs-12.col-sm-8.col-md-6.col-sm-offset-3.col-md-offset-2.hidden
|
||||||
a.btn.btn-lg.btn-block.signup-btn.map-challenge-block-share Section complete. Share your Portfolio with your friends.
|
a.btn.btn-lg.btn-block.signup-btn.map-challenge-block-share Section complete. Share your Portfolio with your friends.
|
||||||
.hidden(id="#{challengeBlock.name}")
|
.hidden(id="#{challengeBlock.name}")
|
||||||
script.
|
script.
|
||||||
|
Reference in New Issue
Block a user