Debian Codegraph @

doc/jsdoc/abstract_menu.js.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: abstract_menu.js</title>
6
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13 <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14 </head>
15
16 <body>
17
18 <div id="main">
19
20 <h1 class="page-title">Source: abstract_menu.js</h1>
21
22
23
24
25
26
27 <section>
28 <article>
29 <pre class="prettyprint source linenums"><code>/*************************************************************
30 *
31 * Copyright (c) 2015-2016 The MathJax Consortium
32 *
33 * Licensed under the Apache License, Version 2.0 (the "License");
34 * you may not use this file except in compliance with the License.
35 * You may obtain a copy of the License at
36 *
37 * http://www.apache.org/licenses/LICENSE-2.0
38 *
39 * Unless required by applicable law or agreed to in writing, software
40 * distributed under the License is distributed on an "AS IS" BASIS,
41 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 * See the License for the specific language governing permissions and
43 * limitations under the License.
44 */
45 /**
46 * @fileoverview Abstract class of context menus.
47 *
48 * @author [email protected] (Volker Sorge)
49 */
50 /// &lt;reference path="abstract_postable.ts" />
51 /// &lt;reference path="menu.ts" />
52 /// &lt;reference path="menu_element.ts" />
53 /// &lt;reference path="item.ts" />
54 /// &lt;reference path="variable_pool.ts" />
55 var ContextMenu;
56 (function (ContextMenu) {
57 class AbstractMenu extends ContextMenu.AbstractPostable {
58 /**
59 * @constructor
60 * @extends {AbstractPostable}
61 * @implements {Menu}
62 */
63 constructor(...args) {
64 super(...args);
65 /**
66 * @override
67 */
68 this.className = ContextMenu.HtmlClasses['CONTEXTMENU'];
69 /**
70 * @override
71 */
72 this.role = 'menu';
73 this.items = [];
74 }
75 /**
76 * @override
77 */
78 getItems() {
79 return this.items;
80 }
81 ;
82 /**
83 * @override
84 */
85 getPool() {
86 return this.variablePool;
87 }
88 ;
89 /**
90 * @override
91 */
92 getFocused() {
93 return this.focused;
94 }
95 /**
96 * @override
97 */
98 setFocused(item) {
99 if (this.focused === item) {
100 return;
101 }
102 if (!this.focused) {
103 this.unfocus();
104 }
105 // Order here is important for test in submenu.unfocus.
106 let old = this.focused;
107 this.focused = item;
108 if (old) {
109 old.unfocus();
110 }
111 }
112 /**
113 * @override
114 */
115 up(event) {
116 let items = this.getItems().filter(x => (x instanceof ContextMenu.AbstractItem) &amp;&amp; (!x.isHidden()));
117 if (items.length === 0) {
118 return;
119 }
120 if (!this.focused) {
121 items[items.length - 1].focus();
122 return;
123 }
124 let index = items.indexOf(this.focused);
125 if (index === -1) {
126 return;
127 }
128 index = index ? --index : items.length - 1;
129 items[index].focus();
130 }
131 /**
132 * @override
133 */
134 down(event) {
135 let items = this.getItems().filter(x => (x instanceof ContextMenu.AbstractItem) &amp;&amp; (!x.isHidden()));
136 if (items.length === 0) {
137 return;
138 }
139 if (!this.focused) {
140 items[0].focus();
141 return;
142 }
143 let index = items.indexOf(this.focused);
144 if (index === -1) {
145 return;
146 }
147 index++;
148 index = (index === items.length) ? 0 : index;
149 items[index].focus();
150 }
151 /**
152 * @override
153 */
154 generateHtml() {
155 super.generateHtml();
156 this.generateMenu();
157 }
158 /**
159 * @override
160 */
161 generateMenu() {
162 let html = this.getHtml();
163 html.classList.add(ContextMenu.HtmlClasses['MENU']);
164 for (let i = 0, item; item = this.items[i]; i++) {
165 if (!item.isHidden()) {
166 html.appendChild(item.getHtml());
167 continue;
168 }
169 let itemHtml = item.getHtml();
170 if (itemHtml.parentNode) {
171 itemHtml.parentNode.removeChild(itemHtml);
172 }
173 }
174 }
175 /**
176 * @override
177 */
178 unpostSubmenus() {
179 let submenus = this.items.filter(x => x instanceof ContextMenu.Submenu);
180 for (let i = 0, submenu; submenu = submenus[i]; i++) {
181 submenu.getSubmenu().unpost();
182 if (submenu !== this.getFocused()) {
183 submenu.unfocus();
184 }
185 }
186 }
187 /**
188 * @override
189 */
190 unpost() {
191 super.unpost();
192 this.unpostSubmenus();
193 this.setFocused(null);
194 }
195 /**
196 * @override
197 */
198 find(id) {
199 for (let item of this.getItems()) {
200 if (item.getType() === 'rule') {
201 continue;
202 }
203 if (item.getId() === id) {
204 return item;
205 }
206 if (item.getType() === 'submenu') {
207 let result = item.getSubmenu().find(id);
208 if (result) {
209 return result;
210 }
211 }
212 }
213 return null;
214 }
215 /**
216 * Parses items in JSON formats and attaches them to the menu.
217 * @param {Array.&lt;JSON>} items List of JSON menu items.
218 */
219 parseItems(items) {
220 let hidden = items.map(x => [this.parseItem.bind(this)(x), x.hidden]);
221 hidden.forEach(x => x[1] &amp;&amp; x[0].hide());
222 }
223 /**
224 * Parses items in JSON formats and attaches them to the menu.
225 * @param {Array.&lt;JSON>} items List of JSON menu items.
226 * @return {}
227 */
228 parseItem(item) {
229 const parseMapping_ = {
230 'checkbox': ContextMenu.Checkbox.parse,
231 'command': ContextMenu.Command.parse,
232 'label': ContextMenu.Label.parse,
233 'radio': ContextMenu.Radio.parse,
234 'rule': ContextMenu.Rule.parse,
235 'submenu': ContextMenu.Submenu.parse
236 };
237 let func = parseMapping_[item['type']];
238 if (func) {
239 let menuItem = func(item, this);
240 this.getItems().push(menuItem);
241 if (item['disabled']) {
242 menuItem.disable();
243 }
244 return menuItem;
245 }
246 }
247 }
248 ContextMenu.AbstractMenu = AbstractMenu;
249 })(ContextMenu || (ContextMenu = {}));
250 </code></pre>
251 </article>
252 </section>
253
254
255
256
257 </div>
258
259 <nav>
260 <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AbstractEntry.html">AbstractEntry</a></li><li><a href="AbstractItem.html">AbstractItem</a></li><li><a href="AbstractMenu.html">AbstractMenu</a></li><li><a href="AbstractNavigatable.html">AbstractNavigatable</a></li><li><a href="AbstractPostable.html">AbstractPostable</a></li><li><a href="Checkbox.html">Checkbox</a></li><li><a href="CloseButton.html">CloseButton</a></li><li><a href="Command.html">Command</a></li><li><a href="ContextMenu.html">ContextMenu</a></li><li><a href="Info.html">Info</a></li><li><a href="Label.html">Label</a></li><li><a href="MenuElement.html">MenuElement</a></li><li><a href="MenuStore.html">MenuStore</a></li><li><a href="Popup.html">Popup</a></li><li><a href="Radio.html">Radio</a></li><li><a href="Rule.html">Rule</a></li><li><a href="SubMenu.html">SubMenu</a></li><li><a href="Submenu_.html">Submenu</a></li><li><a href="Variable.html">Variable</a></li><li><a href="VariablePool.html">VariablePool</a></li></ul><h3>Namespaces</h3><ul><li><a href="CssStyles.html">CssStyles</a></li><li><a href="MenuUtil.html">MenuUtil</a></li></ul><h3>Interfaces</h3><ul><li><a href="Element.html">Element</a></li><li><a href="Entry.html">Entry</a></li><li><a href="Item.html">Item</a></li><li><a href="KeyNavigatable.html">KeyNavigatable</a></li><li><a href="Menu.html">Menu</a></li><li><a href="MouseNavigatable.html">MouseNavigatable</a></li><li><a href="Postable.html">Postable</a></li><li><a href="TouchNavigatable.html">TouchNavigatable</a></li><li><a href="VariableItem.html">VariableItem</a></li></ul><h3>Global</h3><ul><li><a href="global.html#HtmlAttrs">HtmlAttrs</a></li><li><a href="global.html#HtmlClasses">HtmlClasses</a></li><li><a href="global.html#KEY">KEY</a></li><li><a href="global.html#MOUSE">MOUSE</a></li><li><a href="global.html#TOUCH">TOUCH</a></li></ul>
261 </nav>
262
263 <br class="clear">
264
265 <footer>
266 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Wed Aug 17 2016 12:38:38 GMT+0100 (BST)
267 </footer>
268
269 <script> prettyPrint(); </script>
270 <script src="scripts/linenumber.js"> </script>
271 </body>
272 </html>