-
Notifications
You must be signed in to change notification settings - Fork 0
/
vid.js
123 lines (106 loc) · 4.04 KB
/
vid.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
$(function () {
//ADD YouTube vid ID to db
//----------------------------------------------------------------------------------------------------------------//
$(document).on("keypress", "#addYouTubeVidID_Input", function (e) {
if (e.which == 13) {
var VidIDField = '#addYouTubeVidID_Input';
var VidID = $(VidIDField).val();
if (VidID.length != 0) {
$.ajax({
url: window.location.pathname + "home/yt_submit",
type: 'GET',
data: {'VidID': VidID},
success: function (result) {
$('#addYouTubeVidID_Input').val(result);
revertSubmitButton();
},
failure: function () {
$('#addYouTubeVidID_Input').value('Failed');
revertSubmitButton();
}
});
}
return false; //<---- Add this line
}
});
//show Login
//----------------------------------------------------------------------------------------------------------------//
$('#ADD-toggle').on('click', function (e) {
if ( $("#addyoutubevidid_form").hasClass('gone')) {
appear();
} else {
dissapear();
}
$("#addyoutubevidid_form").focus();
e.preventDefault();
});
//load initial vidset
//----------------------------------------------------------------------------------------------------------------//
$(document).ready(function () {
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
})
//
$(document).on("click", ".loadTrigger", function (e) {
$id = event.target.id;
$('#'+$id).closest("a").find(".video").hide();
onYouTubeIframeAPIReady(event.target.id);
e.preventDefault();
})
//Focus moves to the input when clicking the ADD button
$(document).on("click", "#ADD-toggle", function (e) {
$("#addYouTubeVidID_Input").focus();
});
//load more vid covers on scroll
//----------------------------------------------------------------------------------------------------------------//
$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height())
{
$.ajax({
url: window.location.pathname + "home/videoset",
type: 'POST',
success: function (result) {
$('.img-list ').append(result);
}
});
}
});
});
//----------------------------------------------------------------------------------------------------------------//
//show/hide ADD input
function dissapear() {
$("#addyoutubevidid_form").animate({opacity: '0'});
$("#addyoutubevidid_form").addClass('gone');
}
function appear() {
$("#addyoutubevidid_form").animate({opacity: '100'});
$("#addyoutubevidid_form").removeClass('gone');
}
//reset the ADD button text after 2 seconds
function revertSubmitButton() {
setTimeout(function () {
$('#addyoutubevidid_form').addClass('gone');
$('#addyoutubevidid_form').removeAttr('style');
$('#addYouTubeVidID_Input').val('');
}, 2000);
}
//----------------------------------------------------------------------------------------------------------------//
//youtube api
function onYouTubeIframeAPIReady(id) {
player1 = new YT.Player(id, {
height: '237',
width: '317',
videoId: id,
events: {
'onReady': onPlayerReady
}
});
}
// The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
//----------------------------------------------------------------------------------------------------------------//