forked from django-cms/djangocms-versioning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Fabian Braun <[email protected]>
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
djangocms_versioning/static/djangocms_versioning/js/versioning.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(function() { | ||
var firstChecked, lastChecked; | ||
|
||
function handleVersionSelection(event) { | ||
if (firstChecked instanceof HTMLInputElement && firstChecked.checked) { | ||
firstChecked.checked = false; | ||
firstChecked.closest('tr').classList.remove('selected'); | ||
firstChecked = lastChecked; | ||
} | ||
if (event.target instanceof HTMLInputElement) { | ||
if (event.target.checked) { | ||
firstChecked = lastChecked; | ||
lastChecked = event.target; | ||
} else if (firstChecked === event.target) { | ||
firstChecked = null; | ||
} else { | ||
lastChecked = null; | ||
} | ||
} | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function(){ | ||
var selectedVersions = document.querySelectorAll('#result_list input[type="checkbox"].action-select'); | ||
var selectElement = document.querySelector('#changelist-form select[name="action"]'); | ||
if (selectElement instanceof HTMLSelectElement) { | ||
for (var i = 0; i < selectElement.options.length; i++) { | ||
if (selectElement.options[i].value && selectElement.options[i].value !== 'compare_versions') { | ||
// for future safety: do not restrict on two selected versions, since there might be other actions | ||
return; | ||
} | ||
} | ||
} | ||
selectedVersions.forEach(function(selectedVersion){ | ||
selectedVersion.addEventListener('change', handleVersionSelection); | ||
}); | ||
}); | ||
})(); |