mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#5403 Improved native clipboard support in layout editor.
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -114,34 +114,46 @@
|
||||
};
|
||||
|
||||
$(document).on("cut copy paste", function (e) {
|
||||
// The real clipboard is supported, so disable the peudo clipboard.
|
||||
clipboard.disable();
|
||||
var focusedElement = $scope.element.focusedElement;
|
||||
if (!!focusedElement) {
|
||||
$scope.$apply(function () {
|
||||
switch (e.type) {
|
||||
case "copy":
|
||||
focusedElement.copy(e.originalEvent.clipboardData);
|
||||
break;
|
||||
case "cut":
|
||||
focusedElement.cut(e.originalEvent.clipboardData);
|
||||
break;
|
||||
case "paste":
|
||||
focusedElement.paste(e.originalEvent.clipboardData);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// HACK: Workaround because of how Angular treats the DOM when elements are shifted around - input focus is sometimes lost.
|
||||
window.setTimeout(function () {
|
||||
$scope.$apply(function () {
|
||||
if (!!$scope.element.focusedElement)
|
||||
$scope.element.focusedElement.setIsFocused();
|
||||
});
|
||||
}, 100);
|
||||
|
||||
// If the pseudo clipboard was already invoked (which happens on the first clipboard
|
||||
// operation after page load even if native clipboard support exists) then sit this
|
||||
// one operation out, but make sure whatever is on the pseudo clipboard gets migrated
|
||||
// to the native clipboard for subsequent operations.
|
||||
if (clipboard.wasInvoked()) {
|
||||
e.originalEvent.clipboardData.setData("text/plain", clipboard.getData("text/plain"));
|
||||
e.originalEvent.clipboardData.setData("text/json", clipboard.getData("text/json"));
|
||||
e.preventDefault();
|
||||
}
|
||||
else {
|
||||
var focusedElement = $scope.element.focusedElement;
|
||||
if (!!focusedElement) {
|
||||
$scope.$apply(function () {
|
||||
switch (e.type) {
|
||||
case "copy":
|
||||
focusedElement.copy(e.originalEvent.clipboardData);
|
||||
break;
|
||||
case "cut":
|
||||
focusedElement.cut(e.originalEvent.clipboardData);
|
||||
break;
|
||||
case "paste":
|
||||
focusedElement.paste(e.originalEvent.clipboardData);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// HACK: Workaround because of how Angular treats the DOM when elements are shifted around - input focus is sometimes lost.
|
||||
window.setTimeout(function () {
|
||||
$scope.$apply(function () {
|
||||
if (!!$scope.element.focusedElement)
|
||||
$scope.element.focusedElement.setIsFocused();
|
||||
});
|
||||
}, 100);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
// Native clipboard support obviously exists, so disable the peudo clipboard from now on.
|
||||
clipboard.disable();
|
||||
});
|
||||
}
|
||||
],
|
||||
|
@@ -3,17 +3,29 @@
|
||||
|
||||
var Clipboard = function () {
|
||||
var self = this;
|
||||
this.clipboardData = {};
|
||||
this.setData = function(contentType, data, realClipBoard) {
|
||||
self.clipboardData[contentType] = data;
|
||||
};
|
||||
this.getData = function (contentType, realClipBoard) {
|
||||
return self.clipboardData[contentType];
|
||||
};
|
||||
this._clipboardData = {};
|
||||
this._isDisabled = false;
|
||||
this._wasInvoked = false;
|
||||
|
||||
this.disable = function() {
|
||||
this.disabled = true;
|
||||
this.setData = function(contentType, data) {
|
||||
self._clipboardData[contentType] = data;
|
||||
self._wasInvoked = true;
|
||||
};
|
||||
this.getData = function (contentType) {
|
||||
return self._clipboardData[contentType];
|
||||
self._wasInvoked = true;
|
||||
};
|
||||
this.disable = function() {
|
||||
self._isDisabled = true;
|
||||
self._wasInvoked = false;
|
||||
self._clipboardData = {};
|
||||
};
|
||||
this.isDisabled = function () {
|
||||
return self._isDisabled;
|
||||
}
|
||||
this.wasInvoked = function () {
|
||||
return self._wasInvoked;
|
||||
}
|
||||
}
|
||||
|
||||
LayoutEditor.Clipboard = new Clipboard();
|
||||
@@ -25,7 +37,9 @@
|
||||
return {
|
||||
setData: LayoutEditor.Clipboard.setData,
|
||||
getData: LayoutEditor.Clipboard.getData,
|
||||
disable: LayoutEditor.Clipboard.disable
|
||||
disable: LayoutEditor.Clipboard.disable,
|
||||
isDisabled: LayoutEditor.Clipboard.isDisabled,
|
||||
wasInvoked: LayoutEditor.Clipboard.wasInvoked
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
@@ -15,12 +15,11 @@
|
||||
var resetFocus = false;
|
||||
var element = $scope.element;
|
||||
|
||||
|
||||
if (element.editor.isDragging || element.editor.inlineEditingIsActive)
|
||||
return;
|
||||
|
||||
// If the "real" clipboard works, then the pseudo-clipboard will have been disabled.
|
||||
if (!clipboard.disabled) {
|
||||
// If native clipboard support exists, the pseudo-clipboard will have been disabled.
|
||||
if (!clipboard.isDisabled()) {
|
||||
var focusedElement = element.editor.focusedElement;
|
||||
if (!!focusedElement) {
|
||||
// Pseudo clipboard handling for browsers not allowing real clipboard operations.
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -157,7 +157,6 @@
|
||||
this.copy = function (clipboardData) {
|
||||
var text = this.getInnerText();
|
||||
clipboardData.setData("text/plain", text);
|
||||
console.log(text);
|
||||
|
||||
var data = this.toObject();
|
||||
var json = JSON.stringify(data, null, "\t");
|
||||
|
Reference in New Issue
Block a user