passman/js/app/directives/qrreader.js
2016-10-12 20:16:37 +02:00

43 lines
No EOL
1 KiB
JavaScript

(function () {
'use strict';
/**
* @ngdoc directive
* @name passmanApp.directive:passwordGen
* @description
* # passwordGen
*/
angular.module('passmanApp').directive("qrread", ['$parse',
function ($parse) {
return {
scope: true,
link: function (scope, element, attributes) {
var invoker = $parse(attributes.onRead);
scope.imageData = null;
qrcode.callback = function (result) {
//console.log('QR callback:',result);
invoker(scope, {
qrdata: {
qrData: result,
image: scope.imageData
}
});
//element.val('');
};
element.bind("change", function (changeEvent) {
var reader = new FileReader(), file = changeEvent.target.files[0];
reader.readAsDataURL(file);
reader.onload = (function () {
return function (e) {
//gCtx.clearRect(0, 0, gCanvas.width, gCanvas.height);
scope.imageData = e.target.result;
qrcode.decode(e.target.result);
};
})(file);
});
}
};
}
]);
}());