(function($, window, undefined){ $.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; }; $.vgquotes = { refresh: function() { } }; (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); } window.location.href = url; }; 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; }()); $(document).ready(function() { (function(){ var submitSearch = function() { var searchQuery = $.trim($("#search-query").val()); if (searchQuery.length > 0) { window.location = "/search/" + searchQuery; } return false; }; $("#search-query").keypress(function(e) { if (e.which === 13) { submitSearch(); } }); $("#search-submit").click(submitSearch); }()); var getQuoteId = function($container) { return $container.find("input.quote-id").val(); }; 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; var quoteId = getQuoteId($container); $.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) { $("") .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) { $("") .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; }); //report link $(".quote-report-link").click(function() { if ($(".report-dialog").length > 0) { return false; } var $link = $(this); var $container = $link.parents(".quote-container"); var quoteId = getQuoteId($container); var $row = $("