Use iframe for cross-browser pdf view (pdfjs)

Since some browsers (safari and some mobile ones) don't update their
ui when the src attribute of an embed element changes, an iframe is
used now. But only for the "cross browser" variant.

Fixes: #1210
This commit is contained in:
eikek 2022-02-28 11:20:17 +01:00
parent d70517ad0e
commit 78448991ca
2 changed files with 34 additions and 6 deletions

View File

@ -85,12 +85,12 @@ view texts flags settings model pos attach =
, style "max-height" "calc(100vh - 140px)"
, style "min-height" "500px"
]
[ embed
[ src <| Data.UiSettings.pdfUrl settings flags fileUrl
, class "absolute h-full w-full top-0 left-0 mx-0 py-0"
[ Data.UiSettings.pdfView settings
flags
fileUrl
[ class "absolute h-full w-full top-0 left-0 mx-0 py-0"
, id "ds-pdf-view-iframe"
]
[]
]
]

View File

@ -24,6 +24,7 @@ module Data.UiSettings exposing
, merge
, mergeDefaults
, pdfUrl
, pdfView
, storedUiSettingsDecoder
, storedUiSettingsEncode
, tagColor
@ -41,8 +42,8 @@ import Data.ItemTemplate exposing (ItemTemplate)
import Data.Pdf exposing (PdfMode)
import Data.UiTheme exposing (UiTheme)
import Dict exposing (Dict)
import Html exposing (Attribute)
import Html.Attributes as HA
import Html exposing (Attribute, Html, embed, iframe)
import Html.Attributes as HA exposing (src)
import Json.Decode as Decode
import Json.Decode.Pipeline as P
import Json.Encode as Encode
@ -426,6 +427,33 @@ pdfUrl settings flags originalUrl =
Data.Pdf.serverUrl originalUrl
pdfView : UiSettings -> Flags -> String -> List (Attribute msg) -> Html msg
pdfView settings flags originalUrl attrs =
let
url =
pdfUrl settings flags originalUrl
native =
embed (src url :: attrs) []
fallback =
iframe (src url :: attrs) []
in
case settings.pdfMode of
Data.Pdf.Detect ->
if flags.pdfSupported then
native
else
fallback
Data.Pdf.Native ->
native
Data.Pdf.Server ->
fallback
getUiLanguage : Flags -> UiSettings -> UiLanguage -> UiLanguage
getUiLanguage flags settings default =
case flags.account of