summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-05-28 16:39:38 +0200
committerYorhel <git@yorhel.nl>2020-05-28 16:39:40 +0200
commite36bfde55478f4ae5d83ee73845a348a92386bca (patch)
tree932eea74bd2b29dbac5065c810691c731ef30e63
parent002f165ed4823b7563e7443526d907d27b5b431b (diff)
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.
-rw-r--r--data/js/misc.js19
-rw-r--r--data/style.css12
-rw-r--r--elm/Lib/DropDown.elm2
-rw-r--r--elm/ReleaseExtLinks.elm31
-rw-r--r--lib/VNDB/Handler/Producers.pm2
-rw-r--r--lib/VNDB/Handler/Releases.pm30
-rw-r--r--lib/VNWeb/Releases/Lib.pm31
7 files changed, 32 insertions, 95 deletions
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<l.length; i++) {
- var o = byName(l[i].parentNode, 'ul')[0];
- if(o) {
- l[i].links_ul = l[i].parentNode.removeChild(o);
- setClass(l[i].links_ul, 'hidden', false);
- ddInit(l[i], 'left', function(acr) {
- return acr.links_ul;
- });
- if(l[i].href.match(/#$/)) {
- l[i].onclick = function() { return false; };
- }
- }
- }
-})();
-
-
// spam protection on all forms
setTimeout(function() {
for(var i=1; i<document.forms.length; i++)
diff --git a/data/style.css b/data/style.css
index 150eb885..c841115e 100644
--- a/data/style.css
+++ b/data/style.css
@@ -67,7 +67,7 @@ div.warning h2, div.notice h2 { font-size: 13px; font-weight: bold; margin: 0; }
#ds_box tr.selected { background: $boxbg$; }
#ds_box table { width: 100%; }
-/* Elm dropdowns */
+/* Elm dropdowns (also in perl: VNWeb::Releases::Lib) */
.elm_dd > 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;