Skip to content
Open
Changes from all commits
Commits
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
53 changes: 47 additions & 6 deletions ratticweb/static/rattic/js/newcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,12 @@ var RATTIC = (function ($, ZeroClipboard) {

/* Add copy buttons to table cells */
my.controls.tableCopyButtons = function (cells) {
if (!FlashDetect.installed) {
return false;
}

cells.each(function () {
// Get the players
var me = $(this),
button = me.children('button'),
text = me.children('span'),
clip = new ZeroClipboard(button);
clip = FlashDetect.installed ? new ZeroClipboard(button) : null;

// Set data for callbacks
button.data('copyfrom', text);
Expand All @@ -632,7 +628,21 @@ var RATTIC = (function ($, ZeroClipboard) {
clip.on('mouseover', _showCopyButton);
}

clip.on('dataRequested', _copyButtonGetData);
if(FlashDetect.installed) {
clip.on('dataRequested', _copyButtonGetData);
} else {
button.on('click', function(event) {
var fakeClient = {
setText: function(text) {
copyText(text);
}
}

_copyButtonGetData.call(this, fakeClient);

event.preventDefault();
});
}
});

return true;
Expand Down Expand Up @@ -781,3 +791,34 @@ $(document).ready(function () {
sjcl.random.startCollectors();
});

// https://gist.github.com/jonrohan/81085b119d16cdd7868a
var copyNode, copyText, createNode;

createNode = function(text) {
var node;
node = document.createElement('span');
node.style.position = 'absolute';
node.style.left = '-10000px';
node.textContent = text;
return node;
};

copyNode = function(node) {
var range, selection;
selection = getSelection();
selection.removeAllRanges();
range = document.createRange();
range.selectNodeContents(node);
selection.addRange(range);
document.execCommand('copy');
return selection.removeAllRanges();
};

copyText = function(text) {
var node;
node = createNode(text);
document.body.appendChild(node);
copyNode(node);
return document.body.removeChild(node);
};