From 80f31de88e86cab23e2bcefdc862ec8099c9bd17 Mon Sep 17 00:00:00 2001 From: Andrey Kuvshinov Date: Wed, 29 Apr 2020 17:57:55 +0300 Subject: [PATCH] add cookie in pdf file --- app/pub/scripts/anviewer.js | 71 ++++++++++++++++++++++++------------- app/views/anpdf2.phtml | 1 + app/views/layout.phtml | 2 +- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/app/pub/scripts/anviewer.js b/app/pub/scripts/anviewer.js index 2209340..6fe8e7b 100644 --- a/app/pub/scripts/anviewer.js +++ b/app/pub/scripts/anviewer.js @@ -1,10 +1,14 @@ var pdfjsLib = window['pdfjs-dist/build/pdf']; +var pdfcanvas = "the-canvas"; +var cnt = 100; + + function renderPage() { var el_title = document.getElementById('pdfprogress'); - + el_title.innerHTML = 'Идет подготовка страницы ...'; @@ -12,7 +16,7 @@ function renderPage() { // Using promise to fetch the page pdfDoc.getPage(pageNum).then(function(page) { - var canvas = document.getElementById('the-canvas'); + var canvas = document.getElementById(pdfcanvas); var context = canvas.getContext('2d'); //var viewport = page.getViewport({scale: scale}); var viewport = page.getViewport({scale: 1.5}); @@ -38,8 +42,7 @@ function renderPage() { pageNumPending = null; } - // document.getElementById('zoompdf').innerHTML = scale + 'x'; - el_title.innerHTML = 'Приятного чтения ↓'; + el_title.innerHTML = 'Приятного чтения ↓'; }); }); @@ -79,25 +82,33 @@ function pdfzoomout(){ } -var cnt = 100; function resize_plus(){ - var div = document.getElementById("the-canvas"); - cnt += 4; - div.style.width = cnt+"%"; - setzoom(cnt); + cnt += 4; + newpdfzoom(cnt); } -function resize_minus(){ - var div = document.getElementById("the-canvas"); + + +function resize_minus(){ cnt -= 4; - div.style.width = cnt+"%"; - setzoom(cnt); + newpdfzoom(cnt); } +function newpdfzoom(czoom){ + + var status = czoom+"%"; + + document.getElementById(pdfcanvas).style.width = status; + document.getElementById('zoomstatus').innerHTML = status; -function getzoom(){ + setzoom('pdfscale', czoom); - var name = 'pdfscale'; - +} + + + +function getzoom( name ){ + + var results = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' ); if ( results ){ @@ -109,9 +120,7 @@ function getzoom(){ } -function setzoom( cvalue, exdays = 30 ) { - - var cname = 'pdfscale'; +function setzoom( cname, cvalue, exdays = 30 ) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); @@ -123,16 +132,28 @@ function setzoom( cvalue, exdays = 30 ) { } -function startpdfviewer(){ - var div = document.getElementById("the-canvas"); - czoom = getzoom(); - if (czoom != null & czoom > 10) { - div.style.width = czoom+"%" +function startpdfviewer(newpdf){ - } + var div = document.getElementById(pdfcanvas); + + + currpdf = getzoom('currpdf'); + + if (currpdf !== null & currpdf !== newpdf){ + + czoom = getzoom('pdfscale'); + + if (czoom != null & czoom > 10) { + newpdfzoom(czoom); + } + + } + else { + setzoom('currpdf', newpdf); + } pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) { diff --git a/app/views/anpdf2.phtml b/app/views/anpdf2.phtml index 227bd24..5b1466d 100644 --- a/app/views/anpdf2.phtml +++ b/app/views/anpdf2.phtml @@ -25,6 +25,7 @@
+
+
100%
diff --git a/app/views/layout.phtml b/app/views/layout.phtml index ee4f62f..79abb35 100644 --- a/app/views/layout.phtml +++ b/app/views/layout.phtml @@ -2,7 +2,7 @@ Еженедельник Аргументы Недели - <?=$title?> - +