Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
329 lines (293 loc) · 9.91 KB
/
Copy pathscript.js
File metadata and controls
329 lines (293 loc) · 9.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*************************************
* constant of pixel ratio of device *
*************************************/
const pix = window.devicePixelRatio;
/***********************************/
const converter = new showdown.Converter();
let myClasses = ['team', 'project', 'process', 'inspiration', 'german', 'output'];
// let myTags = ['yano', 'micha', 'shintaro', 'selena', 'viktor', 'kayla']
/**
* Object to store visibility and name of classes
* @param {String} _name - name of the class
* @param {boolean} _visible - boolean to set the visibility of the class
*/
function ClassObject(_name, _visible) {
this.name = _name;
this.visible = _visible;
}
let ClassObjects = [];
for (let i = 0; i < myClasses.length; i++) {
ClassObjects.push(new ClassObject(myClasses[i], true));
}
/**
* function that reveals only certain elements of the website
* @param {HTMLObjectElement} el - the section that needs to be shown!
*/
function reveal(el) {
// window.scrollTo(0, 0);
document.querySelector('div.main').scrollTo(0, 0);
console.log(el.dataset.section);
const section = el.dataset.section
const articles = document.getElementById('articles').children;
let i = 0;
for (const child of articles) {
if (child.dataset.section === section) child.style.display = 'grid';
else child.style.display = 'none';
i++
}
console.log(i);
hide_inspiration();
}
function reveal_inspiration(el) {
if (el !== undefined) reveal(el);
const inspiration = document.getElementById('inspiration')
// if(inspiration.style.display === 'none'){
inspiration.style.display = 'block'
// }
}
function hide_inspiration() {
const inspiration = document.getElementById('inspiration')
if (inspiration.style.display === 'block') {
inspiration.style.display = 'none'
}
}
/**
* function that shows all the posts of the wesite
*/
function showAll() {
document.querySelector('div.main').scrollTo(0, 0);
const articles = document.getElementById('articles').children;
for (const child of articles) child.style.display = 'grid';
reveal_inspiration();
}
let content;
let start_content = 0;
let end_content = 5;
const content_range = 5;
function initialize_content() {
$.getJSON('content.json', data => {
// console.log(data);
data = convert_data(data).sort((a, b) => b.date - a.date);
// console.log(data);
render_content(data);
});
}
initialize_content();
function convert_data(arr) {
const result = arr;
for (const el of result) {
// console.log(el.date);
const date = el.date.split('/');
const month = parseInt(date[0]);
const year = parseInt(date[1]);
const parsed_date = new Date(year, month, 1);
el.date = parsed_date;
}
return result;
}
let g_data;
function render_content(data) {
// if the url is a link to a specific post we render it opened
// get referrer
// console.log(window.location);
let hash = window.location.hash
if (hash) {
console.log(hash);
hash = hash.replace('#', '');
console.log(hash);
// const div_to_enlarge = document.getElementById(hash);
// // we enlarge the div
// enlargeDivs(div_to_enlarge);
// const article = data.filter(result => result.id === hash);
// console.log(article[0]);
}
for (const el of data) {
// const el = content[i];
// console.log(i);
// create asrticle element
const article = document.createElement('div');
article.setAttribute('class', 'preview copy');
article.setAttribute('id', el.id);
// add data: date, section && link
const month = el.date.getMonth() + 1;
const year = el.date.getFullYear();
article.setAttribute('data-date', month + '/' + year);
article.setAttribute('data-section', el.section);
const link_to_div = window.location.origin + '/index.html#' + el.id;
article.setAttribute('data-clipboard-text', link_to_div)
const image_url = el.img_list[0] || 'img/commoning_web.png'
article.style.backgroundImage = 'url(' + image_url + ')';
if (el.section === 'german') article.style.display = 'none';
const title = document.createElement('div');
title.innerText = el.title;
title.setAttribute('class', 'title-content');
article.appendChild(title);
const txt = document.createElement('div');
txt.setAttribute('class', 'text-content');
const p = document.createElement('p');
const MD_to_html = converter.makeHtml(el.content);
// console.log(MD_to_html);
p.innerHTML = MD_to_html;
txt.appendChild(p);
// article.appendChild(txt);
const media_content = document.createElement('div');
media_content.setAttribute('class', 'media-content');
for (const url of el.video_list) {
const my_iframe = document.createElement('iframe');
my_iframe.setAttribute('src', url);
my_iframe.setAttribute('frameborder', '0');
my_iframe.setAttribute('width', '100%');
my_iframe.setAttribute('height', 'auto');
media_content.appendChild(my_iframe);
}
for (const url of el.img_list) {
const my_img = document.createElement('img');
my_img.setAttribute('src', url);
media_content.appendChild(my_img);
}
// article.appendChild(media_content);
// set random width to div;
// if (innerWidth > 899) {
// const random_w = (2 + Math.floor(Math.random() * 3)) * 10;
// article.style.width = random_w + '%';
// }
const main = document.getElementById('articles');
article.addEventListener('click', () => enlargeDivs(article))
article.appendChild(media_content)
article.appendChild(txt)
main.appendChild(article);
if (hash === el.id) {
// console.log(article);
enlargeDivs(article);
// const $media = $(media_content);
// const $content = $(txt);
// const container = article;
// $(container).append($media);
// $(container).append($content);
} else {
// $(article).click(enlargeDivs);
// $(article).click((el) => {
// // console.log($(this));
// const $media = $(media_content);
// const $content = $(txt);
// const container = article;
// $(container).append($media);
// $(container).append($content);
// })
}
}
}
/**
* this function enlarges the divs by clicking on them
*/
let previous = null, prevH, prevW, prev;
function enlargeDivs(el) {
let scroll_to = true;
let my_div = el;
// if (el) { // this is a work around to detect whether the el is a dom element or a jquery object
// my_div = el.target;
// } else {
// my_div = el;
// scroll_to = true;
// }
// console.log(my_div);
if (previous === null) {
// continue;
//needs refactoring!!!!!!!
} else {
//reset the previous clicked div to its initial state
previous.setAttribute('class', 'preview copy');
previous.querySelector('.media-content').style.display = 'none'
previous.querySelector('.text-content').style.display = 'none'
}
//let's save the div so we can reset it later
previous = my_div;
my_div.setAttribute('class', 'enlarged copy');
console.log(my_div);
for (const child of my_div.children) {
child.style.display = 'block'
}
my_div.style.backgroundImage = 'none';
const main = document.querySelector('div.main')
if (scroll_to) {//here we get the height of the top menu (needs refactoring set it as gloal variable)
const y = parseFloat(my_div.getBoundingClientRect().y) + main.scrollTop - 100; //this helps us to get the position of the div to scroll to
console.log(document.querySelector('div.main').scrollTop, y)
main.scrollTop = y;
} else {
// console.log(my_div.getBoundingClientRect());
// console.log(main.scrollTop);
// main.scrollTop = my_div.getBoundingClientRect().y - 600;
// const val = my_div.getBoundingClientRect().y - 600
// console.log(val);
// main.scrollTo(0, val);
// console.log(main.scrollTop);
}
}
/**
* this function returns the bounds of the menu at any time
*/
function BoundsById(id) {
return document.getElementById(id).getBoundingClientRect();
}
/**
* function to show hide the menu
*/
let icon1 = 'img/icons/icon_01.png';
let icon2 = 'img/icons/icon_02.png';
// let menuIsShow = true;
let menuIsShow = true;
function closeOpenMenu() {
menuIsShow = !menuIsShow;//every click we change the status of the boolean
let myTags = document.getElementsByClassName('menuelement');
let displayOption;
for (let i = 0; i < myTags.length; i++) {
menuIsShow == false ? myTags[i].style.display = 'none' : myTags[i].style.display = 'inherit';
}
let myMenu = document.getElementById('myMenu');
// menuIsShow == false ? myMenu.style.width = 'auto' : myMenu.style.width = 'auto';
let button = document.getElementById('openClose');
// menuIsShow == true ? button.innerHTML = 'Close Menu' : button.innerHTML = 'Show Menu';
menuIsShow == true ? document.getElementById('menuIcon').src = icon1 : document.getElementById('menuIcon').src = icon2;
}
/**
* this function returns the device orientation in angles
*/
function getOrientation() {
return window.screen.orientation.angle;
}
/**
* this function sets the number of columns of a div
* @param {HTML Dom element} el
* @param {String} num - number of columns to be set
*/
function setNumberOfColumns(el, num) {
el.style.columnCount = num;
el.style.MozColumnCount = num;
el.style.WebkitColumnCount = num;
}
/**
* function to set the rotation of divs
* @param {HTMLElement} el - the element to be rotated
* @param {Number} deg - degree of rotation
*/
function setRotation(el, deg) {
el.style.transform = 'rotate(' + deg + 'deg)';
el.style.WebkitTransform = 'rotate(' + deg + 'deg)';
el.style.MozTransform = 'rotate(' + deg + 'deg)';
}
/**
* this function returns a random number between two numbers
* @param {Number} a
* @param {Number} b
* @returns {Number} random number between the input numbers
*/
function Random(a, b) {
//if a is smaller than b we should swap them
if (b < a) {
let Swap = b;
b = a;
a = Swap;
}
let c = Math.abs(a - b);
return a + (Math.random() * c);
}