generator.js
Members
- markerReady :
boolean markerReady - Flag indicating if the marker images (
marker0andmarker1) are loaded and are ready to use / download.- qrUrl :
string qrUrl - The full URL of the QR-Code (
baseUrl+ URL extension).- downloadReady :
boolean downloadReady - Flag indicating if the
qrImimage is loaded and ready to use / download.
Constants
- xmlIn :
HTMLElement The input element for the eScriptorium XML file.
- rmXmlBtn :
HTMLElement The button to remove the uploaded eScriptorium XML file.
- dlMarkerBtn :
HTMLElement The button to download both marker as a png file.
- dlQrBtn :
HTMLElement The button to download the QR-Code as a png file.
- dlPdfBtn :
HTMLElement The button to download both marker andQR-code as a single pdf file.
- shortenBtn :
HTMLElement The button to shorten the URL to makethe QR-Code more readable.
- canvas :
HTMLCanvasElement The canvas element to draw the marker and QR-Code to.
- ctx :
CanvasRenderingContext2D The rendering context of the canvas.
- trisIn :
HTMLElement The input element for the Trismegistos identifier.
- marker0 :
HTMLImageElement Image of the marker with value 0.
- marker1 :
HTMLImageElement Image of the marker with value 1.
- canvas0 :
HTMLCanvasElement Internal canvas for image manipulation.
- ctx0 :
CanvasRenderingContext2D Rendering context of the internal canvas.
- qrIm :
HTMLImageElement Image of the QR-Code.
- baseUrl :
string Base URL for generating the QR-Codes.
- xmlList :
function Event listener that binds the
xmlIninput change event tothegenerateWithXMLfunction.- xmlRem :
function Event listener that binds the remove eScriptorium XML button click event to the
removeXmlfunction.- trisLis :
function Event listener that binds the Trismegistos input event to the
generateWithTrisfunction.- resizeLis :
function Event listener that binds the window resize event to the
onResizefunction.- shortenList :
function Event listener that binds the
shortenBtnbutton onclick event totheshortenUrlfunction.- dlMarkerList :
function Event listener that binds the
dlMarkerBtnbutton onclick event tothedownloadMarkerfunction.- dlQrList :
function Event listener that binds the
dlQrBtnbutton onclick event tothedownloadQRfunction.- dlPdfList :
function Event listener that binds the
dlPdfBtnbutton onclick event tothedownloadPdffunction.
Functions
- removeXml() ⇒
void This function removes the uploaded eScriptorium XML from the
xmlInand hides thermXmlBtn. It also resets thetrisIn, such that the Trismegistos input can be used again.The function is called automatically by the onclick event listener of thermXmlBtn.- onResize() ⇒
void This function resizes the
canvasand redraws the images to fit the currentwindowsize. The function prevents thecanvasfrom getting tobig / small when resizing thewindow.The function is called automatically by the resize event listener of thewindow.- shortenUrl() ⇒
void This function uses the URL shortener spoo.me to shorten the URL and generatea new QR-Code with the new URL. The function is called automatically by the onclick event listener of the
shortenBtn. Because this service is not provided by us and has an API limit of 5 calls per minute (50 per hour), it might happen, that this process fails. In this case, the function logs the error to the console, alerts the user and keeps the old QR-Code.More information on spoo.me can be found here:https://github.com/spoo-me/url-shortener
- generateWithTris() ⇒
void This function generates the QR-Code using the Trismegistos input (
trisIn)and draws the QR-Code to the canvas.The function is called automatically by the input event listener ofthetrisIninput.xmlIn, if present, will always get prioritized. In this case, this function will just clear the value oftrisInon input. If thetrisIninput is cleared by the user, this function will set thedownloadReadyflag tofalseand callonResizeto clear the current QR-Code.- generateWithXML() ⇒
void This function generates the QR-Code using a the eScriptorium XML providedby the user through
xmlIn. The function will reset thetrisIninput.After that, it parses the file and gathers the neededinformation to construct the URL. The URL is then used to generate theQR-Code and draw it to the canvas.The function is called automatically by the onchange event listener ofxmlIn.If there is no file present, the function will callremoveXml. This isdone, such that the Trismegistos input is enabled again after the usercancels a XML selection.- stringToNumberArray(str) ⇒
Array.<number> This function converts a space-separated string into an array of numbers.
- drawQR(url) ⇒
void This function takes a URL as string and creates a QR-Code with the givenURL. It saves this QR-Code to the
qrImand draws it to thecanvas.If the marker are not ready yet, this will do nothing, so thefunction should always be called after loading the marker images.The function uses theQRCodeStylingfunction of the qr-code-styling framework.For more information on the framework look at:https://github.com/kozakdenys/qr-code-styling
- downloadMarker() ⇒
void This function downloads the marker images as PNG files, if the
markerReadyflag is set totrue.The function is called automatically by the onclick event listener of thedlMarkerBtn.- downloadQR() ⇒
void This function downloads the QR-Code image as a PNG file, if the
downloadReadyflag is set totrue.The function is called automatically by the onclick event listener of thedlQrBtn.- downloadPdf() ⇒
void This function downloads both marker images and the QR-Code image as a single PDF file, if
downloadReadyandmarkerReadyare both set totrue. It uses the jspdf framework.The function is called automatically by the onclick event listener of thedlPdfBtn.For more information on the framework look at:https://github.com/parallax/jsPDF
markerReady : boolean
markerReady - Flag indicating if the marker images (marker0 and marker1) are loaded and are ready to use / download.
Kind: global variable
qrUrl : string
qrUrl - The full URL of the QR-Code (baseUrl + URL extension).
Kind: global variable
downloadReady : boolean
downloadReady - Flag indicating if the qrIm image is loaded and ready to use / download.
Kind: global variable
xmlIn : HTMLElement
The input element for the eScriptorium XML file.
Kind: global constant
rmXmlBtn : HTMLElement
The button to remove the uploaded eScriptorium XML file.
Kind: global constant
dlMarkerBtn : HTMLElement
The button to download both marker as a png file.
Kind: global constant
dlQrBtn : HTMLElement
The button to download the QR-Code as a png file.
Kind: global constant
dlPdfBtn : HTMLElement
The button to download both marker and QR-code as a single pdf file.
Kind: global constant
shortenBtn : HTMLElement
The button to shorten the URL to make the QR-Code more readable.
Kind: global constant
canvas : HTMLCanvasElement
The canvas element to draw the marker and QR-Code to.
Kind: global constant
ctx : CanvasRenderingContext2D
The rendering context of the canvas.
Kind: global constant
trisIn : HTMLElement
The input element for the Trismegistos identifier.
Kind: global constant
marker0 : HTMLImageElement
Image of the marker with value 0.
Kind: global constant
marker1 : HTMLImageElement
Image of the marker with value 1.
Kind: global constant
canvas0 : HTMLCanvasElement
Internal canvas for image manipulation.
Kind: global constant
ctx0 : CanvasRenderingContext2D
Rendering context of the internal canvas.
Kind: global constant
qrIm : HTMLImageElement
Image of the QR-Code.
Kind: global constant
baseUrl : string
Base URL for generating the QR-Codes.
Kind: global constant
xmlList : function
Event listener that binds the xmlIn input change event to
the generateWithXML function.
Kind: global constant
xmlRem : function
Event listener that binds the remove eScriptorium XML
button click event to the removeXml function.
Kind: global constant
trisLis : function
Event listener that binds the Trismegistos input event to
the generateWithTris function.
Kind: global constant
resizeLis : function
Event listener that binds the window resize event to
the onResize function.
Kind: global constant
shortenList : function
Event listener that binds the shortenBtn button onclick event to
the shortenUrl function.
Kind: global constant
dlMarkerList : function
Event listener that binds the dlMarkerBtn button onclick event to
the downloadMarker function.
Kind: global constant
dlQrList : function
Event listener that binds the dlQrBtn button onclick event to
the downloadQR function.
Kind: global constant
dlPdfList : function
Event listener that binds the dlPdfBtn button onclick event to
the downloadPdf function.
Kind: global constant
removeXml() ⇒ void
This function removes the uploaded eScriptorium XML from the xmlIn
and hides the rmXmlBtn. It also resets the trisIn, such that the
Trismegistos input can be used again.
The function is called automatically by the onclick event listener of
the rmXmlBtn.
Kind: global function
Returns: void - This function does not return anything.
onResize() ⇒ void
This function resizes the canvas and redraws the images to fit the
current window size. The function prevents the canvas from getting to
big / small when resizing the window.
The function is called automatically by the resize event listener
of the window.
Kind: global function
Returns: void - This function does not return anything.
shortenUrl() ⇒ void
This function uses the URL shortener spoo.me to shorten the URL and generate
a new QR-Code with the new URL. The function is called automatically by the
onclick event listener of the shortenBtn.
Because this service is not provided by us and has an API limit of 5 calls
per minute (50 per hour), it might happen, that this process fails. In this
case, the function logs the error to the console, alerts the user and keeps
the old QR-Code.
More information on spoo.me can be found here: https://github.com/spoo-me/url-shortener
Kind: global function
Returns: void - This function does not return anything.
generateWithTris() ⇒ void
This function generates the QR-Code using the Trismegistos input (trisIn)
and draws the QR-Code to the canvas.
The function is called automatically by the input event listener of
the trisIn input.
xmlIn, if present, will always get prioritized. In
this case, this function will just clear the value of trisIn on input. If
the trisIn input is cleared by the user, this function will set the
downloadReady flag to false and call onResize to clear the current
QR-Code.
Kind: global function
Returns: void - This function does not return anything.
generateWithXML() ⇒ void
This function generates the QR-Code using a the eScriptorium XML provided
by the user through xmlIn. The function will reset the trisIn input.
After that, it parses the file and gathers the needed
information to construct the URL. The URL is then used to generate the
QR-Code and draw it to the canvas.
The function is called automatically by the onchange event listener of
xmlIn.
If there is no file present, the function will call removeXml. This is
done, such that the Trismegistos input is enabled again after the user
cancels a XML selection.
Kind: global function
Returns: void - This function does not return anything.
stringToNumberArray(str) ⇒ Array.<number>
This function converts a space-separated string into an array of numbers.
Kind: global function
Returns: Array.<number> - - Array of numbers.
| Param | Type | Description |
|---|---|---|
| str | string | The string to convert. |
Example
stringToNumberArray("40 3 1 23");
// This will return [40, 3, 1, 23].
drawQR(url) ⇒ void
This function takes a URL as string and creates a QR-Code with the given
URL. It saves this QR-Code to the qrIm and draws it to the canvas.
If the marker are not ready yet, this will do nothing, so the
function should always be called after loading the marker images.
The function uses the QRCodeStyling function of the qr-code-styling
framework.
For more information on the framework look at: https://github.com/kozakdenys/qr-code-styling
Kind: global function
Returns: void - This function does not return anything.
| Param | Type | Description |
|---|---|---|
| url | string | The URL to generate a QR-Code for. |
downloadMarker() ⇒ void
This function downloads the marker images as PNG files, if the markerReady
flag is set to true.
The function is called automatically by the onclick event listener of the
dlMarkerBtn.
Kind: global function
Returns: void - This function does not return anything.
downloadQR() ⇒ void
This function downloads the QR-Code image as a PNG file, if the
downloadReady flag is set to true.
The function is called automatically by the onclick event listener of the
dlQrBtn.
Kind: global function
Returns: void - This function does not return anything.
downloadPdf() ⇒ void
This function downloads both marker images and the QR-Code image as a
single PDF file, if downloadReady and markerReady are both set to
true. It uses the jspdf framework.
The function is called automatically by the onclick event listener
of the dlPdfBtn.
For more information on the framework look at: https://github.com/parallax/jsPDF
Kind: global function
Returns: void - This function does not return anything.