Skip to content

Commit

Permalink
Merge pull request #6 from christophery/encode-special-characters
Browse files Browse the repository at this point in the history
Encode special characters
  • Loading branch information
christophery authored Aug 7, 2020
2 parents 20c1499 + b67fe76 commit 26efa13
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>Title & URL defined</h2>

<h2>Title, text and URL defined</h2>
<p>This share button will share a defined title, text and url set by data attributes.</p>
<button class="good-share" data-share-title="Chris' Github Profile" data-share-text="Lorem ipsum dolor sit amet, consectetur adipiscing elit" data-share-url="https://github.com/christophery">Share</button>
<button class="good-share" data-share-title="Chris' Github Profile" data-share-text="Lorem ipsum dolor sit amet, consectetur adipiscing elit" data-share-url="https://github.com/christophery?foo=bar&hello=world">Share</button>
</div>

<script src="dist/good-share.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion dist/good-share.min.js

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

8 changes: 8 additions & 0 deletions js/good-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@
share_text = event.target.dataset.shareText || og_description || '';
share_url = event.target.dataset.shareUrl || og_url || current_url;

//check if fallback share
if( navigator.share == null ){
//escape special characters
share_title = encodeURIComponent(share_title);
share_text = encodeURIComponent(share_text);
share_url = encodeURIComponent(share_url);
}

//open share window
open_share_modal( share_title, share_text, share_url );
}
Expand Down
41 changes: 11 additions & 30 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "good-share",
"description": "Good Share is a share button library with Web Share API integration",
"version": "1.1.0",
"version": "1.1.1",
"homepage": "https://chrisyee.ca/good-share/",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -30,6 +30,6 @@
"@babel/core": "^7.5.4"
},
"browserslist": [
"last 2 versions"
"last 2 versions"
]
}

0 comments on commit 26efa13

Please sign in to comment.