2015-08-03 11:35:01 +02:00
|
|
|
/**
|
|
|
|
* Movim Javascript Template functions
|
2015-08-10 23:42:45 +02:00
|
|
|
*
|
2015-08-03 11:35:01 +02:00
|
|
|
* These are the default callback functions that users may (or may not) use.
|
|
|
|
*
|
|
|
|
* Note that all of them take only one parameter. Don't be fooled by this, the
|
|
|
|
* expected parameter is actually an array containing the real parameters. These
|
|
|
|
* are checked before use.
|
|
|
|
*
|
|
|
|
* Look at the comments for help.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// movim_append(div, text)
|
|
|
|
function movim_append(id, html)
|
|
|
|
{
|
|
|
|
target = document.getElementById(id);
|
|
|
|
if(target) {
|
|
|
|
target.insertAdjacentHTML('beforeend', html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// movim_prepend(div, text)
|
|
|
|
function movim_prepend(id, html)
|
|
|
|
{
|
|
|
|
target = document.getElementById(id);
|
|
|
|
if(target) {
|
|
|
|
target.insertAdjacentHTML('afterbegin', html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// movim_fill(div, text)
|
|
|
|
function movim_fill(id, html)
|
|
|
|
{
|
|
|
|
target = document.getElementById(id);
|
|
|
|
if(target) {
|
|
|
|
target.innerHTML = html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// movim_delete(div)
|
|
|
|
function movim_delete(id)
|
|
|
|
{
|
|
|
|
target = document.getElementById(id);
|
|
|
|
if(target)
|
|
|
|
target.parentNode.removeChild(target);
|
|
|
|
}
|
|
|
|
// movim_replace(id)
|
|
|
|
function movim_replace(id, html)
|
|
|
|
{
|
|
|
|
target = document.getElementById(id);
|
|
|
|
if(target) {
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.innerHTML = html;
|
|
|
|
var element = div.firstChild;
|
|
|
|
replacedNode = target.parentNode.replaceChild(element, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var MovimTpl = {
|
|
|
|
init : function() {
|
|
|
|
if(document.getElementById('back') != null)
|
|
|
|
document.getElementById('back').style.display = 'none';
|
|
|
|
},
|
|
|
|
showPanel : function() {
|
|
|
|
movim_add_class('main section > div:first-child:nth-last-child(2) ~ div', 'enabled');
|
|
|
|
MovimTpl.scrollPanelTop();
|
|
|
|
},
|
|
|
|
hidePanel : function() {
|
|
|
|
Header_ajaxReset(CURRENT_PAGE);
|
|
|
|
var selector = 'main section > div:first-child:nth-last-child(2) ~ div';
|
|
|
|
var inner = document.querySelector(selector + ' div');
|
|
|
|
|
|
|
|
movim_remove_class(selector, 'enabled');
|
|
|
|
|
|
|
|
// Clear the right panel
|
|
|
|
//if(inner != null) inner.innerHTML = '';
|
|
|
|
//else document.querySelector(selector).innerHTML = '';
|
|
|
|
},
|
|
|
|
fill : function(selector, html) {
|
|
|
|
target = document.querySelector(selector);
|
|
|
|
if(target) {
|
|
|
|
target.innerHTML = html;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isPanel : function() {
|
|
|
|
if(movim_has_class('main section > div:first-child:nth-last-child(2) ~ div', 'enabled')) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2015-08-10 23:42:45 +02:00
|
|
|
isPanelScrolled : function() {
|
2015-11-13 13:37:39 +01:00
|
|
|
var selector = document.querySelector('main section > div:first-child:nth-last-child(2) ~ div div');
|
2015-08-10 23:42:45 +02:00
|
|
|
|
|
|
|
if(selector != null) {
|
2015-11-13 13:37:39 +01:00
|
|
|
return (selector.scrollHeight - Math.floor(selector.scrollTop) === selector.clientHeight);
|
2015-08-10 23:42:45 +02:00
|
|
|
}
|
|
|
|
},
|
2015-08-03 11:35:01 +02:00
|
|
|
scrollPanel : function() {
|
|
|
|
var selector = document.querySelector('main section > div:first-child:nth-last-child(2) ~ div div');
|
|
|
|
|
|
|
|
if(selector != null) {
|
|
|
|
selector.scrollTop = selector.scrollHeight;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scrollPanelTop : function() {
|
|
|
|
var selector = document.querySelector('main section > div:first-child:nth-last-child(2) ~ div');
|
|
|
|
|
|
|
|
if(selector != null) {
|
|
|
|
selector.scrollTop = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleMenu : function() {
|
|
|
|
movim_toggle_class('body > nav', 'active');
|
|
|
|
},
|
|
|
|
toggleContextMenu : function(e) {
|
|
|
|
var element = 'ul.context_menu';
|
|
|
|
var classname = 'shown';
|
|
|
|
|
|
|
|
if(document.querySelector(element) == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(document.querySelector('.show_context_menu').contains(e.target)) {
|
|
|
|
movim_add_class(element, classname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-10 23:42:45 +02:00
|
|
|
//if(!document.querySelector(element).contains(e.target))
|
2015-08-03 11:35:01 +02:00
|
|
|
movim_remove_class(element, classname);
|
|
|
|
},
|
2015-08-10 23:42:45 +02:00
|
|
|
toggleActionButton : function() {
|
|
|
|
movim_toggle_class('.button.action', 'active');
|
|
|
|
},
|
2015-08-03 11:35:01 +02:00
|
|
|
hideContextMenu : function() {
|
|
|
|
movim_remove_class('ul.context_menu', 'shown');
|
|
|
|
},
|
|
|
|
hideMenu : function() {
|
|
|
|
movim_remove_class('body > nav', 'active');
|
|
|
|
},
|
|
|
|
back : function() {
|
|
|
|
// If the contect menu is show
|
|
|
|
var cm = document.querySelector('ul.context_menu');
|
|
|
|
if(cm != null && cm.className.includes('shown')) {
|
|
|
|
MovimTpl.toggleContextMenu(document);
|
|
|
|
}
|
|
|
|
// If a dialog box is show
|
|
|
|
else if(Dialog.filled()) {
|
|
|
|
Dialog.clear();
|
|
|
|
// If the menu is shown
|
|
|
|
} else if(movim_has_class('body > nav', 'active')) {
|
|
|
|
movim_toggle_class('body > nav', 'active');
|
|
|
|
// If the panel is shown
|
|
|
|
} else if(MovimTpl.isPanel()) {
|
|
|
|
MovimTpl.hidePanel();
|
|
|
|
} else {
|
|
|
|
window.history.back();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getHeaderColor : function() {
|
|
|
|
var header = document.querySelector('body main > header');
|
|
|
|
return window.getComputedStyle(header).backgroundColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
movim_add_onload(function() {
|
|
|
|
MovimTpl.init();
|
|
|
|
document.body.addEventListener('click', MovimTpl.toggleContextMenu, false);
|
|
|
|
});
|