-
Notifications
You must be signed in to change notification settings - Fork 2
/
backbone.api.vimeo.js
72 lines (55 loc) · 1.67 KB
/
backbone.api.vimeo.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
/* Backbone API: Vimeo
* Source: https://github.com/backbone-api/vimeo
*
* 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: http://developer.vimeo.com/apis/simple
// Constants
var api = "http://vimeo.com/api/v2"
// 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 Vimeo = new Backbone.Model({
"appId": false,
"uri": false
});
// Namespace definition
Vimeo.Models = {};
Vimeo.Collections = {};
Vimeo.Views = {};
// Models
// JSONP requests for all direct API requests
Vimeo.Model = Model.extend({
sync : function( method, model, options ) {
options.dataType = 'jsonp';
return Backbone.sync( method, model, options );
}
});
//
Vimeo.Models.Video = Vimeo.Model.extend({
url: function(){ return api + "/video/"+ this.id +".json" },
defaults : {
},
parse: function( data ){
//console.log("Vimeo.Models.Video: ", data);
// validate data?
return data[0];
}
});
// Store in selected namespace(s)
//APP = window.APP || (APP = { Models: {}, Collections: {}, Views: {} });
if( _.isUndefined(Backbone.API) ) Backbone.API = {};
Backbone.API.Vimeo = Vimeo;
// alias APP.API
if( typeof APP != "undefined" && (_.isUndefined( APP.API) || _.isUndefined( APP.API.Vimeo) ) ){
APP.API = APP.API || {};
APP.API.Vimeo = Backbone.API.Vimeo;
}
// Shortcut
if(typeof window.Vimeo == "undefined"){
window.Vimeo = Vimeo;
}
})(this._, this.Backbone);