Prevent opening thread view when clicking on ext. links.
This commit is contained in:
parent
9668e63f34
commit
558f0295a5
36
src/View.elm
36
src/View.elm
@ -8,7 +8,7 @@ import List.Extra exposing (elemIndex, getAt)
|
|||||||
import Mastodon.Helper
|
import Mastodon.Helper
|
||||||
import Mastodon.Model
|
import Mastodon.Model
|
||||||
import Model exposing (..)
|
import Model exposing (..)
|
||||||
import ViewHelper
|
import ViewHelper exposing (..)
|
||||||
import Date
|
import Date
|
||||||
import Date.Extra.Config.Config_en_au as DateEn
|
import Date.Extra.Config.Config_en_au as DateEn
|
||||||
import Date.Extra.Format as DateFormat
|
import Date.Extra.Format as DateFormat
|
||||||
@ -32,7 +32,7 @@ closeablePanelheading iconName label onClose =
|
|||||||
, div [ class "col-xs-3 text-right" ]
|
, div [ class "col-xs-3 text-right" ]
|
||||||
[ a
|
[ a
|
||||||
[ href ""
|
[ href ""
|
||||||
, ViewHelper.onClickWithPreventAndStop onClose
|
, onClickWithPreventAndStop onClose
|
||||||
]
|
]
|
||||||
[ icon "remove" ]
|
[ icon "remove" ]
|
||||||
]
|
]
|
||||||
@ -70,7 +70,7 @@ accountLink : Mastodon.Model.Account -> Html Msg
|
|||||||
accountLink account =
|
accountLink account =
|
||||||
a
|
a
|
||||||
[ href account.url
|
[ href account.url
|
||||||
, ViewHelper.onClickWithPreventAndStop (LoadAccount account.id)
|
, onClickWithPreventAndStop (LoadAccount account.id)
|
||||||
]
|
]
|
||||||
[ text <| "@" ++ account.username ]
|
[ text <| "@" ++ account.username ]
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ accountAvatarLink : Mastodon.Model.Account -> Html Msg
|
|||||||
accountAvatarLink account =
|
accountAvatarLink account =
|
||||||
a
|
a
|
||||||
[ href account.url
|
[ href account.url
|
||||||
, ViewHelper.onClickWithPreventAndStop (LoadAccount account.id)
|
, onClickWithPreventAndStop (LoadAccount account.id)
|
||||||
, title <| "@" ++ account.username
|
, title <| "@" ++ account.username
|
||||||
]
|
]
|
||||||
[ img [ class "avatar", src account.avatar ] [] ]
|
[ img [ class "avatar", src account.avatar ] [] ]
|
||||||
@ -103,7 +103,7 @@ attachmentPreview context sensitive attachments ({ url, preview_url } as attachm
|
|||||||
a
|
a
|
||||||
[ class "attachment-image"
|
[ class "attachment-image"
|
||||||
, href url
|
, href url
|
||||||
, ViewHelper.onClickWithPreventAndStop <|
|
, onClickWithPreventAndStop <|
|
||||||
ViewerEvent (OpenViewer attachments attachment)
|
ViewerEvent (OpenViewer attachments attachment)
|
||||||
, style
|
, style
|
||||||
[ ( "background"
|
[ ( "background"
|
||||||
@ -143,8 +143,8 @@ statusContentView : String -> Mastodon.Model.Status -> Html Msg
|
|||||||
statusContentView context status =
|
statusContentView context status =
|
||||||
case status.spoiler_text of
|
case status.spoiler_text of
|
||||||
"" ->
|
"" ->
|
||||||
div [ class "status-text", onClick <| OpenThread status ]
|
div [ class "status-text", onClickWithStop <| OpenThread status ]
|
||||||
[ div [] <| ViewHelper.formatContent status.content status.mentions
|
[ div [] <| formatContent status.content status.mentions
|
||||||
, attachmentListView context status
|
, attachmentListView context status
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ statusContentView context status =
|
|||||||
, input [ type_ "checkbox", id statusId, class "spoiler-toggler" ] []
|
, input [ type_ "checkbox", id statusId, class "spoiler-toggler" ] []
|
||||||
, label [ for statusId ] [ text "Reveal content" ]
|
, label [ for statusId ] [ text "Reveal content" ]
|
||||||
, div [ class "spoiled-content" ]
|
, div [ class "spoiled-content" ]
|
||||||
[ div [] <| ViewHelper.formatContent status.content status.mentions
|
[ div [] <| formatContent status.content status.mentions
|
||||||
, attachmentListView context status
|
, attachmentListView context status
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -174,7 +174,7 @@ statusView context ({ account, content, media_attachments, reblog, mentions } as
|
|||||||
-- When clicking on a status, we should not let the browser
|
-- When clicking on a status, we should not let the browser
|
||||||
-- redirect to a new page. That's why we're preventing the default
|
-- redirect to a new page. That's why we're preventing the default
|
||||||
-- behavior here
|
-- behavior here
|
||||||
, ViewHelper.onClickWithPreventAndStop (LoadAccount account.id)
|
, onClickWithPreventAndStop (LoadAccount account.id)
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
case reblog of
|
case reblog of
|
||||||
@ -212,7 +212,7 @@ accountTimelineView account statuses label iconName =
|
|||||||
[ img [ src account.avatar ] []
|
[ img [ src account.avatar ] []
|
||||||
, span [ class "account-display-name" ] [ text account.display_name ]
|
, span [ class "account-display-name" ] [ text account.display_name ]
|
||||||
, span [ class "account-username" ] [ text ("@" ++ account.username) ]
|
, span [ class "account-username" ] [ text ("@" ++ account.username) ]
|
||||||
, span [ class "account-note" ] (ViewHelper.formatContent account.note [])
|
, span [ class "account-note" ] (formatContent account.note [])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
, div [ class "row account-infos" ]
|
, div [ class "row account-infos" ]
|
||||||
@ -278,24 +278,24 @@ statusActionsView status =
|
|||||||
div [ class "btn-group actions" ]
|
div [ class "btn-group actions" ]
|
||||||
[ a
|
[ a
|
||||||
[ class baseBtnClasses
|
[ class baseBtnClasses
|
||||||
, ViewHelper.onClickWithPreventAndStop <|
|
, onClickWithPreventAndStop <|
|
||||||
DraftEvent (UpdateReplyTo targetStatus)
|
DraftEvent (UpdateReplyTo targetStatus)
|
||||||
]
|
]
|
||||||
[ icon "share-alt" ]
|
[ icon "share-alt" ]
|
||||||
, a
|
, a
|
||||||
[ class reblogClasses
|
[ class reblogClasses
|
||||||
, ViewHelper.onClickWithPreventAndStop reblogEvent
|
, onClickWithPreventAndStop reblogEvent
|
||||||
]
|
]
|
||||||
[ icon "fire", text (toString status.reblogs_count) ]
|
[ icon "fire", text (toString status.reblogs_count) ]
|
||||||
, a
|
, a
|
||||||
[ class favClasses
|
[ class favClasses
|
||||||
, ViewHelper.onClickWithPreventAndStop favEvent
|
, onClickWithPreventAndStop favEvent
|
||||||
]
|
]
|
||||||
[ icon "star", text (toString status.favourites_count) ]
|
[ icon "star", text (toString status.favourites_count) ]
|
||||||
, a
|
, a
|
||||||
[ class baseBtnClasses
|
[ class baseBtnClasses
|
||||||
, href status.url
|
, href status.url
|
||||||
, ViewHelper.onClickWithPreventAndStop <| OpenThread status
|
, onClickWithPreventAndStop <| OpenThread status
|
||||||
]
|
]
|
||||||
[ icon "time", formatDate ]
|
[ icon "time", formatDate ]
|
||||||
]
|
]
|
||||||
@ -374,7 +374,7 @@ notificationFollowView { accounts } =
|
|||||||
, onClick <| LoadAccount account.id
|
, onClick <| LoadAccount account.id
|
||||||
]
|
]
|
||||||
<|
|
<|
|
||||||
ViewHelper.formatContent account.note []
|
formatContent account.note []
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
div [ class "notification follow" ]
|
div [ class "notification follow" ]
|
||||||
@ -419,7 +419,7 @@ draftReplyToView draft =
|
|||||||
[ text "In reply to this toot ("
|
[ text "In reply to this toot ("
|
||||||
, a
|
, a
|
||||||
[ href ""
|
[ href ""
|
||||||
, ViewHelper.onClickWithPreventAndStop <| DraftEvent ClearReplyTo
|
, onClickWithPreventAndStop <| DraftEvent ClearReplyTo
|
||||||
]
|
]
|
||||||
[ icon "remove" ]
|
[ icon "remove" ]
|
||||||
, text ")"
|
, text ")"
|
||||||
@ -689,7 +689,7 @@ viewerView { attachments, attachment } =
|
|||||||
a
|
a
|
||||||
[ href ""
|
[ href ""
|
||||||
, class className
|
, class className
|
||||||
, ViewHelper.onClickWithPreventAndStop <|
|
, onClickWithPreventAndStop <|
|
||||||
ViewerEvent (OpenViewer attachments target)
|
ViewerEvent (OpenViewer attachments target)
|
||||||
]
|
]
|
||||||
[ text label ]
|
[ text label ]
|
||||||
@ -697,7 +697,7 @@ viewerView { attachments, attachment } =
|
|||||||
div
|
div
|
||||||
[ class "viewer"
|
[ class "viewer"
|
||||||
, tabindex -1
|
, tabindex -1
|
||||||
, ViewHelper.onClickWithPreventAndStop <| ViewerEvent CloseViewer
|
, onClickWithPreventAndStop <| ViewerEvent CloseViewer
|
||||||
]
|
]
|
||||||
[ span [ class "close" ] [ text "×" ]
|
[ span [ class "close" ] [ text "×" ]
|
||||||
, navLink "❮" "prev" prev
|
, navLink "❮" "prev" prev
|
||||||
|
@ -2,6 +2,8 @@ module ViewHelper
|
|||||||
exposing
|
exposing
|
||||||
( formatContent
|
( formatContent
|
||||||
, getMentionForLink
|
, getMentionForLink
|
||||||
|
, onClickWithStop
|
||||||
|
, onClickWithPrevent
|
||||||
, onClickWithPreventAndStop
|
, onClickWithPreventAndStop
|
||||||
, toVirtualDom
|
, toVirtualDom
|
||||||
)
|
)
|
||||||
@ -27,6 +29,22 @@ onClickWithPreventAndStop msg =
|
|||||||
(Decode.succeed msg)
|
(Decode.succeed msg)
|
||||||
|
|
||||||
|
|
||||||
|
onClickWithPrevent : msg -> Attribute msg
|
||||||
|
onClickWithPrevent msg =
|
||||||
|
onWithOptions
|
||||||
|
"click"
|
||||||
|
{ preventDefault = True, stopPropagation = False }
|
||||||
|
(Decode.succeed msg)
|
||||||
|
|
||||||
|
|
||||||
|
onClickWithStop : msg -> Attribute msg
|
||||||
|
onClickWithStop msg =
|
||||||
|
onWithOptions
|
||||||
|
"click"
|
||||||
|
{ preventDefault = False, stopPropagation = True }
|
||||||
|
(Decode.succeed msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Views
|
-- Views
|
||||||
|
|
||||||
@ -63,7 +81,11 @@ createLinkNode attrs children mentions =
|
|||||||
(toVirtualDom mentions children)
|
(toVirtualDom mentions children)
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Html.node "a" (List.map toAttribute attrs) (toVirtualDom mentions children)
|
Html.node "a"
|
||||||
|
((List.map toAttribute attrs)
|
||||||
|
++ [ onClickWithStop Model.NoOp, target "_blank" ]
|
||||||
|
)
|
||||||
|
(toVirtualDom mentions children)
|
||||||
|
|
||||||
|
|
||||||
getHrefLink : List ( String, String ) -> Maybe String
|
getHrefLink : List ( String, String ) -> Maybe String
|
||||||
|
Loading…
Reference in New Issue
Block a user