Skip to content

Commit

Permalink
fix issue when no src attr is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Makhov committed May 2, 2016
1 parent 1cb423e commit 0a08aae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
12 changes: 1 addition & 11 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,7 @@ <h3>Dynamically change PDF source</h3>
<template>
<paper-button raised id="one">PDF One</paper-button>
<paper-button raised id="another">PDF Two</paper-button>
<pdf-element id="pdf" show-spinner width=800 height=600></pdf-element>
<script>
window.onload = function() {
document.querySelector("#one").addEventListener("click", function() {
document.getElementById("pdf").setAttribute("src", "./pdf.pdf");
});
document.querySelector("#another").addEventListener("click", function() {
document.getElementById("pdf").setAttribute("src", "./example.pdf");
});
}
</script>
<pdf-element id="pdf" show-spinner width=800 height=600></pdf-element>
</template>
<script>
window.onload = function() {
Expand Down
19 changes: 9 additions & 10 deletions pdf-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
*/
src: {
type: String,
notify: true
notify: true,
observer: '_srcChanged'
},
/**
* The z-depth of this element, from 0-5. Setting to 0 will remove the shadow, and each increasing number greater than 0 will be "deeper" than the last.
Expand Down Expand Up @@ -200,15 +201,13 @@
this.fileName = this.src.split('/').pop();
this.currentPage = 1;
},
attributeChanged: function(attrName, oldVal, newVal) {
if (attrName == 'src' && newVal != '') {
if (typeof this.instance == 'undefined') this._initializeReader();
else {
this.instance.changePDFSource(newVal);
this.currentPage = 1;
this.totalPages = this.instance.totalPages;
this.fileName = this.src.split('/').pop();
}
_srcChanged: function(newVal) {
if (typeof this.instance == 'undefined') this._initializeReader();
else {
this.instance.changePDFSource(newVal);
this.currentPage = 1;
this.totalPages = this.instance.totalPages;
this.fileName = this.src.split('/').pop();
}
},
zoomIn: function() {
Expand Down

0 comments on commit 0a08aae

Please sign in to comment.