Support image selection from the fullscreen view.
authorSteinar H. Gunderson <sesse@debian.org>
Mon, 31 Jul 2006 23:30:30 +0000 (01:30 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Mon, 31 Jul 2006 23:30:30 +0000 (01:30 +0200)
files/pr0n-fullscreen.css
files/pr0n-fullscreen.js
perl/Sesse/pr0n/Select.pm
templates/default/fullscreen-footer

index 390ffdcb7d4ce4ad6c2027384b32b8b0dc20dc97..8df506111ca39c22d974b80fe8e7b2754590978c 100644 (file)
@@ -10,7 +10,7 @@ body {
 .container {
        text-align: center;
 }
-img {
+img, #text {
        vertical-align: middle;
 }
 
index 468f249c0c6c780b30c87eed132d5923f8ec8968..1e2e8f0eec1615d8e6fe22716fd86c95bb82ee74 100644 (file)
@@ -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()
 {
index 1086587ae77769df03fbf93864e662de94d370ba..777e02b37cd3adc236f1ef7d161afc0eb0e2c4bb 100644 (file)
@@ -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("    <p>Selected image ID `$id'.</p>\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("    <p>Selected image ID `$id'.</p>\n");
+                               }
                        }
                }
        }
index 98df35c65c20287585f9db1e5d6ee16610a2bcd1..872440fcf81f3a7ea0b1318011306a4b4bfdb87c 100644 (file)
@@ -7,7 +7,7 @@ var global_image_num = %START%;
     </script>
     <script type="text/JavaScript" src="/pr0n-fullscreen.js"></script>
   </head>
-  <body onresize="relayout();" onload="relayout();" onkeydown="key_down(event.which);" onkeyup="key_up(event.which);">
+  <body onresize="relayout();" onload="init_ajax(); relayout();" onkeydown="key_down(event.which);" onkeyup="key_up(event.which);">
     <div class="container" id="main"></div>
     <img id="previous" src="/previous.png" alt="&lt;-" onmousedown="if (can_go_previous()) set_opacity('previous', 1.0)" onmouseup="if (can_go_previous()) { set_opacity('previous', 0.7); go_previous(); }" onmouseout="if (can_go_previous()) { set_opacity('previous', 0.7); }" />
     <img id="next" src="/next.png" alt="-&gt;" onmousedown="if (can_go_next()) set_opacity('next', 1.0)" onmouseup="if (can_go_next()) { set_opacity('next', 0.7); go_next(); }" onmouseout="if (can_go_next()) { set_opacity('next', 0.7); }" />