From 37cbb9a92aede2e523e80e95ba3a7c7138ac622d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 12 Apr 2010 21:57:57 +0000 Subject: [PATCH] BUGFIX #4471: Fixed link insertion in Safari. (from r97581) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102507 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/tiny_mce_improvements.js | 32 ++++++++--------------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/javascript/tiny_mce_improvements.js b/javascript/tiny_mce_improvements.js index 01d1fa46e..857977c6a 100755 --- a/javascript/tiny_mce_improvements.js +++ b/javascript/tiny_mce_improvements.js @@ -187,22 +187,10 @@ LinkForm.prototype = { } break; } - + if(this.originalSelection) { tinyMCE.activeEditor.selection.setRng(this.originalSelection); } - /* - else { - var mceInst = tinyMCE.activeEditor; - var sel = mceInst.getSel(); - if(sel.addRange && sel.removeAllRanges) { - sel.removeAllRanges(); - sel.addRange(this.originalSelection); - } - mceInst.selectedElement = mceInst.getFocusElement(); - } - } - */ var attributes = { href : href, @@ -211,23 +199,15 @@ LinkForm.prototype = { innerHTML : this.elements.LinkText.value ? this.elements.LinkText.value : "Your Link" }; - // Remove the old link while preserving the selection - if(tinyMCE.activeEditor.selection.getContent() != "") { - var rng = tinyMCE.activeEditor.selection.getRng(); - tinyMCE.activeEditor.selection.setRng(rng); - tinyMCE.activeEditor.execCommand('unlink'); - tinyMCE.activeEditor.selection.setRng(rng); - } - // Add the new link - this.ssInsertLink(tinyMCE.activeEditor, attributes); + this.ssInsertLink(tinyMCE.activeEditor, attributes, this); }, /** * Insert a link into the given editor. * Replaces mceInsertLink in that innerHTML can also be set */ - ssInsertLink: function(ed, attributes) { + ssInsertLink: function(ed, attributes, linkFormObj) { var v = attributes; var s = ed.selection, e = ed.dom.getParent(s.getNode(), 'A'); @@ -239,12 +219,16 @@ LinkForm.prototype = { if(k == 'innerHTML') e.innerHTML = v; else ed.dom.setAttrib(e, k, v); }); + try { + s.select(e); + if(linkFormObj) linkFormObj.updateSelection(ed); + } catch(er) {} }; function replace() { tinymce.each(ed.dom.select('a'), function(e) { if (e.href == 'javascript:mctmp(0);') set(e); - }); + }); } if(attributes.innerHTML && !ed.selection.getContent()) {