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) {
|
$(document).on("cut copy paste", function (e) {
|
||||||
// The real clipboard is supported, so disable the peudo clipboard.
|
// If the pseudo clipboard was already invoked (which happens on the first clipboard
|
||||||
clipboard.disable();
|
// operation after page load even if native clipboard support exists) then sit this
|
||||||
var focusedElement = $scope.element.focusedElement;
|
// one operation out, but make sure whatever is on the pseudo clipboard gets migrated
|
||||||
if (!!focusedElement) {
|
// to the native clipboard for subsequent operations.
|
||||||
$scope.$apply(function () {
|
if (clipboard.wasInvoked()) {
|
||||||
switch (e.type) {
|
e.originalEvent.clipboardData.setData("text/plain", clipboard.getData("text/plain"));
|
||||||
case "copy":
|
e.originalEvent.clipboardData.setData("text/json", clipboard.getData("text/json"));
|
||||||
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();
|
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 Clipboard = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.clipboardData = {};
|
this._clipboardData = {};
|
||||||
this.setData = function(contentType, data, realClipBoard) {
|
this._isDisabled = false;
|
||||||
self.clipboardData[contentType] = data;
|
this._wasInvoked = false;
|
||||||
};
|
|
||||||
this.getData = function (contentType, realClipBoard) {
|
|
||||||
return self.clipboardData[contentType];
|
|
||||||
};
|
|
||||||
|
|
||||||
this.disable = function() {
|
this.setData = function(contentType, data) {
|
||||||
this.disabled = true;
|
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();
|
LayoutEditor.Clipboard = new Clipboard();
|
||||||
@@ -25,7 +37,9 @@
|
|||||||
return {
|
return {
|
||||||
setData: LayoutEditor.Clipboard.setData,
|
setData: LayoutEditor.Clipboard.setData,
|
||||||
getData: LayoutEditor.Clipboard.getData,
|
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 resetFocus = false;
|
||||||
var element = $scope.element;
|
var element = $scope.element;
|
||||||
|
|
||||||
|
|
||||||
if (element.editor.isDragging || element.editor.inlineEditingIsActive)
|
if (element.editor.isDragging || element.editor.inlineEditingIsActive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If the "real" clipboard works, then the pseudo-clipboard will have been disabled.
|
// If native clipboard support exists, the pseudo-clipboard will have been disabled.
|
||||||
if (!clipboard.disabled) {
|
if (!clipboard.isDisabled()) {
|
||||||
var focusedElement = element.editor.focusedElement;
|
var focusedElement = element.editor.focusedElement;
|
||||||
if (!!focusedElement) {
|
if (!!focusedElement) {
|
||||||
// Pseudo clipboard handling for browsers not allowing real clipboard operations.
|
// 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) {
|
this.copy = function (clipboardData) {
|
||||||
var text = this.getInnerText();
|
var text = this.getInnerText();
|
||||||
clipboardData.setData("text/plain", text);
|
clipboardData.setData("text/plain", text);
|
||||||
console.log(text);
|
|
||||||
|
|
||||||
var data = this.toObject();
|
var data = this.toObject();
|
||||||
var json = JSON.stringify(data, null, "\t");
|
var json = JSON.stringify(data, null, "\t");
|
||||||
|
Reference in New Issue
Block a user