From: Steinar H. Gunderson Date: Mon, 31 Jul 2006 23:30:30 +0000 (+0200) Subject: Support image selection from the fullscreen view. X-Git-Url: https://git.sesse.net/?p=pr0n;a=commitdiff_plain;h=0737361d60ab3c2be28045ac522ce19722d2ffaf Support image selection from the fullscreen view. --- diff --git a/files/pr0n-fullscreen.css b/files/pr0n-fullscreen.css index 390ffdc..8df5061 100644 --- a/files/pr0n-fullscreen.css +++ b/files/pr0n-fullscreen.css @@ -10,7 +10,7 @@ body { .container { text-align: center; } -img { +img, #text { vertical-align: middle; } diff --git a/files/pr0n-fullscreen.js b/files/pr0n-fullscreen.js index 468f249..1e2e8f0 100644 --- a/files/pr0n-fullscreen.js +++ b/files/pr0n-fullscreen.js @@ -1,3 +1,30 @@ +var req; + +function init_ajax() +{ + req = false; + + if (window.XMLHttpRequest) { + // Mozilla/Safari + try { + req = new XMLHttpRequest(); + } catch(e) { + req = false; + } + } else if (window.ActiveXObject) { + // IE/Windows + try { + req = new ActiveXObject("Msxml2.XMLHTTP"); + } catch(e) { + try { + req = new ActiveXObject("Microsoft.XMLHTTP"); + } catch(e) { + req = false; + } + } + } +} + function find_width() { if (typeof(window.innerWidth) == 'number') { @@ -207,6 +234,38 @@ function key_up(which) { } else if (which == 27) { // escape set_opacity("close", 0.7); do_close(); + } else if (which == 32) { // space + select_image(global_image_list[global_image_num]); + } +} + +function select_image(filename) +{ + if (!req) + return; + + draw_text("Selecting " + filename + "..."); + + req.open("POST", "http://" + global_vhost + "/select", false); + req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + req.send("mode=single&event=" + global_evt + "&filename=" + filename); + + setTimeout("fade_text(0.99)", 30); +} + +function fade_text(opacity) +{ + set_opacity("text", opacity); + if (opacity > 0.0) { + opacity -= 0.03; + if (opacity < 0.0) + opacity = 0.0; + setTimeout("fade_text(" + opacity + ")", 30); + } else { + var text = document.getElementById("text"); + if (text != null) { + text.parentNode.removeChild(text); + } } } @@ -215,6 +274,29 @@ function do_close() window.location = global_return_url; } +function draw_text(msg) +{ + // remove any text we might have left + var text = document.getElementById("text"); + if (text != null) { + text.parentNode.removeChild(text); + } + + text = document.createElement("p"); + text.id = "text"; + text.style.position = "absolute"; + text.style.color = "white"; + text.style.lineHeight = "24px"; + text.style.font = "24px verdana, arial, sans-serif"; + text.innerHTML = msg; + + var main = document.getElementById("main"); + main.appendChild(text); + + text.style.left = (main.clientWidth - text.clientWidth) / 2 + "px"; + text.style.top = (main.clientHeight - text.clientHeight) / 2 + "px"; +} + // enable the horrible horrible IE PNG hack function ie_png_hack() { diff --git a/perl/Sesse/pr0n/Select.pm b/perl/Sesse/pr0n/Select.pm index 1086587..777e02b 100644 --- a/perl/Sesse/pr0n/Select.pm +++ b/perl/Sesse/pr0n/Select.pm @@ -23,16 +23,23 @@ sub handler { local $dbh->{AutoCommit} = 0; local $dbh->{RaiseError} = 1; - $dbh->do('UPDATE images SET selected=\'f\' WHERE event=?', undef, $event); - - my @params = $apr->param(); - my $key; - for $key (@params) { - if ($key =~ /^sel-(\d+)/ && $apr->param($key) eq 'on') { - my $id = $1; - my $q = $dbh->do('UPDATE images SET selected=\'t\' WHERE id=?', undef, $id) - or dberror($r, "Selection of $id failed: $!"); - $r->print("

Selected image ID `$id'.

\n"); + if (defined($apr->param('mode')) && $apr->param('mode') eq 'single') { + # single mode; enable one (FIXME: need to support disable too) + my $filename = $apr->param('filename'); + $dbh->do('UPDATE images SET selected=\'t\' WHERE event=? AND filename=?', undef, $event, $filename); + } else { + # traditional multi-mode + $dbh->do('UPDATE images SET selected=\'f\' WHERE event=?', undef, $event); + + my @params = $apr->param(); + my $key; + for $key (@params) { + if ($key =~ /^sel-(\d+)/ && $apr->param($key) eq 'on') { + my $id = $1; + my $q = $dbh->do('UPDATE images SET selected=\'t\' WHERE id=?', undef, $id) + or dberror($r, "Selection of $id failed: $!"); + $r->print("

Selected image ID `$id'.

\n"); + } } } } diff --git a/templates/default/fullscreen-footer b/templates/default/fullscreen-footer index 98df35c..872440f 100644 --- a/templates/default/fullscreen-footer +++ b/templates/default/fullscreen-footer @@ -7,7 +7,7 @@ var global_image_num = %START%; - +
<- ->