feat(problemset): replace semantic-ui dropdown with native select for hardness filter
- Replace custom semantic-ui dropdown component with standard HTML select element - Simplify JavaScript by using native event listener instead of semantic-ui dropdown API - Remove unnecessary dropdown initialization and selection setting code - Maintain same functionality while reducing complexity and dependency on semantic-ui
This commit is contained in:
@@ -108,39 +108,31 @@
|
||||
$selected_hardness = 0;
|
||||
}
|
||||
?>
|
||||
<div class="ui selection dropdown" id="hardness_dropdown" style="width: 120px; height: 28px; margin-left: 10px; vertical-align: middle;">
|
||||
<input type="hidden" id="hardness_value" value="<?php echo $selected_hardness; ?>">
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">难度</div>
|
||||
<div class="menu">
|
||||
<div class="item" data-value="0">全部难度</div>
|
||||
<?php for ($h = 1; $h <= 8; $h++) {
|
||||
echo '<div class="item" data-value="' . $h . '">难度 ' . $h . '</div>';
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
<select id="hardness_select" class="ui dropdown" style="width: 120px; height: 28px; margin-left: 10px; vertical-align: middle;">
|
||||
<option value="0" <?php if ($selected_hardness == 0)
|
||||
echo 'selected'; ?>>全部难度</option>
|
||||
<?php for ($h = 1; $h <= 8; $h++) {
|
||||
echo '<option value="' . $h . '"' . ($selected_hardness == $h ? ' selected' : '') . '>难度 ' . $h . '</option>';
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
$('#hardness_dropdown').dropdown({
|
||||
onChange: function (value) {
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
if (value == '0' || value === '') {
|
||||
params.delete('hardness');
|
||||
} else {
|
||||
params.set('hardness', value);
|
||||
}
|
||||
params.delete('page');
|
||||
window.location.href = '?' + params.toString();
|
||||
document.getElementById('hardness_select').addEventListener('change', function () {
|
||||
var value = this.value;
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
if (value == '0' || value === '') {
|
||||
params.delete('hardness');
|
||||
} else {
|
||||
params.set('hardness', value);
|
||||
}
|
||||
params.delete('page');
|
||||
var query = params.toString();
|
||||
window.location.href = query ? ('?' + query) : window.location.pathname;
|
||||
});
|
||||
var hv = $('#hardness_value').val();
|
||||
if (hv && hv !== '0') {
|
||||
$('#hardness_dropdown').dropdown('set selected', hv);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user