@iguide/viewer
Advanced tools
+44
-11
@@ -1,20 +0,34 @@ | ||
| /* eslint-disable */ | ||
| function IGuideViewer(element) { | ||
| this.element = element; | ||
| this.iframe = this.element.contentWindow; | ||
| this.iframe = this.element ? this.element.contentWindow : null; | ||
| this.listeners = []; | ||
| this.readyPromiseResolve = null; | ||
| this._onMessageCb = this._onMessage.bind(this); | ||
| if (!this.iframe) { | ||
| throw new Error('iGUIDE API error: iframe does not exist'); | ||
| } | ||
| window.addEventListener('message', this._onMessageCb); | ||
| var that = this; | ||
| this.readyPromise = new window.Promise(function (resolve) { | ||
| window.addEventListener('message', function promiseMessage(e) { | ||
| if (e.source !== that.iframe) { return; } | ||
| if (e.data === 'vf-jview-ready') { | ||
| window.removeEventListener('message', promiseMessage); | ||
| window.addEventListener('message', that._onMessage.bind(that)); | ||
| resolve(); | ||
| } | ||
| }); | ||
| this.readyPromise = new window.Promise(function (resolve, reject) { | ||
| if (that.iframe.closed) { | ||
| reject(new Error('iGUIDE API error: iframe is closed')); | ||
| that.disconnect(); | ||
| return; | ||
| } | ||
| that.readyPromiseResolve = resolve; | ||
| try { | ||
| that.iframe.postMessage({ctrl: 'ping'}, '*'); | ||
| } catch (err) { | ||
| reject(err); | ||
| that.disconnect(); | ||
| } | ||
| }); | ||
| this.tour = { | ||
| // eslint-disable-next-line no-extra-parens | ||
| move: (function (position, camera, transition) { | ||
@@ -29,2 +43,3 @@ var data = { | ||
| }).bind(this), | ||
| // eslint-disable-next-line no-extra-parens | ||
| moveCamera: (function (camera) { | ||
@@ -44,4 +59,21 @@ var data = { | ||
| IGuideViewer.prototype.disconnect = function () { | ||
| window.removeEventListener('message', this._onMessageCb); | ||
| this.listeners = []; | ||
| this.readyPromise = null; | ||
| this.readyPromiseResolve = null; | ||
| }; | ||
| IGuideViewer.prototype._onMessage = function (e) { | ||
| if (e.source !== this.iframe) { return; } | ||
| if (e.data && e.data.ctrl) { | ||
| if ((e.data.ctrl === 'ready' || e.data.ctrl === 'pong') && | ||
| this.readyPromiseResolve) { | ||
| this.readyPromiseResolve(); | ||
| this.readyPromiseResolve = null; | ||
| } | ||
| return; | ||
| } | ||
| if (e.data && e.data.event) { | ||
@@ -75,2 +107,3 @@ var listener; | ||
| // eslint-disable-next-line no-undef | ||
| module.exports = IGuideViewer; |
+4
-4
| { | ||
| "name": "@iguide/viewer", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "iGUIDE Viewer API", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "test": "echo \"Warning: no test specified\" && exit 0" | ||
| }, | ||
| "keywords": [ | ||
| "iguide" | ||
| "iguide", "planitar" | ||
| ], | ||
| "author": "", | ||
| "author": "Planitar Inc.", | ||
| "license": "ISC" | ||
| } |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
3023
36.79%92
39.39%2
-33.33%