From e68e5cc849b625dccc38b903fd19e418d62d1c22 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 15:18:14 +0100 Subject: [PATCH] Split editable select code used for quota selection into a jquery plugin --- core/js/singleselect.js | 76 ++++ settings/css/settings.css | 1 - settings/js/users.js | 792 ++++++++++++++++------------------- settings/templates/users.php | 62 ++- settings/users.php | 1 + 5 files changed, 475 insertions(+), 457 deletions(-) create mode 100644 core/js/singleselect.js diff --git a/core/js/singleselect.js b/core/js/singleselect.js new file mode 100644 index 0000000000..1a018b7414 --- /dev/null +++ b/core/js/singleselect.js @@ -0,0 +1,76 @@ +(function ($) { + $.fn.singleSelect = function () { + return this.each(function (i, select) { + var input = $(''); + select = $(select); + input.css('position', 'absolute'); + input.css(select.offset()); + input.css({ + 'box-sizing': 'border-box', + '-moz-box-sizing': 'border-box', + 'margin': 0, + 'width': (select.width() - 5) + 'px', + 'height': (select.outerHeight() - 2) + 'px', + 'border': 'none', + 'box-shadow': 'none', + 'margin-top': '1px', + 'margin-left': '1px', + 'z-index': 1000 + }); + input.hide(); + $('body').append(input); + + select.on('change', function (event) { + var value = $(this).val(), + newAttr = $('option:selected', $(this)).attr('data-new'); + if (!(typeof newAttr !== 'undefined' && newAttr !== false)) { + input.hide(); + select.data('previous', value); + } else { + event.stopImmediatePropagation(); + input.show(); + select.css('background-color', 'white'); + input.focus(); + } + }); + + $(select).data('previous', $(select).val()); + + input.on('change', function () { + var value = $(this).val(); + if (value) { + select.children().attr('selected', null); + var existingOption = select.children().filter(function (i, option) { + return ($(option).val() == value); + }); + if (existingOption.length) { + existingOption.attr('selected', 'selected'); + } else { + var option = $('