Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/toryanderson/hugo-icarus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordigitalcraftsman <digitalcraftsman@protonmail.com>2016-09-01 21:39:44 +0300
committerdigitalcraftsman <digitalcraftsman@protonmail.com>2016-09-01 21:39:44 +0300
commit925dc6a06a058a1692c06faa7e3aca9bfda58724 (patch)
tree1a6e67a6d3b2baec9d0887f8dccd2a3fa7c14c78 /layouts
parent3de1ba8bbc03530d9f9f00e100ed929689313093 (diff)
Refactor JS for share buttons
Fixes #48.
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/article_footer.html65
-rw-r--r--layouts/partials/footer_js.html3
-rw-r--r--layouts/partials/head.html5
3 files changed, 70 insertions, 3 deletions
diff --git a/layouts/partials/article_footer.html b/layouts/partials/article_footer.html
index 9aa84e2..582ac22 100644
--- a/layouts/partials/article_footer.html
+++ b/layouts/partials/article_footer.html
@@ -7,4 +7,69 @@
{{with .Site.Data.l10n.articles.comments}}{{.}}{{end}}
</a>
{{end}}
+
+ <script>
+ (function ($) {
+ // Prevent duplicate binding
+ if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
+ __SHARE_BUTTON_BINDED__ = true;
+ } else {
+ return;
+ }
+ $('body').on('click', function() {
+ $('.article-share-box.on').removeClass('on');
+ }).on('click', '.article-share-link', function(e) {
+ e.stopPropagation();
+
+ var $this = $(this),
+ url = $this.attr('data-url'),
+ encodedUrl = encodeURIComponent(url),
+ id = 'article-share-box-' + $this.attr('data-id'),
+ offset = $this.offset(),
+ box;
+
+ if ($('#' + id).length) {
+ box = $('#' + id);
+
+ if (box.hasClass('on')){
+ box.removeClass('on');
+ return;
+ }
+ } else {
+ var html = [
+ '<div id="' + id + '" class="article-share-box">',
+ '<input class="article-share-input" value="' + url + '">',
+ '<div class="article-share-links">',
+ '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
+ '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
+ '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
+ '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
+ '</div>',
+ '</div>'
+ ].join('');
+
+ box = $(html);
+
+ $('body').append(box);
+ }
+
+ $('.article-share-box.on').hide();
+
+ box.css({
+ top: offset.top + 25,
+ left: offset.left
+ }).addClass('on');
+
+ }).on('click', '.article-share-box', function (e) {
+ e.stopPropagation();
+ }).on('click', '.article-share-box-input', function () {
+ $(this).select();
+ }).on('click', '.article-share-box-link', function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
+ });
+ })(jQuery);
+ </script>
</footer>
diff --git a/layouts/partials/footer_js.html b/layouts/partials/footer_js.html
index e62eb05..0938b5d 100644
--- a/layouts/partials/footer_js.html
+++ b/layouts/partials/footer_js.html
@@ -1,5 +1,4 @@
{{ template "_internal/google_analytics.html" . }}
-<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="{{ .Site.BaseURL }}fancybox/jquery.fancybox.pack.js"></script>
<script src="{{ .Site.BaseURL }}js/script.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/highlight.min.js"></script>
@@ -12,4 +11,4 @@ MathJax.Hub.Config({
inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
-<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> \ No newline at end of file
+<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 9d10c3a..e1fceeb 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -15,7 +15,7 @@
<link href="{{ .RSSlink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
<link href="{{ .RSSlink }}" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end }}
- <link rel="canonical" href="{{ .Permalink }}"/>
+ <link rel="canonical" href="{{ .Permalink }}"/>
<link rel="icon" href="{{ .Site.BaseURL }}favicon.ico">
<link rel="apple-touch-icon" href="{{ .Site.BaseURL }}apple-touch-icon.png" />
<link rel="stylesheet" href="{{ .Site.BaseURL }}css/style.css">
@@ -37,6 +37,9 @@
}
</style>
{{ end }}
+
+ <!-- needs to be loaded first for following scripts -->
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="container">