Skip to content

Commit ebaa46b

Browse files
author
perploug
committed
Fixes: U4-4212 Insert Image in RTE not resizing image
1 parent 426b02b commit ebaa46b

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

src/Umbraco.Web.UI.Client/lib/tinymce/skins/umbraco/content.min.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ td.mce-item-selected, th.mce-item-selected {
9292
-webkit-background-size: 18px;
9393
background-size: 18px;
9494
background-position-x: 99%;
95-
}
95+
}
96+
97+
/* TINYMCE IMAGE RESIZING LIMITS */
98+
#mceResizeHandlen, #mceResizeHandles, #mceResizeHandlee, #mceResizeHandlew{display: none !important; visibility: hidden !important;}

src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,16 @@ function tinyMceService(dialogService, $log, imageHelper, $http, $timeout, macro
121121
var size = editor.dom.getSize(imgElm);
122122

123123
var newSize = imageHelper.scaleToMaxSize(500, size.w, size.h);
124+
124125
var s = "width: " + newSize.width + "px; height:" + newSize.height + "px;";
125126
editor.dom.setAttrib(imgElm, 'style', s);
126-
editor.dom.setAttrib(imgElm, 'rel', newSize.width + "," + newSize.height);
127127
editor.dom.setAttrib(imgElm, 'id', null);
128128

129+
if(img.url){
130+
var src = img.url + "?width=" + newSize.width + "&height=" + newSize.height;
131+
editor.dom.setAttrib(imgElm, 'data-mce-src', src);
132+
}
133+
129134
}, 500);
130135
}
131136
}

src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,57 @@ angular.module("umbraco")
109109
//listen to both change and blur and also on our own 'saving' event. I think this will be best because a
110110
//timer might end up using unwanted cpu and we'd still have to listen to our saving event in case they clicked
111111
//save before the timeout elapsed.
112-
editor.on('change', function (e) {
112+
113+
//this doesnt actually work...
114+
//editor.on('change', function (e) {
115+
// angularHelper.safeApply($scope, function () {
116+
// $scope.model.value = editor.getContent();
117+
// });
118+
//});
119+
120+
//when we leave the editor (maybe)
121+
editor.on('blur', function (e) {
122+
editor.save();
123+
angularHelper.safeApply($scope, function () {
124+
$scope.model.value = editor.getContent();
125+
});
126+
});
127+
128+
//when buttons modify content
129+
editor.on('ExecCommand', function (e) {
130+
editor.save();
113131
angularHelper.safeApply($scope, function () {
114132
$scope.model.value = editor.getContent();
115133
});
116134
});
117135

118-
editor.on('blur', function (e) {
136+
// Update model on keypress
137+
editor.on('KeyUp', function (e) {
138+
editor.save();
139+
angularHelper.safeApply($scope, function () {
140+
$scope.model.value = editor.getContent();
141+
});
142+
});
143+
144+
// Update model on change, i.e. copy/pasted text, plugins altering content
145+
editor.on('SetContent', function (e) {
146+
if(!e.initial){
147+
editor.save();
119148
angularHelper.safeApply($scope, function () {
120149
$scope.model.value = editor.getContent();
121150
});
151+
}
152+
});
153+
154+
155+
editor.on('ObjectResized', function(e) {
156+
var qs = "?width=" + e.width + "px&height=" + e.height + "px";
157+
var srcAttr = $(e.target).attr("src");
158+
var path = srcAttr.split("?")[0];
159+
$(e.target).attr("data-mce-src", path + qs);
122160
});
123-
161+
162+
124163
//Create the insert media plugin
125164
tinyMceService.createMediaPicker(editor, $scope);
126165

@@ -165,7 +204,6 @@ angular.module("umbraco")
165204

166205
//listen for formSubmitting event (the result is callback used to remove the event subscription)
167206
var unsubscribe = $scope.$on("formSubmitting", function () {
168-
169207
//TODO: Here we should parse out the macro rendered content so we can save on a lot of bytes in data xfer
170208
// we do parse it out on the server side but would be nice to do that on the client side before as well.
171209
$scope.model.value = tinyMceEditor.getContent();

0 commit comments

Comments
 (0)