|
@@ -4901,6 +4901,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
|
|
|
|
|
TopNav.showViewButtons();
|
|
TopNav.showViewButtons();
|
|
|
|
|
|
|
|
|
|
+ CopyToClipboard.showKeyboardShortcutHint();
|
|
|
|
|
+
|
|
|
// this cannot be grouped with showViewButtons due to remaining time calculation
|
|
// this cannot be grouped with showViewButtons due to remaining time calculation
|
|
|
TopNav.showEmailButton();
|
|
TopNav.showEmailButton();
|
|
|
|
|
|
|
@@ -5337,6 +5339,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
// shows the remaining time (until) deletion
|
|
// shows the remaining time (until) deletion
|
|
|
PasteStatus.showRemainingTime(paste);
|
|
PasteStatus.showRemainingTime(paste);
|
|
|
|
|
|
|
|
|
|
+ CopyToClipboard.showKeyboardShortcutHint();
|
|
|
|
|
+
|
|
|
Promise.all(decryptionPromises)
|
|
Promise.all(decryptionPromises)
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
Alert.hideLoading();
|
|
Alert.hideLoading();
|
|
@@ -5366,6 +5370,138 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
return me;
|
|
return me;
|
|
|
})();
|
|
})();
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard
|
|
|
|
|
+ * @class
|
|
|
|
|
+ */
|
|
|
|
|
+ const CopyToClipboard = (function () {
|
|
|
|
|
+ const me = {};
|
|
|
|
|
+
|
|
|
|
|
+ let copyButton = $("#prettymessageCopyBtn"),
|
|
|
|
|
+ copyIcon = $("#copyIcon"),
|
|
|
|
|
+ successIcon = $("#copySuccessIcon"),
|
|
|
|
|
+ shortcutHint = $("#copyShortcutHintText");
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Handle copy to clipboard button click
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.handleCopyButtonClick
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ function handleCopyButtonClick() {
|
|
|
|
|
+ $(copyButton).click(function() {
|
|
|
|
|
+ const text = PasteViewer.getText();
|
|
|
|
|
+ saveToClipboard(text);
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Handle CTRL+C/CMD+C keyboard shortcut
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.handleKeyboardShortcut
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ function handleKeyboardShortcut() {
|
|
|
|
|
+ $(document).bind('copy', function () {
|
|
|
|
|
+ if (!isUserSelectedTextToCopy()) {
|
|
|
|
|
+ const text = PasteViewer.getText();
|
|
|
|
|
+ saveToClipboard(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Check if user selected some text on the page to copy it
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.isUserSelectedTextToCopy
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @function
|
|
|
|
|
+ * @returns {boolean}
|
|
|
|
|
+ */
|
|
|
|
|
+ function isUserSelectedTextToCopy() {
|
|
|
|
|
+ let text = "";
|
|
|
|
|
+
|
|
|
|
|
+ if (window.getSelection) {
|
|
|
|
|
+ text = window.getSelection().toString();
|
|
|
|
|
+ } else if (document.selection && document.selection.type != "Control") {
|
|
|
|
|
+ text = document.selection.createRange().text;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return text.length > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Save text to the clipboard
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.saveToClipboard
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @param {string} text
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ function saveToClipboard(text) {
|
|
|
|
|
+ navigator.clipboard.writeText(text);
|
|
|
|
|
+ toggleSuccessIcon();
|
|
|
|
|
+ showAlertMessage();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Show alert message after text copy
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.showAlertMessage
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ function showAlertMessage() {
|
|
|
|
|
+ Alert.showStatus("Paste copied to clipboard");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Toogle success icon after copy
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.toggleSuccessIcon
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ function toggleSuccessIcon() {
|
|
|
|
|
+ $(copyIcon).css("display", "none");
|
|
|
|
|
+ $(successIcon).css("display", "block");
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout(function() {
|
|
|
|
|
+ $(copyIcon).css("display", "block");
|
|
|
|
|
+ $(successIcon).css("display", "none");
|
|
|
|
|
+ }, 1000);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Show keyboard shortcut hint
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.showKeyboardShortcutHint
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ me.showKeyboardShortcutHint = function () {
|
|
|
|
|
+ I18n._(
|
|
|
|
|
+ shortcutHint,
|
|
|
|
|
+ 'To copy paste press on the copy button or use the clipboard shortcut Ctrl+c/Cmd+c'
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Initialize
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name CopyToClipboard.init
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ me.init = function() {
|
|
|
|
|
+ handleCopyButtonClick();
|
|
|
|
|
+ handleKeyboardShortcut();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return me;
|
|
|
|
|
+ })();
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* (controller) main PrivateBin logic
|
|
* (controller) main PrivateBin logic
|
|
|
*
|
|
*
|
|
@@ -5612,6 +5748,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
Prompt.init();
|
|
Prompt.init();
|
|
|
TopNav.init();
|
|
TopNav.init();
|
|
|
UiHelper.init();
|
|
UiHelper.init();
|
|
|
|
|
+ CopyToClipboard.init();
|
|
|
|
|
|
|
|
// check for legacy browsers before going any further
|
|
// check for legacy browsers before going any further
|
|
|
if (!Legacy.Check.getInit()) {
|
|
if (!Legacy.Check.getInit()) {
|
|
@@ -5668,6 +5805,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
ServerInteraction: ServerInteraction,
|
|
ServerInteraction: ServerInteraction,
|
|
|
PasteEncrypter: PasteEncrypter,
|
|
PasteEncrypter: PasteEncrypter,
|
|
|
PasteDecrypter: PasteDecrypter,
|
|
PasteDecrypter: PasteDecrypter,
|
|
|
|
|
+ CopyToClipboard: CopyToClipboard,
|
|
|
Controller: Controller
|
|
Controller: Controller
|
|
|
};
|
|
};
|
|
|
})(jQuery, RawDeflate);
|
|
})(jQuery, RawDeflate);
|