-
Notifications
You must be signed in to change notification settings - Fork 60
/
youtuberss.html
189 lines (137 loc) · 5.5 KB
/
youtuberss.html
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
<script type="text/javascript">
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// pageChanged & sizeChanged functions are needed in every model file
// other functions for model should also be in here to avoid conflicts
var youtuberss = new function() {
var $pageContents,
$panel,
$resultsHolder,
searchTerm;
// function called every time the page is viewed after it has initially loaded
this.pageChanged = function() {
};
// function called every time the size of the LO is changed
this.sizeChanged = function() {
if (x_browserInfo.mobile == false) {
var $panel = $("#pageContents .panel");
$panel.height($x_pageHolder.height() - parseInt($x_pageDiv.css("padding-top")) * 2 - parseInt($panel.css("padding-top")) * 2 - 5);
}
};
this.init = function() {
$pageContents = $("#pageContents");
$panel = $("#pageContents .panel");
$resultsHolder = $pageContents.find("#resultsHolder");
$("#loadingSpinner p").html(x_getLangInfo(x_languageData.find("fetchResults")[0], "label", "Fetching results..."));
var panelWidth = x_currentPageXML.getAttribute("panelWidth");
if (panelWidth == "Full") {
$("#pageContents .right div:first").appendTo($("#pageContents"));
$("#pageContents .splitScreen").remove();
} else {
$("#textHolder").html(x_addLineBreaks(x_currentPageXML.getAttribute("text")));
if (panelWidth == "Small") {
$("#pageContents .splitScreen").addClass("large");
} else if (panelWidth == "Medium") {
$("#pageContents .splitScreen").addClass("medium");
} else {
$("#pageContents .splitScreen").addClass("small");
}
}
$.ajax({
async:false,
type:'GET',
url:"https://apis.google.com/js/client.js",
data:null,
dataType:'script'
}).success( function(){
window.setTimeout(youtuberss.loadAPI, 500);
});
}
this.loadAPI = function(){
//gapi.client.setApiKey('ENTER YOUR KEY HERE');
gapi.client.setApiKey(x_youtube_api_key);
gapi.client.load('youtube', 'v3', function() {
youtuberss.fetchResults();
});
};
this.fetchResults = function(){
searchTerm = x_currentPageXML.getAttribute("url");
var searchCount = x_currentPageXML.getAttribute("results");
var request = gapi.client.youtube.search.list({
q: searchTerm,
part: 'snippet',
maxResults: searchCount,
type: 'video',
safeSearch: 'strict'
});
request.execute(function(response) {
// if language attributes aren't in xml will have to use english fall back
var resultsTxt = x_currentPageXML.getAttribute("resultsTxt");
if (resultsTxt == undefined) {
resultsTxt = "Youtube results for term";
}
var apiErrorMesg = x_currentPageXML.getAttribute("apiErrorMesg");
if (apiErrorMesg == undefined) {
apiErrorMesg = "The Youtube API returned the following error: \"{0}\" <br>If no API key is set, ask your admin to set up a key in api_keys.php (see api_keys.dist.php for a template).";
}
clearTimeout(x_timer);
$("#loadingSpinner").hide();
if (response.code !== undefined)
{
apiErrorMesg = apiErrorMesg.replace("{0}", response.message);
resultsHolder = '<div><p>' + apiErrorMesg + '</p></div>';
}
else {
var resultsHolder = "";
$pageContents.find("#headerHolder").html("<h3>" + resultsTxt + " '" + searchTerm + "'</h3>");
if (response.pageInfo && response.pageInfo.totalResults > 0) { //we have results
$.each(response.items, function (index, item) {
if (x_browserInfo.iOS == true || x_browserInfo.mobile) {
hyperlink = '<a href="https://www.youtube.com/watch?v=' + item.id.videoId + '">' + item.snippet.title + '</a>';
} else {
hyperlink = '<a target="_blank" href="https://www.youtube.com/watch?v=' + item.id.videoId + '">' + item.snippet.title + '</a>';
}
resultsHolder += '<div><img src="' + item.snippet.thumbnails.default.url + '" alt="' + item.snippet.description + ', thumbnail" />';
resultsHolder += '<p>' + hyperlink + '</br>';
resultsHolder += item.snippet.description + '</p></div>';
});
} else {
resultsHolder = '<div><p>' + x_getLangInfo(x_languageData.find("noResults")[0], "label", "No results returned") + '</p></div>';
}
}
$resultsHolder
.html(resultsHolder)
.find("div:even").addClass("shadedDiv");
});
this.sizeChanged();
x_pageLoaded();
}
this.init();
};
</script>
<div id="pageContents">
<div class="splitScreen">
<div id="textHolder" class="left" tabindex="1"></div>
<div id="youtuberssHolder" class="right">
<div class="panel">
<div id="loadingSpinner"><div class="spinner"></div><p></p></div>
<div id="headerHolder"></div>
<div id="resultsHolder"></div>
</div>
</div>
</div>
</div>