vgquotes/Src/VideoGameQuotes.Web/media/js/vgquotes.compressed.js
2011-03-04 08:20:37 +00:00

1 line
7.3 KiB
JavaScript

(function(b,a){b.cookie=function(m,c,e){if(typeof c!="undefined"){e=e||{};if(c===null){c="";e.expires=-1}var d="";if(e.expires&&(typeof e.expires=="number"||e.expires.toUTCString)){var h;if(typeof e.expires=="number"){h=new Date();h.setTime(h.getTime()+(e.expires*24*60*60*1000))}else{h=e.expires}d="; expires="+h.toUTCString()}var j=e.path?"; path="+(e.path):"";var l=e.domain?"; domain="+(e.domain):"";var o=e.secure?"; secure":"";document.cookie=[m,"=",encodeURIComponent(c),d,j,l,o].join("")}else{var n=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var f=0;f<k.length;f++){var g=b.trim(k[f]);if(g.substring(0,m.length+1)==(m+"=")){n=decodeURIComponent(g.substring(m.length+1));break}}}return n}}}(jQuery,window));(function(a){a.fn.center=function(){var b=this.css("position")==="fixed";this.css("top",(a(window).height()-this.height())/2+(b?0:a(window).scrollTop())+"px");this.css("left",(a(window).width()-this.width())/2+(b?0:a(window).scrollLeft())+"px");return this}}(jQuery));(function(a){a.fn.applyModelErrors=function(b,c){var d=this;if(b!==null){d.find(".error-summary").first().text(b).show()}a.each(c,function(f,e){var g=d.find("input[name='"+f+"']");if(g.length>1){g=a("#"+f)}if(g.length===1){if(g[0].localName==="INPUT"){g.addClass("input-validation-error")}a("<span/>").addClass("field-validation-error").append(a("<span/>").addClass("error-icon")).append(a("<span/>").text(e)).insertAfter(g)}});return this};a.fn.clearModelErrors=function(){this.find(".field-validation-error").remove().end().find(".input-validation-error").removeClass("input-validation-error").end().find(".error-summary").empty().hide();return this}}(jQuery));(function(e,c){var a="jquery.refresh.fragment";var d=function(){var g=c.location.href;var f=g.lastIndexOf("#");if(f>=0){if(f!==g.length-1){e.cookie(a,g.substring(f+1))}g=g.substring(0,f)}c.location.href=g};var b=function(){var f=e.cookie(a);if(f!==null){c.location.href+="#"+f;e.cookie(a,null)}};e(document).ready(b);e.refresh=d}(jQuery,window));(function(f,d,a){f.vgquotes=function(){var i=function(k,j){return function(l){if(typeof(l)==="undefined"||typeof(l.Error)==="undefined"||l.Error!==null){j.call(null,null);return}j.call(null,l.Data.records[0])}};return{parseDate:function(j){return new Date(parseInt(j.substr(6)))},formatDate:function(j){return j.getFullYear()+"-"+(j.getMonth()+1)+"-"+j.getDate()},parseAndFormatDate:function(j){return f.vgquotes.formatDate(f.vgquotes.parseDate(j))},ajaxErrorHandler:function(j){alert("An error occurred ("+j.status+")")},preload:function(j){f.each(j,function(){f("<img/>")[0].src=this})},loadingGif:"/media/images/loading.gif",getResourceById:function(k,j,l){j=j.toString();f.ajax("/api/"+k+"/"+j,{type:"GET",success:i(k,l),error:i(k,l)})},createDialog:function(j){f("body").append(f("<div/>").attr("id","modal-background")).append(j);j.center()},closeDialog:function(j){f("#modal-background").remove();j.remove()}}}();var b=function(){var i=function(){var j=f.trim(f("#search-query").val());if(j.length>0){d.location="/search/"+j}return false};f(document).ready(function(){f("#search-query").keypress(function(j){if(j.which===13){i()}});f("#search-submit").click(i)})};var h=function(){var i=false;f(".vote-for, .vote-against").live("click",function(){if(i){alert("Please wait for the current vote to process before voting again");return false}i=true;var m=f(this);var o=m.parents(".quote-container");var l=m.hasClass("vote-for")?1:0;var j=o.find("input.quote-id").val();var n=o.find(".quote-score");var k=n.text();f.ajax("/vote",{type:"POST",data:{QuoteId:j,Direction:l},beforeSend:function(){n.empty().append(f("<img/>").attr({src:f.vgquotes.loadingGif,title:"submitting your vote"+String.fromCharCode(8230)}))},success:function(p,q,r){if(p.Error!==null){d.alert(p.Error);return}k=p.Data.score;n.attr("title","+"+p.Data.upVotes+", -"+p.Data.downVotes);m.remove();if(l===1){if(o.find(".vote-against").length===0){f("<span/>").addClass("vote-against").attr("title","I hate this quote").text(String.fromCharCode(9660)).appendTo(o.find(".vote-container:last"))}}else{if(o.find(".vote-for").length===0){f("<span/>").addClass("vote-for").attr("title","I like this quote").text(String.fromCharCode(9650)).appendTo(o.find(".vote-container:first"))}}},complete:function(){i=false;var p=n.find("img");if(p.length){p.remove()}n.text(k)}});return false})};var g=function(){f(".quote-flag-link").click(function(){if(f(".flag-dialog").length>0){return false}var q=f(this).parents(".quote-container");var k=q.find("input.quote-id").val();var p=f("<tr/>");var o=[[1,"Inaccurate"],[2,"Duplicate"],[3,"Spam"],[4,"Fake"],[0,"Other"]];for(var j=0;j<o.length;j++){var m='<td><input type="radio" name="flagType" value="'+o[j][0]+'" id="flag-type-'+o[j][0]+'"/><label for="flag-type-'+o[j][0]+'">'+o[j][1]+"</label></td>";p.append(f(m))}var n=f("<div/>").addClass("dialog flag-dialog");var l=f("<a/>").attr({href:"#",title:"submit"}).addClass("button-link").append(f("<span/>").addClass("submit-icon")).append(f("<span/>").text("Submit")).click(function(){var i=f(this).find(".submit-icon");i.toggleClass("submit-icon loading-icon");f.ajax("/flag",{type:"POST",data:{QuoteId:k,Comment:n.find("textarea").val(),FlagType:n.find("input[name='flagType']:checked").val()},success:function(s,t,u){if(s.Error!==null){alert(s.Error);return}f.vgquotes.closeDialog(n)},complete:function(){i.toggleClass("submit-icon loading-icon")}});return false});var r=f("<a/>").attr({href:"#",title:"cancel"}).addClass("button-link").append(f("<span/>").addClass("cancel-icon")).append(f("<span/>").text("Cancel")).click(function(){f.vgquotes.closeDialog(n);return false});n.append(f("<p/>").addClass("label").text("Flag as:")).append(f("<table/>").append(p)).append(f("<p/>").addClass("label").text("Comment")).append(f("<textarea/>")).append(f("<div/>").addClass("submit-container").append(l).append(r));n.find("#flag-type-0").attr("checked","checked");f.vgquotes.createDialog(n);return false})};var c=function(){f(".delete-quote-link").click(function(){var i=f(this);var j=i.parents(".quote-container");f.ajax("/quote/delete",{type:"POST",data:{id:j.find(".quote-id").val()},beforeSend:function(){i.toggleClass("delete-icon loading-icon")},success:function(k){if(k.Error!==null){d.alert(k.Error);return}j.remove()},complete:function(){i.toggleClass("delete-icon loading-icon")}});return false})};var e=function(){var i=function(){var j=f("#login-dialog");if(j.length>0){f.vgquotes.closeDialog(j);return false}var k=f("<input/>").attr({type:"text",id:"login-username"});var n=f("<input/>").attr({type:"password",id:"login-password"});var m=f("<input/>").attr("type","submit").css("display","none");var l=f("<form/>").attr({method:"post",action:"/login"}).submit(function(){f.ajax("/login",{type:"POST",data:{username:k.val(),password:n.val()},success:function(o,p,q){if(o.Error!==null){alert(o.Error);return}f.refresh()}});return false});j=f("<div/>").addClass("dialog").attr("id","login-dialog");l.append(k).append(n).append(m);j.append(l);f.vgquotes.createDialog(j);k.focus();return false};f(document).ready(function(){f("#login-link").click(i)})};(function(){e();b();f(document).ready(function(){f.vgquotes.preload([f.vgquotes.loadingGif]);g();c();h();f("body").ajaxError(function(l,i,k,j){f.vgquotes.ajaxErrorHandler.call(this,i)});f("#search-query").focus();f(document).keyup(function(i){if(i.keyCode===27){f.vgquotes.closeDialog(f(".dialog"))}})})}())}(jQuery,window));