Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
90a4237
Move building share menu to share-menu.js
mszylkowski Dec 13, 2021
38e02db
Reorganized share-menu.js
mszylkowski Dec 14, 2021
a3c76cc
Working share menu with proper split
mszylkowski Dec 14, 2021
9485073
Fixed dep-check, streamlined build
mszylkowski Dec 14, 2021
4627523
Fixed styling
mszylkowski Dec 14, 2021
462bb94
Cleaned up
mszylkowski Dec 14, 2021
cd68d5f
Updated comment
mszylkowski Dec 14, 2021
9a77fb7
CanonicalURL is unnecessary in constructor
mszylkowski Dec 14, 2021
9feca68
Fixed tests
mszylkowski Dec 15, 2021
d677cbd
Removed outdated amp-story links
mszylkowski Dec 15, 2021
c97aad9
Fixed lint errors
mszylkowski Dec 15, 2021
5c303e2
Merge branch 'main' of github.com:ampproject/amphtml into removeShare…
mszylkowski Dec 15, 2021
439cee0
Merge branch 'main' of github.com:ampproject/amphtml into removeShare…
mszylkowski Dec 15, 2021
c5eedef
Merge branch 'main' of github.com:ampproject/amphtml into removeShare…
mszylkowski Dec 16, 2021
16b8153
Removed share menu from amp-story extension
mszylkowski Dec 16, 2021
54dd432
Merge branch 'main' of github.com:ampproject/amphtml into removeShare…
mszylkowski Dec 20, 2021
15c386c
Merge branch 'main' of github.com:ampproject/amphtml into removeShare…
mszylkowski Dec 20, 2021
8ba6918
Fixed dep check
mszylkowski Dec 20, 2021
6465db7
Removed useless test
mszylkowski Dec 20, 2021
ed8d5c6
Added owners
mszylkowski Dec 20, 2021
643c69c
Transformed to BaseElement
mszylkowski Dec 20, 2021
60c3d26
Fixed tests
mszylkowski Dec 20, 2021
0b62241
Fixed visual tets
mszylkowski Dec 20, 2021
28641cf
Resolve depcheck
mszylkowski Dec 20, 2021
264af79
Fixed visual tests
mszylkowski Dec 20, 2021
3edc872
Removed console log
mszylkowski Dec 20, 2021
f9fff82
Fixed visual tests
mszylkowski Dec 20, 2021
b41fd82
Fixed invalid whitespaces
mszylkowski Dec 20, 2021
5bfc62f
Merge branch 'main' of github.com:ampproject/amphtml into removeShare…
mszylkowski Dec 21, 2021
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
Prev Previous commit
Next Next commit
Reorganized share-menu.js
  • Loading branch information
mszylkowski committed Dec 14, 2021
commit 38e02dbf30e35394ba3d84c04c0c48b54c74bb62
118 changes: 50 additions & 68 deletions extensions/amp-story-share-menu/0.1/amp-story-share-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,6 @@ const renderShareItemElement = (child) => (
<li class="i-amphtml-story-share-item">{child}</li>
);

/**
* @private
* @param {!Element} el
* @param {function(e)} onClick
* @return {!Element}
*/
function renderLinkShareItemElement(el, onClick) {
return renderShareItemElement(
<div
class="i-amphtml-story-share-icon i-amphtml-story-share-icon-link"
tabIndex={0}
role="button"
aria-label={localize(
el,
LocalizedStringId_Enum.AMP_STORY_SHARING_PROVIDER_NAME_LINK
)}
onClick={onClick}
onKeyUp={(e) => {
// Check if pressed Space or Enter to trigger button.
// TODO(wg-stories): Try switching this element to a <button> and
// removing this keyup handler, since it gives you this behavior for free.
const code = e.charCode || e.keyCode;
if (code === 32 || code === 13) {
onClick();
}
}}
>
<span class="i-amphtml-story-share-label">
{localize(
el,
LocalizedStringId_Enum.AMP_STORY_SHARING_PROVIDER_NAME_LINK
)}
</span>
</div>
);
}

/**
* Returns the share button for the provider if available.
* @param {!Document} doc
Expand Down Expand Up @@ -142,25 +105,6 @@ function buildProvider(doc, shareType) {
);
}

/**
* @param {!Document} doc
* @param {string} url
* @return {!Element}
*/
function buildCopySuccessfulToast(doc, url) {
return (
<div class="i-amphtml-story-copy-successful">
<div>
{localize(
doc,
LocalizedStringId_Enum.AMP_STORY_SHARING_CLIPBOARD_SUCCESS_TEXT
)}
</div>
<div class="i-amphtml-story-copy-url">{url}</div>
</div>
);
}

