diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2017-12-04 17:54:04 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2017-12-04 17:54:04 +0100 |
commit | 317f8f8f0651488f226b5280a8f036c7c135c639 (patch) | |
tree | 97bd4889ab2822a00d4b0f0d5cde38b59f9f41de /sources/plugins/link/dialogs | |
parent | 1096cdefb1c9a3f3c4ca6807e272da6c92e5ed9c (diff) | |
download | piedsjaloux-ckeditor-component-317f8f8f0651488f226b5280a8f036c7c135c639.tar.gz piedsjaloux-ckeditor-component-317f8f8f0651488f226b5280a8f036c7c135c639.tar.zst piedsjaloux-ckeditor-component-317f8f8f0651488f226b5280a8f036c7c135c639.zip |
Add oembed4.7.3
Diffstat (limited to 'sources/plugins/link/dialogs')
-rw-r--r-- | sources/plugins/link/dialogs/anchor.js | 29 | ||||
-rw-r--r-- | sources/plugins/link/dialogs/link.js | 223 |
2 files changed, 190 insertions, 62 deletions
diff --git a/sources/plugins/link/dialogs/anchor.js b/sources/plugins/link/dialogs/anchor.js index e544275..04a4abe 100644 --- a/sources/plugins/link/dialogs/anchor.js +++ b/sources/plugins/link/dialogs/anchor.js | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. | 2 | * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | 3 | * For licensing, see LICENSE.md or http://ckeditor.com/license |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -18,6 +18,21 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) { | |||
18 | } ), 'cke_anchor', 'anchor' ); | 18 | } ), 'cke_anchor', 'anchor' ); |
19 | } | 19 | } |
20 | 20 | ||
21 | |||
22 | function getSelectedAnchor( selection ) { | ||
23 | var range = selection.getRanges()[ 0 ], | ||
24 | element = selection.getSelectedElement(); | ||
25 | |||
26 | // In case of table cell selection, we want to shrink selection from td to a element. | ||
27 | range.shrink( CKEDITOR.SHRINK_ELEMENT ); | ||
28 | element = range.getEnclosedNode(); | ||
29 | |||
30 | if ( element && element.type === CKEDITOR.NODE_ELEMENT && | ||
31 | ( element.data( 'cke-real-element-type' ) === 'anchor' || element.is( 'a' ) ) ) { | ||
32 | return element; | ||
33 | } | ||
34 | } | ||
35 | |||
21 | return { | 36 | return { |
22 | title: editor.lang.link.anchor.title, | 37 | title: editor.lang.link.anchor.title, |
23 | minWidth: 300, | 38 | minWidth: 300, |
@@ -35,9 +50,10 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) { | |||
35 | var newFake = createFakeAnchor( editor, attributes ); | 50 | var newFake = createFakeAnchor( editor, attributes ); |
36 | newFake.replace( this._.selectedElement ); | 51 | newFake.replace( this._.selectedElement ); |
37 | 52 | ||
38 | // Selecting fake element for IE. (#11377) | 53 | // Selecting fake element for IE. (http://dev.ckeditor.com/ticket/11377) |
39 | if ( CKEDITOR.env.ie ) | 54 | if ( CKEDITOR.env.ie ) { |
40 | editor.getSelection().selectElement( newFake ); | 55 | editor.getSelection().selectElement( newFake ); |
56 | } | ||
41 | } else { | 57 | } else { |
42 | this._.selectedElement.setAttributes( attributes ); | 58 | this._.selectedElement.setAttributes( attributes ); |
43 | } | 59 | } |
@@ -56,7 +72,7 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) { | |||
56 | // Apply style. | 72 | // Apply style. |
57 | var style = new CKEDITOR.style( { element: 'a', attributes: attributes } ); | 73 | var style = new CKEDITOR.style( { element: 'a', attributes: attributes } ); |
58 | style.type = CKEDITOR.STYLE_INLINE; | 74 | style.type = CKEDITOR.STYLE_INLINE; |
59 | editor.applyStyle( style ); | 75 | style.applyToRange( range ); |
60 | } | 76 | } |
61 | } | 77 | } |
62 | }, | 78 | }, |
@@ -67,7 +83,7 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) { | |||
67 | 83 | ||
68 | onShow: function() { | 84 | onShow: function() { |
69 | var sel = editor.getSelection(), | 85 | var sel = editor.getSelection(), |
70 | fullySelected = sel.getSelectedElement(), | 86 | fullySelected = getSelectedAnchor( sel ), |
71 | fakeSelected = fullySelected && fullySelected.data( 'cke-realelement' ), | 87 | fakeSelected = fullySelected && fullySelected.data( 'cke-realelement' ), |
72 | linkElement = fakeSelected ? | 88 | linkElement = fakeSelected ? |
73 | CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected ) : | 89 | CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected ) : |
@@ -77,8 +93,9 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) { | |||
77 | loadElements.call( this, linkElement ); | 93 | loadElements.call( this, linkElement ); |
78 | !fakeSelected && sel.selectElement( linkElement ); | 94 | !fakeSelected && sel.selectElement( linkElement ); |
79 | 95 | ||
80 | if ( fullySelected ) | 96 | if ( fullySelected ) { |
81 | this._.selectedElement = fullySelected; | 97 | this._.selectedElement = fullySelected; |
98 | } | ||
82 | } | 99 | } |
83 | 100 | ||
84 | this.getContentElement( 'info', 'txtName' ).focus(); | 101 | this.getContentElement( 'info', 'txtName' ).focus(); |
diff --git a/sources/plugins/link/dialogs/link.js b/sources/plugins/link/dialogs/link.js index 35975c7..4c60928 100644 --- a/sources/plugins/link/dialogs/link.js +++ b/sources/plugins/link/dialogs/link.js | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. | 2 | * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | 3 | * For licensing, see LICENSE.md or http://ckeditor.com/license |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -7,7 +7,112 @@ | |||
7 | 7 | ||
8 | ( function() { | 8 | ( function() { |
9 | CKEDITOR.dialog.add( 'link', function( editor ) { | 9 | CKEDITOR.dialog.add( 'link', function( editor ) { |
10 | var plugin = CKEDITOR.plugins.link; | 10 | var plugin = CKEDITOR.plugins.link, |
11 | initialLinkText; | ||
12 | |||
13 | function createRangeForLink( editor, link ) { | ||
14 | var range = editor.createRange(); | ||
15 | |||
16 | range.setStartBefore( link ); | ||
17 | range.setEndAfter( link ); | ||
18 | |||
19 | return range; | ||
20 | } | ||
21 | |||
22 | function insertLinksIntoSelection( editor, data ) { | ||
23 | var attributes = plugin.getLinkAttributes( editor, data ), | ||
24 | ranges = editor.getSelection().getRanges(), | ||
25 | style = new CKEDITOR.style( { | ||
26 | element: 'a', | ||
27 | attributes: attributes.set | ||
28 | } ), | ||
29 | rangesToSelect = [], | ||
30 | range, | ||
31 | text, | ||
32 | nestedLinks, | ||
33 | i, | ||
34 | j; | ||
35 | |||
36 | style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why. | ||
37 | |||
38 | for ( i = 0; i < ranges.length; i++ ) { | ||
39 | range = ranges[ i ]; | ||
40 | |||
41 | // Use link URL as text with a collapsed cursor. | ||
42 | if ( range.collapsed ) { | ||
43 | // Short mailto link text view (http://dev.ckeditor.com/ticket/5736). | ||
44 | text = new CKEDITOR.dom.text( data.linkText || ( data.type == 'email' ? | ||
45 | data.email.address : attributes.set[ 'data-cke-saved-href' ] ), editor.document ); | ||
46 | range.insertNode( text ); | ||
47 | range.selectNodeContents( text ); | ||
48 | } else if ( initialLinkText !== data.linkText ) { | ||
49 | text = new CKEDITOR.dom.text( data.linkText, editor.document ); | ||
50 | |||
51 | // Shrink range to preserve block element. | ||
52 | range.shrink( CKEDITOR.SHRINK_TEXT ); | ||
53 | |||
54 | // Use extractHtmlFromRange to remove markup within the selection. Also this method is a little | ||
55 | // smarter than range#deleteContents as it plays better e.g. with table cells. | ||
56 | editor.editable().extractHtmlFromRange( range ); | ||
57 | |||
58 | range.insertNode( text ); | ||
59 | } | ||
60 | |||
61 | // Editable links nested within current range should be removed, so that the link is applied to whole selection. | ||
62 | nestedLinks = range._find( 'a' ); | ||
63 | |||
64 | for ( j = 0; j < nestedLinks.length; j++ ) { | ||
65 | nestedLinks[ j ].remove( true ); | ||
66 | } | ||
67 | |||
68 | |||
69 | // Apply style. | ||
70 | style.applyToRange( range, editor ); | ||
71 | |||
72 | rangesToSelect.push( range ); | ||
73 | } | ||
74 | |||
75 | editor.getSelection().selectRanges( rangesToSelect ); | ||
76 | } | ||
77 | |||
78 | function editLinksInSelection( editor, selectedElements, data ) { | ||
79 | var attributes = plugin.getLinkAttributes( editor, data ), | ||
80 | ranges = [], | ||
81 | element, | ||
82 | href, | ||
83 | textView, | ||
84 | newText, | ||
85 | i; | ||
86 | |||
87 | for ( i = 0; i < selectedElements.length; i++ ) { | ||
88 | // We're only editing an existing link, so just overwrite the attributes. | ||
89 | element = selectedElements[ i ]; | ||
90 | href = element.data( 'cke-saved-href' ); | ||
91 | textView = element.getHtml(); | ||
92 | |||
93 | element.setAttributes( attributes.set ); | ||
94 | element.removeAttributes( attributes.removed ); | ||
95 | |||
96 | |||
97 | if ( data.linkText && initialLinkText != data.linkText ) { | ||
98 | // Display text has been changed. | ||
99 | newText = data.linkText; | ||
100 | } else if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 ) { | ||
101 | // Update text view when user changes protocol (http://dev.ckeditor.com/ticket/4612). | ||
102 | // Short mailto link text view (http://dev.ckeditor.com/ticket/5736). | ||
103 | newText = data.type == 'email' ? data.email.address : attributes.set[ 'data-cke-saved-href' ]; | ||
104 | } | ||
105 | |||
106 | if ( newText ) { | ||
107 | element.setText( newText ); | ||
108 | } | ||
109 | |||
110 | ranges.push( createRangeForLink( editor, element ) ); | ||
111 | } | ||
112 | |||
113 | // We changed the content, so need to select it again. | ||
114 | editor.getSelection().selectRanges( ranges ); | ||
115 | } | ||
11 | 116 | ||
12 | // Handles the event when the "Target" selection box is changed. | 117 | // Handles the event when the "Target" selection box is changed. |
13 | var targetChanged = function() { | 118 | var targetChanged = function() { |
@@ -109,13 +214,30 @@ | |||
109 | 214 | ||
110 | return { | 215 | return { |
111 | title: linkLang.title, | 216 | title: linkLang.title, |
112 | minWidth: 350, | 217 | minWidth: ( CKEDITOR.skinName || editor.config.skin ) == 'moono-lisa' ? 450 : 350, |
113 | minHeight: 230, | 218 | minHeight: 240, |
114 | contents: [ { | 219 | contents: [ { |
115 | id: 'info', | 220 | id: 'info', |
116 | label: linkLang.info, | 221 | label: linkLang.info, |
117 | title: linkLang.info, | 222 | title: linkLang.info, |
118 | elements: [ { | 223 | elements: [ { |
224 | type: 'text', | ||
225 | id: 'linkDisplayText', | ||
226 | label: linkLang.displayText, | ||
227 | setup: function() { | ||
228 | this.enable(); | ||
229 | |||
230 | this.setValue( editor.getSelection().getSelectedText() ); | ||
231 | |||
232 | // Keep inner text so that it can be compared in commit function. By obtaining value from getData() | ||
233 | // we get value stripped from new line chars which is important when comparing the value later on. | ||
234 | initialLinkText = this.getValue(); | ||
235 | }, | ||
236 | commit: function( data ) { | ||
237 | data.linkText = this.isEnabled() ? this.getValue() : ''; | ||
238 | } | ||
239 | }, | ||
240 | { | ||
119 | id: 'linkType', | 241 | id: 'linkType', |
120 | type: 'select', | 242 | type: 'select', |
121 | label: linkLang.type, | 243 | label: linkLang.type, |
@@ -145,7 +267,7 @@ | |||
145 | label: commonLang.protocol, | 267 | label: commonLang.protocol, |
146 | 'default': 'http://', | 268 | 'default': 'http://', |
147 | items: [ | 269 | items: [ |
148 | // Force 'ltr' for protocol names in BIDI. (#5433) | 270 | // Force 'ltr' for protocol names in BIDI. (http://dev.ckeditor.com/ticket/5433) |
149 | [ 'http://\u200E', 'http://' ], | 271 | [ 'http://\u200E', 'http://' ], |
150 | [ 'https://\u200E', 'https://' ], | 272 | [ 'https://\u200E', 'https://' ], |
151 | [ 'ftp://\u200E', 'ftp://' ], | 273 | [ 'ftp://\u200E', 'ftp://' ], |
@@ -218,7 +340,7 @@ | |||
218 | }, | 340 | }, |
219 | commit: function( data ) { | 341 | commit: function( data ) { |
220 | // IE will not trigger the onChange event if the mouse has been used | 342 | // IE will not trigger the onChange event if the mouse has been used |
221 | // to carry all the operations #4724 | 343 | // to carry all the operations http://dev.ckeditor.com/ticket/4724 |
222 | this.onChange(); | 344 | this.onChange(); |
223 | 345 | ||
224 | if ( !data.url ) | 346 | if ( !data.url ) |
@@ -776,28 +898,55 @@ | |||
776 | setup: setupAdvParams, | 898 | setup: setupAdvParams, |
777 | commit: commitAdvParams | 899 | commit: commitAdvParams |
778 | } ] | 900 | } ] |
901 | }, | ||
902 | { | ||
903 | type: 'hbox', | ||
904 | widths: [ '45%', '55%' ], | ||
905 | children: [ { | ||
906 | type: 'checkbox', | ||
907 | id: 'download', | ||
908 | requiredContent: 'a[download]', | ||
909 | label: linkLang.download, | ||
910 | setup: function( data ) { | ||
911 | if ( data.download !== undefined ) | ||
912 | this.setValue( 'checked', 'checked' ); | ||
913 | }, | ||
914 | commit: function( data ) { | ||
915 | if ( this.getValue() ) { | ||
916 | data.download = this.getValue(); | ||
917 | } | ||
918 | } | ||
919 | } ] | ||
779 | } ] | 920 | } ] |
780 | } ] | 921 | } ] |
781 | } ], | 922 | } ], |
782 | onShow: function() { | 923 | onShow: function() { |
783 | var editor = this.getParentEditor(), | 924 | var editor = this.getParentEditor(), |
784 | selection = editor.getSelection(), | 925 | selection = editor.getSelection(), |
785 | element = null; | 926 | displayTextField = this.getContentElement( 'info', 'linkDisplayText' ).getElement().getParent().getParent(), |
927 | elements = plugin.getSelectedLink( editor, true ), | ||
928 | firstLink = elements[ 0 ] || null; | ||
786 | 929 | ||
787 | // Fill in all the relevant fields if there's already one link selected. | 930 | // Fill in all the relevant fields if there's already one link selected. |
788 | if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) { | 931 | if ( firstLink && firstLink.hasAttribute( 'href' ) ) { |
789 | // Don't change selection if some element is already selected. | 932 | // Don't change selection if some element is already selected. |
790 | // For example - don't destroy fake selection. | 933 | // For example - don't destroy fake selection. |
791 | if ( !selection.getSelectedElement() ) | 934 | if ( !selection.getSelectedElement() && !selection.isInTable() ) { |
792 | selection.selectElement( element ); | 935 | selection.selectElement( firstLink ); |
793 | } else { | 936 | } |
794 | element = null; | ||
795 | } | 937 | } |
796 | 938 | ||
797 | var data = plugin.parseLinkAttributes( editor, element ); | 939 | var data = plugin.parseLinkAttributes( editor, firstLink ); |
940 | |||
941 | // Here we'll decide whether or not we want to show Display Text field. | ||
942 | if ( elements.length <= 1 && plugin.showDisplayTextForElement( firstLink, editor ) ) { | ||
943 | displayTextField.show(); | ||
944 | } else { | ||
945 | displayTextField.hide(); | ||
946 | } | ||
798 | 947 | ||
799 | // Record down the selected element in the dialog. | 948 | // Record down the selected element in the dialog. |
800 | this._.selectedElement = element; | 949 | this._.selectedElements = elements; |
801 | 950 | ||
802 | this.setupContent( data ); | 951 | this.setupContent( data ); |
803 | }, | 952 | }, |
@@ -807,50 +956,12 @@ | |||
807 | // Collect data from fields. | 956 | // Collect data from fields. |
808 | this.commitContent( data ); | 957 | this.commitContent( data ); |
809 | 958 | ||
810 | var selection = editor.getSelection(), | 959 | if ( !this._.selectedElements.length ) { |
811 | attributes = plugin.getLinkAttributes( editor, data ); | 960 | insertLinksIntoSelection( editor, data ); |
812 | |||
813 | if ( !this._.selectedElement ) { | ||
814 | var range = selection.getRanges()[ 0 ]; | ||
815 | |||
816 | // Use link URL as text with a collapsed cursor. | ||
817 | if ( range.collapsed ) { | ||
818 | // Short mailto link text view (#5736). | ||
819 | var text = new CKEDITOR.dom.text( data.type == 'email' ? | ||
820 | data.email.address : attributes.set[ 'data-cke-saved-href' ], editor.document ); | ||
821 | range.insertNode( text ); | ||
822 | range.selectNodeContents( text ); | ||
823 | } | ||
824 | |||
825 | // Apply style. | ||
826 | var style = new CKEDITOR.style( { | ||
827 | element: 'a', | ||
828 | attributes: attributes.set | ||
829 | } ); | ||
830 | |||
831 | style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why. | ||
832 | style.applyToRange( range, editor ); | ||
833 | range.select(); | ||
834 | } else { | 961 | } else { |
835 | // We're only editing an existing link, so just overwrite the attributes. | 962 | editLinksInSelection( editor, this._.selectedElements, data ); |
836 | var element = this._.selectedElement, | ||
837 | href = element.data( 'cke-saved-href' ), | ||
838 | textView = element.getHtml(); | ||
839 | |||
840 | element.setAttributes( attributes.set ); | ||
841 | element.removeAttributes( attributes.removed ); | ||
842 | |||
843 | // Update text view when user changes protocol (#4612). | ||
844 | if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 ) { | ||
845 | // Short mailto link text view (#5736). | ||
846 | element.setHtml( data.type == 'email' ? | ||
847 | data.email.address : attributes.set[ 'data-cke-saved-href' ] ); | ||
848 | |||
849 | // We changed the content, so need to select it again. | ||
850 | selection.selectElement( element ); | ||
851 | } | ||
852 | 963 | ||
853 | delete this._.selectedElement; | 964 | delete this._.selectedElements; |
854 | } | 965 | } |
855 | }, | 966 | }, |
856 | onLoad: function() { | 967 | onLoad: function() { |