-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtool.js
81 lines (77 loc) · 2.99 KB
/
tool.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
$("#sortable").sortable({
change: function(){generateLinks();},
update: function(){generateLinks();}
});
$("#sortable").disableSelection();
$("input").on("input", function(){
generateLinks();
})
// default parameters
$("input[type=checkbox]").each(function() {
$(this).prop("checked", true);
})
$("#no-background-input").prop("checked", false);
generateLinks();
function generateLinks() {
var finalHTML = `
<div id='shareLinks' style='display:flex;flex-direction:row;font-size: ${$("#scale-input").val()*16}px;'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
`;
$(".socialmedia-checkbox").each(function() {
if ($(this).is(":checked")) {
finalHTML += generateLink($(this).attr('id'));
}
});
finalHTML += `
<style>
.fa {
text-decoration: none;
color: ${$("#icon-color-input").val()};
${$("#no-background-input").is(":checked") ? "" : "background: " + $("#background-color-input").val() + ";"}
border-radius: ${$("#border-radius-input").val()}%;
padding: ${$("#padding-within-input").val()}px;
padding-top: ${parseInt($("#padding-within-input").val()) + $("#scale-input").val()*3}px;
padding-bottom: ${parseInt($("#padding-within-input").val()) - $("#scale-input").val()*3}px;
margin: 0 ${$("#space-between-input").val()}px;
width: ${$("#scale-input").val()*20}px;
height: ${$("#scale-input").val()*20}px;
text-align: center;
}
${$("#hover-input").is(":checked") ? ".fa:hover{opacity: 0.5;}" : ""}
</style>
</div>
`
$("#preview").html(finalHTML);
$("#embed").text(finalHTML);
}
function generateLink(social) {
if (social == "CopyLink") {
return (`
<a class="fa fa-share" href="javascript:void(0);" onclick="copyUrlToClipboard()"></a>
<script>
function copyUrlToClipboard() {
var dummy = document.createElement("textarea");
document.body.appendChild(dummy);
dummy.value = window.location.href;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
alert("Share link copied to clipboard!");
}
</script>
`)
}
socialMap = {
"Facebook" : ["https://www.facebook.com/sharer/sharer.php?u=", ""],
"Twitter" : ["http://www.twitter.com/share?url=", ""],
"LinkedIn" : ["https://www.linkedin.com/sharing/share-offsite/?url=", ""],
"Pinterest" : ["http://pinterest.com/pin/create/link/?url=", ""],
};
return (`
<a id="${social}-share-icon" class="fa fa-${social.toLowerCase()}" target="_blank"></a>
<script>
var curr = window.location.href;
document.getElementById("${social}-share-icon").href = \`${socialMap[social][0]}\${curr}${socialMap[social][1]}\`;
</script>
`);
}