-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackbone.api.behance.js
More file actions
118 lines (89 loc) · 2.93 KB
/
backbone.api.behance.js
File metadata and controls
118 lines (89 loc) · 2.93 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
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
/* Backbone API: Behance
* Source: https://github.com/backbone-api/behance
*
* 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://www.behance.net/dev/api/endpoints/
// Constants
var api = "http://www.behance.net/v2"
// Support backbone-app (if available)
var Model = ( typeof APP != "undefined" && !_.isUndefined( APP.Model) ) ? APP.Model : Backbone.Model;
var Collection = ( typeof APP != "undefined" && !_.isUndefined( APP.Collection) ) ? APP.Collection : Backbone.Collection;
// Base model - mainly used for setup options
var Behance = new Backbone.Model({
"key": null,
"api": api
// "uri": false
});
// Namespace definition
Behance.Models = {};
Behance.Collections = {};
Behance.Views = {};
// Models
// JSONP requests for all direct API requests
Behance.Model = Model.extend({
sync : function( method, model, options ) {
options.dataType = 'jsonp';
return Backbone.sync( method, model, options );
}
});
Behance.Collection = Collection.extend({
sync : function( method, model, options ) {
options.dataType = 'jsonp';
return Backbone.sync( method, model, options );
}
});
//
Behance.Models.Project = Behance.Model.extend({
// url: function(){ return api + "/projects/"+ this.id +".json" },
url: function(){
var url = Behance.get("api") + "/projects/"+ this.get("id") +"?api_key="+ Behance.get("key");
console.log("Url" + url);
return url;
},
defaults : {
},
parse: function( data ){
// console.log("Behance.Models.Project: ", data);
// validate data?
return data[0];
}
});
Behance.Collections.Projects = Behance.Collection.extend({
model: Behance.Models.Project,
// url: "http://www.behance.net/v2/users/ryndel/projects?tags=monkey5&api_key="+ config.behance.key +"&callback=?",
url: function(){
var url = Behance.get("api") + "/users/"+ this.options.user + "/projects?api_key="+ Behance.get("key");
// console.log( this.options );
return url;
},
options: {
user: null
},
initialize: function(models, options){
options = options || {};
_.extend( this.options, options);
return Behance.Collection.prototype.initialize.apply(this, arguments);
},
parse: function( data ){
//console.log( data );
return (data.projects) ? data.projects : data;
}
});
// Store in selected namespace(s)
//APP = window.APP || (APP = { Models: {}, Collections: {}, Views: {} });
if( _.isUndefined(Backbone.API) ) Backbone.API = {};
Backbone.API.Behance = Behance;
// alias APP.API
if( typeof APP != "undefined" && (_.isUndefined( APP.API) || _.isUndefined( APP.API.Behance) ) ){
APP.API = APP.API || {};
APP.API.Behance = Backbone.API.Behance;
}
// Shortcut
if(typeof window.Behance == "undefined"){
window.Behance = Behance;
}
})(this._, this.Backbone);