diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-01-25 17:45:33 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-01-25 18:00:33 +0100 |
commit | 7adcb81e4f83f98c468889aaa5a85558ba88c770 (patch) | |
tree | 0d6ede733777b29060b48df4afaa2c64bfbae276 /sources/plugins/link/dialogs/anchor.js | |
download | connexionswing-ckeditor-component-7adcb81e4f83f98c468889aaa5a85558ba88c770.tar.gz connexionswing-ckeditor-component-7adcb81e4f83f98c468889aaa5a85558ba88c770.tar.zst connexionswing-ckeditor-component-7adcb81e4f83f98c468889aaa5a85558ba88c770.zip |
Initial commit4.5.6
Diffstat (limited to 'sources/plugins/link/dialogs/anchor.js')
-rw-r--r-- | sources/plugins/link/dialogs/anchor.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/sources/plugins/link/dialogs/anchor.js b/sources/plugins/link/dialogs/anchor.js new file mode 100644 index 00000000..899f7dc4 --- /dev/null +++ b/sources/plugins/link/dialogs/anchor.js | |||
@@ -0,0 +1,105 @@ | |||
1 | /** | ||
2 | * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | ||
4 | */ | ||
5 | |||
6 | CKEDITOR.dialog.add( 'anchor', function( editor ) { | ||
7 | // Function called in onShow to load selected element. | ||
8 | var loadElements = function( element ) { | ||
9 | this._.selectedElement = element; | ||
10 | |||
11 | var attributeValue = element.data( 'cke-saved-name' ); | ||
12 | this.setValueOf( 'info', 'txtName', attributeValue || '' ); | ||
13 | }; | ||
14 | |||
15 | function createFakeAnchor( editor, attributes ) { | ||
16 | return editor.createFakeElement( editor.document.createElement( 'a', { | ||
17 | attributes: attributes | ||
18 | } ), 'cke_anchor', 'anchor' ); | ||
19 | } | ||
20 | |||
21 | return { | ||
22 | title: editor.lang.link.anchor.title, | ||
23 | minWidth: 300, | ||
24 | minHeight: 60, | ||
25 | onOk: function() { | ||
26 | var name = CKEDITOR.tools.trim( this.getValueOf( 'info', 'txtName' ) ); | ||
27 | var attributes = { | ||
28 | id: name, | ||
29 | name: name, | ||
30 | 'data-cke-saved-name': name | ||
31 | }; | ||
32 | |||
33 | if ( this._.selectedElement ) { | ||
34 | if ( this._.selectedElement.data( 'cke-realelement' ) ) { | ||
35 | var newFake = createFakeAnchor( editor, attributes ); | ||
36 | newFake.replace( this._.selectedElement ); | ||
37 | |||
38 | // Selecting fake element for IE. (#11377) | ||
39 | if ( CKEDITOR.env.ie ) | ||
40 | editor.getSelection().selectElement( newFake ); | ||
41 | } else { | ||
42 | this._.selectedElement.setAttributes( attributes ); | ||
43 | } | ||
44 | } else { | ||
45 | var sel = editor.getSelection(), | ||
46 | range = sel && sel.getRanges()[ 0 ]; | ||
47 | |||
48 | // Empty anchor | ||
49 | if ( range.collapsed ) { | ||
50 | var anchor = createFakeAnchor( editor, attributes ); | ||
51 | range.insertNode( anchor ); | ||
52 | } else { | ||
53 | if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) | ||
54 | attributes[ 'class' ] = 'cke_anchor'; | ||
55 | |||
56 | // Apply style. | ||
57 | var style = new CKEDITOR.style( { element: 'a', attributes: attributes } ); | ||
58 | style.type = CKEDITOR.STYLE_INLINE; | ||
59 | editor.applyStyle( style ); | ||
60 | } | ||
61 | } | ||
62 | }, | ||
63 | |||
64 | onHide: function() { | ||
65 | delete this._.selectedElement; | ||
66 | }, | ||
67 | |||
68 | onShow: function() { | ||
69 | var sel = editor.getSelection(), | ||
70 | fullySelected = sel.getSelectedElement(), | ||
71 | fakeSelected = fullySelected && fullySelected.data( 'cke-realelement' ), | ||
72 | linkElement = fakeSelected ? | ||
73 | CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected ) : | ||
74 | CKEDITOR.plugins.link.getSelectedLink( editor ); | ||
75 | |||
76 | if ( linkElement ) { | ||
77 | loadElements.call( this, linkElement ); | ||
78 | !fakeSelected && sel.selectElement( linkElement ); | ||
79 | |||
80 | if ( fullySelected ) | ||
81 | this._.selectedElement = fullySelected; | ||
82 | } | ||
83 | |||
84 | this.getContentElement( 'info', 'txtName' ).focus(); | ||
85 | }, | ||
86 | contents: [ { | ||
87 | id: 'info', | ||
88 | label: editor.lang.link.anchor.title, | ||
89 | accessKey: 'I', | ||
90 | elements: [ { | ||
91 | type: 'text', | ||
92 | id: 'txtName', | ||
93 | label: editor.lang.link.anchor.name, | ||
94 | required: true, | ||
95 | validate: function() { | ||
96 | if ( !this.getValue() ) { | ||
97 | alert( editor.lang.link.anchor.errorName ); // jshint ignore:line | ||
98 | return false; | ||
99 | } | ||
100 | return true; | ||
101 | } | ||
102 | } ] | ||
103 | } ] | ||
104 | }; | ||
105 | } ); | ||