We are creating a plugin that allows the user to select from a long list of custom anchors. We apply this anchor style to the selected text or if there is not selected text, we create some text, select it and apply the same anchor we would if there was a selection. Everything works in FF and Chrome. The problem comes in IE. The first time we try, it fails at the style.apply(editor.document); line. Then if you try it again, it works just fine.
Below is the code we are using to create the anchor. Can anyone see what we are doing wrong?
var link = { text: 'Brochure Link', tag: 'http://www.example.com/brochure.php' }; var selection = editor.getSelection(); var ranges = selection.getRanges(); try { range = ranges[0]; } catch (e) { return; } range.shrink(editor.SHRINK_TEXT); // Create element if current selection is collapsed. if (ranges.length == 1 && ranges[0].collapsed) { var text = new window.parent.CKEDITOR.dom.text(link.text, editor.document); ranges[0].insertNode(text); ranges[0].selectNodeContents(text); } var style = new window.parent.CKEDITOR.style({ element: 'a', attributes: { href: link.tag} }); style.type = window.parent.CKEDITOR.STYLE_INLINE; // need to override... dunno why. style.apply(editor.document);
Re: Applying anchor style to selected text in IE
Re: Applying anchor style to selected text in IE