Commit ff7c4e6e authored by Martin Lees's avatar Martin Lees
Browse files

Fixed the front page display errors

parent d9dbc5a9
......@@ -109,6 +109,7 @@ class Steempress_sp_Public {
if (!isset($options["twoway"]))
$options["twoway"] = "off";
......@@ -122,6 +123,7 @@ class Steempress_sp_Public {
$payout = "";
$data = "";
$comments = "";
$front_page = "";
if (sizeof($username) == 1 and sizeof($permlink) == 1 and sizeof($tag) == 1) {
......@@ -129,18 +131,17 @@ class Steempress_sp_Public {
$permlink = $permlink[0];
$tag = $tag[0];
$data = "<div id=\"steempress_sp_username\" style=\"display: none;\">" . $username . "</div>";
$data .= "<div id=\"steempress_sp_permlink\" style=\"display: none;\">" . $permlink . "</div>";
$data .= "<div id=\"steempress_sp_tag\" style=\"display: none;\">" . $tag . "</div>";
$data = "<div name=\"steempress_sp_username\" style=\"display: none;\">" . $username . "</div>";
$data .= "<div name=\"steempress_sp_permlink\" style=\"display: none;\">" . $permlink . "</div>";
$data .= "<div name=\"steempress_sp_tag\" style=\"display: none;\">" . $tag . "</div>";
$payout = "<div id='steempress_sp_price'>0.000$</div>";
$payout = "<div name='steempress_sp_price'>0.000$</div>";
if (!is_front_page())
$comments = "<br/><div name='steempress_sp_comments'></div>";
// comment zone
$comments = "<br/><div id='steempress_sp_comments'></div>";
}
return $content . $data . $payout . $comments;
return $content . $data . $payout . $comments.$front_page;
} else
return $content;
......
......@@ -2,48 +2,77 @@
(function( $ ) {
'use strict';
// Create the XHR object.
function createCORSRequest() {
var url = "http://localhost:8002"
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open("POST", url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open("POST", url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
function post_request(username, permlink, tag, steempress_sp_price, steempress_sp_comment)
{
var xhr = createCORSRequest();
if (steempress_sp_comment === null)
var params = "username=" + username + "&permlink=" + permlink + "&tag=" + tag + "&display_comment=false";
else
var params = "username=" + username + "&permlink=" + permlink + "&tag=" + tag + "&display_comment=true";
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
if (!xhr) {
return;
}
xhr.steempress_sp_price = steempress_sp_price;
xhr.steempress_sp_comment = steempress_sp_comment;
xhr.username = username;
xhr.permlink = permlink;
// Response handlers.
xhr.onload = function () {
var data = JSON.parse(xhr.responseText);
this.steempress_sp_price.innerHTML = data.payout;
if (this.steempress_sp_comment !== null)
this.steempress_sp_comment.innerHTML = data.comments;
};
xhr.send(params);
}
function load_steem_capabilities() {
const username = $("#steempress_sp_username")[0].innerText;
const permlink = $("#steempress_sp_permlink")[0].innerText;
const tag = $("#steempress_sp_tag")[0].innerText;
// 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;
}
const usernames = document.getElementsByName("steempress_sp_username");
const permlinks = document.getElementsByName("steempress_sp_permlink");
const tags = document.getElementsByName("steempress_sp_tag");
const front_page = (document.getElementsByName("steempress_sp_comments").length === 0);
var steempress_sp_prices = document.getElementsByName("steempress_sp_price");
var steempress_sp_comments = document.getElementsByName("steempress_sp_comments");
var url = "http://localhost:8002";
for (var i = 0; i < usernames.length; i++) {
var xhr = createCORSRequest('POST', url);
var params = "username="+username+"&permlink="+permlink+"&tag="+tag;
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
if (!xhr) {
return;
}
var username = usernames[i].innerText;
var permlink = permlinks[i].innerText;
var tag = tags[i].innerText;
// Response handlers.
xhr.onload = function() {
var data = JSON.parse(xhr.responseText);
$("#steempress_sp_price")[0].innerHTML = data.payout;
$("#steempress_sp_comments")[0].innerHTML = data.comments;
};
var steempress_sp_price = steempress_sp_prices[i];
var steempress_sp_comment = (!front_page ? steempress_sp_comments[i] : null);
xhr.send(params);
post_request(username, permlink, tag, steempress_sp_price, steempress_sp_comment);
}
}
$(window).load(load_steem_capabilities)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment