123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 'use strict';
- (function(){
- var lowercase = function(string){return (typeof string === 'string') ? string.toLowerCase() : string;};
- function toBoolean(value) {
- if (typeof value === 'function') {
- value = true;
- } else if (value && value.length !== 0) {
- var v = lowercase('' + value);
- value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
- } else {
- value = false;
- }
- return value;
- }
- var AngularPrint = angular.module('AngularPrint',[]);
- AngularPrint.directive('printSection', function(){
- return {
- restrict: 'A',
- link: function(scope, element){
- element[0].classList.add('printSection');
- }
- };
- });
- AngularPrint.directive('printHide', function(){
- return {
- restrict: 'A',
- link: function(scope, element){
- element[0].classList.add('printHide');
- }
- };
- });
- AngularPrint.directive('printRemove', function(){
- return {
- restrict: 'A',
- link: function(scope, element){
- element[0].classList.add('printRemove');
- }
- };
- });
- AngularPrint.directive('printOnly', function(){
- return {
- restrict: 'A',
- link: {
- post: function(scope, element){
- element[0].classList.add('printOnly');
- }
- }
- };
- });
- AngularPrint.directive('printAvoidBreak', function(){
- return {
- restrict: 'A',
- link: function(scope, element){
- element[0].classList.add('avoidPageBreak');
- }
- };
- });
- AngularPrint.directive('printBtn',['$window', function($window){
- return {
- restrict: 'A',
- link: function($scope, element){
- element.on('click', function(){
- element[0].classList.add('avoidPageBreak');
- if($scope.printrequest){
- $window.print();
- }else{
- var sle = JSON.stringify($scope.selected);
- localStorage.setItem("key",sle)
- var printContents = document.querySelector('.qrcanvasfloat').innerHTML;
- var popupWin = window.open('', '_blank', 'width=630,height=891');
- popupWin.document.open();
- popupWin.document.write('<head><link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css"><link rel="stylesheet" href="assets/css/styles.css"></head><script src="../bower_components/angular/angular.min.js"></script><script src="../bower_components/jquery/dist/jquery.min.js"></script><script src="assets/js/controllers/qrgen.js"></script><script>var app = angular.module("myApp", []);app.controller("myCtrl", function($scope) {$scope.selected=JSON.parse(window.localStorage.getItem("key"));$(".qrcanvas").empty();angular.forEach($scope.selected.items,function(item){function $(selector) {return document.querySelector(selector);};$scope.q= $(".qrcanvas");var canvas;var colorIn = "#000000";var colorOut = "#000000";var colorFore = "#000000";var colorBack = "#ffffff";var options = {cellSize: 4,foreground: [{style: colorFore},{row: 0, rows: 7, col: 0, cols: 7, style: colorOut},{row: -7, rows: 7, col: 0, cols: 7, style: colorOut},{row: 0, rows: 7, col: -7, cols: 7, style: colorOut},{row: 2, rows: 3, col: 2, cols: 3, style: colorIn},{row: -5, rows: 3, col: 2, cols: 3, style: colorIn},{row: 2, rows: 3, col: -5, cols: 3, style: colorIn},],background: colorBack,data: item.uuid,typeNumber: 1,};var effect = "none";if (effect !== "none") {options.effect = {key: effect, value: 1};if (effect === "image") {options.background = [colorBack, effectImg];}};options.reuseCanvas = canvas;canvas = qrgen.canvas(options);$scope.q.appendChild(canvas);});$("canvas").addClass("canvasclass")})</script><body onload="window.print()"><div ng-app="myApp" ng-controller="myCtrl" class="qrcanvas"></div>'+printContents+'<div ng-app="myApp" ng-controller="myCtrl"></div></body>');
- popupWin.document.close();
- }
- });
- }
- };
- }]);
- AngularPrint.directive('printIf', ['$animate', function($animate) {
- return function(scope, element, attr) {
- scope.$watch(attr.printIf, function applyPrint(value){
- if('printOnly' in attr){
- $animate[toBoolean(value) ? 'removeClass' : 'addClass'](element, 'printRemove');
- }
- else{
- $animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'printSection');
- }
- });
- };
- }]);
- AngularPrint.directive('printLandscape',function(){
- return {
- restrict: 'A',
- link: function(){
- var sheet = (function() {
- var style = document.createElement('style');
- style.appendChild(document.createTextNode(''));
- document.head.appendChild(style);
- return style.sheet;
- })();
- sheet.insertRule('@page{size:landscape;}', 0);
- }
- };
- });
- AngularPrint.directive('printTable', function(){
- return function(scope, element, attr) {
- scope.$watch(attr.printTable, function makeTable(value){
- setTimeout(function(){
- if(value == null) return;
- var elem = element[0];
- elem.classList.add('printSection');
- elem.id = 'print-table';
- var tds = elem.getElementsByTagName('h1');
- for(var i = 0, content, div; i < tds.length; i++){
- content = tds[i].innerHTML;
- tds[i].innerHTML = '';
- div = document.createElement('div');
- div.className = 'avoidPageBreak';
- div.innerHTML = content;
- tds[i].appendChild(div);
- }
- element[0] = elem;
- },1000);
- });
- };
- });
- })();
|