From 28108cb766c227a7beb847d1d763f9dab00c59aa Mon Sep 17 00:00:00 2001 From: Guido Vollbach Date: Fri, 4 Dec 2015 09:27:16 +0100 Subject: [PATCH] testcase cleanup --- js/InteractiveVideoPlayerUtils.js | 14 ++++++------ js/jquery.InteractiveVideoPlayer.js | 26 +++++++++++----------- js/test/InteractiveVideoPlayerUtilsTest.js | 20 ++++++++--------- templates/default/tpl.video_tpl.html | 3 ++- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/js/InteractiveVideoPlayerUtils.js b/js/InteractiveVideoPlayerUtils.js index 3feb36ca..53df1510 100644 --- a/js/InteractiveVideoPlayerUtils.js +++ b/js/InteractiveVideoPlayerUtils.js @@ -85,11 +85,11 @@ il.InteractiveVideoPlayerUtils = (function () { { username = '[' + username + ']'; } - if(parseInt(is_interactive, 10) == 1) + if(parseInt(is_interactive, 10) === 1) { username = '[' + question_text + ']'; } - return ' ' + username + ''; + return ' ' + username + ' '; }; pro.builCommentTitleHtml = function (title) @@ -98,12 +98,12 @@ il.InteractiveVideoPlayerUtils = (function () { { title = ''; } - return '' + title + ''; + return '' + title + ' '; }; pro.builCommentTextHtml = function (text) { - return '' + text + ''; + return '' + text + ' '; }; pro.appendPrivateHtml = function (is_private) @@ -117,19 +117,19 @@ il.InteractiveVideoPlayerUtils = (function () { { private_comment = ''; } - return ''+ private_comment + ''; + return ''+ private_comment + ' '; }; pro.builCommentTagsHtml = function (tags) { var comment_tags = ''; - if(tags === null) + if(tags == null) { comment_tags = ''; } else { - comment_tags = '' + tags.split(',').join(' ') + ''; + comment_tags = '' + tags.split(',').join(' ') + ' '; } return '
' + comment_tags + '
'; }; diff --git a/js/jquery.InteractiveVideoPlayer.js b/js/jquery.InteractiveVideoPlayer.js index b181770c..e41a0352 100755 --- a/js/jquery.InteractiveVideoPlayer.js +++ b/js/jquery.InteractiveVideoPlayer.js @@ -51,8 +51,7 @@ $( document ).ready(function() { (function ($) { il.Util.addOnLoad(function () { - var _lastTime = 0, - player = null, + var player = null, interval = null; InteractiveVideo.last_stopPoint = -1; player = new MediaElementPlayer("#ilInteractiveVideo", { @@ -71,11 +70,11 @@ $( document ).ready(function() { media.addEventListener('seeked', function(e) { $().debugPrinter('Player', 'seeked'); clearInterval(interval); - if (_lastTime > media.currentTime) { - _lastTime = media.currentTime; + if (InteractiveVideo.last_time > media.currentTime) { + InteractiveVideo.last_time = media.currentTime; InteractiveVideo.last_stopPoint = -1; - } else if (_lastTime < media.currentTime) { - _lastTime = media.currentTime; + } else if (InteractiveVideo.last_time < media.currentTime) { + InteractiveVideo.last_time = media.currentTime; } il.InteractiveVideoPlayerUtils.replaceCommentsAfterSeeking(media.currentTime); }, false); @@ -83,13 +82,14 @@ $( document ).ready(function() { media.addEventListener('pause', function(e) { $().debugPrinter('Player', 'paused'); clearInterval(interval); - _lastTime = media.currentTime; + InteractiveVideo.last_time = media.currentTime; }, false); media.addEventListener('ended', function(e) { $().debugPrinter('Player', 'video finished'); }, false); media.addEventListener('playing', function(e) { + var cueTime, stop_video, i, j; $().debugPrinter('Player', 'playing'); interval = setInterval(function () { if (media.currentTime >= media.duration) { @@ -99,15 +99,15 @@ $( document ).ready(function() { if (!isNaN(media.currentTime) && media.currentTime > 0) { // @todo: Evtl. use a better way to detect the relevant stopping point - for (var j = stopPoints.length - 1; j >= 0; j--) + for (j = stopPoints.length - 1; j >= 0; j--) { - var cueTime = parseInt(stopPoints[j], 10); - if (cueTime >= _lastTime && cueTime <= media.currentTime) + cueTime = parseInt(stopPoints[j], 10); + if (cueTime >= InteractiveVideo.last_time && cueTime <= media.currentTime) { - var stop_video = 0; + stop_video = 0; if (InteractiveVideo.last_stopPoint < cueTime) { - for (var i = 0; i < Object.keys(comments).length; i++) + for (i = 0; i < Object.keys(comments).length; i++) { if (comments[i].comment_time == cueTime) { @@ -134,7 +134,7 @@ $( document ).ready(function() { InteractiveVideo.last_stopPoint = parseInt(cueTime, 10); } } - _lastTime = media.currentTime; + InteractiveVideo.last_time = media.currentTime; } }, 500); diff --git a/js/test/InteractiveVideoPlayerUtilsTest.js b/js/test/InteractiveVideoPlayerUtilsTest.js index 850807a1..bc693b18 100644 --- a/js/test/InteractiveVideoPlayerUtilsTest.js +++ b/js/test/InteractiveVideoPlayerUtilsTest.js @@ -24,37 +24,37 @@ describe("InteractiveVideoPlayerUtils Tests", function () { }); it("builCommentTextHtml must return html", function () { - var expec = 'My little text'; + var expec = 'My little text '; var value = il.InteractiveVideoPlayerUtils.protect.builCommentTextHtml('My little text'); expect(value).toEqual(expec); }); it("builCommentTitleHtml must return html", function () { - var expec = 'My little text'; + var expec = 'My little text '; var value = il.InteractiveVideoPlayerUtils.protect.builCommentTitleHtml('My little text'); expect(value).toEqual(expec); - expec = ''; + expec = ' '; value = il.InteractiveVideoPlayerUtils.protect.builCommentTitleHtml(null); expect(value).toEqual(expec); }); it("builCommentUsernameHtml must return html", function () { - var expec = ' [Username]'; + var expec = ' [Username] '; var value = il.InteractiveVideoPlayerUtils.protect.builCommentUsernameHtml('Username', 0); expect(value).toEqual(expec); - expec = ' [Question]'; + expec = ' [Question] '; value = il.InteractiveVideoPlayerUtils.protect.builCommentUsernameHtml('Username', 1); expect(value).toEqual(expec); - expec = ' '; + expec = ' '; value = il.InteractiveVideoPlayerUtils.protect.builCommentUsernameHtml('', 0); expect(value).toEqual(expec); }); it("builCommentPrivateHtml must return html", function () { - var expec = ' (private)'; + var expec = ' (private) '; var value = il.InteractiveVideoPlayerUtils.protect.appendPrivateHtml(1); expect(value).toEqual(expec); - expec = ''; + expec = ' '; value = il.InteractiveVideoPlayerUtils.protect.appendPrivateHtml(0); expect(value).toEqual(expec); }); @@ -70,7 +70,7 @@ describe("InteractiveVideoPlayerUtils Tests", function () { it("builCommentTagsHtml must return html", function () { var tags = 'Tag1, Tag2'; - var expec = '
Tag1 Tag2
'; + var expec = '
Tag1 Tag2
'; var value = il.InteractiveVideoPlayerUtils.protect.builCommentTagsHtml(tags); expect(value).toEqual(expec); expec = '
'; @@ -117,7 +117,7 @@ describe("InteractiveVideoPlayerUtils Tests", function () { loadFixtures('InteractiveVideoPlayerUtils_fixtures.html'); il.InteractiveVideoPlayerUtils.replaceCommentsAfterSeeking(1); expect($("#ul_scroll").html()).toEqual(expec); - expec = '
  • [undefined]undefinedText
  • '; + expec = '
  • [undefined] undefined Text
  • '; comments = [{comment_time: 1, comment_text: 'Text', is_interactive: 0, comment_tags: null}]; il.InteractiveVideoPlayerUtils.replaceCommentsAfterSeeking(5); expect($("#ul_scroll").html()).toEqual(expec); diff --git a/templates/default/tpl.video_tpl.html b/templates/default/tpl.video_tpl.html index 2debcae5..717f9b14 100755 --- a/templates/default/tpl.video_tpl.html +++ b/templates/default/tpl.video_tpl.html @@ -56,7 +56,8 @@

    {TXT_COMMENTS}

    auto_resume : false, pause_on_click_in_comment_field : true, iv_debug : false, - last_stopPoint : -1 + last_stopPoint : -1, + last_time : 0 }; $.fn.debugPrinter = function (message, element)