Ticket #8435: testplugin.html

File testplugin.html, 1.9 KB (added by Jakub Ś, 12 years ago)
Line 
1<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
2<script type="text/javascript">
3
4function insertLink(){
5        var CK = window.parent.CKEDITOR;
6        var link = $("#txtLink").val();
7        if(link == ""){
8                link = "no link";
9        }
10        if (CK != null)
11        {
12                var selected_html = CK.instances.editor1.getSelection().getSelectedText();                             
13                var mySelection = CK.instances.editor1.getSelection();
14                var ranges = mySelection.getRanges( true );
15                if ( ranges.length == 1 && ranges[0].collapsed )
16                {
17                        //link.js Line 1339
18                        var text = new CK.dom.text( link, CK.instances.editor1.document );
19                        ranges[0].insertNode( text );
20                        ranges[0].selectNodeContents( text );
21                        mySelection.selectRanges( ranges );
22                }
23                /*if(CK.instances.editor1.getSelection().getStartElement().getName() == "img"){
24                        selected_html = CK.instances.editor1.getSelection().getStartElement().getOuterHtml();
25                }
26                else{
27                        var mySelection = CK.instances.editor1.getSelection();                 
28                        if (CK.env.ie) {
29                                mySelection.unlock(true);
30                                selected_html = mySelection.getNative().createRange().text;
31                        } else {
32                                selected_html = mySelection.getNative();
33                        }
34                        if(selected_html == ""){
35                                selected_html = link;
36                        }
37                }*/
38               
39               
40                var attributes = {};
41                attributes.target = '_blank';
42                attributes.href = link;
43                // Insert link (apply link style) to selected html in editor.
44                var style = new CK.style( { element : 'a', attributes : attributes } );
45                style.type = CK.STYLE_INLINE; // need to override... dunno why.
46                style.apply( CK.instances.editor1.document );   
47               
48                //var link = "<a href='" + link + "' target='_blank'>" + selected_html + "</a>";
49                //CK.instances.editor1.insertHtml( link);       
50               
51        }
52        CK.dialog.getCurrent().hide();
53       
54}
55
56
57</script>
58<input id="txtLink" name="txtLink"/>
59<a href="javascript:void(0);" onclick="insertLink()">Insert Link</a>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy