summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/commit
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
committerFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
commitaaa9509d120524573085e94af9de5cdde83e3271 (patch)
tree3824cffd4cdd132ee9cf75a00a7624f5ccc0dabd /app/assets/javascripts/commit
parent56b79181adc0bd6e9abef97ea075c14be971a01a (diff)
downloadgitlab-ce-aaa9509d120524573085e94af9de5cdde83e3271.tar.gz
ES6ify all the things!
Diffstat (limited to 'app/assets/javascripts/commit')
-rw-r--r--app/assets/javascripts/commit/file.js13
-rw-r--r--app/assets/javascripts/commit/file.js.coffee5
-rw-r--r--app/assets/javascripts/commit/image-file.js175
-rw-r--r--app/assets/javascripts/commit/image-file.js.coffee127
4 files changed, 188 insertions, 132 deletions
diff --git a/app/assets/javascripts/commit/file.js b/app/assets/javascripts/commit/file.js
new file mode 100644
index 00000000000..be24ee56aad
--- /dev/null
+++ b/app/assets/javascripts/commit/file.js
@@ -0,0 +1,13 @@
+(function() {
+ this.CommitFile = (function() {
+ function CommitFile(file) {
+ if ($('.image', file).length) {
+ new ImageFile(file);
+ }
+ }
+
+ return CommitFile;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/commit/file.js.coffee b/app/assets/javascripts/commit/file.js.coffee
deleted file mode 100644
index 83e793863b6..00000000000
--- a/app/assets/javascripts/commit/file.js.coffee
+++ /dev/null
@@ -1,5 +0,0 @@
-class @CommitFile
-
- constructor: (file) ->
- if $('.image', file).length
- new ImageFile(file)
diff --git a/app/assets/javascripts/commit/image-file.js b/app/assets/javascripts/commit/image-file.js
new file mode 100644
index 00000000000..c0d0b2d049f
--- /dev/null
+++ b/app/assets/javascripts/commit/image-file.js
@@ -0,0 +1,175 @@
+(function() {
+ this.ImageFile = (function() {
+ var prepareFrames;
+
+ ImageFile.availWidth = 900;
+
+ ImageFile.viewModes = ['two-up', 'swipe'];
+
+ function ImageFile(file) {
+ this.file = file;
+ this.requestImageInfo($('.two-up.view .frame.deleted img', this.file), (function(_this) {
+ return function(deletedWidth, deletedHeight) {
+ return _this.requestImageInfo($('.two-up.view .frame.added img', _this.file), function(width, height) {
+ if (width === deletedWidth && height === deletedHeight) {
+ return _this.initViewModes();
+ } else {
+ return _this.initView('two-up');
+ }
+ });
+ };
+ })(this));
+ }
+
+ ImageFile.prototype.initViewModes = function() {
+ var viewMode;
+ viewMode = ImageFile.viewModes[0];
+ $('.view-modes', this.file).removeClass('hide');
+ $('.view-modes-menu', this.file).on('click', 'li', (function(_this) {
+ return function(event) {
+ if (!$(event.currentTarget).hasClass('active')) {
+ return _this.activateViewMode(event.currentTarget.className);
+ }
+ };
+ })(this));
+ return this.activateViewMode(viewMode);
+ };
+
+ ImageFile.prototype.activateViewMode = function(viewMode) {
+ $('.view-modes-menu li', this.file).removeClass('active').filter("." + viewMode).addClass('active');
+ return $(".view:visible:not(." + viewMode + ")", this.file).fadeOut(200, (function(_this) {
+ return function() {
+ $(".view." + viewMode, _this.file).fadeIn(200);
+ return _this.initView(viewMode);
+ };
+ })(this));
+ };
+
+ ImageFile.prototype.initView = function(viewMode) {
+ return this.views[viewMode].call(this);
+ };
+
+ prepareFrames = function(view) {
+ var maxHeight, maxWidth;
+ maxWidth = 0;
+ maxHeight = 0;
+ $('.frame', view).each((function(_this) {
+ return function(index, frame) {
+ var height, width;
+ width = $(frame).width();
+ height = $(frame).height();
+ maxWidth = width > maxWidth ? width : maxWidth;
+ return maxHeight = height > maxHeight ? height : maxHeight;
+ };
+ })(this)).css({
+ width: maxWidth,
+ height: maxHeight
+ });
+ return [maxWidth, maxHeight];
+ };
+
+ ImageFile.prototype.views = {
+ 'two-up': function() {
+ return $('.two-up.view .wrap', this.file).each((function(_this) {
+ return function(index, wrap) {
+ $('img', wrap).each(function() {
+ var currentWidth;
+ currentWidth = $(this).width();
+ if (currentWidth > ImageFile.availWidth / 2) {
+ return $(this).width(ImageFile.availWidth / 2);
+ }
+ });
+ return _this.requestImageInfo($('img', wrap), function(width, height) {
+ $('.image-info .meta-width', wrap).text(width + "px");
+ $('.image-info .meta-height', wrap).text(height + "px");
+ return $('.image-info', wrap).removeClass('hide');
+ });
+ };
+ })(this));
+ },
+ 'swipe': function() {
+ var maxHeight, maxWidth;
+ maxWidth = 0;
+ maxHeight = 0;
+ return $('.swipe.view', this.file).each((function(_this) {
+ return function(index, view) {
+ var ref;
+ ref = prepareFrames(view), maxWidth = ref[0], maxHeight = ref[1];
+ $('.swipe-frame', view).css({
+ width: maxWidth + 16,
+ height: maxHeight + 28
+ });
+ $('.swipe-wrap', view).css({
+ width: maxWidth + 1,
+ height: maxHeight + 2
+ });
+ return $('.swipe-bar', view).css({
+ left: 0
+ }).draggable({
+ axis: 'x',
+ containment: 'parent',
+ drag: function(event) {
+ return $('.swipe-wrap', view).width((maxWidth + 1) - $(this).position().left);
+ },
+ stop: function(event) {
+ return $('.swipe-wrap', view).width((maxWidth + 1) - $(this).position().left);
+ }
+ });
+ };
+ })(this));
+ },
+ 'onion-skin': function() {
+ var dragTrackWidth, maxHeight, maxWidth;
+ maxWidth = 0;
+ maxHeight = 0;
+ dragTrackWidth = $('.drag-track', this.file).width() - $('.dragger', this.file).width();
+ return $('.onion-skin.view', this.file).each((function(_this) {
+ return function(index, view) {
+ var ref;
+ ref = prepareFrames(view), maxWidth = ref[0], maxHeight = ref[1];
+ $('.onion-skin-frame', view).css({
+ width: maxWidth + 16,
+ height: maxHeight + 28
+ });
+ $('.swipe-wrap', view).css({
+ width: maxWidth + 1,
+ height: maxHeight + 2
+ });
+ return $('.dragger', view).css({
+ left: dragTrackWidth
+ }).draggable({
+ axis: 'x',
+ containment: 'parent',
+ drag: function(event) {
+ return $('.frame.added', view).css('opacity', $(this).position().left / dragTrackWidth);
+ },
+ stop: function(event) {
+ return $('.frame.added', view).css('opacity', $(this).position().left / dragTrackWidth);
+ }
+ });
+ };
+ })(this));
+ }
+ };
+
+ ImageFile.prototype.requestImageInfo = function(img, callback) {
+ var domImg;
+ domImg = img.get(0);
+ if (domImg) {
+ if (domImg.complete) {
+ return callback.call(this, domImg.naturalWidth, domImg.naturalHeight);
+ } else {
+ return img.on('load', (function(_this) {
+ return function() {
+ return callback.call(_this, domImg.naturalWidth, domImg.naturalHeight);
+ };
+ })(this));
+ }
+ }
+ };
+
+ return ImageFile;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/commit/image-file.js.coffee b/app/assets/javascripts/commit/image-file.js.coffee
deleted file mode 100644
index 9c723f51e54..00000000000
--- a/app/assets/javascripts/commit/image-file.js.coffee
+++ /dev/null
@@ -1,127 +0,0 @@
-class @ImageFile
-
- # Width where images must fits in, for 2-up this gets divided by 2
- @availWidth = 900
- @viewModes = ['two-up', 'swipe']
-
- constructor: (@file) ->
- # Determine if old and new file has same dimensions, if not show 'two-up' view
- this.requestImageInfo $('.two-up.view .frame.deleted img', @file), (deletedWidth, deletedHeight) =>
- this.requestImageInfo $('.two-up.view .frame.added img', @file), (width, height) =>
- if width == deletedWidth && height == deletedHeight
- this.initViewModes()
- else
- this.initView('two-up')
-
- initViewModes: ->
- viewMode = ImageFile.viewModes[0]
-
- $('.view-modes', @file).removeClass 'hide'
- $('.view-modes-menu', @file).on 'click', 'li', (event) =>
- unless $(event.currentTarget).hasClass('active')
- this.activateViewMode(event.currentTarget.className)
-
- this.activateViewMode(viewMode)
-
- activateViewMode: (viewMode) ->
- $('.view-modes-menu li', @file)
- .removeClass('active')
- .filter(".#{viewMode}").addClass 'active'
- $(".view:visible:not(.#{viewMode})", @file).fadeOut 200, =>
- $(".view.#{viewMode}", @file).fadeIn(200)
- this.initView viewMode
-
- initView: (viewMode) ->
- this.views[viewMode].call(this)
-
- prepareFrames = (view) ->
- maxWidth = 0
- maxHeight = 0
- $('.frame', view).each (index, frame) =>
- width = $(frame).width()
- height = $(frame).height()
- maxWidth = if width > maxWidth then width else maxWidth
- maxHeight = if height > maxHeight then height else maxHeight
- .css
- width: maxWidth
- height: maxHeight
-
- [maxWidth, maxHeight]
-
- views:
- 'two-up': ->
- $('.two-up.view .wrap', @file).each (index, wrap) =>
- $('img', wrap).each ->
- currentWidth = $(this).width()
- if currentWidth > ImageFile.availWidth / 2
- $(this).width ImageFile.availWidth / 2
-
- this.requestImageInfo $('img', wrap), (width, height) ->
- $('.image-info .meta-width', wrap).text "#{width}px"
- $('.image-info .meta-height', wrap).text "#{height}px"
- $('.image-info', wrap).removeClass('hide')
-
- 'swipe': ->
- maxWidth = 0
- maxHeight = 0
-
- $('.swipe.view', @file).each (index, view) =>
-
- [maxWidth, maxHeight] = prepareFrames(view)
-
- $('.swipe-frame', view).css
- width: maxWidth + 16
- height: maxHeight + 28
-
- $('.swipe-wrap', view).css
- width: maxWidth + 1
- height: maxHeight + 2
-
- $('.swipe-bar', view).css
- left: 0
- .draggable
- axis: 'x'
- containment: 'parent'
- drag: (event) ->
- $('.swipe-wrap', view).width (maxWidth + 1) - $(this).position().left
- stop: (event) ->
- $('.swipe-wrap', view).width (maxWidth + 1) - $(this).position().left
-
- 'onion-skin': ->
- maxWidth = 0
- maxHeight = 0
-
- dragTrackWidth = $('.drag-track', @file).width() - $('.dragger', @file).width()
-
- $('.onion-skin.view', @file).each (index, view) =>
-
- [maxWidth, maxHeight] = prepareFrames(view)
-
- $('.onion-skin-frame', view).css
- width: maxWidth + 16
- height: maxHeight + 28
-
- $('.swipe-wrap', view).css
- width: maxWidth + 1
- height: maxHeight + 2
-
- $('.dragger', view).css
- left: dragTrackWidth
- .draggable
- axis: 'x'
- containment: 'parent'
- drag: (event) ->
- $('.frame.added', view).css('opacity', $(this).position().left / dragTrackWidth)
- stop: (event) ->
- $('.frame.added', view).css('opacity', $(this).position().left / dragTrackWidth)
-
-
-
- requestImageInfo: (img, callback) ->
- domImg = img.get(0)
- if domImg
- if domImg.complete
- callback.call(this, domImg.naturalWidth, domImg.naturalHeight)
- else
- img.on 'load', =>
- callback.call(this, domImg.naturalWidth, domImg.naturalHeight)