From e36bfde55478f4ae5d83ee73845a348a92386bca Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 28 May 2020 16:39:38 +0200 Subject: Drop ReleaseExtLinks.elm in favor of pure CSS solution It's the only Elm module used on VN pages for not-logged-in visitors, so doing this in CSS makes it possible to not load an Elm bundle on those pages (when I get to splitting up the JS files). This solution also simplifies code reuse with the producer pages, but a v2rw migration of that page would have taken care of that as well. --- data/js/misc.js | 19 ------------------- data/style.css | 12 ++++++------ elm/Lib/DropDown.elm | 2 +- elm/ReleaseExtLinks.elm | 31 ------------------------------- lib/VNDB/Handler/Producers.pm | 2 +- lib/VNDB/Handler/Releases.pm | 30 ------------------------------ lib/VNWeb/Releases/Lib.pm | 31 ++++++++++++++++++++++++------- 7 files changed, 32 insertions(+), 95 deletions(-) delete mode 100644 elm/ReleaseExtLinks.elm diff --git a/data/js/misc.js b/data/js/misc.js index 35d04849..9c151eae 100644 --- a/data/js/misc.js +++ b/data/js/misc.js @@ -37,25 +37,6 @@ })(); -// external links dropdown for releases (/p+) -(function(){ - var l = byClass('rllinks'); - for(var i=0; i a { color: $maintext$; display: block; border: none; padding-right: 15px; position: relative } .elm_dd > a > span:last-child { position: absolute; right: 5px; top: 0; width: 16px; text-align: right; display: block } .elm_dd > a > span:last-child i { visibility: hidden; font-style: normal } @@ -88,10 +88,13 @@ div.warning h2, div.notice h2 { font-size: 13px; font-weight: bold; margin: 0; } .elm_dd_input .elm_dd > a { background-color: $secbg$; color: $maintext$; border: 1px solid $secborder$; font: 14px "Tahoma", "Arial", sans-serif; padding: 1px 15px 1px 2px; margin: -1px } .elm_dd_noarrow .elm_dd > a { padding-right: 0 } .elm_dd_noarrow .elm_dd > a > span:last-child { display: none } +.elm_dd_hover .elm_dd > div { display: none } +.elm_dd_hover .elm_dd:hover > div { display: block } .elm_dd_left .elm_dd > div { float: left } .elm_dd_left .elm_dd > div > ul { right: 0; top: -20px } -.elm_dd_relextlink .elm_dd > a { padding-left: 4px } - +.elm_dd_relextlink .elm_dd > a { padding-left: 4px; color: $link$ } +.elm_dd_relextlink ul a { text-align: right } +.elm_dd_relextlink ul span { color: $maintext$; padding-right: 10px } /* general text formatting */ @@ -479,9 +482,6 @@ div#vntags { margin: 0 30px 0 30px; border-top: 1px solid $bo .releases td.tc5 { width: 70px; text-align: right } .releases td.tc6 { text-align: right; width: 25px; padding: 0; white-space: nowrap } -.rllinks_dd a { text-align: right } -.rllinks_dd span { color: $maintext$; padding-right: 10px } - #screenshots p.rel { background: $boxbg$; margin: 0; diff --git a/elm/Lib/DropDown.elm b/elm/Lib/DropDown.elm index 95063e3b..286a61cb 100644 --- a/elm/Lib/DropDown.elm +++ b/elm/Lib/DropDown.elm @@ -12,7 +12,7 @@ import Lib.Html exposing (..) type alias Config msg = { id : String , opened : Bool - , hover : Bool -- if true, the dropdown opens on mouse-over rather than click + , hover : Bool -- if true, the dropdown opens on mouse-over rather than click (not currently used) , toggle : Bool -> msg } diff --git a/elm/ReleaseExtLinks.elm b/elm/ReleaseExtLinks.elm deleted file mode 100644 index 754b9d69..00000000 --- a/elm/ReleaseExtLinks.elm +++ /dev/null @@ -1,31 +0,0 @@ --- Helper for VNWeb::Releases::Lib::release_extlinks_() -module ReleaseExtLinks exposing (main) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Browser -import Lib.Api as Api -import Lib.DropDown as DD - -type alias Links = List (String, String, Maybe String) -type alias Model = { lnk : Links, dd : DD.Config Bool } - -main : Program (String,Links) Model Bool -main = Browser.element - { init = \(id,l) -> - let dd = DD.init ("relextlink_"++id) identity - in ({ lnk = l, dd = { dd | hover = True } }, Cmd.none) - , view = view - , update = \b m -> ({ m | dd = DD.toggle m.dd b }, Cmd.none) - , subscriptions = \model -> DD.sub model.dd - } - -view : Model -> Html Bool -view model = - div [ class "elm_dd_noarrow", class "elm_dd_left", class "elm_dd_relextlink" ] - [ DD.view model.dd Api.Normal - (span [ class "fake_link" ] [ text <| String.fromInt (List.length model.lnk), abbr [ class "icons external", title "External link" ] [] ]) - (\_ -> [ ul [ class "rllinks_dd" ] <| List.map (\(lbl,url,price) -> - li [] [ a [ href url ] [ Maybe.withDefault (text "") (Maybe.map (\p -> span [] [ text p ]) price), text lbl ] ] - ) model.lnk ]) - ] diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index 9be2a75c..4457c9b6 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -170,7 +170,7 @@ sub _releases { td class => 'tc5', join ', ', ($rel->{developer} ? 'developer' : ()), ($rel->{publisher} ? 'publisher' : ()); td class => 'tc6'; - $self->releaseExtLinks($rel); + VNWeb::Releases::Lib::release_extlinks_($rel); end; end 'tr'; } diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm index 0e7c8933..72f32106 100644 --- a/lib/VNDB/Handler/Releases.pm +++ b/lib/VNDB/Handler/Releases.pm @@ -6,9 +6,6 @@ use warnings; use TUWF ':html', ':xml', 'uri_escape'; use VNDB::Func; use VNDB::Types; -use Exporter 'import'; - -our @EXPORT = ('releaseExtLinks'); TUWF::register( @@ -213,32 +210,5 @@ sub enginexml { end; } - -# Generate the html for an 'external links' dropdown, assumes enrich_extlinks() has already been called on this object. -sub releaseExtLinks { - my($self, $r) = @_; - my $has_dd = $r->{extlinks}->@* > ($r->{website} ? 1 : 0); - if($r->{extlinks}->@*) { - a href => $r->{website}||'#', class => 'rllinks'; - txt scalar $r->{extlinks}->@* if $has_dd; - cssicon 'external', 'External link'; - end; - if($has_dd) { - ul class => 'hidden rllinks_dd'; - for ($r->{extlinks}->@*) { - li; - a href => $_->[1]; - span $_->[2] if $_->[2]; - txt $_->[0]; - end; - end; - }; - end; - } - } else { - txt ' '; - } -} - 1; diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm index a5853504..29042c56 100644 --- a/lib/VNWeb/Releases/Lib.pm +++ b/lib/VNWeb/Releases/Lib.pm @@ -10,15 +10,32 @@ our @EXPORT = qw/release_extlinks_/; sub release_extlinks_ { my($r, $id) = @_; return if !$r->{extlinks}->@*; - my $has_dd = $r->{extlinks}->@* > ($r->{website} ? 1 : 0); - my sub icon_ { - a_ href => $r->{website}||'#', sub { - txt_ scalar $r->{extlinks}->@* if $has_dd; - abbr_ class => 'icons external', title => 'External link', ''; + + if($r->{extlinks}->@* == 1 && $r->{website}) { + a_ href => $r->{website}, sub { + abbr_ class => 'icons external', title => 'Official website', ''; + }; + return + } + + div_ class => 'elm_dd_noarrow elm_dd_hover elm_dd_left elm_dd_relextlink', sub { + div_ class => 'elm_dd', sub { + a_ href => $r->{website}||'#', sub { + txt_ scalar $r->{extlinks}->@*; + abbr_ class => 'icons external', title => 'External link', ''; + }; + div_ sub { + ul_ sub { + li_ sub { + a_ href => $_->[1], sub { + span_ $_->[2] if length $_->[2]; + txt_ $_->[0]; + } + } for $r->{extlinks}->@*; + } + } } } - elm_ ReleaseExtLinks => undef, [ ''.($id||$r->{id}), $r->{extlinks} ], \&icon_ if $has_dd; - icon_ if !$has_dd; } 1; -- cgit v1.2.3