2012-09-12 13:43:05 +00:00
|
|
|
function log(msg) {
|
|
|
|
if (console && console.log) {
|
|
|
|
console.log(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function logged() {
|
|
|
|
return $('#login').length == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clicked() {
|
|
|
|
return function() {
|
|
|
|
if (! logged()) {
|
|
|
|
$("#loginmessage").show();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var entryLine = $(this).parent();
|
|
|
|
log("entryLine = " + entryLine);
|
|
|
|
var param=$(this).attr("class");
|
|
|
|
log("param = "+param);
|
|
|
|
|
|
|
|
var oldValue=parseInt($(this).text());
|
|
|
|
var yeahdiv = entryLine.children(".yeah");
|
|
|
|
var neahdiv = entryLine.children(".neah");
|
|
|
|
var oldYeahValue = parseInt(yeahdiv.text());
|
|
|
|
var oldNeahValue = parseInt(neahdiv.text());
|
|
|
|
|
|
|
|
// put logic here, 6 possibles cases
|
|
|
|
// old state: not voted, neah, yeah
|
|
|
|
// action: yeah, neah
|
|
|
|
//
|
|
|
|
if ($(entryLine).hasClass("yeah_voted")) { // Old state yeah
|
|
|
|
// discard the yeah
|
|
|
|
entryLine.removeClass("yeah_voted");
|
|
|
|
yeahdiv.text( oldYeahValue - 1);
|
|
|
|
if (param == "neah") { // vote yeah
|
|
|
|
entryLine.addClass("neah_voted");
|
|
|
|
neahdiv.text( oldNeahValue + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ($(entryLine).hasClass("neah_voted")) { // Old state neah
|
|
|
|
// discard the neah
|
|
|
|
entryLine.removeClass("neah_voted");
|
|
|
|
neahdiv.text( oldNeahValue - 1);
|
|
|
|
if (param == "yeah") { // vote yeah
|
|
|
|
entryLine.addClass("yeah_voted");
|
|
|
|
yeahdiv.text( oldYeahValue + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // Old state not voted
|
|
|
|
entryLine.addClass(param+"_voted");
|
|
|
|
$(this).text(oldValue + 1);
|
|
|
|
}
|
|
|
|
var jsonparams={};
|
|
|
|
jsonparams[param]=1;
|
|
|
|
$.post( entryLine.attr('url')
|
|
|
|
, jsonparams
|
|
|
|
, function(data) {log(data);}
|
|
|
|
, "json");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function ask(msg,f,yes,no) {
|
|
|
|
if ($('#popin').length == 0) {
|
|
|
|
$('<div/>',{ id: "popin" , click: function(){$("#popin").hide(); }
|
|
|
|
}).appendTo($('body'));
|
|
|
|
$('<div/>',{"class": "insidebox"}).appendTo($("#popin"));
|
|
|
|
}
|
|
|
|
$("#popin").show()
|
|
|
|
$("#popin .insidebox").html(msg);
|
|
|
|
$('<div/>', { "class": "buttons"}).appendTo($("#popin .insidebox"));
|
|
|
|
$('<div/>', { click: function(){f();$("#popin").hide();}
|
|
|
|
, "class": "button"
|
|
|
|
, text: yes
|
|
|
|
}).appendTo("#popin .insidebox .buttons");
|
|
|
|
$('<div/>', { click: function(){ $("#popin").hide();}
|
|
|
|
, "class": "button"
|
|
|
|
, text: no
|
|
|
|
}).appendTo("#popin .insidebox .buttons");
|
|
|
|
$('<div class="flush"></div>').appendTo("#popin .insidebox .buttons");
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteEntry(url,elem) {
|
|
|
|
$.ajax({ type: "DELETE"
|
|
|
|
, url: url
|
|
|
|
, success: function(data) {elem.remove();}
|
|
|
|
, dataType: "json"});
|
|
|
|
}
|
2012-09-17 11:58:54 +00:00
|
|
|
function deleteComment(url,elem) {
|
|
|
|
$.ajax({ type: "DELETE"
|
|
|
|
, url: url
|
|
|
|
, success: function(data) {
|
|
|
|
elem.addClass("deleted");
|
|
|
|
elem.find(".creator").html("by Anonymous Coward");
|
|
|
|
elem.find(".content").html("deleted");
|
|
|
|
}
|
|
|
|
, dataType: "json"});
|
|
|
|
}
|
2012-09-12 15:50:20 +00:00
|
|
|
function deleteEntryGoHome(url,elem) {
|
|
|
|
$.ajax({ type: "DELETE"
|
|
|
|
, url: url
|
|
|
|
, success: function(data) {window.location='/';}
|
|
|
|
, dataType: "json"});
|
|
|
|
}
|
2012-09-12 13:43:05 +00:00
|
|
|
|
2012-09-17 16:14:01 +00:00
|
|
|
function flipauto(elem, f) {
|
2012-09-12 13:43:05 +00:00
|
|
|
var target=elem.attr("flipshow");
|
2012-09-17 11:58:54 +00:00
|
|
|
var closedText=elem.attr("closed");
|
|
|
|
var openedText=elem.attr("opened");
|
|
|
|
if (elem.html() == closedText) {
|
|
|
|
elem.html(openedText);
|
|
|
|
} else {
|
|
|
|
elem.html(closedText);
|
|
|
|
}
|
2012-09-17 16:14:01 +00:00
|
|
|
if (typeof f === 'undefined') {
|
2012-09-17 11:58:54 +00:00
|
|
|
$(target).toggle();
|
2012-09-12 13:43:05 +00:00
|
|
|
} else {
|
2012-09-17 11:58:54 +00:00
|
|
|
f($(target));
|
2012-09-12 13:43:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-12 15:07:24 +00:00
|
|
|
|
|
|
|
function getUrlParams() {
|
|
|
|
var vars = [], hash;
|
|
|
|
var substr = window.location.href.replace(/[^\?]*\?/,'').replace(/#[^#]*$/,'');
|
|
|
|
var hashes = substr.split('&');
|
|
|
|
for(var i = 0; i < hashes.length; i++) {
|
|
|
|
hash = hashes[i].split('=');
|
|
|
|
vars.push(hash[0]);
|
|
|
|
vars[hash[0]] = hash[1];
|
|
|
|
}
|
|
|
|
return vars;
|
|
|
|
}
|
2012-09-18 14:25:01 +00:00
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
$('#message').click(function(){
|
|
|
|
$('#message').slideUp('slow')});
|
|
|
|
setTimeout(function(){
|
|
|
|
$('#message').slideUp('slow')}
|
|
|
|
, 10000);
|
|
|
|
});
|