Forked from onozaty/gist:a684d5e8087f03bc20c6
Last active Jan 20, 2017
Better checkbox field by Redmine view customize plugin(トラッカー変更対応版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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