Page MenuHomePhabricator

Add download link to embedded files
ClosedPublic

Authored by chad on Dec 2 2016, 8:59 PM.
Tags
None
Referenced Files
F14051427: D16980.diff
Fri, Nov 15, 12:51 AM
F14037795: D16980.diff
Sun, Nov 10, 7:13 PM
F14022694: D16980.diff
Wed, Nov 6, 6:45 PM
F14015325: D16980.diff
Sun, Nov 3, 5:33 PM
F13990485: D16980.id40859.diff
Tue, Oct 22, 3:56 AM
F13986930: D16980.id41206.diff
Mon, Oct 21, 6:30 AM
F13980063: D16980.id40858.diff
Sat, Oct 19, 8:15 AM
F13962725: D16980.id.diff
Oct 15 2024, 11:55 AM
Subscribers

Details

Summary

Ref T3612. Doesn't render correctly, need help please. Adds a download icon into the renderfilelinkview to allow easier downloads.

Test Plan

Click on link, get download, click on file, get lightbox.

Diff Detail

Repository
rP Phabricator
Branch
file-embed-download (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 15089
Build 19806: Run Core Tests
Build 19805: arc lint + arc unit

Event Timeline

chad retitled this revision from to Add download link to embedded files.
chad updated this object.
chad edited the test plan for this revision. (Show Details)
chad added a reviewer: epriestley.
chad added a task: T3612: Lightbox v2.

Getting a double render here I think, not sure what I'm setting incorrectly (the form triggers it).

pasted_file (133×340 px, 5 KB)

If there is no easy way to do this, lmk, I'll just maybe re-think if Files should be lightboxable at all.

Oh, sorry, missed this. Let me take a look...

The browser inspector is misleading. The issue is that we're emitting this HTML:

<a
  href="http://local.phacility.com/file/data/@local/egwoplzjb6feujagzrj4/PHID-FILE-eb73u3bajy7emc3i22yg/psyduck.png"
  class="phabricator-remarkup-embed-layout-link "
  data-sigil="lightboxable"
  data-meta="0_26"
  data-mustcapture="1"
  rel="noreferrer">
  <span class="visual-only phui-icon-view phui-font-fa fa-file-picture-o" aria-hidden="true"></span>
  <span class="phabricator-remarkup-embed-layout-info-block">
    <span class="phabricator-remarkup-embed-layout-name">psyduck.png</span>
    <span class="phabricator-remarkup-embed-layout-info">490 KB</span>
  </span>
  <form action="#" method="POST" class="embed-download-form" data-sigil="embed-download-form">
    <input type="hidden" name="__csrf__" value="B@qw2kw2zt247d96d8816fcd9a" />
    <input type="hidden" name="__form__" value="1" />
    <a class="phui-icon-circle hover-green" href="#">
      <span class="visual-only phui-icon-view phui-font-fa fa-download" aria-hidden="true"></span>
    </a>
  </form>
</a>

More simply:

<a><form><a>...</a></form></a>

I think you can't have a form in a link, and you definitely can't have a link in a link.

I think browsers are silently reorganizing the outer <a> and <form> tags to be valid, which makes it appear that a double render has occurred.

Changing getTagName() to div instead of a fixes the apparent double render (although we'll need more work to make the element actually work).

This took me a bit, but here's how I ultimately figured this out:

  • Changed renderFileLink() to return this:
return array(
  "\n\n\n",
  $view,
  "\n\n\n",
);
  • Looked at the raw page source. The DOM inspector sometimes lies about this stuff, and reflects changes made by Javascript. You can compare the DOM inspector to the raw source to find problems caused by Javascript or by bad HTML tag soup: if the raw page source looks good but the DOM inspector looks broken, either the browser "fixed" something for you or the problem is with some kind of JS thing.
  • Copy/pasted the separated block of stuff of raw source stuff into my text editor.
  • Manually reformatted the tags to be readable, revealing the <a><form><a>.
epriestley edited edge metadata.

ok you can have this back now

This revision now requires changes to proceed.Dec 7 2016, 9:21 PM

This "improvement" to the source is particularly bizarre and I haven't seen browsers make it before but I guess we learned something new today?

chad edited edge metadata.
  • switch to divs

I think this all works as expected, though downloading the file now changes submit button to 0.5 opacity and never clears and I'm not sure how to skip that feature.

Alternatively, I believe you can add the sigil download to stop the disable-on-submit behavior.

This revision is now accepted and ready to land.Jan 3 2017, 6:48 PM
This revision was automatically updated to reflect the committed changes.