-
Notifications
You must be signed in to change notification settings - Fork 58
/
plone_javascripts.js
525 lines (461 loc) · 30.8 KB
/
plone_javascripts.js
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
if ( typeof(window.console)=='undefined' ){
window.console = {
log: function(str){}
};
}
function registerPloneFunction(func){if(window.addEventListener)window.addEventListener("load",func,false);else if(window.attachEvent)window.attachEvent("onload",func);}
function unRegisterPloneFunction(func){if(window.removeEventListener)window.removeEventListener("load",func,false);else if(window.detachEvent)window.detachEvent("onload",func);}
function getContentArea(){node=document.getElementById('region-content')
if(!node){node=document.getElementById('content')}
return node}
function wrapNode(node,wrappertype,wrapperclass){wrapper=document.createElement(wrappertype)
wrapper.className=wrapperclass;innerNode=node.parentNode.replaceChild(wrapper,node);wrapper.appendChild(innerNode)}
var registerXatafaceDecorator=null;var decorateXatafaceNode=null;(function(){var decorators=[];registerXatafaceDecorator=function(decorator){decorators.push(decorator);};decorateXatafaceNode=function(node){var replaceCallbacks=[];removeNoDecorateSections(node,replaceCallbacks);for(var i=0;i<decorators.length;i++){decorators[i](node);}
for(var i=0;i<replaceCallbacks.length;i++){replaceCallbacks[i]();}}
function removeNoDecorateSections(node,callbacks){if(typeof(jQuery)!='undefined'){jQuery('.xf-disable-decorate',node).each(function(){var replace=document.createTextNode('');var parent=jQuery(this).parent();jQuery(this).replaceWith(replace);var self=this;callbacks.push(function(){jQuery(replace).replaceWith(self);});});}}})();window.addEventListener('DOMContentLoaded', function(){decorateXatafaceNode(document.documentElement)});function showDay(date){document.getElementById('day'+date).style.visibility='visible';return true;}
function hideDay(date){document.getElementById('day'+date).style.visibility='hidden';return true;}
function setFocus(){var xre=new RegExp(/\berror\b/);for(var f=0;(formnode=document.getElementsByTagName('form').item(f));f++){for(var i=0;(node=formnode.getElementsByTagName('div').item(i));i++){if(xre.exec(node.className)){for(var j=0;(inputnode=node.getElementsByTagName('input').item(j));j++){inputnode.focus();return;}}}}}
registerPloneFunction(setFocus)
function compare(a,b)
{au=new String(a);bu=new String(b);if(au.charAt(4)!='-'&&au.charAt(7)!='-')
{var an=parseFloat(au)
var bn=parseFloat(bu)}
if(isNaN(an)||isNaN(bn))
{as=au.toLowerCase()
bs=bu.toLowerCase()
if(as>bs)
{return 1;}
else
{return-1;}}
else{return an-bn;}}
function getConcatenedTextContent(node){var _result="";if(node==null){return _result;}
var childrens=node.childNodes;var i=0;while(i<childrens.length){var child=childrens.item(i);switch(child.nodeType){case 1:case 5:_result+=getConcatenedTextContent(child);break;case 3:case 2:case 4:_result+=child.nodeValue;break;case 6:case 7:case 8:case 9:case 10:case 11:case 12:break;}
i++;}
return _result;}
function sort(e){var el=window.event?window.event.srcElement:e.currentTarget;var a=new Array();if(el.nodeName=='IMG')el=el.parentNode;var name=el.childNodes.item(1).nodeValue;var dad=el.parentNode;var node;for(var im=0;(node=dad.getElementsByTagName("th").item(im));im++){if(node.lastChild.nodeName=='IMG')
{lastindex=node.getElementsByTagName('img').length-1;node.getElementsByTagName('img').item(lastindex).setAttribute('src',portal_url+'/images/arrowBlank.gif');}}
for(var i=0;(node=dad.getElementsByTagName("th").item(i));i++){var xre=new RegExp(/\bnosort\b/);if(!xre.exec(node.className)&&node.childNodes.item(1).nodeValue==name)
{lastindex=node.getElementsByTagName('img').length-1;node.getElementsByTagName('img').item(lastindex).setAttribute('src',portal_url+'/images/arrowUp.gif');break;}}
var tbody=dad.parentNode.parentNode.getElementsByTagName("tbody").item(0);for(var j=0;(node=tbody.getElementsByTagName("tr").item(j));j++){a[j]=new Array();a[j][0]=getConcatenedTextContent(node.getElementsByTagName("td").item(i));a[j][1]=getConcatenedTextContent(node.getElementsByTagName("td").item(1));a[j][2]=getConcatenedTextContent(node.getElementsByTagName("td").item(0));a[j][3]=node;}
if(a.length>1){a.sort(compare);if(a[0][0]==getConcatenedTextContent(tbody.getElementsByTagName("tr").item(0).getElementsByTagName("td").item(i))&&a[1][0]==getConcatenedTextContent(tbody.getElementsByTagName("tr").item(1).getElementsByTagName("td").item(i)))
{a.reverse();lastindex=el.getElementsByTagName('img').length-1;el.getElementsByTagName('img').item(lastindex).setAttribute('src',portal_url+'/images/arrowDown.gif');}}
for(var j=0;j<a.length;j++){tbody.appendChild(a[j][3]);}}
function initalizeTableSort(e){var tbls=document.getElementsByTagName('table');for(var t=0;t<tbls.length;t++)
{var re=new RegExp(/\blisting2\b/)
var xre=new RegExp(/\bnosort\b/)
if(re.exec(tbls[t].className)&&!xre.exec(tbls[t].className))
{try{var tablename=tbls[t].getAttribute('id');var thead=document.getElementById(tablename).getElementsByTagName("thead").item(0);var node;blankarrow=document.createElement('img');blankarrow.setAttribute('src',portal_url+'/images/arrowBlank.gif');blankarrow.setAttribute('height',6);blankarrow.setAttribute('width',9);initialsort=false;for(var i=0;(node=thead.getElementsByTagName("th").item(i));i++){if(!xre.exec(node.className)){node.insertBefore(blankarrow.cloneNode(1),node.firstChild);if(!initialsort){initialsort=true;uparrow=document.createElement('img');uparrow.setAttribute('src',portal_url+'/images/arrowUp.gif');uparrow.setAttribute('height',6);uparrow.setAttribute('width',9);node.appendChild(uparrow);}else{node.appendChild(blankarrow.cloneNode(1));}
if(node.addEventListener)node.addEventListener("click",sort,false);else if(node.attachEvent)node.attachEvent("onclick",sort);}}}catch(er){}}}}
registerPloneFunction(initalizeTableSort)
function submitFolderAction(folderAction){document.folderContentsForm.action=document.folderContentsForm.action+'/'+folderAction;document.folderContentsForm.submit();}
function submitFilterAction(){document.folderContentsForm.action=document.folderContentsForm.action+'/folder_contents';filter_selection=document.getElementById('filter_selection');for(var i=0;i<filter_selection.length;i++){if(filter_selection.options[i].selected){if(filter_selection.options[i].value=='#'){document.folderContentsForm.filter_state.value='clear_view_filter';}
else{document.folderContentsForm.filter_state.value='set_view_filter';}}}
document.folderContentsForm.submit();}
function selectAll(id,formName){if(formName==null){checkboxes=document.getElementsByName(id)
for(i=0;i<checkboxes.length;i++)
checkboxes[i].checked=true;}else{for(i=0;i<document.forms[formName].elements.length;i++)
{if(document.forms[formName].elements[i].name==id)
document.forms[formName].elements[i].checked=true;}}}
function deselectAll(id,formName){if(formName==null){checkboxes=document.getElementsByName(id)
for(i=0;i<checkboxes.length;i++)
checkboxes[i].checked=false;}else{for(i=0;i<document.forms[formName].elements.length;i++)
{if(document.forms[formName].elements[i].name==id)
document.forms[formName].elements[i].checked=false;}}}
function toggleSelect(selectbutton,id,initialState,formName){id=id||'ids:list'
if(selectbutton.isSelected==null)
{initialState=initialState||false;selectbutton.isSelected=initialState;}
if(selectbutton.isSelected==false){selectbutton.setAttribute('src',portal_url+'/images/select_none_icon.gif');selectbutton.isSelected=true;return selectAll(id,formName);}
else{selectbutton.setAttribute('src',portal_url+'/images/select_all_icon.gif');selectbutton.isSelected=false;return deselectAll(id,formName);}}
function climb(node,word){if(!node){return false}
if(node.hasChildNodes){var i;for(i=0;i<node.childNodes.length;i++){climb(node.childNodes[i],word);}
if(node.nodeType==3){checkforhighlight(node,word);}}
function checkforhighlight(node,word){ind=node.nodeValue.toLowerCase().indexOf(word.toLowerCase())
if(ind!=-1){if(node.parentNode.className!="highlightedSearchTerm"){par=node.parentNode;contents=node.nodeValue;hiword=document.createElement("span");hiword.className="highlightedSearchTerm";hiword.appendChild(document.createTextNode(contents.substr(ind,word.length)));par.insertBefore(document.createTextNode(contents.substr(0,ind)),node);par.insertBefore(hiword,node);par.insertBefore(document.createTextNode(contents.substr(ind+word.length)),node);par.removeChild(node);}}}}
function correctPREformatting(){contentarea=getContentArea();if(!contentarea){return false}
pres=contentarea.getElementsByTagName('pre');for(i=0;i<pres.length;i++){wrapNode(pres[i],'div','visualOverflow')}}
function highlightSearchTerm(){query=window.location.search
if(typeof decodeURI!='undefined'){query=unescape(decodeURI(query))}
else{return false}
if(query){var qfinder=new RegExp()
qfinder.compile("searchterm=([^&]*)","gi")
qq=qfinder.exec(query)
if(qq&&qq[1]){query=qq[1]
if(!query){return false}
queries=query.replace(/\+/g,' ').split(/\s+/)
contentarea=getContentArea();for(q=0;q<queries.length;q++){if(queries[q].toLowerCase()!='not'&&queries[q].toLowerCase()!='and'&&queries[q].toLowerCase()!='or'){climb(contentarea,queries[q]);}}}}}
registerPloneFunction(highlightSearchTerm);function setActiveStyleSheet(title,reset){var i,a,main;for(i=0;(a=document.getElementsByTagName("link")[i]);i++){if(a.getAttribute("rel").indexOf("style")!=-1&&a.getAttribute("title")){a.disabled=true;if(a.getAttribute("title")==title)a.disabled=false;}}
if(reset==1){createCookie("wstyle",title,365);}}
function setStyle(){var style=readCookie("wstyle");if(style!=null){setActiveStyleSheet(style,0);}}
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else expires="";document.cookie=name+"="+escape(value)+expires+"; path=/;";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return unescape(c.substring(nameEQ.length,c.length));}
return null;}
registerPloneFunction(setStyle);function onJsCalendarDateUpdate(cal){var year=cal.params.input_id_year;var month=cal.params.input_id_month;var day=cal.params.input_id_day;var daystr=''+cal.date.getDate();if(daystr.length==1)
daystr='0'+daystr;var monthstr=''+(cal.date.getMonth()+1);if(monthstr.length==1)
monthstr='0'+monthstr;cal.params.inputField.value=''+cal.date.getFullYear()+'/'+monthstr+'/'+daystr
year.value=cal.params.inputField.value.substring(0,4);month.value=cal.params.inputField.value.substring(5,7);day.value=cal.params.inputField.value.substring(8,10);}
function showJsCalendar(input_id_anchor,input_id,input_id_year,input_id_month,input_id_day,input_id_hour,input_id_minute,yearStart,yearEnd){var input_id_anchor=document.getElementById(input_id_anchor);var input_id=document.getElementById(input_id);var input_id_year=document.getElementById(input_id_year);var input_id_month=document.getElementById(input_id_month);var input_id_day=document.getElementById(input_id_day);var format='y/mm/dd';var dateEl=input_id;var mustCreate=false;var cal=window.calendar;var params={'range':[yearStart,yearEnd],inputField:input_id,input_id_year:input_id_year,input_id_month:input_id_month,input_id_day:input_id_day};function param_default(pname,def){if(typeof params[pname]=="undefined"){params[pname]=def;}};param_default("inputField",null);param_default("displayArea",null);param_default("button",null);param_default("eventName","click");param_default("ifFormat","%Y/%m/%d");param_default("daFormat","%Y/%m/%d");param_default("singleClick",true);param_default("disableFunc",null);param_default("dateStatusFunc",params["disableFunc"]);param_default("mondayFirst",true);param_default("align","Bl");param_default("range",[1900,2999]);param_default("weekNumbers",true);param_default("flat",null);param_default("flatCallback",null);param_default("onSelect",null);param_default("onClose",null);param_default("onUpdate",null);param_default("date",null);param_default("showsTime",false);param_default("timeFormat","24");if(!window.calendar){window.calendar=cal=new Calendar(true,null,onJsCalendarDateUpdate,function(cal){cal.hide();});cal.time24=true;cal.weekNumbers=true;mustCreate=true;}else{cal.hide();}
cal.setRange(yearStart,yearEnd);cal.params=params;cal.setDateStatusHandler(null);cal.setDateFormat(format);if(mustCreate)
cal.create();cal.parseDate(dateEl.value||dateEl.innerHTML);cal.refresh();cal.showAtElement(input_id_anchor,null);return false;}
function update_date_field(field,year,month,day,hour,minute,ampm)
{var field=document.getElementById(field)
var date=document.getElementById(date)
var year=document.getElementById(year)
var month=document.getElementById(month)
var day=document.getElementById(day)
var hour=document.getElementById(hour)
var minute=document.getElementById(minute)
var ampm=document.getElementById(ampm)
if(0<year.value)
{field.value=year.value+"-"+month.value+"-"+day.value+" "+hour.value+":"+minute.value
if(ampm&&m.value)
field.value=field.value+" "+ampm.value}
else
{field.value=''
month.options[0].selected=1
day.options[0].selected=1
hour.options[0].selected=1
minute.options[0].selected=1
if(ampm&&m.options)
ampm.options[0].selected=1}}
function fullscreenMode(){if(document.getElementById('portal-top').style.display=='none'){document.getElementById('portal-top').style.display='block';document.getElementById('portal-column-one').style.display='block';document.getElementById('portal-column-two').style.display='block';}
else{document.getElementById('portal-top').style.display='none';document.getElementById('portal-column-one').style.display='none';document.getElementById('portal-column-two').style.display='none';}}
function invalidateTranslations(url){var res=confirm('Are you sure you want to invalidate the translations for this record? This will mark the record for re-translation.');if(!res)return;var div=document.getElementsByTagName('body')[0].appendChild(document.createElement('div'));var html='<form id="invalidate_translation_form" method="POST" action="'+url+'">';html+='<input type="hidden" name="--confirm_invalidate" value="1">';div.innerHTML=html;var form=document.getElementById('invalidate_translation_form');form.submit();}
function hackPush(el){this[this.length]=el;}
function hackPop(){var N=this.length-1,el=this[N];this.length=N
return el;}
function hackShift(){var one=this[0],N=this.length;for(var i=1;i<N;i++){this[i-1]=this[i];}
this.length=N-1
return one;}
function require(path){if(!window._javascripts_loaded)window._javascripts_loaded={};if(window._javascripts_loaded[path])return true;else window._javascripts_loaded[path]=true;var e=document.createElement("script");e.src=path;e.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(e);}
function loadScripts(e){var scriptTags=e.getElementsByTagName('script');for(var i=0;i<scriptTags.length;i++){if(scriptTags[i].getAttribute('src'))require(scriptTags[i].getAttribute('src'));}}
function registerRecord(id,vals){if(!document.recordIndex)document.recordIndex={};document.recordIndex[id]=vals;}
function getRecord(id){if(!document.recordIndex)document.recordIndex={};return document.recordIndex[id];}
function addToValuelist(table,valuelist,element){var value=prompt('Enter the value you wish to add to this value list. Use the notation key=value if you need to add both a key and a value for the option.');if(!value)return;if(value.indexOf('=')>=0){var vals=value.split('=');var key=vals[0];value=vals[1];}else{key=null;}
var http=getHTTPObject();http.open('POST',window.location,true);var params="-action=ajax_valuelist_append&-table="+escape(table)+"&-valuelist="+escape(valuelist)+"&-value="+escape(value)+"&-key="+escape(key);http.setRequestHeader("Content-type","application/x-www-form-urlencoded");http.setRequestHeader("Content-length",params.length);http.setRequestHeader("Connection","close");http.element=element;http.onreadystatechange=function(){if(http.readyState==4){eval('var retval = '+http.responseText+';');if(retval['success']){element.options[element.options.length]=element.options[element.options.length-1];element.options[element.options.length-2]=new Option(retval['value']['value'],retval['value']['key']);element.selectedIndex=element.options.length-2;}else{alert(retval['msg']);element.selectedIndex=0;}}}
http.send(params);}
function makeSelectEditable(table,valuelist,select){if(select.onchange){select.onchange_old=select.onchange;}
select.onchange=function(){if(this.options[this.selectedIndex].value=='-1'){addToValuelist(table,valuelist,this);}
if(this.onchange_old)
return this.onchange_old();};select.options[select.options.length]=new Option('Edit values...','-1');}
var testPushPop=new Array();if(testPushPop.push){}else{Array.prototype.push=hackPush
Array.prototype.pop=hackPop
Array.prototype.shift=hackShift;}
function registerOnloadHandler(func){if(!document._onload)document._onload=[];document._onload[document._onload.length]=func;}
function bodyOnload(){if(document._onload){for(var i=0;i<document._onload.length;i++){document._onload[i]();}}}
function getElementsByClassName(oElm,strTagName,strClassName){var arrElements=(strTagName=="*"&&oElm.all)?oElm.all:oElm.getElementsByTagName(strTagName);var arrReturnElements=new Array();strClassName=strClassName.replace(/\-/g,"\\-");var oRegExp=new RegExp("(^|\\s)"+strClassName+"(\\s|$)");var oElement;for(var i=0;i<arrElements.length;i++){oElement=arrElements[i];if(oRegExp.test(oElement.className)){arrReturnElements.push(oElement);}}
return(arrReturnElements)}
function toggleSelectedRows(checkbox,tableid){var table=document.getElementById(tableid);var checkboxes=getElementsByClassName(table,'input','rowSelectorCheckbox');for(var i=0;i<checkboxes.length;i++){checkboxes[i].checked=checkbox.checked;}}
function getSelectedIds(tableid){var table=document.getElementById(tableid);var checkboxes=getElementsByClassName(table,'input','rowSelectorCheckbox');var ids=[];for(var i=0;i<checkboxes.length;i++){if(checkboxes[i].checked){var id=checkboxes[i].getAttribute('id');id=id.substring(id.indexOf(':')+1);ids.push(id);}}
return ids;}
function actOnSelected(tableid,action,beforeHook,vals){var ids=getSelectedIds(tableid);if(ids.length==0){alert("First you must select the rows you wish to modify.");return false;}
if(typeof(beforeHook)!='undefined'){if(!beforeHook())return false;}
var form=document.getElementById("result_list_selected_items_form");form.elements['--selected-ids'].value=ids.join("\n");form.elements['-action'].value=action;form.submit();return false;}
function copySelected(tableid){var ids=getSelectedIds(tableid);if(ids.length==0){alert("Please first check boxes beside the records you wish to copy, and then press 'Copy'.");return;}
var form=document.getElementById("result_list_selected_items_form");form.elements['--selected-ids'].value=ids.join("\n");form.elements['-action'].value='copy_replace';var fld=document.createElement('input');fld.name='--copy';fld.type='hidden';fld.value='1';form.appendChild(fld);form.submit();}
function updateSelected(tableid){var ids=getSelectedIds(tableid);if(ids.length==0){alert("Please first check boxes beside the records you wish to update, and then press 'Update'.");return;}
var form=document.getElementById("result_list_selected_items_form");form.elements['--selected-ids'].value=ids.join("\n");form.elements['-action'].value='copy_replace';form.submit();}
function removeSelectedRelated(tableid){var ids=getSelectedIds(tableid);if(ids.length==0){alert("Please first check boxes beside the records you wish to remove, and then press 'Remove'.");return;}
var form=document.getElementById("result_list_selected_items_form");form.elements['--selected-ids'].value=ids.join("\n");form.elements['-action'].value='remove_related_record';form.submit();}
(function() {
// Mobile stuff now
var mobileActivated = false;
function xfHandleResize() {
var body = document.querySelector('body');
if (!body) return;
if (window.innerWidth < 768) {
if (body.classList.contains('large') || !body.classList.contains('small')) {
body.classList.add('small');
body.classList.remove('large');
window.dispatchEvent(new Event('xf-mobileenter'));
}
mobileActivated = true;
} else {
if (body.classList.contains('small') || !body.classList.contains('large')) {
body.classList.remove('small');
body.classList.add('large');
window.dispatchEvent(new Event('xf-mobileexit'));
}
}
}
xfHandleResize();
window.addEventListener('DOMContentLoaded', xfHandleResize);
window.addEventListener('resize', xfHandleResize);
var paddingTopExplicit = false;
var paddingBottomExplicit = false;
var viewport = {
top : 0,
left : 0,
right : 0,
bottom : 0,
width : window.innerWidth,
height : window.innerHeight
};
var firedInitialViewportChangedEvent = false;
function updateBodyPadding() {
var localFiredInitialViewportChangedEvent = firedInitialViewportChangedEvent;
firedInitialViewportChangedEvent = true;
if (!mobileActivated) {
if (viewport.width != window.innerWidth || viewport.height != window.innerHeight) {
viewport.width = window.innerWidth;
viewport.height = window.innerHeight;
var event = new Event('xf-viewport-changed');
window.dispatchEvent(event);
} else {
if (!localFiredInitialViewportChangedEvent) {
var event = new Event('xf-viewport-changed');
window.dispatchEvent(event);
}
}
return;
}
var body = document.querySelector('body');
var changed = false;
if (!body.classList.contains('small')) {
changed = paddingTopExplicit || paddingBottomExplicit;
body.style.paddingBottom = null;
body.style.paddingTop = null;
paddingTopExplicit = paddingBottomExplicit = false;
viewport.top = viewport.bottom = viewport.left = viewport.right = 0;
viewport.width = window.innerWidth;
viewport.height = window.innerHeight;
} else {
var footer = document.querySelector('.mobile-footer');
var buttons = document.querySelector('.button-section');
if (footer || buttons) {
var offsetHeight = 0;
if (footer) offsetHeight = footer.offsetHeight;
if (buttons) offsetHeight = Math.max(offsetHeight, buttons.offsetHeight);
if (body.style.paddingBottom != offsetHeight+'px') {
changed = true;
}
body.style.paddingBottom = offsetHeight + 'px';
viewport.bottom = offsetHeight;
viewport.height = window.innerHeight - viewport.bottom - viewport.top;
viewport.width = window.innerWidth;
explicitBottomPadding = true;
}
var header = document.querySelector('.mobile-header');
if (header) {
if (body.style.paddingTop != header.offsetHeight+'px') {
changed = true;
}
body.style.paddingTop = header.offsetHeight + 'px';
viewport.top = header.offsetHeight;
viewport.height = window.innerHeight - viewport.top - viewport.bottom;
viewport.width = window.innerWidth;
explicitBottomPadding = true;
}
}
if (changed) {
var event = new Event('xf-viewport-changed');
window.dispatchEvent(event);
}
}
function getViewport() {
return Object.assign({}, viewport);
}
window.xataface = window.xataface || {};
Object.defineProperty(window.xataface, 'viewport', {
get: getViewport,
configurable: false,
enumerable: false
});
window.addEventListener('DOMContentLoaded', updateBodyPadding);
window.addEventListener('load', updateBodyPadding);
setInterval(updateBodyPadding, 1000);
})();
(function() {
// browser detection
function iOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
// iPad on iOS 13 detection
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
function addUserAgentCSSClass() {
if (iOS()) {
document.body.classList.add('iphone');
}
}
window.addEventListener('DOMContentLoaded', addUserAgentCSSClass);
})();
(function() {
var isScrolled = false;
function onReady() {
var body = document.querySelector('body');
var runOnScroll = function(evt) {
//console.log("scrolling ", body.scrollTop);
if (body.scrollTop < 100) {
if (isScrolled) {
body.classList.remove('xf-viewport-scrolled');
isScrolled = false;
}
} else {
if (!isScrolled) {
body.classList.add('xf-viewport-scrolled');
isScrolled = true;
}
}
};
body.addEventListener('scroll', runOnScroll, {passive:true});
}
window.addEventListener('DOMContentLoaded', onReady);
})();
(function() {
if (!window.localStorage) {
return;
}
var history = window.localStorage.getItem('xf-history');
if (!history) {
history = {startPos : 0, endPos: 0, urls : {}};
localStorage.setItem('xf-history', JSON.stringify(history));
} else {
history = JSON.parse(history);
}
history.urls[history.endPos++] = window.location.href;
var currPos = history.endPos-1;
while (history.endPos - history.startPos > 100) {
delete history.urls[history.startPos++];
}
localStorage.setItem('xf-history', JSON.stringify(history));
function addBackButton() {
if (!window.jQuery) {
return;
}
var referrerIndex = getReferrer();
var $ = jQuery;
var backButton = $('<button class="back-btn"><i class="material-icons">navigate_before</i> <span>Back</span></button>');
var backUrl = history.urls[referrerIndex];
if (!backUrl) {
return;
}
backButton.click(function() {
window.location.href = backUrl;
});
backButton.insertBefore($('.site_logo'));
$('body').addClass('has-back-button');
}
function getReferrer() {
var search = window.location.search;
var referrerPos = search.indexOf('&--referrer=');
if (referrerPos < 0) {
return -1;
}
referrerPos = search.indexOf('=', referrerPos)+1;
var referrerEndPos = search.indexOf('&', referrerPos);
var referrerIndex = -1;
if (referrerEndPos < 0) {
referrerIndex = search.substring(referrerPos);
} else {
referrerIndex = search.substring(referrerPos, referrerEndPos);
}
referrerIndex = parseInt(referrerIndex);
return referrerIndex;
}
function addReferrer(link, index) {
if (!link) {
return link;
}
if (link.indexOf('javascript:') === 0) {
return link;
}
if (link.indexOf('--referrer') > 0) {
return link;
}
if (link.indexOf('?') < 0) {
link += '?';
}
if (index) {
return link + '&--referrer=' + index;
}
return link + '&--referrer=' + currPos;
}
var thisReferrer = getReferrer();
registerXatafaceDecorator(function(root) {
if (!window.jQuery) {
console.log('jquery not loaded yet');
return;
}
var $ = jQuery;
$('[rel][href]').each(function() {
var rel = $(this).attr('rel');
if (rel == 'child') {
$(this).attr('href', addReferrer(this.getAttribute('href')));
} else if (rel == 'sibling') {
if (thisReferrer >= 0) {
$(this).attr('href', addReferrer(this.getAttribute('href'), thisReferrer));
}
}
});
});
window.addEventListener('DOMContentLoaded', addBackButton);
})();
(function() {
var $ = jQuery;
var xataface = window.xataface || {};
window.xataface = xataface;
xataface.showInfiniteProgress = showInfiniteProgress;
xataface.hideInfiniteProgress = hideInfiniteProgress;
var globalInfiniteProgress;
function showInfiniteProgress(el) {
var spinner = el ? $('<div class="spin"></div>') : $('<div class="spin fillscreen"></div>');
if (el) {
$(el).append(spinner);
} else {
if (globalInfiniteProgress && jQuery.contains(document, globalInfiniteProgress)) {
return globalInfiniteProgress;
}
$('body').append(spinner);
globalInfiniteProgress = spinner.get(0);
}
return spinner.get(0);
}
function hideInfiniteProgress(el) {
if (el) {
$(el).remove();
} else {
if (globalInfiniteProgress) {
$(globalInfiniteProgress).remove();
globalInfiniteProgress = null;
}
}
}
})();
(function() {
// Define a goBackToParentContext() method which is used in the new record form
// when the -add-related-context is supplied (meaning that it is actually adding a record to a relationship).
var $ = jQuery;
var xataface = window.xataface || {};
window.xataface = xataface;
xataface.goBackToParentContext = goBackToParentContext;
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
function goBackToParentContext() {
var params = new URLSearchParams(document.location.search.substring(1));
var contextString = params.get('-add-related-context');
if (!contextString) {
// Context string might be embedded in hidden fields on forms
contextString = $('input[name="-add-related-context"]').val();
if (contextString) {
contextString = decodeHtml(contextString);
}
}
if (!contextString) {
return;
}
var context = JSON.parse(contextString);
var id = context.id;
var tableName = id.substring(0, id.indexOf('?'));
window.location.search = '?-table=' + encodeURIComponent(tableName)+ '&-action=related_records_list&-relationship=' + encodeURIComponent(context.relationship) + '&-recordid=' + encodeURIComponent(id);
}
})();