Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.2 #8

Merged
merged 8 commits into from
Mar 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
![jQlipboard](https://user-images.githubusercontent.com/66105586/110230030-c00dce80-7edb-11eb-9d03-2d796745e606.png)

# jQlipboard
jQlipboard is a jQuery extension that makes accessing the clipboard much easier. This plugin also has features that make it usable across most if not all browsers.
jQlipboard is a jQuery extension that makes accessing the clipboard much easier. This plugin also has features that make it usable across all modern browsers.

The following is a brief tutorial on how to use jQlipboard. Full documentation can be found [here](https://diriectordoc.github.io/jQlipboard-Docs).

## Installation
To install, simply add the following script tag below the tag where `jQuery.js` is called:

```html
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/DiriectorDoc/jQlipboard/master/jQlipboard.js"></script>
<script src="https://diriectordoc.github.io/jQlipboard-Docs/src/v0.2/jQlipboard.js"></script>
```

Or, for a minified script:

```html
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/DiriectorDoc/jQlipboard/master/jQlipboard.min.js"></script>
<script src="https://diriectordoc.github.io/jQlipboard-Docs/src/v0.2/jQlipboard.min.js"></script>
```

## Copying
Expand Down
40 changes: 20 additions & 20 deletions jQlipboard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* jQlipboard v0.1.9
* jQlipboard v0.2
* A jQuery plugin that makes handling clipboard processes easier
*
*
* Author: Diriector_Doc
* Licence: MIT
* repository: https://github.com/DiriectorDoc/jQlipboard
* Repository: https://github.com/DiriectorDoc/jQlipboard
* Website: https://diriectordoc.github.io/jQlipboard-Docs/
*
*
* Copyright (c) 2020–2021 Diriector_Doc (DiriectorDoc on github)
Expand Down Expand Up @@ -37,7 +38,7 @@
*/
$.fn.copy = function(){
if(this.parent().length){
if(this[0].tagName == "TABLE"){
if($(this).is("table")){
$.copy(this[0].outerHTML)
} else {
let nodeB = selec.baseNode,
Expand All @@ -60,11 +61,11 @@
opacity: 0,
color: "rgba(0,0,0,0)", // Makes the object invisible. `display:none` will not work since it supresses selecting

"-webkit-user-select": "auto",
"-khtml-user-select": "auto",
"-moz-user-select": "auto",
"-ms-user-select": "auto",
"user-select": "auto" // Ensures that the appended object can be selected, just in case it was disabled in the stylesheet
"-webkit-user-select": "text",
"-khtml-user-select": "text",
"-moz-user-select": "text",
"-ms-user-select": "text",
"user-select": "text" // Ensures that the appended object can be selected, just in case it was disabled in the stylesheet
})
.appendTo("body")
.copy()
Expand All @@ -84,27 +85,26 @@
/*
* @returns {jQuery} this
*/
const $select = $.fn.select;
$.fn.select = function(elem, name, value, pass){
if("INPUT" == this[0].tagName || "TEXTAREA" == this[0].tagName){
return $select(elem, name, value, pass)
} else {
select(this[0])
$.fn.select = function(data, fn){
if(arguments.length > 0){
return this.on("select", null, data, fn)
}
if($(this).is("input,textarea")){
return this.trigger("select")
}
select(this[0])
return this
};

/*
* @returns {undefined}
*/
$.deselect = function(){
selec.removeAllRanges()
};
$.deselect = () => selec.removeAllRanges();

/*
* @returns {boolean}
*/
$.cut = function(){
$.cut = () => {
try {
if(!document.execCommand("cut")){
throw false
Expand All @@ -131,7 +131,7 @@
* @param {string} text
* @returns {boolean}
*/
$.copy = function(text){
$.copy = text => {
if(text !== undefined){
$("<a>")
.html(text)
Expand Down Expand Up @@ -163,7 +163,7 @@
}
};

$.jQlipboard.version = "0.1.9";
$.jQlipboard = {version: "v0.2"};
}((function(){
try{
return jQuery
Expand Down
4 changes: 2 additions & 2 deletions jQlipboard.min.js

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

40 changes: 19 additions & 21 deletions jQlipboard.tomin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

let exec=a=>document.execCommand(a)||(b=>{throw 0})(),
focused=a=>$(document.activeElement),
$select = $.fn.select,
c=console,
error = c.error,
info = c.info,
Expand All @@ -22,12 +21,11 @@
range.selectNode(nodeB)
}
w.addRange(range)
},
isTag=function(elem){return [...arguments].some(a=>a==elem[0].tagName)};
};

$.fn.copy = function() {
if (this.parent().length) {
if(isTag(this, "TABLE")){
if($(this).is("table")){
$.copy(this[0].outerHTML)
} else {
let nodeB = w.baseNode,
Expand All @@ -48,11 +46,11 @@
position: "absolute", // Ensures that appending the object does not mess up the existing document
opacity: 0, // ↴
color: "rgba(0,0,0,0)", // Makes the object invisible. `display:none` will not work since it disables the avility to select it
"-webkit-user-select": "auto",
"-khtml-user-select": "auto",
"-moz-user-select": "auto", // Ensures that the appended object can be selected, just in case it was disabled in the stylesheet
"-ms-user-select": "auto",
"user-select": "auto"
"-webkit-user-select": "text",
"-khtml-user-select": "text",
"-moz-user-select": "text", // Ensures that the appended object can be selected, just in case it was disabled in the stylesheet
"-ms-user-select": "text",
"user-select": "text"
})
.appendTo("body")
.copy()
Expand All @@ -66,18 +64,18 @@
.remove()
};

$.fn.select = function(elem, name, value, pass) {
if (isTag(this, "INPUT", "TEXTAREA"))
return $select(elem, name, value, pass);
else select(this[0]);
$.fn.select = function(data, fn) {
if(arguments.length > 0)
return this.on("select", null, data, fn);
if($(this).is("input,textarea"))
return this.trigger("select");
select(this[0]);
return this
};

$.deselect = function(){
w.removeAllRanges()
};
$.deselect = a => w.removeAllRanges();

$.cut = function(){
$.cut = a=>{
try {
return exec("cut")
} catch(err){
Expand All @@ -89,7 +87,7 @@
}
};

$.copy = function(text){
$.copy = text=>{
if(text !== undefined){
$("<a>")
.html(text)
Expand All @@ -104,7 +102,7 @@
let error = a=>!!error("Cannot copy text to clipboard",a);
if(navigator.clipboard){
let success = !info("Trying navigator.clipboard.writeText() instead");
navigator.clipboard.writeText(w.toString())
navigator.clipboard.writeText(w+"")
.then(a=>0)
.catch(y=>{
success = error(y)
Expand All @@ -116,5 +114,5 @@
}
};

$.jQlipboard.version = "0.1.9";
})(typeof jQuery != "undefined" ? jQuery:console.warn("jQuery not detected. You must use a jQuery version of 1.0 or newer to run this plugin."));
$.jQlipboard = {version: "v0.2"};
})(window.jQuery || console.warn("jQuery not detected. You must use a jQuery version of 1.0 or newer to run this plugin."));