Committer: vkurkin
LJSV-1478: Inserting a link in the Rich Text editor in IE9 failsU trunk/htdocs/js/ck/config.js U trunk/htdocs/js/ck/plugins/livejournal/plugin.js U trunk/htdocs/js/entry.js U trunk/htdocs/js/poll.js U trunk/htdocs/js/rte.js
Modified: trunk/htdocs/js/ck/config.js =================================================================== --- trunk/htdocs/js/ck/config.js 2011-07-21 07:08:09 UTC (rev 19504) +++ trunk/htdocs/js/ck/config.js 2011-07-21 08:10:40 UTC (rev 19505) @@ -28,7 +28,7 @@ 'colordialog,' + 'contextmenu,' + 'dialog,' + - 'div,' + + //'div,' + //'elementspath,' + 'enterkey,' + 'entities,' + @@ -54,17 +54,17 @@ 'pastefromword,' + 'pastetext,' + //'popup,' + - 'preview,' + + //'preview,' + //'print,' + 'removeformat,' + 'resize,' + //'save,' + //'smiley,' + - 'showblocks,' + + //'showblocks,' + 'showborders,' + 'sourcearea,' + 'stylescombo,' + - 'scayt,' + + //'scayt,' + 'table,' + 'tabletools,' + 'specialchar,' + @@ -149,7 +149,7 @@ config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div'; config.bodyId = ''; config.bodyClass = ''; - config.fontSize_defaultLabel = ''; + config.fontSize_defaultLabel = 'Size'; config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var'; config.removeFormatAttributes = 'class,style,lang,width,height,align,hspace,valign'; config.stylesSet = [{ Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js =================================================================== --- trunk/htdocs/js/ck/plugins/livejournal/plugin.js 2011-07-21 07:08:09 UTC (rev 19504) +++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js 2011-07-21 08:10:40 UTC (rev 19505) @@ -2,30 +2,30 @@ var likeButtons = [ { + label: top.CKLang.LJLike_button_facebook, + id: 'facebook', + abbr: 'fb', + html: '<div class="lj-like-item lj-like-gag">' + top.CKLang.LJLike_button_facebook + '</div>' + }, + { + label: top.CKLang.LJLike_button_twitter, + id: 'twitter', + abbr: 'tw', + html: '<div class="lj-like-item lj-like-gag">' + top.CKLang.LJLike_button_twitter + '</div>' + }, + { label: top.CKLang.LJLike_button_google, id: 'google', abbr: 'go', html: '<div class="lj-like-item lj-like-gag">' + top.CKLang.LJLike_button_google + '</div>' }, { - label: top.CKLang.LJLike_button_facebook, - id: 'facebook', - abbr: 'fb', - html: '<div class="lj-like-item lj-like-gag">' + top.CKLang.LJLike_button_facebook + '</div>' - }, - { label: top.CKLang.LJLike_button_vkontakte, id: 'vkontakte', abbr: 'vk', html: '<div class="lj-like-item lj-like-gag">' + top.CKLang.LJLike_button_vkontakte + '</div>' }, { - label: top.CKLang.LJLike_button_twitter, - id: 'twitter', - abbr: 'tw', - html: '<div class="lj-like-item lj-like-gag">' + top.CKLang.LJLike_button_twitter + '</div>' - }, - { label: top.CKLang.LJLike_button_give, id: 'livejournal', abbr: 'lj', @@ -39,6 +39,7 @@ init: function(editor){ 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>') @@ -63,7 +64,6 @@ html = '<pre>' + html + '</pre>'; } - html = html.replace(/<br\s*\/?>/g, ''); html = CKEDITOR.htmlDataProcessor.prototype.toHtml.call(this, html, fixForBody); if(!$('event_format').checked){ @@ -238,8 +238,6 @@ } }); - - editor.ui.addButton('LJImage', { label: editor.lang.common.imageButton, command: 'LJImage' @@ -262,8 +260,11 @@ function doEmbed(content){ if(content && content.length){ - editor.insertHtml('<div class="ljembed">' + content + '</div><br/>'); - editor.focus(); + if(switchedRteOn){ + editor.insertHtml('<div class="ljembed">' + content + '</div><br/>'); + } else { + + } } } @@ -340,7 +341,7 @@ var command = editor.getCommand('LJPollLink'); command.setState(state); currentPollForm = this.getSelection().getStartElement().getAscendant('form', true); - currentPollForm = currentPollForm && currentPollForm.hasClass('ljpoll') ? currentPollForm.$ : null; + currentPollForm = currentPollForm && currentPollForm.hasClass('ljpoll') ? currentPollForm : null; if(state == CKEDITOR.TRISTATE_ON){ parent.LJ_IPPU.showNote(noticeHtml, editor.container.$).centerOnWidget(editor.container.$); } @@ -399,7 +400,7 @@ elements :[ { type : 'html', - html : '<iframe src="/tools/ck_poll_setup.bml" frameborder="0" style="width:100%; height:370px"></iframe>', + html : '<iframe src="/tools/ck_poll_setup.bml" allowTransparency="true" frameborder="0" style="width:100%; height:370px; position: relative;"></iframe>', onShow: function(data){ if(!okButtonNode){ (okButtonNode = document.getElementById(data.sender.getButton('LJPool_Ok').domId).parentNode) @@ -423,7 +424,7 @@ elements:[ { type : 'html', - html : '<iframe src="/tools/ck_poll_questions.bml" frameborder="0" style="width:100%; height:370px"></iframe>', + html : '<iframe src="/tools/ck_poll_questions.bml" allowTransparency="true" frameborder="0" style="width:100%; height:370px; position: relative;"></iframe>', onShow: function(){ var iframe = this.getElement('iframe'); questionsWindow = iframe.$.contentWindow; @@ -481,13 +482,13 @@ ////////// LJ Like Button ////////////// var buttonsLength = likeButtons.length; var dialogContents = []; - var currentLjLikeNode; + var currentLjLikeNode, currentLjLikeButton; likeButtons.defaultButtons = []; for(var i = 0; i < buttonsLength; i++){ var button = likeButtons[i]; likeButtons[button.id] = likeButtons[button.abbr] = button; - likeButtons.defaultButtons.push(button.abbr); + likeButtons.defaultButtons.push(button.id); dialogContents.push({ type: 'checkbox', label: button.label, @@ -534,13 +535,15 @@ onClick : function(evt){ var dialog = evt.data.dialog, attr = []; var likeNode = currentLjLikeNode || new CKEDITOR.dom.element('div'); + likeNode.$.readOnly = true; + likeNode.remove(); likeNode.setHtml(''); for(var i = 0; i < buttonsLength; i++){ var button = likeButtons[i]; var buttonNode = dialog.getContentElement('LJLike_Options', 'LJLike_' + button.id); if(buttonNode.getValue('checked')){ - attr.push(button.abbr); + attr.push(button.id); likeNode.appendHtml(button.html); } } @@ -549,8 +552,6 @@ likeNode.setAttribute('buttons', attr.join(',')); likeNode.setAttribute('class', 'lj-like'); editor.insertElement(likeNode); - } else { - likeNode.remove(); } dialog.hide(); } @@ -583,13 +584,21 @@ editor.attachStyleStateChange(new CKEDITOR.style({ element: 'div' }), function(){ - currentLjLikeNode = editor.getSelection().getStartElement().getAscendant('div', true); + currentLjLikeNode = this.getSelection().getStartElement(); + if(currentLjLikeButton){ + currentLjLikeButton.setStyle('border-color', '#999999'); + currentLjLikeButton = null; + } while(currentLjLikeNode){ - if(currentLjLikeNode.hasClass('lj-like')){ + if(currentLjLikeNode.hasClass('lj-like-item')){ + currentLjLikeButton = currentLjLikeNode; + currentLjLikeButton.setStyle('border-color', '#ff0000'); + } else if(currentLjLikeNode.hasClass('lj-like')){ break; } currentLjLikeNode = currentLjLikeNode.getParent(); } + editor.getCommand('LJLikeCommand').setState(currentLjLikeNode ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF); }); @@ -600,8 +609,81 @@ } }); + /*editor.on('dataReady', function(){ + editor.document.on('keypress', function(evt){ + var key = evt.data.getKey(); + if(editor.getCommand('LJLikeCommand').state == CKEDITOR.TRISTATE_ON){ + if(key == 46 || key == 8){ + if(currentLjLikeButton){ + editor.getCommand('LJLike_remove').exec(); + } + + if(!currentLjLikeNode.getChildCount()){ + editor.getCommand('LJLike_removeAll').exec(); + } + + console.log(editor.getSelection().getRanges()); + evt.data.preventDefault(); + } + } + }); + });*/ + editor.addCommand('LJLikeCommand', new CKEDITOR.dialogCommand('LJLikeDialog')); + editor.addCommand('LJLike_remove', { + exec : function(){ + var newButtons = currentLjLikeNode.getAttribute('buttons').split(','); + newButtons.splice(currentLjLikeButton.getIndex(), 1); + currentLjLikeNode.setAttribute('buttons', newButtons.join(',')); + currentLjLikeButton.remove(); + } + }); + + editor.addCommand('LJLike_removeAll', { + exec : function(){ + currentLjLikeNode.remove(); + } + }); + + editor.addMenuGroup('LJLike', 5); + + editor.addMenuItems({ + LJLike_remove: { + label : 'Delete button', + command : 'LJLike_remove', + group : 'LJLike', + order : 5 + }, + LJLike_removeAll: { + label : 'Delete all buttons', + command : 'LJLike_removeAll', + group : 'LJLike', + order : 5 + } + }); + + var execCommandDefinition = { + LJLike_remove : CKEDITOR.TRISTATE_ON, + LJLike_removeAll : CKEDITOR.TRISTATE_ON + }; + + editor.contextMenu.addListener(function(element){ + if(!element || element.isReadOnly()){ + return null; + } + + var elementPath = new CKEDITOR.dom.elementPath(element); + currentLjLikeButton = elementPath.block; + + if(currentLjLikeButton && currentLjLikeButton.hasClass('lj-like-item')){ + return execCommandDefinition; + } + + + return null; + }); + editor.ui.addButton('LJLike', { label: top.CKLang.LJLike_name, command: 'LJLikeCommand' Modified: trunk/htdocs/js/entry.js =================================================================== --- trunk/htdocs/js/entry.js 2011-07-21 07:08:09 UTC (rev 19504) +++ trunk/htdocs/js/entry.js 2011-07-21 08:10:40 UTC (rev 19505) @@ -944,26 +944,24 @@ return true; }; -entry_insert_embed = function (cb){ - var prompt = "Add media from other websites by copying and pasting their embed code here. "; - LJ_IPPU.textPrompt("Insert Embedded Content", prompt, cb); -}; - InOb.handleInsertEmbed = function (){ - var cb = function (content){ - var form = $("updateForm"); - if(! form || ! form.event){ - ; - } - form.event.value += "\n<lj-embed>\n" + content + "\n</lj-embed>"; - }; - entry_insert_embed(cb); + LJ_IPPU.textPrompt(top.CKLang.LJEmbedPromptTitle, top.CKLang.LJEmbedPrompt, function(content){ + $('updateForm').event.value += "\n<lj-embed>\n" + content + "\n</lj-embed>"; + }); }; InOb.handleInsertImage = function (){ - var include; - include = '/imgupload.bml'; - onInsertObject(include); + // if PhotoHosting enabled - show new popup + 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(){ Modified: trunk/htdocs/js/poll.js =================================================================== --- trunk/htdocs/js/poll.js 2011-07-21 07:08:09 UTC (rev 19504) +++ trunk/htdocs/js/poll.js 2011-07-21 08:10:40 UTC (rev 19505) @@ -14,19 +14,18 @@ ], ...} */ -// Poll Object Constructor function Poll(selectPoll, qDoc, sDoc, qNum){ if(typeof selectPoll == 'string'){ // IE custom tags. http://msdn.microsoft.com/en-us/library/ms531076%28VS.85%29.aspx selectPoll = jQuery(selectPoll.replace(/<(\/?)lj-(poll|pq|pi)(>| )/gi, '<$1lj:$2$3')); - var tag_prefix = jQuery.browser.msie ? '' : 'lj\\:'; + var tagPrefix = jQuery.browser.msie && Number(jQuery.browser.version) < 9 ? '' : 'lj\\:'; this.name = selectPoll.attr('name'); this.whovote = selectPoll.attr('whovote'); this.whoview = selectPoll.attr('whoview'); this.questions = []; - selectPoll.find(tag_prefix + 'pq').each(function(i, pq){ + selectPoll.find(tagPrefix + 'pq').each(function(i, pq){ pq = jQuery(pq); var name = pq.html().match(/^\s*(.*?)\s*(?:<lj:pi>|$)/); var question = { @@ -40,7 +39,7 @@ } if(/^check|drop|radio$/.test(question.type)){ - pq.find(tag_prefix + 'pi').each(function(){ + pq.find(tagPrefix + 'pi').each(function(){ question.answers.push(jQuery(this).html()) }); } @@ -80,13 +79,13 @@ if(this.name){ html += ' <i>' + this.name + '</i>'; } - html += '<br/>Open to: ' + '<b>' + this.whovote + '</b>, results viewable to: ' + '<b>' + this.whoview + '</b>'; + html += '<br />Open to: ' + '<b>' + this.whovote + '</b>, results viewable to: ' + '<b>' + this.whoview + '</b>'; for(var i = 0; i < this.questions.length; i++){ - html += '<br/><p>' + this.questions[i].name + '</p>' + '<p style="margin:0 0 10px 40px">'; + html += '<br /><p>' + this.questions[i].name + '</p>' + '<p style="margin:0 0 10px 40px">'; if(this.questions[i].type == 'radio' || this.questions[i].type == 'check'){ var type = this.questions[i].type == 'check' ? 'checkbox' : this.questions[i].type; for(var j = 0; j < this.questions[i].answers.length; j++){ - html += '<input type="' + type + '">' + this.questions[i].answers[j] + '<br/>'; + html += '<input type="' + type + '">' + this.questions[i].answers[j] + '<br />'; } } else if(this.questions[i].type == 'drop'){ html += '<select name="select_' + i + '">' + '<option value=""></option>'; @@ -103,7 +102,7 @@ to = Number(this.questions[i].to), by = Number(this.questions[i].by); for(var j = from; j <= to; j = j + by){ - html += '<td><input type="radio"/><br/>' + j + '</td>'; + html += '<td><input type="radio"/><br />' + j + '</td>'; } html += '</tr></tbody></table>'; } Modified: trunk/htdocs/js/rte.js =================================================================== --- trunk/htdocs/js/rte.js 2011-07-21 07:08:09 UTC (rev 19504) +++ trunk/htdocs/js/rte.js 2011-07-21 08:10:40 UTC (rev 19505) @@ -1,78 +1,7 @@ (function(){ - var cache= {}; - - function updateLJUser(ljTag, html){ - var node = CKEditor.document.$.createElement('b'); - node.innerHTML = html; - ljTag.parentNode.replaceChild(node.firstChild, ljTag); - } - - function LJToHtml(){ - var insobj = $('insobj'); - if(insobj){ - insobj.className = 'on'; - } - - var jrich = $('jrich'); - if(jrich){ - jrich.className = 'on'; - } - - var jplain = $('jplain'); - if(jplain){ - jplain.className = ''; - } - - var htmltools = $('htmltools'); - if(htmltools){ - htmltools.style.display = 'none'; - } - - var preview = $('qotd_html_preview'); - if(preview){ - preview.style.display = 'none'; - } - - 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--){ - 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); - } - } - - return false; - } - window.switchedRteOn = false; var CKEditor; - var closeEmptyTags = function(data){ - return data.replace(/<((?!br)[^\s>]+)([^\/>]+)?\/>/gi, '<$1$2></$1>'); - }; - window.useRichText = function (textArea, statPrefix){ if(!switchedRteOn){ window.switchedRteOn = true; @@ -95,7 +24,64 @@ } }; - CKEditor.on('dataReady', LJToHtml); + CKEditor.on('dataReady', function(){ + var insobj = $('insobj'); + if(insobj){ + insobj.className = 'on'; + } + + var jrich = $('jrich'); + if(jrich){ + jrich.className = 'on'; + } + + var jplain = $('jplain'); + if(jplain){ + jplain.className = ''; + } + + var htmltools = $('htmltools'); + if(htmltools){ + htmltools.style.display = 'none'; + } + + var preview = $('qotd_html_preview'); + if(preview){ + preview.style.display = 'none'; + } + + 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); + } + } + }); }); } else { var data = CKEditor.element.getValue(); @@ -106,8 +92,7 @@ commands[command].setState(CKEDITOR.TRISTATE_OFF); } } - - data = closeEmptyTags(data); + CKEditor.setData(data); } }