Skip to content

Make umd; export with update method #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/share-buttons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions example/dynamic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>

<title>Test page for sharing</title>
<meta name="description" content="Page description" />

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<style>
/* Few styles :) */
.share-btn > a {
border: 1px solid #ccc;
padding: 5px;
font-size: 12px;
font-family: Verdana, Arial;
}
.share-btn > a:hover {
cursor: pointer;
}
</style>
</head>
<body>

<p>Share this page with:</p>

<!-- data-url="" data-title="" data-desc="" -->


<div class="share-btn" data-url="https://github.com/wcoder/share-buttons">
</div>

<script src="../src/share-buttons.js"></script>
<script>
var social = [
{id: 'vk', className: 'btn-vk', icon: 'fab fa-vk', name: 'VK'},
{id: 'fb', className: 'btn-facebook', icon: 'fab fa-facebook-square', name: 'Facebook'},
{id: 'tw', className: 'btn-twitter', icon: 'fab fa-twitter', name: 'Twitter'},
{id: 'tg', className: 'btn-telegram', icon: 'fab fa-telegram', name: 'Telegram'},
{id: 'pk', className: 'btn-pocket', icon: 'fab fa-get-pocket', name: 'Pocket'},
{id: 're', className: 'btn-reddit', icon: 'fab fa-reddit', name: 'Reddit'},
{id: 'ev', className: 'btn-evernote', icon: 'far fa-sticky-note', name: 'Evernote'},
{id: 'in', className: 'btn-linkedin', icon: 'fab fa-linkedin', name: 'LinkedIn'},
{id: 'pi', className: 'btn-pinterest', icon: 'fab fa-pinterest', name: 'Pinterest'},
{id: 'sk', className: 'btn-skype', icon: 'fab fa-skype', name: 'Skype'},
{id: 'wa', className: 'btn-whatsapp', icon: 'fab fa-whatsapp', name: 'WhatsApp'},
{id: 'ok', className: 'btn-ok', icon: 'fab fa-odnoklassniki', name: 'Odnoklassniki'},
{id: 'tu', className: 'btn-tumblr', icon: 'fab fa-tumblr', name: 'Tumblr'},
{id: 'hn', className: 'btn-hn', icon: 'fab fa-hacker-news', name: 'Hacker News'},
{id: 'xi', className: 'btn-xing', icon: 'fab fa-xing', name: 'Xing'},
{id: 'mail', className: 'btn-mail', icon: 'fas fa-at', name: 'EMail'},
{id: 'btn-print', className: 'print', icon: 'fas fa-print', name: 'Print'},
]
var shareBtnContainer = document.getElementsByClassName('share-btn')[0];
for (var i = 0; i < social.length; i++) {
var s = social[i];
shareBtnContainer.innerHTML += '<a class="' + s.className + '" data-id="' + s.id + '">' +
'<i class="' + s.icon + '"></i> ' + s.name + '</a>';
}

window.ShareButtons.update();
</script>
</body>
</html>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"example": "example"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "gulp build"
},
"repository": {
"type": "git",
Expand Down
21 changes: 17 additions & 4 deletions src/share-buttons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
(function (w, d) {
'use strict';
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.ShareButtons = factory());
}(this, function () { 'use strict';

var w = window;
var d = w.document;

/**
* Class to display the buttons of social networks.
Expand Down Expand Up @@ -350,6 +356,13 @@
}

// start
new ShareButtons().i();
var shareButtons = new ShareButtons();
shareButtons.i();

}(window, document));
return {
update: function () {
shareButtons.i();
}
};

}));