dokuwiki-template-landing/assets/landing.js

247 lines
10 KiB
JavaScript

jQuery(function($) {
var mediaMgrInterval = null;
/**
* Edit form
*/
(function() {
var $wikibar = $('#wiki__editbar');
if(!$wikibar.length) return;
var $editButtons = $wikibar.find('.editButtons');
// toolbar with proper buttons
var $tb = $('#tool__bar').addClass("btn-group").attr("role", "group");
$tb.find('button').addClass('btn btn-default').attr("type","button");
$('#wiki__text').addClass("form-control");
// Make the textarea big when the screen is big
var wh = $(window).height();
if(wh > 500) {
$('#wiki__text').css({"height":wh*0.7});
}
// buttons in different colors
$btnCancel = $editButtons.find('button').addClass("btn btn-default");
$btnSave = $editButtons.find('#edbtn__save').removeClass('btn-default').addClass("btn-success");
$btnEdit = $editButtons.find('#edbtn__preview').removeClass('btn-default').addClass("btn-warning");
// full width comment input
$wikibar.find('#edit__summary').addClass("form-control");
// Infos and hints in colored boxes
$('.editBox .license').addClass("alert alert-warning");
$('.act-edit > .container > p').addClass("alert alert-info");
// Draft status with tick in green
$('.act-edit.mode_preview #draft__status').addClass("success");
/* when previewing, scroll to the page preview */
if($('.mode_preview').length) {
jQuery('html, body').animate({
scrollTop: $('#preview').position().top
}, 600);
}
})();
/**
* Login Form
*/
(function() {
$loginForm = $('#dw__login');
if(!$loginForm.length) return;
$loginContainer = $loginForm.parent().parent();
$loginContainer.find('.level1').addClass('alert alert-warning');
$loginContainer.find('form').addClass('form-horizontal');
$loginContainer.find('input[name=u], input[name=p]').addClass('form-control');
$loginContainer.find('form > div').addClass('row panel panel-default');
$loginContainer.find('form > div > fieldset').addClass('col-md-12 panel-body');
$loginContainer.find('form > div > fieldset legend').addClass('hid');
$loginContainer.find('form > div > p').addClass('col-md-12 panel-footer');
$btnLogin = $loginContainer.find('button[type=submit]').addClass("btn btn-primary");
})();
/**
* Profile
*/
(function() {
var $profileForm = $('#dw__register');
if(!$profileForm.length) return;
$profileContainer = $profileForm.parent().parent();
$registerContainer = $profileForm;
$registerContainer.find('input[type=text], input[type=password], input[type=email]').addClass('form-control');
$registerContainer.find('button[type=submit]').addClass('btn btn-primary');
//$('#dw__register').addClass('panel');
$deleteContainer = $profileContainer.find('#dw__profiledelete');
$deleteContainer.addClass('panel alert alert-danger');
$deleteContainer.find('button').addClass('btn-danger');
//$profileContainer.find('button[type=reset]').addClass('btn btn-default');
})();
/**
* Admin Config Manager
*/
(function() {
$adminConfigHeadline = $('#config__manager');
if(!$adminConfigHeadline.length) return;
function enableAdvancedLevel($form, level) {
var $allPreferences = $form.find('td.label');
var $disabledElements = $allPreferences.filter(function(i, col) {
$(col).parent().show();
hide = false;
if($(col).find('img[alt=warning]').length) {
$(col).parent().addClass('config-advanced');
hide = level < 2;
}
if($(col).find('img[alt=danger]').length) {
$(col).parent().addClass('config-expert');
hide = level < 3;
};
return hide;
});
$disabledElements.map(function(i, col) {
$(col).parent().hide();
});
}
$adminConfigContainer = $adminConfigHeadline.parent();
$adminConfigContainer.find('input[type=text], input[type=password], input[type=email], select').addClass('form-control');
$adminConfigContainer.find('button[type=submit]').addClass('btn btn-primary');
$adminConfigContainer.find('td .outkey').removeClass('outkey').addClass('help-block');
// idea: all settings with warnings are advanced. switch
$configForm = $('#dw__configform');
$advancedButtons = $('<div class="btn-group btn-group-justified" id="switch-advanced"></div>');
$advancedButtons.append('<div class="btn-group"><button type="button" class="btn btn-success" id="switch-advanced-basic">Basic</button></div>');
$advancedButtons.append('<div class="btn-group"><button type="button" class="btn btn-warning" id="switch-advanced-advanced">Advanced</button></div>');
$advancedButtons.append('<div class="btn-group"><button type="button" class="btn btn-danger" id="switch-advanced-expert">Expert</button></div>');
$advancedButtons.on('click', 'button', function(e) {
var level = 1;
var elem = e.target;
$(elem).removeClass('active');
switch(elem.id) {
case 'switch-advanced-basic':
$(elem).addClass('active');
level = 1;
break;
case 'switch-advanced-advanced':
$(elem).addClass('active');
level = 2;
break;
case 'switch-advanced-expert':
$(elem).addClass('active');
level = 3;
break;
}
enableAdvancedLevel($configForm, level);
});
$configForm.prepend($advancedButtons);
$('#switch-advanced-basic').click();
})();
/* Manage users */
(function() {
$adminUserManager = $('#user__manager');
if(!$adminUserManager.length) return;
$adminUserManager.find('input[type=text], input[type=password], input[type=email]').addClass('form-control');
$adminUserManager.find('button').addClass('btn btn-default');
$adminUserManager.find('table').addClass('table table-striped');
$adminUserManager.find('ul.notes').addClass('alert alert-info');
$adminUserManager.find('.import_users').addClass('panel alert alert-warning');
})();
/* Show revisions */
(function() {
$revisions = $('#page__revisions');
if(!$revisions.length) return;
var potentialCurrent = $revisions.find('.li').first();
if(potentialCurrent.html().trim().match(/\(current\)$/)) {
potentialCurrent.html(potentialCurrent.html().replace('(current)',''));
potentialCurrent.addClass('bg-success');
}
})();
/* Show recent */
(function() {
$revisions = $('#dw__recent');
if(!$revisions.length) return;
})();
/* Diff revisions */
(function() {
$diff = $('#differences');
if(!$diff.length) return;
$('.difflink').addClass('btn btn-primary');
$('select[name=difftype]').addClass('form-control');
$('.diffnav').addClass('btn-group');
$('.diffnav > a').addClass('btn btn-default').wrap('<div class="btn-group"></div>');
$('.diffnav > form').addClass('btn-group');
$('.diffnav > form select').addClass('form-control');
})();
/* Admin start page */
(function() {
$adminHeadline = $('#administration');
if(!$adminHeadline.length) return;
$adminStart = $adminHeadline.parent();
$adminStart.find('.admin_tasks, .admin_plugins').addClass('btn-group-vertical');
$adminStart.find('.admin_tasks li, .admin_plugins li').addClass('btn btn-default text-left');
$adminStart.addClass('row').find('> ul').addClass('col-md-12');
$adminStart.find('> a').attr('style', '').addClass('panel alert alert-danger');
$adminStart.find('#admin__version').addClass('panel alert alert-info col-md-12')
})();
(function() {
$resendpwForm = $('#dw__resendpwd');
if(!$resendpwForm.length) return;
$resendpw = $resendpwForm.parent().parent();
$resendpw.find('.centeralign').removeClass('centeralign').addClass('panel alert alert-info');
$resendpw.find('form input[name=login]').addClass('form-control');
$resendpw.find('button').addClass('btn btn-primary');
})();
(function() {
var $mediamanager = $('#mediamanager__page');
if(!$mediamanager.length) return;
// Couldn't find another way than to overload this function to fix the panel resize width issue.
// Copied from dokuwiki's media.js
// changed 99.9% to 99% to avoid flow into second row.
dw_mediamanager.update_resizable = function() {
var $resizables = dw_mediamanager.$resizables();
$resizables.resizable({
handles: (jQuery('html[dir=rtl]').length ? 'w' : 'e'),
resize: function (event, ui) {
var $page = $mediamanager;
var widthFull = $page.width();
var widthResizables = 0;
$resizables.each(function () {
widthResizables += jQuery(this).width();
});
var $filePanel = $page.find('div.panel.file');
// set max width of resizable column
var widthOtherResizable = widthResizables - jQuery(this).width();
var minWidthNonResizable = parseFloat($filePanel.css("min-width"));
var maxWidth = widthFull - (widthOtherResizable + minWidthNonResizable) - 1;
$resizables.resizable("option", "maxWidth", maxWidth);
// was: 99.9%
var relWidthNonResizable = 99 - (100 * widthResizables / widthFull);
$filePanel.width(relWidthNonResizable + '%');
dw_mediamanager.resize();
dw_mediamanager.opacity_slider();
dw_mediamanager.portions_slider();
}
});
dw_mediamanager.resize();
};
})();
});