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

[livejournal] r19689: LJSUP-9460: Disable RTE tab for ipad

Committer: vkurkin
LJSUP-9460: Disable RTE tab for ipad
LJSUP-9159: Update and improve RTE by CKEditor 3.6.1
U   trunk/cgi-bin/LJ/Widget/EntryForm.pm
U   trunk/htdocs/editjournal.bml
U   trunk/htdocs/js/ck/plugins/livejournal/plugin.js
U   trunk/htdocs/js/entry.js
U   trunk/htdocs/js/rte.js
U   trunk/htdocs/update.bml
Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/EntryForm.pm	2011-08-10 09:03:41 UTC (rev 19688)
+++ trunk/cgi-bin/LJ/Widget/EntryForm.pm	2011-08-10 09:39:36 UTC (rev 19689)
@@ -629,7 +629,7 @@
 
     my $switch_rte_link = BML::ml("entryform.htmlokay.rich4", {
         'opts' => 'href="javascript:void(0);" '.
-            'onclick="return useRichText(\'draft\', \'' .
+            'onclick="return useRichText(\'' .
             $LJ::JSPREFIX. '\');"'
     });
 
@@ -640,7 +640,7 @@
 
     my $switch_plaintext_link = BML::ml("entryform.plainswitch2", {
         'aopts' => 'href="javascript:void(0);" '.
-            'onclick="return usePlainText(\'draft\');"'
+            'onclick="return usePlainText();"'
     });
 
     my $switch_plaintext_tab =
@@ -1499,11 +1499,11 @@
             </noscript>
         };
 
