mirror of
https://github.com/friendica/friendica
synced 2025-04-25 07:10:11 +00:00
improve like/share buttons
change the button only if it could send its request successfully to the server. fixes: * disrupting a video on liking or sharing * timeline jumps around somewhere else, when you like or share a posting/comment, and you can not find back.
This commit is contained in:
parent
bb835848d4
commit
f8fc9c1e8b
3 changed files with 53 additions and 14 deletions
|
@ -764,12 +764,52 @@ function htmlToText(htmlString) {
|
|||
* @param {boolean} un Whether to perform an activity removal instead of creation
|
||||
*/
|
||||
function doActivityItemAction(ident, verb, un) {
|
||||
if (verb.indexOf("attend") === 0) {
|
||||
$(".item-" + ident + " .button-event:not(#" + verb + "-" + ident + ")").removeClass("active");
|
||||
}
|
||||
$("#" + verb + "-" + ident).toggleClass("active");
|
||||
console.log(ident, verb, un);
|
||||
_verb = un ? 'un' + verb : verb;
|
||||
$('#like-rotator-' + ident.toString()).show();
|
||||
$.post('item/' + ident.toString() + '/activity/' + _verb)
|
||||
.success(
|
||||
function(data){
|
||||
console.log("data.status: " + data.status);
|
||||
if (data.status == "ok") {
|
||||
console.log("connection: " + data.status);
|
||||
$('#like-rotator-' + ident.toString()).hide();
|
||||
if (verb.indexOf("announce") === 0 ) {
|
||||
console.log("announce")
|
||||
if (data.verb == "un" + verb) {
|
||||
$("button[id^=shareMenuOptions-" + ident.toString() + "]" ).removeClass("active");
|
||||
$("button[id^=shareMenuOptions-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + false + ")").change();
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).removeClass("active");
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + false + ")").change();
|
||||
} else {
|
||||
$("button[id^=shareMenuOptions-" + ident.toString() + "]" ).addClass("active");
|
||||
$("button[id^=shareMenuOptions-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + true + ")").change();
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).addClass("active");
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + true + ")").change();
|
||||
}
|
||||
} else {
|
||||
console.log("likes")
|
||||
if (data.verb == "un" + verb) {
|
||||
console.log(data.state);
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).removeClass("active");
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + false + ")").change();
|
||||
} else {
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).addClass("active");
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + true + ")").change();
|
||||
}
|
||||
$("button[id^=" + verb + "-" + ident.toString() + "]" ).button('refresh');
|
||||
}
|
||||
} else {
|
||||
$.jGrowl("No connection to host for like or share", {sticky: false, theme: 'info', life: 5000});
|
||||
console.err("No connection to host");
|
||||
}
|
||||
})
|
||||
.error(
|
||||
function(data){
|
||||
$.jGrowl("Network not reachable", {sticky: false, theme: 'info', life: 5000});
|
||||
console.log("POST unsuccessfull " + data.toString());
|
||||
});
|
||||
|
||||
doActivityItem(ident, verb, un);
|
||||
}
|
||||
|
||||
// Decodes a hexadecimally encoded binary string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue