comparison sat_templates/templates/default/static/common.js @ 171:cede18c118c9

js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
author Goffi <goffi@goffi.org>
date Fri, 25 Jan 2019 11:28:41 +0100
parents 178f55b825b7
children 0e69b5843c2f
comparison
equal deleted inserted replaced
170:6c251da9a4f3 171:cede18c118c9
5 /* check if session or local storage is available 5 /* check if session or local storage is available
6 * 6 *
7 * @param type(string): "session" or "storage" 7 * @param type(string): "session" or "storage"
8 * @return (boolean): true if requested storage is available 8 * @return (boolean): true if requested storage is available
9 */ 9 */
10 console.assert(type == 'session' || type == 'storage', "bad storage type (%s)", type); 10 console.assert(type === 'session' || type === 'storage', "bad storage type (%s)", type);
11 const var_name = '__' + type + '_storage_available'; 11 const var_name = '__' + type + '_storage_available';
12 var available = window[var_name]; 12 var available = window[var_name];
13 if (available === undefined) { 13 if (available === undefined) {
14 // test method from https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API 14 // test method from https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
15 var storage = window[type + 'Storage']; 15 var storage = window[type + 'Storage'];
165 let template = document.createElement('template'); 165 let template = document.createElement('template');
166 template.innerHTML = html.trim(); 166 template.innerHTML = html.trim();
167 new_element = template.content.firstChild; 167 new_element = template.content.firstChild;
168 return new_element; 168 return new_element;
169 } 169 }
170
171
172 function fitHeightToContent(elt) {
173 /* adapt height to content, specially useful for iframe */
174 elt.style.height = elt.contentWindow.document.body.scrollHeight + 80 + 'px';
175 }