annotate sat_templates/templates/default/static/common.js @ 174:46c58fb996dd

Added tag 0.7.0a3 for changeset 221cd8f0c9d5
author Goffi <goffi@goffi.org>
date Wed, 06 Feb 2019 09:06:28 +0100
parents cede18c118c9
children 0e69b5843c2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
83
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
1 var __session_storage_available;
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
2 var __local_storage_available;
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
3
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
4 function storageAvailable(type) {
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
5 /* check if session or local storage is available
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
6 *
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
7 * @param type(string): "session" or "storage"
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
8 * @return (boolean): true if requested storage is available
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
9 */
171
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
10 console.assert(type === 'session' || type === 'storage', "bad storage type (%s)", type);
83
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
11 const var_name = '__' + type + '_storage_available';
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
12 var available = window[var_name];
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
13 if (available === undefined) {
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
14 // test method from https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
15 var storage = window[type + 'Storage'];
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
16 try {
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
17 x = '__storage_test__';
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
18 storage.setItem(x, x);
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
19 storage.removeItem(x);
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
20 available = true;
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
21 }
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
22 catch(e) {
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
23 available = e instanceof DOMException && (
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
24 // everything except Firefox
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
25 e.code === 22 ||
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
26 // Firefox
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
27 e.code === 1014 ||
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
28 // test name field too, because code might not be present
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
29 // everything except Firefox
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
30 e.name === 'QuotaExceededError' ||
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
31 // Firefox
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
32 e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
33 // acknowledge QuotaExceededError only if there's something already stored
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
34 storage.length !== 0;
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
35 }
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
36
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
37 if (!available) {
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
38 console.warn("%s storage not available", type);
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
39 }
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
40 window[var_name] = available;
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
41 }
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
42
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
43 return available;
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
44 }
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
45
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
46 function toggle_clicked_class_tag(tag_name, class_name='state_clicked') {
15
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 for (let elt of document.getElementsByTagName(tag_name)) {
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 elt.classList.toggle(class_name);
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 }
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 }
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
52 function toggle_clicked_class_sel(selectors, class_name='state_clicked') {
67
3a9dae71aa6c static (js/css): method to toggle clicked class on all elements matching a selector
Goffi <goffi@goffi.org>
parents: 41
diff changeset
53 for (let elt of document.querySelectorAll(selectors)) {
3a9dae71aa6c static (js/css): method to toggle clicked class on all elements matching a selector
Goffi <goffi@goffi.org>
parents: 41
diff changeset
54 elt.classList.toggle(class_name);
3a9dae71aa6c static (js/css): method to toggle clicked class on all elements matching a selector
Goffi <goffi@goffi.org>
parents: 41
diff changeset
55 }
3a9dae71aa6c static (js/css): method to toggle clicked class on all elements matching a selector
Goffi <goffi@goffi.org>
parents: 41
diff changeset
56 }
3a9dae71aa6c static (js/css): method to toggle clicked class on all elements matching a selector
Goffi <goffi@goffi.org>
parents: 41
diff changeset
57
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
58 function set_clicked_class_id(trigger_elem_id, target_elem_id=null, class_name='state_clicked') {
15
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 if (target_elem_id === null) { target_elem_id = trigger_elem_id; }
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 document.getElementById(trigger_elem_id).addEventListener(
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "click",
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 function() {
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 document.getElementById(target_elem_id).classList.toggle(class_name);
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 }
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 );
c319291943be static: css.js (library for basic style manipulation) first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 }
29
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
67
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
68 function tab_select(tab_btn_elt, tab_page_id) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
69 for (let elt of document.getElementsByClassName("tab__btn")) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
70 if (elt === tab_btn_elt) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
71 elt.classList.add('state_clicked');
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
72 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
73 else {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
74 elt.classList.remove('state_clicked');
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
75 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
76 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
77 let tab_page_elt = document.getElementById(tab_page_id);
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
78 for (let elt of document.getElementsByClassName("tab__page")) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
79 if (elt === tab_page_elt) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
80 elt.classList.add('state_clicked');
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
81 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
82 else {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
83 elt.classList.remove('state_clicked');
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
84 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
85 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
86 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
87
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
88 function get_elt(arg) {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
89 if (typeof arg === 'string') {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
90 // we should have an id
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
91 return document.getElementById(arg);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
92 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
93 else {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
94 // we should have an element
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
95 return arg;
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
96 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
97 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
98
29
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
99 function clicked_cls(elt) {
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
100 /* toggle "state_clicked" class on each click, and remove "state_init" class if present */
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
101 // state_init
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
102 if (elt.classList.contains("state_init")) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
103 elt.classList.remove("state_init");
29
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
104 }
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
105
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
106 // clicked
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
107 elt.classList.toggle("state_clicked");
29
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
108 }
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
109
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
110 function clicked_mh_fix(arg, max_height) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
111 /* toggle state_clicked, and fix max-height on transitionend
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
112 *
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
113 * needed to workaround transition issue with max-height:none
83
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
114 * inspired from https://css-tricks.com/using-css-transitions-auto-dimensions,
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
115 * thanks to Brandon Smith
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
116 *
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
117 * @param arg(string, DOM element): element to toggle (id as string, or element itself)
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
118 * @param max_height(int): maximum height when collapsed (default to clientHeight)
83
caab77328b1c js (common): added a method to check if local or session storage is available
Goffi <goffi@goffi.org>
parents: 78
diff changeset
119 * */
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
120 elt = get_elt(arg);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
121
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
122 if (!elt.classList.contains("state_clicked")) {
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
123 /* expand */
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
124 let fix_expand = function(event) {
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
125 elt.removeEventListener("transitionend", fix_expand, false);
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
126 if (elt.classList.contains("state_clicked")) {
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
127 /* if event is clicked quicker than transition time,
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
128 * this callback can be called on reduce */
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
129 elt.style.maxHeight = "none";
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
130 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
131 };
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
132
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
133 if (!elt.hasAttribute('_max_height_init')) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
134 elt.setAttribute('_max_height_init', max_height!==undefined?max_height:elt.clientHeight);
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
135 }
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
136 elt.addEventListener("transitionend", fix_expand, false);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
137 clicked_cls(elt);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
138 elt.style.maxHeight = elt.scrollHeight + 'px';
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
139
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
140 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
141 else {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
142 /* reduce */
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
143 let transition_save = elt.style.transition;
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
144 elt.style.transition = '';
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
145 requestAnimationFrame(function() {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
146 elt.style.maxHeight = elt.scrollHeight + 'px';
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
147 elt.style.transition = transition_save;
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
148
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
149 requestAnimationFrame(function() {
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
150 elt.style.maxHeight = elt.getAttribute('_max_height_init') + 'px';
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
151 });
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
152 });
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
153
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
154 clicked_cls(elt);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
155 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
156 }
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
157
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
158 function createElement(html) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
159 /* create a DOM element from raw HTML
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
160 *
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
161 * @param html(string): raw HTML to parse
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
162 * @return: DOM element
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
163 */
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
164
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
165 let template = document.createElement('template');
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
166 template.innerHTML = html.trim();
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
167 new_element = template.content.firstChild;
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
168 return new_element;
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
169 }
171
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
170
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
171
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
172 function fitHeightToContent(elt) {
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
173 /* adapt height to content, specially useful for iframe */
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
174 elt.style.height = elt.contentWindow.document.body.scrollHeight + 80 + 'px';
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
175 }