cordova-plugin-document-viewer
Advanced tools
Comparing version 0.8.0 to 0.8.1
{ | ||
"name": "cordova-plugin-document-viewer", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "winjs": "latest", |
{ | ||
"name": "cordova-plugin-document-viewer", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Document viewer cordova plugin for iOS, Android and Windows 8.1 + 10.", | ||
@@ -32,3 +32,3 @@ "license": "MIT", | ||
"cordovaDependencies": { | ||
"0.8.0": { | ||
"0.8.1": { | ||
"cordova": ">=3.7.0", | ||
@@ -35,0 +35,0 @@ "cordova-windows": ">=4.4.0" |
@@ -139,2 +139,5 @@ Cordova Document Viewer Plugin | ||
enabled : BOOLEAN | ||
}, | ||
autoClose: { | ||
onPause : BOOLEAN | ||
} | ||
@@ -266,7 +269,7 @@ } | ||
- Add transparent support for online files. | ||
- The external Viewer App (Android) cannot access files stored in app private directories. Due to this fact, the plugin copies a file to a shared temp folder before starting the viewer. When the viewer is closed, the temp file is immediately deleted. While the viewer is running, a sophisticated user may 'steel' the file from the shared temp directory. We are still searching for a better solution, any good idea is welcome. | ||
- The external Viewer App (Android) cannot access files stored in app private directories. Due to this fact, the plugin copies a file to a shared temp folder before starting the viewer. When the viewer is closed, the temp file is immediately deleted. While the viewer is running, a sophisticated user may 'steal' the file from the shared temp directory. We are still searching for a better solution, any good idea is welcome. | ||
- Add support for pdf forms. | ||
- Add fulltext search features. | ||
- Add user bookmark support. | ||
- Add support for additional mime types like dwg, docx etc. | ||
- Add support for additional mime types like dwg, docx, etc. | ||
- Optimize user experience for small screens. Currently the viewer components are tested and optimized on tablets only. | ||
@@ -273,0 +276,0 @@ - Let developers provide graphics for buttons at runtime. |
@@ -9,2 +9,15 @@ (function (window) | ||
var _suspended = false; | ||
function _onSuspending() | ||
{ | ||
_suspended = true; | ||
} | ||
function _onResuming() | ||
{ | ||
_suspended = false; | ||
} | ||
function createCommonErrorHandler(context) | ||
@@ -16,7 +29,20 @@ { | ||
var detail = eventInfo.detail; | ||
var dialog = new Windows.UI.Popups.MessageDialog( | ||
detail.stack, detail.message); | ||
dialog.showAsync().done(); | ||
if (!_suspended) | ||
{ | ||
var dialog; | ||
if (eventInfo.detail) | ||
{ | ||
var detail = eventInfo.detail; | ||
dialog = new Windows.UI.Popups.MessageDialog( | ||
detail.stack, detail.message); | ||
} | ||
else | ||
{ | ||
dialog = new Windows.UI.Popups.MessageDialog( | ||
context, eventInfo); | ||
} | ||
dialog.showAsync().done(); | ||
} | ||
// By returning true, we signal that the exception was handled, | ||
@@ -32,4 +58,51 @@ // preventing the application from being terminated | ||
window.onerror = function (msg, url, line, col, error) | ||
{ | ||
window.console.error(msg, | ||
{url: url, line: line, col: col, error: error}); | ||
// TODO: suspend event not fired in windows apps. why? | ||
// if (!_suspended) | ||
// { | ||
// try | ||
// { | ||
// var extra = !col ? '' : '\ncolumn: ' + col; | ||
// extra += !error ? '' : '\nerror: ' + error; | ||
// | ||
// var dialog = new Windows.UI.Popups.MessageDialog( | ||
// msg, "\nurl: " + url + "\nline: " + line + extra); | ||
// dialog.showAsync().done(); | ||
// } | ||
// catch (e) | ||
// { | ||
// // ignore | ||
// window.console.error("cannot show dialog", e); | ||
// } | ||
// } | ||
// | ||
return true; | ||
}; | ||
// var webUIApp = (Windows | ||
// && Windows.UI) ? Windows.UI.WebUI.WebUIApplication : null; | ||
// if (webUIApp) | ||
// { | ||
// webUIApp.addEventListener("suspending", _onSuspending); | ||
// webUIApp.addEventListener("resuming", _onResuming); | ||
// } | ||
// | ||
var module = angular.module('viewer', ['winjs'], null); | ||
module.run(function($rootScope){ | ||
$rootScope.$on("app.suspending", _onSuspending); | ||
$rootScope.$on("app.resuming", _onResuming); | ||
}); | ||
module.factory('log', function ($window) | ||
@@ -134,5 +207,5 @@ { | ||
ctrl.gotoPage = function(pageIndex, viewId) | ||
ctrl.gotoPage = function (pageIndex, viewId) | ||
{ | ||
if(pageIndex==null) | ||
if (pageIndex == null) | ||
return; | ||
@@ -142,3 +215,3 @@ | ||
if(viewId) | ||
if (viewId) | ||
ctrl.setView(viewId); | ||
@@ -581,26 +654,35 @@ }; | ||
{ | ||
if (generator.canceled || _generator | ||
!= generator) | ||
return; | ||
try | ||
{ | ||
if (generator.canceled || _generator | ||
!= generator) | ||
return; | ||
_dirty = false; | ||
_generator = null; | ||
_dirty = false; | ||
_generator = null; | ||
var srcObject = pi.imageSrc; | ||
var srcObject = pi.imageSrc; | ||
$scope.$evalAsync(function () | ||
$scope.$evalAsync(function () | ||
{ | ||
if (generator.canceled) | ||
return; | ||
page.setImageSrc( | ||
URL.createObjectURL( | ||
srcObject, | ||
{oneTimeOnly: false}), | ||
URL.revokeObjectURL | ||
); | ||
}); | ||
} | ||
catch (e) | ||
{ | ||
if (generator.canceled) | ||
return; | ||
page.setImageSrc( | ||
URL.createObjectURL( | ||
srcObject, | ||
{oneTimeOnly: false}), | ||
URL.revokeObjectURL | ||
); | ||
}); | ||
window.console.error(e); | ||
} | ||
}, | ||
applyError: function (error) | ||
{ | ||
window.console.error(error); | ||
if (generator.canceled || _generator | ||
@@ -617,2 +699,16 @@ != generator) | ||
var _unregisterOnSuspending; | ||
function _onSuspending() | ||
{ | ||
// webUIApp.removeEventListener("suspending", | ||
// _onSuspending); | ||
if(_unregisterOnSuspending) | ||
{ | ||
_unregisterOnSuspending(); | ||
_unregisterOnSuspending = null; | ||
} | ||
generator.cancel(); | ||
} | ||
// force async exec | ||
@@ -624,2 +720,7 @@ $scope.$applyAsync(function () | ||
// if (webUIApp) | ||
// webUIApp.addEventListener("suspending", | ||
// _onSuspending); | ||
_unregisterOnSuspending = $scope.$on("app.suspending", _onSuspending); | ||
generator.promise = pdfLibrary.loadPage( | ||
@@ -989,13 +1090,15 @@ page.pageIndex, | ||
module.controller('OutlineViewCtrl', function (ViewCtrlBase, $scope, pdfViewer) | ||
{ | ||
var ctrl = this; | ||
ViewCtrlBase.call(ctrl, $scope); | ||
module.controller('OutlineViewCtrl', | ||
function (ViewCtrlBase, $scope, pdfViewer) | ||
{ | ||
var ctrl = this; | ||
ViewCtrlBase.call(ctrl, $scope); | ||
function _showOutline(){ | ||
ctrl.outline = pdfViewer.doc.outline; | ||
} | ||
function _showOutline() | ||
{ | ||
ctrl.outline = pdfViewer.doc.outline; | ||
} | ||
pdfViewer.waitForPDF().then(_showOutline); | ||
}); | ||
pdfViewer.waitForPDF().then(_showOutline); | ||
}); | ||
@@ -1063,4 +1166,6 @@ | ||
loadFile(pdfUri) | ||
.then(function(file){ | ||
return $q.all([loadPDF(file), loadPDFOutline(pdfUri)]);}) | ||
.then(function (file) | ||
{ | ||
return $q.all([loadPDF(file), loadPDFOutline(pdfUri)]); | ||
}) | ||
.done(function () | ||
@@ -1159,3 +1264,3 @@ { | ||
{ | ||
if(pageIndex!=null) | ||
if (pageIndex != null) | ||
item.pageIndex = pageIndex; | ||
@@ -1234,5 +1339,13 @@ else | ||
_setHandler(function (args) | ||
{ | ||
_showPdf(args); | ||
_setHandler({ | ||
showPDF: function (args) | ||
{ | ||
_showPdf(args); | ||
}, | ||
appSuspend : function(){ | ||
$rootScope.$broadcast("app.suspend"); | ||
}, | ||
appResume : function(){ | ||
$rootScope.$broadcast("app.resume"); | ||
} | ||
}); | ||
@@ -1343,11 +1456,2 @@ | ||
function _setArgs(args) | ||
{ | ||
_args = args; | ||
_handler.forEach(function (handler) | ||
{ | ||
handler(_args); | ||
}); | ||
} | ||
function _setHandler(handler) | ||
@@ -1357,3 +1461,3 @@ { | ||
if (_args) | ||
handler(_args); | ||
handler.showPDF(_args); | ||
} | ||
@@ -1371,6 +1475,10 @@ | ||
{ | ||
_setArgs({ | ||
_args = { | ||
pdfUri: pdfUri, | ||
pdfOptions: pdfOptions, | ||
closeHandler: closeHandler | ||
}; | ||
_handler.forEach(function (handler) | ||
{ | ||
handler.showPDF(_args); | ||
}); | ||
@@ -1380,2 +1488,20 @@ }; | ||
window.appSuspend = function () | ||
{ | ||
_handler.forEach(function (handler) | ||
{ | ||
handler.appSuspend(_args); | ||
}); | ||
}; | ||
window.appResume = function () | ||
{ | ||
_handler.forEach(function (handler) | ||
{ | ||
handler.appResume(_args); | ||
}); | ||
}; | ||
})(this); |
@@ -13,2 +13,98 @@ var PDF = "application/pdf"; | ||
var viewerId = "sitewaertsdocumentviewer_windows"; | ||
var iframeId = viewerId + "_iframe"; | ||
var closeId = viewerId + "_close"; | ||
function _getContainer(create){ | ||
var iframe = document.getElementById(iframeId); | ||
var viewer = document.getElementById(viewerId); | ||
var close = document.getElementById(closeId); | ||
if(!iframe) | ||
{ | ||
if(!create) | ||
return null; | ||
viewer = document.createElement("div"); | ||
viewer.id = viewerId; | ||
viewer.className = "sitewaertsdocumentviewer windows"; | ||
close = document.createElement("div"); | ||
close.id = closeId; | ||
close.className = "close"; | ||
iframe = document.createElement("iframe"); | ||
iframe.id = iframeId; | ||
var body = document.getElementsByTagName("body")[0]; | ||
viewer.appendChild(iframe); | ||
viewer.appendChild(close); | ||
body.appendChild(viewer); | ||
close.addEventListener("click", _doClose); | ||
} | ||
var _closeHandler; | ||
function _setCloseHandler(closeHandler){ | ||
_closeHandler = closeHandler; | ||
} | ||
var _closeOnPause; | ||
function _setCloseOnPause(closeOnPause){ | ||
_closeOnPause = closeOnPause == true; | ||
} | ||
/** | ||
* @void | ||
*/ | ||
function _cleanup() | ||
{ | ||
iframe.src = ""; | ||
viewer.style.display = 'none'; | ||
_closeOnPause = null; | ||
} | ||
function _doClose(){ | ||
_cleanup(); | ||
if(_closeHandler) | ||
_closeHandler(); // closed | ||
_closeHandler = null; | ||
} | ||
function _showPDF(url, options, close){ | ||
var w = iframe.window || iframe.contentWindow; | ||
w.showPDF(url, options, close); | ||
viewer.style.display = 'block'; | ||
} | ||
function _appSuspend(){ | ||
var w = iframe.window || iframe.contentWindow; | ||
if(w) | ||
w.appSuspend(); | ||
if(_closeOnPause) | ||
_doClose(); | ||
} | ||
function _appResume(){ | ||
var w = iframe.window || iframe.contentWindow; | ||
if(w) | ||
w.appResume(); | ||
} | ||
return { | ||
iframe : iframe, | ||
viewer : viewer, | ||
showPDF : _showPDF, | ||
close: _doClose, | ||
cleanup : _cleanup, | ||
appSuspend : _appSuspend, | ||
appResume: _appResume, | ||
setCloseHandler : _setCloseHandler, | ||
setCloseOnPause : _setCloseOnPause | ||
}; | ||
} | ||
//launching file in external app: | ||
@@ -80,45 +176,10 @@ // see https://msdn.microsoft.com/en-us/library/windows/apps/hh452687.aspx | ||
var c = _getContainer(true); | ||
c.setCloseHandler(function(){ | ||
successCallback({status: 0}); // 0 = closed | ||
}); | ||
var viewerId = "sitewaertsdocumentviewer_windows"; | ||
var iframeId = viewerId + "_iframe"; | ||
c.setCloseOnPause(options && options.autoClose && options.autoClose.onPause); | ||
var iframe = document.getElementById(iframeId); | ||
var viewer = document.getElementById(viewerId); | ||
if(!iframe) | ||
{ | ||
viewer = document.createElement("div"); | ||
viewer.id = viewerId; | ||
viewer.className = "sitewaertsdocumentviewer windows"; | ||
var close = document.createElement("div"); | ||
close.className = "close"; | ||
iframe = document.createElement("iframe"); | ||
iframe.id = iframeId; | ||
var body = document.getElementsByTagName("body")[0]; | ||
viewer.appendChild(iframe); | ||
viewer.appendChild(close); | ||
body.appendChild(viewer); | ||
close.addEventListener("click", doClose); | ||
} | ||
/** | ||
* @void | ||
*/ | ||
function _cleanup() | ||
{ | ||
iframe.src = ""; | ||
viewer.style.display = 'none'; | ||
} | ||
/** | ||
* @void | ||
*/ | ||
function doClose() | ||
{ | ||
_cleanup(); | ||
successCallback({status: 0}); // closed | ||
} | ||
function doCloseAsync() | ||
@@ -128,3 +189,3 @@ { | ||
{ | ||
doClose(); | ||
c.close(); | ||
}, 100); | ||
@@ -134,22 +195,16 @@ } | ||
// sitewaertsdocumentviewer must be located in www | ||
iframe.src = "/www/" + viewerLocation + "/viewer.html"; | ||
c.iframe.src = "/www/" + viewerLocation + "/viewer.html"; | ||
iframe.onload = function () | ||
c.iframe.onload = function () | ||
{ | ||
// avoid reloading on close | ||
c.iframe.onload = null; | ||
try | ||
{ | ||
// avoid reloading on close | ||
iframe.onload = null; | ||
var w = iframe.window || iframe.contentWindow; | ||
w.showPDF(url, options, doCloseAsync); | ||
//frames[iframeId].window.showPDF(url, options, doCloseAsync); | ||
viewer.style.display = 'block'; | ||
successCallback({status: 1}); // shown | ||
c.showPDF(url, options, doCloseAsync); | ||
successCallback({status: 1}); // 1 = shown | ||
} | ||
catch(e) | ||
{ | ||
_cleanup(); | ||
c.cleanup(); | ||
errorCallback({status: 0, message: "cannot init frame", error : e}); | ||
@@ -160,2 +215,29 @@ } | ||
}, | ||
appPaused: function (successCallback, errorCallback) | ||
{ | ||
// ignore | ||
// no need to handle external events as we have internal listeners for pause and resume | ||
successCallback(); | ||
}, | ||
appResumed: function (successCallback, errorCallback) | ||
{ | ||
// ignore | ||
// no need to handle external events as we have internal listeners for pause and resume | ||
successCallback(); | ||
}, | ||
close: function (successCallback, errorCallback) | ||
{ | ||
var c = _getContainer(false); | ||
try | ||
{ | ||
if(c) | ||
c.close(); | ||
successCallback({status: 0}); // 1 = closed | ||
} | ||
catch(e) | ||
{ | ||
c.cleanup(); | ||
errorCallback({status: 0, message: "cannot close frame", error : e}); | ||
} | ||
}, | ||
install: function (successCallback, errorCallback) | ||
@@ -166,1 +248,36 @@ { | ||
}); | ||
// listeners MUST be registered after deviceready event | ||
// attention: windows app may be never suspended in debug mode! | ||
// TODO: why are these events no fired in windows app even in release mode? | ||
document.addEventListener("deviceready", function(){ | ||
document.addEventListener("pause", function () | ||
{ | ||
var c = _getContainer(false); | ||
try | ||
{ | ||
if(c) | ||
c.appSuspend(); | ||
} | ||
catch(e) | ||
{ | ||
window.console.error(e); | ||
} | ||
}, false); | ||
document.addEventListener("resume", function () | ||
{ | ||
var c = _getContainer(false); | ||
try | ||
{ | ||
if(c) | ||
c.appResume(); | ||
} | ||
catch(e) | ||
{ | ||
window.console.error(e); | ||
} | ||
}, false); | ||
}, false); | ||
@@ -21,2 +21,6 @@ // cordova-plugin-document-viewer | ||
APP_PAUSED: "appPaused", | ||
APP_RESUMED: "appResumed", | ||
INSTALL_VIEWER_APP: "install" | ||
@@ -74,2 +78,4 @@ }; | ||
if (!options.autoClose) | ||
options.autoClose = {onPause : false}; | ||
@@ -223,2 +229,30 @@ if (!options.android) | ||
// only needed on iOS as I don't know how to listen for this event in native C code | ||
function _firePause(){ | ||
exec( | ||
function () | ||
{ | ||
window.console.log(JS_HANDLE + ": fired pause event to native plugin"); | ||
}, | ||
_logError, | ||
CDV_HANDLE, | ||
CDV_HANDLE_ACTIONS.APP_PAUSED, | ||
[] | ||
); | ||
} | ||
// only needed on iOS as I don't know how to listen for this event in native C code | ||
function _fireResume(){ | ||
exec( | ||
function () | ||
{ | ||
window.console.log(JS_HANDLE + ": fired resume event to native plugin"); | ||
}, | ||
_logError, | ||
CDV_HANDLE, | ||
CDV_HANDLE_ACTIONS.APP_RESUMED, | ||
[] | ||
); | ||
} | ||
function _beforeShow(next) | ||
@@ -241,2 +275,11 @@ { | ||
function _onShow(){ | ||
document.addEventListener("pause", _firePause, false); | ||
document.addEventListener("resume", _fireResume, false); | ||
if (onShow) | ||
onShow(); | ||
} | ||
function _beforeClose(next) | ||
@@ -249,2 +292,6 @@ { | ||
} | ||
document.removeEventListener("pause", _firePause); | ||
document.removeEventListener("resume", _fireResume); | ||
if(next) | ||
@@ -254,9 +301,13 @@ next(); | ||
function _close(){ | ||
function _onClose(){ | ||
_beforeClose(onClose); | ||
} | ||
function _logError(e){ | ||
window.console.error(errorPrefix, e); | ||
} | ||
function _onError(e) | ||
{ | ||
window.console.log(errorPrefix, e); | ||
_logError(e); | ||
_beforeClose(function () | ||
@@ -292,8 +343,7 @@ { | ||
{ | ||
if (onShow) | ||
onShow(); | ||
_onShow(); | ||
} | ||
else if (status == 0) | ||
{ | ||
_close(); | ||
_onClose(); | ||
} | ||
@@ -305,3 +355,3 @@ else | ||
+ "'"; | ||
window.console.log( | ||
window.console.error( | ||
errorPrefix + errorMsg); | ||
@@ -308,0 +358,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16382100
230929
300