1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-27 02:20:50 +12:00

another check for #1

This commit is contained in:
gorhill 2014-10-24 17:22:32 -04:00
parent 207ee2773b
commit 1743f198e5
2 changed files with 22 additions and 23 deletions

View file

@ -40,21 +40,21 @@ transparent 76%,transparent\
)'; )';
var updateSubframeDemo = function() { var updateSubframeDemo = function() {
var demo = $('#subframe-color-demo'); var demo = uDom('#subframe-color-demo');
var color = $('#subframe-color').val(); var color = uDom('#subframe-color').val();
demo.css('border-color', color); demo.css('border-color', color);
var re = new RegExp('\{\{color\}\}', 'g'); var re = new RegExp('\{\{color\}\}', 'g');
demo.css('background-image', subframeDemoBackgroundImage.replace(re, color)); demo.css('background-image', subframeDemoBackgroundImage.replace(re, color));
demo.css('opacity', (parseInt($('#subframe-opacity').val(), 10) / 100).toFixed(1)); demo.css('opacity', (parseInt(uDom('#subframe-opacity').val(), 10) / 100).toFixed(1));
}; };
var onSubframeColorChanged = function() { var onSubframeColorChanged = function() {
var color = $('#subframe-color').val(); var color = uDom('#subframe-color').val();
if ( color === '' ) { if ( color === '' ) {
$('#subframe-color').val(color); uDom('#subframe-color').val(color);
} }
changeUserSettings('subframeColor', color); changeUserSettings('subframeColor', color);
var opacity = parseInt($('#subframe-opacity').val(), 10); var opacity = parseInt(uDom('#subframe-opacity').val(), 10);
if ( Number.isNaN(opacity) ) { if ( Number.isNaN(opacity) ) {
opacity = 100; opacity = 100;
} }
@ -83,42 +83,42 @@ function prepareToDie() {
var installEventHandlers = function() { var installEventHandlers = function() {
// `data-range` allows to add/remove bool properties without // `data-range` allows to add/remove bool properties without
// changing code. // changing code.
$('input[data-range="bool"]').on('change', function() { uDom('input[data-range="bool"]').on('change', function() {
changeUserSettings(this.id, this.checked); changeUserSettings(this.id, this.checked);
}); });
$('input[name="displayTextSize"]').on('change', function(){ uDom('input[name="displayTextSize"]').on('change', function(){
changeUserSettings('displayTextSize', $(this).attr('value')); changeUserSettings('displayTextSize', this.value);
}); });
$('#smart-auto-reload').on('change', function(){ uDom('#smart-auto-reload').on('change', function(){
changeUserSettings('smartAutoReload', this.value); changeUserSettings('smartAutoReload', this.value);
}); });
$('#subframe-color').on('change', function(){ onSubframeColorChanged(); }); uDom('#subframe-color').on('change', function(){ onSubframeColorChanged(); });
$('#subframe-opacity').on('change', function(){ onSubframeColorChanged(); }); uDom('#subframe-opacity').on('change', function(){ onSubframeColorChanged(); });
// https://github.com/gorhill/httpswitchboard/issues/197 // https://github.com/gorhill/httpswitchboard/issues/197
$(window).one('beforeunload', prepareToDie); uDom(window).on('beforeunload', prepareToDie);
}; };
/******************************************************************************/ /******************************************************************************/
$(function() { uDom.onLoad(function() {
var onUserSettingsReceived = function(userSettings) { var onUserSettingsReceived = function(userSettings) {
// Cache copy // Cache copy
cachedUserSettings = userSettings; cachedUserSettings = userSettings;
// `data-range` allows to add/remove bool properties without // `data-range` allows to add/remove bool properties without
// changing code. // changing code.
$('input[data-range="bool"]').each(function() { uDom('input[data-range="bool"]').toArray().forEach(function(elem) {
this.checked = userSettings[this.id] === true; elem.checked = userSettings[elem.id] === true;
}); });
$('input[name="displayTextSize"]').attr('checked', function(){ uDom('input[name="displayTextSize"]').toArray().forEach(function(elem) {
return $(this).attr('value') === userSettings.displayTextSize; elem.checked = elem.value === userSettings.displayTextSize;
}); });
$('#smart-auto-reload').val(userSettings.smartAutoReload); uDom('#smart-auto-reload').val(userSettings.smartAutoReload);
$('#subframe-color').val(userSettings.subframeColor); uDom('#subframe-color').val(userSettings.subframeColor);
$('#subframe-opacity').val(userSettings.subframeOpacity); uDom('#subframe-opacity').val(userSettings.subframeOpacity);
updateSubframeDemo(); updateSubframeDemo();
installEventHandlers(); installEventHandlers();

View file

@ -66,7 +66,6 @@ ul > li {
</ul> </ul>
<script src="lib/jquery-2.min.js"></script>
<script src="js/udom.js"></script> <script src="js/udom.js"></script>
<script src="js/i18n.js"></script> <script src="js/i18n.js"></script>
<script src="js/dashboard-common.js"></script> <script src="js/dashboard-common.js"></script>