-        $$js = "init_update_bml();";
+        $$js = "initUpdateBml();";
         if ($opts->{'richtext_default'}) {
-            $$js .= 'useRichText("draft", "' . LJ::ejs($LJ::JSPREFIX) . '");';
+            $$js .= 'useRichText("' . LJ::ejs($LJ::JSPREFIX) . '");';
         } else {
-            $$js .= 'usePlainText("draft");';
+            $$js .= 'usePlainText();';
         }
         $$js = $self->wrap_js($$js);
 

Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml	2011-08-10 09:03:41 UTC (rev 19688)
+++ trunk/htdocs/editjournal.bml	2011-08-10 09:39:36 UTC (rev 19689)
@@ -567,7 +567,7 @@
             $$head .= qq{
     <script type="text/javascript">
     //<![CDATA[
-        function init_update_bml () {
+        function initUpdateBml() {
             window.isSupUser = $is_sup;
             $onload
         }

Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js
===================================================================
--- trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2011-08-10 09:03:41 UTC (rev 19688)
+++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js	2011-08-10 09:39:36 UTC (rev 19689)
@@ -1,4 +1,4 @@
-(function(){
+(function() {
 
 	var likeButtons = [
 		{
@@ -30,7 +30,8 @@
 			id: 'vkontakte',
 			abbr: 'vk',
 			html: '<span class="lj-like-item lj-like-gag vk">' + top.CKLang.LJLike_button_vkontakte + '</span>',
-			htmlOpt: window.isSupUser ? '<li class="like-vk"><input type="checkbox" id="like-vk" /><label for="like-vk">' + top.CKLang
+			htmlOpt: window
+				.isSupUser ? '<li class="like-vk"><input type="checkbox" id="like-vk" /><label for="like-vk">' + top.CKLang
 				.LJLike_button_vkontakte + '</label></li>' : ''
 		},
 		{
@@ -42,27 +43,33 @@
 				.LJLike_button_give + '</label></li>'
 		}
 	];
-	
+
 	var note;
 
 	var ljNoteData = {
 		LJPollLink: {
-			html: encodeURIComponent(top.CKLang.Poll_PollWizardNotice + '<br /><a href="#">' + top.CKLang.Poll_PollWizardNoticeLink + '</a>')
+			html: encodeURIComponent(top.CKLang.Poll_PollWizardNotice + '<br /><a href="#">' + top.CKLang
+				.Poll_PollWizardNoticeLink + '</a>')
 		},
 		LJLike: {
-			html: encodeURIComponent(top.CKLang.LJLike_WizardNotice + '<br /><a href="#">' + top.CKLang.LJLike_WizardNoticeLink + '</a>')
+			html: encodeURIComponent(top.CKLang.LJLike_WizardNotice + '<br /><a href="#">' + top.CKLang
+				.LJLike_WizardNoticeLink + '</a>')
 		},
 		LJUserLink: {
-			html: encodeURIComponent(top.CKLang.LJUser_WizardNotice + '<br /><a href="#">' + top.CKLang.LJUser_WizardNoticeLink + '</a>')
+			html: encodeURIComponent(top.CKLang.LJUser_WizardNotice + '<br /><a href="#">' + top.CKLang
+				.LJUser_WizardNoticeLink + '</a>')
 		},
 		LJLink: {
-			html: encodeURIComponent(top.CKLang.LJLink_WizardNotice + '<br /><a href="#">' + top.CKLang.LJLink_WizardNoticeLink + '</a>')
+			html: encodeURIComponent(top.CKLang.LJLink_WizardNotice + '<br /><a href="#">' + top.CKLang
+				.LJLink_WizardNoticeLink + '</a>')
 		},
 		LJImage: {
-			html: encodeURIComponent(top.CKLang.LJImage_WizardNotice + '<br /><a href="#">' + top.CKLang.LJImage_WizardNoticeLink + '</a>')
+			html: encodeURIComponent(top.CKLang.LJImage_WizardNotice + '<br /><a href="#">' + top.CKLang
+				.LJImage_WizardNoticeLink + '</a>')
 		},
 		LJCut :{
-			html: encodeURIComponent(top.CKLang.LJCut_WizardNotice + '<br /><a href="#">' + top.CKLang.LJCut_WizardNoticeLink + '</a>')
+			html: encodeURIComponent(top.CKLang.LJCut_WizardNotice + '<br /><a href="#">' + top.CKLang
+				.LJCut_WizardNoticeLink + '</a>')
 		}
 	};
 
@@ -70,11 +77,11 @@
 	var currentNoteNode;
 
 	CKEDITOR.plugins.add('livejournal', {
-		init: function(editor){
-			function onFindCmd(evt){
+		init: function(editor) {
+			function onFindCmd(evt) {
 				var cmd;
-				
-				if(evt.name == 'mouseout'){
+
+				if (evt.name == 'mouseout') {
 					note.hide();
 					return;
 				}
@@ -83,27 +90,27 @@
 				var node = isMouseOver ? evt.data.getTarget() : editor.getSelection().getStartElement();
 				var actNode;
 
-				while(node){
+				while (node) {
 
-					if(!attr){
-						if(node.is('img')){
+					if (!attr) {
+						if (node.is('img')) {
 							node.setAttribute('lj-cmd', 'LJImage');
-						} else if(node.is('a')){
+						} else if (node.is('a')) {
 							node.setAttribute('lj-cmd', 'LJLink');
 						}
 					}
 
 					var attr = node.getAttribute('lj-cmd');
 
-					if(attr){
+					if (attr) {
 						cmd = attr;
 						actNode = node;
 					}
 					node = node.getParent();
 				}
 
-				if(cmd && ljNoteData.hasOwnProperty(cmd)){
-					if(!isMouseOver){
+				if (cmd && ljNoteData.hasOwnProperty(cmd)) {
+					if (!isMouseOver) {
 						ljNoteData[cmd].node = actNode;
 					}
 					note.show(ljNoteData[cmd].html, cmd, actNode);
@@ -112,13 +119,13 @@
 				}
 			}
 
-			editor.dataProcessor.toHtml = function(html, fixForBody){
+			editor.dataProcessor.toHtml = function(html, fixForBody) {
 				html = html.replace(/<((?!br)[^\s>]+)([^\/>]+)?\/>/gi, '<$1$2></$1>')
 					.replace(/<lj-template name=['"]video['"]>(\S+?)<\/lj-template>/g, '<div class="ljvideo" url="$1"><img src="' + Site
 					.statprefix + '/fck/editor/plugins/livejournal/ljvideo.gif" /></div>')
 					.replace(/<lj-embed\s*(?:id="(\d*)")?\s*>([\s\S]*?)<\/lj-embed>/gi, '<div class="ljembed" embedid="$1">$2</div>')
 					.replace(/<lj-poll .*?>[^b]*?<\/lj-poll>/gm,
-					function(ljtags){
+					function(ljtags) {
 						return new Poll(ljtags).outputHTML();
 					}).replace(/<lj-template(.*?)><\/lj-template>/g, "<lj-template$1 />");
 
@@ -126,7 +133,7 @@
 					.replace(/(<lj-cut[^>]*>)/g, '\ufeff$1').replace(/(<\/lj-cut>)/g, '$1\ufeff');
 
 				// IE custom tags. http://msdn.microsoft.com/en-us/library/ms531076%28VS.85%29.aspx
-				if(CKEDITOR.env.ie){
+				if (CKEDITOR.env.ie) {
 					html = html.replace(/<lj-cut([^>]*)>/g, '<lj:cut$1>').replace(/<\/lj-cut>/g, '</lj:cut>')
 						.replace(/<([\/])?lj-raw>/g, '<$1lj:raw>').replace(/<([\/])?lj-wishlist>/g, '<$1lj:wishlist>')
 						.replace(/(<lj [^>]*)> /g, '$1> '); // IE merge spaces
@@ -134,13 +141,13 @@
 					// close <lj user> tags
 					html = html.replace(/(<lj [^>]*[^\/])>/g, '$1/> ');
 				}
-				if(!$('event_format').checked){
+				if (!$('event_format').checked) {
 					html = '<pre>' + html + '</pre>';
 				}
 
 				html = CKEDITOR.htmlDataProcessor.prototype.toHtml.call(this, html, fixForBody);
 
-				if(!$('event_format').checked){
+				if (!$('event_format').checked) {
 					html = html.replace(/<\/?pre>/g, '');
 					html = html.replace(/\n/g, '<br\/>');
 				}
@@ -148,53 +155,22 @@
 				return html;
 			};
 
-			editor.dataProcessor.toDataFormat = function(html, fixForBody){
-				// DOM methods are used for detection of node opening/closing
-				/*var document = editor.document.$;
-				 var newBody = document.createElement('div'),
-				 copyNode = document.body.firstChild;
-				 if(copyNode){
-				 newBody.appendChild(copyNode.cloneNode(true));
-				 while(copyNode = copyNode.nextSibling){
-				 newBody.appendChild(copyNode.cloneNode(true));
-				 }
-				 var divs = newBody.getElementsByTagName('div'),
-				 i = divs.length;
-				 while(i--){
-				 var div = divs[i];
-				 switch(div.className){
-				 // lj-template any name: <lj-template name="" value="" alt="html code"/>
-				 case 'lj-template':
-				 var name = div.getAttribute('name'),
-				 value = div.getAttribute('value'),
-				 alt = div.getAttribute('alt');
-				 if(!name || !value || !alt){
-				 break;
-				 }
-				 var ljtag = FCK.EditorDocument.createElement('lj-template');
-				 ljtag.setAttribute('name', name);
-				 ljtag.setAttribute('value', value);
-				 ljtag.setAttribute('alt', alt);
-				 div.parentNode.replaceChild(ljtag, div);
-				 }
-
-				 }
-				 }*/
+			editor.dataProcessor.toDataFormat = function(html, fixForBody) {
 				html = html.replace(/^<pre>\n*([\s\S]*?)\n*<\/pre>\n*$/, '$1');
 
 				html = CKEDITOR.htmlDataProcessor.prototype.toDataFormat.call(this, html, fixForBody);
 
 				html = html.replace(/\t/g, ' ');
 				html = html.replace(/>\n\s*(?!\s)([^<]+)</g, '>$1<');
-				if(!CKEDITOR.env.ie){
+				if (!CKEDITOR.env.ie) {
 					html = html.replace(/<br (type="_moz" )? ?\/>$/, '');
-					if(CKEDITOR.env.webkit){
+					if (CKEDITOR.env.webkit) {
 						html = html.replace(/<br type="_moz" \/>/, '');
 					}
 				}
 
 				html = html.replace(/<form.*?class="ljpoll" data="([^"]*)"[\s\S]*?<\/form>/gi,
-					function(form, data){
+					function(form, data) {
 						return unescape(data);
 					}).replace(/<\/lj>/g, '');
 
@@ -207,12 +183,12 @@
 					.replace(/(<lj-template id="\d+" )([^>]*)class="ljqotd"?([^>]*\/>)/g, '$1name="qotd" $2$3')// class attrib
 					.replace(/(<lj-template id="\d+" name="qotd" )[^>]*(lang="\w+")[^>]*\/>/g, '$1$2 \/>'); // lang attrib
 
-				if(!$('event_format').checked && !top.switchedRteOn){
+				if (!$('event_format').checked && !top.switchedRteOn) {
 					html = html.replace(/\n?\s*<br \/>\n?/g, '\n');
 				}
 
 				// IE custom tags
-				if(CKEDITOR.env.ie){
+				if (CKEDITOR.env.ie) {
 					html = html.replace(/<lj:cut([^>]*)>/g, '<lj-cut$1>').replace(/<\/lj:cut>/g, '</lj-cut>')
 						.replace(/<([\/])?lj:wishlist>/g, '<$1lj-wishlist>').replace(/<([\/])?lj:raw>/g, '<$1lj-raw>');
 				}
@@ -222,15 +198,15 @@
 				return html;
 			};
 
-			function addLastTag(){
+			function addLastTag() {
 				var body = editor.document.getBody();
 				var last = body.getLast();
-				if(last && last.type == 1 && !last.is('br')){
+				if (last && last.type == 1 && !last.is('br')) {
 					body.appendHtml('<br />');
 				}
 			}
 
-			editor.on('dataReady', function(){
+			editor.on('dataReady', function() {
 
 				editor.document.on('mouseover', onFindCmd);
 				editor.document.on('mouseout', onFindCmd);
@@ -240,7 +216,7 @@
 				editor.document.on('keyup', addLastTag);
 				editor.document.on('click', addLastTag);
 
-				if(!note){
+				if (!note) {
 					var timer,
 						state,
 						currentData = {},
@@ -248,45 +224,45 @@
 						noteNode = document.createElement('lj-note'),
 						isIE = typeof(document.body.style.opacity) != 'string';
 
-					var animate = (function(){
-						var
-							fps = 60,
+					var animate = (function() {
+						var fps = 60,
 							totalTime = 100,
 							steps = totalTime * fps / 1000,
 							timeOuts = [],
 							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){
-								noteNode.style.filter = (currentStep >= 1) ? null : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (currentStep * 100) + ')';
+							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,
@@ -302,37 +278,37 @@
 					})();
 
 					noteNode.className = 'note-popup';
-					
-					noteNode.onmouseout = function(){
-						if(!currentData.cmd) {
+
+					noteNode.onmouseout = function() {
+						if (!currentData.cmd) {
 							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(){
-						if(currentData.cmd){
+					function callCmd() {
+						if (currentData.cmd) {
 							currentNoteNode = ljNoteData[currentData.cmd].node = currentData.node;
 							editor.getCommand(currentData.cmd).exec();
 						}
 						return false;
 					}
 
-					function applyNote(){
-						if(state){
+					function applyNote() {
+						if (state) {
 							currentData.cmd = tempData.cmd;
 							currentData.data = tempData.data;
 							currentData.node = tempData.node;
@@ -344,7 +320,7 @@
 							noteNode.innerHTML = decodeURIComponent(currentData.data);
 
 							var link = noteNode.getElementsByTagName('a')[0];
-							if(link && currentData.cmd){
+							if (link && currentData.cmd) {
 								link.onclick = callCmd;
 							}
 						} else {
@@ -361,33 +337,33 @@
 					}
 
 					note = {
-						show: function(data, cmd, node){
-							if(data == tempData.data && cmd == tempData.cmd && node === tempData.node){
+						show: function(data, cmd, node) {
+							if (data == tempData.data && cmd == tempData.cmd && node === tempData.node) {
 								return;
 							}
 
-							if(timer){
+							if (timer) {
 								clearTimeout(timer);
 								timer = null;
 							}
 
 							state = 1;
 							timer = setTimeout(applyNote, 1000);
-							
+
 							tempData.data = data;
 							tempData.cmd = cmd;
 							tempData.node = node;
 						},
-						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);
 								}
 							}
@@ -402,16 +378,16 @@
 
 			editor.attachStyleStateChange(new CKEDITOR.style({
 				element: 'span'
-			}), function(){
+			}), function() {
 				var selectNode = editor.getSelection().getStartElement().getAscendant('span', true);
 				var isUserLink = selectNode && selectNode.hasClass('ljuser');
 				ljNoteData.LJUserLink.node = isUserLink ? selectNode : null;
 				editor.getCommand('LJUserLink').setState(isUserLink ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF);
 			});
 
-			editor.on('doubleclick', function(evt){
+			editor.on('doubleclick', function(evt) {
 				var command = editor.getCommand('LJUserLink');
-				if(command.state == CKEDITOR.TRISTATE_ON){
+				if (command.state == CKEDITOR.TRISTATE_ON) {
 					command.exec();
 				}
 
@@ -419,22 +395,23 @@
 			});
 
 			editor.addCommand('LJUserLink', {
-				exec : function(editor){
+				exec : function(editor) {
 					var userName = '',
 						selection = editor.getSelection(),
 						LJUser = ljNoteData.LJUserLink.node;
 
-					if(ljNoteData.LJUserLink.node){
-						userName = prompt(top.CKLang.UserPrompt, ljNoteData.LJUserLink.node.getElementsByTag('b').getItem(0).getText());
-					} else if(selection.getType() == 2){
+					if (ljNoteData.LJUserLink.node) {
+						userName = prompt(top.CKLang.UserPrompt, ljNoteData.LJUserLink.node.getElementsByTag('b').getItem(0)
+							.getText());
+					} else if (selection.getType() == 2) {
 						userName = selection.getSelectedText();
 					}
 
-					if(userName == ''){
+					if (userName == '') {
 						userName = prompt(top.CKLang.UserPrompt, userName);
 					}
 
-					if(!userName){
+					if (!userName) {
 						return;
 					}
 
@@ -444,12 +421,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>', '');
@@ -461,7 +438,7 @@
 							ljNoteData.LJUserLink.node = tmpNode.getFirst();
 							ljNoteData.LJUserLink.node.setAttribute('lj-cmd', 'LJUserLink');
 
-							if(LJUser){
+							if (LJUser) {
 								LJUser.$.parentNode.replaceChild(ljNoteData.LJUserLink.node.$, LJUser.$);
 							} else {
 								editor.insertElement(ljNoteData.LJUserLink.node);
@@ -478,18 +455,15 @@
 
 			//////////  LJ Image Button //////////////
 			editor.addCommand('LJImage', {
-				exec : function(editor){
-					if(window.ljphotoEnabled){
-						jQuery('#updateForm')
-							.photouploader({
-								type: 'upload'
-							})
-							.photouploader('show')
-								.bind('htmlready', function (event, html) {
-									editor.insertHtml(html);
-								});
+				exec : function(editor) {
+					if (window.ljphotoEnabled) {
+						jQuery('#updateForm').photouploader({
+																									type: 'upload'
+																								}).photouploader('show').bind('htmlready', function (event, html) {
+							editor.insertHtml(html);
+						});
 					} else {
-						if(ljNoteData.LJImage.node){
+						if (ljNoteData.LJImage.node) {
 							editor.getSelection().selectElement(ljNoteData.LJImage.node);
 						}
 						editor.getCommand('image').exec();
@@ -499,16 +473,16 @@
 
 			editor.attachStyleStateChange(new CKEDITOR.style({
 				element: 'img'
-			}), function(state){
-				if(state == CKEDITOR.TRISTATE_OFF && !currentNoteNode){
+			}), function(state) {
+				if (state == CKEDITOR.TRISTATE_OFF && !currentNoteNode) {
 					delete ljNoteData.LJImage.node;
 				}
 				editor.getCommand('LJImage').setState(state);
 			});
 
-			editor.on('doubleclick', function(evt){
+			editor.on('doubleclick', function(evt) {
 				var command = editor.getCommand('LJImage');
-				if(command.state == CKEDITOR.TRISTATE_ON){
+				if (command.state == CKEDITOR.TRISTATE_ON) {
 					command.exec();
 				}
 
@@ -522,8 +496,8 @@
 
 			//////////  LJ Link Button //////////////
 			editor.addCommand('LJLink', {
-				exec : function(editor){
-					if(ljNoteData.LJLink.node){
+				exec : function(editor) {
+					if (ljNoteData.LJLink.node) {
 						editor.getSelection().selectElement(ljNoteData.LJLink.node);
 					}
 					editor.getCommand('link').exec();
@@ -532,16 +506,16 @@
 
 			editor.attachStyleStateChange(new CKEDITOR.style({
 				element: 'a'
-			}), function(state){
-				if(state == CKEDITOR.TRISTATE_OFF && !currentNoteNode){
+			}), function(state) {
+				if (state == CKEDITOR.TRISTATE_OFF && !currentNoteNode) {
 					delete ljNoteData.LJLink.node;
 				}
 				editor.getCommand('LJLink').setState(state);
 			});
 
-			editor.on('doubleclick', function(evt){
+			editor.on('doubleclick', function(evt) {
 				var command = editor.getCommand('LJLink');
-				if(command.state == CKEDITOR.TRISTATE_ON){
+				if (command.state == CKEDITOR.TRISTATE_ON) {
 					command.exec();
 				}
 
@@ -555,7 +529,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'
 					});
@@ -570,9 +544,9 @@
 			editor.addCss('img.lj-embed' + '{' + 'background-image: url(' + CKEDITOR.getUrl(this
 				.path + 'images/placeholder_flash.png') + ');' + 'background-position: center center;' + 'background-repeat: no-repeat;' + 'border: 1px solid #a9a9a9;' + 'width: 80px;' + 'height: 80px;' + '}');
 
-			function doEmbed(content){
-				if(content && content.length){
-					if(switchedRteOn){
+			function doEmbed(content) {
+				if (content && content.length) {
+					if (switchedRteOn) {
 						editor.insertHtml('<div class="ljembed">' + content + '</div><br/>');
 					}
 				}
@@ -581,27 +555,27 @@
 			//////////  LJ Cut Button //////////////
 			editor.attachStyleStateChange(new CKEDITOR.style({
 				element: 'lj-cut'
-			}), function(state){
-				if(state == CKEDITOR.TRISTATE_OFF && !currentNoteNode){
+			}), function(state) {
+				if (state == CKEDITOR.TRISTATE_OFF && !currentNoteNode) {
 					delete ljNoteData.LJCut.node;
 				}
 				editor.getCommand('LJCut').setState(state);
 			});
 
-			editor.on('doubleclick', function(evt){
+			editor.on('doubleclick', function(evt) {
 				var command = editor.getCommand('LJCut');
-				if(command.state == CKEDITOR.TRISTATE_ON){
+				if (command.state == CKEDITOR.TRISTATE_ON) {
 					command.exec();
 				}
 			});
 
 			editor.addCommand('LJCut', {
-				exec: function(){
+				exec: function() {
 					var text;
-					if(ljNoteData.LJCut.node){
+					if (ljNoteData.LJCut.node) {
 						text = prompt(top.CKLang.CutPrompt, ljNoteData.LJCut.node.getAttribute('text') || top.CKLang.ReadMore);
-						if(text){
-							if(text == top.CKLang.ReadMore){
+						if (text) {
+							if (text == top.CKLang.ReadMore) {
 								ljNoteData.LJCut.node.removeAttribute('text');
 							} else {
 								ljNoteData.LJCut.node.setAttribute('text', text);
@@ -609,10 +583,10 @@
 						}
 					} else {
 						text = prompt(top.CKLang.CutPrompt, top.CKLang.ReadMore);
-						if(text){
+						if (text) {
 							ljNoteData.LJCut.node = editor.document.createElement('lj-cut');
 							ljNoteData.LJCut.node.setAttribute('lj-cmd', 'LJCut');
-							if(text != top.CKLang.ReadMore){
+							if (text != top.CKLang.ReadMore) {
 								ljNoteData.LJCut.node.setAttribute('text', text);
 							}
 							editor.getSelection().getRanges()[0].extractContents().appendTo(ljNoteData.LJCut.node);
@@ -631,7 +605,7 @@
 			});
 
 			//////////  LJ Poll Button //////////////
-			if(top.canmakepoll){
+			if (top.canmakepoll) {
 				var currentPoll;
 
 				editor.attachStyleStateChange(new CKEDITOR.style({
@@ -639,31 +613,31 @@
 					attributes: {
 						'class': 'ljpoll'
 					}
-				}), function(state){
-					if(state == CKEDITOR.TRISTATE_OFF && !currentNoteNode){
+				}), function(state) {
+					if (state == CKEDITOR.TRISTATE_OFF && !currentNoteNode) {
 						delete ljNoteData.LJPollLink.node;
 					}
 					editor.getCommand('LJPollLink').setState(state);
 				});
 
-				editor.on('doubleclick', function(evt){
+				editor.on('doubleclick', function(evt) {
 					var command = editor.getCommand('LJPollLink');
-					if(command.state == CKEDITOR.TRISTATE_ON){
+					if (command.state == CKEDITOR.TRISTATE_ON) {
 						command.exec();
 						evt.data.dialog = '';
 					}
 				});
 
-				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){
-							currentPoll = new Poll(ljNoteData.LJPollLink.node && unescape(ljNoteData.LJPollLink.node.getAttribute('data')), questionsWindow
-								.document, setupWindow.document, questionsWindow.Questions);
+						if (isAllFrameLoad && okButtonNode) {
+							currentPoll = new Poll(ljNoteData.LJPollLink.node && unescape(ljNoteData.LJPollLink.node
+								.getAttribute('data')), questionsWindow.document, setupWindow.document, questionsWindow.Questions);
 
 							questionsWindow.ready(currentPoll);
 							setupWindow.ready(currentPoll);
@@ -678,8 +652,8 @@
 						title : top.CKLang.Poll_PollWizardTitle,
 						width : 420,
 						height : 270,
-						onShow: function(){
-							if(isAllFrameLoad){
+						onShow: function() {
+							if (isAllFrameLoad) {
 								currentPoll = new Poll(ljNoteData.LJPollLink.node && unescape(ljNoteData.LJPollLink.node
 									.getAttribute('data')), questionsWindow.document, setupWindow.document, questionsWindow.Questions);
 
@@ -696,14 +670,14 @@
 									{
 										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('LJPool_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);
@@ -720,10 +694,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);
@@ -737,13 +711,13 @@
 							type : 'button',
 							id : 'LJPool_Ok',
 							label : editor.lang.common.ok,
-							onClick : function(evt){
+							onClick : function(evt) {
 								evt.data.dialog.hide();
 								var pollSource = new Poll(currentPoll, questionsWindow.document, setupWindow.document, questionsWindow
 									.Questions).outputHTML();
 
-								if(pollSource.length > 0){
-									if(ljNoteData.LJPollLink.node){
+								if (pollSource.length > 0) {
+									if (ljNoteData.LJPollLink.node) {
 										var node = editor.document.createElement('div');
 										node.setHtml(pollSource);
 										ljNoteData.LJPollLink.node.insertBeforeMe(node);
@@ -761,7 +735,7 @@
 				editor.addCommand('LJPollLink', new CKEDITOR.dialogCommand('LJPollDialog'));
 			} else {
 				editor.addCommand('LJPollLink', {
-					exec: function(){
+					exec: function() {
 						note.show(top.CKLang.Poll_AccountLevelNotice);
 					}
 				});
@@ -779,7 +753,7 @@
 			var dialogContent = '<div class="cke-dialog-likes"><ul class="cke-dialog-likes-list">';
 			likeButtons.defaultButtons = [];
 
-			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);
@@ -789,36 +763,39 @@
 			dialogContent += '</ul><p class="cke-dialog-likes-faq">' + window.faqLink + '</p></div>';
 
 			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');
+					ljLikeDialog.getButton('LJLike_Ok')
+						.getElement()[countChanges == 0 ? 'addClass' : 'removeClass']('btn-disabled');
 				}
 			}
 
-			CKEDITOR.dialog.add('LJLikeDialog', function(){
+			CKEDITOR.dialog.add('LJLikeDialog', function() {
 				return {
-					title : top.CKLang.LJLike_name,
-					width : 145,
-					height : 180,
+					title: top.CKLang.LJLike_name,
+					width: 145,
+					height: 180,
 					resizable: false,
-					contents : [
+					contents: [
 						{
 							id: 'LJLike_Options',
-							elements: [{
-								type: 'html',
-								html: dialogContent
-							}]
+							elements: [
+								{
+									type: 'html',
+									html: dialogContent
+								}
+							]
 						}
 					],
-					buttons : [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')){
+					buttons: [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')) {
 								return false;
 							}
 
@@ -826,45 +803,46 @@
 								likeHtml = '',
 								likeNode = ljNoteData.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;
 								}
 							}
 
-							if(attr.length){
-								if(likeNode){
+							if (attr.length) {
+								if (likeNode) {
 									ljNoteData.LJLike.node.setAttribute('buttons', attr.join(','));
 									ljNoteData.LJLike.node.setHtml(likeHtml);
 								} else {
-									editor.insertHtml('<div class="lj-like" lj-cmd="LJLike" buttons="' + attr.join(',') + '">' + likeHtml + '</div>');
+									editor.insertHtml('<div class="lj-like" lj-cmd="LJLike" buttons="' + attr
+										.join(',') + '">' + likeHtml + '</div>');
 								}
-							} else if(likeNode){
+							} else if (likeNode) {
 								ljNoteData.LJLike.node.remove();
 							}
 
 							ljLikeDialog.hide();
 						}
 					}), CKEDITOR.dialog.cancelButton],
-					onShow: function(){
+					onShow: function() {
 						var command = editor.getCommand('LJLike');
 						var i = countChanges = 0,
 							isOn = command.state == CKEDITOR.TRISTATE_ON,
 							buttons = ljNoteData.LJLike.node && ljNoteData.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++;
 								}
 
@@ -872,14 +850,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);
 						}
@@ -889,27 +867,27 @@
 
 			editor.attachStyleStateChange(new CKEDITOR.style({
 				element: 'div'
-			}), function(){
+			}), function() {
 				var ljLikeNode = this.getSelection().getStartElement();
 
-				while(ljLikeNode){
-					if(ljLikeNode.hasClass('lj-like')){
+				while (ljLikeNode) {
+					if (ljLikeNode.hasClass('lj-like')) {
 						ljNoteData.LJLike.node = ljLikeNode;
 						break;
 					}
 					ljLikeNode = ljLikeNode.getParent();
 				}
 
-				if(!ljLikeNode && !currentNoteNode){
+				if (!ljLikeNode && !currentNoteNode) {
 					delete ljNoteData.LJLike.node;
 				}
 
 				editor.getCommand('LJLike').setState(ljLikeNode ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF);
 			});
 
-			editor.on('doubleclick', function(){
+			editor.on('doubleclick', function() {
 				var command = editor.getCommand('LJLike');
-				if(command.state == CKEDITOR.TRISTATE_ON){
+				if (command.state == CKEDITOR.TRISTATE_ON) {
 					command.exec();
 				}
 			});
@@ -921,16 +899,16 @@
 				command: 'LJLike'
 			});
 		},
-		afterInit : function(editor){
+		afterInit: function(editor) {
 			var flashFilenameRegex = /\.swf(?:$|\?)/i;
 
-			function isFlashEmbed(element){
+			function isFlashEmbed(element) {
 				var attributes = element.attributes;
 
 				return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test(attributes.src || '') );
 			}
 
-			function createFakeElement(editor, realElement){
+			function createFakeElement(editor, realElement) {
 				return editor.createFakeParserElement(realElement, 'lj-embed', 'flash', false);
 			}
 
@@ -938,17 +916,17 @@
 
 			dataProcessor.dataFilter.addRules({
 				elements: {
-					'lj-cut': function(element){
+					'lj-cut': function(element) {
 						element.attributes['lj-cmd'] = 'LJCut';
 					},
-					'cke:object' : function(element){
+					'cke:object': function(element) {
 						//////////  LJ Embed Media Button //////////////
 						var attributes = element.attributes,
 							classId = attributes.classid && String(attributes.classid).toLowerCase();
 
-						if(!classId && !isFlashEmbed(element)){
-							for(var i = 0; i < element.children.length; i++){
-								if(element.children[i].name == 'cke:embed'){
+						if (!classId && !isFlashEmbed(element)) {
+							for (var i = 0; i < element.children.length; i++) {
+								if (element.children[i].name == 'cke:embed') {
 									return isFlashEmbed(element.children[i]) ? createFakeElement(editor, element) : null;
 								}
 							}
@@ -957,10 +935,10 @@
 
 						return createFakeElement(editor, element);
 					},
-					'cke:embed' : function(element){
+					'cke:embed': function(element) {
 						return isFlashEmbed(element) ? createFakeElement(editor, element) : null;
 					},
-					'lj-like': function(element){
+					'lj-like': function(element) {
 						var attr = [];
 
 						var fakeElement = new CKEDITOR.htmlParser.element('div');
@@ -971,10 +949,10 @@
 							.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) {
 								var buttonNode = new CKEDITOR.htmlParser.fragment.fromHtml(button.html).children[0];
 								fakeElement.add(buttonNode);
 								attr.push(buttonName);
@@ -985,28 +963,28 @@
 						fakeElement.attributes.style = element.attributes.style;
 						return fakeElement;
 					},
-					'lj': function(element){
+					'lj': 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';
 							return ljTag;
 						} else {
-							var onSuccess = function(data){
+							var onSuccess = function(data) {
 								ljUsers[cacheName] = data.ljuser;
 
-								if(data.error){
+								if (data.error) {
 									return alert(data.error + ' "' + username + '"');
 								}
-								if(!data.success){
+								if (!data.success) {
 									return;
 								}
 
@@ -1014,12 +992,12 @@
 
 								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(cacheName == userTitle ? userName + ':' + userTitle : userName){
+									if (cacheName == userTitle ? userName + ':' + userTitle : userName) {
 										ljTag.setHtml(ljUsers[cacheName]);
 										var newLjTag = ljTag.getFirst();
 										newLjTag.setAttribute('lj-cmd', 'LJUserLink');
@@ -1029,7 +1007,7 @@
 								}
 							};
 
-							var onError = function(err){
+							var onError = function(err) {
 								alert(err + ' "' + ljUserName + '"');
 							};
 
@@ -1037,7 +1015,7 @@
 								username: ljUserName
 							};
 
-							if(ljUserTitle){
+							if (ljUserTitle) {
 								postData.usertitle = ljUserTitle;
 							}
 
@@ -1050,10 +1028,10 @@
 							});
 						}
 					},
-					a: function(element){
+					a: function(element) {
 						element.attributes['lj-cmd'] = 'LJLink';
 					},
-					img: function(element){
+					img: function(element) {
 						element.attributes['lj-cmd'] = 'LJImage';
 					}
 				}
@@ -1061,28 +1039,28 @@
 
 			dataProcessor.htmlFilter.addRules({
 				elements: {
-					div: function(element){
-						if(element.attributes['class'] == 'lj-like'){
+					div: function(element) {
+						if (element.attributes['class'] == 'lj-like') {
 							var ljLikeNode = new CKEDITOR.htmlParser.element('lj-like');
 							ljLikeNode.attributes.buttons = element.attributes.buttons;
-							if(element.attributes.style){
+							if (element.attributes.style) {
 								ljLikeNode.attributes.style = element.attributes.style;
 							}
 							ljLikeNode.isEmpty = true;
 							ljLikeNode.isOptionalClose = true;
 							return ljLikeNode;
-						} else if(!element.children.length){
+						} else if (!element.children.length) {
 							return false;
 						}
 					},
-					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;
 							var userTitle = element.children[1].children[0].children[0].value;
 
-							if(userTitle && userTitle != userName){
+							if (userTitle && userTitle != userName) {
 								ljUserNode.attributes.title = userTitle;
 							}
 
@@ -1092,14 +1070,14 @@
 					}
 				},
 				attributes: {
-					'lj-cmd': function(){
+					'lj-cmd': function() {
 						return false;
 					}
 				}
 			});
 		},
 
-		requires : [ 'fakeobjects' ]
+		requires: ['fakeobjects']
 	});
 
 })();

Modified: trunk/htdocs/js/entry.js
===================================================================
--- trunk/htdocs/js/entry.js	2011-08-10 09:03:41 UTC (rev 19688)
+++ trunk/htdocs/js/entry.js	2011-08-10 09:39:36 UTC (rev 19689)
@@ -18,7 +18,11 @@
 }
 
 function showEntryTabs(){
-	document.getElementById('entry-tabs').style.visibility = 'visible';
+	if(CKEDITOR && CKEDITOR.env.isCompatible){
+		document.getElementById('entry-tabs').style.visibility = 'visible';
+	} else {
+		document.getElementById('htmltools').style.display = 'block';
+	}
 }
 
 function changeSubmit(prefix, defaultjournal, defPrefix){
@@ -742,20 +746,13 @@
 
 	input: function(){
 		var ary = $('selecttags-all').value.split(/ *, */),
-			checkboxes = IPPUSelectTags.checkboxes,
-			tag;
+			checkboxes = IPPUSelectTags.checkboxes;
 		ary = jQuery.map(ary, function (val, idx){
 			return (val.length > 0) ? val : null
 		});
 		checkboxes.attr('checked', false);
 		while(ary.length){
-			tag = ary.pop();
-			try {
-				//if tag contains nonalpha chars, this may easily fall
-				checkboxes.filter('[value=' + tag + ']').attr('checked', true);
-			} catch(e) {
-				checkboxes.filter( function() { return this.value === tag; } ).attr('checked', true);
-			}
+			checkboxes.filter('[value=' + ary.pop() + ']').attr('checked', true);
 		}
 	},
 
@@ -972,19 +969,16 @@
 
 InOb.handleInsertImage = function (){
 	// if PhotoHosting enabled - show new popup
-    if (window.ljphotoEnabled) {
-        jQuery('#updateForm')
-            .photouploader('option', 'type', 'upload')
-            .bind('htmlready', function (event, htmlOutput) {
-                jQuery('#draft').val(jQuery('#draft').val() + htmlOutput);
-            })
-            .photouploader('show');
-    } else {
-        onInsertObject('/imgupload.bml');
-    }
-    return true;
+	if(window.ljphotoEnabled){
+		jQuery('#content').photouploader('option', 'type', 'upload')
+			.bind('htmlready', function (event, htmlOutput){
+				jQuery('#draft').val(jQuery('#draft').val() + htmlOutput);
+		}).photouploader('show');
+	} else {
+		onInsertObject('/imgupload.bml');
+	}
+	return true;
 };
-
 InOb.handleInsertVideo = function(){
 	var videoUrl = prompt('Please enter a video URL:');
 	var draft = $('draft');
@@ -1353,141 +1347,4 @@
 InOb.setTitle = function (title){
 	var wintitle = currentPopupWindow.document.getElementById('wintitle');
 	wintitle.innerHTML = title;
-};
-
-/* ******************** DRAFT SUPPORT ******************** */
-
-/* RULES:
- -- don't save if they have typed in last 3 seconds, unless it's been
- 15 seconds.  otherwise save at most every 10 seconds, if dirty.
- */
-
-var LJDraft = {};
-
-LJDraft.saveInProg = false;
-LJDraft.epoch = 0;
-LJDraft.lastSavedBody = "";
-LJDraft.prevCheckBody = "";
-LJDraft.lastTypeTime = 0;
-LJDraft.lastSaveTime = 0;
-LJDraft.autoSaveInterval = 10;
-LJDraft.savedMsg = "Autosaved at [[time]]";
-
-LJDraft.save = function (drafttext, cb){
-	var callback = cb;  // old safari closure bug
-	if(LJDraft.saveInProg){
-		return;
-	}
-
-	LJDraft.saveInProg = true;
-
-	var finished = function (){
-		LJDraft.saveInProg = false;
-		if(callback){
-			callback();
-		}
-	};
-
-	HTTPReq.getJSON({
-		method: 'POST',
-		url: '/tools/endpoints/draft.bml',
-		onData: finished,
-		onError: function (){
-			LJDraft.saveInProg = false;
-		},
-		data: HTTPReq.formEncoded({"saveDraft": drafttext})
-	});
-};
-
-LJDraft.startTimer = function (){
-	setInterval(LJDraft.checkIfDirty, 1000);  // check every second
-	LJDraft.epoch = 0;
-};
-
-LJDraft.checkIfDirty = function (){
-	LJDraft.epoch++;
-	var curBody, draft = $('draft');
-
-	if(!draft){
-		return false;
-	}
-
-	if(draft.style.display == 'none'){ // Need to check this to deal with hitting the back button
-		// Since they may start using the RTE in the middle of writing their
-		// entry, we should just get the editor each time.
-		if(!CKEDITOR || !CKEDITOR.env.isCompatible){
-			return;
-		}
-
-		curBody = CKEDITOR.instances.draft.getData();
-	} else {
-		curBody = $('draft').value;
-	}
-
-	// no changes to save
-	if(curBody == LJDraft.lastSavedBody){
-		return;
-	}
-
-	// at this point, things are dirty.
-
-	// see if they've typed in the last second.  if so,
-	// we'll want to note their last type time, and defer
-	// saving until they settle down, unless they've been
-	// typing up a storm and pass our 15 second barrier.
-	if(curBody != LJDraft.prevCheckBody){
-		LJDraft.lastTypeTime = LJDraft.epoch;
-		LJDraft.prevCheckBody = curBody;
-	}
-
-	if(LJDraft.lastSaveTime < LJDraft.lastTypeTime - 15){
-		// let's fall through and save!  they've been busy.
-	} else if(LJDraft.lastTypeTime > LJDraft.epoch - 3){
-		// they're recently typing, don't save.  let them finish.
-		return;
-	} else if(LJDraft.lastSaveTime > LJDraft.epoch - LJDraft.autoSaveInterval){
-		// we've saved recently enough.
-		return;
-	}
-
-	// async save, and pass in our callback
-	var curEpoch = LJDraft.epoch;
-	LJDraft.save(curBody, function (){
-		var msg = LJDraft.savedMsg.replace(/\[\[time\]\]/, LJDraft.getTime());
-		$('draftstatus').value = msg + ' ';
-		LJDraft.lastSaveTime = curEpoch;
-		/* capture lexical.  remember: async! */
-		LJDraft.lastSavedBody = curBody;
-	});
-};
-
-LJDraft.getTime = function (){
-	var date = new Date();
-	var hour, minute, sec, time;
-
-	hour = date.getHours();
-	if(hour >= 12){
-		time = ' PM';
-	} else {
-		time = ' AM';
-	}
-
-	if(hour > 12){
-		hour -= 12;
-	} else if(hour == 0){
-		hour = 12;
-	}
-
-	minute = date.getMinutes();
-	if(minute < 10){
-		minute = '0' + minute;
-	}
-
-	sec = date.getSeconds();
-	if(sec < 10){
-		sec = '0' + sec;
-	}
-
-	time = hour + ':' + minute + ':' + sec + time;
-	return time;
-};
+};
\ No newline at end of file

Modified: trunk/htdocs/js/rte.js
===================================================================
--- trunk/htdocs/js/rte.js	2011-08-10 09:03:41 UTC (rev 19688)
+++ trunk/htdocs/js/rte.js	2011-08-10 09:39:36 UTC (rev 19689)
@@ -1,73 +1,74 @@
-(function(){
+(function($, window) {
 	window.switchedRteOn = false;
-	var CKEditor;
 
-	window.useRichText = function (textArea, statPrefix){
-		if(!switchedRteOn){
+	var CKEditor,
+		draftData;
+
+	window.initDraft = function(data) {
+		draftData = data;
+
+		data.lastValue = '';
+		data.textArea = $('#draft');
+		data.statusNode = $('#draftstatus');
+
+		if (data.ask && data.restoreData) {
+			if (confirm(data.confirmMsg)) {
+				data.lastValue = data.restoreData;
+				data.statusNode.val(data.draftStatus);
+			}
+		}
+
+		draftData.textArea.val(draftData.lastValue);
+
+		$('#updateForm').delegate('#draft', 'keypress click', checkDraftTimer);
+	};
+
+	window.useRichText = function (statPrefix) {
+		if (!window.switchedRteOn) {
 			window.switchedRteOn = true;
-			$('switched_rte_on').value = '1';
+			$('#switched_rte_on').value = '1';
 
-			if(!CKEditor && CKEDITOR && CKEDITOR.env.isCompatible){
+			if (!CKEditor && CKEDITOR && CKEDITOR.env.isCompatible) {
 				CKEDITOR.basePath = statPrefix + '/ck/';
-				var editor = CKEDITOR.replace(textArea, {
+				var editor = CKEDITOR.replace('draft', {
 					skin: 'v2',
 					baseHref: CKEDITOR.basePath,
 					height: 350,
 					language: Site.current_lang || 'en'
 				});
 
-				editor.on('instanceReady', function(){
+				editor.on('instanceReady', function() {
 					CKEditor = editor;
 
-					$('updateForm').onsubmit = function(){
-						if(switchedRteOn){
-							this['draft'].value = CKEditor.getData();
+					editor.resetDirty();
+
+					$('#updateForm').onsubmit = function() {
+						if (window.switchedRteOn) {
+							draftData.textArea.val(CKEditor.getData());
 						}
 					};
 
-					CKEditor.on('dataReady', function(){
+					CKEditor.on('dataReady', function() {
+						$('#entry-form-wrapper').attr('class', 'hide-html');
 
-						$('entry-form-wrapper').className = 'hide-html';
-
 						CKEditor.container.show();
 						CKEditor.element.hide();
 
-						/*var ljTags = CKEditor.document.getElementsByTag('lj-template').$,
-							i = ljTags.length;
-
-						var styleNoEdit = 'cursor: default; -moz-user-select: all; -moz-user-input: none; -moz-user-focus: none; -khtml-user-select: all;';
-						while(i--){
-							var ljTag = ljTags[i];
-							var name = ljTag.getAttribute('name');
-							switch(name){
-								case 'video':
-								case 'qotd':
-									break;
-								default:
-									var value = ljTag.getAttribute('value'),
-										alt = ljTag.getAttribute('alt');
-									if(!value || !alt){
-										break;
-									}
-									var div = CKEditor.document.$.createElement('div');
-									div.className = 'lj-template';
-									div.setAttribute('name', name);
-									div.setAttribute('value', value);
-									div.setAttribute('alt', alt);
-									div.setAttribute('style', styleNoEdit);
-									div.contentEditable = false;
-									div.innerHTML = alt;
-									ljTag.parentNode.replaceChild(div, ljTag);
-							}
-						}*/
+						editor.on('dialogHide', checkDraftTimer);
+						editor.on('afterCommandExec', checkDraftTimer);
+						editor.on('insertElement', checkDraftTimer);
+						editor.on('insertHtml', checkDraftTimer);
+						editor.on('insertText', checkDraftTimer);
+						editor.document.on('keypress', checkDraftTimer);
+						editor.document.on('click', checkDraftTimer);
 					});
 				});
 			} else {
 				var data = CKEditor.element.getValue();
 
 				var commands = CKEditor._.commands;
-				for(var command in CKEditor._.commands){
-					if(commands.hasOwnProperty(command) && commands[command].state == CKEDITOR.TRISTATE_ON){
+				for (var command in CKEditor._.commands) {
+					if (commands.hasOwnProperty(command) && commands[command].state == CKEDITOR.TRISTATE_ON) {
 						commands[command].setState(CKEDITOR.TRISTATE_OFF);
 					}
 				}
@@ -75,25 +76,101 @@
 				CKEditor.setData(data);
 			}
 		}
-		return false; // do not follow link
+
+		return false;
 	};
 
-	window.usePlainText = function(textArea){
-		if(switchedRteOn){
+	window.usePlainText = function() {
+		if (window.switchedRteOn) {
 			window.switchedRteOn = false;
-			$('switched_rte_on').value = '0';
+			$('#switched_rte_on').value = '0';
 
-			if(CKEditor){
+			if (CKEditor) {
 				var data = CKEditor.getData();
 				CKEditor.element.setValue(data);
-				
+
 				CKEditor.container.hide();
 				CKEditor.element.show();
 			}
 
-			$('entry-form-wrapper').className = 'hide-richtext';
+			$('#entry-form-wrapper').attr('class', 'hide-richtext');
 		}
 
 		return false;
 	};
-})();
\ No newline at end of file
+
+	function checkDraftTimer() {
+		if (draftData.timer) {
+			draftData.timer = clearTimeout(draftData.timer);
+		}
+
+		if (!draftData.globalTimer) {
+			draftData.globalTimer = setTimeout(saveDraft, draftData.interval * 1000);
+		}
+
+		draftData.timer = setTimeout(saveDraft, 3000);
+	}
+
+	function onSaveDraft() {
+		var date = new Date();
+		var hour, minute, sec, time;
+
+		hour = date.getHours();
+		if (hour >= 12) {
+			time = ' PM';
+		} else {
+			time = ' AM';
+		}
+
+		if (hour > 12) {
+			hour -= 12;
+		} else if (hour == 0) {
+			hour = 12;
+		}
+
+		minute = date.getMinutes();
+		if (minute < 10) {
+			minute = Number('0' + minute);
+		}
+
+		sec = date.getSeconds();
+		if (sec < 10) {
+			sec = Number('0' + sec);
+		}
+
+		draftData.statusNode.val(draftData.saveMsg.replace(/\[\[time\]\]/, hour + ':' + minute + ':' + sec + time + ' '));
+	}
+
+	function saveDraft() {
+		var value = '';
+
+		if (window.switchedRteOn && CKEditor) {
+			if (CKEditor.checkDirty()) {
+				CKEditor.resetDirty();
+				value = CKEditor.getData();
+			}
+		} else if (draftData.textArea.length) {
+			var currentValue = draftData.textArea.val();
+			if (currentValue != draftData.lastValue) {
+				value = currentValue;
+			}
+		}
+
+		if (value.length) {
+			if (draftData.globalTimer) {
+				draftData.globalTimer = clearTimeout(draftData.globalTimer);
+			}
+
+			draftData.lastValue = value;
+			HTTPReq.getJSON({
+				method: 'POST',
+				url: '/tools/endpoints/draft.bml',
+				onData: onSaveDraft,
+				data: HTTPReq.formEncoded({
+					saveDraft: value
+				})
+			});
+		}
+	}
+
+})(jQuery, this);
\ No newline at end of file

Modified: trunk/htdocs/update.bml
===================================================================
--- trunk/htdocs/update.bml	2011-08-10 09:03:41 UTC (rev 19688)
+++ trunk/htdocs/update.bml	2011-08-10 09:39:36 UTC (rev 19689)
@@ -812,31 +812,19 @@
             top.location.href = document.location.href;
         }
 
-        var restoredDraft = $draft;
-
-        function init_update_bml() {
+        function initUpdateBml() {
             window.isSupUser = $is_sup;
-            $initDraft;
             $_[0]->{'onload'}
+            window.initDraft({
+              ask: true,
+              restoreData: $draft,
+              saveMsg: '$eMLautosave',
+              interval: $LJ::AUTOSAVE_DRAFT_INTERVAL,
+              draftStatus: '$eMLrestored ',
+              confirmMsg: '$eMLconfirm'
+            });
             $pageload
         }
-
-        // TODO: make these function calls
-        LJDraft.autoSaveInterval = $LJ::AUTOSAVE_DRAFT_INTERVAL;
-        LJDraft.savedMsg = '$eMLautosave';
-
-        function initDraft(askToRestore) {
-            if (askToRestore && restoredDraft) {
-                if (confirm("$eMLconfirm")) {
-                    \$("draft").value = restoredDraft;
-                    \$("draftstatus").value = '$eMLrestored ';
-                } else {
-                    // Clear out their current draft
-                    LJDraft.save('');
-                }
-            }
-            LJDraft.startTimer();
-        }
     </script>^;
 
     $ret .= (! $LJ::REQ_HEAD_HAS{'chalresp_js'}++) ? $LJ::COMMON_CODE{'chalresp_js'} : "";

Tags: b_vladi, bml, js, livejournal, pm
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