Commit 5adac371 authored by Marvin Karegyeya's avatar Marvin Karegyeya Committed by Natalia Tepluhina

Remove IIFEs from image_file.js

parent 2ffab3be
/* eslint-disable func-names, no-var, no-else-return, consistent-return, one-var, no-return-assign, no-unused-expressions, no-sequences */ /* eslint-disable func-names, no-var, no-else-return, consistent-return, one-var, no-return-assign */
import $ from 'jquery'; import $ from 'jquery';
...@@ -9,40 +9,29 @@ const viewModes = ['two-up', 'swipe']; ...@@ -9,40 +9,29 @@ const viewModes = ['two-up', 'swipe'];
export default class ImageFile { export default class ImageFile {
constructor(file) { constructor(file) {
this.file = file; this.file = file;
this.requestImageInfo( this.requestImageInfo($('.two-up.view .frame.deleted img', this.file), () =>
$('.two-up.view .frame.deleted img', this.file), this.requestImageInfo($('.two-up.view .frame.added img', this.file), () => {
(function(_this) { this.initViewModes();
return function() {
return _this.requestImageInfo($('.two-up.view .frame.added img', _this.file), () => {
_this.initViewModes();
// Load two-up view after images are loaded // Load two-up view after images are loaded
// so that we can display the correct width and height information // so that we can display the correct width and height information
const $images = $('.two-up.view img', _this.file); const $images = $('.two-up.view img', this.file);
$images.waitForImages(() => { $images.waitForImages(() => {
_this.initView('two-up'); this.initView('two-up');
}); });
}); }),
};
})(this),
); );
} }
initViewModes() { initViewModes() {
const viewMode = viewModes[0]; const viewMode = viewModes[0];
$('.view-modes', this.file).removeClass('hide'); $('.view-modes', this.file).removeClass('hide');
$('.view-modes-menu', this.file).on( $('.view-modes-menu', this.file).on('click', 'li', event => {
'click',
'li',
(function(_this) {
return function(event) {
if (!$(event.currentTarget).hasClass('active')) { if (!$(event.currentTarget).hasClass('active')) {
return _this.activateViewMode(event.currentTarget.className); return this.activateViewMode(event.currentTarget.className);
} }
}; });
})(this),
);
return this.activateViewMode(viewMode); return this.activateViewMode(viewMode);
} }
...@@ -51,15 +40,10 @@ export default class ImageFile { ...@@ -51,15 +40,10 @@ export default class ImageFile {
.removeClass('active') .removeClass('active')
.filter(`.${viewMode}`) .filter(`.${viewMode}`)
.addClass('active'); .addClass('active');
return $(`.view:visible:not(.${viewMode})`, this.file).fadeOut( return $(`.view:visible:not(.${viewMode})`, this.file).fadeOut(200, () => {
200, $(`.view.${viewMode}`, this.file).fadeIn(200);
(function(_this) { return this.initView(viewMode);
return function() { });
$(`.view.${viewMode}`, _this.file).fadeIn(200);
return _this.initView(viewMode);
};
})(this),
);
} }
initView(viewMode) { initView(viewMode) {
...@@ -103,22 +87,18 @@ export default class ImageFile { ...@@ -103,22 +87,18 @@ export default class ImageFile {
.on('touchmove', dragMove); .on('touchmove', dragMove);
} }
prepareFrames(view) { static prepareFrames(view) {
var maxHeight, maxWidth; var maxHeight, maxWidth;
maxWidth = 0; maxWidth = 0;
maxHeight = 0; maxHeight = 0;
$('.frame', view) $('.frame', view)
.each( .each((index, frame) => {
(function() {
return function(index, frame) {
var height, width; var height, width;
width = $(frame).width(); width = $(frame).width();
height = $(frame).height(); height = $(frame).height();
maxWidth = width > maxWidth ? width : maxWidth; maxWidth = width > maxWidth ? width : maxWidth;
return (maxHeight = height > maxHeight ? height : maxHeight); return (maxHeight = height > maxHeight ? height : maxHeight);
}; })
})(this),
)
.css({ .css({
width: maxWidth, width: maxWidth,
height: maxHeight, height: maxHeight,
...@@ -128,9 +108,7 @@ export default class ImageFile { ...@@ -128,9 +108,7 @@ export default class ImageFile {
views = { views = {
'two-up': function() { 'two-up': function() {
return $('.two-up.view .wrap', this.file).each( return $('.two-up.view .wrap', this.file).each((index, wrap) => {
(function(_this) {
return function(index, wrap) {
$('img', wrap).each(function() { $('img', wrap).each(function() {
var currentWidth; var currentWidth;
currentWidth = $(this).width(); currentWidth = $(this).width();
...@@ -138,24 +116,21 @@ export default class ImageFile { ...@@ -138,24 +116,21 @@ export default class ImageFile {
return $(this).width(availWidth / 2); return $(this).width(availWidth / 2);
} }
}); });
return _this.requestImageInfo($('img', wrap), (width, height) => { return this.requestImageInfo($('img', wrap), (width, height) => {
$('.image-info .meta-width', wrap).text(`${width}px`); $('.image-info .meta-width', wrap).text(`${width}px`);
$('.image-info .meta-height', wrap).text(`${height}px`); $('.image-info .meta-height', wrap).text(`${height}px`);
return $('.image-info', wrap).removeClass('hide'); return $('.image-info', wrap).removeClass('hide');
}); });
}; });
})(this),
);
}, },
swipe() { swipe() {
var maxHeight, maxWidth; var maxHeight, maxWidth;
maxWidth = 0; maxWidth = 0;
maxHeight = 0; maxHeight = 0;
return $('.swipe.view', this.file).each( return $('.swipe.view', this.file).each((index, view) => {
(function(_this) { var $swipeWrap, $swipeBar, $swipeFrame, wrapPadding;
return function(index, view) { const ref = ImageFile.prepareFrames(view);
var $swipeWrap, $swipeBar, $swipeFrame, wrapPadding, ref; [maxWidth, maxHeight] = ref;
(ref = _this.prepareFrames(view)), ([maxWidth, maxHeight] = ref);
$swipeFrame = $('.swipe-frame', view); $swipeFrame = $('.swipe-frame', view);
$swipeWrap = $('.swipe-wrap', view); $swipeWrap = $('.swipe-wrap', view);
$swipeBar = $('.swipe-bar', view); $swipeBar = $('.swipe-bar', view);
...@@ -175,26 +150,24 @@ export default class ImageFile { ...@@ -175,26 +150,24 @@ export default class ImageFile {
wrapPadding = parseInt($swipeWrap.css('right').replace('px', ''), 10); wrapPadding = parseInt($swipeWrap.css('right').replace('px', ''), 10);
_this.initDraggable($swipeBar, wrapPadding, (e, left) => { this.initDraggable($swipeBar, wrapPadding, (e, left) => {
if (left > 0 && left < $swipeFrame.width() - wrapPadding * 2) { if (left > 0 && left < $swipeFrame.width() - wrapPadding * 2) {
$swipeWrap.width(maxWidth + 1 - left); $swipeWrap.width(maxWidth + 1 - left);
$swipeBar.css('left', left); $swipeBar.css('left', left);
} }
}); });
}; });
})(this),
);
}, },
'onion-skin': function() { 'onion-skin': function() {
var dragTrackWidth, maxHeight, maxWidth; var dragTrackWidth, maxHeight, maxWidth;
maxWidth = 0; maxWidth = 0;
maxHeight = 0; maxHeight = 0;
dragTrackWidth = $('.drag-track', this.file).width() - $('.dragger', this.file).width(); dragTrackWidth = $('.drag-track', this.file).width() - $('.dragger', this.file).width();
return $('.onion-skin.view', this.file).each( return $('.onion-skin.view', this.file).each((index, view) => {
(function(_this) { var $frame, $track, $dragger, $frameAdded, framePadding;
return function(index, view) {
var $frame, $track, $dragger, $frameAdded, framePadding, ref; const ref = ImageFile.prepareFrames(view);
(ref = _this.prepareFrames(view)), ([maxWidth, maxHeight] = ref); [maxWidth, maxHeight] = ref;
$frame = $('.onion-skin-frame', view); $frame = $('.onion-skin-frame', view);
$frameAdded = $('.frame.added', view); $frameAdded = $('.frame.added', view);
$track = $('.drag-track', view); $track = $('.drag-track', view);
...@@ -215,7 +188,7 @@ export default class ImageFile { ...@@ -215,7 +188,7 @@ export default class ImageFile {
$frameAdded.css('opacity', 1); $frameAdded.css('opacity', 1);
framePadding = parseInt($frameAdded.css('right').replace('px', ''), 10); framePadding = parseInt($frameAdded.css('right').replace('px', ''), 10);
_this.initDraggable($dragger, framePadding, (e, left) => { this.initDraggable($dragger, framePadding, (e, left) => {
var opacity = left / dragTrackWidth; var opacity = left / dragTrackWidth;
if (opacity >= 0 && opacity <= 1) { if (opacity >= 0 && opacity <= 1) {
...@@ -223,9 +196,7 @@ export default class ImageFile { ...@@ -223,9 +196,7 @@ export default class ImageFile {
$frameAdded.css('opacity', opacity); $frameAdded.css('opacity', opacity);
} }
}); });
}; });
})(this),
);
}, },
}; };
...@@ -235,14 +206,7 @@ export default class ImageFile { ...@@ -235,14 +206,7 @@ export default class ImageFile {
if (domImg.complete) { if (domImg.complete) {
return callback.call(this, domImg.naturalWidth, domImg.naturalHeight); return callback.call(this, domImg.naturalWidth, domImg.naturalHeight);
} else { } else {
return img.on( return img.on('load', () => callback.call(this, domImg.naturalWidth, domImg.naturalHeight));
'load',
(function(_this) {
return function() {
return callback.call(_this, domImg.naturalWidth, domImg.naturalHeight);
};
})(this),
);
} }
} }
} }
......
---
title: Removed IIFEs from image_file.js
merge_request: 19548
author: nuwe1
type: other
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment