Skip to content

Commit

Permalink
Merge pull request #527 from trheyi/main
Browse files Browse the repository at this point in the history
[add] JavaScript code to prevent default save behavior in iframe
  • Loading branch information
trheyi authored Dec 14, 2023
2 parents e7d6cd4 + 37e4fde commit 0f828ff
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions sui/core/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,21 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) {
}

// Block save event
// jsCode := `
// console.log("hello ifrme")
// document.addEventListener('keydown', function (event) {
// const isCtrlOrCmdPressed = event.ctrlKey || event.metaKey;
// const isSPressed = event.key === 's';
// if (isCtrlOrCmdPressed && isSPressed) {
// event.preventDefault();
// console.log('Control/Command + S pressed in iframe! Default save behavior prevented.');
// }
// });
// `
// jsCode := ` console.log("hello ifrme")`
// doc.Find("body").AppendHtml(`<script language="javascript">` + jsCode + `</script>`)
res.HTML, err = doc.Find("body").Html()
jsCode := `
document.addEventListener('keydown', function (event) {
const isCtrlOrCmdPressed = event.ctrlKey || event.metaKey;
const isSPressed = event.key === 's';
if (isCtrlOrCmdPressed && isSPressed) {
event.preventDefault();
console.log('Control/Command + S pressed in iframe! Default save behavior prevented.');
}
});
`
doc.Find("body").AppendHtml(`<script type="text/javascript">` + jsCode + `</script>`)
res.HTML, err = doc.Html()
if err != nil {
return nil, err
}
// fmt.Println(res.HTML)

var data Data = nil
if page.Codes.DATA.Code != "" {
Expand Down

0 comments on commit 0f828ff

Please sign in to comment.