-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feature/59 create with html element instead of id only #697
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
Open
bilal-elchami
wants to merge
24
commits into
mebjas:master
Choose a base branch
from
bilal-elchami:feature/59_Create_With_HTML_Element_Instead_Of_Id
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c667224
Send HTML Element instead of Id to scanner
bilal-elchami dcabcdc
Add backward compatibility
bilal-elchami 6bb601f
Rename variables & format documents
bilal-elchami 006e728
Remove unused var & format documents
bilal-elchami 73d0ebf
Merge branch 'master' into feature/59_Create_With_HTML_Element_Instea…
bilal-elchami 2d937ea
Update package-lock
bilal-elchami 891ce00
Add shadow dom example
bilal-elchami 240dcc8
Update Example & Documentation
bilal-elchami ddea928
Format example
bilal-elchami 735ef23
Revert 3rd party fix
bilal-elchami a70cd3a
Reduce constructor complexity & fix back quotes
bilal-elchami 133a752
Initialize the container in the constructor
bilal-elchami 2db7242
Replace single quotes with double quotes
bilal-elchami d987f39
Revert html5 example & upload new build
bilal-elchami 2c875e8
Merge branch 'master' into feature/59_Create_With_HTML_Element_Instea…
bilal-elchami 88b5a26
Remove manual scan call
bilal-elchami 1bad070
Merge branch 'master' into feature/59_Create_With_HTML_Element_Instea…
bilal-elchami 313e4cb
Revert minified and package lock files
bilal-elchami 33c3428
Update readmes
bilal-elchami df96228
Revert package lock and minified files
bilal-elchami 77c78b8
Fix Code Analyzer warning
bilal-elchami bcc6017
Merge branch 'master' into feature/59_Create_With_HTML_Element_Instea…
bilal-elchami f67598c
Merge latest master and fix test errors
bilal-elchami 5d80902
Fix readme table
bilal-elchami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,51 @@ | ||
# html5-qrcode with HTML Element | ||
|
||
## Include the js library in your project | ||
```html | ||
<script src="https://unpkg.com/html5-qrcode"></script> | ||
``` | ||
|
||
## Create the component in JavaScript | ||
```js | ||
class CustomComponent extends HTMLElement { | ||
constructor() { | ||
// Always call super first in constructor | ||
super(); | ||
|
||
// Create a shadow root | ||
const shadow = this.attachShadow({ mode: 'open' }); | ||
|
||
// Create elements | ||
const wrapper = document.createElement('div'); | ||
const title = document.createElement('h2'); | ||
title.innerText = 'HTML5 qr-code Scanner with shadow dom components'; | ||
const idReader = document.createElement('div'); | ||
idReader.className = 'qr-reader'; | ||
idReader.style.width = '500px'; | ||
wrapper.appendChild(title); | ||
wrapper.appendChild(idReader); | ||
// Attach the created elements to the shadow dom | ||
shadow.appendChild(wrapper); | ||
} | ||
} | ||
|
||
// Define the new element | ||
customElements.define('custom-component', CustomComponent); | ||
``` | ||
|
||
## Query an HTML element from DOM or Shadow DOM and pass it to the library | ||
|
||
```js | ||
const myCustomComponent = document.querySelector("custom-component"); | ||
const childComponentQrReaderElement = myCustomComponent.shadowRoot.querySelector("div.qr-reader"); | ||
const html5QrCodeScanner = new Html5QrcodeScanner(childComponentQrReaderElement, { | ||
fps: 10, | ||
qrbox: 250, | ||
}); | ||
html5QrCodeScanner.render(onScanSuccess); | ||
``` | ||
|
||
### Contributors | ||
| Name | Profile| | ||
| ----- | ------ | | ||
| Bilal EL CHAMI | [@bilal-elchami](https://github.com/bilal-elchami) | |
This file contains hidden or 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,67 @@ | ||
<html> | ||
|
||
<head> | ||
<title>Html-Qrcode Demo</title> | ||
|
||
<body> | ||
<h1>This is a Shadow Dom example</h1> | ||
<custom-component></custom-component> | ||
</body> | ||
<script src="/html5-qrcode.min.js"></script> | ||
<script> | ||
// Create a class for the element | ||
class CustomComponent extends HTMLElement { | ||
constructor() { | ||
// Always call super first in constructor | ||
super(); | ||
|
||
// Create a shadow root | ||
const shadow = this.attachShadow({ mode: 'open' }); | ||
|
||
// Create elements | ||
const wrapper = document.createElement('div'); | ||
const title = document.createElement('h2'); | ||
title.innerText = 'HTML5 qr-code Scanner with shadow dom components'; | ||
const idReader = document.createElement('div'); | ||
idReader.className = 'qr-reader'; | ||
idReader.style.width = '500px'; | ||
wrapper.appendChild(title); | ||
wrapper.appendChild(idReader); | ||
// Attach the created elements to the shadow dom | ||
shadow.appendChild(wrapper); | ||
} | ||
} | ||
|
||
// Define the new element | ||
customElements.define('custom-component', CustomComponent); | ||
|
||
function docReady(fn) { | ||
// see if DOM is already available | ||
if (document.readyState === "complete" | ||
|| document.readyState === "interactive") { | ||
// call on next available tick | ||
setTimeout(fn, 1); | ||
} else { | ||
document.addEventListener("DOMContentLoaded", fn); | ||
} | ||
} | ||
|
||
docReady(function () { | ||
var lastResult, countResults = 0; | ||
function onScanSuccess(decodedText, decodedResult) { | ||
if (decodedText !== lastResult) { | ||
++countResults; | ||
lastResult = decodedText; | ||
// Handle on success condition with the decoded message. | ||
console.log(`Scan result ${decodedText}`, decodedResult); | ||
} | ||
} | ||
const myCustomComponent = document.querySelector('custom-component'); | ||
const childComponentQrReaderElement = myCustomComponent.shadowRoot.querySelector('div.qr-reader') | ||
var html5QrCodeScanner = new Html5QrcodeScanner(childComponentQrReaderElement, { fps: 10, qrbox: 250 }); | ||
html5QrCodeScanner.render(onScanSuccess); | ||
}); | ||
</script> | ||
</head> | ||
|
||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.