Skip to content
This repository was archived by the owner on Dec 13, 2017. It is now read-only.

Commit 85012d0

Browse files
Fixes some problems with images and blockquotes. #842
1 parent 5d4abf2 commit 85012d0

1 file changed

Lines changed: 47 additions & 29 deletions

File tree

Assets/ZSSRichTextEditor.js

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -806,16 +806,35 @@ ZSSEditor.insertImage = function(url, alt) {
806806
* does not check for that. It would be a mistake.
807807
*/
808808
ZSSEditor.insertLocalImage = function(imageNodeIdentifier, localImageUrl) {
809-
var progressIdentifier = this.getImageProgressIdentifier(imageNodeIdentifier);
810-
var imageContainerIdentifier = this.getImageContainerIdentifier(imageNodeIdentifier);
811-
var imgContainerStart = '<span id="' + imageContainerIdentifier+'" class="img_container">';
812-
var imgContainerEnd = '</span>';
813-
var progress = '<progress id="' + progressIdentifier+'" value=0 class="wp_media_indicator"></progress>';
814-
var image = '<img data-wpid="' + imageNodeIdentifier + '" src="' + localImageUrl + '" alt="" />';
815-
var html = imgContainerStart + progress+image + imgContainerEnd;
816-
817-
this.insertHTML(html);
818-
this.sendEnabledStyles();
809+
810+
if (window.getSelection) {
811+
sel = window.getSelection();
812+
if (sel.getRangeAt && sel.rangeCount) {
813+
var progressIdentifier = this.getImageProgressIdentifier(imageNodeIdentifier);
814+
815+
var span = document.createElement("span");
816+
span.id = imageNodeIdentifier;
817+
span.className = "img_container";
818+
819+
var progress = document.createElement("progress");
820+
progress.id = progressIdentifier;
821+
progress.value = 0;
822+
progress.className = "wp_media_indicator";
823+
824+
var image = document.createElement("img");
825+
image.setAttribute("data-wpid", imageNodeIdentifier);
826+
image.src = localImageUrl;
827+
image.alt = "";
828+
829+
span.appendChild(progress);
830+
span.appendChild(image);
831+
832+
range = sel.getRangeAt(0);
833+
range.insertNode(span);
834+
835+
this.sendEnabledStyles();
836+
}
837+
}
819838
};
820839

821840
ZSSEditor.getImageNodeWithIdentifier = function(imageNodeIdentifier) {
@@ -932,36 +951,35 @@ ZSSEditor.setProgressOnImage = function(imageNodeIdentifier, progress) {
932951
* @brief Notifies that the image upload as finished
933952
*
934953
* @param imageNodeIdentifier The unique image ID for the uploaded image
935-
* @param image The image to be replaces
954+
* @param image The image to be replaced.
936955
* @param mediaID An integer that is the mediaID of the image on the server
937956
*/
938957
ZSSEditor.markImageUploadDone = function(imageNodeIdentifier, image, mediaID) {
958+
959+
var progressId = this.getImageProgressIdentifier(imageNodeIdentifier);
960+
var container = this.getImageContainerNodeWithIdentifier(imageNodeIdentifier)
961+
962+
this.log("Completing image: " + imageNodeIdentifier);
963+
this.log("Removing progress: " + progressId);
964+
965+
// Remove the progress bar from the DOM.
966+
$("#" + progressId).remove();
967+
968+
// Unwrap the image from the image container, leaving it wrapped inside a link
939969
var imageNode = this.getImageNodeWithIdentifier(imageNodeIdentifier);
940-
if (imageNode.length > 0){
941-
// remove identifier attributed from image
942-
imageNode.removeAttr('data-wpid');
943-
944-
// remove uploading style
970+
971+
if (imageNode.length > 0) {
972+
imageNode.unwrap();
973+
imageNode.wrap("<a href='" + image.src + "'></a>");
945974
imageNode.removeClass("uploading");
975+
imageNode.removeAttr('data-wpid');
946976
imageNode.removeAttr("class");
947-
948-
// set remote source
949977
imageNode.attr('src', image.src);
950-
// set attributes
951978
imageNode.attr({'width':image.width, 'height':image.height, 'class':'alignnone size-full'});
979+
952980
if (mediaID >= 0) {
953981
imageNode.addClass('wp-image-' + mediaID);
954982
}
955-
956-
// Remove all extra formatting nodes for progress
957-
if (imageNode.parent().attr("id") == this.getImageContainerIdentifier(imageNodeIdentifier)) {
958-
// remove id from container to avoid to report a user removal
959-
imageNode.parent().attr("id", "");
960-
imageNode.parent().replaceWith(imageNode);
961-
}
962-
// Wrap link around image
963-
var linkTag = '<a href="' + imageNode.attr("src") + '"></a>';
964-
imageNode.wrap(linkTag);
965983
}
966984

967985
var joinedArguments = ZSSEditor.getJoinedFocusedFieldIdAndCaretArguments();

0 commit comments

Comments
 (0)