Browse code

tinyMCE '2' is now 2.1.2 - Seems tinyMCE '2' was actually 3.0.9 (my fault for not checking), so '2' is now 2.1.2, and '3' is now 3.4.8... eFiction 3.4.3 used tinyMCE 2.1.0, and 3.5 upgraded that to 3.0.9.

Clarissa Walker authored on 2026/07/28 07:20:33
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,185 @@
1
+/**
2
+ * $Id$
3
+ *
4
+ * @author Moxiecode
5
+ * @copyright Copyright � 2004-2007, Moxiecode Systems AB, All rights reserved.
6
+ */
7
+
8
+/**
9
+ * Constructor for the menu layer class.
10
+ *
11
+ * @constructor
12
+ * @base TinyMCE_Layer
13
+ * @member TinyMCE_Menu
14
+ */
15
+function TinyMCE_Menu() {
16
+	var id;
17
+
18
+	if (typeof(tinyMCE.menuCounter) == "undefined")
19
+		tinyMCE.menuCounter = 0;
20
+
21
+	id = "mc_menu_" + tinyMCE.menuCounter++;
22
+
23
+	TinyMCE_Layer.call(this, id, true);
24
+
25
+	this.id = id;
26
+	this.items = [];
27
+	this.needsUpdate = true;
28
+};
29
+
30
+/**#@+
31
+ * @member TinyMCE_Menu
32
+ */
33
+TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, {
34
+	/**#@+
35
+	 * @method
36
+	 */
37
+
38
+	/**
39
+	 * Initializes the Menu with settings. This will also create the menu
40
+	 * as a DIV element if it doesn't exists in the DOM.
41
+	 *
42
+	 * @param {Array} s Name/Value array with settings.
43
+	 */
44
+	init : function(s) {
45
+		var n;
46
+
47
+		// Default params
48
+		this.settings = {
49
+			separator_class : 'mceMenuSeparator',
50
+			title_class : 'mceMenuTitle',
51
+			disabled_class : 'mceMenuDisabled',
52
+			menu_class : 'mceMenu',
53
+			drop_menu : true
54
+		};
55
+
56
+		for (n in s)
57
+			this.settings[n] = s[n];
58
+
59
+		this.create('div', this.settings.menu_class);
60
+	},
61
+
62
+	/**
63
+	 * Clears the menu.
64
+	 */
65
+	clear : function() {
66
+		this.items = [];
67
+	},
68
+
69
+	/**
70
+	 * Adds a menu title, this is a static item that can't be clicked.
71
+	 *
72
+	 * @param {string} t Text to add to title.
73
+	 */
74
+	addTitle : function(t) {
75
+		this.add({type : 'title', text : t});
76
+	},
77
+
78
+	/**
79
+	 * Adds a disabled menu item, this is a static item that can't be clicked.
80
+	 *
81
+	 * @param {string} t Text to add to title.
82
+	 */
83
+	addDisabled : function(t) {
84
+		this.add({type : 'disabled', text : t});
85
+	},
86
+
87
+	/**
88
+	 * Adds a menu separator line.
89
+	 */
90
+	addSeparator : function() {
91
+		this.add({type : 'separator'});
92
+	},
93
+
94
+	/**
95
+	 * Adds a menu item.
96
+	 *
97
+	 * @param {string} t Menu item text.
98
+	 * @param {string} js JS string to evaluate on click.
99
+	 */
100
+	addItem : function(t, js) {
101
+		this.add({text : t, js : js});
102
+	},
103
+
104
+	/**
105
+	 * Adds a menu item object.
106
+	 *
107
+	 * @param {Object} mi Menu item object to add.
108
+	 */
109
+	add : function(mi) {
110
+		this.items[this.items.length] = mi;
111
+		this.needsUpdate = true;
112
+	},
113
+
114
+	/**
115
+	 * Update the menu with new HTML contents.
116
+	 */
117
+	update : function() {
118
+		var e = this.getElement(), h = '', i, t, m = this.items, s = this.settings;
119
+
120
+		if (this.settings.drop_menu)
121
+			h += '<span class="mceMenuLine"></span>';
122
+
123
+		h += '<table border="0" cellpadding="0" cellspacing="0">';
124
+
125
+		for (i=0; i<m.length; i++) {
126
+			t = tinyMCE.xmlEncode(m[i].text);
127
+			c = m[i].class_name ? ' class="' + m[i].class_name + '"' : '';
128
+
129
+			switch (m[i].type) {
130
+				case 'separator':
131
+					h += '<tr class="' + s.separator_class + '"><td>';
132
+					break;
133
+
134
+				case 'title':
135
+					h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>';
136
+					break;
137
+
138
+				case 'disabled':
139
+					h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>';
140
+					break;
141
+
142
+				default:
143
+					h += '<tr><td><a href="' + tinyMCE.xmlEncode(m[i].js) + '" onmousedown="' + tinyMCE.xmlEncode(m[i].js) + ';return tinyMCE.cancelEvent(event);" onclick="return tinyMCE.cancelEvent(event);" onmouseup="return tinyMCE.cancelEvent(event);"><span' + c +'>' + t + '</span></a>';
144
+			}
145
+
146
+			h += '</td></tr>';
147
+		}
148
+
149
+		h += '</table>';
150
+
151
+		e.innerHTML = h;
152
+
153
+		this.needsUpdate = false;
154
+		this.updateBlocker();
155
+	},
156
+
157
+	/**
158
+	 * Displays the menu. This function will automaticly hide any previously visible menus.
159
+	 */
160
+	show : function() {
161
+		var nl, i;
162
+
163
+		if (tinyMCE.lastMenu == this)
164
+			return;
165
+
166
+		if (this.needsUpdate)
167
+			this.update();
168
+
169
+		if (tinyMCE.lastMenu && tinyMCE.lastMenu != this)
170
+			tinyMCE.lastMenu.hide();
171
+
172
+		TinyMCE_Layer.prototype.show.call(this);
173
+
174
+		if (!tinyMCE.isOpera) {
175
+			// Accessibility stuff
176
+/*			nl = this.getElement().getElementsByTagName("a");
177
+			if (nl.length > 0)
178
+				nl[0].focus();*/
179
+		}
180
+
181
+		tinyMCE.lastMenu = this;
182
+	}
183
+
184
+	/**#@-*/
185
+});