-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
67 lines (57 loc) · 1.79 KB
/
main.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
/**
* @module ui/main.reel
* @requires montage/ui/component
*/
var Component = require("montage/ui/component").Component;
/**
* @class Main
* @extends Component
*/
exports.Main = Component.specialize(/** @lends Main# */ {
constructor: {
value: function Main() {
this.super();
var hostname = this.getParameterByName('hostname');
if (hostname) {
this.hostname = hostname;
}
}
},
hostname: {
value: 'demo.wp-api.org'
},
posts: {
value: null
},
enterDocument: {
value: function (firstTime) {
var self = this;
if (firstTime) {
this.templateObjects.wordpressConnector.queryPosts('featured').then(function (result) {
self.posts = result.map(function (post) {
post.better_featured_image = post.better_featured_image || post.featured_image || {};
post.better_featured_image.source_url = post.better_featured_image.source || post.better_featured_image.source_url || '../../assets/images/default.jpg';
return post;
});
})
}
}
},
getParameterByName: {
value: function (name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) {
return null;
} else if (!results[2]) {
return '';
} else {
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
}
},
});