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

[livejournal] r20532: SUP-10289 Replace block elements in RTE ...

Committer: vkurkin
SUP-10289 Replace block elements in RTE with iframes - stage 2
U   trunk/htdocs/js/ck/plugins/livejournal/plugin.js
U   trunk/htdocs/js/rte.js
Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js
===================================================================
--- trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2011-11-14 07:38:59 UTC (rev 20531)
+++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2011-11-15 04:08:46 UTC (rev 20532)
@@ -1,22 +1,19 @@
-(function(){
+(function() {
 	var dtd = CKEDITOR.dtd;
 
-	dtd.$block['lj:template'] = 1;
-	dtd.$block['lj:raw'] = 1;
-	dtd.$block['lj:cut'] = 1;
-
-	CKEDITOR.tools.extend(dtd.div, dtd.$block);
-	CKEDITOR.tools.extend(dtd.$body, dtd.$block);
-	dtd.$nonEditable['lj:template'] = 1;
-
-	dtd['lj:template'] = {};
-	dtd['lj:raw'] = dtd.div;
-	dtd['lj:cut'] = dtd.div;
-
+	dtd.$block['lj-template'] = 1;
+	dtd.$block['lj-raw'] = 1;
+	dtd.$block['lj-cut'] = 1;
 	dtd.$block['lj-poll'] = 1;
 	dtd.$block['lj-pq'] = 1;
 	dtd.$block['lj-pi'] = 1;
+	dtd.$nonEditable['lj-template'] = 1;
 
+	dtd['lj-template'] = {};
+	dtd['lj-map'] = {};
+	dtd['lj-raw'] = dtd.div;
+	dtd['lj-cut'] = dtd.div;
+
 	dtd['lj-poll'] = {
 		'lj-pq': 1
 	};
@@ -33,6 +30,11 @@
 	dtd.$block.iframe = dtd.$inline.iframe;
 	delete dtd.$inline.iframe;
 
+	CKEDITOR.tools.extend(dtd.div, dtd.$block);
+	CKEDITOR.tools.extend(dtd.$body, dtd.$block);
+
+	delete dtd['lj-cut']['lj-cut'];
+
 	var likeButtons = [
 		{
 			label: top.CKLang.LJLike_button_facebook,
@@ -95,7 +97,7 @@
 	var ljUsers = {};
 	var execFromEditor;
 
-	function createNote(editor){
+	function createNote(editor) {
 		var timer,
 			state,
 			currentData,
@@ -103,7 +105,7 @@
 			noteNode = document.createElement('lj-note'),
 			isIE = typeof(document.body.style.opacity) != 'string';
 
-		var animate = (function(){
+		var animate = (function() {
 			var fps = 60,
 				totalTime = 100,
 				steps = totalTime * fps / 1000,
@@ -111,36 +113,36 @@
 				type,
 				parentContainer = document.getElementById('draft-container') || document.body;
 
-			function apply(){
+			function apply() {
 				var data = timeOuts.shift();
 				var currentStep = (type ? data.time / totalTime : -(data.time / totalTime - 1)).toFixed(1);
 
-				if(!timeOuts.length){
+				if (!timeOuts.length) {
 					currentStep = type ? 1 : 0;
 				}
 
-				if(isIE){
+				if (isIE) {
 					noteNode.style.filter = (currentStep >= 1) ? null : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (currentStep * 100) + ')';
 				} else {
 					noteNode.style.opacity = currentStep;
 				}
 
-				if(currentStep == 0 && noteNode && noteNode.parentNode){
+				if (currentStep == 0 && noteNode && noteNode.parentNode) {
 					noteNode.parentNode.removeChild(noteNode);
 				}
 			}
 
-			return function(animateType){
+			return function(animateType) {
 				type = animateType;
 
-				if(type && noteNode.parentNode){
-					if(isIE){
+				if (type && noteNode.parentNode) {
+					if (isIE) {
 						noteNode.style.filter = null;
 					} else {
 						noteNode.style.opacity = 1;
 					}
 				} else {
-					for(var i = 1; i <= steps; i++){
+					for (var i = 1; i <= steps; i++) {
 						var time = Math.floor(1000 / fps) * i;
 						timeOuts.push({
 							time: time,
@@ -157,29 +159,29 @@
 
 		noteNode.className = 'note-popup';
 
-		noteNode.onmouseout = function(){
-			if(!currentData || !currentData.cmd){
+		noteNode.onmouseout = function() {
+			if (!currentData || !currentData.cmd) {
 				CKEDITOR.note.hide();
 			}
 		};
 
-		noteNode.onmouseover = function(){
-			if(timer && !state){
+		noteNode.onmouseover = function() {
+			if (timer && !state) {
 				state = 1;
 				clearTimeout(timer);
 				timer = null;
 			}
 		};
 
-		if(isIE){
+		if (isIE) {
 			noteNode.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
 		} else {
 			noteNode.style.opacity = 0;
 		}
 
-		function callCmd(){
+		function callCmd() {
 			var cmd = this.getAttribute('lj-cmd');
-			if(currentData.hasOwnProperty(cmd)){
+			if (currentData.hasOwnProperty(cmd)) {
 				ljTagsData[cmd].node = currentData[cmd].node;
 				var selection = new CKEDITOR.dom.selection(editor.document);
 				selection.selectElement(ljTagsData[cmd].node);
@@ -190,17 +192,17 @@
 			return false;
 		}
 
-		function applyNote(){
-			if(!window.switchedRteOn){
+		function applyNote() {
+			if (!window.switchedRteOn) {
 				CKEDITOR.note.hide(true);
 			}
-			if(state){
+			if (state) {
 				currentData = tempData;
 				tempData = null;
 
 				var html = '';
-				for(var cmd in currentData){
-					if(currentData.hasOwnProperty(cmd)){
+				for (var cmd in currentData) {
+					if (currentData.hasOwnProperty(cmd)) {
 						html += '<div class="noteItem">' + currentData[cmd].content + '</div>';
 					}
 				}
@@ -208,9 +210,9 @@
 				noteNode.innerHTML = decodeURIComponent(html);
 
 				var links = noteNode.getElementsByTagName('a');
-				for(var i = 0, l = links.length; i < l; i++){
+				for (var i = 0, l = links.length; i < l; i++) {
 					var link = links[i];
-					if(ljTagsData.hasOwnProperty(link.getAttribute('lj-cmd'))){
+					if (ljTagsData.hasOwnProperty(link.getAttribute('lj-cmd'))) {
 						link.onclick = callCmd;
 					}
 				}
@@ -224,12 +226,12 @@
 		}
 
 		CKEDITOR.note = {
-			show: function(data, isNow){
-				if((!isNow && data == tempData) || window.swi){
+			show: function(data, isNow) {
+				if ((!isNow && data == tempData) || window.swi) {
 					return;
 				}
 
-				if(timer){
+				if (timer) {
 					clearTimeout(timer);
 					timer = null;
 				}
@@ -240,16 +242,16 @@
 
 				isNow === true ? applyNote() : timer = setTimeout(applyNote, 1000);
 			},
-			hide: function(isNow){
-				if(state){
+			hide: function(isNow) {
+				if (state) {
 					state = 0;
 
-					if(timer){
+					if (timer) {
 						clearTimeout(timer);
 						timer = null;
 					}
 
-					if(noteNode.parentNode){
+					if (noteNode.parentNode) {
 						isNow === true ? applyNote() : timer = setTimeout(applyNote, 500);
 					}
 				}
@@ -258,50 +260,51 @@
 	}
 
 	CKEDITOR.plugins.add('livejournal', {
-		init: function(editor){
+		init: function(editor) {
 			editor.addCss('.lj_selected {' + 'background-color: #C4E0F7 !important;' + 'border: 1px solid #6EA9DF !important;' + '}');
 
-			function onClickFrame(evt){
-				if(this.$ != editor.document.$){
+			function onClickFrame(evt) {
+				if (this.$ != editor.document.$) {
+					this.frameElement.addClass('lj_selected');
 					new CKEDITOR.dom.selection(editor.document).selectElement(this.frameElement);
 				}
 
 				evt.data.getKey() == 1 && evt.data.preventDefault();
 			}
 
-			function onKeyUp(evt){
-				if(evt.data.getKey() == 46){
+			function onKeyUp(evt) {
+				if (evt.data.getKey() == 46) {
 					var ranges = new CKEDITOR.dom.selection(editor.document).getRanges();
 					var length = ranges.length;
-					while(length--){
+					while (length--) {
 						ranges[length].deleteContents();
 					}
 				}
 			}
 
-			function onLoadFrame(){
+			function onLoadFrame() {
 				var win = this.$.contentWindow;
 				var doc = win.document;
-				if(win.frameElement.getAttribute('lj-cmd') && doc.body.scrollHeight){
+				if (win.frameElement.getAttribute('lj-cmd') && doc.body.scrollHeight) {
 					this.setStyle('height', doc.body.scrollHeight + 'px');
 				}
 
 				var body = new CKEDITOR.dom.element.get(doc.body);
 				body.on('dblclick', onDoubleClick);
 				body.on('click', onClickFrame);
+				body.on('keyup', onKeyUp);
 
 				doc = new CKEDITOR.dom.element.get(doc);
-				doc.on('keyup', onKeyUp);
 
 				doc.frameElement = body.frameElement = this;
 			}
 
-			function updateFrames(){
+			function updateFrames() {
 				execFromEditor = false;
 				var frames = editor.document.getElementsByTag('iframe');
 				var length = frames.count();
 
-				while(length--){
+				while (length--) {
 					var iFrameCss = 'widht: 100%; margin: 0; padding 0; overflow-y: hidden;',
 						frame = frames.getItem(length),
 						cmd = frame.getAttribute('lj-cmd'),
@@ -309,7 +312,7 @@
 						doc = frameWin.document,
 						ljStyle = frame.getAttribute('lj-style');
 
-					if(ljStyle){
+					if (ljStyle) {
 						iFrameCss += ljStyle;
 					}
 
@@ -321,30 +324,35 @@
 				}
 			}
 
-			function findLJTags(evt){
+			function findLJTags(evt) {
 				var noteData,
 					isSelection = evt.name == 'selectionChange' || evt.name == 'click',
 					target = evt.data.element || evt.data.getTarget(),
 					node,
 					command;
 
-				if(evt.name == 'click' && (evt.data.getKey() == 1 || evt.data.$.button == 0)){
+				if (editor.onSwitch === true) {
+					delete editor.onSwitch;
+					return;
+				}
+
+				if (evt.name == 'click' && (evt.data.getKey() == 1 || evt.data.$.button == 0)) {
 					evt.data.preventDefault();
 				}
 
-				if(target.type != 1){
+				if (target.type != 1) {
 					target = target.getParent();
 				}
 
 				node = target;
 
-				if(isSelection){
+				if (isSelection) {
 					var frames = editor.document.getElementsByTag('iframe');
-					for(var i = 0, l = frames.count(); i < l; i++){
+					for (var i = 0, l = frames.count(); i < l; i++) {
 						frames.getItem(i).removeClass('lj_selected');
 					}
 
-					if(node.is('iframe')){
+					if (node.is('iframe')) {
 						node.addClass('lj_selected');
 					}
 				}
@@ -352,19 +360,19 @@
 				do {
 					var attr = node.getAttribute('lj-cmd');
 
-					if(!attr && node.type == 1){
+					if (!attr && node.type == 1) {
 						var parent = node.getParent();
-						if(node.is('img') && parent.getParent() && !parent.getParent().hasAttribute('lj:user')){
+						if (node.is('img') && parent.getParent() && !parent.getParent().hasAttribute('lj:user')) {
 							attr = 'image';
 							node.setAttribute('lj-cmd', attr);
-						} else if(node.is('a') && !parent.hasAttribute('lj:user')){
+						} else if (node.is('a') && !parent.hasAttribute('lj:user')) {
 							attr = 'LJLink';
 							node.setAttribute('lj-cmd', attr);
 						}
 					}
 
-					if(attr && ljTagsData.hasOwnProperty(attr)){
-						if(isSelection){
+					if (attr && ljTagsData.hasOwnProperty(attr)) {
+						if (isSelection) {
 							ljTagsData[attr].node = node;
 							editor.getCommand(attr).setState(CKEDITOR.TRISTATE_ON);
 						}
@@ -373,11 +381,11 @@
 							node: node
 						};
 					}
-				} while(node = node.getParent());
+				} while (node = node.getParent());
 
-				if(isSelection){
-					for(command in ljTagsData){
-						if(ljTagsData.hasOwnProperty(command) && (!noteData || !noteData.hasOwnProperty(command))){
+				if (isSelection) {
+					for (command in ljTagsData) {
+						if (ljTagsData.hasOwnProperty(command) && (!noteData || !noteData.hasOwnProperty(command))) {
 							delete ljTagsData[command].node;
 							editor.getCommand(command).setState(CKEDITOR.TRISTATE_OFF);
 						}
@@ -387,33 +395,33 @@
 				noteData ? CKEDITOR.note.show(noteData) : CKEDITOR.note.hide();
 			}
 
-			editor.dataProcessor.toHtml = function(html, fixForBody){
+			editor.dataProcessor.toHtml = function(html, fixForBody) {
 				html = html.replace(/(<lj [^>]+)(?!\/)>/gi, '$1 />').replace(/(<lj-map[^>]+)(?!\/)>/gi, '$1 />').replace(/(<lj-template[^>]*)(?!\/)>/gi, '$1 />').replace(/<((?!br)[^\s>]+)([^>]*?)\/>/gi, '<$1$2></$1>').replace(/<lj-poll.*?>[\s\S]*?<\/lj-poll>/gi,
-					function(ljtags){
+					function(ljtags) {
 						var poll = new Poll(ljtags);
 						return '<iframe class="lj-poll" frameborder="0" allowTransparency="true" ' + 'lj-cmd="LJPollLink" lj-data="' + poll.outputLJtags() + '" lj-content="' + poll.outputHTML() + '"></iframe>';
-					}).replace(/<lj-embed(.*?)>([\s\S]*?)<\/lj-embed>/gi, function(result, attrs, data){
-						return '<iframe' + attrs + ' class="lj-embed" lj-style="height: 100%;" lj-data="' + encodeURIComponent(data) + '" frameborder="0" allowTransparency="true"></iframe>';
+					}).replace(/<lj-embed(.*?)>([\s\S]*?)<\/lj-embed>/gi, function(result, attrs, data) {
+						return '<iframe' + attrs + ' class="lj-embed" lj-data="' + encodeURIComponent(data) + '" frameborder="0" allowTransparency="true"></iframe>';
 					});
 
-				if(!$('event_format').checked){
+				if (!$('event_format').checked) {
 					html = html.replace(/(<lj-raw.*?>)([\s\S]*?)(<\/lj-raw>)/gi,
-						function(result, open, content, close){
+						function(result, open, content, close) {
 							return open + content.replace(/\n/g, '') + close;
 						}).replace(/\n/g, '<br />');
 				}
 
 				html = CKEDITOR.htmlDataProcessor.prototype.toHtml.call(this, html, fixForBody);
-				if(CKEDITOR.env.ie){
+				if (CKEDITOR.env.ie) {
 					html = '<xml:namespace ns="livejournal" prefix="lj" />' + html;
 				}
 				return html;
 			};
 
-			editor.dataProcessor.toDataFormat = function(html, fixForBody){
+			editor.dataProcessor.toDataFormat = function(html, fixForBody) {
 				html = CKEDITOR.htmlDataProcessor.prototype.toDataFormat.call(this, html, fixForBody);
 
-				if(!$('event_format').checked){
+				if (!$('event_format').checked) {
 					html = html.replace(/<br\s*\/>/gi, '\n');
 				}
 
@@ -425,18 +433,18 @@
 			editor.dataProcessor.writer.indentationChars = '';
 			editor.dataProcessor.writer.lineBreakChars = '';
 
-			function onDoubleClick(evt){
+			function onDoubleClick(evt) {
 				var node = evt.data.element || evt.data.getTarget();
 
-				if(node.type != 1){
+				if (node.type != 1) {
 					node = node.getParent();
 				}
 
-				while(node){
+				while (node) {
 					var cmdName = node.getAttribute('lj-cmd');
-					if(ljTagsData.hasOwnProperty(cmdName)){
+					if (ljTagsData.hasOwnProperty(cmdName)) {
 						var cmd = editor.getCommand(cmdName);
-						if(cmd.state == CKEDITOR.TRISTATE_ON){
+						if (cmd.state == CKEDITOR.TRISTATE_ON) {
 							var selection = new CKEDITOR.dom.selection(editor.document);
 							ljTagsData[cmdName].node = node.is('body') ? new CKEDITOR.dom.element.get(node.getWindow().$.frameElement) : node;
 							selection.selectElement(ljTagsData[cmdName].node);
@@ -453,7 +461,7 @@
 
 			var styleSheet = '';
 
-			CKEDITOR.ajax.load(editor.config.contentsCss, function(data){
+			CKEDITOR.ajax.load(editor.config.contentsCss, function(data) {
 				styleSheet = data;
 			});
 
@@ -461,15 +469,15 @@
 			editor.on('doubleclick', onDoubleClick);
 			editor.on('afterCommandExec', updateFrames);
 			editor.on('dialogHide', updateFrames);
-			editor.on('dataReady', function(){
-				if(!CKEDITOR.note){
+			editor.on('dataReady', function() {
+				if (!CKEDITOR.note) {
 					createNote(editor);
 				}
 
 				editor.document.on('click', findLJTags);
 				editor.document.on('mouseout', CKEDITOR.note.hide);
 				editor.document.on('mouseover', findLJTags);
-				editor.document.on('keyup', onKeyUp);
+				editor.document.getBody().on('keyup', onKeyUp);
 				updateFrames();
 			});
 
@@ -477,25 +485,25 @@
 			var url = top.Site.siteroot + '/tools/endpoints/ljuser.bml';
 
 			editor.addCommand('LJUserLink', {
-				exec: function(editor){
+				exec: function(editor) {
 					var userName = '',
 						selection = new CKEDITOR.dom.selection(editor.document),
 						LJUser = ljTagsData.LJUserLink.node,
 						currentUserName;
 
-					if(LJUser){
+					if (LJUser) {
 						CKEDITOR.note && CKEDITOR.note.hide(true);
 						currentUserName = ljTagsData.LJUserLink.node.getElementsByTag('b').getItem(0).getText();
 						userName = prompt(top.CKLang.UserPrompt, currentUserName);
-					} else if(selection.getType() == 2){
+					} else if (selection.getType() == 2) {
 						userName = selection.getSelectedText();
 					}
 
-					if(userName == ''){
+					if (userName == '') {
 						userName = prompt(top.CKLang.UserPrompt, userName);
 					}
 
-					if(!userName || currentUserName == userName){
+					if (!userName || currentUserName == userName) {
 						return;
 					}
 
@@ -505,12 +513,12 @@
 						}),
 						method: 'POST',
 						url: url,
-						onData: function(data){
-							if(data.error){
+						onData: function(data) {
+							if (data.error) {
 								alert(data.error);
 								return;
 							}
-							if(!data.success){
+							if (!data.success) {
 								return;
 							}
 							data.ljuser = data.ljuser.replace('<span class="useralias-value">*</span>', '');
@@ -520,7 +528,7 @@
 							var tmpNode = new CKEDITOR.dom.element.createFromHtml(data.ljuser);
 							tmpNode.setAttribute('lj-cmd', 'LJUserLink');
 
-							if(LJUser){
+							if (LJUser) {
 								LJUser.$.parentNode.replaceChild(tmpNode.$, LJUser.$);
 							} else {
 								editor.insertElement(tmpNode);
@@ -541,14 +549,14 @@
 				command: 'image'
 			});
 
-			if(window.ljphotoEnabled){
+			if (window.ljphotoEnabled) {
 				editor.addCommand('LJImage_beta', {
-					exec: function(editor){
+					exec: function(editor) {
 						jQuery('#updateForm').photouploader({
 							type: 'upload'
-						}).photouploader('show').bind('htmlready', function (event){
+						}).photouploader('show').bind('htmlready', function (event) {
 								var html = event.htmlStrings;
-								for(var i = 0, l = html.length; i < l; i++){
+								for (var i = 0, l = html.length; i < l; i++) {
 									editor.insertElement(new CKEDITOR.dom.element.createFromHtml(html[i], editor.document));
 								}
 							});
@@ -564,7 +572,7 @@
 
 			//////////  LJ Link Button //////////////
 			editor.addCommand('LJLink', {
-				exec: function(editor){
+				exec: function(editor) {
 					!execFromEditor && this.state == CKEDITOR.TRISTATE_ON ? editor.execCommand('unlink') : editor.openDialog('link');
 					CKEDITOR.note && CKEDITOR.note.hide(true);
 				},
@@ -578,7 +586,7 @@
 
 			//////////  LJ Embed Media Button //////////////
 			editor.addCommand('LJEmbedLink', {
-				exec: function(){
+				exec: function() {
 					top.LJ_IPPU.textPrompt(top.CKLang.LJEmbedPromptTitle, top.CKLang.LJEmbedPrompt, doEmbed, {
 						width: '350px'
 					});
@@ -592,12 +600,11 @@
 
 			editor.addCss('.lj-embed {' + 'background: #CCCCCC url(' + CKEDITOR.getUrl(this.path + 'images/placeholder_flash.png') + ') no-repeat center center;' + 'border: 1px dotted #000000;' + 'height: 80px;' + 'width: 100%;' + '}');
 
-			function doEmbed(content){
-				if(content && content.length){
-					if(window.switchedRteOn){
+			function doEmbed(content) {
+				if (content && content.length) {
+					if (window.switchedRteOn) {
 						var iframe = new CKEDITOR.dom.element('iframe', editor.document);
 						iframe.setAttribute('lj-data', encodeURIComponent(content));
-						iframe.setAttribute('lj-style', 'height: 100%;');
 						iframe.setAttribute('class', 'lj-embed');
 						iframe.setAttribute('frameBorder', 0);
 						iframe.setAttribute('allowTransparency', 'true');
@@ -608,43 +615,61 @@
 			}
 
 			//////////  LJ Cut Button //////////////
+			editor.addCss('.lj-cut {' + 'width: 100%;' + 'height: 20px;' + 'display: block;' + 'border: #000 1px dotted;' + 'background-color: #d2d2d2;' + 'min-height: 14px;' + '}');
+
 			editor.addCommand('LJCut', {
-				exec: function(){
+				exec: function() {
 					var text,
 						ljCutNode = ljTagsData.LJCut.node;
 
-					if(ljCutNode){
-						if(text = prompt(top.CKLang.CutPrompt, ljCutNode.getAttribute('text') || top.CKLang.ReadMore)){
-							if(text == top.CKLang.ReadMore){
+					if (ljCutNode) {
+						if (text = prompt(top.CKLang.CutPrompt, ljCutNode.getAttribute('text') || top.CKLang.ReadMore)) {
+							if (text == top.CKLang.ReadMore) {
 								ljCutNode.removeAttribute('text');
 							} else {
 								ljCutNode.setAttribute('text', text);
 							}
 						}
 					} else {
-						if(text = prompt(top.CKLang.CutPrompt, top.CKLang.ReadMore)){
-							var selection = new CKEDITOR.dom.selection(editor.document);
+						if (text = prompt(top.CKLang.CutPrompt, top.CKLang.ReadMore)) {
+							var selection = new CKEDITOR.dom.selection(editor.document),
+								ranges = selection.getRanges();
 
-							ljTagsData.LJCut.node = new CKEDITOR.dom.element.get(document.createElement('lj:cut'));
-							ljTagsData.LJCut.node.setAttribute('lj-cmd', 'LJCut');
+							var fragment = new CKEDITOR.dom.documentFragment(editor.document);
 
-							if(text != top.CKLang.ReadMore){
-								ljTagsData.LJCut.node.setAttribute('text', text);
-							}
+							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);
 
-							var ranges = selection.getRanges();
-							selection.lock();
-							for(var i = 0, l = ranges.length; i < l; i++){
+							for (var i = 0, l = ranges.length; i < l; i++) {
 								var range = ranges[i];
-								range.cloneContents().appendTo(ljTagsData.LJCut.node);
+								fragment.append(range.extractContents());
 							}
-							selection.unlock();
-							editor.insertElement(ljTagsData.LJCut.node);
-							selection.selectElement(ljTagsData.LJCut.node);
+
+							var iframeClose = new CKEDITOR.dom.element('iframe', editor.document);
+							iframeClose.addClass('lj-cut lj-cut-close');
+							iframeClose.setAttribute('lj-cmd', 'LJCut');
+							iframeClose.setAttribute('frameBorder', 0);
+							iframeClose.setAttribute('allowTransparency', 'true');
+							fragment.append(iframeClose);
+
+							if (text != top.CKLang.ReadMore) {
+								iframeOpen.setAttribute('text', text);
+							}
+
+							var startContainer = selection.getRanges()[0].startContainer;
+							if (startContainer.type == 1 && startContainer.is('body')) {
+								startContainer.append(fragment);
+							} else {
+								fragment.insertAfterNode(startContainer);
+							}
 						}
+
+						CKEDITOR.note && CKEDITOR.note.hide(true);
 					}
-
-					CKEDITOR.note && CKEDITOR.note.hide(true);
 				},
 				editorFocus: false
 			});
@@ -655,21 +680,21 @@
 			});
 
 			//////////  LJ Justify //////////////
-			(function(){
-				function getAlignment(element, useComputedState){
+			(function() {
+				function getAlignment(element, useComputedState) {
 					useComputedState = useComputedState === undefined || useComputedState;
 
 					var align,
 						LJLike = ljTagsData.LJLike.node;
-					if(LJLike){
+					if (LJLike) {
 						var attr = element.getAttribute('lj-style');
 						align = attr ? attr.replace(/text-align:\s*(left|right|center)/i, '$1') : 'left';
-					} else if(useComputedState){
+					} else if (useComputedState) {
 						align = element.getComputedStyle('text-align');
 					} else {
-						while(!element.hasAttribute || !( element.hasAttribute('align') || element.getStyle('text-align') )){
+						while (!element.hasAttribute || !( element.hasAttribute('align') || element.getStyle('text-align') )) {
 							var parent = element.getParent();
-							if(!parent){
+							if (!parent) {
 								break;
 							}
 							element = parent;
@@ -684,17 +709,17 @@
 					return align;
 				}
 
-				function onSelectionChange(evt){
-					if(evt.editor.readOnly){
+				function onSelectionChange(evt) {
+					if (evt.editor.readOnly) {
 						return;
 					}
 
 					var command = evt.editor.getCommand(this.name),
 						element = evt.data.element,
 						cmd = element.type == 1 && element.hasAttribute('lj-cmd') && element.getAttribute('lj-cmd');
-					if(cmd == 'LJLike'){
+					if (cmd == 'LJLike') {
 						command.state = (getAlignment(element, editor.config.useComputedState) == this.value) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
-					} else if(!element || element.type != 1 || element.is('body') || element.is('iframe')){
+					} else if (!element || element.type != 1 || element.getName() == 'body' || element.getName() == 'iframe') {
 						command.state = CKEDITOR.TRISTATE_OFF;
 					} else {
 						command.state = getAlignment(element, editor.config.useComputedState) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
@@ -703,13 +728,13 @@
 					command.fire('state');
 				}
 
-				function justifyCommand(editor, name, value){
+				function justifyCommand(editor, name, value) {
 					this.name = name;
 					this.value = value;
 
 					var classes = editor.config.justifyClasses;
-					if(classes){
-						switch(value){
+					if (classes) {
+						switch (value) {
 							case 'left' :
 								this.cssClassName = classes[0];
 								break;
@@ -725,7 +750,7 @@
 					}
 				}
 
-				function onDirChanged(e){
+				function onDirChanged(e) {
 					var editor = e.editor;
 
 					var range = new CKEDITOR.dom.range(editor.document);
@@ -735,10 +760,10 @@
 					var walker = new CKEDITOR.dom.walker(range),
 						node;
 
-					while(( node = walker.next() )){
-						if(node.type == CKEDITOR.NODE_ELEMENT){
+					while (( node = walker.next() )) {
+						if (node.type == CKEDITOR.NODE_ELEMENT) {
 							// A child with the defined dir is to be ignored.
-							if(!node.equals(e.data.node) && node.getDirection()){
+							if (!node.equals(e.data.node) && node.getDirection()) {
 								range.setStartAfter(node);
 								walker = new CKEDITOR.dom.walker(range);
 								continue;
@@ -746,14 +771,14 @@
 
 							// Switch the alignment.
 							var classes = editor.config.justifyClasses;
-							if(classes){
+							if (classes) {
 								// The left align class.
-								if(node.hasClass(classes[ 0 ])){
+								if (node.hasClass(classes[ 0 ])) {
 									node.removeClass(classes[ 0 ]);
 									node.addClass(classes[ 2 ]);
 								}
 								// The right align class.
-								else if(node.hasClass(classes[ 2 ])){
+								else if (node.hasClass(classes[ 2 ])) {
 									node.removeClass(classes[ 2 ]);
 									node.addClass(classes[ 0 ]);
 								}
@@ -763,9 +788,9 @@
 							var style = 'text-align';
 							var align = node.getStyle(style);
 
-							if(align == 'left'){
+							if (align == 'left') {
 								node.setStyle(style, 'right');
-							} else if(align == 'right'){
+							} else if (align == 'right') {
 								node.setStyle(style, 'left');
 							}
 						}
@@ -773,17 +798,17 @@
 				}
 
 				justifyCommand.prototype = {
-					exec : function(editor){
+					exec : function(editor) {
 						var selection = editor.getSelection(),
 							enterMode = editor.config.enterMode;
 
-						if(!selection){
+						if (!selection) {
 							return;
 						}
 
 						var bookmarks = selection.createBookmarks();
 
-						if(ljTagsData.LJLike.node){
+						if (ljTagsData.LJLike.node) {
 							ljTagsData.LJLike.node.setAttribute('lj-style', 'text-align: ' + this.value);
 						} else {
 							var ranges = selection.getRanges(true);
@@ -795,16 +820,16 @@
 							var useComputedState = editor.config.useComputedState;
 							useComputedState = useComputedState === undefined || useComputedState;
 
-							for(var i = ranges.length - 1; i >= 0; i--){
+							for (var i = ranges.length - 1; i >= 0; i--) {
 								var range = ranges[i];
 								var encloseNode = range.getEnclosedNode();
-								if(encloseNode && encloseNode.is('iframe')){
+								if (encloseNode && encloseNode.is('iframe')) {
 									return;
 								}
 
 								iterator = range.createIterator();
 								iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;
-								while(( block = iterator.getNextParagraph(enterMode == CKEDITOR.ENTER_P ? 'p' : 'div') )){
+								while (( block = iterator.getNextParagraph(enterMode == CKEDITOR.ENTER_P ? 'p' : 'div') )) {
 									block.removeAttribute('align');
 									block.removeStyle('text-align');
 
@@ -813,14 +838,14 @@
 
 									var apply = ( this.state == CKEDITOR.TRISTATE_OFF ) && ( !useComputedState || ( getAlignment(block, true) != this.value ) );
 
-									if(cssClassName){
+									if (cssClassName) {
 										// Append the desired class name.
-										if(apply){
+										if (apply) {
 											block.addClass(cssClassName);
-										} else if(!className){
+										} else if (!className) {
 											block.removeAttribute('class');
 										}
-									} else if(apply){
+									} else if (apply) {
 										block.setStyle('text-align', this.value);
 									}
 								}
@@ -862,19 +887,19 @@
 			})();
 
 			//////////  LJ Poll Button //////////////
-			if(top.canmakepoll){
+			if (top.canmakepoll) {
 				var currentPoll;
 
 				editor.addCss('.lj-poll {' + 'width:100%;' + 'border: #000 1px dotted;' + 'background-color: #d2d2d2;' + 'font-style: italic;' + '}');
 
-				CKEDITOR.dialog.add('LJPollDialog', function(){
+				CKEDITOR.dialog.add('LJPollDialog', function() {
 					var isAllFrameLoad = 0, okButtonNode, questionsWindow, setupWindow;
 
-					var onLoadPollPage = function(){
-						if(this.removeListener){
+					var onLoadPollPage = function() {
+						if (this.removeListener) {
 							this.removeListener('load', onLoadPollPage);
 						}
-						if(isAllFrameLoad && okButtonNode){
+						if (isAllFrameLoad && okButtonNode) {
 							currentPoll = new Poll(ljTagsData.LJPollLink.node && decodeURIComponent(ljTagsData.LJPollLink.node.getAttribute('lj-data')), questionsWindow.document, setupWindow.document, questionsWindow.Questions);
 
 							questionsWindow.ready(currentPoll);
@@ -891,14 +916,14 @@
 						type: 'button',
 						id: 'LJPoll_Ok',
 						label: editor.lang.common.ok,
-						onClick: function(evt){
+						onClick: function(evt) {
 							evt.data.dialog.hide();
 							var poll = new Poll(currentPoll, questionsWindow.document, setupWindow.document, questionsWindow.Questions);
 							var pollSource = poll.outputHTML();
 							var pollLJTags = poll.outputLJtags();
 
-							if(pollSource.length > 0){
-								if(ljTagsData.LJPollLink.node){
+							if (pollSource.length > 0) {
+								if (ljTagsData.LJPollLink.node) {
 									ljTagsData.LJPollLink.node.setAttribute('lj-content', pollSource);
 									ljTagsData.LJPollLink.node.setAttribute('lj-data', pollLJTags);
 								} else {
@@ -924,8 +949,8 @@
 						width: 420,
 						height: 270,
 						resizable: false,
-						onShow: function(){
-							if(isAllFrameLoad){
+						onShow: function() {
+							if (isAllFrameLoad) {
 								currentPoll = new Poll(ljTagsData.LJPollLink.node && unescape(ljTagsData.LJPollLink.node.getAttribute('data')), questionsWindow.document, setupWindow.document, questionsWindow.Questions);
 
 								questionsWindow.ready(currentPoll);
@@ -941,13 +966,13 @@
 									{
 										type: 'html',
 										html: '<iframe src="/tools/ck_poll_setup.bml" allowTransparency="true" frameborder="0" style="width:100%; height:320px;"></iframe>',
-										onShow: function(data){
-											if(!okButtonNode){
+										onShow: function(data) {
+											if (!okButtonNode) {
 												(okButtonNode = document.getElementById(data.sender.getButton('LJPoll_Ok').domId).parentNode).style.display = 'none';
 											}
 											var iframe = this.getElement('iframe');
 											setupWindow = iframe.$.contentWindow;
-											if(setupWindow.ready){
+											if (setupWindow.ready) {
 												onLoadPollPage();
 											} else {
 												iframe.on('load', onLoadPollPage);
@@ -964,10 +989,10 @@
 									{
 										type: 'html',
 										html: '<iframe src="/tools/ck_poll_questions.bml" allowTransparency="true" frameborder="0" style="width:100%; height:320px;"></iframe>',
-										onShow: function(){
+										onShow: function() {
 											var iframe = this.getElement('iframe');
 											questionsWindow = iframe.$.contentWindow;
-											if(questionsWindow.ready){
+											if (questionsWindow.ready) {
 												onLoadPollPage();
 											} else {
 												iframe.on('load', onLoadPollPage);
@@ -984,7 +1009,7 @@
 				editor.addCommand('LJPollLink', new CKEDITOR.dialogCommand('LJPollDialog'));
 			} else {
 				editor.addCommand('LJPollLink', {
-					exec: function(){
+					exec: function() {
 						CKEDITOR.note && CKEDITOR.note.show(top.CKLang.Poll_AccountLevelNotice, null, null, true);
 					}
 				});
@@ -1004,7 +1029,7 @@
 
 			editor.addCss('.lj-like {' + 'width: 100%;' + 'height: 44px !important;' + 'overflow: hidden;' + 'padding: 0;' + 'margin: 0;' + 'background: #D2D2D2;' + 'border: 1px dotted #000;' + '}');
 
-			for(var i = 0; i < buttonsLength; i++){
+			for (var i = 0; i < buttonsLength; i++) {
 				var button = likeButtons[i];
 				likeButtons[button.id] = likeButtons[button.abbr] = button;
 				likeButtons.defaultButtons.push(button.id);
@@ -1015,21 +1040,21 @@
 
 			var countChanges = 0, ljLikeDialog, ljLikeInputs;
 
-			function onChangeLike(){
+			function onChangeLike() {
 				var command = editor.getCommand('LJLike');
-				if(command.state == CKEDITOR.TRISTATE_OFF){
+				if (command.state == CKEDITOR.TRISTATE_OFF) {
 					this.$.checked ? countChanges++ : countChanges--;
 					ljLikeDialog.getButton('LJLike_Ok').getElement()[countChanges == 0 ? 'addClass' : 'removeClass']('btn-disabled');
 				}
 			}
 
-			CKEDITOR.dialog.add('LJLikeDialog', function(){
+			CKEDITOR.dialog.add('LJLikeDialog', function() {
 				var buttonsDefinition = [new CKEDITOR.ui.button({
 					type: 'button',
 					id: 'LJLike_Ok',
 					label: editor.lang.common.ok,
-					onClick: function(){
-						if(ljLikeDialog.getButton('LJLike_Ok').getElement().hasClass('btn-disabled')){
+					onClick: function() {
+						if (ljLikeDialog.getButton('LJLike_Ok').getElement().hasClass('btn-disabled')) {
 							return false;
 						}
 
@@ -1037,19 +1062,19 @@
 							likeHtml = '<span class="lj-like-wrapper">',
 							likeNode = ljTagsData.LJLike.node;
 
-						for(var i = 0; i < buttonsLength; i++){
+						for (var i = 0; i < buttonsLength; i++) {
 							var button = likeButtons[i];
 							var input = document.getElementById('like-' + button.abbr);
 							var currentBtn = likeNode && likeNode.getAttribute('buttons');
-							if((input && input.checked) || (currentBtn && !button.htmlOpt && (currentBtn.indexOf(button.abbr) + 1 || currentBtn.indexOf(button.id) + 1))){
+							if ((input && input.checked) || (currentBtn && !button.htmlOpt && (currentBtn.indexOf(button.abbr) + 1 || currentBtn.indexOf(button.id) + 1))) {
 								attr.push(button.id);
 								likeHtml += button.html;
 							}
 						}
 
 						likeHtml += '</span>';
-						if(attr.length){
-							if(likeNode){
+						if (attr.length) {
+							if (likeNode) {
 								ljTagsData.LJLike.node.setAttribute('buttons', attr.join(','));
 								ljTagsData.LJLike.node.setAttribute('lj-content', encodeURIComponent(likeHtml));
 							} else {
@@ -1062,7 +1087,7 @@
 								likeNode.setAttribute('allowTransparency', 'true');
 								editor.insertElement(likeNode);
 							}
-						} else if(likeNode){
+						} else if (likeNode) {
 							ljTagsData.LJLike.node.remove();
 						}
 
@@ -1088,20 +1113,20 @@
 							]
 						}
 					],
-					onShow: function(){
+					onShow: function() {
 						CKEDITOR.note && CKEDITOR.note.hide(true);
 						var command = editor.getCommand('LJLike');
 						var i = countChanges = 0,
 							isOn = command.state == CKEDITOR.TRISTATE_ON,
 							buttons = ljTagsData.LJLike.node && ljTagsData.LJLike.node.getAttribute('buttons');
 
-						for(; i < buttonsLength; i++){
+						for (; i < buttonsLength; i++) {
 							var isChecked = buttons ? !!(buttons.indexOf(likeButtons[i].abbr) + 1 || buttons.indexOf(likeButtons[i].id) + 1) : true;
 
 							var input = document.getElementById('like-' + likeButtons[i].abbr);
 
-							if(input){
-								if(isChecked && !isOn){
+							if (input) {
+								if (isChecked && !isOn) {
 									countChanges++;
 								}
 
@@ -1109,14 +1134,14 @@
 							}
 						}
 
-						if(countChanges > 0){
+						if (countChanges > 0) {
 							ljLikeDialog.getButton('LJLike_Ok').getElement().removeClass('btn-disabled');
 						}
 					},
-					onLoad: function(){
+					onLoad: function() {
 						ljLikeDialog = this;
 						ljLikeInputs = ljLikeDialog.parts.contents.getElementsByTag('input');
-						for(var i = 0; i < buttonsLength; i++){
+						for (var i = 0; i < buttonsLength; i++) {
 							var item = ljLikeInputs.getItem(i);
 							item && item.on('click', onChangeLike);
 						}
@@ -1135,17 +1160,39 @@
 			//////////  LJ Map Button & LJ Iframe //////////////
 			editor.addCss('.lj-map, .lj-iframe {' + 'width: 100%;' + 'overflow: hidden;' + 'min-height: 13px;' + 'margin-top: 20px;' + 'background: #D2D2D2;' + 'border: 1px dotted #000;' + 'text-align: center;' + '}');
 		},
-		afterInit: function(editor){
+		afterInit: function(editor) {
 			var dataProcessor = editor.dataProcessor;
 
+			function createLJCut(element) {
+				var openFrame = new CKEDITOR.htmlParser.element('iframe');
+				openFrame.attributes['class'] = 'lj-cut lj-cut-open';
+				openFrame.attributes['lj-cmd'] = 'LJCut';
+				openFrame.attributes['frameBorder'] = 0;
+				openFrame.attributes['allowTransparency'] = 'true';
+
+				if (element.attributes.hasOwnProperty('text')) {
+					openFrame.attributes.text = element.attributes.text;
+				}
+
+				element.children.unshift(openFrame);
+
+				var closeFrame = new CKEDITOR.htmlParser.element('iframe');
+				closeFrame.attributes['class'] = 'lj-cut lj-cut-close';
+				closeFrame.attributes['frameBorder'] = 0;
+				closeFrame.attributes['allowTransparency'] = 'true';
+				element.children.push(closeFrame);
+
+				delete element.name;
+			}
+
 			dataProcessor.dataFilter.addRules({
 				elements: {
-					'lj-like': function(element){
+					'lj-like': function(element) {
 						var attr = [];
 
 						var fakeElement = new CKEDITOR.htmlParser.element('iframe');
 						fakeElement.attributes['class'] = 'lj-like';
-						if(element.attributes.hasOwnProperty('style')){
+						if (element.attributes.hasOwnProperty('style')) {
 							fakeElement.attributes['lj-style'] = element.attributes.style;
 						}
 						fakeElement.attributes['lj-cmd'] = 'LJLike';
@@ -1156,10 +1203,10 @@
 						var currentButtons = element.attributes.buttons && element.attributes.buttons.split(',') || likeButtons.defaultButtons;
 
 						var length = currentButtons.length;
-						for(var i = 0; i < length; i++){
+						for (var i = 0; i < length; i++) {
 							var buttonName = currentButtons[i].replace(/^\s*([a-z]{2,})\s*$/i, '$1');
 							var button = likeButtons[buttonName];
-							if(button){
+							if (button) {
 								fakeElement.attributes['lj-content'] += encodeURIComponent(button.html);
 								attr.push(buttonName);
 							}
@@ -1170,16 +1217,16 @@
 						fakeElement.attributes.buttons = attr.join(',');
 						return fakeElement;
 					},
-					'lj': (function(){
-						function updateUser(name){
+					'lj': (function() {
+						function updateUser(name) {
 							var ljTags = editor.document.getElementsByTag('lj');
 
-							for(var i = 0, l = ljTags.count(); i < l; i++){
+							for (var i = 0, l = ljTags.count(); i < l; i++) {
 								var ljTag = ljTags.getItem(i);
 
 								var userName = ljTag.getAttribute('user');
 								var userTitle = ljTag.getAttribute('title');
-								if(name == (userTitle ? userName + ':' + userTitle : userName)){
+								if (name == (userTitle ? userName + ':' + userTitle : userName)) {
 									var newLjTag = new CKEDITOR.dom.element.createFromHtml(ljUsers[name], editor.document);
 									newLjTag.setAttribute('lj-cmd', 'LJUserLink');
 									ljTag.insertBeforeMe(newLjTag);
@@ -1190,16 +1237,16 @@
 							editor.removeListener('dataReady', updateUser);
 						}
 
-						return function(element){
+						return function(element) {
 							var ljUserName = element.attributes.user;
-							if(!ljUserName || !ljUserName.length){
+							if (!ljUserName || !ljUserName.length) {
 								return;
 							}
 
 							var ljUserTitle = element.attributes.title;
 							var cacheName = ljUserTitle ? ljUserName + ':' + ljUserTitle : ljUserName;
 
-							if(ljUsers.hasOwnProperty(cacheName)){
+							if (ljUsers.hasOwnProperty(cacheName)) {
 								var ljTag = (new CKEDITOR.htmlParser.fragment.fromHtml(ljUsers[cacheName])).children[0];
 
 								ljTag.attributes['lj-cmd'] = 'LJUserLink';
@@ -1209,7 +1256,7 @@
 									username: ljUserName
 								};
 
-								if(ljUserTitle){
+								if (ljUserTitle) {
 									postData.usertitle = ljUserTitle;
 								}
 
@@ -1217,15 +1264,15 @@
 									data: HTTPReq.formEncoded(postData),
 									method: 'POST',
 									url: Site.siteroot + '/tools/endpoints/ljuser.bml',
-									onError: function(err){
+									onError: function(err) {
 										alert(err + ' "' + ljUserName + '"');
 									},
-									onData: function(data){
-										if(data.error){
+									onData: function(data) {
+										if (data.error) {
 											return alert(data.error + ' "' + username + '"');
 										}
 
-										if(!data.success){
+										if (!data.success) {
 											return;
 										}
 
@@ -1233,10 +1280,10 @@
 
 										data.ljuser = data.ljuser.replace('<span class="useralias-value">*</span>', '');
 
-										if(editor.document){
+										if (editor.document) {
 											updateUser(cacheName);
 										} else {
-											editor.on('dataReady', function(){
+											editor.on('dataReady', function() {
 												updateUser(cacheName);
 											});
 										}
@@ -1245,7 +1292,7 @@
 							}
 						};
 					})(),
-					'lj-map': function(element){
+					'lj-map': function(element) {
 						var fakeElement = new CKEDITOR.htmlParser.element('iframe');
 						fakeElement.attributes.style = 'width:' + (isNaN(element.attributes.width) ? 500 : element.attributes.width) + 'px;' + 'height:' + (isNaN(element.attributes.height) ? 350 : element.attributes.height) + 'px;';
 
@@ -1258,28 +1305,26 @@
 
 						return fakeElement;
 					},
-					'lj-repost': function(element){
+					'lj-repost': function(element) {
 						var fakeElement = new CKEDITOR.htmlParser.element('input');
 						fakeElement.attributes.type = 'button';
 						fakeElement.attributes.value = (element.attributes && element.attributes.button) || top.CKLang.LJRepost_Value;
 						fakeElement.attributes['class'] = 'lj-repost';
 						return fakeElement;
-					},'lj-cut': function(element){
-						element.name = 'lj:cut';
-						element.attributes['lj-cmd'] = 'LJCut';
 					},
-					'lj-raw': function(element){
+					'lj-raw': function(element) {
 						element.name = 'lj:raw';
 					},
-					'lj-wishlist': function(element){
+					'lj-wishlist': function(element) {
 						element.name = 'lj:wishlist';
 					},
-					'lj-template': function(element){
+					'lj-template': function(element) {
 						element.name = 'lj:template';
 						element.children.length = 0;
 					},
-					'iframe': function(element){
-						if(element.attributes['class'] && element.attributes['class'].indexOf('lj-') + 1 == 1){
+					'lj-cut': createLJCut,
+					'iframe': function(element) {
+						if (element.attributes['class'] && element.attributes['class'].indexOf('lj-') + 1 == 1) {
 							return element;
 						}
 						var fakeElement = new CKEDITOR.htmlParser.element('iframe');
@@ -1290,24 +1335,24 @@
 						fakeElement.attributes['lj-content'] = '<p class="lj-iframe">iframe</p>';
 						fakeElement.attributes['lj-style'] = ' height: 100%; text-align: center;';
 						fakeElement.attributes['frameBorder'] = 0;
+						fakeElement.attributes['allowTransparency'] = 'true';
 
 						return fakeElement;
 					},
-					a: function(element){
-						if(element.parent.attributes && !element.parent.attributes['lj:user']){
+					a: function(element) {
+						if (element.parent.attributes && !element.parent.attributes['lj:user']) {
 							element.attributes['lj-cmd'] = 'LJLink';
 						}
 					},
-					img: function(element){
+					img: function(element) {
 						var parent = element.parent.parent;
-						if(!parent || !parent.attributes || !parent.attributes['lj:user']){
+						if (!parent || !parent.attributes || !parent.attributes['lj:user']) {
 							element.attributes['lj-cmd'] = 'image';
 						}
 					},
-					div: function(element){
-						if(element.attributes && element.attributes['class'] == 'ljcut'){
-							element.name = 'lj:cut';
-							element.attributes['lj-cmd'] = 'LJCut';
+					div: function(element) {
+						if (element.attributes['class'] == 'lj-cut') {
+							createLJCut(element);
 						}
 					}
 				}
@@ -1315,19 +1360,19 @@
 
 			dataProcessor.htmlFilter.addRules({
 				elements: {
-					iframe: function(element){
+					iframe: function(element) {
 						var newElement = element;
 						var className = /lj-[a-z]+/i.exec(element.attributes['class']);
-						if(className){
+						if (className) {
 							className = className[0];
 						} else {
 							return element;
 						}
-						switch(className){
+						switch (className) {
 							case 'lj-like':
 								newElement = new CKEDITOR.htmlParser.element('lj-like');
 								newElement.attributes.buttons = element.attributes.buttons;
-								if(element.attributes.hasOwnProperty('lj-style')){
+								if (element.attributes.hasOwnProperty('lj-style')) {
 									newElement.attributes.style = element.attributes['lj-style'];
 								}
 								newElement.isEmpty = true;
@@ -1336,7 +1381,7 @@
 							case 'lj-embed':
 								newElement = new CKEDITOR.htmlParser.element('lj-embed');
 								newElement.attributes.id = element.attributes.id;
-								if(element.attributes.hasOwnProperty('source_user')){
+								if (element.attributes.hasOwnProperty('source_user')) {
 									newElement.attributes.source_user = element.attributes.source_user;
 								}
 								newElement.children = new CKEDITOR.htmlParser.fragment.fromHtml(decodeURIComponent(element.attributes['lj-data'])).children;
@@ -1345,7 +1390,7 @@
 							case 'lj-map':
 								newElement = new CKEDITOR.htmlParser.element('lj-map');
 								newElement.attributes.url = decodeURIComponent(element.attributes['lj-url']);
-								element.attributes.style && (element.attributes.style + ';').replace(/([a-z-]+):(.*?);/gi, function(result, name, value){
+								element.attributes.style && (element.attributes.style + ';').replace(/([a-z-]+):(.*?);/gi, function(result, name, value) {
 									newElement.attributes[name.toLowerCase()] = parseInt(value);
 								});
 
@@ -1354,7 +1399,7 @@
 							case 'lj-iframe':
 								newElement = new CKEDITOR.htmlParser.element('iframe');
 								newElement.attributes.src = decodeURIComponent(element.attributes['lj-url']);
-								element.attributes.style && (element.attributes.style + ';').replace(/([a-z-]+):(.*?);/gi, function(result, name, value){
+								element.attributes.style && (element.attributes.style + ';').replace(/([a-z-]+):(.*?);/gi, function(result, name, value) {
 									newElement.attributes[name.toLowerCase()] = parseInt(value);
 								});
 								newElement.attributes.frameBorder = 0;
@@ -1362,70 +1407,98 @@
 							case 'lj-poll':
 								newElement = new CKEDITOR.htmlParser.fragment.fromHtml(decodeURIComponent(element.attributes['lj-data'])).children[0];
 								break;
+							case 'lj-cut':
+								if (element.attributes['class'].indexOf('lj-cut-open') + 1) {
+									var node = element.next;
+									newElement = new CKEDITOR.htmlParser.element('lj-cut');
+
+									if (element.attributes.hasOwnProperty('text')) {
+										newElement.attributes.text = element.attributes.text;
+									}
+
+									while (node) {
+										if (node.name == 'iframe') {
+											var ljCutclassName = node.attributes['class'];
+											if (ljCutclassName.indexOf('lj-cut-close') + 1) {
+												newElement.next = node;
+												break;
+											} else if (ljCutclassName.indexOf('lj-cut-open') + 1) {
+												newElement.next = node;
+												break;
+											}
+										}
+
+										node.parent.children.remove(node);
+										newElement.add(node);
+										var next = node.next;
+										node.next = null;
+										node = next;
+									}
+								} else {
+									newElement = false;
+								}
+								break;
 							default:
-								if(!element.children.length){
+								if (!element.children.length) {
 									newElement = false;
 								}
 						}
 
 						return newElement;
 					},
-					span: function(element){
+					span: function(element) {
 						var userName = element.attributes['lj:user'];
-						if(userName){
+						if (userName) {
 							var ljUserNode = new CKEDITOR.htmlParser.element('lj');
 							ljUserNode.attributes.user = userName;
 
-							try{
+							try {
 								var userTitle = element.children[1].children[0].children[0].value;
-							} catch(e){
+							} catch(e) {
 								return false;
 							}
 
-							if(userTitle && userTitle != userName){
+							if (userTitle && userTitle != userName) {
 								ljUserNode.attributes.title = userTitle;
 							}
 
 							ljUserNode.isOptionalClose = ljUserNode.isEmpty = true;
 							return ljUserNode;
-						} else if(element.attributes.style == 'display: none;' || !element.children.length){
+						} else if (element.attributes.style == 'display: none;' || !element.children.length) {
 							return false;
 						}
 					},
-					input: function(element){
-						if(element.attributes['class'] == 'lj-repost'){
+					input: function(element) {
+						if (element.attributes['class'] == 'lj-repost') {
 							var newElement = new CKEDITOR.htmlParser.element('lj-repost');
-							if(element.attributes.value != top.CKLang.LJRepost_Value){
+							if (element.attributes.value != top.CKLang.LJRepost_Value) {
 								newElement.attributes.button = element.attributes.value;
 							}
 							newElement.isOptionalClose = newElement.isEmpty = true;
 							return newElement;
 						}
 					},
-					div: function(element){
-						if(!element.children.length){
+					div: function(element) {
+						if (!element.children.length) {
 							return false;
 						}
 					},
-					'lj:template': function(element){
+					'lj:template': function(element) {
 						element.name = 'lj-template';
 						element.isOptionalClose = element.isEmpty = true;
 					},
-					'lj:cut': function(element){
-						element.name = 'lj-cut';
-					},
-					'lj:raw': function(element){
+					'lj:raw': function(element) {
 						element.name = 'lj-raw';
 					},
-					'lj:wishlist': function(element){
+					'lj:wishlist': function(element) {
 						element.name = 'lj-wishlist';
 					}
 				},
 				attributes: {
-					'lj-cmd': function(){
+					'lj-cmd': function() {
 						return false;
 					},
-					'contenteditable': function(){
+					'contenteditable': function() {
 						return false;
 					}
 				}

Modified: trunk/htdocs/js/rte.js
===================================================================
--- trunk/htdocs/js/rte.js	2011-11-14 07:38:59 UTC (rev 20531)
+++ trunk/htdocs/js/rte.js	2011-11-15 04:08:46 UTC (rev 20532)
@@ -109,49 +109,48 @@
 		}
 
 		if (!window.switchedRteOn) {
-			window.switchedRteOn = true;
-			$('#switched_rte_on').val('1');
-
 			if (!CKEditor && CKEDITOR && CKEDITOR.env.isCompatible) {
 				CKEDITOR.basePath = statPrefix + '/ck/';
-				var editor = CKEDITOR.replace('draft', {
+
+				CKEDITOR.replace('draft', {
 					skin: 'v2',
 					baseHref: CKEDITOR.basePath,
 					height: 350,
 					language: Site.current_lang || 'en'
-				});
+				}).on('instanceReady', function() {
+						CKEditor = this;
+						this.resetDirty();
 
-				editor.on('instanceReady', function() {
-					CKEditor = editor;
-					editor.resetDirty();
-
-					$('#updateForm')[0].onsubmit = function() {
-						if (window.switchedRteOn) {
-							var data = CKEditor.getData();
-							if(!$('#event_format')[0].checked){
-								data = data.replace(/\r|\n/g, '<br />');
+						$('#updateForm')[0].onsubmit = function() {
+							if (window.switchedRteOn) {
+								var data = CKEditor.getData();
+								if (!$('#event_format')[0].checked) {
+									data = data.replace(/\r|\n/g, '<br />');
+								}
+								draftData.textArea.val(data);
 							}
-							draftData.textArea.val(data);
-						}
-					};
+						};
 
-					CKEditor.on('dataReady', function() {
-						$('#entry-form-wrapper').attr('class', 'hide-html');
+						this.on('dialogHide', updateDraftState);
+						this.on('afterCommandExec', updateDraftState);
+						this.on('insertElement', updateDraftState);
+						this.on('insertHtml', updateDraftState);
+						this.on('insertText', updateDraftState);
 
-						CKEditor.container.show();
-						CKEditor.element.hide();
+						this.on('dataReady', function() {
+							$('#entry-form-wrapper').attr('class', 'hide-html');
+							this.container.show();
+							this.element.hide();
+							this.document.on('keypress', updateDraftState);
+							this.document.on('click', updateDraftState);
 
-						editor.on('dialogHide', updateDraftState);
-						editor.on('afterCommandExec', updateDraftState);
-						editor.on('insertElement', updateDraftState);
-						editor.on('insertHtml', updateDraftState);
-						editor.on('insertText', updateDraftState);
-						editor.document.on('keypress', updateDraftState);
-						editor.document.on('click', updateDraftState);
+							this.onSwitch = true;
+							!CKEDITOR.env.ie && this.focus();
 
-						!CKEDITOR.env.ie && editor.focus();
+							$('#switched_rte_on').val('1');
+							window.switchedRteOn = true;
+						});
 					});
-				});
 			} else {
 				var data = CKEditor.element.getValue();
 
@@ -163,7 +162,10 @@
 				}
 
 				CKEditor.setData(data);
+				$('#switched_rte_on').val('1');
+				window.switchedRteOn = true;
 			}
+
 		}
 
 		return false;

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