Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <svg xmlns="http://www.w3.org/2000/svg" style="display:none">
  <symbol id="share-icon" viewBox="0 0 32 32">
    <path d="M27 22a4.985 4.985 0 00-3.594 1.526L9.937 16.792a5.035 5.035 0 000-1.582l13.469-6.734a5 5 0 10-1.343-2.683L8.594 12.527A5 5 0 105 21.001a4.985 4.985 0 003.594-1.526l13.469 6.734A5 5 0 1027 22z" />
  </symbol>
  <symbol id="twitter-icon" viewBox="0 0 32 32">
    <path d="M32 7.075a12.941 12.941 0 01-3.769 1.031 6.601 6.601 0 002.887-3.631 13.21 13.21 0 01-4.169 1.594A6.565 6.565 0 0022.155 4a6.563 6.563 0 00-6.563 6.563c0 .512.056 1.012.169 1.494A18.635 18.635 0 012.23 5.195a6.56 6.56 0 00-.887 3.3 6.557 6.557 0 002.919 5.463 6.565 6.565 0 01-2.975-.819v.081a6.565 6.565 0 005.269 6.437 6.574 6.574 0 01-2.968.112 6.588 6.588 0 006.131 4.563 13.17 13.17 0 01-9.725 2.719 18.568 18.568 0 0010.069 2.95c12.075 0 18.681-10.006 18.681-18.681 0-.287-.006-.569-.019-.85A13.216 13.216 0 0032 7.076z" />
  </symbol>
  <symbol id="facebook-icon" viewBox="0 0 32 32">
    <path d="M19 6h5V0h-5c-3.86 0-7 3.14-7 7v3H8v6h4v16h6V16h5l1-6h-6V7c0-.542.458-1 1-1z" />
  </symbol>
</svg>

<div class="social-box"></div>
              
            
!

CSS

              
                svg:not(:root) {
  overflow: hidden;
  pointer-events: none;
}

.social-box {
  display: flex;
}

.social-box .icon {
  display: flex;
  cursor: pointer;
  justify-content: center;
  align-items: center;
  width: 30px;
  height: 30px;
  padding: 5px;
  margin-right: 8px;
  background: #d3d3d3;
  transition: all 300ms ease-in-out;
  border-radius: 3px;
}

.social-box .icon:hover {
  background: #4d4d4d;
}

.social-box .icon:hover svg {
  fill: #fff;
}

.social-box svg {
  width: 18px;
  height: 18px;
  fill: #4d4d4d;
}

              
            
!

JS

              
                const socialBox = document.querySelector(".social-box");

const smallButton = `
  <div class="icon" title="Udostępnij w serwisie Facebook" data-share="facebook">
    <svg class="svg-icon">
      <use xlink:href="#facebook-icon"></use>
    </svg>
  </div>
  <div class="icon" title="Udostępnij w serwisie Twitter" data-share="twitter">
    <svg class="svg-icon">
      <use xlink:href="#twitter-icon"></use>
    </svg>
  </div>
`;

const shareButton = `
  <div class="icon share-icon">
    <svg class="svg-icon">
      <use xlink:href="#share-icon"></use>
    </svg>
  </div>
`;

// const shareData = {
//   title: document.querySelector("title").textContent,
//   text: document.querySelector('meta[name="description"]').getAttribute("content"),
//   url: document.querySelector('link[rel="canonical"]').getAttribute("href")
// };

const shareData = {
  title: 'navigator.shar method',
  text: 'opis interesującej strony',
  url: 'https://address.pl'
};


socialBox.innerHTML = navigator.share ? shareButton : smallButton;

if (navigator.share) {
  socialBox.addEventListener("click", async () => {
    try {
      await navigator.share(shareData);
    } catch (err) {
      console.log(err);
    }
  });
}

function showShareLink(typeSocial, url, title) {
  let urlLink;
  switch (typeSocial) {
    case "facebook":
      urlLink = `https://www.facebook.com/sharer/sharer.php?u=${encodeURI(
        url
      )}&p=${encodeURI(title)}`;
      break;
    case "twitter":
      urlLink = `http://twitter.com/share?text=${title}&url=${url}`;
      break;
    default:
      break;
  }
  return urlLink;
}

const socialIcons = document.querySelectorAll("div[data-share]");

const winWidth = 520;
const winHeight = 320;
const winTop = window.screen.height / 2 - winHeight / 2;
const winLeft = window.screen.width / 2 - winWidth / 2;

socialIcons.forEach((icon) => {
  icon.addEventListener("click", (event) => {
    window.open(
      showShareLink(event.target.dataset.share, shareData.url, shareData.title),
      "sharer",
      `top=${winTop}, left=${winLeft}, toolbar=0, status=0, width=${winWidth}, height=${winHeight}`
    );
  });
});

              
            
!
999px

Console