Skip to content

Commit 6b082fe

Browse files
rendromwcoder
authored andcommitted
Make umd; export with update method (#18)
* Make umd; export with update method * Build
1 parent d9d598c commit 6b082fe

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

dist/share-buttons.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/dynamic.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='utf-8'>
5+
6+
<title>Test page for sharing</title>
7+
<meta name="description" content="Page description" />
8+
9+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
10+
<style>
11+
/* Few styles :) */
12+
.share-btn > a {
13+
border: 1px solid #ccc;
14+
padding: 5px;
15+
font-size: 12px;
16+
font-family: Verdana, Arial;
17+
}
18+
.share-btn > a:hover {
19+
cursor: pointer;
20+
}
21+
</style>
22+
</head>
23+
<body>
24+
25+
<p>Share this page with:</p>
26+
27+
<!-- data-url="" data-title="" data-desc="" -->
28+
29+
30+
<div class="share-btn" data-url="https://github.com/wcoder/share-buttons">
31+
</div>
32+
33+
<script src="../src/share-buttons.js"></script>
34+
<script>
35+
var social = [
36+
{id: 'vk', className: 'btn-vk', icon: 'fab fa-vk', name: 'VK'},
37+
{id: 'fb', className: 'btn-facebook', icon: 'fab fa-facebook-square', name: 'Facebook'},
38+
{id: 'tw', className: 'btn-twitter', icon: 'fab fa-twitter', name: 'Twitter'},
39+
{id: 'tg', className: 'btn-telegram', icon: 'fab fa-telegram', name: 'Telegram'},
40+
{id: 'pk', className: 'btn-pocket', icon: 'fab fa-get-pocket', name: 'Pocket'},
41+
{id: 're', className: 'btn-reddit', icon: 'fab fa-reddit', name: 'Reddit'},
42+
{id: 'ev', className: 'btn-evernote', icon: 'far fa-sticky-note', name: 'Evernote'},
43+
{id: 'in', className: 'btn-linkedin', icon: 'fab fa-linkedin', name: 'LinkedIn'},
44+
{id: 'pi', className: 'btn-pinterest', icon: 'fab fa-pinterest', name: 'Pinterest'},
45+
{id: 'sk', className: 'btn-skype', icon: 'fab fa-skype', name: 'Skype'},
46+
{id: 'wa', className: 'btn-whatsapp', icon: 'fab fa-whatsapp', name: 'WhatsApp'},
47+
{id: 'ok', className: 'btn-ok', icon: 'fab fa-odnoklassniki', name: 'Odnoklassniki'},
48+
{id: 'tu', className: 'btn-tumblr', icon: 'fab fa-tumblr', name: 'Tumblr'},
49+
{id: 'hn', className: 'btn-hn', icon: 'fab fa-hacker-news', name: 'Hacker News'},
50+
{id: 'xi', className: 'btn-xing', icon: 'fab fa-xing', name: 'Xing'},
51+
{id: 'mail', className: 'btn-mail', icon: 'fas fa-at', name: 'EMail'},
52+
{id: 'btn-print', className: 'print', icon: 'fas fa-print', name: 'Print'},
53+
]
54+
var shareBtnContainer = document.getElementsByClassName('share-btn')[0];
55+
for (var i = 0; i < social.length; i++) {
56+
var s = social[i];
57+
shareBtnContainer.innerHTML += '<a class="' + s.className + '" data-id="' + s.id + '">' +
58+
'<i class="' + s.icon + '"></i> ' + s.name + '</a>';
59+
}
60+
61+
window.ShareButtons.update();
62+
</script>
63+
</body>
64+
</html>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"example": "example"
77
},
88
"scripts": {
9-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"test": "echo \"Error: no test specified\" && exit 1",
10+
"build": "gulp build"
1011
},
1112
"repository": {
1213
"type": "git",

src/share-buttons.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
(function (w, d) {
2-
'use strict';
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global = global || self, global.ShareButtons = factory());
5+
}(this, function () { 'use strict';
6+
7+
var w = window;
8+
var d = w.document;
39

410
/**
511
* Class to display the buttons of social networks.
@@ -350,6 +356,13 @@
350356
}
351357

352358
// start
353-
new ShareButtons().i();
359+
var shareButtons = new ShareButtons();
360+
shareButtons.i();
354361

355-
}(window, document));
362+
return {
363+
update: function () {
364+
shareButtons.i();
365+
}
366+
};
367+
368+
}));

0 commit comments

Comments
 (0)