Skip to content

Commit

Permalink
Fix PDF initial scale
Browse files Browse the repository at this point in the history
  • Loading branch information
loleg committed Dec 5, 2022
1 parent 44c3a9b commit e450915
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions dribdat/aggregation.py
Expand Up @@ -132,6 +132,8 @@ def SyncProjectData(project, data):
if 'image_url' in data and data['image_url'] and \
(not project.image_url):
project.image_url = data['image_url'][:2048]
if 'is_webembed' in data and data['is_webembed']:
project.is_webembed = True
project.update()
db.session.add(project)
db.session.commit()
Expand Down
27 changes: 26 additions & 1 deletion dribdat/static/js/render.js
Expand Up @@ -11,7 +11,7 @@ var pdfDoc = null,
pageNum = 1,
pageRendering = false,
pageNumPending = null,
scale = 0.8,
scale = 1.5,
canvas = $thecanvas[0],
ctx = canvas.getContext('2d');

Expand Down Expand Up @@ -106,6 +106,31 @@ function onGoPage() {
}
document.getElementById('go').addEventListener('click', onGoPage);

/**
* Displays next page.
function pdfViewZoomIn(ticks) {
let newScale = this.pdfViewer.currentScale;
do {
newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
newScale = Math.ceil(newScale * 10) / 10;
newScale = Math.min(MAX_SCALE, newScale);
} while (--ticks && newScale < MAX_SCALE);
this.pdfViewer.currentScaleValue = newScale;
}
document.getElementById('zoomIn').addEventListener('click', pdfViewZoomIn);
function pdfViewZoomOut(ticks) {
let newScale = this.pdfViewer.currentScale;
do {
newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
newScale = Math.floor(newScale * 10) / 10;
newScale = Math.max(MIN_SCALE, newScale);
} while (--ticks && newScale > MIN_SCALE);
this.pdfViewer.currentScaleValue = newScale;
}
document.getElementById('zoomIn').addEventListener('click', pdfViewZoomOut);
*/

/**
* Asynchronously downloads PDF.
*/
Expand Down
4 changes: 3 additions & 1 deletion dribdat/templates/public/project.html
Expand Up @@ -244,7 +244,9 @@ <h2>{{project.name}}</h2>
{{ project.webembed|safe }}
<div class="win-size-grip"></div>
</div>
<a href="{{ project.webpage_url }}" class="btn btn-small btn-default" target="_blank" rel="noopener noreferrer">&#x26F6; Open</a>
<a href="{{ project.webpage_url }}" class="btn btn-small btn-default"
target="_blank" rel="noopener noreferrer">
&#x26F6;&nbsp;&nbsp;Open&nbsp;fullscreen</a>
{% endif %}

{% if project.longtext %}
Expand Down
17 changes: 14 additions & 3 deletions dribdat/templates/render.html
Expand Up @@ -17,10 +17,21 @@
</head>
<body class="render" src="{{ render_src }}">

<div class="btn-group">
<button id="prev">&#9664;</button>
<div class="btn-group toolbar-pdf">
<button title="Previous" id="prev">&#9664;</button>
<button id="go"><span id="page_num"></span> / <span id="page_count"></span></button>
<button id="next">&#9654;</button>
<button title="Next" id="next">&#9654;</button>
<!--
<button title="Zoom Out" id="zoomOut"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-zoom-out" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zM13 6.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0z"/>
<path d="M10.344 11.742c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1 6.538 6.538 0 0 1-1.398 1.4z"/>
<path fill-rule="evenodd" d="M3 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5z"/>
</svg></button>
<button title="Zoom In" id="zoomIn"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-zoom-in" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zM13 6.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0z"/>
<path d="M10.344 11.742c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1 6.538 6.538 0 0 1-1.398 1.4z"/>
<path fill-rule="evenodd" d="M6.5 3a.5.5 0 0 1 .5.5V6h2.5a.5.5 0 0 1 0 1H7v2.5a.5.5 0 0 1-1 0V7H3.5a.5.5 0 0 1 0-1H6V3.5a.5.5 0 0 1 .5-.5z"/>
</svg></button>-->
</div>
<canvas id="canv"></canvas>

Expand Down
1 change: 1 addition & 0 deletions dribdat/user/models.py
Expand Up @@ -598,6 +598,7 @@ def data(self):
'score': self.score,
'phase': self.phase,
'is_challenge': self.is_challenge,
'is_webembed': self.is_webembed,
'progress': self.progress,
'summary': self.summary or '',
'hashtag': self.hashtag or '',
Expand Down

0 comments on commit e450915

Please sign in to comment.