annotate sat_templates/templates/default/static/common.js @ 260:caadb06854a0

bulma (invitation): invitation manager first draft
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 17:01:31 +0200
parents 61f3efd69fc3
children
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
230
0e69b5843c2f theme: bulma theme first draft:
Goffi <goffi@goffi.org>
parents: 171
diff changeset
68 function tab_select(tab_btn_elt, tab_page_id, btn_clicked_cls='state_clicked', tab_clicked_cls='state_clicked') {
0e69b5843c2f theme: bulma theme first draft:
Goffi <goffi@goffi.org>
parents: 171
diff changeset
69
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
70 for (let elt of document.getElementsByClassName("tab__btn")) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
71 if (elt === tab_btn_elt) {
230
0e69b5843c2f theme: bulma theme first draft:
Goffi <goffi@goffi.org>
parents: 171
diff changeset
72 elt.classList.add(btn_clicked_cls);
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
73 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
74 else {
230
0e69b5843c2f theme: bulma theme first draft:
Goffi <goffi@goffi.org>
parents: 171
diff changeset
75 elt.classList.remove(btn_clicked_cls);
166
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 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
78 let tab_page_elt = document.getElementById(tab_page_id);
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
79 for (let elt of document.getElementsByClassName("tab__page")) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
80 if (elt === tab_page_elt) {
230
0e69b5843c2f theme: bulma theme first draft:
Goffi <goffi@goffi.org>
parents: 171
diff changeset
81 elt.classList.add(tab_clicked_cls);
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
82 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
83 else {
230
0e69b5843c2f theme: bulma theme first draft:
Goffi <goffi@goffi.org>
parents: 171
diff changeset
84 elt.classList.remove(tab_clicked_cls);
166
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 }
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
88
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
89 function get_elt(arg) {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
90 if (typeof arg === 'string') {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
91 // we should have an id
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
92 return document.getElementById(arg);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
93 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
94 else {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
95 // we should have an element
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
96 return arg;
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 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
99
29
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
100 function clicked_cls(elt) {
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
101 /* 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
102 // state_init
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
103 if (elt.classList.contains("state_init")) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
104 elt.classList.remove("state_init");
29
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
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
107 // clicked
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
108 elt.classList.toggle("state_clicked");
29
494d740aa3d6 static/css.js: added clicked_cls function:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
109 }
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
110
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
111 function clicked_mh_fix(arg, max_height) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
112 /* 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
113 *
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
114 * 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
115 * 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
116 * thanks to Brandon Smith
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
117 *
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
118 * @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
119 * @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
120 * */
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
121 elt = get_elt(arg);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
122
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
123 if (!elt.classList.contains("state_clicked")) {
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
124 /* expand */
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
125 let fix_expand = function(event) {
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
126 elt.removeEventListener("transitionend", fix_expand, false);
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
127 if (elt.classList.contains("state_clicked")) {
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
128 /* if event is clicked quicker than transition time,
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
129 * this callback can be called on reduce */
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
130 elt.style.maxHeight = "none";
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 };
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
133
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
134 if (!elt.hasAttribute('_max_height_init')) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
135 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
136 }
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
137 elt.addEventListener("transitionend", fix_expand, false);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
138 clicked_cls(elt);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
139 elt.style.maxHeight = elt.scrollHeight + 'px';
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
140
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
141 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
142 else {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
143 /* reduce */
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
144 let transition_save = elt.style.transition;
41
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
145 elt.style.transition = '';
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
146 requestAnimationFrame(function() {
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
147 elt.style.maxHeight = elt.scrollHeight + 'px';
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
148 elt.style.transition = transition_save;
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
149
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
150 requestAnimationFrame(function() {
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
151 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
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
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
155 clicked_cls(elt);
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
156 }
e296ee56f611 static (css.js): max-height transition fix:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
157 }
166
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
158
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
159 function createElement(html) {
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
160 /* create a DOM element from raw HTML
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
161 *
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
162 * @param html(string): raw HTML to parse
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
163 * @return: DOM element
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
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
166 let template = document.createElement('template');
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
167 template.innerHTML = html.trim();
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
168 new_element = template.content.firstChild;
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
169 return new_element;
178f55b825b7 small refactoring/redesign, better BEM integration:
Goffi <goffi@goffi.org>
parents: 164
diff changeset
170 }
171
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
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
173 function fitHeightToContent(elt) {
cede18c118c9 js (common): added fitHeightToContent to fit <iframe> to its content + <iframe> CSS
Goffi <goffi@goffi.org>
parents: 166
diff changeset
174 /* 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
175 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
176 }
239
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
177
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
178 /* we don't want default behaviour which load a dragged file */
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
179
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
180 window.addEventListener("dragenter", function(e) {
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
181 console.log(e.target.tagName + " " + e.target.type);
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
182 if (e.target.tagName != "INPUT" || e.target.type != "file") {
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
183 e.preventDefault();
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
184 e.dataTransfer.effectAllowed = "none";
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
185 e.dataTransfer.dropEffect = "none";
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
186 }
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
187 }, false);
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
188
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
189 window.addEventListener("dragover", function(e) {
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
190 if (e.target.tagName != "INPUT" || e.target.type != "file") {
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
191 e.preventDefault();
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
192 e.dataTransfer.effectAllowed = "none";
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
193 e.dataTransfer.dropEffect = "none";
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
194 }
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
195 });
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
196
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
197 window.addEventListener("drop", function(e) {
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
198 if (e.target.tagName != "INPUT" || e.target.type != "file") {
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
199 e.preventDefault();
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
200 e.dataTransfer.effectAllowed = "none";
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
201 e.dataTransfer.dropEffect = "none";
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
202 }
61f3efd69fc3 js (common): prevent default behaviour for drag and drop:
Goffi <goffi@goffi.org>
parents: 230
diff changeset
203 });