2011-02-15 00:14:24 +00:00
|
|
|
|
(function($, window, undefined){
|
2011-02-15 01:18:23 +00:00
|
|
|
|
|
|
|
|
|
$.fn.center = function () {
|
|
|
|
|
this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
|
|
|
|
|
this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
|
|
|
|
|
return this;
|
2011-02-17 20:55:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$.vgquotes = {
|
|
|
|
|
refresh: function() { }
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
(function(){
|
|
|
|
|
var refreshCookie = "vgquotes.refreshFragment";
|
|
|
|
|
|
|
|
|
|
var refresh = function() {
|
|
|
|
|
var url = window.location.href;
|
|
|
|
|
var fragmentPosition = url.lastIndexOf("#");
|
|
|
|
|
if (fragmentPosition >= 0) {
|
|
|
|
|
if (fragmentPosition !== url.length - 1) {
|
|
|
|
|
$.cookie(refreshCookie, url.substring(fragmentPosition + 1)); //store the fragment in a cookie
|
|
|
|
|
}
|
|
|
|
|
url = url.substring(0, fragmentPosition);
|
|
|
|
|
}
|
2011-02-15 01:18:23 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
window.location.href = url;
|
|
|
|
|
};
|
2011-02-17 07:52:56 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var applyFragmentFromCookie = function() {
|
|
|
|
|
var fragment = $.cookie(refreshCookie);
|
|
|
|
|
if (fragment !== null) {
|
|
|
|
|
window.location.href += "#" + fragment;
|
|
|
|
|
$.cookie(refreshCookie, null); //delete cookie
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(document).ready(applyFragmentFromCookie);
|
|
|
|
|
$.vgquotes.refresh = refresh;
|
|
|
|
|
}());
|
2011-02-17 07:52:56 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var setupSearch = function() {
|
|
|
|
|
var submitSearch = function() {
|
|
|
|
|
var searchQuery = $.trim($("#search-query").val());
|
|
|
|
|
if (searchQuery.length > 0) {
|
|
|
|
|
window.location = "/search/" + searchQuery;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2011-02-17 07:52:56 +00:00
|
|
|
|
$("#search-query").keypress(function(e) {
|
|
|
|
|
if (e.which === 13) {
|
|
|
|
|
submitSearch();
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-02-17 05:30:31 +00:00
|
|
|
|
|
2011-02-17 07:52:56 +00:00
|
|
|
|
$("#search-submit").click(submitSearch);
|
2011-02-19 09:41:09 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
2011-02-15 01:18:23 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var setupVoting = function() {
|
2011-02-15 00:14:24 +00:00
|
|
|
|
var voting = false;
|
|
|
|
|
$(".vote-for, .vote-against").live("click", function() {
|
|
|
|
|
if (voting) {
|
|
|
|
|
alert("Please wait for the current vote to process before voting again");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
voting = true;
|
|
|
|
|
var $votingLink = $(this);
|
|
|
|
|
var $container = $votingLink.parents(".quote-container");
|
|
|
|
|
var direction = $votingLink.hasClass("vote-for") ? 1 : 0;
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var quoteId = $container.find("input.quote-id").val();
|
2011-02-15 00:14:24 +00:00
|
|
|
|
$.ajax("/vote", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: {
|
|
|
|
|
QuoteId: quoteId,
|
|
|
|
|
Direction: direction
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
success: function(data, status, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$container
|
|
|
|
|
.find(".quote-score")
|
|
|
|
|
.attr("title", "+" + data.Data.upVotes + ", -" + data.Data.downVotes)
|
|
|
|
|
.text(data.Data.netVotes);
|
|
|
|
|
|
|
|
|
|
//remove the voting arrow, and add the other one if needed
|
|
|
|
|
$votingLink.remove();
|
|
|
|
|
if (direction === 1) {
|
|
|
|
|
if ($container.find(".vote-against").length === 0) {
|
|
|
|
|
$("<span/>")
|
|
|
|
|
.addClass("vote-against")
|
|
|
|
|
.attr("title", "I hate this quote")
|
|
|
|
|
.text(String.fromCharCode(0x25BC))
|
|
|
|
|
.appendTo($container.find(".vote-container:last"));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($container.find(".vote-for").length === 0) {
|
|
|
|
|
$("<span/>")
|
|
|
|
|
.addClass("vote-for")
|
|
|
|
|
.attr("title", "I like this quote")
|
|
|
|
|
.text(String.fromCharCode(0x25B2))
|
|
|
|
|
.appendTo($container.find(".vote-container:first"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
complete: function() { voting = false; }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2011-02-19 09:41:09 +00:00
|
|
|
|
};
|
2011-02-15 01:18:23 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var setupReportLink = function() {
|
2011-02-15 01:18:23 +00:00
|
|
|
|
$(".quote-report-link").click(function() {
|
|
|
|
|
if ($(".report-dialog").length > 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var $link = $(this);
|
|
|
|
|
var $container = $link.parents(".quote-container");
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var quoteId = $container.find("input.quote-id").val();
|
2011-02-15 01:18:23 +00:00
|
|
|
|
|
|
|
|
|
var $row = $("<tr/>");
|
|
|
|
|
var flagTypes = [ [1, "Inaccurate"], [2, "Duplicate"], [3, "Spam"], [4, "Fake"], [0, "Other"] ];
|
|
|
|
|
for (var i = 0; i < flagTypes.length; i++) {
|
|
|
|
|
var html = "<td><input type=\"radio\" name=\"flagType\" value=\""
|
|
|
|
|
+ flagTypes[i][0] + "\" id=\"flag-type-" +flagTypes[i][0] + "\"/>"
|
|
|
|
|
+ "<label for=\"flag-type-" + flagTypes[i][0] + "\">" + flagTypes[i][1] + "</label></td>";
|
|
|
|
|
|
|
|
|
|
$row.append($(html));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var $dialog = $("<div/>").addClass("dialog report-dialog");
|
|
|
|
|
|
|
|
|
|
var $submit = $("<input/>")
|
|
|
|
|
.attr("type", "button")
|
|
|
|
|
.attr("value", "Submit Report")
|
|
|
|
|
.click(function() {
|
|
|
|
|
$.ajax("/report", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: { QuoteId: quoteId, Comment: $dialog.find("textarea").val(), FlagType: $dialog.find("input[name='flagType']:checked").val() },
|
|
|
|
|
complete: function() { $dialog.remove(); },
|
|
|
|
|
success: function(data, status, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var $cancel = $("<input/>")
|
|
|
|
|
.attr("type", "button")
|
|
|
|
|
.attr("value", "Cancel")
|
|
|
|
|
.click(function() { $dialog.remove(); });
|
|
|
|
|
|
|
|
|
|
$dialog
|
|
|
|
|
.append($("<p/>").text("Flag as:"))
|
|
|
|
|
.append($("<table/>").append($row))
|
|
|
|
|
.append($("<p/>").text("Comment"))
|
|
|
|
|
.append($("<textarea/>"))
|
|
|
|
|
.append($("<div/>").css("text-align", "center").append($submit).append($cancel));
|
|
|
|
|
|
|
|
|
|
//"other" should be checked by default
|
|
|
|
|
$dialog.find("#flag-type-0").attr("checked", "checked");
|
|
|
|
|
|
|
|
|
|
$("body").append($dialog);
|
|
|
|
|
$dialog.center();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2011-02-19 09:41:09 +00:00
|
|
|
|
};
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var setupLogin = function() {
|
|
|
|
|
var showLoginForm = function() {
|
|
|
|
|
var $dialog = $("#login-dialog");
|
|
|
|
|
if ($dialog.length > 0) {
|
|
|
|
|
$dialog.remove();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
var $usernameInput = $("<input/>").attr({ type: "text", id: "login-username" });
|
|
|
|
|
var $passwordInput = $("<input/>").attr({ type: "password", id: "login-password" });
|
|
|
|
|
var $submit = $("<input/>").attr("type", "submit").css("display", "none");
|
|
|
|
|
|
|
|
|
|
var $form = $("<form/>").attr({ method: "post", action: "/login" }).submit(function() {
|
|
|
|
|
$.ajax("/login", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: { username: $usernameInput.val(), password: $passwordInput.val() },
|
|
|
|
|
success: function(data, status, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
2011-02-17 20:55:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
$.vgquotes.refresh();
|
|
|
|
|
}
|
2011-02-17 20:55:47 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var $dialog = $("<div/>").addClass("dialog").attr("id", "login-dialog");
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
$form.append($usernameInput).append($passwordInput).append($submit);
|
|
|
|
|
$dialog.append($form);
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
$("body").append($dialog);
|
|
|
|
|
$dialog.center();
|
|
|
|
|
$usernameInput.focus();
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
};
|
2011-02-17 20:55:47 +00:00
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
$(document).ready(function() {
|
2011-02-17 20:55:47 +00:00
|
|
|
|
$("#login-link").click(showLoginForm);
|
2011-02-19 09:41:09 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var setupQuoteForm = function() {
|
2011-02-22 09:39:59 +00:00
|
|
|
|
var toggleFormAndLink = function(type) {
|
|
|
|
|
return function() {
|
|
|
|
|
$("#create-" + type + "-form").toggle();
|
|
|
|
|
$("#" + type + "-select").toggle();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var addNewCheckbox = function($table, name, value, text, cellsPerRow) {
|
|
|
|
|
var $row = $table.find("tr:last");
|
|
|
|
|
if ($row.find("td").length === cellsPerRow) {
|
|
|
|
|
$row = $("<tr/>");
|
|
|
|
|
$table.append($row);
|
2011-02-19 09:41:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 09:39:59 +00:00
|
|
|
|
var $cell = $("<td/>").append($("<input/>").attr({
|
|
|
|
|
type: "checkbox",
|
|
|
|
|
name: name,
|
|
|
|
|
value: value,
|
|
|
|
|
id: name + "_" + value,
|
|
|
|
|
checked: "checked"
|
|
|
|
|
})).append($("<label/>").attr("for", name + "_" + value).text(text));
|
|
|
|
|
|
|
|
|
|
$row.append($cell);
|
|
|
|
|
$table.append($row);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$("#create-game-link, #create-game-cancel").click(toggleFormAndLink("game"));
|
|
|
|
|
$("#create-system-link, #create-system-cancel").click(toggleFormAndLink("system"));
|
|
|
|
|
$("#create-publisher-link, #create-publisher-cancel").click(toggleFormAndLink("publisher"));
|
|
|
|
|
|
|
|
|
|
$("#create-system-submit").click(function() {
|
|
|
|
|
$.ajax("/system/create", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: { Name: $("#SystemName").val(), Abbreviation: $("#SystemAbbreviation").val(), ReleaseDate: $("#SystemReleaseDate").val() },
|
|
|
|
|
success: function(data, statux, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add checkbox to table
|
|
|
|
|
addNewCheckbox($("#system-checkbox-table"), "SystemIds", data.Data.Id, data.Data.Abbreviation, 8);
|
|
|
|
|
toggleFormAndLink("system")();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
});
|
2011-02-22 09:39:59 +00:00
|
|
|
|
|
|
|
|
|
$("#create-publisher-submit").click(function() {
|
|
|
|
|
$.ajax("/publisher/create", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: { Name: $("#PublisherName").val(), Website: $("#PublisherWebsite").val() },
|
|
|
|
|
success: function(data, statux, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addNewCheckbox($("#publisher-checkbox-table"), "PublisherIds", data.Data.Id, data.Data.Name, 8);
|
|
|
|
|
toggleFormAndLink("publisher")();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
});
|
2011-02-22 09:39:59 +00:00
|
|
|
|
|
|
|
|
|
$("#create-game-submit").click(function() {
|
|
|
|
|
var regions = [], publishers = [], systems = [];
|
|
|
|
|
$("input:checked[name='GameRegions']").each(function(index, input) { regions.push(input.value); });
|
|
|
|
|
$("input:checked[name='SystemIds']").each(function(index, input) { systems.push(input.value); });
|
|
|
|
|
$("input:checked[name='PublisherIds']").each(function(index, input) { publishers.push(input.value); });
|
|
|
|
|
|
|
|
|
|
$.ajax("/game/create", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: {
|
|
|
|
|
Name: $("#GameName").val(),
|
|
|
|
|
Website: $("#GameWebsite").val(),
|
|
|
|
|
Region: regions,
|
|
|
|
|
SystemIds: systems,
|
|
|
|
|
PublisherIds: publishers
|
|
|
|
|
},
|
|
|
|
|
traditional: true,
|
|
|
|
|
success: function(data, statux, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#GameId")
|
|
|
|
|
.append($("<option/>").attr({ value: data.Data.Id}).text(data.Data.Name))
|
|
|
|
|
.val(data.Data.Id);
|
|
|
|
|
|
|
|
|
|
toggleFormAndLink("game")();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-02-19 09:41:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(".dismiss-flag-link").click(function() {
|
|
|
|
|
var $link = $(this);
|
|
|
|
|
var $container = $link.parents(".quote-flag");
|
|
|
|
|
var flagId = $container.find(".quote-flag-id").val();
|
|
|
|
|
var quoteId = $("#quote-id").val();
|
|
|
|
|
|
|
|
|
|
$.ajax("/dismiss-flag", {
|
|
|
|
|
type: "POST",
|
|
|
|
|
data: { quoteId: quoteId, flagId : flagId },
|
|
|
|
|
success: function(data, status, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert(data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$container.remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#create-category-link").click(function() {
|
|
|
|
|
var $table = $("#category-checkbox-table");
|
|
|
|
|
var $row = $table.find("tr:last");
|
|
|
|
|
if ($row.find("#new-category-name").length === 0) {
|
|
|
|
|
var $cell = $("<td/>");
|
|
|
|
|
if ($row.find("td").length === 8) {
|
|
|
|
|
$row = $("<tr/>");
|
|
|
|
|
$table.append($row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$row.append($cell);
|
|
|
|
|
|
|
|
|
|
var $input = $("<input/>").attr("id", "new-category-name").attr("type", "text").val("Category name");
|
|
|
|
|
|
|
|
|
|
$input.bind("keypress", function(e) {
|
|
|
|
|
if (e.which === 13) {
|
|
|
|
|
e.preventDefault(); //make sure the parent form doesn't get submitted
|
|
|
|
|
|
|
|
|
|
$input.attr("disabled", "disabled");
|
|
|
|
|
$.ajax("/category/create", {
|
|
|
|
|
data: { Name: $input.val() },
|
|
|
|
|
type: "POST",
|
|
|
|
|
success: function(data, status, $xhr) {
|
|
|
|
|
if (data.Error !== null) {
|
|
|
|
|
alert("An error occurred: " + data.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add category checkbox to table
|
|
|
|
|
var $checkbox = $("<input/>")
|
|
|
|
|
.attr({
|
|
|
|
|
"id": "category_" + data.Data.categoryId,
|
|
|
|
|
"type": "checkbox",
|
|
|
|
|
"name": "CategoryIds",
|
|
|
|
|
"checked": "checked"
|
|
|
|
|
}).val(data.Data.categoryId);
|
|
|
|
|
|
|
|
|
|
var $label = $("<label/>")
|
|
|
|
|
.attr("for", $checkbox.attr("id"))
|
|
|
|
|
.text(data.Data.categoryName);
|
|
|
|
|
|
|
|
|
|
$input.before($checkbox).before($label);
|
|
|
|
|
},
|
|
|
|
|
error: function($xhr, status, error) {
|
|
|
|
|
alert("An error occurred");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
complete: function() {
|
|
|
|
|
$input.remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$cell.append($input);
|
|
|
|
|
$input.select();
|
|
|
|
|
$(this).text("Cancel new category");
|
|
|
|
|
} else {
|
|
|
|
|
$row.find("td:last").remove();
|
|
|
|
|
$(this).text("Create new category");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
(function(){
|
|
|
|
|
setupLogin();
|
|
|
|
|
setupSearch();
|
|
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
setupReportLink();
|
|
|
|
|
setupVoting();
|
|
|
|
|
|
|
|
|
|
if ($("#edit-quote-form").length > 0) {
|
|
|
|
|
setupQuoteForm();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}());
|
|
|
|
|
|
2011-02-15 00:14:24 +00:00
|
|
|
|
}(jQuery, window));
|