Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
46 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
function getSingleUse(item) { | ||
var url = $(item).data('generate_single_use_link_url'); | ||
var rurl = window.location.protocol+"//"+window.location.host; | ||
var resp = $.ajax({ | ||
headers: { Accept: "application/javascript" }, | ||
type: 'get', | ||
function getSingleUse(item, fn) { | ||
console.log(item) | ||
var url = $(item).data('generate-single-use-link-url'); | ||
if (!url) { | ||
alert("No url was provided for generating a single use link"); | ||
return; | ||
} | ||
|
||
$.ajax({ | ||
type: 'post', | ||
url: url, | ||
async: false | ||
success: fn | ||
}); | ||
return rurl + resp.responseText; | ||
} | ||
|
||
// A Turbolinks-enabled link has been clicked | ||
document.addEventListener("page:before-change", function(){ | ||
ZeroClipboard.destroy(); | ||
}); | ||
|
||
Blacklight.onLoad(function() { | ||
$.each($(".copypaste"), function(idx, item) { | ||
var clip = new ZeroClipboard(this); | ||
|
||
clip.on("copy", function(client, args) { | ||
clip.setText(getSingleUse(item)); | ||
clip.on("dataRequested", function(client, args) { | ||
getSingleUse(item, function(data) { | ||
client.setText(data) | ||
}); | ||
}); | ||
|
||
clip.on("aftercopy", function(client, args) { | ||
clip.on("complete", function(client, args) { | ||
alert("A single use link to " + args.text + " was copied to your clipboard."); | ||
}); | ||
|
||
clip.on("error", function(client, args) { | ||
alert("Your single-use link (please copy): " + getSingleUse(item)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters