/* Sone JavaScript functions. */
+/* jQuery overrides. */
+oldGetJson = jQuery.prototype.getJSON;
+jQuery.prototype.getJSON = function(url, data, successCallback, errorCallback) {
+ if (typeof errorCallback == "undefined") {
+ return oldGetJson(url, data, successCallback);
+ }
+ if (jQuery.isFunction(data)) {
+ errorCallback = successCallback;
+ successCallback = data;
+ data = null;
+ }
+ return jQuery.ajax({
+ data: data,
+ error: errorCallback,
+ success: successCallback,
+ url: url
+ });
+}
+
function isOnline() {
return $("#sone").hasClass("online");
}
*/
function getTranslation(key, callback) {
$.getJSON("ajax/getTranslation.ajax", {"key": key}, function(data, textStatus) {
- if (data != null) {
+ if ((data != null) && data.success) {
callback(data.value);
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
function getSoneStatus(soneId, local) {
$.getJSON("ajax/getSoneStatus.ajax", {"sone": soneId}, function(data, textStatus) {
if ((data != null) && data.success) {
- updateSoneStatus(soneId, data.name, data.status, data.modified, data.lastUpdated);
+ updateSoneStatus(soneId, data.name, data.status, data.modified, data.locked, data.lastUpdated);
}
/* seconds! */
updateInterval = 60;
setTimeout(function() {
getSoneStatus(soneId, local);
}, updateInterval * 1000);
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
* “downloading”)
* @param modified
* Whether the Sone is modified
+ * @param locked
+ * Whether the Sone is locked
* @param lastUpdated
* The date and time of the last update (formatted for display)
*/
-function updateSoneStatus(soneId, name, status, modified, lastUpdated) {
+function updateSoneStatus(soneId, name, status, modified, locked, lastUpdated) {
$("#sone .sone." + filterSoneId(soneId)).
toggleClass("unknown", status == "unknown").
toggleClass("idle", status == "idle").
toggleClass("inserting", status == "inserting").
toggleClass("downloading", status == "downloading").
toggleClass("modified", modified);
+ $("#sone .sone." + filterSoneId(soneId) + " .lock").toggleClass("hidden", locked);
+ $("#sone .sone." + filterSoneId(soneId) + " .unlock").toggleClass("hidden", !locked);
$("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(lastUpdated);
$("#sone .sone." + filterSoneId(soneId) + " .profile-link a").text(name);
}
} else if (data.error == "not-authorized") {
alert("You are not allowed to delete this post.");
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
});
}
} else if (data.error == "not-authorized") {
alert("You are not allowed to delete this reply.");
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
});
}
$("#sone .post#" + postId + " > .inner-part > .status-line .like").addClass("hidden");
$("#sone .post#" + postId + " > .inner-part > .status-line .unlike").removeClass("hidden");
updatePostLikes(postId);
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
$("#sone .post#" + postId + " > .inner-part > .status-line .unlike").addClass("hidden");
$("#sone .post#" + postId + " > .inner-part > .status-line .like").removeClass("hidden");
updatePostLikes(postId);
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
$("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
$("#sone .post#" + postId + " > .inner-part > .status-line .likes > span").attr("title", generateSoneList(data.sones));
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
$("#sone .reply#" + replyId + " .status-line .like").addClass("hidden");
$("#sone .reply#" + replyId + " .status-line .unlike").removeClass("hidden");
updateReplyLikes(replyId);
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
$("#sone .reply#" + replyId + " .status-line .unlike").addClass("hidden");
$("#sone .reply#" + replyId + " .status-line .like").removeClass("hidden");
updateReplyLikes(replyId);
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
$("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
$("#sone .reply#" + replyId + " .status-line .likes > span").attr("title", generateSoneList(data.sones));
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
} else {
callbackFunction(false, data.error);
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
if ((data != null) && data.success) {
callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html);
}
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}
$.getJSON("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
/* dismiss in case of error, too. */
notification.slideUp();
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
});
return notification;
oldNotification = $("#sone #notification-area .notification#" + value.id);
notification = ajaxifyNotification(createNotification(value.id, value.text, value.dismissable)).hide();
if (oldNotification.length != 0) {
- oldNotification.slideUp();
- notification.insertBefore(oldNotification);
+ oldNotification.replaceWith(notification.show());
} else {
$("#sone #notification-area").append(notification);
+ notification.slideDown();
}
- notification.slideDown();
});
$.each(data.removedNotifications, function(index, value) {
$("#sone #notification-area .notification#" + value.id).slideUp();
});
+ setTimeout(getNotifications, 5000);
+ } else {
+ setTimeout(getNotifications, 30000);
}
- setTimeout(getNotifications, 5000);
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
});
}