Coder Social home page Coder Social logo

hichemtab-tech / copyshareify-js Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 0.0 544 KB

CopyShareify-js is a versatile JavaScript library that enhances buttons with customizable actions. With CopyShareify-js, you can effortlessly transform ordinary buttons into powerful tools that enable various actions, including copying content, sharing on social media platforms, and more.

Home Page: https://hichemtab-tech.github.io/CopyShareify-js

License: MIT License

JavaScript 87.52% HTML 12.48%
clipboard copy-content dom-manipulation frontend-development html html-elements javascript javascript-library jquery-plugin share-content

copyshareify-js's Introduction

CopyShareify-js

CopyShareify-js is a versatile JavaScript library that enhances buttons with customizable actions. With CopyShareify-js, you can effortlessly transform ordinary buttons into powerful tools that enable various actions, including copying content, sharing on social media platforms, and more.

Features

  • Seamlessly integrate copy and share functionality into buttons on your web pages
  • Copy strings, HTML elements, and even images to the clipboard
  • Customize the action behavior based on your specific requirements
  • Easy way to integrate without manually add the events.

Installation

npm

You can install CopyShareify-js via npm:

  npm install copyshareify-js

CDN

You can also include CopyShareify-js directly from a CDN by adding the following script tag to your HTML file:

  <script src="https://cdn.jsdelivr.net/gh/HichemTab-tech/[email protected]/dist/copyshareify.min.js"></script>

Local Download

If you prefer to host the library locally, you can download the latest release from the source code and include it in your project:

<script src="path/to/copyshareify.min.js"></script>

Usage

HTML Attribute Method

To use CopyShareify-js with HTML attributes, include the necessary dependencies (e.g., jQuery) and the CopyShareify-js script in your HTML file. Use the data-action attribute to specify the action, and other data attributes to configure the options.

<!DOCTYPE html>
<html>
  <head>
    <title>Your Page Title</title>
    <!-- Include the necessary dependencies -->
    <script src="path/to/jquery.js"></script>
    <script src="path/to/copyshareify.js"></script>
  </head>
  <body>
    <!-- Your HTML content here -->
    <button data-action="copy" data-string="Hello, world!">Copy Text</button>
    <button data-action="share" data-title="My Page" data-description="Check out this amazing website!" data-string="https://www.example.com">Share Link</button>

    <script>
      // Initialize CopyShareify on the buttons
      $('[data-action]').CopyShareify();
    </script>
  </body>
</html>

Individual Element Method

Alternatively, you can trigger CopyShareify on individual elements by passing an options object:

<!DOCTYPE html>
<html>
  <head>
    <title>Your Page Title</title>
    <!-- Include the necessary dependencies -->
    <script src="path/to/jquery.js"></script>
    <script src="path/to/copyshareify.js"></script>
  </head>
  <body>
    <!-- Your HTML content here -->
    <button id="copyButton">Copy Text</button>
    <button id="shareButton">Share Link</button>

    <script>
      // Initialize CopyShareify on the buttons individually
      $('#copyButton').CopyShareify({
        action: 'copy',
        string: 'Hello, world!',
      });

      $('#shareButton').CopyShareify({
        action: 'share',
        title: 'My Page',
        description: 'Check out this amazing website!',
        string: 'https://www.example.com',
      });
    </script>
  </body>
</html>

Selecting the Text

CopyShareify-js provides multiple ways to select the text to be copied or shared:

  • String: You can directly specify a string value to be copied or shared.
  • HTML Input Selector: You can select the text from an - HTML input element by providing the input selector.
  • HTML Element Selector: You can select the text from an HTML element by providing the element selector.
  • HTML Image Selector: You can select an image to be copied or shared by providing the image selector.

Here's an example of how to use CopyShareify-js with different selection options:

<!DOCTYPE html>
<html>
  <head>
    <title>Your Page Title</title>
    <!-- Include the necessary dependencies -->
    <script src="path/to/jquery.js"></script>
    <script src="path/to/copyshareify.js"></script>
  </head>
  <body>
    <!-- Your HTML content here -->
    <button data-action="copy" data-string="Hello, world!">Copy Text</button>
    <button data-action="share" data-title="My Page" data-description="Check out this amazing website!" data-string="https://www.example.com">Share Link</button>

    <input type="text" id="inputText" value="This is an input value">
    <p id="paragraph">This is a paragraph text</p>
    <img id="image" src="path/to/image.jpg" alt="Image">

    <button data-action="copy" data-html-input-selector="#inputText">Copy Input Text</button>
    <button data-action="copy" data-html-element-selector="#paragraph">Copy Paragraph Text</button>
    <button data-action="copy" data-html-img-selector="#image">Copy Image</button>

    <script>
      // Initialize CopyShareify on the buttons
      $('[data-action]').CopyShareify();
    </script>
  </body>
</html>

Options

Key Description
action Specifies the action to be performed (e.g., "copy" or "share").
string The string value to be copied or shared.
htmlInputSelector The selector of the HTML input element from which the text will be copied.
htmlElementSelector The selector of the HTML element from which the text will be copied.
htmlImgSelector The selector of the HTML image element to be copied.
title The title or subject of the content to be shared.
description The description or additional information about the content to be shared.
onActionDone The callback function to be executed when the action is successfully performed.
onActionFailed The callback function to be executed when the action fails or encounters an error.

Demo

Here's a Demo example :

Demo

Contributing

Contributions are always welcome!

If you have any ideas, improvements, or bug fixes, please open an issue or submit a pull request.

Authors

License

MIT

copyshareify-js's People

Contributors

deepsource-io[bot] avatar hichemtab-tech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.