define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function($) {
var core = {};
// Time shared by others modules
core.currentTime = new Date().getTime();
core.updateCurrentTime = function() {
core.currentTime = new Date().getTime();
};
// Usage: callback = callback || core.doNothing;
core.doNothing = function() {};
// Used by asyncTaskRunner
core.showWorkingIndicator = function(show) {
if (show === false) {
$(".working-indicator").addClass("hide");
} else {
$(".working-indicator").removeClass("hide");
}
};
// Used to show a notification message
core.showMessage = function(msg, iconClass, options) {
options = options || {};
iconClass = iconClass || "icon-info-sign";
$.jGrowl(" " + msg, options);
};
// Used to show an error message
core.showError = function(msg) {
core.showMessage(msg, "icon-warning-sign");
};
// Offline management
core.isOffline = false;
var offlineTime = core.currentTime;
var offlineListeners = [];
core.addOfflineListener = function(listener) {
offlineListeners.push(listener);
};
core.setOffline = function() {
offlineTime = core.currentTime;
if(core.isOffline === false) {
core.isOffline = true;
core.showMessage("You are offline.", "icon-exclamation-sign msg-offline", {
sticky : true,
close : function() {
core.showMessage("You are back online!", "icon-signal");
}
});
for(var i=0; i").addClass("caret"));
$(".ui-layout-toggler-south").addClass("btn").append(
$("").addClass("caret"));
$(".ui-layout-toggler-east").addClass("btn").append(
$("").addClass("caret"));
$("#navbar").click(function() {
layout.allowOverflow('north');
});
};
// Create the PageDown editor
core.createEditor = function(onTextChange) {
$("#wmd-button-bar").empty();
var converter = Markdown.getSanitizingConverter();
var firstChange = true;
converter.hooks.chain("preConversion", function(text) {
if (!firstChange) {
onTextChange();
}
return text;
});
var editor = new Markdown.Editor(converter);
editor.run();
firstChange = false;
$(".wmd-button-row").addClass("btn-group").find("li:not(.wmd-spacer)")
.addClass("btn").css("left", 0).find("span").hide();
$("#wmd-bold-button").append($("").addClass("icon-bold"));
$("#wmd-italic-button").append($("").addClass("icon-italic"));
$("#wmd-link-button").append($("").addClass("icon-globe"));
$("#wmd-quote-button").append($("").addClass("icon-indent-left"));
$("#wmd-code-button").append($("").addClass("icon-code"));
$("#wmd-image-button").append($("").addClass("icon-picture"));
$("#wmd-olist-button").append($("").addClass("icon-numbered-list"));
$("#wmd-ulist-button").append($("").addClass("icon-list"));
$("#wmd-heading-button").append($("").addClass("icon-text-height"));
$("#wmd-hr-button").append($("").addClass("icon-hr"));
$("#wmd-undo-button").append($("").addClass("icon-undo"));
$("#wmd-redo-button").append($("").addClass("icon-share-alt"));
};
core.init = function() {
// jGrowl configuration
$.jGrowl.defaults.life = 5000;
$.jGrowl.defaults.closer = false;
$.jGrowl.defaults.closeTemplate = '';
$.jGrowl.defaults.position = 'bottom-right';
// listen to online/offline events
$(window).on('offline', core.setOffline);
$(window).on('online', core.setOnline);
if (navigator.onLine === false) {
core.setOffline();
}
this.loadSettings();
this.createLayout();
$(".action-load-settings").click(function() {
core.loadSettings();
});
$(".action-apply-settings").click(function() {
core.saveSettings();
location.reload();
});
};
return core;
});