Skip to content
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
15 changes: 10 additions & 5 deletions demos/share-files.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ <h1>Web Share Test</h1>
logText(message, true);
}

function setShareButtonsEnabled(enabled) {
document.querySelector('#share').disabled = !enabled;
document.querySelector('#share-no-gesture').disabled = !enabled;
}

function checkboxChanged(e) {
const checkbox = e.target;
const textfield = document.querySelector('#' + checkbox.id.split('_')[0]);
Expand All @@ -79,11 +84,6 @@ <h1>Web Share Test</h1>
}

async function testWebShare() {
if (navigator.share === undefined) {
logError('Error: Unsupported feature: navigator.share()');
return;
}

const title_input = document.querySelector('#title');
const text_input = document.querySelector('#text');
const url_input = document.querySelector('#url');
Expand All @@ -97,19 +97,23 @@ <h1>Web Share Test</h1>
if (files && files.length > 0) {
if (!navigator.canShare || !navigator.canShare({files})) {
logError('Error: Unsupported feature: navigator.canShare()');
setShareButtonsEnabled(true);
return;
}
}

setShareButtonsEnabled(false);
try {
await navigator.share({files, title, text, url});
logText('Successfully sent share');
} catch (error) {
logError('Error sharing: ' + error);
}
setShareButtonsEnabled(true);
}

async function testWebShareDelay() {
setShareButtonsEnabled(false);
await sleep(6000);
testWebShare();
}
Expand All @@ -128,6 +132,7 @@ <h1>Web Share Test</h1>
testWebShareDelay);

if (navigator.share === undefined) {
setShareButtonsEnabled(false);
if (window.location.protocol === 'http:') {
// navigator.share() is only available in secure contexts.
window.location.replace(window.location.href.replace(/^http:/, 'https:'));
Expand Down
14 changes: 9 additions & 5 deletions demos/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ <h1>Web Share Test</h1>
logText(message, true);
}

function setShareButtonsEnabled(enabled) {
document.querySelector('#share').disabled = !enabled;
document.querySelector('#share-no-gesture').disabled = !enabled;
}

function checkboxChanged(e) {
const checkbox = e.target;
const textfield = document.querySelector('#' + checkbox.id.split('_')[0]);
Expand All @@ -75,27 +80,25 @@ <h1>Web Share Test</h1>
}

async function testWebShare() {
if (navigator.share === undefined) {
logError('Error: Unsupported feature: navigator.share');
return;
}

const title_input = document.querySelector('#title');
const text_input = document.querySelector('#text');
const url_input = document.querySelector('#url');

const title = title_input.disabled ? undefined : title_input.value;
const text = text_input.disabled ? undefined : text_input.value;
const url = url_input.disabled ? undefined : url_input.value;
setShareButtonsEnabled(false);
try {
await navigator.share({title, text, url});
logText('Successfully sent share');
} catch (error) {
logError('Error sharing: ' + error);
}
setShareButtonsEnabled(true);
}

async function testWebShareDelay() {
setShareButtonsEnabled(false);
await sleep(6000);
testWebShare();
}
Expand All @@ -114,6 +117,7 @@ <h1>Web Share Test</h1>
testWebShareDelay);

if (navigator.share === undefined) {
setShareButtonsEnabled(false);
if (window.location.protocol === 'http:') {
// navigator.share() is only available in secure contexts.
window.location.replace(window.location.href.replace(/^http:/, 'https:'));
Expand Down