\n' +
@@ -445,6 +452,7 @@
onInit: '&',
onPageLoad: '&',
scale: '=?',
+ buttons: '=?'
},
link: function ($scope, $element, $attrs) {
$element.children().wrap('
');
@@ -513,21 +521,32 @@
}, function () {
if (!$attrs.src) return;
- if ($attrs.open === 'false') {
- document.getElementById('openFile').setAttribute('hidden', 'true');
- document.getElementById('secondaryOpenFile').setAttribute('hidden', 'true');
+ // Restored for backward compatibility
+ if ($attrs.open){
+ if(!$scope.buttons){
+ $scope.buttons = {};
+ }
+ $scope.buttons.openFile = ($attrs.open === 'true');
}
-
- if ($attrs.download === 'false') {
- document.getElementById('download').setAttribute('hidden', 'true');
- document.getElementById('secondaryDownload').setAttribute('hidden', 'true');
+
+ // Restored for backward compatibility
+ if ($attrs.download) {
+ if(!$scope.buttons){
+ $scope.buttons = {};
+ }
+ $scope.buttons.download = ($attrs.download === 'true');
}
- if ($attrs.print === 'false') {
- document.getElementById('print').setAttribute('hidden', 'true');
- document.getElementById('secondaryPrint').setAttribute('hidden', 'true');
+ // Restored for backward compatibility
+ if ($attrs.print) {
+ if(!$scope.buttons){
+ $scope.buttons = {};
+ }
+ $scope.buttons.print = ($attrs.print === 'true');
}
+ setButtonsVisibility(pdfjsViewerConfig.buttons, $scope.buttons);
+
if ($attrs.width) {
document.getElementById('outerContainer').style.width = $attrs.width;
}
@@ -542,5 +561,46 @@
};
}]);
+ function setButtonsVisibility(defaultButtons, customButtons) {
+
+ // Merge default provider's buttons and custom directive's buttons
+ var allButtons = angular.merge({}, defaultButtons, customButtons);
+ var key;
+ var keyValue;
+ var button;
+ var buttonSecond;
+
+ for (key in allButtons) {
+ keyValue = null;
+ if (allButtons && allButtons.hasOwnProperty(key)) {
+ keyValue = allButtons[key];
+ }
+ else {
+ // Default shows
+ keyValue = true;
+ }
+
+ button = document.getElementById(key);
+ if (button !== null) {
+ if (keyValue === false) {
+ button.setAttribute('hidden', 'true');
+ }
+ else {
+ button.removeAttribute('hidden');
+ }
+ }
+
+ buttonSecond = document.getElementById('secondary' + (key.charAt(0).toUpperCase() + key.slice(1)));
+ if (buttonSecond !== null) {
+ if (keyValue === false) {
+ buttonSecond.setAttribute('hidden', 'true');
+ }
+ else {
+ button.removeAttribute('hidden');
+ }
+ }
+ }
+ }
+
//
}();
diff --git a/src/angular-pdfjs-viewer.js b/src/angular-pdfjs-viewer.js
index 030e048..8579dcb 100644
--- a/src/angular-pdfjs-viewer.js
+++ b/src/angular-pdfjs-viewer.js
@@ -15,7 +15,8 @@
cmapDir: null,
imageResourcesPath: null,
disableWorker: false,
- verbosity: null
+ verbosity: null,
+ buttons: {}
};
this.setWorkerSrc = function(src) {
@@ -33,11 +34,17 @@
this.disableWorker = function(value) {
if (typeof value === 'undefined') value = true;
config.disableWorker = value;
- }
+ };
this.setVerbosity = function(level) {
config.verbosity = level;
};
+
+ this.setButtonsVisibility = function(buttons) {
+ for (var key in buttons) {
+ config.buttons[key] = (buttons[key] === true);
+ }
+ };
this.$get = function() {
return config;
@@ -64,11 +71,11 @@
if (pdfjsViewerConfig.verbosity !== null) {
var level = pdfjsViewerConfig.verbosity;
if (typeof level === 'string') level = PDFJS.VERBOSITY_LEVELS[level];
- PDFJS.verbosity = pdfjsViewerConfig.verbosity;
+ PDFJS.verbosity = level;
}
}]);
- module.directive('pdfjsViewer', ['$interval', function ($interval) {
+ module.directive('pdfjsViewer', ['$interval', 'pdfjsViewerConfig', function ($interval, pdfjsViewerConfig) {
return {
templateUrl: file.folder + '../../pdf.js-viewer/viewer.html',
restrict: 'E',
@@ -76,6 +83,7 @@
onInit: '&',
onPageLoad: '&',
scale: '=?',
+ buttons: '=?'
},
link: function ($scope, $element, $attrs) {
$element.children().wrap('
');
@@ -144,21 +152,32 @@
}, function () {
if (!$attrs.src) return;
- if ($attrs.open === 'false') {
- document.getElementById('openFile').setAttribute('hidden', 'true');
- document.getElementById('secondaryOpenFile').setAttribute('hidden', 'true');
+ // Restored for backward compatibility
+ if ($attrs.open){
+ if(!$scope.buttons){
+ $scope.buttons = {};
+ }
+ $scope.buttons.openFile = ($attrs.open === 'true');
}
-
- if ($attrs.download === 'false') {
- document.getElementById('download').setAttribute('hidden', 'true');
- document.getElementById('secondaryDownload').setAttribute('hidden', 'true');
+
+ // Restored for backward compatibility
+ if ($attrs.download) {
+ if(!$scope.buttons){
+ $scope.buttons = {};
+ }
+ $scope.buttons.download = ($attrs.download === 'true');
}
- if ($attrs.print === 'false') {
- document.getElementById('print').setAttribute('hidden', 'true');
- document.getElementById('secondaryPrint').setAttribute('hidden', 'true');
+ // Restored for backward compatibility
+ if ($attrs.print) {
+ if(!$scope.buttons){
+ $scope.buttons = {};
+ }
+ $scope.buttons.print = ($attrs.print === 'true');
}
+ setButtonsVisibility(pdfjsViewerConfig.buttons, $scope.buttons);
+
if ($attrs.width) {
document.getElementById('outerContainer').style.width = $attrs.width;
}
@@ -173,6 +192,47 @@
};
}]);
+ function setButtonsVisibility(defaultButtons, customButtons) {
+
+ // Merge default provider's buttons and custom directive's buttons
+ var allButtons = angular.merge({}, defaultButtons, customButtons);
+ var key;
+ var keyValue;
+ var button;
+ var buttonSecond;
+
+ for (key in allButtons) {
+ keyValue = null;
+ if (allButtons && allButtons.hasOwnProperty(key)) {
+ keyValue = allButtons[key];
+ }
+ else {
+ // Default shows
+ keyValue = true;
+ }
+
+ button = document.getElementById(key);
+ if (button !== null) {
+ if (keyValue === false) {
+ button.setAttribute('hidden', 'true');
+ }
+ else {
+ button.removeAttribute('hidden');
+ }
+ }
+
+ buttonSecond = document.getElementById('secondary' + (key.charAt(0).toUpperCase() + key.slice(1)));
+ if (buttonSecond !== null) {
+ if (keyValue === false) {
+ buttonSecond.setAttribute('hidden', 'true');
+ }
+ else {
+ button.removeAttribute('hidden');
+ }
+ }
+ }
+ }
+
// === get current script file ===
var file = {};
file.scripts = document.querySelectorAll('script[src]');