Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
estevanmaito committed Mar 22, 2019
1 parent 78e7efb commit 0e02b20
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
29 changes: 26 additions & 3 deletions dist/sharect.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Sharect = function () {
facebook: false
};
var _twitterConfig = {
username: false,
username: '',
url: 'https://twitter.com/intent/tweet?text=',
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="sharect__icon"><path d="M8.2,20.2c6.5,0,11.7-5.2,11.8-11.6c0-0.1,0-0.1,0-0.2c0-0.2,0-0.4,0-0.5c0.8-0.6,1.5-1.3,2.1-2.2c-0.8,0.3-1.6,0.6-2.4,0.7c0.9-0.5,1.5-1.3,1.8-2.3c-0.8,0.5-1.7,0.8-2.6,1c-1.6-1.7-4.2-1.7-5.9-0.1c-1.1,1-1.5,2.5-1.2,3.9C8.5,8.7,5.4,7.1,3.3,4.6c-1.1,1.9-0.6,4.3,1.3,5.5c-0.7,0-1.3-0.2-1.9-0.5l0,0c0,2,1.4,3.7,3.3,4.1c-0.6,0.2-1.2,0.2-1.9,0.1c0.5,1.7,2.1,2.8,3.9,2.9c-1.7,1.4-3.9,2-6.1,1.7C3.8,19.5,6,20.2,8.2,20.2"/></svg>'
};
Expand All @@ -23,6 +23,7 @@ var Sharect = function () {
var _arrowSize = 5;
var _buttonMargin = 7 * 2;
var _iconSize = 24 + _buttonMargin;
var _selectableElements = ['body'];

function createFacebookButton() {
var fbBtn = new Button(_facebookConfig.icon, function () {
Expand Down Expand Up @@ -126,19 +127,40 @@ var Sharect = function () {
_text = _selection.toString();
}

function getClosestElement(element, ancestor) {
if (Element.prototype.closest) {
return element.closest(ancestor);
} else {
// IE 9+ polyfill
var el = element;
do {
if (el.matches(ancestor)) return el;
el = el.parentNode;
} while (el !== null && el.nodeType === Node.ELEMENT_NODE);
return null;
}
}

function isSelectableElement() {
var currentSelectedElement = window.getSelection().baseNode.parentNode;
return _selectableElements.some(function (ancestor) {
return getClosestElement(currentSelectedElement, ancestor);
});
}

function attachEvents() {
window.addEventListener('mouseup', function () {
setTimeout(function mouseTimeout() {
if (hasTooltipDrawn()) {
if (hasSelection()) {
if (hasSelection() && isSelectableElement()) {
updateTextSelection();
moveTooltip();
return;
} else {
document.querySelector('.sharect').remove();
}
}
if (hasSelection()) {
if (hasSelection() && isSelectableElement()) {
updateTextSelection();
drawTooltip();
}
Expand All @@ -152,6 +174,7 @@ var Sharect = function () {
_twitterConfig.username = options.twitterUsername === undefined ? _twitterConfig.username : options.twitterUsername;
_backgroundColor = options.backgroundColor || _backgroundColor;
_iconColor = options.iconColor || _iconColor;
_selectableElements = options.selectableElements || _selectableElements;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/sharect.min.js

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

2 changes: 1 addition & 1 deletion docs/sharect.min.js

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

0 comments on commit 0e02b20

Please sign in to comment.