Skip to content

Commit

Permalink
Code refactorings (mostly JavaScript fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayIT committed Mar 3, 2014
1 parent d8a3d0c commit 45f484e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@
</text>
}
</script>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ function CategoryExpander() {

var self;

var init = function (treeView, treeViewSelector) {
var init = function(treeView, treeViewSelector) {
treeview = treeView;
treeviewSelector = treeViewSelector;
self = this;
}
};

function onDataBound() {
var categoryId;
Expand All @@ -35,7 +35,7 @@ function CategoryExpander() {
}
}

var categorySelected = function (e) {
var categorySelected = function(e) {
$("#contestsList").html("");
$("#contestsList").addClass("k-loading");

Expand Down Expand Up @@ -66,54 +66,54 @@ function CategoryExpander() {
}

var ajaxUrl = "/Contests/List/ByCategory/" + elementId;
$("#contestsList").load(ajaxUrl, function () {
$("#contestsList").load(ajaxUrl, function() {
$("#contestsList").removeClass("k-loading");
});
}
};

var setNestingData = function (categoriesArray) {
var setNestingData = function(categoriesArray) {
if (categoriesArray) {
data = categoriesArray;
}
}
};

var expandSubcategories = function () {
var expandSubcategories = function() {
for (var i = 0; i < data.length; i++) {
var id = data[i];
self.select(id);
}
}
};

var select = function (id) {
var select = function(id) {
currentlySelectedId = id;

var el = treeview.dataSource.get(id);
if (!el && data.indexOf(id) < 0) {
var parentsUrl = "/Contests/List/GetParents/" + id;

$.ajax({
url: parentsUrl,
success: function (data) {
success: function(data) {
self.setNestingData(data);
self.expandSubcategories();
}
});
} else if (el) {
var element = treeviewSelector.find('[data-uid=' + el.uid + ']');

var elementObj = {
elementId: id
}
};

treeview.trigger('select', elementObj);
treeview.expand(element);
treeview.select(element);
}
}
};

var currentId = function () {
var currentId = function() {
return currentlySelectedId;
}
};

return {
expandSubcategories: expandSubcategories,
Expand All @@ -134,8 +134,8 @@ function getCategoryIdFromHash() {

var expander = new CategoryExpander();

$(document).ready(function () {
$(window).on("hashchange", function (ev) {
$(document).ready(function() {
$(window).on("hashchange", function() {
var categoryId = getCategoryIdFromHash();
if (expander && categoryId !== expander.currentId()) {
expander.select(categoryId);
Expand All @@ -145,4 +145,4 @@ $(document).ready(function () {
var treeviewSelector = $("#contestsCategories");
var treeview = treeviewSelector.data("kendoTreeView");
expander.init(treeview, treeviewSelector);
})
});
25 changes: 12 additions & 13 deletions Open Judge System/Web/OJS.Web/Scripts/Contests/submission-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

function Notifier() {
function showMessage(data) {
container = $("div[id^='notify-container']").filter(':visible');
var container = $("div[id^='notify-container']").filter(':visible');

var notification = $('<div/>', {
text: data.message,
Expand Down Expand Up @@ -101,7 +101,7 @@ function Notifier() {
showMessage: showMessage,
notifySuccess: notifySuccess,
notifyFailure: notifyFailure
}
};
}

// update the code mirror textarea to display the submission content - not used
Expand All @@ -122,12 +122,12 @@ function getCodeMirrorInstance() {
return codeMirrorInstance;
}

var displayMaximumValues = function (maxMemory, maxTime, memoryString, timeString) {
var displayMaximumValues = function(maxMemory, maxTime, memoryString, timeString) {
var memoryInMb = (maxMemory / 1024 / 1024).toFixed(2);
var maxTimeInSeconds = (maxTime / 1000).toFixed(3);
var result = memoryString + ": " + memoryInMb + " MB <br />" + timeString + ": " + maxTimeInSeconds + " s";
return result;
}
};

// validate the submission content
function validateSubmissionContent() {
Expand All @@ -149,7 +149,7 @@ function validateSubmissionContent() {
var messageNotifier = new Notifier();

// validate the submission time
var submissionTimeValidator = function () {
var submissionTimeValidator = function() {
var lastSubmissionTime;
var currentServerTime;

Expand All @@ -161,12 +161,11 @@ var submissionTimeValidator = function () {

if (!currentServerTime) {
currentServerTime = serverTime;
setInterval(function () {
setInterval(function() {
currentServerTime = new Date(currentServerTime.getTime() + 1000);
}, 1000)
}, 1000);
}

var limitBetweenSubmissions = limitBetweenSubmissions;
var currentTime = currentServerTime;
var secondsForLastSubmission = (currentTime - lastSubmissionTime) / 1000;

Expand All @@ -192,8 +191,8 @@ var submissionTimeValidator = function () {

return {
validate: validate
}
}
};
};

var tabStripManager = new TabStripManager();

Expand Down Expand Up @@ -264,15 +263,15 @@ function TabStripManager() {
onContentLoad: onContentLoad,
currentIndex: currentIndex,
init: init
}
};
}

function getSelectedIndexFromHashtag() {
return parseInt(window.location.hash.substr(1));
}

$(document).ready(function () {
$(window).on("hashchange", function (ev) {
$(document).ready(function() {
$(window).on("hashchange", function() {
var hashIndex = getSelectedIndexFromHashtag();
if (hashIndex !== tabStripManager.currentIndex()) {
tabStripManager.selectTabWithIndex(hashIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public override string BuildCompilerArguments(string inputFile, string outputFil

private static void UnzipFile(string fileToUnzip, string outputDirectory)
{
using (ZipFile zip1 = ZipFile.Read(fileToUnzip))
using (var zipFile = ZipFile.Read(fileToUnzip))
{
foreach (ZipEntry entry in zip1)
foreach (var entry in zipFile)
{
entry.Extract(outputDirectory, ExtractExistingFileAction.OverwriteSilently);
}
Expand Down

0 comments on commit 45f484e

Please sign in to comment.