Added Markdown editor and Javascript code refactoring
This commit is contained in:
@@ -1,75 +1,43 @@
|
||||
function App() {
|
||||
this.board = new Board(this);
|
||||
this.markdown = new Markdown();
|
||||
this.search = new Search(this);
|
||||
this.swimlane = new Swimlane(this);
|
||||
this.dropdown = new Dropdown();
|
||||
this.tooltip = new Tooltip(this);
|
||||
this.popover = new Popover(this);
|
||||
this.task = new Task(this);
|
||||
this.project = new Project();
|
||||
this.subtask = new Subtask(this);
|
||||
this.column = new Column(this);
|
||||
this.file = new FileUpload(this);
|
||||
this.accordion = new Accordion(this);
|
||||
this.keyboardShortcuts();
|
||||
this.task.keyboardShortcuts();
|
||||
this.chosen();
|
||||
this.poll();
|
||||
Kanboard.App = function() {
|
||||
this.controllers = {};
|
||||
};
|
||||
|
||||
// Alert box fadeout
|
||||
$(".alert-fade-out").delay(5000).fadeOut(800, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
Kanboard.App.prototype.get = function(controller) {
|
||||
return this.controllers[controller];
|
||||
};
|
||||
|
||||
Kanboard.App.prototype.execute = function() {
|
||||
for (var className in Kanboard) {
|
||||
if (className !== "App") {
|
||||
var controller = new Kanboard[className](this);
|
||||
this.controllers[className] = controller;
|
||||
|
||||
if (typeof controller.execute === "function") {
|
||||
controller.execute();
|
||||
}
|
||||
|
||||
if (typeof controller.listen === "function") {
|
||||
controller.listen();
|
||||
}
|
||||
|
||||
if (typeof controller.focus === "function") {
|
||||
controller.focus();
|
||||
}
|
||||
|
||||
if (typeof controller.keyboardShortcuts === "function") {
|
||||
controller.keyboardShortcuts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App.prototype.listen = function() {
|
||||
this.project.listen();
|
||||
this.popover.listen();
|
||||
this.markdown.listen();
|
||||
this.tooltip.listen();
|
||||
this.dropdown.listen();
|
||||
this.search.listen();
|
||||
this.task.listen();
|
||||
this.swimlane.listen();
|
||||
this.subtask.listen();
|
||||
this.column.listen();
|
||||
this.file.listen();
|
||||
this.accordion.listen();
|
||||
this.search.focus();
|
||||
this.autoComplete();
|
||||
this.datePicker();
|
||||
this.focus();
|
||||
this.chosen();
|
||||
this.keyboardShortcuts();
|
||||
this.datePicker();
|
||||
this.autoComplete();
|
||||
};
|
||||
|
||||
App.prototype.refresh = function() {
|
||||
$(document).off();
|
||||
this.listen();
|
||||
};
|
||||
|
||||
App.prototype.focus = function() {
|
||||
|
||||
// Autofocus fields (html5 autofocus works only with page onload)
|
||||
$("[autofocus]").each(function(index, element) {
|
||||
$(this).focus();
|
||||
})
|
||||
|
||||
// Auto-select input fields
|
||||
$(document).on('focus', '.auto-select', function() {
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
// Workaround for chrome
|
||||
$(document).on('mouseup', '.auto-select', function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
};
|
||||
|
||||
App.prototype.poll = function() {
|
||||
window.setInterval(this.checkSession, 60000);
|
||||
};
|
||||
|
||||
App.prototype.keyboardShortcuts = function() {
|
||||
Kanboard.App.prototype.keyboardShortcuts = function() {
|
||||
var self = this;
|
||||
|
||||
// Submit form
|
||||
@@ -85,31 +53,50 @@ App.prototype.keyboardShortcuts = function() {
|
||||
|
||||
// Close popover and dropdown
|
||||
Mousetrap.bindGlobal("esc", function() {
|
||||
self.popover.close();
|
||||
self.dropdown.close();
|
||||
self.get("Popover").close();
|
||||
self.get("Dropdown").close();
|
||||
});
|
||||
|
||||
// Show keyboard shortcut
|
||||
Mousetrap.bind("?", function() {
|
||||
self.popover.open($("body").data("keyboard-shortcut-url"));
|
||||
self.get("Popover").open($("body").data("keyboard-shortcut-url"));
|
||||
});
|
||||
};
|
||||
|
||||
App.prototype.checkSession = function() {
|
||||
if (! $(".form-login").length) {
|
||||
$.ajax({
|
||||
cache: false,
|
||||
url: $("body").data("status-url"),
|
||||
statusCode: {
|
||||
401: function() {
|
||||
window.location = $("body").data("login-url");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Kanboard.App.prototype.focus = function() {
|
||||
// Auto-select input fields
|
||||
$(document).on('focus', '.auto-select', function() {
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
// Workaround for chrome
|
||||
$(document).on('mouseup', '.auto-select', function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
};
|
||||
|
||||
App.prototype.datePicker = function() {
|
||||
Kanboard.App.prototype.chosen = function() {
|
||||
$(".chosen-select").each(function() {
|
||||
var searchThreshold = $(this).data("search-threshold");
|
||||
|
||||
if (searchThreshold === undefined) {
|
||||
searchThreshold = 10;
|
||||
}
|
||||
|
||||
$(this).chosen({
|
||||
width: "180px",
|
||||
no_results_text: $(this).data("notfound"),
|
||||
disable_search_threshold: searchThreshold
|
||||
});
|
||||
});
|
||||
|
||||
$(".select-auto-redirect").change(function() {
|
||||
var regex = new RegExp($(this).data('redirect-regex'), 'g');
|
||||
window.location = $(this).data('redirect-url').replace(regex, $(this).val());
|
||||
});
|
||||
};
|
||||
|
||||
Kanboard.App.prototype.datePicker = function() {
|
||||
// Datepicker translation
|
||||
$.datepicker.setDefaults($.datepicker.regional[$("body").data("js-lang")]);
|
||||
|
||||
@@ -131,7 +118,7 @@ App.prototype.datePicker = function() {
|
||||
});
|
||||
};
|
||||
|
||||
App.prototype.autoComplete = function() {
|
||||
Kanboard.App.prototype.autoComplete = function() {
|
||||
$(".autocomplete").each(function() {
|
||||
var input = $(this);
|
||||
var field = input.data("dst-field");
|
||||
@@ -157,36 +144,33 @@ App.prototype.autoComplete = function() {
|
||||
});
|
||||
};
|
||||
|
||||
App.prototype.chosen = function() {
|
||||
$(".chosen-select").each(function() {
|
||||
var searchThreshold = $(this).data("search-threshold");
|
||||
|
||||
if (searchThreshold === undefined) {
|
||||
searchThreshold = 10;
|
||||
}
|
||||
|
||||
$(this).chosen({
|
||||
width: "180px",
|
||||
no_results_text: $(this).data("notfound"),
|
||||
disable_search_threshold: searchThreshold
|
||||
});
|
||||
});
|
||||
|
||||
$(".select-auto-redirect").change(function() {
|
||||
var regex = new RegExp($(this).data('redirect-regex'), 'g');
|
||||
window.location = $(this).data('redirect-url').replace(regex, $(this).val());
|
||||
});
|
||||
Kanboard.App.prototype.hasId = function(id) {
|
||||
return !!document.getElementById(id);
|
||||
};
|
||||
|
||||
App.prototype.showLoadingIcon = function() {
|
||||
Kanboard.App.prototype.showLoadingIcon = function() {
|
||||
$("body").append('<span id="app-loading-icon"> <i class="fa fa-spinner fa-spin"></i></span>');
|
||||
};
|
||||
|
||||
App.prototype.hideLoadingIcon = function() {
|
||||
Kanboard.App.prototype.hideLoadingIcon = function() {
|
||||
$("#app-loading-icon").remove();
|
||||
};
|
||||
|
||||
App.prototype.isVisible = function() {
|
||||
Kanboard.App.prototype.formatDuration = function(d) {
|
||||
if (d >= 86400) {
|
||||
return Math.round(d/86400) + "d";
|
||||
}
|
||||
else if (d >= 3600) {
|
||||
return Math.round(d/3600) + "h";
|
||||
}
|
||||
else if (d >= 60) {
|
||||
return Math.round(d/60) + "m";
|
||||
}
|
||||
|
||||
return d + "s";
|
||||
};
|
||||
|
||||
Kanboard.App.prototype.isVisible = function() {
|
||||
var property = "";
|
||||
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
@@ -205,17 +189,3 @@ App.prototype.isVisible = function() {
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
App.prototype.formatDuration = function(d) {
|
||||
if (d >= 86400) {
|
||||
return Math.round(d/86400) + "d";
|
||||
}
|
||||
else if (d >= 3600) {
|
||||
return Math.round(d/3600) + "h";
|
||||
}
|
||||
else if (d >= 60) {
|
||||
return Math.round(d/60) + "m";
|
||||
}
|
||||
|
||||
return d + "s";
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user