-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
executable file
·68 lines (59 loc) · 2.47 KB
/
Copy pathcustom.js
File metadata and controls
executable file
·68 lines (59 loc) · 2.47 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
Handlebars.registerHelper('lte', function (v1, v2, options) {
if (v1 <= v2) {
return options.fn(this);
}
return options.inverse(this);
});
$(document).ready(function() {
var templateArticleFn = Handlebars.compile($("#template-article").html());
Gitana.connect({
"clientKey": "<%=clientKey%>",
"clientSecret": "<%=clientSecret%>",
"username": "<%=username%>",
"password": "<%=password%>",
"baseURL": "<%=baseURL%>",
"application": "<%=application%>"
}, function (err) {
if (err) {
var errorText = "An error occurred while attempting to connect to the Cloud CMS API";
console.error(errorText, err);
alert(errorText + "\rPlease check the console error log.");
return;
}
this.datastore("content").readBranch("master").then(function() {
var query = {
"_type": "custom:article"
};
var pagination = {
"sort": {
"_system.created_on.ms": -1
}
};
this.queryNodes(query, pagination).each(function() {
this.coverURL = "/preview/" + this.getId() + "-preview.jpg?repository=" + this.getRepositoryId() + "&branch=" + this.getBranchId() + "&node=" + this.getId() + "&size=300&attachment=default";
this.downloadURL = "/static/" + this.getId() + "-image.jpg?repository=" + this.getRepositoryId() + "&branch=" + this.getBranchId() + "&node=" + this.getId() + "&attachment=default";
// ensure some defaults exists
if (typeof(this.title) === "undefined") {
this.title = "Sample title";
}
if (typeof(this.body) === "undefined") {
this.body = "Sample body";
}
if (typeof(this.rating) === "undefined") {
this.rating = 3;
}
if (typeof(this.heading) === "undefined") {
this.heading = "Sample heading";
}
if (typeof(this.summary) === "undefined") {
this.summary = "Sample summary";
}
if (typeof(this.author) === "undefined") {
this.author = "Sample author";
}
var html1 = templateArticleFn({article: this});
$(".page-body").append(html1);
});
});
});
});