-
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.
Use block to prevent global variables, add use strict (#27)
- Loading branch information
Showing
4 changed files
with
219 additions
and
214 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
78 changes: 41 additions & 37 deletions
78
django_admin_keyboard_shortcuts/static/admin/js/shortcuts_changeform.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 |
---|---|---|
@@ -1,42 +1,46 @@ | ||
let saveButton = null; | ||
let saveAndAddButton = null; | ||
let saveAndContinueButton = null; | ||
'use strict'; | ||
{ | ||
let saveButton = null; | ||
let saveAndAddButton = null; | ||
let saveAndContinueButton = null; | ||
let deleteButton = null; | ||
|
||
function setUpShortcuts() { | ||
saveButton = document.querySelector("input[name=_save]"); | ||
saveAndAddButton = document.querySelector("input[name=_addanother]"); | ||
saveAndContinueButton = document.querySelector("input[name=_continue]"); | ||
deleteButton = document.querySelector(".deletelink"); | ||
} | ||
function setUpShortcuts() { | ||
saveButton = document.querySelector("input[name=_save]"); | ||
saveAndAddButton = document.querySelector("input[name=_addanother]"); | ||
saveAndContinueButton = document.querySelector("input[name=_continue]"); | ||
deleteButton = document.querySelector(".deletelink"); | ||
} | ||
|
||
function handleKeyUp(event) { | ||
switch (event.code) { | ||
case "KeyS": | ||
if (event.altKey) { | ||
saveButton.click(); | ||
} | ||
break; | ||
case "KeyA": | ||
if (event.altKey) { | ||
saveAndAddButton.click(); | ||
} | ||
break; | ||
case "KeyC": | ||
if (event.altKey) { | ||
saveAndContinueButton.click(); | ||
} | ||
break; | ||
case "KeyD": | ||
if (event.altKey) { | ||
deleteButton.click(); | ||
} | ||
break; | ||
function handleKeyUp(event) { | ||
switch (event.code) { | ||
case "KeyS": | ||
if (event.altKey) { | ||
saveButton.click(); | ||
} | ||
break; | ||
case "KeyA": | ||
if (event.altKey) { | ||
saveAndAddButton.click(); | ||
} | ||
break; | ||
case "KeyC": | ||
if (event.altKey) { | ||
saveAndContinueButton.click(); | ||
} | ||
break; | ||
case "KeyD": | ||
if (event.altKey) { | ||
deleteButton.click(); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (document.readyState === "loading") { | ||
document.addEventListener("DOMContentLoaded", setUpShortcuts); | ||
} else { | ||
setUpShortcuts(); | ||
if (document.readyState === "loading") { | ||
document.addEventListener("DOMContentLoaded", setUpShortcuts); | ||
} else { | ||
setUpShortcuts(); | ||
} | ||
document.addEventListener("keyup", handleKeyUp); | ||
} | ||
document.addEventListener("keyup", handleKeyUp); |
Oops, something went wrong.