'use strict'; (function(definition) { if (typeof define === 'function' && define.amd) { define(['QRCode'], definition); } else if (typeof module === 'object' && module.exports) { var QRCode = require('qrjs'); module.exports = definition(QRCode); } else { definition(window.QRCode); } })(function(QRCode) { // // Prototype // var proto = Object.create(HTMLElement.prototype, { // // Attributes // attrs: { value: { data: null, format: 'png', modulesize: 5, margin: 4 } }, defineAttributes: { value: function () { var attrs = Object.keys(this.attrs), attr; for (var i=0; i' } } else { this.shadowRoot.innerHTML = '
qr-code: no data!
' } } }, generatePNG: { value: function () { try { var img = document.createElement('img'); img.src = QRCode.generatePNG(this.data, this.getOptions()); this.clear(); this.shadowRoot.appendChild(img); } catch (e) { this.shadowRoot.innerHTML = '
qr-code: no canvas support!
' } } }, generateHTML: { value: function () { var div = QRCode.generateHTML(this.data, this.getOptions()); this.clear(); this.shadowRoot.appendChild(div); } }, generateSVG: { value: function () { var div = QRCode.generateSVG(this.data, this.getOptions()); this.clear(); this.shadowRoot.appendChild(div); } }, clear: { value: function () { while (this.shadowRoot.lastChild) { this.shadowRoot.removeChild(this.shadowRoot.lastChild); } } } }); // // Register // document.registerElement('qr-code', { prototype: proto }); });