Skip to content

Commit

Permalink
Fixed js quirk when resizing the image preview field
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarcos committed Jun 26, 2018
1 parent b8e871e commit 336c922
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion arctic/static/arctic/dist/assets/js/app.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion arctic/static/arctic/src/assets/js/components/file_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ function get_file_preview(target, url, filename) {
}
img.onload = function(evt) {
target.html('<a href="' + this.src + '" target="_blank"><img src="' + this.src + '" /></a>');
target.prev().height(target.height());
if (target.height() < 22) {
setTimeout(function(){ target.prev().height(target.height()); }, 20);
}
else {
target.prev().height(target.height());
}
}
img.src = url;
if ($(target).next('.better-file-clear-checkbox')) {
Expand Down
23 changes: 23 additions & 0 deletions example/articles/migrations/0005_auto_20180625_1539.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.6 on 2018-06-25 13:39

import articles.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('articles', '0004_image'),
]

operations = [
migrations.AlterModelOptions(
name='image',
options={'ordering': ['order'], 'verbose_name': 'Image', 'verbose_name_plural': 'Images'},
),
migrations.AlterField(
model_name='image',
name='image',
field=models.ImageField(null=True, upload_to=articles.models.filename),
),
]
2 changes: 1 addition & 1 deletion example/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def filename(instance, filename):

class Image(models.Model):
title = models.CharField(max_length=255, null=True, blank=True)
image = models.ImageField(upload_to=filename, null=True)
image = models.ImageField(upload_to=filename, null=True, blank=True)
article = models.ForeignKey(Article, on_delete=models.CASCADE)
order = models.IntegerField(null=True, blank=True)

Expand Down

0 comments on commit 336c922

Please sign in to comment.