Link demo blog with stacosys backend
This commit is contained in:
parent
4e6c59362c
commit
0bb872162b
3 changed files with 25 additions and 61 deletions
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
<!-- cosysnode dependencies -->
|
<!-- cosysnode dependencies -->
|
||||||
<script src="js/mustache.js"></script>
|
<script src="js/mustache.js"></script>
|
||||||
<script src="js/cosysnode.js"></script>
|
<script src="js/stacosys.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -124,18 +124,18 @@ instance d'ici peu.</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- comments container -->
|
<!-- stacosys comments container -->
|
||||||
<div id="cosys-comments">Chargement...</div>
|
<div id="stacosys-comments">Chargement...</div>
|
||||||
<script id="template" type="x-tmpl-mustache">
|
<script id="stacosys-template" type="x-tmpl-mustache">
|
||||||
{{#comments}}
|
{{#data}}
|
||||||
<hr>
|
<hr>
|
||||||
<div class="inline">
|
<div class="inline">
|
||||||
<img src="http://www.gravatar.com/avatar/{{gravatar}}.jpg" style="float:left; margin-right:10px" height="32" width="32">
|
<img src="http://www.gravatar.com/avatar/{{avatar}}.jpg" style="float:left; margin-right:10px" height="32" width="32">
|
||||||
<span class="title">{{author}}</span>
|
<span class="title">{{author}}</span>
|
||||||
<span> - {{date}}</span>
|
<span> - {{date}}</span>
|
||||||
</div>
|
</div>
|
||||||
<p>{{preview}}</p>
|
<p>{{content}}</p>
|
||||||
{{/comments}}
|
{{/data}}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
// Create the XHR object.
|
|
||||||
function createCORSRequest(method, url) {
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
if ("withCredentials" in xhr) {
|
|
||||||
// XHR for Chrome/Firefox/Opera/Safari.
|
|
||||||
xhr.open(method, url, true);
|
|
||||||
} else if (typeof XDomainRequest != "undefined") {
|
|
||||||
// XDomainRequest for IE.
|
|
||||||
xhr = new XDomainRequest();
|
|
||||||
xhr.open(method, url);
|
|
||||||
} else {
|
|
||||||
// CORS not supported.
|
|
||||||
xhr = null;
|
|
||||||
}
|
|
||||||
return xhr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper method to parse the title tag from the response.
|
|
||||||
function getTitle(text) {
|
|
||||||
return text.match('<title>(.*)?</title>')[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make the actual CORS request.
|
|
||||||
function makeCorsRequest() {
|
|
||||||
// All HTML5 Rocks properties support CORS.
|
|
||||||
var url = 'http://sitea.fr:3000/comments';
|
|
||||||
|
|
||||||
var xhr = createCORSRequest('GET', url);
|
|
||||||
if (!xhr) {
|
|
||||||
alert('CORS not supported');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response handlers.
|
|
||||||
xhr.onload = function() {
|
|
||||||
var text = xhr.responseText;
|
|
||||||
//var title = getTitle(text);
|
|
||||||
alert('Response from CORS request to ' + url + ': ' + text);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onerror = function() {
|
|
||||||
alert('Woops, there was an error making the request.');
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send();
|
|
||||||
}
|
|
|
@ -1,8 +1,13 @@
|
||||||
// Released under Apache license
|
// Released under Apache license
|
||||||
// Copyright (c) 2015 Yannic ARNOUX
|
// Copyright (c) 2015 Yannic ARNOUX
|
||||||
|
|
||||||
|
STACOSYS_URL = 'http://127.0.0.1:8000';
|
||||||
|
STACOSYS_TOKEN = '9fb3fc042c572cb831005fd16186126765140fa2bd9bb2d4a28e47a9457dc26c';
|
||||||
|
//STACOSYS_PAGE = 'blogduyax.madyanne.fr/mes-applications-pour-blackberry.html'
|
||||||
|
STACOSYS_PAGE = 'blogduyax.madyanne.fr/migration-du-blog-sous-pelican.html'
|
||||||
|
|
||||||
// Create the XHR object.
|
// Create the XHR object.
|
||||||
function createCORSRequest(method, url) {
|
function stacosys_get_cors_request(method, url) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
if ("withCredentials" in xhr) {
|
if ("withCredentials" in xhr) {
|
||||||
// XHR for Chrome/Firefox/Opera/Safari.
|
// XHR for Chrome/Firefox/Opera/Safari.
|
||||||
|
@ -18,9 +23,13 @@ function createCORSRequest(method, url) {
|
||||||
return xhr;
|
return xhr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cosysload() {
|
function stacosys_get_url() {
|
||||||
var url = 'http://cosysnode.madyanne.fr:3000/comments';
|
return STACOSYS_URL + '/comments?token=' + STACOSYS_TOKEN + '&url=' + STACOSYS_PAGE;
|
||||||
var xhr = createCORSRequest('GET', url);
|
}
|
||||||
|
|
||||||
|
function stacosys_load() {
|
||||||
|
var url = stacosys_get_url();
|
||||||
|
var xhr = stacosys_get_cors_request('GET', url);
|
||||||
if (!xhr) {
|
if (!xhr) {
|
||||||
alert('CORS not supported');
|
alert('CORS not supported');
|
||||||
return;
|
return;
|
||||||
|
@ -29,9 +38,10 @@ function cosysload() {
|
||||||
// Response handlers.
|
// Response handlers.
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
var jsonResponse = JSON.parse(xhr.responseText);
|
var jsonResponse = JSON.parse(xhr.responseText);
|
||||||
var template = document.getElementById('template').innerHTML;
|
console.log(jsonResponse);
|
||||||
|
var template = document.getElementById('stacosys-template').innerHTML;
|
||||||
var rendered = Mustache.render(template, jsonResponse);
|
var rendered = Mustache.render(template, jsonResponse);
|
||||||
document.getElementById('cosys-comments').innerHTML = rendered;
|
document.getElementById('stacosys-comments').innerHTML = rendered;
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.onerror = function() {
|
xhr.onerror = function() {
|
||||||
|
@ -40,4 +50,4 @@ function cosysload() {
|
||||||
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
window.onload = cosysload;
|
window.onload = stacosys_load;
|
Loading…
Add table
Reference in a new issue