-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackbone.api.youtube.js
More file actions
64 lines (52 loc) · 1.53 KB
/
Copy pathbackbone.api.youtube.js
File metadata and controls
64 lines (52 loc) · 1.53 KB
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
/* Backbone API: Youtube
* Source: https://github.com/backbone-api/youtube
*
* Created by Makis Tracend (@tracend)
* Distributed through [Makesites.org](http://makesites.org)
* Released under the [MIT license](http://makesites.org/licenses/MIT)
*/
(function(_, Backbone) {
// API reference: https://developers.google.com/youtube/v3
// Constants
var api = "https://gdata.youtube.com"
// Support backbone-app (if available)
var Model = ( typeof APP != "undefined" && !_.isUndefined( APP.Model) ) ? APP.Model : Backbone.Model;
// Base model - mainly used for setup options
var Youtube = new Backbone.Model({
"appId": false,
"uri": false
});
// Namespace definition
Youtube.Models = {};
Youtube.Collections = {};
Youtube.Views = {};
// Models
//
Youtube.Models.Video = Model.extend({
url: function(){
return api +"/feeds/api/videos/"+ this.id +"?"+ $.param( this.params )
},
params : {
v : 2,
alt: "json"
},
parse: function( data ){
console.log("Youtube.Models.Video: ", data);
// validate data?
return data.entry;
}
});
// Fallbacks
//APP = window.APP || (APP = { Models: {}, Collections: {}, Views: {} });
if( _.isUndefined(Backbone.API) ) Backbone.API = {};
Backbone.API.Youtube = Youtube;
// alias APP.API
if( typeof APP != "undefined" && (_.isUndefined( APP.API) || _.isUndefined( APP.API.Youtube) ) ){
APP.API = APP.API || {};
APP.API.Youtube = Backbone.API.Youtube;
}
// Shortcut
if(typeof window.Youtube == "undefined"){
window.Youtube = Youtube;
}
})(this._, this.Backbone);