Skip to content

Instantly share code, notes, and snippets.

@frah
Forked from onozaty/gist:a684d5e8087f03bc20c6
Last active January 20, 2017 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frah/5a91b2feb5a511608eecc30d9ac79297 to your computer and use it in GitHub Desktop.
Save frah/5a91b2feb5a511608eecc30d9ac79297 to your computer and use it in GitHub Desktop.
Better checkbox field by Redmine view customize plugin(トラッカー変更対応版)
// Path pattern: /issues/
// Type : JavaScript
$(function() {
var ec_observer = new MutationObserver(function() {enhance_checkbox()});
var ec_target = document.getElementById('all_attributes');
ec_observer.observe(ec_target, { attributes: false, childList: true, characterData: false });
function enhance_checkbox() {
$('.check_box_group')
.each(function() {
var checkBoxGroup = $(this);
checkBoxGroup.hide();
var checkedValueLine =
$('<span>')
.insertBefore(checkBoxGroup)
.text(collectCheckedValues(checkBoxGroup));
$('<a href="#"><img alt="Edit" src="/images/edit.png" style="vertical-align: middle"></a>')
.insertAfter(checkedValueLine)
.on('click', function() {
$(this).hide();
checkBoxGroup.show();
return false;
});
$('<input type="text">')
.prependTo(checkBoxGroup)
.on('keyup', function() {
var inputText = $(this).val();
checkBoxGroup.find('label')
.each(function() {
var label = $(this);
if (match(inputText, label.find('input').val())) {
label.show();
} else {
label.hide();
}
});
});
checkBoxGroup.on('change', function() {
checkedValueLine.text(collectCheckedValues(checkBoxGroup));
});
});
}
function collectCheckedValues(target) {
return target.find(':checked')
.map(function() { return $(this).val(); })
.get().join(', ') || '\u00a0';
}
function match(inputText, targetValue) {
return inputText == ''
|| targetValue.toLowerCase().indexOf(inputText.toLowerCase()) != -1;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment