Debian Codegraph @

doc/jsdoc/variable.js.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: variable.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: variable.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 Generic class for keeping menu variables together with callback
47 * functions to hook into third party libraries.
48 *
49 * @author [email protected] (Volker Sorge)
50 */
51 /// &lt;reference path="variable_item.ts" />
52 var ContextMenu;
53 (function (ContextMenu) {
54 class Variable {
55 /**
56 * @constructor
57 * @template T
58 * @param {string} name The variable name.
59 * @param {T} value It's initial value.
60 * @param {function(T)} callback Function to call when value is changed.
61 */
62 constructor(name, value, callback) {
63 this.name = '';
64 this.items = [];
65 this.name = name;
66 this.value = value;
67 this.callback = callback;
68 }
69 /**
70 * @return {string} The name of the variable.
71 */
72 getName() {
73 return this.name;
74 }
75 ;
76 /**
77 * @return {T} The value of the variable.
78 */
79 getValue() {
80 return this.value;
81 }
82 ;
83 //// TODO: Add accessors for callback.
84 // Possibly put in some messaging service for menu item selected.
85 /**
86 * Sets new variable value. If different from old one it will execute the
87 * callback.
88 * @param {T} value New value of the variable.
89 */
90 setValue(value) {
91 if (value === this.value) {
92 return;
93 }
94 this.value = value;
95 try {
96 this.callback(value);
97 }
98 catch (e) {
99 ContextMenu.MenuUtil.error(e, 'Command of variable ' + this.name + ' failed.');
100 }
101 this.update();
102 }
103 /**
104 * Registers a new item that has this variable.
105 * @param {VariableItem} item The new variable item.
106 */
107 register(item) {
108 if (this.items.indexOf(item) === -1) {
109 this.items.push(item);
110 }
111 }
112 /**
113 * Unregisters an item for this variable.
114 * @param {VariableItem} item The old variable item.
115 */
116 unregister(item) {
117 let index = this.items.indexOf(item);
118 if (index !== -1) {
119 this.items.splice(index, 1);
120 }
121 }
122 /**
123 * Updates the items belonging to the variable.
124 */
125 update() {
126 this.items.forEach(x => x.update());
127 }
128 /**
129 * Registers a callback function with all items associated to this variable.
130 * @param {Function} func Callback that does not take any arguments.
131 * @final
132 */
133 registerCallback(func) {
134 this.items.forEach(x => x.registerCallback(func));
135 }
136 /**
137 * Removes a callback function from all items associated to this variable.
138 * @param {Function} func Callback that does not take any arguments.
139 * @final
140 */
141 unregisterCallback(func) {
142 this.items.forEach(x => x.unregisterCallback(func));
143 }
144 }
145 ContextMenu.Variable = Variable;
146 })(ContextMenu || (ContextMenu = {}));
147 </code></pre>
148 </article>
149 </section>
150
151
152
153
154 </div>
155
156 <nav>
157 <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>
158 </nav>
159
160 <br class="clear">
161
162 <footer>
163 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)
164 </footer>
165
166 <script> prettyPrint(); </script>
167 <script src="scripts/linenumber.js"> </script>
168 </body>
169 </html>