-
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.
✨ Add "Toggle background" button to the
ql-qr-code
context menu
- Loading branch information
Showing
3 changed files
with
74 additions
and
9 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
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 |
---|---|---|
|
@@ -84,7 +84,7 @@ QrCode.setAttribute('qr-error-correction'); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
* @version 0.2.3 | ||
* @version 0.2.4 | ||
*/ | ||
QrCode.setMethod(async function introduced() { | ||
|
||
|
@@ -114,24 +114,40 @@ QrCode.setMethod(async function introduced() { | |
|
||
this.qr_options = qr_options; | ||
|
||
const qrCode = new QRCodeStyling(qr_options); | ||
|
||
qrCode.append(this); | ||
|
||
this.qr_code_instance = qrCode; | ||
this.recreateQrCode(); | ||
|
||
this.addEventListener('contextmenu', e => { | ||
this.showContextMenu(e); | ||
}); | ||
|
||
this.background_is_on = true; | ||
this.previous_background = null; | ||
}); | ||
|
||
/** | ||
* Force a download of the current QR code | ||
* Recreate the QR code | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.3 | ||
* @version 0.2.3 | ||
*/ | ||
QrCode.setMethod(function recreateQrCode(e) { | ||
|
||
Hawkejs.removeChildren(this); | ||
|
||
const qrCode = new QRCodeStyling(this.qr_options); | ||
qrCode.append(this); | ||
|
||
this.qr_code_instance = qrCode; | ||
}); | ||
|
||
/** | ||
* Force a download of the current QR code | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.3 | ||
* @version 0.2.4 | ||
*/ | ||
QrCode.setMethod(async function downloadAsFile(type, width, height, dot_color) { | ||
|
||
await hawkejs.require('qr-code-styling'); | ||
|
@@ -180,17 +196,62 @@ QrCode.setMethod(async function downloadAsFile(type, width, height, dot_color) { | |
instance.download(download_options); | ||
}); | ||
|
||
/** | ||
* Get the current toggle-background title | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.3 | ||
* @version 0.2.4 | ||
*/ | ||
QrCode.setMethod(function getToggleBackgroundTitle() { | ||
|
||
let result = 'Toggle background'; | ||
let color = this.qr_options?.backgroundOptions?.color; | ||
|
||
if (color) { | ||
result += ' (is now ' + color + ')'; | ||
} | ||
|
||
return result; | ||
}); | ||
|
||
/** | ||
* Show the context menu | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.3 | ||
* @version 0.2.3 | ||
* @version 0.2.4 | ||
*/ | ||
QrCode.setMethod(function showContextMenu(e) { | ||
|
||
let menu = this.createElement('he-context-menu'); | ||
|
||
menu.addEntry(this.getToggleBackgroundTitle(), () => { | ||
|
||
if (!this.qr_options) { | ||
this.qr_options = {}; | ||
} | ||
|
||
if (!this.qr_options.backgroundOptions) { | ||
this.qr_options.backgroundOptions = {}; | ||
} | ||
|
||
if (this.background_is_on) { | ||
// Remember the current background color | ||
this.previous_background = this.qr_options?.backgroundOptions?.color; | ||
|
||
// Set it to transparent | ||
this.qr_options.backgroundOptions.color = 'transparent'; | ||
|
||
this.background_is_on = false; | ||
} else { | ||
this.qr_options.backgroundOptions.color = this.previous_background; | ||
this.background_is_on = true; | ||
} | ||
|
||
this.recreateQrCode(); | ||
}); | ||
|
||
if (!this.qr_logo) { | ||
// Logos are somehow always drawn horribly | ||
// (They are included in the file with a set width & height, and then scaled, | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name" : "alchemy-shortlink", | ||
"description" : "A shortlink plugin for AlchemyMVC projects", | ||
"author" : "Jelle De Loecker <[email protected]>", | ||
"version" : "0.2.3", | ||
"version" : "0.2.4", | ||
"repository" : "11ways/alchemy-shortlink", | ||
"license" : "MIT", | ||
"keywords" : ["skeleton", "boilerplate", "alchemymvc"], | ||
|