/**
* Share menu UI.
*/
Expand All @@ -170,6 +114,9 @@ export class ShareMenu {
* @param {!Element} storyEl Element where to append the component
*/
constructor(win, storyEl) {
/** @private {!AmpDoc} */
this.ampdoc_ = getAmpdoc(storyEl);

/** @private @const {!Window} */
this.win_ = win;

Expand Down Expand Up @@ -233,11 +180,11 @@ export class ShareMenu {
* @return {!Element}
*/
buildForFallbackSharing_() {
const shareWidgetElement = this.buildFallback_(getAmpdoc(this.parentEl_));
const shareWidgetElement = this.buildFallback_(this.ampdoc_);
this.element_ = this.renderForFallbackSharing_(shareWidgetElement);
// TODO(mszylkowski): import '../../amp-social-share/0.1/amp-social-share' when this file is lazy loaded.
Services.extensionsFor(this.win_).installExtensionForDoc(
getAmpdoc(this.parentEl_),
this.ampdoc_,
'amp-social-share'
);

Expand Down Expand Up @@ -281,7 +228,6 @@ export class ShareMenu {
* @private
*/
onShareMenuStateUpdate_(isOpen) {
console.log('share menu state update', isOpen);
if (this.isSystemShareSupported_ && isOpen) {
// Dispatches a click event on the amp-social-share button to trigger the
// native system sharing UI. This has to be done upon user interaction.
Expand Down Expand Up @@ -461,30 +407,66 @@ export class ShareMenu {
if (!isCopyingToClipboardSupported(this.win_.document)) {
return;
}
return renderLinkShareItemElement(this.parentEl_, (e) => {
e.preventDefault();
this.copyUrlToClipboard_();
});
return this.renderLinkShareItemElement_(this.parentEl_);
}

/**
* @private
* @param {!Element} el
* @return {!Element}
*/
renderLinkShareItemElement_(el) {
const label = localize(
el,
LocalizedStringId_Enum.AMP_STORY_SHARING_PROVIDER_NAME_LINK
);
return renderShareItemElement(
<button
class="i-amphtml-story-share-icon i-amphtml-story-share-icon-link"
aria-label={label}
onClick={(e) => {
e.preventDefault();
this.copyUrlToClipboard_();
}}
>
<span class="i-amphtml-story-share-label">{label}</span>
</button>
);
}

/**
* @private
*/
copyUrlToClipboard_() {
const url = Services.documentInfoForDoc(this.getAmpDoc_()).canonicalUrl;
const url = Services.documentInfoForDoc(this.ampdoc_).canonicalUrl;

if (!copyTextToClipboard(this.win_, url)) {
const failureString = localize(
this.parentEl_,
LocalizedStringId_Enum.AMP_STORY_SHARING_CLIPBOARD_FAILURE_TEXT
);
Toast.show(this.storyEl_, devAssert(failureString));
Toast.show(this.parentEl_, devAssert(failureString));
return;
}

Toast.show(
this.storyEl_,
buildCopySuccessfulToast(this.win_.document, url)
Toast.show(this.parentEl_, this.buildCopySuccessfulToast_(url));
}

/**
* @param {string} url
* @return {!Element}
*/
buildCopySuccessfulToast_(url) {
return (
<div class="i-amphtml-story-copy-successful">
<div>
{localize(
this.parentEl_,
LocalizedStringId_Enum.AMP_STORY_SHARING_CLIPBOARD_SUCCESS_TEXT
)}
</div>
<div class="i-amphtml-story-copy-url">{url}</div>
</div>
);
}
}
1 change: 1 addition & 0 deletions extensions/amp-story-share-menu/0.1/amp-story-share.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
.i-amphtml-story-share-icon-link {
background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="#fff"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.7 1.4-3.1 3.1-3.1h4V7H7a5 5 0 0 0 0 10h4v-1.9H7A3.1 3.1 0 0 1 3.9 12zM8 13h8v-2H8v2zm9-6h-4v1.9h4a3.1 3.1 0 0 1 0 6.2h-4V17h4a5 5 0 0 0 0-10z"/></svg>') !important;
background-color: #9AA0A6 !important;
border: none !important;
}

.i-amphtml-story-share-icon .i-amphtml-story-share-label {
Expand Down