summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
Diffstat (limited to 'www')
-rw-r--r--www/ajaxVote.php21
-rw-r--r--www/jsScuttle.php36
-rw-r--r--www/vote.php6
3 files changed, 59 insertions, 4 deletions
diff --git a/www/ajaxVote.php b/www/ajaxVote.php
new file mode 100644
index 0000000..27eb62c
--- /dev/null
+++ b/www/ajaxVote.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * We re-use vote.php but set the ajax flag
+ */
+$GLOBALS['ajaxRequest'] = true;
+require 'vote.php';
+
+$bs = SemanticScuttle_Service_Factory::get('Bookmark');
+$ts = SemanticScuttle_Service_Factory::get('Template');
+$bmrow = $bs->getBookmark($bookmark);
+
+header('Content-Type: text/xml; charset=utf-8');
+echo '<voteresult><bookmark>' . $bookmark . '</bookmark>'
+ . '<html xmlns="http://www.w3.org/1999/xhtml">';
+$ts->loadTemplate(
+ 'bookmarks-vote.inc.tpl.php',
+ array('row' => $bmrow)
+);
+
+echo '</html></voteresult>';
+?> \ No newline at end of file
diff --git a/www/jsScuttle.php b/www/jsScuttle.php
index 6aba422..6807e4a 100644
--- a/www/jsScuttle.php
+++ b/www/jsScuttle.php
@@ -42,7 +42,7 @@ function deleteConfirmed(ele, input, response) {
post.style.display = 'none';
deleted = false;
} else {
- loadXMLDoc('<?php echo ROOT; ?>ajaxDelete.php?id=' + input);
+ loadXMLDocProc('<?php echo ROOT; ?>ajaxDelete.php?id=' + input);
post.style.display = 'none';
}
}
@@ -97,7 +97,7 @@ function getTitle(input, response){
title.style.backgroundImage = 'none';
title.value = response;
} else if (input.indexOf('http') > -1) {
- loadXMLDoc('<?php echo ROOT; ?>ajaxGetTitle.php?url=' + input);
+ loadXMLDocProc('<?php echo ROOT; ?>ajaxGetTitle.php?url=' + input);
} else {
return false;
}
@@ -105,11 +105,25 @@ function getTitle(input, response){
}
var xmlhttp;
-function loadXMLDoc(url) {
+function loadXMLDocProc(url) {
+ loadXMLDoc(url, processStateChange);
+}
+function vote(bookmark, vote) {
+ if (vote == 1) {
+ vote = 'for';
+ } else {
+ vote = 'against';
+ }
+ loadXMLDoc(
+ '<?php echo ROOT; ?>ajaxVote.php/' + vote + '/' + bookmark,
+ processVotingResult
+ );
+}
+function loadXMLDoc(url, callback) {
// Native
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = processStateChange;
+ xmlhttp.onreadystatechange = callback;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
// ActiveX
@@ -131,6 +145,20 @@ function processStateChange() {
eval(method + '(\'\', result)');
}
}
+function processVotingResult() {
+ if (xmlhttp.readyState != 4 || xmlhttp.status != 200) {
+ return;
+ }
+ var response = xmlhttp.responseXML.documentElement;
+ var bookmark = response.getElementsByTagName('bookmark')[0]
+ .firstChild.nodeValue;
+ var bmnode = document.getElementById('bmv-'+bookmark);
+
+ bmnode.parentNode.replaceChild(
+ response.getElementsByTagName('html')[0].firstChild,
+ bmnode
+ );
+}
function playerLoad() {
var anchors = document.getElementsByTagName('a');
diff --git a/www/vote.php b/www/vote.php
index 6dda31b..406b7d0 100644
--- a/www/vote.php
+++ b/www/vote.php
@@ -65,5 +65,11 @@ if ($vs->hasVoted($bookmark, $user)) {
}
$vs->vote($bookmark, $user, $type == 'for' ? 1 : -1);
+
+if (isset($GLOBALS['ajaxRequest']) && $GLOBALS['ajaxRequest']) {
+ //we are in ajax mode and return the badge in ajaxVote.php
+ return;
+}
+
header('Location: ' . $from);
?> \ No newline at end of file