| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>JSDoc: Source: popup.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: popup.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 Class of popup windows. Each object can actually spawn multiple |
| 47 |
* windows. |
| 48 |
* |
| 49 |
* @author [email protected] (Volker Sorge) |
| 50 |
*/ |
| 51 |
/// <reference path="context_menu.ts" /> |
| 52 |
/// <reference path="menu_util.ts" /> |
| 53 |
var ContextMenu; |
| 54 |
(function (ContextMenu) { |
| 55 |
class Popup extends ContextMenu.AbstractPostable { |
| 56 |
/** |
| 57 |
* @constructor |
| 58 |
* @extends {AbstractPostable} |
| 59 |
* @param {string} title The title of the popup window. |
| 60 |
* @param {Function} content Function generating the content. |
| 61 |
*/ |
| 62 |
constructor(title, content) { |
| 63 |
super(); |
| 64 |
this.title = ''; |
| 65 |
/** |
| 66 |
* The last opened window. |
| 67 |
* @type {Window} |
| 68 |
*/ |
| 69 |
this.window = null; |
| 70 |
/** |
| 71 |
* The list of all windows opened by this object. |
| 72 |
* @type {Array.<Window>} |
| 73 |
*/ |
| 74 |
this.windowList = []; |
| 75 |
this.mobileFlag = false; |
| 76 |
this.active = null; |
| 77 |
this.title = title; |
| 78 |
this.content = content || function () { return ''; }; |
| 79 |
} |
| 80 |
/** |
| 81 |
* Attaches the widget to a context menu. |
| 82 |
* @param {ContextMenu} menu The parent menu. |
| 83 |
*/ |
| 84 |
attachMenu(menu) { |
| 85 |
this.menu = menu; |
| 86 |
} |
| 87 |
/** |
| 88 |
* @override |
| 89 |
*/ |
| 90 |
post() { |
| 91 |
this.display(); |
| 92 |
} |
| 93 |
/** |
| 94 |
* @override |
| 95 |
*/ |
| 96 |
display() { |
| 97 |
this.active = this.menu.getStore().getActive(); |
| 98 |
let settings = []; |
| 99 |
for (let setting in Popup.popupSettings) { |
| 100 |
settings.push(setting + '=' + Popup.popupSettings[setting]); |
| 101 |
} |
| 102 |
this.window = window.open('', '_blank', settings.join(',')); |
| 103 |
this.windowList.push(this.window); |
| 104 |
let doc = this.window.document; |
| 105 |
if (this.mobileFlag) { |
| 106 |
doc.open(); |
| 107 |
doc.write('<html><head><meta name="viewport" ' + |
| 108 |
'content="width=device-width, initial-scale=1.0" /><title>' + |
| 109 |
this.title + |
| 110 |
'</title></head><body style="font-size:85%">'); |
| 111 |
doc.write('<pre>' + this.generateContent() + '</pre>'); |
| 112 |
doc.write('<hr><input type="button" value="' + |
| 113 |
//// TODO: Localise |
| 114 |
'Close' + '" onclick="window.close()" />'); |
| 115 |
doc.write('</body></html>'); |
| 116 |
doc.close(); |
| 117 |
} |
| 118 |
else { |
| 119 |
doc.open(); |
| 120 |
doc.write('<html><head><title>' + this.title + |
| 121 |
'</title></head><body style="font-size:85%">'); |
| 122 |
doc.write('<table><tr><td><pre>' + this.generateContent() + |
| 123 |
'</pre></td></tr></table>'); |
| 124 |
doc.write('</body></html>'); |
| 125 |
doc.close(); |
| 126 |
setTimeout(this.resize.bind(this), 50); |
| 127 |
} |
| 128 |
} |
| 129 |
/** |
| 130 |
* @override |
| 131 |
*/ |
| 132 |
unpost() { |
| 133 |
this.windowList.forEach(x => x.close()); |
| 134 |
this.window = null; |
| 135 |
} |
| 136 |
/** |
| 137 |
* Generates the content of the window. |
| 138 |
* @return {string} The generated content. |
| 139 |
*/ |
| 140 |
generateContent() { |
| 141 |
return this.content(this.active); |
| 142 |
} |
| 143 |
/** |
| 144 |
* Resizes the window so it fits snuggly around the content. |
| 145 |
* @private |
| 146 |
*/ |
| 147 |
resize() { |
| 148 |
let table = this.window.document.body.firstChild; |
| 149 |
let H = (this.window.outerHeight - this.window.innerHeight) || 30; |
| 150 |
let W = (this.window.outerWidth - this.window.innerWidth) || 30; |
| 151 |
W = Math.max(140, Math.min(Math.floor(.5 * screen.width), table.offsetWidth + W + 25)); |
| 152 |
H = Math.max(40, Math.min(Math.floor(.5 * screen.height), table.offsetHeight + H + 25)); |
| 153 |
this.window.resizeTo(W, H); |
| 154 |
let bb = this.active.getBoundingClientRect(); |
| 155 |
if (bb) { |
| 156 |
let x = Math.max(0, Math.min(bb.right - Math.floor(W / 2), screen.width - W - 20)); |
| 157 |
let y = Math.max(0, Math.min(bb.bottom - Math.floor(H / 2), screen.height - H - 20)); |
| 158 |
this.window.moveTo(x, y); |
| 159 |
} |
| 160 |
this.active = null; |
| 161 |
} |
| 162 |
} |
| 163 |
Popup.popupSettings = { |
| 164 |
status: 'no', |
| 165 |
toolbar: 'no', |
| 166 |
locationbar: 'no', |
| 167 |
menubar: 'no', |
| 168 |
directories: 'no', |
| 169 |
personalbar: 'no', |
| 170 |
resizable: 'yes', |
| 171 |
scrollbars: 'yes', |
| 172 |
width: 400, |
| 173 |
height: 300, |
| 174 |
left: Math.round((screen.width - 400) / 2), |
| 175 |
top: Math.round((screen.height - 300) / 3) |
| 176 |
}; |
| 177 |
ContextMenu.Popup = Popup; |
| 178 |
})(ContextMenu || (ContextMenu = {})); |
| 179 |
</code></pre> |
| 180 |
</article> |
| 181 |
</section> |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
</div> |
| 187 |
|
| 188 |
<nav> |
| 189 |
<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> |
| 190 |
</nav> |
| 191 |
|
| 192 |
<br class="clear"> |
| 193 |
|
| 194 |
<footer> |
| 195 |
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) |
| 196 |
</footer> |
| 197 |
|
| 198 |
<script> prettyPrint(); </script> |
| 199 |
<script src="scripts/linenumber.js"> </script> |
| 200 |
</body> |
| 201 |
</html> |