]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/wplink/plugin.js
WordPress 3.9.1
[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
20                 button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) );
21                 button.active( parent && parent.href );
22         }
23
24         editor.addButton( 'link', {
25                 icon: 'link',
26                 tooltip: 'Insert/edit link',
27                 shortcut: 'Alt+Shift+A',
28                 cmd: 'WP_Link',
29
30                 onPostRender: function() {
31                         linkButton = this;
32
33                         editor.on( 'nodechange', function( event ) {
34                                 setState( linkButton, event.element );
35                         });
36                 }
37         });
38
39         editor.addButton( 'unlink', {
40                 icon: 'unlink',
41                 tooltip: 'Remove link',
42                 cmd: 'unlink',
43
44                 onPostRender: function() {
45                         var unlinkButton = this;
46
47                         editor.on( 'nodechange', function( event ) {
48                                 setState( unlinkButton, event.element );
49                         });
50                 }
51         });
52
53         editor.addMenuItem( 'link', {
54                 icon: 'link',
55                 text: 'Insert link',
56                 shortcut: 'Alt+Shift+A',
57                 cmd: 'WP_Link',
58                 stateSelector: 'a[href]',
59                 context: 'insert',
60                 prependToContext: true
61         });
62 });