~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/editor/tinymce/tiny_mce/3.5.10/plugins/contextmenu/editor_plugin_src.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * editor_plugin_src.js
 
3
 *
 
4
 * Copyright 2009, Moxiecode Systems AB
 
5
 * Released under LGPL License.
 
6
 *
 
7
 * License: http://tinymce.moxiecode.com/license
 
8
 * Contributing: http://tinymce.moxiecode.com/contributing
 
9
 */
 
10
 
 
11
(function() {
 
12
        var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
 
13
 
 
14
        /**
 
15
         * This plugin a context menu to TinyMCE editor instances.
 
16
         *
 
17
         * @class tinymce.plugins.ContextMenu
 
18
         */
 
19
        tinymce.create('tinymce.plugins.ContextMenu', {
 
20
                /**
 
21
                 * Initializes the plugin, this will be executed after the plugin has been created.
 
22
                 * This call is done before the editor instance has finished it's initialization so use the onInit event
 
23
                 * of the editor instance to intercept that event.
 
24
                 *
 
25
                 * @method init
 
26
                 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
 
27
                 * @param {string} url Absolute URL to where the plugin is located.
 
28
                 */
 
29
                init : function(ed) {
 
30
                        var t = this, showMenu, contextmenuNeverUseNative, realCtrlKey, hideMenu;
 
31
 
 
32
                        t.editor = ed;
 
33
 
 
34
                        contextmenuNeverUseNative = ed.settings.contextmenu_never_use_native;
 
35
 
 
36
                        /**
 
37
                         * This event gets fired when the context menu is shown.
 
38
                         *
 
39
                         * @event onContextMenu
 
40
                         * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.
 
41
                         * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
 
42
                         */
 
43
                        t.onContextMenu = new tinymce.util.Dispatcher(this);
 
44
 
 
45
                        hideMenu = function(e) {
 
46
                                hide(ed, e);
 
47
                        };
 
48
 
 
49
                        showMenu = ed.onContextMenu.add(function(ed, e) {
 
50
                                // Block TinyMCE menu on ctrlKey and work around Safari issue
 
51
                                if ((realCtrlKey !== 0 ? realCtrlKey : e.ctrlKey) && !contextmenuNeverUseNative)
 
52
                                        return;
 
53
 
 
54
                                Event.cancel(e);
 
55
 
 
56
                                // Select the image if it's clicked. WebKit would other wise expand the selection
 
57
                                if (e.target.nodeName == 'IMG')
 
58
                                        ed.selection.select(e.target);
 
59
 
 
60
                                t._getMenu(ed).showMenu(e.clientX || e.pageX, e.clientY || e.pageY);
 
61
                                Event.add(ed.getDoc(), 'click', hideMenu);
 
62
 
 
63
                                ed.nodeChanged();
 
64
                        });
 
65
                        
 
66
                        ed.onRemove.add(function() {
 
67
                                if (t._menu)
 
68
                                        t._menu.removeAll();
 
69
                        });
 
70
 
 
71
                        function hide(ed, e) {
 
72
                                realCtrlKey = 0;
 
73
 
 
74
                                // Since the contextmenu event moves
 
75
                                // the selection we need to store it away
 
76
                                if (e && e.button == 2) {
 
77
                                        realCtrlKey = e.ctrlKey;
 
78
                                        return;
 
79
                                }
 
80
 
 
81
                                if (t._menu) {
 
82
                                        t._menu.removeAll();
 
83
                                         t._menu.destroy();
 
84
                                        Event.remove(ed.getDoc(), 'click', hideMenu);
 
85
                                        t._menu = null;
 
86
                                }
 
87
                        };
 
88
 
 
89
                        ed.onMouseDown.add(hide);
 
90
                        ed.onKeyDown.add(hide);
 
91
                        ed.onKeyDown.add(function(ed, e) {
 
92
                                if (e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode === 121) {
 
93
                                        Event.cancel(e);
 
94
                                        showMenu(ed, e);
 
95
                                }
 
96
                        });
 
97
                },
 
98
 
 
99
                /**
 
100
                 * Returns information about the plugin as a name/value array.
 
101
                 * The current keys are longname, author, authorurl, infourl and version.
 
102
                 *
 
103
                 * @method getInfo
 
104
                 * @return {Object} Name/value array containing information about the plugin.
 
105
                 */
 
106
                getInfo : function() {
 
107
                        return {
 
108
                                longname : 'Contextmenu',
 
109
                                author : 'Moxiecode Systems AB',
 
110
                                authorurl : 'http://tinymce.moxiecode.com',
 
111
                                infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
 
112
                                version : tinymce.majorVersion + "." + tinymce.minorVersion
 
113
                        };
 
114
                },
 
115
 
 
116
                _getMenu : function(ed) {
 
117
                        var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p;
 
118
 
 
119
                        if (m) {
 
120
                                m.removeAll();
 
121
                                m.destroy();
 
122
                        }
 
123
 
 
124
                        p = DOM.getPos(ed.getContentAreaContainer());
 
125
 
 
126
                        m = ed.controlManager.createDropMenu('contextmenu', {
 
127
                                offset_x : p.x + ed.getParam('contextmenu_offset_x', 0),
 
128
                                offset_y : p.y + ed.getParam('contextmenu_offset_y', 0),
 
129
                                constrain : 1,
 
130
                                keyboard_focus: true
 
131
                        });
 
132
 
 
133
                        t._menu = m;
 
134
 
 
135
                        m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
 
136
                        m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
 
137
                        m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
 
138
 
 
139
                        if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
 
140
                                m.addSeparator();
 
141
                                m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
 
142
                                m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
 
143
                        }
 
144
 
 
145
                        m.addSeparator();
 
146
                        m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
 
147
 
 
148
                        m.addSeparator();
 
149
                        am = m.addMenu({title : 'contextmenu.align'});
 
150
                        am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
 
151
                        am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
 
152
                        am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
 
153
                        am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
 
154
 
 
155
                        t.onContextMenu.dispatch(t, m, el, col);
 
156
 
 
157
                        return m;
 
158
                }
 
159
        });
 
160
 
 
161
        // Register plugin
 
162
        tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
 
163
})();