-
-
Save frah/5a91b2feb5a511608eecc30d9ac79297 to your computer and use it in GitHub Desktop.
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