summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob_edit
diff options
context:
space:
mode:
authorConnor Shea <connor.james.shea@gmail.com>2016-06-24 12:26:11 -0600
committerSean McGivern <sean@gitlab.com>2016-08-18 21:48:10 +0100
commit0baaf490e289adb36ef7145a57f75cdab05eb01c (patch)
tree9e322e443cc729a3c5d7f31877216d8cb74fc605 /app/assets/javascripts/blob_edit
parentd97c83096a70ed102f993d4c484aff9c786ca831 (diff)
downloadgitlab-ce-0baaf490e289adb36ef7145a57f75cdab05eb01c.tar.gz
Only load Ace on Snippets and file edit pages.
Diffstat (limited to 'app/assets/javascripts/blob_edit')
-rw-r--r--app/assets/javascripts/blob_edit/blob_edit_bundle.js12
-rw-r--r--app/assets/javascripts/blob_edit/edit_blob.js66
2 files changed, 78 insertions, 0 deletions
diff --git a/app/assets/javascripts/blob_edit/blob_edit_bundle.js b/app/assets/javascripts/blob_edit/blob_edit_bundle.js
new file mode 100644
index 00000000000..99034a7678f
--- /dev/null
+++ b/app/assets/javascripts/blob_edit/blob_edit_bundle.js
@@ -0,0 +1,12 @@
+/*= require_tree . */
+
+(function() {
+ $(function() {
+ url = $(".js-edit-blob-form").data("relative-url-root");
+ url += $(".js-edit-blob-form").data("assets-prefix");
+
+ blob = new EditBlob(url, $('.js-edit-blob-form').data('blob-language'));
+ new NewCommitForm($('.js-edit-blob-form'));
+ });
+
+}).call(this);
diff --git a/app/assets/javascripts/blob_edit/edit_blob.js b/app/assets/javascripts/blob_edit/edit_blob.js
new file mode 100644
index 00000000000..649c79daee8
--- /dev/null
+++ b/app/assets/javascripts/blob_edit/edit_blob.js
@@ -0,0 +1,66 @@
+(function() {
+ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ 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());
+ };
+ })(this));
+ this.initModePanesAndLinks();
+ new BlobLicenseSelectors({
+ editor: this.editor
+ });
+ new BlobGitignoreSelectors({
+ editor: this.editor
+ });
+ new BlobCiYamlSelectors({
+ editor: this.editor
+ });
+ }
+
+ 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") {
+ return $.post(currentLink.data("preview-url"), {
+ content: this.editor.getValue()
+ }, function(response) {
+ currentPane.empty().append(response);
+ return currentPane.syntaxHighlight();
+ });
+ } else {
+ return this.editor.focus();
+ }
+ };
+
+ return EditBlob;
+
+ })();
+
+}).call(this);