Skip to content

Commit

Permalink
feat: network defined in netorks directory
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Aug 23, 2024
1 parent c88ff22 commit 02205eb
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 154 deletions.
18 changes: 0 additions & 18 deletions src/config/constants.js

This file was deleted.

41 changes: 0 additions & 41 deletions src/functions/getData.js

This file was deleted.

58 changes: 49 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,77 @@
// import constants
import { selectorClick, selectorDiv, options } from './config/constants';

// import functions
import getData from './functions/getData';
import share from './shares/index';
import networks from './networks/index';

const CoCreateSocialShare = {

init: function () {
const selectorClick = '[share-network]';

let elements = document.querySelectorAll(selectorClick);
elements.forEach(el => this.initElement(el));
},

initElement: function (el) {
var that = this;
const self = this;
el.addEventListener("click", function (event) {

// Select Div element with dataset to share
event.preventDefault()
const selectorDiv = '[share-url], [share-title], [share-text], [share-height], [share-width] [share-media]';
const container = el.closest(selectorDiv)

// Get data to share from attributes
const data = getData(el, document, container);
const data = self.getData(el, document, container);

// Generate share url from data
const network = share(el, data);
const network = networks(el, data);

// Popup sub-window to share data
that.popup(network)
self.popup(network)
});
},

getData: function (el, document, container) {

let url = el.getAttribute('share-url') || '';
if (url == '') url = container.getAttribute('share-url') || '';
// url = encodeURIComponent((url == '') ? document.URL : url);

const urlObj = new URL(url || document.URL);
url = encodeURIComponent(urlObj.origin) + urlObj.pathname + urlObj.search + urlObj.hash;

let text = el.getAttribute('share-text') || '';
if (text == '') text = container.getAttribute('share-text') || '';
text = encodeURIComponent(text);

let title = el.getAttribute('share-title') || '';
if (title == '') title = container.getAttribute('share-title') || '';
title = encodeURIComponent((title == '') ? document.title : title);

let height = el.getAttribute('share-height') || '';
if (height == '') height = container.getAttribute('share-height') || '';
height = parseInt((height == '') ? 600 : height);

let width = el.getAttribute('share-width') || '';
if (width == '') width = container.getAttribute('share-width') || '';
width = parseInt((width == '') ? 500 : width);

let media = el.getAttribute('share-media') || '';
if (media == '') media = container.getAttribute('share-media') || '';
media = encodeURIComponent((media == '') ? '' : media);

return {
width,
height,
url,
text,
title,
media,
source: url
}
},

popup: function (network) {
const options = 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,';
window.open(network["url"], '', options + 'height=' + network["height"] + ',width=' + network["width"]);
}

Expand Down
5 changes: 5 additions & 0 deletions src/networks/bufferapp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const bufferapp = (data) => {
return 'http://bufferapp.com/add?text=' + data.text + '&url=' + data.url;
};

export default bufferapp;
6 changes: 6 additions & 0 deletions src/networks/delicious.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const delicious = (data) => {
return 'https://delicious.com/save?v=5&provider=' + data.provider + '&noui&jump=close&url=' + data.url +
'&title=' + data.title;
};

export default delicious;
5 changes: 5 additions & 0 deletions src/networks/digg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const digg = (data) => {
return 'http://digg.com/submit?url=' + '&title=' + data.title;
};

export default digg;
5 changes: 5 additions & 0 deletions src/networks/facebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const facebook = (data) => {
return 'https://www.facebook.com/sharer/sharer.php?display=popup&u=' + data.url + '&title=' + data.title;
};

export default facebook;
5 changes: 5 additions & 0 deletions src/networks/google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const google = (data) => {
return 'https://plus.google.com/share?url=' + data.url;
};

export default google;
5 changes: 5 additions & 0 deletions src/networks/hackernews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const hackernews = (data) => {
return 'http://news.ycombinator.com/submitlink?u=' + data.url + '&t=' + data.title;
};

export default hackernews;
File renamed without changes.
5 changes: 5 additions & 0 deletions src/networks/linkedIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const linkedIn = (data) => {
return 'https://www.linkedin.com/shareArticle?mini=true&url=' + data.url + '&title=' + data.title + '&source=' + data.source;
};

export default linkedIn;
6 changes: 6 additions & 0 deletions src/networks/pinterest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const pinterest = (data) => {
return 'https://www.pinterest.com/pin/create/button/?description=' + data.text + '&url=' + data.url + '&media=' +
data.media + '&is_video=false';
};

export default pinterest;
5 changes: 5 additions & 0 deletions src/networks/reddit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const reddit = (data) => {
return 'http://www.reddit.com/submit?url=' + data.url + '&title=' + data.title;
};

export default reddit;
5 changes: 5 additions & 0 deletions src/networks/stumbleupon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const stumbleupon = (data) => {
return 'http://www.stumbleupon.com/submit?url=' + data.url + '&title=' + data.title;
};

export default stumbleupon;
5 changes: 5 additions & 0 deletions src/networks/tumblr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const tumblr = (data) => {
return 'http://www.tumblr.com/share?s=&v=3&u=' + data.url + '&t=' + data.title;
};

export default tumblr;
5 changes: 5 additions & 0 deletions src/networks/twitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const twitter = (data) => {
return 'https://twitter.com/intent/tweet?text=' + data.text + '&url=' + data.url;
};

export default twitter;
7 changes: 0 additions & 7 deletions src/shares/bufferapp.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/shares/delicious.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/digg.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/facebook.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/google.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/hackernews.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/linkedIn.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/shares/pinterest.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/reddit.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/stumbleupon.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/tumblr.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/shares/twitter.js

This file was deleted.

0 comments on commit 02205eb

Please sign in to comment.