Skip to content

dblclick to restore size of images #1970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2012
Merged

dblclick to restore size of images #1970

merged 2 commits into from
Jun 18, 2012

Conversation

minrk
Copy link
Member

@minrk minrk commented Jun 15, 2012

alternative to #1887

adds double-click to resize, and removes the use of load(), which is unreliable and can produce zero-sized elements, in favor of a quarter second timeout.

img.load(function () {
$(this).resizable({'aspectRatio': true, 'autoHide': true})
});
setTimeout(function () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add setTimeout() because the parent div's width/height weren't available? Won't this cause flashing of the UI when the png is resized after 250ms?

I had the same problem, and chose to grab the width of the input field (which is known at the point this code is running).
https://github.com/mcelrath/ipython/blob/51514ef9c8dd7f8aeea35cb7da744ca16957e4e1/IPython/frontend/html/notebook/static/js/outputarea.js#L271

Because resize png/jpeg/svg will duplicate this code 3 times, we should think about unifying them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this will cause no flashing, because the image still draws immediately. The only delayed effect is making the image resizable, which has no visible effect until hover.

It makes no sense to use the shape of the container for raster images, which must start with no zoom. It is imperative that these images start without any sizing CSS on them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True: that's something different for svg: it requires sizing. So maybe we should not attempt to merge these.

@ellisonbg
Copy link
Member

I have tested this and it seems to work well. I like this UI for restoring the original size an the code looks good. I am wondering if there is any times where the 250ms delay wouldn't be enough. I thought a large notebook with many images might cause a problem, but I tried it and it worked fine. We could tune this later if we run into problems though.

@minrk
Copy link
Member Author

minrk commented Jun 17, 2012

I can chain timeouts, so it will check if the height/width is zero, and schedule another timeout if so.

@ellisonbg
Copy link
Member

That is probably safest if it isn't too difficult.

@minrk
Copy link
Member Author

minrk commented Jun 17, 2012

on a chained callback, and consolidated duplicate png/jpg implementations into private method.

@minrk
Copy link
Member Author

minrk commented Jun 17, 2012

I haven't managed to trigger a case where a second timeout is triggered, even with 1ms timeout, so this may be superfluous, but it should be safer nonetheless.

@ellisonbg
Copy link
Member

This looks merge ready, no?

@minrk
Copy link
Member Author

minrk commented Jun 18, 2012

Yes, I think so.

minrk added a commit that referenced this pull request Jun 18, 2012
dblclick to restore resized images
@minrk minrk merged commit 1cf36a2 into ipython:master Jun 18, 2012
@minrk minrk deleted the resize branch March 31, 2014 23:36
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
dblclick to restore resized images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants