From ba74b4f6ae4b9dacefda5b61b95cefcf643e2651 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 2 Nov 2014 02:40:50 -0800 Subject: [PATCH] Cleanup older code, write in accordance with present Annotation framework --- src/core/annotation.js | 52 ++------------------------------ src/display/annotation_helper.js | 41 +++++++++++++++++++++++++ src/shared/util.js | 3 +- 3 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 6d3df669ea8c98..c11ae3baf23d62 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -537,7 +537,7 @@ var LinkAnnotation = (function LinkAnnotationClosure() { var VideoAnnotation = (function VideoAnnotationClosure() { function VideoAnnotation(params) { - Annotation.call(this, params); + InteractiveAnnotation.call(this, params); if (params.data) { return; } @@ -562,6 +562,7 @@ var VideoAnnotation = (function VideoAnnotationClosure() { var dict = params.dict; var data = this.data; + data.annotationType = AnnotationType.VIDEO; // Check for various annotations related to videos. if (dict.get('Subtype').name === 'Screen') { data.contentType = dict.get('A').get('R').get('C').get('CT') || ''; @@ -590,55 +591,8 @@ var VideoAnnotation = (function VideoAnnotationClosure() { data.src = dict.get('Movie').get('F').get('F'); } } - Util.inherit(VideoAnnotation, Annotation, { - hasHtml: function VideoAnnotation_hasHtml() { - return true; - }, - - getHtmlElement: function VideoAnnotation_getHtmlElement(commonObjs) { - var contentType = this.data.contentType; - var element = document.createElement('video'); - var checkSupport = element.canPlayType(contentType); - if (checkSupport === 'probably') { - element.src = this.data.src || ''; - element.type = contentType || ''; - element.poster = this.data.poster || ''; - element.controls = true; - } else if (contentType in navigator.mimeTypes) { - element = document.createElement('object'); - element.data = this.data.src || ''; - element.type = this.data.contentType || ''; - var param = document.createElement('param'); - param.name = 'controller'; - param.value = true; - element.appendChild(param); - var param2 = document.createElement('param'); - param2.name = 'uiMode'; - param2.value = 'mini'; - element.appendChild(param2); - } else { - warn('Cant play the video, unsupported'); - } - var rect = this.data.rect; - var borderWidth = this.data.borderWidth; + Util.inherit(VideoAnnotation, InteractiveAnnotation, { }); - element.style.borderWidth = borderWidth + 'px'; - var color = this.data.color; - var rgb = []; - for (var i = 0; i < 3; i) { - rgb[i] = Math.round(color[i] * 255); - } - element.style.borderColor = Util.makeCssRgb(rgb); - element.style.borderStyle = 'solid'; - var width = rect[2] - rect[0] - 2 * borderWidth; - var height = rect[3] - rect[1] - 2 * borderWidth; - element.style.width = width + 'px'; - element.style.height = height + 'px'; - element.data = this.data.src || ''; - element.type = this.data.contentType || ''; - return element; - } - }); return VideoAnnotation; })(); diff --git a/src/display/annotation_helper.js b/src/display/annotation_helper.js index 4502d95f8972cf..c25c0d61b0af9f 100644 --- a/src/display/annotation_helper.js +++ b/src/display/annotation_helper.js @@ -232,6 +232,45 @@ var AnnotationUtils = (function AnnotationUtilsClosure() { return container; } + function getHtmlElementForVideoAnnotation(item) { + var container = initContainer(item); + container.className = 'annotVideo'; + + container.style.borderColor = item.colorCssRgb; + container.style.borderStyle = 'solid'; + + var contentType = item.contentType; + var element = document.createElement('video'); + var checkSupport = element.canPlayType(contentType); + if (!checkSupport && (contentType in navigator.mimeTypes)) { + element = document.createElement('object'); + element.data = item.src || ''; + element.type = item.contentType || ''; + var param = document.createElement('param'); + param.name = 'controller'; + param.value = true; + element.appendChild(param); + var param2 = document.createElement('param'); + param2.name = 'uiMode'; + param2.value = 'mini'; + element.appendChild(param2); + } else if (checkSupport) { + // "maybe" and "probably" + element.src = item.src || ''; + element.type = contentType || ''; + element.poster = item.poster || ''; + element.controls = true; + } else { + console.warn('Cant play the video, unsupported'); + } + + element.data = item.src || ''; + element.type = item.contentType || ''; + + container.appendChild(element); + return container; + } + function getHtmlElement(data, objs) { switch (data.annotationType) { case AnnotationType.WIDGET: @@ -240,6 +279,8 @@ var AnnotationUtils = (function AnnotationUtilsClosure() { return getHtmlElementForTextAnnotation(data); case AnnotationType.LINK: return getHtmlElementForLinkAnnotation(data); + case AnnotationType.VIDEO: + return getHtmlElementForVideoAnnotation(data); default: throw new Error('Unsupported annotationType: ' + data.annotationType); } diff --git a/src/shared/util.js b/src/shared/util.js index 7deb991756c41e..28d0fca30b8108 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -47,7 +47,8 @@ var ImageKind = { var AnnotationType = { WIDGET: 1, TEXT: 2, - LINK: 3 + LINK: 3, + VIDEO: 4 }; var StreamType = {