2016-06-06 18:40:38 +03:00
|
|
|
/**
|
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2016, Bjoern Schiessle
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2016-06-22 14:44:33 +03:00
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
2016-06-06 18:40:38 +03:00
|
|
|
* License, or (at your opinion) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2016-06-09 22:46:30 +03:00
|
|
|
|
|
|
|
function setThemingValue(setting, value) {
|
2016-06-16 18:30:18 +03:00
|
|
|
OC.msg.startSaving('#theming_settings_msg');
|
2016-06-09 22:46:30 +03:00
|
|
|
$.post(
|
|
|
|
OC.generateUrl('/apps/theming/ajax/updateStylesheet'), {'setting' : setting, 'value' : value}
|
2016-06-16 18:30:18 +03:00
|
|
|
).done(function(response) {
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
|
|
|
}).fail(function(response) {
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
|
|
|
});
|
2016-06-09 22:46:30 +03:00
|
|
|
preview(setting, value);
|
|
|
|
}
|
|
|
|
|
2016-07-12 15:59:28 +03:00
|
|
|
function calculateLuminance(rgb) {
|
2016-07-15 15:45:05 +03:00
|
|
|
var hexValue = rgb.replace(/[^0-9A-Fa-f]/, '');
|
2016-07-12 15:59:28 +03:00
|
|
|
var r,g,b;
|
2016-07-15 15:45:05 +03:00
|
|
|
if (hexValue.length === 3) {
|
2016-07-12 15:59:28 +03:00
|
|
|
hexValue = hexValue[0] + hexValue[0] + hexValue[1] + hexValue[1] + hexValue[2] + hexValue[2];
|
|
|
|
}
|
2016-07-15 15:45:05 +03:00
|
|
|
if (hexValue.length !== 6) {
|
2016-07-12 15:59:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
r = parseInt(hexValue.substring(0,2), 16);
|
|
|
|
g = parseInt(hexValue.substring(2,4), 16);
|
|
|
|
b = parseInt(hexValue.substring(4,6), 16);
|
|
|
|
return (0.299*r + 0.587*g + 0.114*b)/255;
|
|
|
|
}
|
|
|
|
|
2016-07-25 18:32:11 +03:00
|
|
|
function generateRadioButton(color) {
|
|
|
|
var radioButton = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' +
|
|
|
|
'<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="' + color + '"/></svg>';
|
|
|
|
return btoa(radioButton);
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:46:30 +03:00
|
|
|
function preview(setting, value) {
|
|
|
|
if (setting === 'color') {
|
|
|
|
var headerClass = document.getElementById('header');
|
2016-07-12 15:59:28 +03:00
|
|
|
var expandDisplayNameClass = document.getElementById('expandDisplayName');
|
|
|
|
var headerAppName = headerClass.getElementsByClassName('header-appname')[0];
|
2016-07-27 21:03:53 +03:00
|
|
|
var textColor, icon;
|
2016-07-19 14:53:47 +03:00
|
|
|
var luminance = calculateLuminance(value);
|
|
|
|
var elementColor = value;
|
|
|
|
|
|
|
|
if (luminance > 0.5) {
|
2016-07-12 15:59:28 +03:00
|
|
|
textColor = "#000000";
|
|
|
|
icon = 'caret-dark';
|
|
|
|
} else {
|
|
|
|
textColor = "#ffffff";
|
|
|
|
icon = 'caret';
|
|
|
|
}
|
2016-07-19 14:53:47 +03:00
|
|
|
if (luminance>0.8) {
|
2016-07-25 17:44:56 +03:00
|
|
|
elementColor = '#555555';
|
2016-07-19 14:53:47 +03:00
|
|
|
}
|
2016-07-12 15:59:28 +03:00
|
|
|
|
2016-06-09 22:46:30 +03:00
|
|
|
headerClass.style.background = value;
|
|
|
|
headerClass.style.backgroundImage = '../img/logo-icon.svg';
|
2016-07-12 15:59:28 +03:00
|
|
|
expandDisplayNameClass.style.color = textColor;
|
|
|
|
headerAppName.style.color = textColor;
|
|
|
|
|
2016-07-19 14:53:47 +03:00
|
|
|
$('#previewStyles').html(
|
|
|
|
'#header .icon-caret { background-image: url(\'' + OC.getRootPath() + '/core/img/actions/' + icon + '.svg\') }' +
|
2016-07-25 18:32:11 +03:00
|
|
|
'input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' +
|
2016-07-25 17:44:56 +03:00
|
|
|
'background-image:url(\'' + OC.getRootPath() + '/core/img/actions/checkmark-white.svg\');' +
|
|
|
|
'background-color: ' + elementColor + '; background-position: center center; background-size:contain;' +
|
|
|
|
'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;}' +
|
2016-07-25 18:32:11 +03:00
|
|
|
'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' +
|
|
|
|
'background-image: url(\'data:image/svg+xml;base64,' + generateRadioButton(elementColor) + '\'); }'
|
2016-07-19 14:53:47 +03:00
|
|
|
);
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
if (setting === 'logoMime') {
|
|
|
|
console.log(setting);
|
2016-06-09 22:46:30 +03:00
|
|
|
var logos = document.getElementsByClassName('logo-icon');
|
2016-06-22 15:04:54 +03:00
|
|
|
var timestamp = new Date().getTime();
|
2016-07-15 15:45:05 +03:00
|
|
|
if (value !== '') {
|
2016-07-25 19:54:13 +03:00
|
|
|
logos[0].style.backgroundImage = "url('" + OC.generateUrl('/apps/theming/logo') + "?v" + timestamp + "')";
|
|
|
|
logos[0].style.backgroundSize = "contain";
|
2016-06-21 22:21:46 +03:00
|
|
|
} else {
|
2016-07-25 19:54:13 +03:00
|
|
|
logos[0].style.backgroundImage = "url('" + OC.getRootPath() + '/core/img/logo-icon.svg?v' + timestamp +"')";
|
|
|
|
logos[0].style.backgroundSize = "contain";
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2016-06-27 21:36:23 +03:00
|
|
|
$('#theming [data-toggle="tooltip"]').tooltip();
|
2016-06-09 22:46:30 +03:00
|
|
|
|
2016-07-19 14:53:47 +03:00
|
|
|
$('html > head').append($('<style type="text/css" id="previewStyles"></style>'));
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
var uploadParamsLogo = {
|
|
|
|
pasteZone: null,
|
2016-06-21 22:46:27 +03:00
|
|
|
dropZone: null,
|
2016-06-21 22:21:46 +03:00
|
|
|
done: function (e, response) {
|
|
|
|
preview('logoMime', response.result.data.name);
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response.result);
|
|
|
|
},
|
|
|
|
submit: function(e, response) {
|
|
|
|
OC.msg.startSaving('#theming_settings_msg');
|
|
|
|
},
|
|
|
|
fail: function (e, data){
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var uploadParamsLogin = {
|
2016-06-09 22:46:30 +03:00
|
|
|
pasteZone: null,
|
2016-06-21 22:46:27 +03:00
|
|
|
dropZone: null,
|
2016-06-16 18:30:18 +03:00
|
|
|
done: function (e, response) {
|
2016-06-21 22:21:46 +03:00
|
|
|
preview('backgroundMime', response.result.data.name);
|
2016-06-16 18:30:18 +03:00
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response.result);
|
2016-06-09 22:46:30 +03:00
|
|
|
},
|
2016-06-16 18:30:18 +03:00
|
|
|
submit: function(e, response) {
|
|
|
|
OC.msg.startSaving('#theming_settings_msg');
|
2016-06-09 22:46:30 +03:00
|
|
|
},
|
|
|
|
fail: function (e, data){
|
2016-06-16 18:30:18 +03:00
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
|
|
|
};
|
2016-06-22 14:44:33 +03:00
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
$('#uploadlogo').fileupload(uploadParamsLogo);
|
|
|
|
$('#upload-login-background').fileupload(uploadParamsLogin);
|
2016-06-09 22:46:30 +03:00
|
|
|
|
2016-06-27 21:46:12 +03:00
|
|
|
$('#theming-name').change(function(e) {
|
|
|
|
var el = $(this);
|
|
|
|
$.when(el.focusout()).then(function() {
|
|
|
|
setThemingValue('name', $(this).val());
|
|
|
|
});
|
2016-06-09 22:46:30 +03:00
|
|
|
if (e.keyCode == 13) {
|
|
|
|
setThemingValue('name', $(this).val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-27 21:46:12 +03:00
|
|
|
$('#theming-url').change(function(e) {
|
|
|
|
var el = $(this);
|
|
|
|
$.when(el.focusout()).then(function() {
|
|
|
|
setThemingValue('url', $(this).val());
|
|
|
|
});
|
2016-06-09 22:46:30 +03:00
|
|
|
if (e.keyCode == 13) {
|
|
|
|
setThemingValue('url', $(this).val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-27 21:46:12 +03:00
|
|
|
$('#theming-slogan').change(function(e) {
|
|
|
|
var el = $(this);
|
|
|
|
$.when(el.focusout()).then(function() {
|
|
|
|
setThemingValue('slogan', $(this).val());
|
|
|
|
});
|
2016-06-09 22:46:30 +03:00
|
|
|
if (e.keyCode == 13) {
|
|
|
|
setThemingValue('slogan', $(this).val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#theming-color').change(function (e) {
|
|
|
|
setThemingValue('color', '#' + $(this).val());
|
|
|
|
});
|
2016-06-22 14:44:33 +03:00
|
|
|
|
2016-06-09 22:46:30 +03:00
|
|
|
$('.theme-undo').click(function (e) {
|
|
|
|
var setting = $(this).data('setting');
|
2016-06-16 18:30:18 +03:00
|
|
|
OC.msg.startSaving('#theming_settings_msg');
|
2016-06-09 22:46:30 +03:00
|
|
|
$.post(
|
|
|
|
OC.generateUrl('/apps/theming/ajax/undoChanges'), {'setting' : setting}
|
2016-06-16 18:30:18 +03:00
|
|
|
).done(function(response) {
|
2016-06-09 22:46:30 +03:00
|
|
|
if (setting === 'color') {
|
|
|
|
var colorPicker = document.getElementById('theming-color');
|
2016-06-16 18:30:18 +03:00
|
|
|
colorPicker.style.backgroundColor = response.data.value;
|
|
|
|
colorPicker.value = response.data.value.slice(1);
|
2016-06-21 22:21:46 +03:00
|
|
|
} else if (setting !== 'logoMime' && setting !== 'backgroundMime') {
|
2016-06-09 22:46:30 +03:00
|
|
|
var input = document.getElementById('theming-'+setting);
|
2016-06-16 18:30:18 +03:00
|
|
|
input.value = response.data.value;
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
2016-06-16 18:30:18 +03:00
|
|
|
preview(setting, response.data.value);
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
2016-06-09 22:46:30 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|