]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/wplink/plugin.js
WordPress 4.2
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wplink / plugin.js
1 /* global tinymce */
2 tinymce.PluginManager.add( 'wplink', function( editor ) {
3         editor.addCommand( 'WP_Link', function() {
4                 window.wpLink && window.wpLink.open( editor.id );
5         });
6
7         // WP default shortcut
8         editor.addShortcut( 'Alt+Shift+A', '', 'WP_Link' );
9         // The "de-facto standard" shortcut, see #27305
10         editor.addShortcut( 'Meta+K', '', 'WP_Link' );
11
12         editor.addButton( 'link', {
13                 icon: 'link',
14                 tooltip: 'Insert/edit link',
15                 cmd: 'WP_Link',
16                 stateSelector: 'a[href]'
17         });
18
19         editor.addButton( 'unlink', {
20                 icon: 'unlink',
21                 tooltip: 'Remove link',
22                 cmd: 'unlink'
23         });
24
25         editor.addMenuItem( 'link', {
26                 icon: 'link',
27                 text: 'Insert/edit link',
28                 cmd: 'WP_Link',
29                 stateSelector: 'a[href]',
30                 context: 'insert',
31                 prependToContext: true
32         });
33
34         editor.on( 'pastepreprocess', function( event ) {
35                 var pastedStr = event.content;
36
37                 if ( ! editor.selection.isCollapsed() ) {
38                         pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
39                         pastedStr = tinymce.trim( pastedStr );
40
41                         if ( /^(?:https?:)?\/\/\S+$/i.test( pastedStr ) ) {
42                                 editor.execCommand( 'mceInsertLink', false, {
43                                         href: editor.dom.decode( pastedStr )
44                                 } );
45
46                                 event.preventDefault();
47                         }
48                 }
49         } );
50 });