", { "class": "ganttview-grid-row" });
@@ -162,7 +168,7 @@ Gantt.prototype.renderGrid = function(dates) {
};
// Render bar containers
-Gantt.prototype.addBlockContainers = function() {
+Kanboard.Gantt.prototype.addBlockContainers = function() {
var blocksDiv = jQuery("
", { "class": "ganttview-blocks" });
for (var i = 0; i < this.data.length; i++) {
@@ -173,7 +179,7 @@ Gantt.prototype.addBlockContainers = function() {
};
// Render bars
-Gantt.prototype.addBlocks = function(slider, start) {
+Kanboard.Gantt.prototype.addBlocks = function(slider, start) {
var rows = jQuery("div.ganttview-blocks div.ganttview-block-container", slider);
var rowIdx = 0;
@@ -219,7 +225,7 @@ Gantt.prototype.addBlocks = function(slider, start) {
};
// Get tooltip for vertical header
-Gantt.prototype.getVerticalHeaderTooltip = function(record) {
+Kanboard.Gantt.prototype.getVerticalHeaderTooltip = function(record) {
var tooltip = "";
if (record.type == "task") {
@@ -246,7 +252,7 @@ Gantt.prototype.getVerticalHeaderTooltip = function(record) {
};
// Get tooltip for bars
-Gantt.prototype.getBarTooltip = function(record) {
+Kanboard.Gantt.prototype.getBarTooltip = function(record) {
var tooltip = "";
if (record.not_defined) {
@@ -266,7 +272,7 @@ Gantt.prototype.getBarTooltip = function(record) {
};
// Set bar color
-Gantt.prototype.setBarColor = function(block, record) {
+Kanboard.Gantt.prototype.setBarColor = function(block, record) {
if (record.not_defined) {
block.addClass("ganttview-block-not-defined");
}
@@ -277,7 +283,7 @@ Gantt.prototype.setBarColor = function(block, record) {
};
// Setup jquery-ui resizable
-Gantt.prototype.listenForBlockResize = function(startDate) {
+Kanboard.Gantt.prototype.listenForBlockResize = function(startDate) {
var self = this;
jQuery("div.ganttview-block", this.options.container).resizable({
@@ -293,7 +299,7 @@ Gantt.prototype.listenForBlockResize = function(startDate) {
};
// Setup jquery-ui drag and drop
-Gantt.prototype.listenForBlockMove = function(startDate) {
+Kanboard.Gantt.prototype.listenForBlockMove = function(startDate) {
var self = this;
jQuery("div.ganttview-block", this.options.container).draggable({
@@ -309,7 +315,7 @@ Gantt.prototype.listenForBlockMove = function(startDate) {
};
// Update the record data and the position on the chart
-Gantt.prototype.updateDataAndPosition = function(block, startDate) {
+Kanboard.Gantt.prototype.updateDataAndPosition = function(block, startDate) {
var container = jQuery("div.ganttview-slide-container", this.options.container);
var scroll = container.scrollLeft();
var offset = block.offset().left - container.offset().left - 1 + scroll;
@@ -349,7 +355,7 @@ Gantt.prototype.updateDataAndPosition = function(block, startDate) {
// Creates a 3 dimensional array [year][month][day] of every day
// between the given start and end dates
-Gantt.prototype.getDates = function(start, end) {
+Kanboard.Gantt.prototype.getDates = function(start, end) {
var dates = [];
dates[start.getFullYear()] = [];
dates[start.getFullYear()][start.getMonth()] = [start];
@@ -374,7 +380,7 @@ Gantt.prototype.getDates = function(start, end) {
};
// Convert data to Date object
-Gantt.prototype.prepareData = function(data) {
+Kanboard.Gantt.prototype.prepareData = function(data) {
for (var i = 0; i < data.length; i++) {
var start = new Date(data[i].start[0], data[i].start[1] - 1, data[i].start[2], 0, 0, 0, 0);
data[i].start = start;
@@ -387,7 +393,7 @@ Gantt.prototype.prepareData = function(data) {
};
// Get the start and end date from the data provided
-Gantt.prototype.getDateRange = function(minDays) {
+Kanboard.Gantt.prototype.getDateRange = function(minDays) {
var minStart = new Date();
var maxEnd = new Date();
@@ -425,7 +431,7 @@ Gantt.prototype.getDateRange = function(minDays) {
};
// Returns the number of day between 2 dates
-Gantt.prototype.daysBetween = function(start, end) {
+Kanboard.Gantt.prototype.daysBetween = function(start, end) {
if (! start || ! end) {
return 0;
}
@@ -441,17 +447,17 @@ Gantt.prototype.daysBetween = function(start, end) {
};
// Return true if it's the weekend
-Gantt.prototype.isWeekend = function(date) {
+Kanboard.Gantt.prototype.isWeekend = function(date) {
return date.getDay() % 6 == 0;
};
// Clone Date object
-Gantt.prototype.cloneDate = function(date) {
+Kanboard.Gantt.prototype.cloneDate = function(date) {
return new Date(date.getTime());
};
// Add days to a Date object
-Gantt.prototype.addDays = function(date, value) {
+Kanboard.Gantt.prototype.addDays = function(date, value) {
date.setDate(date.getDate() + value * 1);
return date;
};
@@ -463,7 +469,7 @@ Gantt.prototype.addDays = function(date, value) {
* 0 = values are equal
* 1 = date1 is greaterthan date2.
*/
-Gantt.prototype.compareDate = function(date1, date2) {
+Kanboard.Gantt.prototype.compareDate = function(date1, date2) {
if (isNaN(date1) || isNaN(date2)) {
throw new Error(date1 + " - " + date2);
} else if (date1 instanceof Date && date2 instanceof Date) {
diff --git a/assets/js/src/LeadCycleTimeChart.js b/assets/js/src/LeadCycleTimeChart.js
index 9ba4a2228..7eee77fcc 100644
--- a/assets/js/src/LeadCycleTimeChart.js
+++ b/assets/js/src/LeadCycleTimeChart.js
@@ -1,20 +1,27 @@
-function LeadCycleTimeChart(app) {
+Kanboard.LeadCycleTimeChart = function(app) {
this.app = app;
-}
+};
-LeadCycleTimeChart.prototype.execute = function() {
- var metrics = $("#chart").data("metrics");
- var cycle = [$("#chart").data("label-cycle")];
- var lead = [$("#chart").data("label-lead")];
+Kanboard.LeadCycleTimeChart.prototype.execute = function() {
+ if (this.app.hasId("analytic-lead-cycle-time")) {
+ this.show();
+ }
+};
+
+Kanboard.LeadCycleTimeChart.prototype.show = function() {
+ var chart = $("#chart");
+ var metrics = chart.data("metrics");
+ var cycle = [chart.data("label-cycle")];
+ var lead = [chart.data("label-lead")];
var categories = [];
var types = {};
- types[$("#chart").data("label-cycle")] = 'area';
- types[$("#chart").data("label-lead")] = 'area-spline';
+ types[chart.data("label-cycle")] = 'area';
+ types[chart.data("label-lead")] = 'area-spline';
var colors = {};
- colors[$("#chart").data("label-lead")] = '#afb42b';
- colors[$("#chart").data("label-cycle")] = '#4e342e';
+ colors[chart.data("label-lead")] = '#afb42b';
+ colors[chart.data("label-cycle")] = '#4e342e';
for (var i = 0; i < metrics.length; i++) {
cycle.push(parseInt(metrics[i].avg_cycle_time));
diff --git a/assets/js/src/Markdown.js b/assets/js/src/Markdown.js
index 502937297..11673eec6 100644
--- a/assets/js/src/Markdown.js
+++ b/assets/js/src/Markdown.js
@@ -1,48 +1,59 @@
-function Markdown() {
-}
+Kanboard.Markdown = function(app) {
+ this.app = app;
+ this.editor = null;
+};
-Markdown.prototype.showPreview = function(e) {
- e.preventDefault();
+Kanboard.Markdown.prototype.onPopoverOpened = function() {
+ this.listen();
+};
- var write = $(".write-area");
- var preview = $(".preview-area");
- var textarea = $("textarea");
+Kanboard.Markdown.prototype.onPopoverClosed = function() {
+ this.listen();
+};
- $("#markdown-write").parent().removeClass("form-tab-selected");
- $("#markdown-preview").parent().addClass("form-tab-selected");
+Kanboard.Markdown.prototype.listen = function() {
+ var editors = $(".markdown-editor");
- var request = $.ajax({
- url: $("body").data("markdown-preview-url"),
- contentType: "application/json",
- type: "POST",
- processData: false,
- dataType: "html",
- data: JSON.stringify({
- "text": textarea.val()
- })
- });
+ if (this.editor) {
+ this.destroy();
+ }
- request.done(function(data) {
- preview.find(".markdown").html(data)
- preview.css("height", textarea.css("height"));
- preview.css("width", textarea.css("width"));
+ if (editors.length > 0) {
+ this.show(editors[0]);
+ }
+};
- write.hide();
- preview.show();
+Kanboard.Markdown.prototype.destroy = function() {
+ var cm = this.editor.codemirror;
+ var wrapper = cm.getWrapperElement();
+
+ for (var item in ["toolbar", "statusbar", "sideBySide"]) {
+ if (this.editor.gui[item]) {
+ wrapper.parentNode.removeChild(this.editor.gui[item]);
+ }
+ }
+
+ cm.toTextArea();
+ this.editor = null;
+};
+
+Kanboard.Markdown.prototype.show = function(textarea) {
+ var toolbar = ["bold", "italic", "strikethrough", "heading", "|", "unordered-list", "ordered-list", "link", "|", "code", "table"];
+
+ this.editor = new SimpleMDE({
+ element: textarea,
+ status: false,
+ toolbarTips: false,
+ autoDownloadFontAwesome: false,
+ spellChecker: false,
+ autosave: {
+ enabled: false
+ },
+ forceSync: true,
+ blockStyles: {
+ italic: "_"
+ },
+ toolbar: textarea.hasAttribute("data-markdown-editor-disable-toolbar") ? false : toolbar,
+ placeholder: textarea.getAttribute("placeholder")
});
};
-
-Markdown.prototype.showWriter = function(e) {
- e.preventDefault();
-
- $("#markdown-write").parent().addClass("form-tab-selected");
- $("#markdown-preview").parent().removeClass("form-tab-selected");
-
- $(".write-area").show();
- $(".preview-area").hide();
-};
-
-Markdown.prototype.listen = function() {
- $(document).on("click", "#markdown-preview", this.showPreview.bind(this));
- $(document).on("click", "#markdown-write", this.showWriter.bind(this));
-};
diff --git a/assets/js/src/Namespace.js b/assets/js/src/Namespace.js
new file mode 100644
index 000000000..6b4b05430
--- /dev/null
+++ b/assets/js/src/Namespace.js
@@ -0,0 +1,3 @@
+'use strict';
+
+var Kanboard = {};
diff --git a/assets/js/src/Notification.js b/assets/js/src/Notification.js
new file mode 100644
index 000000000..840ee9882
--- /dev/null
+++ b/assets/js/src/Notification.js
@@ -0,0 +1,9 @@
+Kanboard.Notification = function(app) {
+ this.app = app;
+};
+
+Kanboard.Notification.prototype.execute = function() {
+ $(".alert-fade-out").delay(4000).fadeOut(800, function() {
+ $(this).remove();
+ });
+};
diff --git a/assets/js/src/Popover.js b/assets/js/src/Popover.js
index 03716d412..705a035ad 100644
--- a/assets/js/src/Popover.js
+++ b/assets/js/src/Popover.js
@@ -1,35 +1,28 @@
-function Popover(app) {
+Kanboard.Popover = function(app) {
this.app = app;
- this.router = new Router();
- this.router.addRoute('screenshot-zone', Screenshot);
-}
-
-Popover.prototype.isOpen = function() {
- return $('#popover-container').size() > 0;
};
-Popover.prototype.open = function(link) {
+Kanboard.Popover.prototype.listen = function() {
var self = this;
- self.app.dropdown.close();
- $.get(link, function(content) {
- $("body").prepend('
');
- self.afterOpen();
+ $(document).on("click", ".popover", function(e) {
+ self.onClick(e);
+ });
+
+ $(document).on("click", ".close-popover", function(e) {
+ self.close(e);
+ });
+
+ $(document).on("click", "#popover-container", function(e) {
+ self.close(e);
+ });
+
+ $(document).on("click", "#popover-content", function(e) {
+ e.stopPropagation();
});
};
-Popover.prototype.close = function(e) {
- if (this.isOpen()) {
-
- if (e) {
- e.preventDefault();
- }
-
- $('#popover-container').remove();
- }
-};
-
-Popover.prototype.onClick = function(e) {
+Kanboard.Popover.prototype.onClick = function(e) {
e.preventDefault();
e.stopPropagation();
@@ -45,20 +38,69 @@ Popover.prototype.onClick = function(e) {
}
};
-Popover.prototype.listen = function() {
- $(document).on("click", ".popover", this.onClick.bind(this));
- $(document).on("click", ".close-popover", this.close.bind(this));
- $(document).on("click", "#popover-container", this.close.bind(this));
- $(document).on("click", "#popover-content", function(e) { e.stopPropagation(); });
+Kanboard.Popover.prototype.isOpen = function() {
+ return $('#popover-container').size() > 0;
};
-Popover.prototype.afterOpen = function() {
+Kanboard.Popover.prototype.open = function(link) {
+ var self = this;
+
+ $.get(link, function(content) {
+ $("body").prepend('
');
+ self.executeOnOpenedListeners();
+ });
+};
+
+Kanboard.Popover.prototype.close = function(e) {
+ if (this.isOpen()) {
+ if (e) {
+ e.preventDefault();
+ }
+
+ $("#popover-container").remove();
+ this.executeOnClosedListeners();
+ }
+};
+
+Kanboard.Popover.prototype.ajaxReload = function(data, request, self) {
+ var redirect = request.getResponseHeader("X-Ajax-Redirect");
+
+ if (redirect) {
+ window.location = redirect === 'self' ? window.location.href.split("#")[0] : redirect;
+ }
+ else {
+ $("#popover-content").html(data);
+ $("#popover-content input[autofocus]").focus();
+ self.executeOnOpenedListeners();
+ }
+};
+
+Kanboard.Popover.prototype.executeOnOpenedListeners = function() {
+ for (var className in this.app.controllers) {
+ var controller = this.app.get(className);
+
+ if (typeof controller.onPopoverOpened === "function") {
+ controller.onPopoverOpened();
+ }
+ }
+
+ this.afterOpen();
+};
+
+Kanboard.Popover.prototype.executeOnClosedListeners = function() {
+ for (var className in this.app.controllers) {
+ var controller = this.app.get(className);
+
+ if (typeof controller.onPopoverClosed === "function") {
+ controller.onPopoverClosed();
+ }
+ }
+};
+
+Kanboard.Popover.prototype.afterOpen = function() {
var self = this;
var popoverForm = $("#popover-content .popover-form");
- self.app.refresh();
- self.router.dispatch(this.app);
-
// Submit forms with Ajax request
if (popoverForm) {
popoverForm.on("submit", function(e) {
@@ -69,7 +111,7 @@ Popover.prototype.afterOpen = function() {
url: popoverForm.attr("action"),
data: popoverForm.serialize(),
success: function(data, textStatus, request) {
- self.afterSubmit(data, request, self);
+ self.ajaxReload(data, request, self);
},
beforeSend: function() {
var button = $('.popover-form button[type="submit"]');
@@ -88,21 +130,16 @@ Popover.prototype.afterOpen = function() {
type: "GET",
url: $(this).attr("href"),
success: function(data, textStatus, request) {
- self.afterSubmit(data, request, self);
+ self.ajaxReload(data, request, self);
}
});
});
-};
-Popover.prototype.afterSubmit = function(data, request, self) {
- var redirect = request.getResponseHeader("X-Ajax-Redirect");
+ // Autofocus fields (html5 autofocus works only with page onload)
+ $("[autofocus]").each(function() {
+ $(this).focus();
+ });
- if (redirect) {
- window.location = redirect === 'self' ? window.location.href.split("#")[0] : redirect;
- }
- else {
- $("#popover-content").html(data);
- $("#popover-content input[autofocus]").focus();
- self.afterOpen();
- }
+ this.app.datePicker();
+ this.app.autoComplete();
};
diff --git a/assets/js/src/Project.js b/assets/js/src/Project.js
deleted file mode 100644
index 19941f03f..000000000
--- a/assets/js/src/Project.js
+++ /dev/null
@@ -1,28 +0,0 @@
-function Project() {
-}
-
-Project.prototype.listen = function() {
- $('.project-change-role').on('change', function() {
- $.ajax({
- cache: false,
- url: $(this).data('url'),
- contentType: "application/json",
- type: "POST",
- processData: false,
- data: JSON.stringify({
- "id": $(this).data('id'),
- "role": $(this).val()
- })
- });
- });
-
- $('#project-creation-form #form-src_project_id').on('change', function() {
- var srcProjectId = $(this).val();
-
- if (srcProjectId == 0) {
- $(".project-creation-options").hide();
- } else {
- $(".project-creation-options").show();
- }
- });
-};
diff --git a/assets/js/src/ProjectCreation.js b/assets/js/src/ProjectCreation.js
new file mode 100644
index 000000000..180eab949
--- /dev/null
+++ b/assets/js/src/ProjectCreation.js
@@ -0,0 +1,15 @@
+Kanboard.ProjectCreation = function(app) {
+ this.app = app;
+};
+
+Kanboard.ProjectCreation.prototype.onPopoverOpened = function() {
+ $('#project-creation-form #form-src_project_id').on('change', function() {
+ var srcProjectId = $(this).val();
+
+ if (srcProjectId == 0) {
+ $(".project-creation-options").hide();
+ } else {
+ $(".project-creation-options").show();
+ }
+ });
+};
diff --git a/assets/js/src/ProjectPermission.js b/assets/js/src/ProjectPermission.js
new file mode 100644
index 000000000..fec666b1b
--- /dev/null
+++ b/assets/js/src/ProjectPermission.js
@@ -0,0 +1,19 @@
+Kanboard.ProjectPermission = function(app) {
+ this.app = app;
+};
+
+Kanboard.ProjectPermission.prototype.listen = function() {
+ $('.project-change-role').on('change', function () {
+ $.ajax({
+ cache: false,
+ url: $(this).data('url'),
+ contentType: "application/json",
+ type: "POST",
+ processData: false,
+ data: JSON.stringify({
+ "id": $(this).data('id'),
+ "role": $(this).val()
+ })
+ });
+ });
+};
diff --git a/assets/js/src/Router.js b/assets/js/src/Router.js
deleted file mode 100644
index ab23c0fd4..000000000
--- a/assets/js/src/Router.js
+++ /dev/null
@@ -1,37 +0,0 @@
-function Router() {
- this.routes = {};
-}
-
-Router.prototype.addRoute = function(id, controller) {
- this.routes[id] = controller;
-};
-
-Router.prototype.dispatch = function(app) {
- for (var id in this.routes) {
- if (document.getElementById(id)) {
- var controller = Object.create(this.routes[id].prototype);
- this.routes[id].apply(controller, [app]);
- controller.execute();
- break;
- }
- }
-};
-
-jQuery(document).ready(function() {
- var app = new App();
- var router = new Router();
- router.addRoute('board', Board);
- router.addRoute('calendar', Calendar);
- router.addRoute('screenshot-zone', Screenshot);
- router.addRoute('analytic-task-repartition', TaskRepartitionChart);
- router.addRoute('analytic-user-repartition', UserRepartitionChart);
- router.addRoute('analytic-cfd', CumulativeFlowDiagram);
- router.addRoute('analytic-burndown', BurndownChart);
- router.addRoute('analytic-avg-time-column', AvgTimeColumnChart);
- router.addRoute('analytic-task-time-column', TaskTimeColumnChart);
- router.addRoute('analytic-lead-cycle-time', LeadCycleTimeChart);
- router.addRoute('analytic-compare-hours', CompareHoursColumnChart);
- router.addRoute('gantt-chart', Gantt);
- router.dispatch(app);
- app.listen();
-});
diff --git a/assets/js/src/Screenshot.js b/assets/js/src/Screenshot.js
index e7430dd7b..5c74288b2 100644
--- a/assets/js/src/Screenshot.js
+++ b/assets/js/src/Screenshot.js
@@ -1,13 +1,16 @@
-function Screenshot() {
+Kanboard.Screenshot = function(app) {
+ this.app = app;
this.pasteCatcher = null;
-}
+};
-Screenshot.prototype.execute = function() {
- this.initialize();
+Kanboard.Screenshot.prototype.onPopoverOpened = function() {
+ if (this.app.hasId("screenshot-zone")) {
+ this.initialize();
+ }
};
// Setup event listener and workarounds
-Screenshot.prototype.initialize = function() {
+Kanboard.Screenshot.prototype.initialize = function() {
this.destroy();
if (! window.Clipboard) {
@@ -40,7 +43,7 @@ Screenshot.prototype.initialize = function() {
};
// Destroy contentEditable element
-Screenshot.prototype.destroy = function() {
+Kanboard.Screenshot.prototype.destroy = function() {
if (this.pasteCatcher != null) {
document.body.removeChild(this.pasteCatcher);
}
@@ -53,14 +56,14 @@ Screenshot.prototype.destroy = function() {
};
// Set focus on contentEditable element
-Screenshot.prototype.setFocus = function() {
+Kanboard.Screenshot.prototype.setFocus = function() {
if (this.pasteCatcher !== null) {
this.pasteCatcher.focus();
}
};
// Paste event callback
-Screenshot.prototype.pasteHandler = function(e) {
+Kanboard.Screenshot.prototype.pasteHandler = function(e) {
// Firefox doesn't have the property e.clipboardData.items (only Chrome)
if (e.clipboardData && e.clipboardData.items) {
@@ -95,7 +98,7 @@ Screenshot.prototype.pasteHandler = function(e) {
};
// Parse the input in the paste catcher element
-Screenshot.prototype.checkInput = function() {
+Kanboard.Screenshot.prototype.checkInput = function() {
var child = this.pasteCatcher.childNodes[0];
if (child) {
@@ -110,7 +113,7 @@ Screenshot.prototype.checkInput = function() {
};
// Creates a new image from a given source
-Screenshot.prototype.createImage = function(blob) {
+Kanboard.Screenshot.prototype.createImage = function(blob) {
var pastedImage = new Image();
pastedImage.src = blob;
diff --git a/assets/js/src/Search.js b/assets/js/src/Search.js
index 4fbfee460..1fcbc5ef7 100644
--- a/assets/js/src/Search.js
+++ b/assets/js/src/Search.js
@@ -1,18 +1,21 @@
-function Search(app) {
+Kanboard.Search = function(app) {
this.app = app;
- this.keyboardShortcuts();
-}
+};
+
+Kanboard.Search.prototype.focus = function() {
-Search.prototype.focus = function() {
// Place cursor at the end when focusing on the search box
$(document).on("focus", "#form-search", function() {
- if ($("#form-search")[0].setSelectionRange) {
- $('#form-search')[0].setSelectionRange($('#form-search').val().length, $('#form-search').val().length);
+ var input = $("#form-search");
+
+ if (input[0].setSelectionRange) {
+ var len = input.val().length * 2;
+ input[0].setSelectionRange(len, len);
}
});
};
-Search.prototype.listen = function() {
+Kanboard.Search.prototype.listen = function() {
var self = this;
// Filter helper for search
@@ -21,68 +24,51 @@ Search.prototype.listen = function() {
var filter = $(this).data("filter");
var appendFilter = $(this).data("append-filter");
+ var input = $("#form-search");
if (appendFilter) {
- filter = $("#form-search").val() + " " + appendFilter;
+ filter = input.val() + " " + appendFilter;
}
- $("#form-search").val(filter);
-
- if ($('#board').length) {
- self.app.board.reloadFilters(filter);
- }
- else {
- $("form.search").submit();
- }
+ input.val(filter);
+ $("form.search").submit();
});
};
-Search.prototype.keyboardShortcuts = function() {
+Kanboard.Search.prototype.goToView = function(label) {
+ var link = $(label);
+
+ if (link.length) {
+ window.location = link.attr('href');
+ }
+};
+
+Kanboard.Search.prototype.keyboardShortcuts = function() {
var self = this;
// Switch view mode for projects: go to the overview page
- Mousetrap.bind("v o", function(e) {
- var link = $(".view-overview");
-
- if (link.length) {
- window.location = link.attr('href');
- }
+ Mousetrap.bind("v o", function() {
+ self.goToView(".view-overview");
});
// Switch view mode for projects: go to the board
- Mousetrap.bind("v b", function(e) {
- var link = $(".view-board");
-
- if (link.length) {
- window.location = link.attr('href');
- }
+ Mousetrap.bind("v b", function() {
+ self.goToView(".view-board");
});
// Switch view mode for projects: go to the calendar
- Mousetrap.bind("v c", function(e) {
- var link = $(".view-calendar");
-
- if (link.length) {
- window.location = link.attr('href');
- }
+ Mousetrap.bind("v c", function() {
+ self.goToView(".view-calendar");
});
// Switch view mode for projects: go to the listing
- Mousetrap.bind("v l", function(e) {
- var link = $(".view-listing");
-
- if (link.length) {
- window.location = link.attr('href');
- }
+ Mousetrap.bind("v l", function() {
+ self.goToView(".view-listing");
});
// Switch view mode for projects: go to the gantt chart
- Mousetrap.bind("v g", function(e) {
- var link = $(".view-gantt");
-
- if (link.length) {
- window.location = link.attr('href');
- }
+ Mousetrap.bind("v g", function() {
+ self.goToView(".view-gantt");
});
// Focus to the search field
@@ -99,14 +85,9 @@ Search.prototype.keyboardShortcuts = function() {
Mousetrap.bind("r", function(e) {
e.preventDefault();
var reset = $(".filter-reset").data("filter");
+ var input = $("#form-search");
- $("#form-search").val(reset);
-
- if ($('#board').length) {
- self.app.board.reloadFilters(reset);
- }
- else {
- $("form.search").submit();
- }
+ input.val(reset);
+ $("form.search").submit();
});
};
diff --git a/assets/js/src/Session.js b/assets/js/src/Session.js
new file mode 100644
index 000000000..c07bc58d2
--- /dev/null
+++ b/assets/js/src/Session.js
@@ -0,0 +1,21 @@
+Kanboard.Session = function(app) {
+ this.app = app;
+};
+
+Kanboard.Session.prototype.execute = function() {
+ window.setInterval(this.checkSession, 60000);
+};
+
+Kanboard.Session.prototype.checkSession = function() {
+ if (! $(".form-login").length) {
+ $.ajax({
+ cache: false,
+ url: $("body").data("status-url"),
+ statusCode: {
+ 401: function() {
+ window.location = $("body").data("login-url");
+ }
+ }
+ });
+ }
+};
diff --git a/assets/js/src/Subtask.js b/assets/js/src/Subtask.js
index 7670095ea..d46066439 100644
--- a/assets/js/src/Subtask.js
+++ b/assets/js/src/Subtask.js
@@ -1,15 +1,14 @@
-function Subtask(app) {
+Kanboard.Subtask = function(app) {
this.app = app;
-}
+};
-Subtask.prototype.listen = function() {
+Kanboard.Subtask.prototype.listen = function() {
var self = this;
-
this.dragAndDrop();
$(document).on("click", ".subtask-toggle-status", function(e) {
- e.preventDefault();
var el = $(this);
+ e.preventDefault();
$.ajax({
cache: false,
@@ -27,8 +26,8 @@ Subtask.prototype.listen = function() {
});
$(document).on("click", ".subtask-toggle-timer", function(e) {
- e.preventDefault();
var el = $(this);
+ e.preventDefault();
$.ajax({
cache: false,
@@ -41,7 +40,7 @@ Subtask.prototype.listen = function() {
});
};
-Subtask.prototype.dragAndDrop = function() {
+Kanboard.Subtask.prototype.dragAndDrop = function() {
var self = this;
$(".draggable-row-handle").mouseenter(function() {
@@ -71,7 +70,7 @@ Subtask.prototype.dragAndDrop = function() {
}).disableSelection();
};
-Subtask.prototype.savePosition = function(subtaskId, position) {
+Kanboard.Subtask.prototype.savePosition = function(subtaskId, position) {
var url = $(".subtasks-table").data("save-position-url");
var self = this;
diff --git a/assets/js/src/Swimlane.js b/assets/js/src/Swimlane.js
index 60dbf41f2..f95c66786 100644
--- a/assets/js/src/Swimlane.js
+++ b/assets/js/src/Swimlane.js
@@ -1,60 +1,15 @@
-function Swimlane(app) {
+Kanboard.Swimlane = function(app) {
this.app = app;
-}
-
-Swimlane.prototype.getStorageKey = function() {
- return "hidden_swimlanes_" + $("#board").data("project-id");
};
-Swimlane.prototype.expand = function(swimlaneId) {
- var swimlaneIds = this.getAllCollapsed();
- var index = swimlaneIds.indexOf(swimlaneId);
-
- if (index > -1) {
- swimlaneIds.splice(index, 1);
- }
-
- localStorage.setItem(this.getStorageKey(), JSON.stringify(swimlaneIds));
-
- $('.board-swimlane-columns-' + swimlaneId).css('display', 'table-row');
- $('.board-swimlane-tasks-' + swimlaneId).css('display', 'table-row');
- $('.hide-icon-swimlane-' + swimlaneId).css('display', 'inline');
- $('.show-icon-swimlane-' + swimlaneId).css('display', 'none');
-};
-
-Swimlane.prototype.collapse = function(swimlaneId) {
- var swimlaneIds = this.getAllCollapsed();
-
- if (swimlaneIds.indexOf(swimlaneId) < 0) {
- swimlaneIds.push(swimlaneId);
- localStorage.setItem(this.getStorageKey(), JSON.stringify(swimlaneIds));
- }
-
- $('.board-swimlane-columns-' + swimlaneId + ':not(:first-child)').css('display', 'none');
- $('.board-swimlane-tasks-' + swimlaneId).css('display', 'none');
- $('.hide-icon-swimlane-' + swimlaneId).css('display', 'none');
- $('.show-icon-swimlane-' + swimlaneId).css('display', 'inline');
-};
-
-Swimlane.prototype.isCollapsed = function(swimlaneId) {
- return this.getAllCollapsed().indexOf(swimlaneId) > -1;
-};
-
-Swimlane.prototype.getAllCollapsed = function() {
- return JSON.parse(localStorage.getItem(this.getStorageKey())) || [];
-};
-
-Swimlane.prototype.refresh = function() {
- var swimlaneIds = this.getAllCollapsed();
-
- for (var i = 0; i < swimlaneIds.length; i++) {
- this.collapse(swimlaneIds[i]);
+Kanboard.Swimlane.prototype.execute = function() {
+ if ($(".swimlanes-table").length) {
+ this.dragAndDrop();
}
};
-Swimlane.prototype.listen = function() {
+Kanboard.Swimlane.prototype.listen = function() {
var self = this;
- self.dragAndDrop();
$(document).on('click', ".board-swimlane-toggle", function(e) {
e.preventDefault();
@@ -70,7 +25,57 @@ Swimlane.prototype.listen = function() {
});
};
-Swimlane.prototype.dragAndDrop = function() {
+Kanboard.Swimlane.prototype.onBoardRendered = function() {
+ var swimlaneIds = this.getAllCollapsed();
+
+ for (var i = 0; i < swimlaneIds.length; i++) {
+ this.collapse(swimlaneIds[i]);
+ }
+};
+
+Kanboard.Swimlane.prototype.getStorageKey = function() {
+ return "hidden_swimlanes_" + $("#board").data("project-id");
+};
+
+Kanboard.Swimlane.prototype.expand = function(swimlaneId) {
+ var swimlaneIds = this.getAllCollapsed();
+ var index = swimlaneIds.indexOf(swimlaneId);
+
+ if (index > -1) {
+ swimlaneIds.splice(index, 1);
+ }
+
+ localStorage.setItem(this.getStorageKey(), JSON.stringify(swimlaneIds));
+
+ $('.board-swimlane-columns-' + swimlaneId).css('display', 'table-row');
+ $('.board-swimlane-tasks-' + swimlaneId).css('display', 'table-row');
+ $('.hide-icon-swimlane-' + swimlaneId).css('display', 'inline');
+ $('.show-icon-swimlane-' + swimlaneId).css('display', 'none');
+};
+
+Kanboard.Swimlane.prototype.collapse = function(swimlaneId) {
+ var swimlaneIds = this.getAllCollapsed();
+
+ if (swimlaneIds.indexOf(swimlaneId) < 0) {
+ swimlaneIds.push(swimlaneId);
+ localStorage.setItem(this.getStorageKey(), JSON.stringify(swimlaneIds));
+ }
+
+ $('.board-swimlane-columns-' + swimlaneId + ':not(:first-child)').css('display', 'none');
+ $('.board-swimlane-tasks-' + swimlaneId).css('display', 'none');
+ $('.hide-icon-swimlane-' + swimlaneId).css('display', 'none');
+ $('.show-icon-swimlane-' + swimlaneId).css('display', 'inline');
+};
+
+Kanboard.Swimlane.prototype.isCollapsed = function(swimlaneId) {
+ return this.getAllCollapsed().indexOf(swimlaneId) > -1;
+};
+
+Kanboard.Swimlane.prototype.getAllCollapsed = function() {
+ return JSON.parse(localStorage.getItem(this.getStorageKey())) || [];
+};
+
+Kanboard.Swimlane.prototype.dragAndDrop = function() {
var self = this;
$(".draggable-row-handle").mouseenter(function() {
@@ -100,7 +105,7 @@ Swimlane.prototype.dragAndDrop = function() {
}).disableSelection();
};
-Swimlane.prototype.savePosition = function(swimlaneId, position) {
+Kanboard.Swimlane.prototype.savePosition = function(swimlaneId, position) {
var url = $(".swimlanes-table").data("save-position-url");
var self = this;
diff --git a/assets/js/src/Task.js b/assets/js/src/Task.js
index cbd7dd56d..162386eae 100644
--- a/assets/js/src/Task.js
+++ b/assets/js/src/Task.js
@@ -1,31 +1,31 @@
-function Task(app) {
+Kanboard.Task = function(app) {
this.app = app;
-}
+};
-Task.prototype.keyboardShortcuts = function() {
+Kanboard.Task.prototype.keyboardShortcuts = function() {
var taskView = $("#task-view");
var self = this;
- if (taskView.length) {
+ if (this.app.hasId("task-view")) {
Mousetrap.bind("e", function() {
- self.app.popover.open(taskView.data("edit-url"));
+ self.app.get("Popover").open(taskView.data("edit-url"));
});
Mousetrap.bind("c", function() {
- self.app.popover.open(taskView.data("comment-url"));
+ self.app.get("Popover").open(taskView.data("comment-url"));
});
Mousetrap.bind("s", function() {
- self.app.popover.open(taskView.data("subtask-url"));
+ self.app.get("Popover").open(taskView.data("subtask-url"));
});
Mousetrap.bind("l", function() {
- self.app.popover.open(taskView.data("internal-link-url"));
+ self.app.get("Popover").open(taskView.data("internal-link-url"));
});
}
};
-Task.prototype.listen = function() {
+Kanboard.Task.prototype.onPopoverOpened = function() {
var self = this;
var reloadingProjectId = 0;
@@ -38,11 +38,11 @@ Task.prototype.listen = function() {
// Assign to me
$(document).on("click", ".assign-me", function(e) {
- e.preventDefault();
-
var currentId = $(this).data("current-id");
var dropdownId = "#" + $(this).data("target-id");
+ e.preventDefault();
+
if ($(dropdownId + ' option[value=' + currentId + ']').length) {
$(dropdownId).val(currentId);
}
@@ -65,8 +65,7 @@ Task.prototype.listen = function() {
success: function(data, textStatus, request) {
reloadingProjectId = 0;
$(".loading-icon").hide();
-
- self.app.popover.afterSubmit(data, request, self.app.popover);
+ self.app.get("Popover").ajaxReload(data, request, self.app.get("Popover"));
}
});
}
diff --git a/assets/js/src/TaskRepartitionChart.js b/assets/js/src/TaskRepartitionChart.js
index 1b1368dc8..621be630d 100644
--- a/assets/js/src/TaskRepartitionChart.js
+++ b/assets/js/src/TaskRepartitionChart.js
@@ -1,7 +1,14 @@
-function TaskRepartitionChart() {
-}
+Kanboard.TaskRepartitionChart = function(app) {
+ this.app = app;
+};
-TaskRepartitionChart.prototype.execute = function() {
+Kanboard.TaskRepartitionChart.prototype.execute = function() {
+ if (this.app.hasId("analytic-task-repartition")) {
+ this.show();
+ }
+};
+
+Kanboard.TaskRepartitionChart.prototype.show = function() {
var metrics = $("#chart").data("metrics");
var columns = [];
diff --git a/assets/js/src/TaskTimeColumnChart.js b/assets/js/src/TaskTimeColumnChart.js
index 1ecc486b2..9b26d76ea 100644
--- a/assets/js/src/TaskTimeColumnChart.js
+++ b/assets/js/src/TaskTimeColumnChart.js
@@ -1,10 +1,17 @@
-function TaskTimeColumnChart(app) {
+Kanboard.TaskTimeColumnChart = function(app) {
this.app = app;
-}
+};
-TaskTimeColumnChart.prototype.execute = function() {
- var metrics = $("#chart").data("metrics");
- var plots = [$("#chart").data("label")];
+Kanboard.TaskTimeColumnChart.prototype.execute = function() {
+ if (this.app.hasId("analytic-task-time-column")) {
+ this.show();
+ }
+};
+
+Kanboard.TaskTimeColumnChart.prototype.show = function() {
+ var chart = $("#chart");
+ var metrics = chart.data("metrics");
+ var plots = [chart.data("label")];
var categories = [];
for (var i = 0; i < metrics.length; i++) {
diff --git a/assets/js/src/Tooltip.js b/assets/js/src/Tooltip.js
index f3ef55f9c..376b403ae 100644
--- a/assets/js/src/Tooltip.js
+++ b/assets/js/src/Tooltip.js
@@ -1,10 +1,8 @@
-function Tooltip(app) {
+Kanboard.Tooltip = function(app) {
this.app = app;
-}
-
-Tooltip.prototype.listen = function() {
- var self = this;
+};
+Kanboard.Tooltip.prototype.execute = function() {
$(".tooltip").tooltip({
track: false,
show: false,
diff --git a/assets/js/src/UserRepartitionChart.js b/assets/js/src/UserRepartitionChart.js
index 4255130a4..96c08ab3e 100644
--- a/assets/js/src/UserRepartitionChart.js
+++ b/assets/js/src/UserRepartitionChart.js
@@ -1,7 +1,14 @@
-function UserRepartitionChart() {
-}
+Kanboard.UserRepartitionChart = function(app) {
+ this.app = app;
+};
-UserRepartitionChart.prototype.execute = function() {
+Kanboard.UserRepartitionChart.prototype.execute = function() {
+ if (this.app.hasId("analytic-user-repartition")) {
+ this.show();
+ }
+};
+
+Kanboard.UserRepartitionChart.prototype.show = function() {
var metrics = $("#chart").data("metrics");
var columns = [];
diff --git a/assets/js/src/bootstrap.js b/assets/js/src/bootstrap.js
new file mode 100644
index 000000000..d5f3c7eff
--- /dev/null
+++ b/assets/js/src/bootstrap.js
@@ -0,0 +1,4 @@
+jQuery(document).ready(function() {
+ var app = new Kanboard.App();
+ app.execute();
+});
diff --git a/assets/js/vendor/jquery.textcomplete.js b/assets/js/vendor/jquery.textcomplete.js
deleted file mode 100644
index 0e548a65d..000000000
--- a/assets/js/vendor/jquery.textcomplete.js
+++ /dev/null
@@ -1,1227 +0,0 @@
-(function (factory) {
- if (typeof define === 'function' && define.amd) {
- // AMD. Register as an anonymous module.
- define(['jquery'], factory);
- } else if (typeof module === "object" && module.exports) {
- var $ = require('jquery');
- module.exports = factory($);
- } else {
- // Browser globals
- factory(jQuery);
- }
-}(function (jQuery) {
-
-/*!
- * jQuery.textcomplete
- *
- * Repository: https://github.com/yuku-t/jquery-textcomplete
- * License: MIT (https://github.com/yuku-t/jquery-textcomplete/blob/master/LICENSE)
- * Author: Yuku Takahashi
- */
-
-if (typeof jQuery === 'undefined') {
- throw new Error('jQuery.textcomplete requires jQuery');
-}
-
-+function ($) {
- 'use strict';
-
- var warn = function (message) {
- if (console.warn) { console.warn(message); }
- };
-
- var id = 1;
-
- $.fn.textcomplete = function (strategies, option) {
- var args = Array.prototype.slice.call(arguments);
- return this.each(function () {
- var self = this;
- var $this = $(this);
- var completer = $this.data('textComplete');
- if (!completer) {
- option || (option = {});
- option._oid = id++; // unique object id
- completer = new $.fn.textcomplete.Completer(this, option);
- $this.data('textComplete', completer);
- }
- if (typeof strategies === 'string') {
- if (!completer) return;
- args.shift()
- completer[strategies].apply(completer, args);
- if (strategies === 'destroy') {
- $this.removeData('textComplete');
- }
- } else {
- // For backward compatibility.
- // TODO: Remove at v0.4
- $.each(strategies, function (obj) {
- $.each(['header', 'footer', 'placement', 'maxCount'], function (name) {
- if (obj[name]) {
- completer.option[name] = obj[name];
- warn(name + 'as a strategy param is deprecated. Use option.');
- delete obj[name];
- }
- });
- });
- completer.register($.fn.textcomplete.Strategy.parse(strategies, {
- el: self,
- $el: $this
- }));
- }
- });
- };
-
-}(jQuery);
-
-+function ($) {
- 'use strict';
-
- // Exclusive execution control utility.
- //
- // func - The function to be locked. It is executed with a function named
- // `free` as the first argument. Once it is called, additional
- // execution are ignored until the free is invoked. Then the last
- // ignored execution will be replayed immediately.
- //
- // Examples
- //
- // var lockedFunc = lock(function (free) {
- // setTimeout(function { free(); }, 1000); // It will be free in 1 sec.
- // console.log('Hello, world');
- // });
- // lockedFunc(); // => 'Hello, world'
- // lockedFunc(); // none
- // lockedFunc(); // none
- // // 1 sec past then
- // // => 'Hello, world'
- // lockedFunc(); // => 'Hello, world'
- // lockedFunc(); // none
- //
- // Returns a wrapped function.
- var lock = function (func) {
- var locked, queuedArgsToReplay;
-
- return function () {
- // Convert arguments into a real array.
- var args = Array.prototype.slice.call(arguments);
- if (locked) {
- // Keep a copy of this argument list to replay later.
- // OK to overwrite a previous value because we only replay
- // the last one.
- queuedArgsToReplay = args;
- return;
- }
- locked = true;
- var self = this;
- args.unshift(function replayOrFree() {
- if (queuedArgsToReplay) {
- // Other request(s) arrived while we were locked.
- // Now that the lock is becoming available, replay
- // the latest such request, then call back here to
- // unlock (or replay another request that arrived
- // while this one was in flight).
- var replayArgs = queuedArgsToReplay;
- queuedArgsToReplay = undefined;
- replayArgs.unshift(replayOrFree);
- func.apply(self, replayArgs);
- } else {
- locked = false;
- }
- });
- func.apply(this, args);
- };
- };
-
- var isString = function (obj) {
- return Object.prototype.toString.call(obj) === '[object String]';
- };
-
- var isFunction = function (obj) {
- return Object.prototype.toString.call(obj) === '[object Function]';
- };
-
- var uniqueId = 0;
-
- function Completer(element, option) {
- this.$el = $(element);
- this.id = 'textcomplete' + uniqueId++;
- this.strategies = [];
- this.views = [];
- this.option = $.extend({}, Completer._getDefaults(), option);
-
- if (!this.$el.is('input[type=text]') && !this.$el.is('textarea') && !element.isContentEditable && element.contentEditable != 'true') {
- throw new Error('textcomplete must be called on a Textarea or a ContentEditable.');
- }
-
- if (element === document.activeElement) {
- // element has already been focused. Initialize view objects immediately.
- this.initialize()
- } else {
- // Initialize view objects lazily.
- var self = this;
- this.$el.one('focus.' + this.id, function () { self.initialize(); });
- }
- }
-
- Completer._getDefaults = function () {
- if (!Completer.DEFAULTS) {
- Completer.DEFAULTS = {
- appendTo: $('body'),
- zIndex: '100'
- };
- }
-
- return Completer.DEFAULTS;
- }
-
- $.extend(Completer.prototype, {
- // Public properties
- // -----------------
-
- id: null,
- option: null,
- strategies: null,
- adapter: null,
- dropdown: null,
- $el: null,
-
- // Public methods
- // --------------
-
- initialize: function () {
- var element = this.$el.get(0);
- // Initialize view objects.
- this.dropdown = new $.fn.textcomplete.Dropdown(element, this, this.option);
- var Adapter, viewName;
- if (this.option.adapter) {
- Adapter = this.option.adapter;
- } else {
- if (this.$el.is('textarea') || this.$el.is('input[type=text]')) {
- viewName = typeof element.selectionEnd === 'number' ? 'Textarea' : 'IETextarea';
- } else {
- viewName = 'ContentEditable';
- }
- Adapter = $.fn.textcomplete[viewName];
- }
- this.adapter = new Adapter(element, this, this.option);
- },
-
- destroy: function () {
- this.$el.off('.' + this.id);
- if (this.adapter) {
- this.adapter.destroy();
- }
- if (this.dropdown) {
- this.dropdown.destroy();
- }
- this.$el = this.adapter = this.dropdown = null;
- },
-
- // Invoke textcomplete.
- trigger: function (text, skipUnchangedTerm) {
- if (!this.dropdown) { this.initialize(); }
- text != null || (text = this.adapter.getTextFromHeadToCaret());
- var searchQuery = this._extractSearchQuery(text);
- if (searchQuery.length) {
- var term = searchQuery[1];
- // Ignore shift-key, ctrl-key and so on.
- if (skipUnchangedTerm && this._term === term) { return; }
- this._term = term;
- this._search.apply(this, searchQuery);
- } else {
- this._term = null;
- this.dropdown.deactivate();
- }
- },
-
- fire: function (eventName) {
- var args = Array.prototype.slice.call(arguments, 1);
- this.$el.trigger(eventName, args);
- return this;
- },
-
- register: function (strategies) {
- Array.prototype.push.apply(this.strategies, strategies);
- },
-
- // Insert the value into adapter view. It is called when the dropdown is clicked
- // or selected.
- //
- // value - The selected element of the array callbacked from search func.
- // strategy - The Strategy object.
- // e - Click or keydown event object.
- select: function (value, strategy, e) {
- this._term = null;
- this.adapter.select(value, strategy, e);
- this.fire('change').fire('textComplete:select', value, strategy);
- this.adapter.focus();
- },
-
- // Private properties
- // ------------------
-
- _clearAtNext: true,
- _term: null,
-
- // Private methods
- // ---------------
-
- // Parse the given text and extract the first matching strategy.
- //
- // Returns an array including the strategy, the query term and the match
- // object if the text matches an strategy; otherwise returns an empty array.
- _extractSearchQuery: function (text) {
- for (var i = 0; i < this.strategies.length; i++) {
- var strategy = this.strategies[i];
- var context = strategy.context(text);
- if (context || context === '') {
- var matchRegexp = isFunction(strategy.match) ? strategy.match(text) : strategy.match;
- if (isString(context)) { text = context; }
- var match = text.match(matchRegexp);
- if (match) { return [strategy, match[strategy.index], match]; }
- }
- }
- return []
- },
-
- // Call the search method of selected strategy..
- _search: lock(function (free, strategy, term, match) {
- var self = this;
- strategy.search(term, function (data, stillSearching) {
- if (!self.dropdown.shown) {
- self.dropdown.activate();
- }
- if (self._clearAtNext) {
- // The first callback in the current lock.
- self.dropdown.clear();
- self._clearAtNext = false;
- }
- self.dropdown.setPosition(self.adapter.getCaretPosition());
- self.dropdown.render(self._zip(data, strategy, term));
- if (!stillSearching) {
- // The last callback in the current lock.
- free();
- self._clearAtNext = true; // Call dropdown.clear at the next time.
- }
- }, match);
- }),
-
- // Build a parameter for Dropdown#render.
- //
- // Examples
- //
- // this._zip(['a', 'b'], 's');
- // //=> [{ value: 'a', strategy: 's' }, { value: 'b', strategy: 's' }]
- _zip: function (data, strategy, term) {
- return $.map(data, function (value) {
- return { value: value, strategy: strategy, term: term };
- });
- }
- });
-
- $.fn.textcomplete.Completer = Completer;
-}(jQuery);
-
-+function ($) {
- 'use strict';
-
- var $window = $(window);
-
- var include = function (zippedData, datum) {
- var i, elem;
- var idProperty = datum.strategy.idProperty
- for (i = 0; i < zippedData.length; i++) {
- elem = zippedData[i];
- if (elem.strategy !== datum.strategy) continue;
- if (idProperty) {
- if (elem.value[idProperty] === datum.value[idProperty]) return true;
- } else {
- if (elem.value === datum.value) return true;
- }
- }
- return false;
- };
-
- var dropdownViews = {};
- $(document).on('click', function (e) {
- var id = e.originalEvent && e.originalEvent.keepTextCompleteDropdown;
- $.each(dropdownViews, function (key, view) {
- if (key !== id) { view.deactivate(); }
- });
- });
-
- var commands = {
- SKIP_DEFAULT: 0,
- KEY_UP: 1,
- KEY_DOWN: 2,
- KEY_ENTER: 3,
- KEY_PAGEUP: 4,
- KEY_PAGEDOWN: 5,
- KEY_ESCAPE: 6
- };
-
- // Dropdown view
- // =============
-
- // Construct Dropdown object.
- //
- // element - Textarea or contenteditable element.
- function Dropdown(element, completer, option) {
- this.$el = Dropdown.createElement(option);
- this.completer = completer;
- this.id = completer.id + 'dropdown';
- this._data = []; // zipped data.
- this.$inputEl = $(element);
- this.option = option;
-
- // Override setPosition method.
- if (option.listPosition) { this.setPosition = option.listPosition; }
- if (option.height) { this.$el.height(option.height); }
- var self = this;
- $.each(['maxCount', 'placement', 'footer', 'header', 'noResultsMessage', 'className'], function (_i, name) {
- if (option[name] != null) { self[name] = option[name]; }
- });
- this._bindEvents(element);
- dropdownViews[this.id] = this;
- }
-
- $.extend(Dropdown, {
- // Class methods
- // -------------
-
- createElement: function (option) {
- var $parent = option.appendTo;
- if (!($parent instanceof $)) { $parent = $($parent); }
- var $el = $('
')
- .addClass('textcomplete-dropdown')
- .attr('id', 'textcomplete-dropdown-' + option._oid)
- .css({
- display: 'none',
- left: 0,
- position: 'absolute',
- zIndex: option.zIndex
- })
- .appendTo($parent);
- return $el;
- }
- });
-
- $.extend(Dropdown.prototype, {
- // Public properties
- // -----------------
-
- $el: null, // jQuery object of ul.dropdown-menu element.
- $inputEl: null, // jQuery object of target textarea.
- completer: null,
- footer: null,
- header: null,
- id: null,
- maxCount: 10,
- placement: '',
- shown: false,
- data: [], // Shown zipped data.
- className: '',
-
- // Public methods
- // --------------
-
- destroy: function () {
- // Don't remove $el because it may be shared by several textcompletes.
- this.deactivate();
-
- this.$el.off('.' + this.id);
- this.$inputEl.off('.' + this.id);
- this.clear();
- this.$el = this.$inputEl = this.completer = null;
- delete dropdownViews[this.id]
- },
-
- render: function (zippedData) {
- var contentsHtml = this._buildContents(zippedData);
- var unzippedData = $.map(this.data, function (d) { return d.value; });
- if (this.data.length) {
- this._renderHeader(unzippedData);
- this._renderFooter(unzippedData);
- if (contentsHtml) {
- this._renderContents(contentsHtml);
- this._fitToBottom();
- this._activateIndexedItem();
- }
- this._setScroll();
- } else if (this.noResultsMessage) {
- this._renderNoResultsMessage(unzippedData);
- } else if (this.shown) {
- this.deactivate();
- }
- },
-
- setPosition: function (pos) {
- this.$el.css(this._applyPlacement(pos));
-
- // Make the dropdown fixed if the input is also fixed
- // This can't be done during init, as textcomplete may be used on multiple elements on the same page
- // Because the same dropdown is reused behind the scenes, we need to recheck every time the dropdown is showed
- var position = 'absolute';
- // Check if input or one of its parents has positioning we need to care about
- this.$inputEl.add(this.$inputEl.parents()).each(function() {
- if($(this).css('position') === 'absolute') // The element has absolute positioning, so it's all OK
- return false;
- if($(this).css('position') === 'fixed') {
- position = 'fixed';
- return false;
- }
- });
- this.$el.css({ position: position }); // Update positioning
-
- return this;
- },
-
- clear: function () {
- this.$el.html('');
- this.data = [];
- this._index = 0;
- this._$header = this._$footer = this._$noResultsMessage = null;
- },
-
- activate: function () {
- if (!this.shown) {
- this.clear();
- this.$el.show();
- if (this.className) { this.$el.addClass(this.className); }
- this.completer.fire('textComplete:show');
- this.shown = true;
- }
- return this;
- },
-
- deactivate: function () {
- if (this.shown) {
- this.$el.hide();
- if (this.className) { this.$el.removeClass(this.className); }
- this.completer.fire('textComplete:hide');
- this.shown = false;
- }
- return this;
- },
-
- isUp: function (e) {
- return e.keyCode === 38 || (e.ctrlKey && e.keyCode === 80); // UP, Ctrl-P
- },
-
- isDown: function (e) {
- return e.keyCode === 40 || (e.ctrlKey && e.keyCode === 78); // DOWN, Ctrl-N
- },
-
- isEnter: function (e) {
- var modifiers = e.ctrlKey || e.altKey || e.metaKey || e.shiftKey;
- return !modifiers && (e.keyCode === 13 || e.keyCode === 9 || (this.option.completeOnSpace === true && e.keyCode === 32)) // ENTER, TAB
- },
-
- isPageup: function (e) {
- return e.keyCode === 33; // PAGEUP
- },
-
- isPagedown: function (e) {
- return e.keyCode === 34; // PAGEDOWN
- },
-
- isEscape: function (e) {
- return e.keyCode === 27; // ESCAPE
- },
-
- // Private properties
- // ------------------
-
- _data: null, // Currently shown zipped data.
- _index: null,
- _$header: null,
- _$noResultsMessage: null,
- _$footer: null,
-
- // Private methods
- // ---------------
-
- _bindEvents: function () {
- this.$el.on('mousedown.' + this.id, '.textcomplete-item', $.proxy(this._onClick, this));
- this.$el.on('touchstart.' + this.id, '.textcomplete-item', $.proxy(this._onClick, this));
- this.$el.on('mouseover.' + this.id, '.textcomplete-item', $.proxy(this._onMouseover, this));
- this.$inputEl.on('keydown.' + this.id, $.proxy(this._onKeydown, this));
- },
-
- _onClick: function (e) {
- var $el = $(e.target);
- e.preventDefault();
- e.originalEvent.keepTextCompleteDropdown = this.id;
- if (!$el.hasClass('textcomplete-item')) {
- $el = $el.closest('.textcomplete-item');
- }
- var datum = this.data[parseInt($el.data('index'), 10)];
- this.completer.select(datum.value, datum.strategy, e);
- var self = this;
- // Deactive at next tick to allow other event handlers to know whether
- // the dropdown has been shown or not.
- setTimeout(function () {
- self.deactivate();
- if (e.type === 'touchstart') {
- self.$inputEl.focus();
- }
- }, 0);
- },
-
- // Activate hovered item.
- _onMouseover: function (e) {
- var $el = $(e.target);
- e.preventDefault();
- if (!$el.hasClass('textcomplete-item')) {
- $el = $el.closest('.textcomplete-item');
- }
- this._index = parseInt($el.data('index'), 10);
- this._activateIndexedItem();
- },
-
- _onKeydown: function (e) {
- if (!this.shown) { return; }
-
- var command;
-
- if ($.isFunction(this.option.onKeydown)) {
- command = this.option.onKeydown(e, commands);
- }
-
- if (command == null) {
- command = this._defaultKeydown(e);
- }
-
- switch (command) {
- case commands.KEY_UP:
- e.preventDefault();
- this._up();
- break;
- case commands.KEY_DOWN:
- e.preventDefault();
- this._down();
- break;
- case commands.KEY_ENTER:
- e.preventDefault();
- this._enter(e);
- break;
- case commands.KEY_PAGEUP:
- e.preventDefault();
- this._pageup();
- break;
- case commands.KEY_PAGEDOWN:
- e.preventDefault();
- this._pagedown();
- break;
- case commands.KEY_ESCAPE:
- e.preventDefault();
- this.deactivate();
- break;
- }
- },
-
- _defaultKeydown: function (e) {
- if (this.isUp(e)) {
- return commands.KEY_UP;
- } else if (this.isDown(e)) {
- return commands.KEY_DOWN;
- } else if (this.isEnter(e)) {
- return commands.KEY_ENTER;
- } else if (this.isPageup(e)) {
- return commands.KEY_PAGEUP;
- } else if (this.isPagedown(e)) {
- return commands.KEY_PAGEDOWN;
- } else if (this.isEscape(e)) {
- return commands.KEY_ESCAPE;
- }
- },
-
- _up: function () {
- if (this._index === 0) {
- this._index = this.data.length - 1;
- } else {
- this._index -= 1;
- }
- this._activateIndexedItem();
- this._setScroll();
- },
-
- _down: function () {
- if (this._index === this.data.length - 1) {
- this._index = 0;
- } else {
- this._index += 1;
- }
- this._activateIndexedItem();
- this._setScroll();
- },
-
- _enter: function (e) {
- var datum = this.data[parseInt(this._getActiveElement().data('index'), 10)];
- this.completer.select(datum.value, datum.strategy, e);
- this.deactivate();
- },
-
- _pageup: function () {
- var target = 0;
- var threshold = this._getActiveElement().position().top - this.$el.innerHeight();
- this.$el.children().each(function (i) {
- if ($(this).position().top + $(this).outerHeight() > threshold) {
- target = i;
- return false;
- }
- });
- this._index = target;
- this._activateIndexedItem();
- this._setScroll();
- },
-
- _pagedown: function () {
- var target = this.data.length - 1;
- var threshold = this._getActiveElement().position().top + this.$el.innerHeight();
- this.$el.children().each(function (i) {
- if ($(this).position().top > threshold) {
- target = i;
- return false
- }
- });
- this._index = target;
- this._activateIndexedItem();
- this._setScroll();
- },
-
- _activateIndexedItem: function () {
- this.$el.find('.textcomplete-item.active').removeClass('active');
- this._getActiveElement().addClass('active');
- },
-
- _getActiveElement: function () {
- return this.$el.children('.textcomplete-item:nth(' + this._index + ')');
- },
-
- _setScroll: function () {
- var $activeEl = this._getActiveElement();
- var itemTop = $activeEl.position().top;
- var itemHeight = $activeEl.outerHeight();
- var visibleHeight = this.$el.innerHeight();
- var visibleTop = this.$el.scrollTop();
- if (this._index === 0 || this._index == this.data.length - 1 || itemTop < 0) {
- this.$el.scrollTop(itemTop + visibleTop);
- } else if (itemTop + itemHeight > visibleHeight) {
- this.$el.scrollTop(itemTop + itemHeight + visibleTop - visibleHeight);
- }
- },
-
- _buildContents: function (zippedData) {
- var datum, i, index;
- var html = '';
- for (i = 0; i < zippedData.length; i++) {
- if (this.data.length === this.maxCount) break;
- datum = zippedData[i];
- if (include(this.data, datum)) { continue; }
- index = this.data.length;
- this.data.push(datum);
- html += '
';
- html += datum.strategy.template(datum.value, datum.term);
- html += '';
- }
- return html;
- },
-
- _renderHeader: function (unzippedData) {
- if (this.header) {
- if (!this._$header) {
- this._$header = $('').prependTo(this.$el);
- }
- var html = $.isFunction(this.header) ? this.header(unzippedData) : this.header;
- this._$header.html(html);
- }
- },
-
- _renderFooter: function (unzippedData) {
- if (this.footer) {
- if (!this._$footer) {
- this._$footer = $('').appendTo(this.$el);
- }
- var html = $.isFunction(this.footer) ? this.footer(unzippedData) : this.footer;
- this._$footer.html(html);
- }
- },
-
- _renderNoResultsMessage: function (unzippedData) {
- if (this.noResultsMessage) {
- if (!this._$noResultsMessage) {
- this._$noResultsMessage = $('
').appendTo(this.$el);
- }
- var html = $.isFunction(this.noResultsMessage) ? this.noResultsMessage(unzippedData) : this.noResultsMessage;
- this._$noResultsMessage.html(html);
- }
- },
-
- _renderContents: function (html) {
- if (this._$footer) {
- this._$footer.before(html);
- } else {
- this.$el.append(html);
- }
- },
-
- _fitToBottom: function() {
- var windowScrollBottom = $window.scrollTop() + $window.height();
- var height = this.$el.height();
- if ((this.$el.position().top + height) > windowScrollBottom) {
- this.$el.offset({top: windowScrollBottom - height});
- }
- },
-
- _applyPlacement: function (position) {
- // If the 'placement' option set to 'top', move the position above the element.
- if (this.placement.indexOf('top') !== -1) {
- // Overwrite the position object to set the 'bottom' property instead of the top.
- position = {
- top: 'auto',
- bottom: this.$el.parent().height() - position.top + position.lineHeight,
- left: position.left
- };
- } else {
- position.bottom = 'auto';
- delete position.lineHeight;
- }
- if (this.placement.indexOf('absleft') !== -1) {
- position.left = 0;
- } else if (this.placement.indexOf('absright') !== -1) {
- position.right = 0;
- position.left = 'auto';
- }
- return position;
- }
- });
-
- $.fn.textcomplete.Dropdown = Dropdown;
- $.extend($.fn.textcomplete, commands);
-}(jQuery);
-
-+function ($) {
- 'use strict';
-
- // Memoize a search function.
- var memoize = function (func) {
- var memo = {};
- return function (term, callback) {
- if (memo[term]) {
- callback(memo[term]);
- } else {
- func.call(this, term, function (data) {
- memo[term] = (memo[term] || []).concat(data);
- callback.apply(null, arguments);
- });
- }
- };
- };
-
- function Strategy(options) {
- $.extend(this, options);
- if (this.cache) { this.search = memoize(this.search); }
- }
-
- Strategy.parse = function (strategiesArray, params) {
- return $.map(strategiesArray, function (strategy) {
- var strategyObj = new Strategy(strategy);
- strategyObj.el = params.el;
- strategyObj.$el = params.$el;
- return strategyObj;
- });
- };
-
- $.extend(Strategy.prototype, {
- // Public properties
- // -----------------
-
- // Required
- match: null,
- replace: null,
- search: null,
-
- // Optional
- cache: false,
- context: function () { return true; },
- index: 2,
- template: function (obj) { return obj; },
- idProperty: null
- });
-
- $.fn.textcomplete.Strategy = Strategy;
-
-}(jQuery);
-
-+function ($) {
- 'use strict';
-
- var now = Date.now || function () { return new Date().getTime(); };
-
- // Returns a function, that, as long as it continues to be invoked, will not
- // be triggered. The function will be called after it stops being called for
- // `wait` msec.
- //
- // This utility function was originally implemented at Underscore.js.
- var debounce = function (func, wait) {
- var timeout, args, context, timestamp, result;
- var later = function () {
- var last = now() - timestamp;
- if (last < wait) {
- timeout = setTimeout(later, wait - last);
- } else {
- timeout = null;
- result = func.apply(context, args);
- context = args = null;
- }
- };
-
- return function () {
- context = this;
- args = arguments;
- timestamp = now();
- if (!timeout) {
- timeout = setTimeout(later, wait);
- }
- return result;
- };
- };
-
- function Adapter () {}
-
- $.extend(Adapter.prototype, {
- // Public properties
- // -----------------
-
- id: null, // Identity.
- completer: null, // Completer object which creates it.
- el: null, // Textarea element.
- $el: null, // jQuery object of the textarea.
- option: null,
-
- // Public methods
- // --------------
-
- initialize: function (element, completer, option) {
- this.el = element;
- this.$el = $(element);
- this.id = completer.id + this.constructor.name;
- this.completer = completer;
- this.option = option;
-
- if (this.option.debounce) {
- this._onKeyup = debounce(this._onKeyup, this.option.debounce);
- }
-
- this._bindEvents();
- },
-
- destroy: function () {
- this.$el.off('.' + this.id); // Remove all event handlers.
- this.$el = this.el = this.completer = null;
- },
-
- // Update the element with the given value and strategy.
- //
- // value - The selected object. It is one of the item of the array
- // which was callbacked from the search function.
- // strategy - The Strategy associated with the selected value.
- select: function (/* value, strategy */) {
- throw new Error('Not implemented');
- },
-
- // Returns the caret's relative coordinates from body's left top corner.
- //
- // FIXME: Calculate the left top corner of `this.option.appendTo` element.
- getCaretPosition: function () {
- var position = this._getCaretRelativePosition();
- var offset = this.$el.offset();
- position.top += offset.top;
- position.left += offset.left;
- return position;
- },
-
- // Focus on the element.
- focus: function () {
- this.$el.focus();
- },
-
- // Private methods
- // ---------------
-
- _bindEvents: function () {
- this.$el.on('keyup.' + this.id, $.proxy(this._onKeyup, this));
- },
-
- _onKeyup: function (e) {
- if (this._skipSearch(e)) { return; }
- this.completer.trigger(this.getTextFromHeadToCaret(), true);
- },
-
- // Suppress searching if it returns true.
- _skipSearch: function (clickEvent) {
- switch (clickEvent.keyCode) {
- case 13: // ENTER
- case 40: // DOWN
- case 38: // UP
- return true;
- }
- if (clickEvent.ctrlKey) switch (clickEvent.keyCode) {
- case 78: // Ctrl-N
- case 80: // Ctrl-P
- return true;
- }
- }
- });
-
- $.fn.textcomplete.Adapter = Adapter;
-}(jQuery);
-
-+function ($) {
- 'use strict';
-
- // Textarea adapter
- // ================
- //
- // Managing a textarea. It doesn't know a Dropdown.
- function Textarea(element, completer, option) {
- this.initialize(element, completer, option);
- }
-
- Textarea.DIV_PROPERTIES = {
- left: -9999,
- position: 'absolute',
- top: 0,
- whiteSpace: 'pre-wrap'
- }
-
- Textarea.COPY_PROPERTIES = [
- 'border-width', 'font-family', 'font-size', 'font-style', 'font-variant',
- 'font-weight', 'height', 'letter-spacing', 'word-spacing', 'line-height',
- 'text-decoration', 'text-align', 'width', 'padding-top', 'padding-right',
- 'padding-bottom', 'padding-left', 'margin-top', 'margin-right',
- 'margin-bottom', 'margin-left', 'border-style', 'box-sizing', 'tab-size'
- ];
-
- $.extend(Textarea.prototype, $.fn.textcomplete.Adapter.prototype, {
- // Public methods
- // --------------
-
- // Update the textarea with the given value and strategy.
- select: function (value, strategy, e) {
- var pre = this.getTextFromHeadToCaret();
- var post = this.el.value.substring(this.el.selectionEnd);
- var newSubstr = strategy.replace(value, e);
- if (typeof newSubstr !== 'undefined') {
- if ($.isArray(newSubstr)) {
- post = newSubstr[1] + post;
- newSubstr = newSubstr[0];
- }
- pre = pre.replace(strategy.match, newSubstr);
- this.$el.val(pre + post);
- this.el.selectionStart = this.el.selectionEnd = pre.length;
- }
- },
-
- // Private methods
- // ---------------
-
- // Returns the caret's relative coordinates from textarea's left top corner.
- //
- // Browser native API does not provide the way to know the position of
- // caret in pixels, so that here we use a kind of hack to accomplish
- // the aim. First of all it puts a dummy div element and completely copies
- // the textarea's style to the element, then it inserts the text and a
- // span element into the textarea.
- // Consequently, the span element's position is the thing what we want.
- _getCaretRelativePosition: function () {
- var dummyDiv = $('
').css(this._copyCss())
- .text(this.getTextFromHeadToCaret());
- var span = $('
').text('.').appendTo(dummyDiv);
- this.$el.before(dummyDiv);
- var position = span.position();
- position.top += span.height() - this.$el.scrollTop();
- position.lineHeight = span.height();
- dummyDiv.remove();
- return position;
- },
-
- _copyCss: function () {
- return $.extend({
- // Set 'scroll' if a scrollbar is being shown; otherwise 'auto'.
- overflow: this.el.scrollHeight > this.el.offsetHeight ? 'scroll' : 'auto'
- }, Textarea.DIV_PROPERTIES, this._getStyles());
- },
-
- _getStyles: (function ($) {
- var color = $('
').css(['color']).color;
- if (typeof color !== 'undefined') {
- return function () {
- return this.$el.css(Textarea.COPY_PROPERTIES);
- };
- } else { // jQuery < 1.8
- return function () {
- var $el = this.$el;
- var styles = {};
- $.each(Textarea.COPY_PROPERTIES, function (i, property) {
- styles[property] = $el.css(property);
- });
- return styles;
- };
- }
- })($),
-
- getTextFromHeadToCaret: function () {
- return this.el.value.substring(0, this.el.selectionEnd);
- }
- });
-
- $.fn.textcomplete.Textarea = Textarea;
-}(jQuery);
-
-+function ($) {
- 'use strict';
-
- var sentinelChar = '吶';
-
- function IETextarea(element, completer, option) {
- this.initialize(element, completer, option);
- $('
' + sentinelChar + '').css({
- position: 'absolute',
- top: -9999,
- left: -9999
- }).insertBefore(element);
- }
-
- $.extend(IETextarea.prototype, $.fn.textcomplete.Textarea.prototype, {
- // Public methods
- // --------------
-
- select: function (value, strategy, e) {
- var pre = this.getTextFromHeadToCaret();
- var post = this.el.value.substring(pre.length);
- var newSubstr = strategy.replace(value, e);
- if (typeof newSubstr !== 'undefined') {
- if ($.isArray(newSubstr)) {
- post = newSubstr[1] + post;
- newSubstr = newSubstr[0];
- }
- pre = pre.replace(strategy.match, newSubstr);
- this.$el.val(pre + post);
- this.el.focus();
- var range = this.el.createTextRange();
- range.collapse(true);
- range.moveEnd('character', pre.length);
- range.moveStart('character', pre.length);
- range.select();
- }
- },
-
- getTextFromHeadToCaret: function () {
- this.el.focus();
- var range = document.selection.createRange();
- range.moveStart('character', -this.el.value.length);
- var arr = range.text.split(sentinelChar)
- return arr.length === 1 ? arr[0] : arr[1];
- }
- });
-
- $.fn.textcomplete.IETextarea = IETextarea;
-}(jQuery);
-
-// NOTE: TextComplete plugin has contenteditable support but it does not work
-// fine especially on old IEs.
-// Any pull requests are REALLY welcome.
-
-+function ($) {
- 'use strict';
-
- // ContentEditable adapter
- // =======================
- //
- // Adapter for contenteditable elements.
- function ContentEditable (element, completer, option) {
- this.initialize(element, completer, option);
- }
-
- $.extend(ContentEditable.prototype, $.fn.textcomplete.Adapter.prototype, {
- // Public methods
- // --------------
-
- // Update the content with the given value and strategy.
- // When an dropdown item is selected, it is executed.
- select: function (value, strategy, e) {
- var pre = this.getTextFromHeadToCaret();
- var sel = window.getSelection()
- var range = sel.getRangeAt(0);
- var selection = range.cloneRange();
- selection.selectNodeContents(range.startContainer);
- var content = selection.toString();
- var post = content.substring(range.startOffset);
- var newSubstr = strategy.replace(value, e);
- if (typeof newSubstr !== 'undefined') {
- if ($.isArray(newSubstr)) {
- post = newSubstr[1] + post;
- newSubstr = newSubstr[0];
- }
- pre = pre.replace(strategy.match, newSubstr);
- range.selectNodeContents(range.startContainer);
- range.deleteContents();
- var node = document.createTextNode(pre + post);
- range.insertNode(node);
- range.setStart(node, pre.length);
- range.collapse(true);
- sel.removeAllRanges();
- sel.addRange(range);
- }
- },
-
- // Private methods
- // ---------------
-
- // Returns the caret's relative position from the contenteditable's
- // left top corner.
- //
- // Examples
- //
- // this._getCaretRelativePosition()
- // //=> { top: 18, left: 200, lineHeight: 16 }
- //
- // Dropdown's position will be decided using the result.
- _getCaretRelativePosition: function () {
- var range = window.getSelection().getRangeAt(0).cloneRange();
- var node = document.createElement('span');
- range.insertNode(node);
- range.selectNodeContents(node);
- range.deleteContents();
- var $node = $(node);
- var position = $node.offset();
- position.left -= this.$el.offset().left;
- position.top += $node.height() - this.$el.offset().top;
- position.lineHeight = $node.height();
- $node.remove();
- return position;
- },
-
- // Returns the string between the first character and the caret.
- // Completer will be triggered with the result for start autocompleting.
- //
- // Example
- //
- // // Suppose the html is '
hello wor|ld' and | is the caret.
- // this.getTextFromHeadToCaret()
- // // => ' wor' // not '
hello wor'
- getTextFromHeadToCaret: function () {
- var range = window.getSelection().getRangeAt(0);
- var selection = range.cloneRange();
- selection.selectNodeContents(range.startContainer);
- return selection.toString().substring(0, range.startOffset);
- }
- });
-
- $.fn.textcomplete.ContentEditable = ContentEditable;
-}(jQuery);
-
-return jQuery;
-}));
diff --git a/assets/js/vendor/simplemde.min.js b/assets/js/vendor/simplemde.min.js
new file mode 100644
index 000000000..89bee7f35
--- /dev/null
+++ b/assets/js/vendor/simplemde.min.js
@@ -0,0 +1,14 @@
+/**
+ * simplemde v1.10.1
+ * Copyright Next Step Webs, Inc.
+ * @link https://github.com/NextStepWebs/simplemde-markdown-editor
+ * @license MIT
+ */
+!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.SimpleMDE=e()}}(function(){var e;return function t(e,n,r){function i(l,a){if(!n[l]){if(!e[l]){var s="function"==typeof require&&require;if(!a&&s)return s(l,!0);if(o)return o(l,!0);var c=new Error("Cannot find module '"+l+"'");throw c.code="MODULE_NOT_FOUND",c}var u=n[l]={exports:{}};e[l][0].call(u.exports,function(t){var n=e[l][1][t];return i(n?n:t)},u,u.exports,t,e,n,r)}return n[l].exports}for(var o="function"==typeof require&&require,l=0;l
o;o++)for(var a=this.compoundRules[o],s=0,c=a.length;c>s;s++)this.compoundRuleCodes[a[s]]=[];"ONLYINCOMPOUND"in this.flags&&(this.compoundRuleCodes[this.flags.ONLYINCOMPOUND]=[]),this.dictionaryTable=this._parseDIC(n);for(var o in this.compoundRuleCodes)0==this.compoundRuleCodes[o].length&&delete this.compoundRuleCodes[o];for(var o=0,l=this.compoundRules.length;l>o;o++){for(var u=this.compoundRules[o],d="",s=0,c=u.length;c>s;s++){var h=u[s];d+=h in this.compoundRuleCodes?"("+this.compoundRuleCodes[h].join("|")+")":h}this.compoundRules[o]=new RegExp(d,"i")}}return this};o.prototype={load:function(e){for(var t in e)this[t]=e[t];return this},_readFile:function(e,t){t||(t="ISO8859-1");var n=new XMLHttpRequest;return n.open("GET",e,!1),n.overrideMimeType&&n.overrideMimeType("text/plain; charset="+t),n.send(null),n.responseText},_parseAFF:function(e){var t={};e=this._removeAffixComments(e);for(var n=e.split("\n"),r=0,i=n.length;i>r;r++){var o=n[r],l=o.split(/\s+/),a=l[0];if("PFX"==a||"SFX"==a){for(var s=l[1],c=l[2],u=parseInt(l[3],10),d=[],h=r+1,f=r+1+u;f>h;h++){var o=n[h],p=o.split(/\s+/),m=p[2],g=p[3].split("/"),v=g[0];"0"===v&&(v="");var y=this.parseRuleCodes(g[1]),x=p[4],b={};b.add=v,y.length>0&&(b.continuationClasses=y),"."!==x&&("SFX"===a?b.match=new RegExp(x+"$"):b.match=new RegExp("^"+x)),"0"!=m&&("SFX"===a?b.remove=new RegExp(m+"$"):b.remove=m),d.push(b)}t[s]={type:a,combineable:"Y"==c,entries:d},r+=u}else if("COMPOUNDRULE"===a){for(var u=parseInt(l[1],10),h=r+1,f=r+1+u;f>h;h++){var o=n[h],p=o.split(/\s+/);this.compoundRules.push(p[1])}r+=u}else if("REP"===a){var p=o.split(/\s+/);3===p.length&&this.replacementTable.push([p[1],p[2]])}else this.flags[a]=l[1]}return t},_removeAffixComments:function(e){return e=e.replace(/#.*$/gm,""),e=e.replace(/^\s\s*/m,"").replace(/\s\s*$/m,""),e=e.replace(/\n{2,}/g,"\n"),e=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},_parseDIC:function(e){function t(e,t){e in r&&"object"==typeof r[e]||(r[e]=[]),r[e].push(t)}e=this._removeDicComments(e);for(var n=e.split("\n"),r={},i=1,o=n.length;o>i;i++){var l=n[i],a=l.split("/",2),s=a[0];if(a.length>1){var c=this.parseRuleCodes(a[1]);"NEEDAFFIX"in this.flags&&-1!=c.indexOf(this.flags.NEEDAFFIX)||t(s,c);for(var u=0,d=c.length;d>u;u++){var h=c[u],f=this.rules[h];if(f)for(var p=this._applyRule(s,f),m=0,g=p.length;g>m;m++){var v=p[m];if(t(v,[]),f.combineable)for(var y=u+1;d>y;y++){var x=c[y],b=this.rules[x];if(b&&b.combineable&&f.type!=b.type)for(var w=this._applyRule(v,b),k=0,C=w.length;C>k;k++){var S=w[k];t(S,[])}}}h in this.compoundRuleCodes&&this.compoundRuleCodes[h].push(s)}}else t(s.trim(),[])}return r},_removeDicComments:function(e){return e=e.replace(/^\t.*$/gm,"")},parseRuleCodes:function(e){if(!e)return[];if(!("FLAG"in this.flags))return e.split("");if("long"===this.flags.FLAG){for(var t=[],n=0,r=e.length;r>n;n+=2)t.push(e.substr(n,2));return t}return"num"===this.flags.FLAG?textCode.split(","):void 0},_applyRule:function(e,t){for(var n=t.entries,r=[],i=0,o=n.length;o>i;i++){var l=n[i];if(!l.match||e.match(l.match)){var a=e;if(l.remove&&(a=a.replace(l.remove,"")),"SFX"===t.type?a+=l.add:a=l.add+a,r.push(a),"continuationClasses"in l)for(var s=0,c=l.continuationClasses.length;c>s;s++){var u=this.rules[l.continuationClasses[s]];u&&(r=r.concat(this._applyRule(a,u)))}}}return r},check:function(e){var t=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(this.checkExact(t))return!0;if(t.toUpperCase()===t){var n=t[0]+t.substring(1).toLowerCase();if(this.hasFlag(n,"KEEPCASE"))return!1;if(this.checkExact(n))return!0}var r=t.toLowerCase();if(r!==t){if(this.hasFlag(r,"KEEPCASE"))return!1;if(this.checkExact(r))return!0}return!1},checkExact:function(e){var t=this.dictionaryTable[e];if("undefined"==typeof t){if("COMPOUNDMIN"in this.flags&&e.length>=this.flags.COMPOUNDMIN)for(var n=0,r=this.compoundRules.length;r>n;n++)if(e.match(this.compoundRules[n]))return!0;return!1}for(var n=0,r=t.length;r>n;n++)if(!this.hasFlag(e,"ONLYINCOMPOUND",t[n]))return!0;return!1},hasFlag:function(e,t,n){if(t in this.flags){if("undefined"==typeof n)var n=Array.prototype.concat.apply([],this.dictionaryTable[e]);if(n&&-1!==n.indexOf(this.flags[t]))return!0}return!1},alphabet:"",suggest:function(e,t){function n(e){for(var t=[],n=0,r=e.length;r>n;n++){for(var i=e[n],o=[],l=0,a=i.length+1;a>l;l++)o.push([i.substring(0,l),i.substring(l,i.length)]);for(var s=[],l=0,a=o.length;a>l;l++){var u=o[l];u[1]&&s.push(u[0]+u[1].substring(1))}for(var d=[],l=0,a=o.length;a>l;l++){var u=o[l];u[1].length>1&&d.push(u[0]+u[1][1]+u[1][0]+u[1].substring(2))}for(var h=[],l=0,a=o.length;a>l;l++){var u=o[l];if(u[1])for(var f=0,p=c.alphabet.length;p>f;f++)h.push(u[0]+c.alphabet[f]+u[1].substring(1))}for(var m=[],l=0,a=o.length;a>l;l++){var u=o[l];if(u[1])for(var f=0,p=c.alphabet.length;p>f;f++)h.push(u[0]+c.alphabet[f]+u[1])}t=t.concat(s),t=t.concat(d),t=t.concat(h),t=t.concat(m)}return t}function r(e){for(var t=[],n=0;nu;u++)a[u]in s?s[a[u]]+=1:s[a[u]]=1;var h=[];for(var u in s)h.push([u,s[u]]);h.sort(i).reverse();for(var f=[],u=0,d=Math.min(t,h.length);d>u;u++)c.hasFlag(h[u][0],"NOSUGGEST")||f.push(h[u][0]);return f}if(t||(t=5),this.check(e))return[];for(var o=0,l=this.replacementTable.length;l>o;o++){var a=this.replacementTable[o];if(-1!==e.indexOf(a[0])){var s=e.replace(a[0],a[1]);if(this.check(s))return[s]}}var c=this;return c.alphabet="abcdefghijklmnopqrstuvwxyz",i(e)}},i("undefined"!=typeof o?o:window.Typo)}).call(e,void 0,void 0,void 0,void 0,function(e){t.exports=e})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(t,n,r){!function(i){"object"==typeof r&&"object"==typeof n?i(t("../../lib/codemirror")):"function"==typeof e&&e.amd?e(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";function t(e){var t=e.getWrapperElement();e.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:t.style.width,height:t.style.height},t.style.width="",t.style.height="auto",t.className+=" CodeMirror-fullscreen",document.documentElement.style.overflow="hidden",e.refresh()}function n(e){var t=e.getWrapperElement();t.className=t.className.replace(/\s*CodeMirror-fullscreen\b/,""),document.documentElement.style.overflow="";var n=e.state.fullScreenRestore;t.style.width=n.width,t.style.height=n.height,window.scrollTo(n.scrollLeft,n.scrollTop),e.refresh()}e.defineOption("fullScreen",!1,function(r,i,o){o==e.Init&&(o=!1),!o!=!i&&(i?t(r):n(r))})})},{"../../lib/codemirror":7}],4:[function(t,n,r){!function(i){"object"==typeof r&&"object"==typeof n?i(t("../../lib/codemirror")):"function"==typeof e&&e.amd?e(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){function t(e){e.state.placeholder&&(e.state.placeholder.parentNode.removeChild(e.state.placeholder),e.state.placeholder=null)}function n(e){t(e);var n=e.state.placeholder=document.createElement("pre");n.style.cssText="height: 0; overflow: visible",n.className="CodeMirror-placeholder";var r=e.getOption("placeholder");"string"==typeof r&&(r=document.createTextNode(r)),n.appendChild(r),e.display.lineSpace.insertBefore(n,e.display.lineSpace.firstChild)}function r(e){o(e)&&n(e)}function i(e){var r=e.getWrapperElement(),i=o(e);r.className=r.className.replace(" CodeMirror-empty","")+(i?" CodeMirror-empty":""),i?n(e):t(e)}function o(e){return 1===e.lineCount()&&""===e.getLine(0)}e.defineOption("placeholder","",function(n,o,l){var a=l&&l!=e.Init;if(o&&!a)n.on("blur",r),n.on("change",i),n.on("swapDoc",i),i(n);else if(!o&&a){n.off("blur",r),n.off("change",i),n.off("swapDoc",i),t(n);var s=n.getWrapperElement();s.className=s.className.replace(" CodeMirror-empty","")}o&&!n.hasFocus()&&r(n)})})},{"../../lib/codemirror":7}],5:[function(t,n,r){!function(i){"object"==typeof r&&"object"==typeof n?i(t("../../lib/codemirror")):"function"==typeof e&&e.amd?e(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";var t=/^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,n=/^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,r=/[*+-]\s/;e.commands.newlineAndIndentContinueMarkdownList=function(i){if(i.getOption("disableInput"))return e.Pass;for(var o=i.listSelections(),l=[],a=0;a")>=0?f[2]:parseInt(f[3],10)+1+f[4];l[a]="\n"+p+g+m}}i.replaceSelections(l)}})},{"../../lib/codemirror":7}],6:[function(t,n,r){!function(i){"object"==typeof r&&"object"==typeof n?i(t("../../lib/codemirror")):"function"==typeof e&&e.amd?e(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";e.overlayMode=function(t,n,r){return{startState:function(){return{base:e.startState(t),overlay:e.startState(n),basePos:0,baseCur:null,overlayPos:0,overlayCur:null,streamSeen:null}},copyState:function(r){return{base:e.copyState(t,r.base),overlay:e.copyState(n,r.overlay),basePos:r.basePos,baseCur:null,overlayPos:r.overlayPos,overlayCur:null}},token:function(e,i){return(e!=i.streamSeen||Math.min(i.basePos,i.overlayPos)bo&&setTimeout(function(){s.display.input.reset(!0)},20),_t(this),Xi(),bt(this),this.curOp.forceUpdate=!0,Yr(this,i),r.autofocus&&!Ao||s.hasFocus()?setTimeout(zi(vn,this),20):yn(this);for(var u in el)el.hasOwnProperty(u)&&el[u](this,r[u],tl);k(this),r.finishInit&&r.finishInit(this);for(var d=0;dbo&&(r.gutters.style.zIndex=-1,r.scroller.style.paddingRight=0),wo||go&&Ao||(r.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(r.wrapper):e(r.wrapper)),r.viewFrom=r.viewTo=t.first,r.reportedViewFrom=r.reportedViewTo=t.first,r.view=[],r.renderedView=null,r.externalMeasured=null,r.viewOffset=0,r.lastWrapHeight=r.lastWrapWidth=0,r.updateLineNumbers=null,r.nativeBarWidth=r.barHeight=r.barWidth=0,r.scrollbarsClipped=!1,r.lineNumWidth=r.lineNumInnerWidth=r.lineNumChars=null,r.alignWidgets=!1,r.cachedCharWidth=r.cachedTextHeight=r.cachedPaddingH=null,r.maxLine=null,r.maxLineLength=0,r.maxLineChanged=!1,r.wheelDX=r.wheelDY=r.wheelStartX=r.wheelStartY=null,r.shift=!1,r.selForContextMenu=null,r.activeTouch=null,n.init(r)}function n(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),r(t)}function r(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,Re(e,100),e.state.modeGen++,e.curOp&&Dt(e)}function i(e){e.options.lineWrapping?(Zl(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(Yl(e.display.wrapper,"CodeMirror-wrap"),h(e)),l(e),Dt(e),at(e),setTimeout(function(){y(e)},100)}function o(e){var t=yt(e.display),n=e.options.lineWrapping,r=n&&Math.max(5,e.display.scroller.clientWidth/xt(e.display)-3);return function(i){if(kr(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;lt.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}function f(e){var t=Ii(e.gutters,"CodeMirror-linenumbers");-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function p(e){var t=e.display,n=t.gutters.offsetWidth,r=Math.round(e.doc.height+Ue(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?n:0,docHeight:r,scrollHeight:r+$e(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}function m(e,t,n){this.cm=n;var r=this.vert=_i("div",[_i("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=_i("div",[_i("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(r),e(i),Al(r,"scroll",function(){r.clientHeight&&t(r.scrollTop,"vertical")}),Al(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,xo&&8>bo&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function g(){}function v(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&Yl(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),Al(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,n){"horizontal"==n?on(t,e):rn(t,e)},t),t.display.scrollbars.addClass&&Zl(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=p(e));var n=e.display.barWidth,r=e.display.barHeight;x(e,t);for(var i=0;4>i&&n!=e.display.barWidth||r!=e.display.barHeight;i++)n!=e.display.barWidth&&e.options.lineWrapping&&H(e),x(e,p(e)),n=e.display.barWidth,r=e.display.barHeight}function x(e,t){var n=e.display,r=n.scrollbars.update(t);n.sizer.style.paddingRight=(n.barWidth=r.right)+"px",n.sizer.style.paddingBottom=(n.barHeight=r.bottom)+"px",n.heightForcer.style.borderBottom=r.bottom+"px solid transparent",r.right&&r.bottom?(n.scrollbarFiller.style.display="block",n.scrollbarFiller.style.height=r.bottom+"px",n.scrollbarFiller.style.width=r.right+"px"):n.scrollbarFiller.style.display="",r.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(n.gutterFiller.style.display="block",n.gutterFiller.style.height=r.bottom+"px",n.gutterFiller.style.width=t.gutterWidth+"px"):n.gutterFiller.style.display=""}function b(e,t,n){var r=n&&null!=n.top?Math.max(0,n.top):e.scroller.scrollTop;r=Math.floor(r-qe(e));var i=n&&null!=n.bottom?n.bottom:r+e.wrapper.clientHeight,o=ni(t,r),l=ni(t,i);if(n&&n.ensure){var a=n.ensure.from.line,s=n.ensure.to.line;o>a?(o=a,l=ni(t,ri(Zr(t,a))+e.wrapper.clientHeight)):Math.min(s,t.lastLine())>=l&&(o=ni(t,ri(Zr(t,s))-e.wrapper.clientHeight),l=s)}return{from:o,to:Math.max(l,o+1)}}function w(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var r=S(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=r+"px",l=0;l=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==jt(e))return!1;k(e)&&(Ft(e),t.dims=I(e));var i=r.first+r.size,o=Math.max(t.visible.from-e.options.viewportMargin,r.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);n.viewFroml&&n.viewTo-l<20&&(l=Math.min(i,n.viewTo)),Po&&(o=br(e.doc,o),l=wr(e.doc,l));var a=o!=n.viewFrom||l!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;Bt(e,o,l),n.viewOffset=ri(Zr(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var s=jt(e);if(!a&&0==s&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var c=Gi();return s>4&&(n.lineDiv.style.display="none"),E(e,n.updateLineNumbers,t.dims),s>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,c&&Gi()!=c&&c.offsetHeight&&c.focus(),qi(n.cursorDiv),qi(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,a&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,Re(e,400)),n.updateLineNumbers=null,!0}function N(e,t){for(var n=t.viewport,r=!0;(r&&e.options.lineWrapping&&t.oldDisplayWidth!=Ve(e)||(n&&null!=n.top&&(n={top:Math.min(e.doc.height+Ue(e.display)-Ke(e),n.top)}),t.visible=b(e.display,e.doc,n),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&M(e,t);r=!1){H(e);var i=p(e);Ee(e),O(e,i),y(e,i)}t.signal(e,"update",e),e.display.viewFrom==e.display.reportedViewFrom&&e.display.viewTo==e.display.reportedViewTo||(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function A(e,t){var n=new L(e,t);if(M(e,n)){H(e),N(e,n);var r=p(e);Ee(e),O(e,r),y(e,r),n.finish()}}function O(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=Math.max(t.docHeight+e.display.barHeight+$e(e),t.clientHeight)+"px"}function H(e){for(var t=e.display,n=t.lineDiv.offsetTop,r=0;rbo){var l=o.node.offsetTop+o.node.offsetHeight;i=l-n,n=l}else{var a=o.node.getBoundingClientRect();i=a.bottom-a.top}var s=o.line.height-i;if(2>i&&(i=yt(t)),(s>.001||-.001>s)&&(ei(o.line,i),W(o.line),o.rest))for(var c=0;c=t&&d.lineNumber;d.changes&&(Ii(d.changes,"gutter")>-1&&(h=!1),D(e,d,c,n)),h&&(qi(d.lineNumber),d.lineNumber.appendChild(document.createTextNode(C(e.options,c)))),a=d.node.nextSibling}else{var f=q(e,d,c,n);l.insertBefore(f,a)}c+=d.size}for(;a;)a=r(a)}function D(e,t,n,r){for(var i=0;ibo&&(e.node.style.zIndex=2)),e.node}function F(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var n=P(e);e.background=n.insertBefore(_i("div",null,t),n.firstChild)}}function z(e,t){var n=e.display.externalMeasured;return n&&n.line==t.line?(e.display.externalMeasured=null,t.measure=n.measure,n.built):zr(e,t)}function R(e,t){var n=t.text.className,r=z(e,t);t.text==t.node&&(t.node=r.pre),t.text.parentNode.replaceChild(r.pre,t.text),t.text=r.pre,r.bgClass!=t.bgClass||r.textClass!=t.textClass?(t.bgClass=r.bgClass,t.textClass=r.textClass,B(t)):n&&(t.text.className=n)}function B(e){F(e),e.line.wrapClass?P(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function j(e,t,n,r){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var i=P(t);t.gutterBackground=_i("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?r.fixedPos:-r.gutterTotalWidth)+"px; width: "+r.gutterTotalWidth+"px"),i.insertBefore(t.gutterBackground,t.text)}var o=t.line.gutterMarkers;if(e.options.lineNumbers||o){var i=P(t),l=t.gutter=_i("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?r.fixedPos:-r.gutterTotalWidth)+"px");if(e.display.input.setUneditable(l),i.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||o&&o["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(_i("div",C(e.options,n),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+r.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),o)for(var a=0;a1)if(Ro&&Ro.join("\n")==t){if(r.ranges.length%Ro.length==0){s=[];for(var c=0;c=0;c--){var u=r.ranges[c],d=u.from(),h=u.to();u.empty()&&(n&&n>0?d=Fo(d.line,d.ch-n):e.state.overwrite&&!l&&(h=Fo(h.line,Math.min(Zr(o,h.line).text.length,h.ch+Wi(a).length))));var f=e.curOp.updateInput,p={from:d,to:h,text:s?s[c%s.length]:a,origin:i||(l?"paste":e.state.cutIncoming?"cut":"+input")};Tn(e.doc,p),Si(e,"inputRead",e,p)}t&&!l&&J(e,t),zn(e),e.curOp.updateInput=f,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function Q(e,t){var n=e.clipboardData&&e.clipboardData.getData("text/plain");return n?(e.preventDefault(),t.isReadOnly()||t.options.disableInput||At(t,function(){Z(t,n,0,null,"paste")}),!0):void 0}function J(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var n=e.doc.sel,r=n.ranges.length-1;r>=0;r--){var i=n.ranges[r];if(!(i.head.ch>100||r&&n.ranges[r-1].head.line==i.head.line)){var o=e.getModeAt(i.head),l=!1;if(o.electricChars){for(var a=0;a-1){l=Bn(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Zr(e.doc,i.head.line).text.slice(0,i.head.ch))&&(l=Bn(e,i.head.line,"smart"));l&&Si(e,"electricInput",e,i.head.line)}}}function ee(e){for(var t=[],n=[],r=0;ri?c.map:u[i],l=0;li?e.line:e.rest[i]),d=o[l]+r;return(0>r||a!=t)&&(d=o[l+(r?1:0)]),Fo(s,d)}}}var i=e.text.firstChild,o=!1;if(!t||!Vl(i,t))return le(Fo(ti(e.line),0),!0);if(t==i&&(o=!0,t=i.childNodes[n],n=0,!t)){var l=e.rest?Wi(e.rest):e.line;return le(Fo(ti(l),l.text.length),o)}var a=3==t.nodeType?t:null,s=t;for(a||1!=t.childNodes.length||3!=t.firstChild.nodeType||(a=t.firstChild,n&&(n=a.nodeValue.length));s.parentNode!=i;)s=s.parentNode;var c=e.measure,u=c.maps,d=r(a,s,n);if(d)return le(d,o);for(var h=s.nextSibling,f=a?a.nodeValue.length-n:0;h;h=h.nextSibling){if(d=r(h,h.firstChild,0))return le(Fo(d.line,d.ch-f),o);f+=h.textContent.length}for(var p=s.previousSibling,f=n;p;p=p.previousSibling){if(d=r(p,p.firstChild,-1))return le(Fo(d.line,d.ch+f),o);f+=h.textContent.length}}function ce(e,t,n,r,i){function o(e){return function(t){return t.id==e}}function l(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(null!=n)return""==n&&(n=t.textContent.replace(/\u200b/g,"")),void(a+=n);var u,d=t.getAttribute("cm-marker");if(d){var h=e.findMarks(Fo(r,0),Fo(i+1,0),o(+d));return void(h.length&&(u=h[0].find())&&(a+=Qr(e.doc,u.from,u.to).join(c)))}if("false"==t.getAttribute("contenteditable"))return;for(var f=0;f=0){var l=X(o.from(),i.from()),a=K(o.to(),i.to()),s=o.empty()?i.from()==i.head:o.from()==o.head;t>=r&&--t,e.splice(--r,2,new de(s?a:l,s?l:a))}}return new ue(e,t)}function fe(e,t){return new ue([new de(e,t||e)],0)}function pe(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function me(e,t){if(t.linen?Fo(n,Zr(e,n).text.length):ge(t,Zr(e,t.line).text.length)}function ge(e,t){var n=e.ch;return null==n||n>t?Fo(e.line,t):0>n?Fo(e.line,0):e}function ve(e,t){return t>=e.first&&t=t.ch:a.to>t.ch))){if(i&&(Wl(s,"beforeCursorEnter"),s.explicitlyCleared)){if(o.markedSpans){--l;continue}break}if(!s.atomic)continue;if(n){var c,u=s.find(0>r?1:-1);if((0>r?s.inclusiveRight:s.inclusiveLeft)&&(u=Ie(e,u,-r,u&&u.line==t.line?o:null)),u&&u.line==t.line&&(c=zo(u,n))&&(0>r?0>c:c>0))return He(e,u,t,r,i)}var d=s.find(0>r?-1:1);return(0>r?s.inclusiveLeft:s.inclusiveRight)&&(d=Ie(e,d,r,d.line==t.line?o:null)),d?He(e,d,t,r,i):null}}return t}function We(e,t,n,r,i){var o=r||1,l=He(e,t,n,o,i)||!i&&He(e,t,n,o,!0)||He(e,t,n,-o,i)||!i&&He(e,t,n,-o,!0);return l?l:(e.cantEdit=!0,Fo(e.first,0))}function Ie(e,t,n,r){return 0>n&&0==t.ch?t.line>e.first?me(e,Fo(t.line-1)):null:n>0&&t.ch==(r||Zr(e,t.line)).text.length?t.line=e.display.viewTo||a.to().linet&&(t=0),t=Math.round(t),r=Math.round(r),a.appendChild(_i("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==n?u-e:n)+"px; height: "+(r-t)+"px"))}function i(t,n,i){function o(n,r){return ht(e,Fo(t,n),"div",d,r)}var a,s,d=Zr(l,t),h=d.text.length;return eo(ii(d),n||0,null==i?h:i,function(e,t,l){var d,f,p,m=o(e,"left");if(e==t)d=m,f=p=m.left;else{if(d=o(t-1,"right"),"rtl"==l){var g=m;m=d,d=g}f=m.left,p=d.right}null==n&&0==e&&(f=c),d.top-m.top>3&&(r(f,m.top,null,m.bottom),f=c,m.bottoms.bottom||d.bottom==s.bottom&&d.right>s.right)&&(s=d),c+1>f&&(f=c),r(f,d.top,p-f,d.bottom)}),{start:a,end:s}}var o=e.display,l=e.doc,a=document.createDocumentFragment(),s=Ge(e.display),c=s.left,u=Math.max(o.sizerWidth,Ve(e)-o.sizer.offsetLeft)-s.right,d=t.from(),h=t.to();if(d.line==h.line)i(d.line,d.ch,h.ch);else{var f=Zr(l,d.line),p=Zr(l,h.line),m=yr(f)==yr(p),g=i(d.line,d.ch,m?f.text.length+1:null).end,v=i(h.line,m?0:null,h.ch).start;m&&(g.top0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Re(e,t){e.doc.mode.startState&&e.doc.frontier=e.display.viewTo)){var n=+new Date+e.options.workTime,r=al(t.mode,_e(e,t.frontier)),i=[];t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var l=o.styles,a=o.text.length>e.options.maxHighlightLength,s=Er(e,o,a?al(t.mode,r):r,!0);o.styles=s.styles;var c=o.styleClasses,u=s.classes;u?o.styleClasses=u:c&&(o.styleClasses=null);for(var d=!l||l.length!=o.styles.length||c!=u&&(!c||!u||c.bgClass!=u.bgClass||c.textClass!=u.textClass),h=0;!d&&hn?(Re(e,e.options.workDelay),!0):void 0}),i.length&&At(e,function(){for(var t=0;tl;--a){if(a<=o.first)return o.first;var s=Zr(o,a-1);if(s.stateAfter&&(!n||a<=o.frontier))return a;var c=Rl(s.text,null,e.options.tabSize);(null==i||r>c)&&(i=a-1,r=c)}return i}function _e(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return!0;var o=je(e,t,n),l=o>r.first&&Zr(r,o-1).stateAfter;return l=l?al(r.mode,l):sl(r.mode),r.iter(o,t,function(n){Pr(e,n.text,l);var a=o==t-1||o%5==0||o>=i.viewFrom&&o2&&o.push((s.bottom+c.top)/2-n.top)}}o.push(n.bottom-n.top)}}function Ye(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var r=0;rn)return{map:e.measure.maps[r],cache:e.measure.caches[r],before:!0}}function Ze(e,t){t=yr(t);var n=ti(t),r=e.display.externalMeasured=new It(e.doc,t,n);r.lineN=n;var i=r.built=zr(e,r);return r.text=i.pre,Ui(e.display.lineMeasure,i.pre),r}function Qe(e,t,n,r){return tt(e,et(e,t),n,r)}function Je(e,t){if(t>=e.display.viewFrom&&t=n.lineN&&tt?(i=0,o=1,l="left"):c>t?(i=t-s,o=i+1):(a==e.length-3||t==c&&e[a+3]>t)&&(o=c-s,i=o-1,t>=c&&(l="right")),null!=i){if(r=e[a+2],s==c&&n==(r.insertLeft?"left":"right")&&(l=n),"left"==n&&0==i)for(;a&&e[a-2]==e[a-3]&&e[a-1].insertLeft;)r=e[(a-=3)+2],l="left";if("right"==n&&i==c-s)for(;au;u++){for(;a&&ji(t.line.text.charAt(o.coverStart+a));)--a;for(;o.coverStart+sbo&&0==a&&s==o.coverEnd-o.coverStart)i=l.parentNode.getBoundingClientRect();else if(xo&&e.options.lineWrapping){var d=ql(l,a,s).getClientRects();i=d.length?d["right"==r?d.length-1:0]:qo}else i=ql(l,a,s).getBoundingClientRect()||qo;if(i.left||i.right||0==a)break;s=a,a-=1,c="right"}xo&&11>bo&&(i=it(e.display.measure,i))}else{a>0&&(c=r="right");var d;i=e.options.lineWrapping&&(d=l.getClientRects()).length>1?d["right"==r?d.length-1:0]:l.getBoundingClientRect()}if(xo&&9>bo&&!a&&(!i||!i.left&&!i.right)){var h=l.parentNode.getClientRects()[0];i=h?{left:h.left,right:h.left+xt(e.display),top:h.top,bottom:h.bottom}:qo}for(var f=i.top-t.rect.top,p=i.bottom-t.rect.top,m=(f+p)/2,g=t.view.measure.heights,u=0;un.from?l(e-1):l(e,r)}r=r||Zr(e.doc,t.line),i||(i=et(e,r));var s=ii(r),c=t.ch;if(!s)return l(c);var u=co(s,c),d=a(c,u);return null!=oa&&(d.other=a(c,oa)),d}function pt(e,t){var n=0,t=me(e.doc,t);e.options.lineWrapping||(n=xt(e.display)*t.ch);var r=Zr(e.doc,t.line),i=ri(r)+qe(e.display);return{left:n,right:n,top:i,bottom:i+r.height}}function mt(e,t,n,r){var i=Fo(e,t);return i.xRel=r,n&&(i.outside=!0),i}function gt(e,t,n){var r=e.doc;if(n+=e.display.viewOffset,0>n)return mt(r.first,0,!0,-1);var i=ni(r,n),o=r.first+r.size-1;if(i>o)return mt(r.first+r.size-1,Zr(r,o).text.length,!0,1);0>t&&(t=0);for(var l=Zr(r,i);;){var a=vt(e,l,i,t,n),s=gr(l),c=s&&s.find(0,!0);if(!s||!(a.ch>c.from.ch||a.ch==c.from.ch&&a.xRel>0))return a;i=ti(l=c.to.line)}}function vt(e,t,n,r,i){function o(r){var i=ft(e,Fo(n,r),"line",t,c);return a=!0,l>i.bottom?i.left-s:lg)return mt(n,f,v,1);for(;;){if(u?f==h||f==ho(t,h,1):1>=f-h){for(var y=p>r||g-r>=r-p?h:f,x=r-(y==h?p:g);ji(t.text.charAt(y));)++y;var b=mt(n,y,y==h?m:v,-1>x?-1:x>1?1:0);return b}var w=Math.ceil(d/2),k=h+w;if(u){k=h;for(var C=0;w>C;++C)k=ho(t,k,1)}var S=o(k);S>r?(f=k,g=S,(v=a)&&(g+=1e3),d=w):(h=k,p=S,m=a,d-=w)}}function yt(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Bo){Bo=_i("pre");for(var t=0;49>t;++t)Bo.appendChild(document.createTextNode("x")),Bo.appendChild(_i("br"));Bo.appendChild(document.createTextNode("x"))}Ui(e.measure,Bo);var n=Bo.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),qi(e.measure),n||1}function xt(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=_i("span","xxxxxxxxxx"),n=_i("pre",[t]);Ui(e.measure,n);var r=t.getBoundingClientRect(),i=(r.right-r.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function bt(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Go},Uo?Uo.ops.push(e.curOp):e.curOp.ownsGroup=Uo={ops:[e.curOp],delayedCallbacks:[]}}function wt(e){var t=e.delayedCallbacks,n=0;do{for(;n=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new L(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Lt(e){e.updatedDisplay=e.mustUpdate&&M(e.cm,e.update)}function Tt(e){var t=e.cm,n=t.display;e.updatedDisplay&&H(t),e.barMeasure=p(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Qe(t,n.maxLine,n.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(n.scroller.clientWidth,n.sizer.offsetLeft+e.adjustWidthTo+$e(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Ve(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Mt(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLefto;o=r){var l=new It(e.doc,Zr(e.doc,o),o);r=o+l.size,i.push(l)}return i}function Dt(e,t,n,r){null==t&&(t=e.doc.first),null==n&&(n=e.doc.first+e.doc.size),r||(r=0);var i=e.display;if(r&&nt)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Po&&br(e.doc,t)