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