forked from Manito1123/zhihuishu-fast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zhihuishu.js
2402 lines (2172 loc) · 94.1 KB
/
zhihuishu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var commitStatus = true; // 讨论讨论提交状态
var loadPreStudyNoteState = true; // 查询学习记录
var validateIsJumpChapterStatus = true; // 验证跨章提交状态
var saveDatabaseState = true; // 保存数据库状态
var userId = $('#userId').val(); // 用户ID
var PCourseId = $("#PCourseId").val(); // 扩展表课程ID
courseId = $("#courseId").val(); // 课程ID
rid = $("#rid").val(); // 招生ID
var isJumpChapter = $('#isJumpChapter').val(); // 是否可以跨章
var studentCount = $('#studentCount').val(); // 是否已报名
var chapterId; // 章ID
var lessonId; // 节ID
var lessonVideoId; // 小节id
var videoId = $('#videoId').val(); // 视频id
var courseType = $('#courseType').val(); // 课程类型
var $chapterObject; // 记录点击的章对象
var $videoObject; // 记录点击的视频对象
var currentPlayTime = ""; // 保存视屏播放的当前时间
var lessonQuestions = ""; // 保存节次考题时间
var popupExamInterval = ""; // 弹题定时器
var learnTime = $('#learnTime').val(); // 视频最后学习时间点
var studiedId = ""; // 已学节次ID
var databaseIntervalTime = 1000 * 60 * 5; // 每5分钟保存数据库视频学习时间点
var databaseInterval = ""; // 每分钟保存数据库视频学习时间点定时器
var cacheIntervalTime = 1000 * 120; // 每120秒保存缓存视频学习时间点
var cacheInterval = ""; // 每30秒保存缓存视频学习时间点定时器
var totalStudyTimeInterval = ""; // 累加学习视频时间
var studyTotalTime = 0; // 视频学习总时间(秒)
var videoSize; // 视频大小
var noteId = $("#noteId").val(); // 笔记id
var watchState; // 观看状态
var playTimes = 0 ; // 本次播放时长
var studyStatus = $("#studyStatus").val(); //获得课程是否结束状态 1:已经完成 0:未完成
var lessonPictures = ""; //视频弹图,时间点
var preventPopupTest = false; // 阻止弹题标识
var popupPicInterval = ""; // 弹图定时器
var tokenFlag = true; //token是否通过验证标志
initLoad();
// 初始载入播放器
function initLoad() {
showExploreTip();
hidePanel();
// 检查当前章节视频列表中是否有包含此视频ID(防错),#张立坤注
if (checkedVideoIsExist(videoId)) {
var video = $('#video-' + videoId);
if (isSignUp()) { // 已报名
// 从课程主页进入,弹出此提示,用于引导用户不再从此进入,#张立坤注
validateIntoPoistion();
// 直接当前章(节)
validateIsJumpChapter(video, true);
} else if (isNotSignUp() && isMinCourse()) { // 未报名并且是微课,只能看第一个视频
var firstVideo = $('.video:first');
if (video.attr('_videoId') == firstVideo.attr('_videoId')) {
initPlayInfo(video);
} else {
tmInitLoadingT(zLocale.only_try_watch_first_video, 5000);
setTimeout(reloadDefaultVideo, 3000);
}
} else { // 未报名并且是进阶式课程,直接加载播放器
initPlayInfo(video);
}
} else {
// 设置默认播放视频
defaultVideo();
}
// 前端渲染播放状态(图标:未看、播放未完成、播放完成)
initVideoPlayState();
initLearningEvent();
}
// 初始化视频播放状态
function initVideoPlayState() {
if (isSignUp()) {
// 视频状态显示
$('.isStudiedLesson').each(function (index, event) {
var video_tmp = $(this).parents('li');
var watchState = video_tmp.attr('watchState');
var videoId_tmp = video_tmp.attr('_videoId');
if (watchState != 1) {
var key = getCookieKey(videoId_tmp);
var _value = $.cookie(key);
if (isNotEmpty(_value)) {
var values = _value.split('_');
if (values[0] == 1) {
video_tmp.attr('watchState', 1);
$(this).removeClass().addClass('withborder_no_tip').addClass('fl').attr("tip", zLocale.click_video_can_submit);
} else {
setPlayerState.call(this);
}
} else {
setPlayerState.call(this);
}
} else {
setPlayerState.call(this);
}
function setPlayerState() {
if (watchState != undefined && watchState != null && videoId_tmp != videoId && video_tmp.hasClass('video')) {
if (watchState == 1) {
$(this).removeClass().addClass('time_ico3').addClass('fl');
} else if (watchState == 2) {
$(this).removeClass().addClass('time_ico_half').addClass('fl');
}
}
}
});
$(".time_ico_half").tmTip({color: "black", arrow: 'topMiddle', width: '100px'});
$(".withborder_no_tip").tmTip({color: "black", arrow: 'topMiddle', width: '100px'});
}
}
/**
* 检查视频是否存在
* @param videoId
* @returns {boolean}
*/
function checkedVideoIsExist(videoId) {
if ($('#video-' + videoId).length == 1 && isNotEmpty(videoId)) {
return true;
}
return false;
}
/**
* 默认视频,最近一次观看的视频,如果从未看过,使用第一个
*/
function defaultVideo() {
var defVideo = $('#chapterList').find('li[watchstate!=1]').filter('.video').first();
if (defVideo.length == 0) {
defVideo = $('#chapterList').find('li').filter('.video').first();
}
initPlayInfo(defVideo);
}
/**
* 当前章的前几章的所有节是否已学完
*/
function getUnplayVideoCount(video) {
return video.prevAll('[watchstate!=1]').filter('.video').length;
}
/**
* 验证是否跨章学习
* @param video
*/
function validateIsJumpChapter(video, isFirstLoadVideo) {
if (!validateIsJumpChapterStatus) {
return;
}
if (isJumpChapter == 0) {
//if (isFirstLoadVideo) {
var unPlayCount = getUnplayVideoCount($('#chapter-' + video.attr('_chapterId')));
if (unPlayCount == 0) {
initPlayInfo(video);
} else {
var text="";
if (z_locale==1) {
text="本课程不能跨章学习,本章之前还有"+"【" + (unPlayCount) + "】"+'个视频没有看完';
} else {
text='You are not allowed to skip chapters to learn and there are'+"【" + (unPlayCount) + "】"+ 'videos not finished before this chapter.';
}
tmInitLoadingT(text, 5000);
if (isFirstLoadVideo) {
window.setTimeout(reloadDefaultVideo, 3000);
}
}
} else {
initPlayInfo(video);
}
}
/**
* 重新载入到默认视频
*/
function reloadDefaultVideo() {
tmInitLoadingT(zLocale.auto_jumpto, 3000);
defaultVideo();
}
/**
* 初始化跨章学习参数
*
*/
function initIsJumpChapterParams(video) {
//如果是已完成课程,优先级最高,不做判断,by wyj,2016/6/28
if (studyStatus == 1) {
initPlayInfo(video);
}
// 没有报名的学生,只能学习第一章或者绪章
var chapter = $('#chapter-' + video.attr('_chapterId'));
//章节的课程视频 (video.attr("_chapternum")>1&& video.attr("_zhangNum")>0)||(video.attr("_zhangNum")>1)
//章的课程视频 ((video.attr("_jieNum")>1&&video.attr("orderNumber")>0)||(video.attr("orderNumber")>1))
if (isNotSignUp()){
if(video.attr("_zhangNum")>1){ //章>1弹窗提示
notSignUpTip(zLocale.you_have_not_signed_up);
return;
}else{
if(video.attr("_jieNum")>1){//节>1弹窗提示
notSignUpTip(zLocale.you_have_not_signed_up);
return;
}else{
if(video.attr("_xjieNum")>1){ // 小节>1弹窗提示
notSignUpTip(zLocale.you_have_not_signed_up);
return;
}
}
}
}
if ($chapterObject && isJumpChapter == 0) {
if (chapter.attr("_orderNumber") * 1 > $chapterObject.attr("_orderNumber") * 1 && isSignUp()) {
validateIsJumpChapter(video);
} else {
initPlayInfo(video);
}
} else {
// 没有报名的学生,只能学习第一章或者绪章
var chapter = $('#chapter-' + video.attr('_chapterId'));
if (isNotSignUp() && chapter.attr("_orderNumber") > $('#chapterList').find('.chapter:first').attr("_orderNumber")&&video.attr("_chapterNum")>1) {
notSignUpTip(zLocale.you_have_not_signed_up);
return;
}
initPlayInfo(video);
}
}
/**
* 初始化学习事件,与播放无关,用于页面上其它按钮单击事件监听
*/
function initLearningEvent() {
showTabs(); // 切换Tab,目录、笔记
videoToggle(); // 视频列表切换(章节列表上)
jiaoxuejihua(); // 教学计划弹出
jiaoxuedaGang(); // 教学大纲弹出
priase(); // 笔记点赞
canclePriase(); // 取消点赞
collection(); // 收藏
collectionCancle(); // 取消收藏
saveNote(); // 保存笔记
notePlayTime(); // 获取记录笔记的时间(点击写笔记的编辑框时)
showComment(); // 显示评论
textAreaEvent(); // 监听评论输入框输入文本信息时,评论字数计数
numberCheck(); // 评论计数
addcomment(); // 添加评论
getmoreComment(); // 获取更多评论
notetitleswitch(); // 我的笔记、优秀笔记切换
cancleShareNote(); // 取消共享笔记
shareNote(); // 共享笔记
showDelete(); // 自已的笔记,鼠标悬停时显示删除按钮
deleteNoteContent(); // 删除笔记
changePlayerType(); // 播放器切换(LeTV和老版播放器切换)
intoCourseHomeEvent(); // 点击进入课程主页事件
}
/**
* 初始化播放参数
*/
function initPlayInfo($this) {
recoveryDefault(); // 初始化默认参数
$videoObject = $this;
if (lessonId != $videoObject.attr('_lessonId')|| videoId != $videoObject.attr('_videoId')) {
$('.catalogue').eq(1).attr('loadState', 0);
}
if (lessonId != $videoObject.attr('_lessonId') || videoId != $videoObject.attr('_videoId')) {
$('.catalogue').eq(2).attr('loadState', 0);
}
chapterId = $videoObject.attr('_chapterId');
lessonId = $videoObject.attr('_lessonId');
videoId = $videoObject.attr('_videoId');
var size = parseInt(timeToSec($videoObject.find('.time').text()));
videoSize = isNaN(size) ? null : size;
lessonVideoId = isNotEmpty($videoObject.attr('_lessonVideoId')) ? $videoObject.attr('_lessonVideoId') : null;
$('.current_play').removeClass('current_play');
$videoObject.addClass('current_play');
$chapterObject = $('#chapter-' + chapterId);
if (courseType == 1) { // 进阶式课程
var lessonName = tmFilterTag($videoObject.attr('_name'));
if(typeof($videoObject.attr('_order'))!="undefined"){
$("#lessonOrder").html($videoObject.attr('_order') + "、" + lessonName);
$("#lessonOrder").attr('title', $videoObject.attr('_order') + lessonName);
}
$('#chapterOrder').html(tmFilterTag($chapterObject.attr('_name')));
$('#chapterOrder').attr("title",$('#chapterOrder').text());
} else { // 微课程
var lessonName = tmFilterTag($videoObject.attr('_name'));
$("#lessonOrder").html(lessonName);
$("#lessonOrder").attr('title', lessonName);
$('#chapterOrder').html(tmFilterTag($videoObject.attr('_order')));
$('#chapterOrder').attr("title",$('#chapterOrder').text());
}
//视频时长为0时观看无法记录进度,在此处限制观看视频时长为0的视频(用于限制初始化页面加载视频,手动切换时已前面限制,不会调用本方法)
if($videoObject.attr("_videoSize")=="00:00:00"){
var p = "视频正在转码中,换个时间再来看看吧!";
if(z_locale!=1){
p ="Video is transcoding, another time to look at it .";
}
$.tmDialog.alert({content:p,icon:"warm",fadeout:true,timeout:3,finish:function(ok){}});
return;
}
prelearningNote();// 加载上次当前视频播放信息
loadVideoPointerData();// 加载视频打点数据
rollbackNote();
}
function recoveryDefault() {
clearTimer();// 清除定时器
commitStatus = true;// 讨论讨论提交状态
studiedId = null;// 视频学习记录表Id
studyTotalTime = 0;// 上一个视频累积观看时间
currentPlayTime = null;// 当前视频播放时间
videoSize = null;// 当前视频时长
$("textarea").val("");
loadPreStudyNoteState = true;// 查询学习记录
validateIsJumpChapterStatus = true;// 验证跨章提交状态
$('.videoDotWrap').empty();
}
/**
* 加载上一次学习时间节点
*/
function prelearningNote() {
if (isSignUp()) {
loadPreStudyNote();
if (!isFirstLoad) {
//loadBadgeName();
// getTopNo();
} else {
//upgrade();//徽章是否升级
}
}
// 初始化播放列表状态
initPlayListState();
// 加载视频播放器
initAblePlayer();
// 设置下一节(第次初始化播放器时,绑定下一节按钮的事件)
setNextLesson();
// 限制没有报名的游客
limitNotApply();
//第一次进来没有token,提示
if ($("#csrfToken").val() == "" || $("#csrfToken").val() == null || $("#csrfToken").val() == undefined && $.cookie('csrftoken') == null) {
$.tmDialog.alert({
icon:"warm",
title:zLocale.kindly_remind,
content:zLocale.error_learning_remind,
sureButton:zLocale.sure//确定按钮字
});
tokenFlag = false;
changeWatchState(0);
}
}
function loadPreStudyNote() {
if (!loadPreStudyNoteState) {
return;
}
loadPreStudyNoteState = false;
$.ajax({
type: 'post',
url: jsonPath + '/learning/prelearningNote?time=' + getNowTime(),
data: {
rid: rid,
studentCount: studentCount,
lessonId: lessonId,
PCourseId: PCourseId,
chapterId: chapterId,
lessonVideoId: lessonVideoId,
'userId': userId,
videoId: videoId,
studyStatus : studyStatus
},
success: function (data, textStatus, jqXHR) {
loadPreStudyNoteState = true;
studiedId = data.studiedLessonDto.id;
watchState = data.studiedLessonDto.watchState;
var values = $.cookie(getCookieKey(videoId));
var serviceStudyTotalTime = isEmpty(data.studiedLessonDto.studyTotalTime) ? 0 : parseInt(data.studiedLessonDto.studyTotalTime);
var serviceLearnTime = isNotEmpty(learnTime) ? learnTime : data.studiedLessonDto.learnTime; // 学习笔记跳转到学习页面指定时间
if (isNotEmpty(values)) {
values = values.split('_');
var clientStudyTotalTime = parseInt(values[1]);
if (isEmpty(serviceStudyTotalTime) || serviceStudyTotalTime == 0 || isNaN(serviceStudyTotalTime) || serviceStudyTotalTime < clientStudyTotalTime) {
studyTotalTime = clientStudyTotalTime;
learnTime = isNotEmpty(learnTime) ? learnTime : values[2];
watchState = values[0];
} else {
studyTotalTime = serviceStudyTotalTime;
learnTime = serviceLearnTime;
}
} else {
studyTotalTime = serviceStudyTotalTime;
learnTime = serviceLearnTime;
}
// 上次观看出现异常,手动提交一次
if ($videoObject.find('.withborder_no_tip').length == 1) {
$videoObject.find('.withborder_no_tip').removeClass('withborder_no_tip').addClass('time_ico');
saveDatabaseIntervalTime();
}
},
error: function () {
loadPreStudyNoteState = true;
}
});
}
/**
* 更新视频累计观看时间进度条
*/
var clearProgressbarboxtiper;
var firstLoadShowProgressbarTip = true;
function calculate() {
var size = ((studyTotalTime / videoSize) * 100);
return size > 100 ? 100 : size;
}
/**
* 更新鼠标悬停章节标题时,提示进度信息
*/
function updateProgressbar() {
if (studiedId && videoSize) {
var size;
//token验证不通过的,进度条显示为0
if (tokenFlag != null && !tokenFlag ) {
size = 0
}else{
size = calculate();
}
if (firstLoadShowProgressbarTip) {
//改变进度条长度
$videoObject.find('.progressbar').animate({width: (size) + "%"},1000);
//清除隐藏进度条定时器
clearTimeout(clearProgressbarboxtiper);
//隐藏进度条定时器
clearProgressbarboxtiper = setTimeout(clearProgressbarboxtip, 3000);
firstLoadShowProgressbarTip = false;
} else {
$videoObject.find('.progressbar').css({width: (size) + "%"}, 1000);
}
size = Math.round(size * 100) / 100;
size = size > 95 ? 100 : size;
$videoObject.find('.progressbar_box_tip span').text(zLocale.current_lesson_warch_time+'『' + (size) + '%』');
}
}
/**
* 鼠标悬停显示进度条
*/
function hoverShowprogressbarBoxTip() {
$('.current_play').die('mouseenter').live('mouseenter', function () {
if ($('.progressbar_box_tip').css('display') == 'block') {
return;
}
$('.progressbar_box_tip').fadeIn('fast');
clearTimeout(clearProgressbarboxtiper);
}).mouseleave(function () {
if (!firstLoadShowProgressbarTip) {
clearProgressbarboxtip();
}
});
}
/**
* 隐藏进度条
*/
function clearProgressbarboxtip() {
$('.progressbar_box_tip').fadeOut('slow');
}
/**
* 加载视频打点信息
*/
function loadVideoPointerData() {
if (isEmpty(videoSize))return;
var params = {rid: rid};
if (lessonVideoId) {
params['lessonVideoId'] = lessonVideoId;
} else {
params['lessonId'] = lessonId;
}
params['userId'] = userId;
$.ajax({
async: true,
type: 'post',
url: basePath + '/json/learning/loadVideoPointerInfo?time=' + getNowTime(),
data: params,
success: function (data) {
var videoThemes = data.lessonDtoMap.videoThemeDtos;
var knowledgeCards = data.lessonDtoMap.knowledgeCardDtos;
var allLessonQuestions = "";
if (data.lessonDtoMap.lessonTestQuestionDtos) {
lessonQuestions = data.lessonDtoMap.lessonTestQuestionDtos.split('_')[0];
allLessonQuestions = data.lessonDtoMap.lessonTestQuestionDtos.replace('_', ',');
}
//弹图
var pictureTimerAndUrls = data.lessonDtoMap.popupPictureDtos;
var exam = {};
if (isNotEmpty(allLessonQuestions)) {
var examTimers = allLessonQuestions.split(',');
$.each(examTimers, function (i) {
exam['timeNote'] = examTimers[i];
if (isNotEmpty(examTimers[i])) {
insertPointer('examDot', exam);
}
});
}
if (isNotEmpty(videoThemes)) {
$.each(videoThemes, function () {
insertPointer('themeDot', $(this)[0]);
});
}
if (isNotEmpty(knowledgeCards)) {
$.each(knowledgeCards, function () {
insertPointer('cardDot', $(this)[0]);
});
}
//弹图
var picture = {};
lessonPictures = "";
if(isNotEmpty(pictureTimerAndUrls)){
$.each(pictureTimerAndUrls,function(picKey,picUrl){
lessonPictures += picKey+",";
picture['timeNote'] = picKey;
picture['picUrl'] = picUrl;
if(isNotEmpty(picUrl)){
insertPointer('pictureDot',picture);
}
});
}
showTheme();
showCard();
showExam();
showPicture();
suspendTime();// 视频弹题
},
error: function () {
commitStatus = true;
}
});
}
/**
* 在同一时间段是否已经存在视频打点
*/
function inTimeExistPointerCotainer(time) {
if (time.indexOf(":") < 0) {
return $('#videoDotContainer-' + time).length == 1 ? $('#videoDotContainer-' + time) : false;
}
return $('#videoDotContainer-' + timeToSec(time)).length == 1 ? $('#videoDotContainer-' + timeToSec(time)) : false;
}
/**
* 是否存在视频打点
* @param pointerClass
* @returns {*}
*/
function isNotExistPointer(pointerClass, timeNote) {
var videoDotCotainer = inTimeExistPointerCotainer(timeNote);
var isExistCotainer = videoDotCotainer.length == 1 ? true : false;
var isExistPointer;
if (isExistCotainer) {
isExistPointer = videoDotCotainer.find('.' + pointerClass);
if (isExistPointer.length == 1) {
return isExistPointer;
}
}
return false;
}
/**
* 插入视频打点
* @param pointerType examDot.试题打点 themeDot.主题打点 cardDot.知识卡打点 pictureDot.视频弹图
*/
function insertPointer(pointerClass, data) {
var pointer = $('<span class="videoDot"/>');
//判断是否存在打点
var videoDotCotainer = inTimeExistPointerCotainer(data.timeNote);
var isExistCotainer = videoDotCotainer.length == 1 ? true : false;
pointer.addClass(pointerClass);
if (isExistCotainer) {
var existPointer = isNotExistPointer(pointerClass, data.timeNote);
if (existPointer.length == 1) {
pointer = existPointer;
}
}
var tip;
pointer.attr('id', pointerClass + '_' + data.id);
switch (pointerClass) {
case 'pictureDot':
tip = zLocale.video_popup_picture;
pointer.attr('timeNote',data.timeNote);
pointer.attr('picUrl',data.picUrl);
pointer.attr('title',tip);
break;
case 'examDot':
tip = zLocale.video_tanti;
pointer.attr('timeNote', data.timeNote);
pointer.attr('title', tip);
break;
case 'themeDot':
tip = zLocale.video_topic;
pointer.attr('opid', data.id);
pointer.attr('timeNote', data.timeNote);
pointer.addClass('showTheme');
pointer.attr('content', data.content);
break;
case 'cardDot':
pointer.attr('opid', data.id);
pointer.attr('_title', data.title);
pointer.attr('content', data.content);
tip = zLocale.video_knowcard;
break;
}
var left_ = 0;
if ("pictureDot"==pointerClass) {
left_ = ((parseInt(data.timeNote) / parseInt(videoSize)) * 100);
}else{
left_ = ((parseInt(timeToSec(data.timeNote)) / videoSize) * 100);
}
left_ = left_ > 99 ? 99 : left_;
if (isExistCotainer) {
//是否存在视频打点
if (!isNotExistPointer(pointerClass, data.timeNote)) {
if("pictureDot"==pointerClass){
videoDotCotainer.prepend(pointer);
}else{
videoDotCotainer.append(pointer);
}
}
} else {
videoDotCotainer = $('<div class="videoDotContainer"/>');
videoDotCotainer.attr('id', 'videoDotContainer-' + timeToSec(data.timeNote));
videoDotCotainer.css({left: left_ + '%'});
videoDotCotainer.append(pointer);
$('.videoDotWrap').append(videoDotCotainer);
}
}
function showTheme() {
$('.showTheme').die('click').live('click', function (event) {
var content = $(this).attr('content');
var opid = $(this).attr('opid');
showeThemeTip(content, 'themeDot', opid, tm_posXY(event));
});
}
function showeThemeTip(content, typeClass, opid, position) {
$('.dotCardWrap').find('.dotCardInfoDetail').text(content);
$('.dotCardWrap').find('.dotInfo_editBtn').addClass(typeClass + "Edit").attr('opid', opid);
$('.dotCardWrap').find('.dotInfo_delBtn').addClass(typeClass + "Del").attr('opid', opid);
if(position.x < 120){
$('.dotCardWrap').css({'left': position.x - 30, 'bottom': 50});
$(".dotCardArrow").hide();
}else{
$('.dotCardWrap').css({'left': position.x - 120, 'bottom': 50});
}
$('.dotCardWrap').fadeIn('fast');
hideTip();
}
function showCard() {
$('.cardDot').die('click').live('click', function (event) {
var opid = $(this).attr('opid');
var title = $(this).attr('_title');
var content = $(this).attr('content');
showeCardTip(title, content, 'cardDot', opid, tm_posXY(event));
});
}
function showeCardTip(title, content, typeClass, opid, position) {
var titleObj = $('<span>'+zLocale.subject+'</span>');
var contentObj = $('<span>'+zLocale.content+'</span>');
$('.dotCardWrap02').find('.dotCardInfoDetail').eq(0).html(titleObj);
$('.dotCardWrap02').find('.dotCardInfoDetail').eq(1).html(contentObj);
$('.dotCardWrap02').find('.dotCardInfoDetail').eq(0).append(title);
$('.dotCardWrap02').find('.dotCardInfoDetail').eq(1).append(content);
$('.dotCardWrap02').find('.dotInfo_editBtn').addClass(typeClass + "Edit").attr('opid', opid);
$('.dotCardWrap02').find('.dotInfo_delBtn').addClass(typeClass + "Del").attr('opid', opid);
if(position.x < 120){
$('.dotCardWrap02').css({'left': position.x - 30, 'top': -67});
}else{
$('.dotCardWrap02').css({'left': position.x - 120, 'top': -67});
}
$('.dotCardWrap02').fadeIn('fast');
hideTip();
}
function hideTip() {
$('.dotCardWrap,.dotCardWrap02').die('click').live('mouseleave', function () {
$(this).fadeOut();
}).live('mouseenter', function () {
});
}
/**
* 节视频列表切换videoToggle
*/
function videoToggle() {
$('.video').die('click').live('click', function () {
var $this = $(this);
hideQrcode();
if (isEmpty($this.attr('_videoId'))) {
$.tmDialog.alert({
content: zLocale.not_upload_video,
icon: "warm",
fadeout: true,
timeout: 3,
sureButton:zLocale.sure,//确定按钮字
cancleButton:zLocale.cancel,//取消按钮字
finish: function (ok) {
}
});
return;
}
if (videoId == $this.attr('_videoId')) {
ablePlayerX('mediaplayer').seek(0);
return;
}
//视频时长为0时观看无法记录进度,在此处限制观看视频时长为0的视频
if($this.attr("_videoSize")=="00:00:00"){
var p = "视频正在转码中,换个时间再来看看吧!";
if(z_locale!=1){
p ="Video is transcoding, another time to look at it .";
}
$.tmDialog.alert({content:p,icon:"warm",fadeout:true,timeout:3,finish:function(ok){}});
return;
}
if (limitWatchTime()) {
//如果学生该课程为已结束课程,则不做数据库记录,在saveDatabaseIntervalTime里面做控制,by wyj,2016/6/4
saveDatabaseIntervalTime(1, $this);
}
vId = $this.attr('_videoId');
});
}
/**
* 初始化播放列表状态
*/
var preVideo;
function initPlayListState() {
// 去掉上一个播放状态的样式
if (preVideo) {
if (isSignUp()) {
if (preVideo.attr('watchState') == 1) {
preVideo.find('.time_ico').removeClass('time_ico').addClass('time_ico3');
} else if (preVideo.attr('watchState') == 2) {
preVideo.find('.time_ico').unbind('hover');
preVideo.find('.time_ico').removeClass('time_ico').addClass('time_ico_half');
$(".time_ico_half").tmTip({color: "black", arrow: 'topMiddle', width: '100px'});
} else {
preVideo.find('.time_ico').removeClass('time_ico').addClass('time_ico1');
}
preVideo.find('.progressbar_box_tip').remove();
preVideo.find('.progressbar_box').remove();
} else {
preVideo.find('.time_ico').removeClass('time_ico').addClass('time_ico1');
}
}
$videoObject.find('.time_ico3,.time_ico1,.time_ico_half').unbind('hover');
$videoObject.find('.time_ico3,.time_ico1,.time_ico_half').removeClass().addClass('time_ico').addClass('fl');
preVideo = $videoObject;
if (isSignUp()) {
var progressbar_box = $('<div class="progressbar_box"><div class="progressbar"></div></div><div class="progressbar_box_tip"><span>'+zLocale.history_loading+'</span></div>');
progressbar_box.appendTo($videoObject);
//显示观看累计时间正在加载
setTimeout(updateProgressbar, 3000);
//显示累计观看时间
hoverShowprogressbarBoxTip();
}
}
/**
* 是否报名
*/
function isSignUp() {
return studentCount == 1;
}
function isNotSignUp() {
return isSignUp() ? false : true;
}
/**
* 从课程主页进入,弹出此提示,用于引导用户不再从此进入,#张立坤注
*/
function validateIntoPoistion() {
if ($('#intoType').val() == 2) {
$('#IntoTypeTip').show();
}
}
var isFirstLoad;
/**
* 初始化播放器
*/
function initAblePlayer() {
firstLoadShowProgressbarTip = true;
// 计算当前播放视频坐标,目录列表自动滚动到可见位置(是否是中间,待确认),#张立坤注
var xy = $videoObject.offset();
if (isEmpty(isFirstLoad) && xy) {
$('.catalogue_ul1').animate({scrollTop: xy.top - $('#Tabs_1').find('ul').height()}, 1000);
reSizePlayer(getPlayerSize().mW, getPlayerSize().mh);
isFirstLoad = true;
}
$("#mediaplayer").remove();//删除视频元素
$("#mediaplayer_parent").html("<div id='mediaplayer'></div>");//重新添加存放视频的div
$("#mediaplayer").css({width:getPlayerSize().mW,height:getPlayerSize().mh});
// 针对本学期运行的复旦军理课限制弹幕使用
var commentToggle = (courseId == 2000624 ? false : true) ;
//JIANGJH 2015/9/14
if($('#schoolId').val() == -1){
commentToggle = false;
}
//END JIANGJH
// 加载播放器代码
$("#mediaplayer").Ableplayer({
// host: "http://base1.zhihuishu.com/able-commons/",
id: videoId,
// width: getPlayerSize().mW,
// height: getPlayerSize().mh,
// hide: true,
// primary: 'flash',
// startparam: 'start',
// autostart: true,
// adtime: 10,
// userid: userId,
// username: userName,
// enablecommentsend: commentToggle,
// enablecommentshow: commentToggle,
// image: '',
//// defaltplayertype: $('#changePlayerType').attr('type') // 配置初始使用的播放器类型. 默认值:"1" 乐视播放器:"2" jwplayer播放器:"3" , 如果乐视没有转码完成或者上传失败,就自动使用jwplayer播放
// enableChangePlayerButton: true //是否显示 切换播放器 按扭 默认false
}, {
onReady: function () {// 初始化完成
recordPlayInfo() ;
}, onComplete: function () {// 播放完成
totalStudyTime(), clearTimer(), saveCacheIntervalTime(), saveDatabaseIntervalTime();
}, onPause: function () {
clearTimer(), saveCacheIntervalTime();// 自动保存一次缓存
}, onPlay: function () {
$("#codehint_box").hide();
totalStudyTimeAndTimingDataBaseEvent(), suspendTime(), getVideoSize();
//console.log("onPlay");
}
});
vId = videoId;
}
/**
* 上报播放统计信息
*/
function recordPlayInfo() {
// 与主业务逻辑无关,异常捕获掉
try {
var chapterName = "" ;
if($chapterObject && $chapterObject.length > 0) {
var $title = $chapterObject.find(".catalogue_title") ;
if($title && $title.length > 0) chapterName = $title.text() ;
}
// 向视频组发送消息,用于统计
ablePlayerX("mediaplayer").addCourseInfo({
courseId:courseId,
courseName:$("#courseName").val(),
recruitId:rid,
chapterId:chapterId,
chapterName:chapterName,
userId:userId,
userName:userName,
schoolId:$("#schoolId").val()
});
} catch(e) {
if(console && console.log) console.log(e) ;
}
}
function changePlayerType() {
$('#changePlayerType').live('click', function () {
var $this = $(this);
var type = $this.attr('type');
$this.attr('type', (type == 2) ? 3 : 2);
learnTime = currentPlayTime;
try {
$.Ableplayer.changePlayerType($this.attr('type'), function () {
clearTimer(), initAblePlayer();
});
} catch (e) {
//alert(e);
}
});
}
function getVideoSize() {
// var videoSize1 = parseInt(ablePlayerX("mediaplayer").getDuration());
//
// if (isEmpty(videoSize) || videoSize == 0 || (isNotEmpty(videoSize) && $.isNumeric(videoSize1) && videoSize != 0 && videoSize != videoSize1)) {
// videoSize = videoSize1;
// var params = {'videoTimeDto.videoId': videoId, 'videoTimeDto.videoTime': videoSize, 'courseId': courseId};
// $videoObject.find('.time').text(tm_hhmmss(videoSize));
// $.ajax({async: true, type: 'post', url: jsonPath + '/lessonVideo/updateVideoTime?v=' + getNowTime(), data: params});
loadVideoPointerData();// 加载视频打点数据
// }
}
/**
* 限制微课程观看视频,未报名用户只能观看视频的三分之一
*/
function limitWatchTime() {
if (isNotSignUp() && isMinCourse()) {
stopPlayVideo(); //停止试看
$(".entirePayDiv").fadeIn("slow");
return false;
}
return true;
}
function isMinCourse() {
return courseType == 2;
}
//开始累计观看时间
function totalStudyTime() {
//tokenFlag验证不通过的,定时器时间不增加
if (tokenFlag != null && !tokenFlag) {
studyTotalTime = 0;
palyTimes = 0;
}
if (studyStatus != null && studyStatus == 1){
}else{
studyTotalTime += 5; // 定时器周期是5秒,所以每次加5
playTimes += 5 ; // 累计本次播放时长,用于计算招生纬度累计观看时长
}
updateProgressbar(); // 更新进度
}
/**
* 开始统计学习时间和绑定定时保存数据库事件
*/
function totalStudyTimeAndTimingDataBaseEvent() {
if (isSignUp()) {
// 获取上次学习时间,进度条自动进到指定时间位置
if (isNotEmpty(learnTime)) {