]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/wplink/plugin.js
WordPress 4.0-scripts
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wplink / plugin.js
1 /* global tinymce */
2 tinymce.PluginManager.add( 'wplink', function( editor ) {
3         var linkButton;
4         
5         // Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
6         editor.addCommand( 'WP_Link', function() {
7                 if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) {
8                         window.wpLink.open( editor.id );
9                 }
10         });
11
12         // WP default shortcut
13         editor.addShortcut( 'alt+shift+a', '', 'WP_Link' );
14         // The "de-facto standard" shortcut, see #27305
15         editor.addShortcut( 'ctrl+k', '', 'WP_Link' );
16
17         function setState( button, node ) {
18                 var parent = editor.dom.getParent( node, 'a' ),
19                         getView = editor.plugins.wpview ? editor.plugins.wpview.getView : function() { return false; };
20
21                 button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) || getView( node ) );
22                 button.active( parent && parent.href );
23         }
24
25         editor.addButton( 'link', {
26                 icon: 'link',
27                 tooltip: 'Insert/edit link',
28                 shortcut: 'Alt+Shift+A',
29                 cmd: 'WP_Link',
30
31                 onPostRender: function() {
32                         linkButton = this;
33
34                         editor.on( 'nodechange', function( event ) {
35                                 setState( linkButton, event.element );
36                         });
37                 }
38         });
39
40         editor.addButton( 'unlink', {
41                 icon: 'unlink',
42                 tooltip: 'Remove link',
43                 cmd: 'unlink',
44
45                 onPostRender: function() {
46                         var unlinkButton = this;
47
48                         editor.on( 'nodechange', function( event ) {
49                                 setState( unlinkButton, event.element );
50                         });
51                 }
52         });
53
54         editor.addMenuItem( 'link', {
55                 icon: 'link',
56                 text: 'Insert link',
57                 shortcut: 'Alt+Shift+A',
58                 cmd: 'WP_Link',
59                 stateSelector: 'a[href]',
60                 context: 'insert',
61                 prependToContext: true
62         });
63 });