Change base to be the default DokuWiki template
This commit is contained in:
116
script.js
Normal file → Executable file
116
script.js
Normal file → Executable file
@@ -1,49 +1,89 @@
|
||||
// template-related scripts go here...
|
||||
/**
|
||||
* We handle several device classes based on browser width.
|
||||
*
|
||||
* - desktop: > __tablet_width__ (as set in style.ini)
|
||||
* - mobile:
|
||||
* - tablet <= __tablet_width__
|
||||
* - phone <= __phone_width__
|
||||
*/
|
||||
var device_class = ''; // not yet known
|
||||
var device_classes = 'desktop mobile tablet phone';
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
function tpl_dokuwiki_mobile(){
|
||||
|
||||
function extractHotkey(linkEl) {
|
||||
if (!linkEl) return '';
|
||||
// the z-index in mobile.css is (mis-)used purely for detecting the screen mode here
|
||||
var screen_mode = jQuery('#screen__mode').css('z-index') + '';
|
||||
|
||||
// Prefer the human-facing "[X]" in the title when present.
|
||||
// DokuWiki commonly uses titles like "Edit this page [E]".
|
||||
var title = linkEl.getAttribute('title') || '';
|
||||
var match = title.match(/\[([^\]]+)\]\s*$/);
|
||||
if (match && match[1]) return match[1].trim();
|
||||
// determine our device pattern
|
||||
// TODO: consider moving into dokuwiki core
|
||||
switch (screen_mode) {
|
||||
case '1':
|
||||
if (device_class.match(/tablet/)) return;
|
||||
device_class = 'mobile tablet';
|
||||
break;
|
||||
case '2':
|
||||
if (device_class.match(/phone/)) return;
|
||||
device_class = 'mobile phone';
|
||||
break;
|
||||
default:
|
||||
if (device_class == 'desktop') return;
|
||||
device_class = 'desktop';
|
||||
}
|
||||
|
||||
var accessKey = linkEl.getAttribute('accesskey') || '';
|
||||
if (accessKey) return accessKey.trim().toUpperCase();
|
||||
jQuery('html').removeClass(device_classes).addClass(device_class);
|
||||
|
||||
return '';
|
||||
}
|
||||
// handle some layout changes based on change in device
|
||||
var $handle = jQuery('#dokuwiki__aside h3.toggle');
|
||||
var $toc = jQuery('#dw__toc h3');
|
||||
|
||||
function prependHotkey(linkEl, hotkey) {
|
||||
if (!hotkey) return;
|
||||
if (linkEl.querySelector('.luxtools__hotkey')) return;
|
||||
if (device_class == 'desktop') {
|
||||
// reset for desktop mode
|
||||
if($handle.length) {
|
||||
$handle[0].setState(1);
|
||||
$handle.hide();
|
||||
}
|
||||
if($toc.length) {
|
||||
$toc[0].setState(1);
|
||||
}
|
||||
}
|
||||
if (device_class.match(/mobile/)){
|
||||
// toc and sidebar hiding
|
||||
if($handle.length) {
|
||||
$handle.show();
|
||||
$handle[0].setState(-1);
|
||||
}
|
||||
if($toc.length) {
|
||||
$toc[0].setState(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var label = (linkEl.textContent || '').trim();
|
||||
if (!label) return;
|
||||
jQuery(function(){
|
||||
var resizeTimer;
|
||||
dw_page.makeToggle('#dokuwiki__aside h3.toggle','#dokuwiki__aside div.content');
|
||||
|
||||
linkEl.textContent = '';
|
||||
tpl_dokuwiki_mobile();
|
||||
jQuery(window).on('resize',
|
||||
function(){
|
||||
if (resizeTimer) clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(tpl_dokuwiki_mobile,200);
|
||||
}
|
||||
);
|
||||
|
||||
var span = document.createElement('span');
|
||||
span.className = 'luxtools__hotkey red-168-text';
|
||||
span.textContent = hotkey;
|
||||
// increase sidebar length to match content (desktop mode only)
|
||||
var sidebar_height = jQuery('.desktop #dokuwiki__aside').height();
|
||||
var pagetool_height = jQuery('.desktop #dokuwiki__pagetools ul:first').height();
|
||||
// pagetools div has no height; ul has a height
|
||||
var content_min = Math.max(sidebar_height || 0, pagetool_height || 0);
|
||||
|
||||
linkEl.appendChild(span);
|
||||
linkEl.appendChild(document.createTextNode(' ' + label));
|
||||
}
|
||||
var content_height = jQuery('#dokuwiki__content div.page').height();
|
||||
if(content_min && content_min > content_height) {
|
||||
var $content = jQuery('#dokuwiki__content div.page');
|
||||
$content.css('min-height', content_min);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var pagetools = document.getElementById('dokuwiki__pagetools');
|
||||
if (!pagetools) return;
|
||||
|
||||
var links = pagetools.querySelectorAll('a');
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
var hotkey = extractHotkey(links[i]);
|
||||
if (!hotkey) continue;
|
||||
prependHotkey(links[i], hotkey);
|
||||
}
|
||||
});
|
||||
})();
|
||||
// blur when clicked
|
||||
jQuery('#dokuwiki__pagetools div.tools>ul>li>a').on('click', function(){
|
||||
this.blur();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user