From bc3f33f92a16d3afdb8a472f60940e7c46a31564 Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Fri, 22 Jul 2016 17:01:57 +0300 Subject: JSify all the things! --- app/assets/javascripts/new_commit_form.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/assets/javascripts/new_commit_form.js (limited to 'app/assets/javascripts/new_commit_form.js') diff --git a/app/assets/javascripts/new_commit_form.js b/app/assets/javascripts/new_commit_form.js new file mode 100644 index 00000000000..0c6463f051c --- /dev/null +++ b/app/assets/javascripts/new_commit_form.js @@ -0,0 +1,31 @@ +var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + +this.NewCommitForm = (function() { + function NewCommitForm(form) { + this.renderDestination = bind(this.renderDestination, this); + this.newBranch = form.find('.js-target-branch'); + this.originalBranch = form.find('.js-original-branch'); + this.createMergeRequest = form.find('.js-create-merge-request'); + this.createMergeRequestContainer = form.find('.js-create-merge-request-container'); + this.renderDestination(); + this.newBranch.keyup(this.renderDestination); + } + + NewCommitForm.prototype.renderDestination = function() { + var different; + different = this.newBranch.val() !== this.originalBranch.val(); + if (different) { + this.createMergeRequestContainer.show(); + if (!this.wasDifferent) { + this.createMergeRequest.prop('checked', true); + } + } else { + this.createMergeRequestContainer.hide(); + this.createMergeRequest.prop('checked', false); + } + return this.wasDifferent = different; + }; + + return NewCommitForm; + +})(); -- cgit v1.2.1