Skip to content

Commit

Permalink
Refomat code
Browse files Browse the repository at this point in the history
1. Using space(4) instead of tab
2. Move function to top
3. Remove redundant comma
  • Loading branch information
Blueve committed Apr 23, 2016
1 parent 08ee3df commit 13e8663
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,22 @@ var show_locked = false
var hid = null;

function lockedProblemFilter(){
if($("#b_showlocked").is(':checked'))
{
if(hid != null)
hid.attr("class", "")
}
else
{
hid = $(".fa-lock").parent().parent().filter("tr[class!='hide']")
hid.attr("class", "hide")
}
if($("#b_showlocked").is(':checked')) {
if(hid != null)
hid.attr("class", "")
} else {
hid = $(".fa-lock").parent().parent().filter("tr[class!='hide']")
hid.attr("class", "hide")
}
}

function lockedProblemFilterAppend(){
if(!$("#b_showlocked").is(':checked'))
{
hid = $(".fa-lock").parent().parent().filter("tr[class!='hide']")
hid.attr("class", "hide")
}
}

var tab_url = window.location.href;
if(tab_url.indexOf("tag") == -1) {
$("#filterchosen").parent().after("<div class='row col-md-1'></div><div class='row col-md-4'><div class='checkbox'><label><input type='checkbox' id='b_showlocked' " + (show_locked ? "checked" : "") + "/>Show Locked Problems</label></div></div><div class='row col-md-1></div><div class='row col-md-1></div><div class='row col-md-1></div>")
$("#searchResultRow").before("<div class='row col-md-6'><form class='form-inline'><div class='checkbox' style='width:24%'><label><input type='checkbox' id='b_pick_easy' checked />Easy</label></div><div class='checkbox' style='width:24%'><label><input type='checkbox' id='b_pick_medium' checked />Medium</label></div><div class='checkbox' style='width:24%'><label><input type='checkbox' id='b_pick_hard' checked />Hard</label></div><a class='btn btn-info btn-sm' id='b_pick' >Pick One</a></form></div><div class='row col-md-6'><label id='b_message'></lable></div>")
$("#filterchosen").change(lockedProblemFilterAppend)
$("footer").before("<div class='modal fade' id='pickOneModal'><div class='modal-dialog'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button><h4 class='modal-title'>Pick this one?</h4></div><div class='modal-body'><p id='pickModalContent'></p></div><div class='modal-footer'><button type='button' class='btn btn-success' id='b_yes'>Yes</button><button type='button' class='btn btn-primary' id='b_repick'>Repick</button><button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button></div></div></div></div>")
}
else {
$("#tagCheck").before("<div class='checkbox'><label><input type='checkbox' id='b_showlocked' " + (show_locked ? "checked" : "") + "/>Show Locked Problems</label></div>")
$(".sortable").click(function(){
setTimeout("lockedProblemFilter()", 100)
})
if(!$("#b_showlocked").is(':checked')) {
hid = $(".fa-lock").parent().parent().filter("tr[class!='hide']")
hid.attr("class", "hide")
}
}

lockedProblemFilter();
$("#b_showlocked").change(lockedProblemFilter)


$("#b_pick").click(pickOne)
$("#b_repick").click(pickOne)


function pickOne() {
var easy = $("#b_pick_easy").is(':checked')
var medium = $("#b_pick_medium").is(':checked')
Expand All @@ -63,10 +37,31 @@ function pickOne() {
if (problem_text == "") {
$("#b_message").text("Picked a cat :P")
} else {
$("#pickOneModal").modal('show');
$("#pickModalContent").html("[" + problem_text + "]");
$("#b_yes").bind("click", function () { window.location.href = problem.find("a").attr("href"); });
$("#b_message").text("");
$("#pickOneModal").modal('show')
$("#pickModalContent").html("[" + problem_text + "]")
$("#b_yes").bind("click", function () { window.location.href = problem.find("a").attr("href"); })
$("#b_message").text("")
}
}
}
}

var tab_url = window.location.href;

if(tab_url.indexOf("tag") == -1) {
// Problemset page
$("#filterchosen").parent().after("<div class='row col-md-1'></div><div class='row col-md-4'><div class='checkbox'><label><input type='checkbox' id='b_showlocked' " + (show_locked ? "checked" : "") + "/>Show Locked Problems</label></div></div><div class='row col-md-1></div><div class='row col-md-1></div><div class='row col-md-1></div>")
$("#searchResultRow").before("<div class='row col-md-6'><form class='form-inline'><div class='checkbox' style='width:24%'><label><input type='checkbox' id='b_pick_easy' checked />Easy</label></div><div class='checkbox' style='width:24%'><label><input type='checkbox' id='b_pick_medium' checked />Medium</label></div><div class='checkbox' style='width:24%'><label><input type='checkbox' id='b_pick_hard' checked />Hard</label></div><a class='btn btn-info btn-sm' id='b_pick' >Pick One</a></form></div><div class='row col-md-6'><label id='b_message'></lable></div>")
$("#filterchosen").change(lockedProblemFilterAppend)
$("footer").before("<div class='modal fade' id='pickOneModal'><div class='modal-dialog'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button><h4 class='modal-title'>Pick this one?</h4></div><div class='modal-body'><p id='pickModalContent'></p></div><div class='modal-footer'><button type='button' class='btn btn-success' id='b_yes'>Yes</button><button type='button' class='btn btn-primary' id='b_repick'>Repick</button><button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button></div></div></div></div>")
} else {
// Tag page
$("#tagCheck").before("<div class='checkbox'><label><input type='checkbox' id='b_showlocked' " + (show_locked ? "checked" : "") + "/>Show Locked Problems</label></div>")
$(".sortable").click(function() {
setTimeout("lockedProblemFilter()", 100)
})
}

lockedProblemFilter();
$("#b_showlocked").change(lockedProblemFilter)
$("#b_pick").click(pickOne)
$("#b_repick").click(pickOne)

0 comments on commit 13e8663

Please sign in to comment.