2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, camelcase, no-param-reassign, quotes, prefer-template, no-new, comma-dangle, one-var, one-var-declaration-per-line, prefer-arrow-callback, no-else-return, no-unused-vars, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global ace */
|
|
|
|
/* global BlobGitignoreSelectors */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
this.EditBlob = (function() {
|
|
|
|
function EditBlob(assets_path, ace_mode) {
|
|
|
|
if (ace_mode == null) {
|
|
|
|
ace_mode = null;
|
|
|
|
}
|
|
|
|
this.editModeLinkClickHandler = bind(this.editModeLinkClickHandler, this);
|
|
|
|
ace.config.set("modePath", assets_path + "/ace");
|
|
|
|
ace.config.loadModule("ace/ext/searchbox");
|
|
|
|
this.editor = ace.edit("editor");
|
|
|
|
this.editor.focus();
|
|
|
|
if (ace_mode) {
|
|
|
|
this.editor.getSession().setMode("ace/mode/" + ace_mode);
|
|
|
|
}
|
|
|
|
$('form').submit((function(_this) {
|
|
|
|
return function() {
|
|
|
|
return $("#file-content").val(_this.editor.getValue());
|
|
|
|
};
|
2016-07-26 23:32:10 -04:00
|
|
|
// Before a form submission, move the content from the Ace editor into the
|
|
|
|
// submitted textarea
|
2016-07-24 16:45:11 -04:00
|
|
|
})(this));
|
|
|
|
this.initModePanesAndLinks();
|
2016-09-02 14:42:42 -04:00
|
|
|
this.initSoftWrap();
|
2016-09-27 06:57:49 -04:00
|
|
|
new gl.BlobLicenseSelectors({
|
2016-07-24 16:45:11 -04:00
|
|
|
editor: this.editor
|
|
|
|
});
|
2016-09-28 10:58:36 -04:00
|
|
|
new BlobGitignoreSelectors({
|
2016-07-24 16:45:11 -04:00
|
|
|
editor: this.editor
|
|
|
|
});
|
2016-09-08 08:30:32 -04:00
|
|
|
new gl.BlobCiYamlSelectors({
|
2016-07-24 16:45:11 -04:00
|
|
|
editor: this.editor
|
|
|
|
});
|
2016-11-08 07:42:58 -05:00
|
|
|
new gl.BlobDockerfileSelectors({
|
|
|
|
editor: this.editor
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditBlob.prototype.initModePanesAndLinks = function() {
|
|
|
|
this.$editModePanes = $(".js-edit-mode-pane");
|
|
|
|
this.$editModeLinks = $(".js-edit-mode a");
|
|
|
|
return this.$editModeLinks.click(this.editModeLinkClickHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
EditBlob.prototype.editModeLinkClickHandler = function(event) {
|
|
|
|
var currentLink, currentPane, paneId;
|
|
|
|
event.preventDefault();
|
|
|
|
currentLink = $(event.target);
|
|
|
|
paneId = currentLink.attr("href");
|
|
|
|
currentPane = this.$editModePanes.filter(paneId);
|
|
|
|
this.$editModeLinks.parent().removeClass("active hover");
|
|
|
|
currentLink.parent().addClass("active hover");
|
|
|
|
this.$editModePanes.hide();
|
|
|
|
currentPane.fadeIn(200);
|
|
|
|
if (paneId === "#preview") {
|
2016-09-02 14:42:42 -04:00
|
|
|
this.$toggleButton.hide();
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.post(currentLink.data("preview-url"), {
|
|
|
|
content: this.editor.getValue()
|
|
|
|
}, function(response) {
|
|
|
|
currentPane.empty().append(response);
|
2016-12-08 19:15:08 -05:00
|
|
|
return currentPane.renderGFM();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
} else {
|
2016-09-02 14:42:42 -04:00
|
|
|
this.$toggleButton.show();
|
2016-07-24 16:45:11 -04:00
|
|
|
return this.editor.focus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-02 14:42:42 -04:00
|
|
|
EditBlob.prototype.initSoftWrap = function() {
|
2016-09-27 17:08:05 -04:00
|
|
|
this.isSoftWrapped = false;
|
2016-09-02 14:42:42 -04:00
|
|
|
this.$toggleButton = $('.soft-wrap-toggle');
|
2016-09-27 17:08:05 -04:00
|
|
|
this.$toggleButton.on('click', this.toggleSoftWrap.bind(this));
|
2016-09-02 14:42:42 -04:00
|
|
|
};
|
|
|
|
|
2016-09-27 17:08:05 -04:00
|
|
|
EditBlob.prototype.toggleSoftWrap = function(e) {
|
|
|
|
this.isSoftWrapped = !this.isSoftWrapped;
|
|
|
|
this.$toggleButton.toggleClass('soft-wrap-active', this.isSoftWrapped);
|
2016-09-02 14:42:42 -04:00
|
|
|
this.editor.getSession().setUseWrapMode(this.isSoftWrapped);
|
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return EditBlob;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|