-
Notifications
You must be signed in to change notification settings - Fork 0
Add QR Shortcode Type #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Handles QR animations for <qr-code> elements rendered by AnyS. | ||
| window.anys = window.anys || {}; | ||
| window.anys.shortcodes = window.anys.shortcodes || {}; | ||
|
|
||
| /** | ||
| * Controls QR animations for <qr-code> elements. | ||
| * | ||
| * @since NEXT | ||
| */ | ||
| class QRAnimator { | ||
| /** | ||
| * Constructor. | ||
| * | ||
| * @param {Object} options Optional configuration object. | ||
| * @param {string} [options.selector] CSS selector for QR elements. | ||
| * @param {string} [options.animationAttr] Data attribute that holds animation name. | ||
| * @param {string} [options.renderEvent] Event name fired when QR is rendered. | ||
| * @param {string} [options.animationMethod] Method name on element that triggers animation. | ||
| */ | ||
| constructor(options) { | ||
| this.settings = Object.assign( | ||
| { | ||
| selector: 'qr-code[data-anys-qr-animation]', | ||
| animationAttr: 'data-anys-qr-animation', | ||
| renderEvent: 'codeRendered', | ||
| animationMethod: 'animateQRCode', | ||
| }, | ||
| options || {} | ||
| ); | ||
|
|
||
| this.attachAll = this.attachAll.bind(this); | ||
| } | ||
|
|
||
| /** | ||
| * Initializes the animator on DOM ready. | ||
| */ | ||
| init() { | ||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', this.attachAll); | ||
| } else { | ||
| this.attachAll(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Attaches animation handlers to all matched elements. | ||
| */ | ||
| attachAll() { | ||
| var elements = document.querySelectorAll(this.settings.selector); | ||
|
|
||
| if (!elements.length) { | ||
| return; | ||
| } | ||
|
|
||
| elements.forEach((element) => { | ||
| this.attach(element); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Attaches animation handler to a single element. | ||
| * | ||
| * @param {HTMLElement} element The QR element. | ||
| */ | ||
| attach(element) { | ||
| if (!element) { | ||
| return; | ||
| } | ||
|
|
||
| var attrName = this.settings.animationAttr; | ||
| var animation = element.getAttribute(attrName); | ||
|
|
||
| if (!animation) { | ||
| return; | ||
| } | ||
|
|
||
| var eventName = this.settings.renderEvent; | ||
| var animationMethod = this.settings.animationMethod; | ||
|
|
||
| element.addEventListener( | ||
| eventName, | ||
| function () { | ||
| var animateFn = element[animationMethod]; | ||
|
|
||
| if (typeof animateFn !== 'function') { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| animateFn.call(element, animation); | ||
| } catch (error) { | ||
| // Intentionally ignores animation errors. | ||
| } | ||
| }, | ||
| { once: true } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Exposes class for external usage. | ||
| window.anys.shortcodes.QRAnimator = QRAnimator; | ||
|
|
||
| // Creates default singleton instance. | ||
| window.anys.shortcodes.qrAnimator = new window.anys.shortcodes.QRAnimator(); | ||
| window.anys.shortcodes.qrAnimator.init(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2019-2023 Jason Dreyzehner | ||
| Copyright (c) 2018 BitPay | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /*! Built with http://stenciljs.com */ | ||
| (function(namespace,resourcesUrl){"use strict"; | ||
|
|
||
| })("QrCode"); |
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.