Vlad Kurkin (b_vladi) wrote in changelog,
Vlad Kurkin
b_vladi
changelog

[livejournal] r20553: LJSUP-10427: lj-cut was moving to the st...

Committer: vkurkin
LJSUP-10427: lj-cut was moving to the start of post
U   trunk/htdocs/js/ck/plugins/livejournal/plugin.js
Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js
===================================================================
--- trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2011-11-16 11:31:35 UTC (rev 20552)
+++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2011-11-17 09:12:53 UTC (rev 20553)
@@ -652,46 +652,36 @@
 					} else {
 						if (text = prompt(top.CKLang.CutPrompt, top.CKLang.ReadMore)) {
 							var selection = new CKEDITOR.dom.selection(editor.document),
-								ranges = selection.getRanges();
+								ranges = selection.getRanges(),
+								startContainer,
+								iframeOpen = new CKEDITOR.dom.element('iframe', editor.document),
+								iframeClose = new CKEDITOR.dom.element('iframe', editor.document);
 
-							var startContainer = selection.getRanges()[0].getTouchedStartNode();
-
-							if(startContainer){
-								if (startContainer.type == 1 && !startContainer.is('body')) {
-									startContainer = startContainer.getPrevious();
-								}
-							} else {
-								startContainer = editor.document.getBody();
-							}
-
-							var fragment = new CKEDITOR.dom.documentFragment(editor.document);
-
-							var iframeOpen = new CKEDITOR.dom.element('iframe', editor.document);
 							iframeOpen.setAttribute('lj-cmd', 'LJCut');
 							iframeOpen.addClass('lj-cut lj-cut-open');
 							iframeOpen.setAttribute('frameBorder', 0);
 							iframeOpen.setAttribute('allowTransparency', 'true');
-							fragment.append(iframeOpen);
-
-							for (var i = 0, l = ranges.length; i < l; i++) {
-								var range = ranges[i];
-								fragment.append(range.extractContents());
+							if (text != top.CKLang.ReadMore) {
+								iframeOpen.setAttribute('text', text);
 							}
 
-							var iframeClose = new CKEDITOR.dom.element('iframe', editor.document);
 							iframeClose.addClass('lj-cut lj-cut-close');
 							iframeClose.setAttribute('frameBorder', 0);
 							iframeClose.setAttribute('allowTransparency', 'true');
-							fragment.append(iframeClose);
 
-							if (text != top.CKLang.ReadMore) {
-								iframeOpen.setAttribute('text', text);
-							}
-
-							if (startContainer.is && startContainer.is('body')) {
-								startContainer.append(fragment, true);
+							if(ranges[0].collapsed === true){
+								editor.insertElement(iframeClose);
+								iframeClose.insertBeforeMe(iframeOpen);
 							} else {
-								fragment.insertAfterNode(startContainer);
+								startContainer = ranges[0].getTouchedStartNode();
+
+								var fragment = new CKEDITOR.dom.documentFragment(editor.document);
+								fragment.append(iframeOpen);
+								for (var i = 0, l = ranges.length; i < l; i++) {
+									fragment.append(ranges[i].extractContents());
+								}
+								editor.insertElement(iframeClose);
+								iframeClose.insertBeforeMe(fragment);
 							}
 						}
 

Tags: b_vladi, js, livejournal, vkurkin
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments