summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authoryorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b>2008-08-14 21:11:52 +0000
committeryorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b>2008-08-14 21:11:52 +0000
commit2cf1c1848571f11e753dec784c7323e51b00801d (patch)
treea9502326f5dfc002e962ecaed115995db75d13fd /static
parent889e9b9c481170c94f0b5e773e7c39d27b921a43 (diff)
Added screenshots table to store the dimensions of all images, moved to AJAX for determining when a thumbnail has been generated after uploading a screenshot, and got rid of the javascript image preloader
git-svn-id: svn://vndb.org/vndb@84 1fe2e327-d9db-4752-bcf7-ef0cb4a1748b
Diffstat (limited to 'static')
-rw-r--r--static/files/def.js47
-rw-r--r--static/files/dyna.js49
-rw-r--r--static/files/style.css1
3 files changed, 48 insertions, 49 deletions
diff --git a/static/files/def.js b/static/files/def.js
index 7e7e46d9..56b8d237 100644
--- a/static/files/def.js
+++ b/static/files/def.js
@@ -240,10 +240,11 @@ function scrNsfwHid() {
+(scrNsfwEnabled ? '<a href="javascript:scrNsfwHid()">Show</a> / hide' : 'Show / <a href="javascript:scrNsfwHid()">hide</a>')
+' nsfw.';
}
-var scrInt;
function scrView() {
var u=this.href;
+ var r=this.rel;
var ol=x('screenshots').getElementsByTagName('a');
+ d = x('scrView');
var l=[];
// remove NSFW
@@ -256,51 +257,41 @@ function scrView() {
if(l[i].href == u) {
x('scrnext').style.visibility = l[i+1] ? 'visible' : 'hidden';
x('scrnext').href = l[i+1] ? l[i+1].href : '#';
+ x('scrnext').rel = l[i+1] ? l[i+1].rel : '';
x('scrprev').style.visibility = l[i-1] ? 'visible' : 'hidden';
x('scrprev').href = l[i-1] ? l[i-1].href : '#';
+ x('scrprev').rel = l[i-1] ? l[i-1].rel : '';
}
- // show image
- x('preload').src = u;
- x('scrimg').innerHTML = 'Loading...';
- x('scrView').style.display = 'block';
- scrPosition(1);
- return false;
-}
-function scrPosition(act) {
- d = x('scrView');
- m = x('preload');
- // why don't all browsers use the same DOM...
+ // calculate dimensions
+ var w = Math.floor(r.split('x')[0]);
+ var h = Math.floor(r.split('x')[1]);
var ww = typeof(window.innerWidth) == 'number' ? window.innerWidth : document.documentElement.clientWidth;
var wh = typeof(window.innerHeight) == 'number' ? window.innerHeight : document.documentElement.clientHeight;
var st = typeof(window.pageYOffset) == 'number' ? window.pageYOffset : document.body && document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
- var h=20;var w=200;
- if(act != 1) {
- w = m.offsetWidth;
- h = m.offsetHeight;
- if(w+100 > ww || h+100 > wh) {
- if(w/h > ww/wh) { // width++
- h *= (ww-100)/w;
- w = ww-100;
- } else { // height++
- w *= (wh-100)/h;
- h = wh-100;
- }
+ if(w+100 > ww || h+100 > wh) {
+ if(w/h > ww/wh) { // width++
+ h *= (ww-100)/w;
+ w = ww-100;
+ } else { // height++
+ w *= (wh-100)/h;
+ h = wh-100;
}
}
var dw = w;
var dh = h+20;
dw = dw < 200 ? 200 : dw;
+
+ // update document
+ d.style.display = 'block';
+ x('scrimg').innerHTML = '<img src="'+u+'" onclick="scrClose()" style="width: '+w+'px; height: '+h+'px" />';
d.style.width = dw+'px';
d.style.height = dh+'px';
d.style.left = ((ww - dw) / 2 - 10)+'px';
d.style.top = ((wh - dh) / 2 + st)+'px';
- if(act != 1)
- x('scrimg').innerHTML = '<img src="'+x('preload').src+'" onclick="scrClose()" style="width: '+w+'px; height: '+h+'px" />';
+ return false;
}
function scrClose() {
- clearInterval(scrInt);
- scrInt = null;
x('scrView').style.display = 'none';
x('scrView').style.top = '-5000px';
x('scrimg').innerHTML = '';
diff --git a/static/files/dyna.js b/static/files/dyna.js
index 639acfa9..e9d1e917 100644
--- a/static/files/dyna.js
+++ b/static/files/dyna.js
@@ -599,7 +599,7 @@ function scrLoad() {
var l=x('screenshots').value.split(' ');
for(var i=0;i<l.length;i++)
if(l[i].length > 2)
- scrL[i] = { load: 0, id: l[i].split(',')[0], nsfw: l[i].split(',')[1]>0?1:0 };
+ scrL[i] = { load: 2, id: l[i].split(',')[0], nsfw: l[i].split(',')[1]>0?1:0 };
// <tbody> because IE can't operate on <table>
x('scrfrm').innerHTML = '<table><tbody id="scrTbl"></tbody></table>';
@@ -608,6 +608,8 @@ function scrLoad() {
scrGenerateTR(i);
setTimeout(scrSetSubmit, 1000);
+ setInterval(scrCheckStatus, 1000);
+ scrCheckStatus();
}
// give an error when submitting the form while still uploading an image
@@ -657,7 +659,8 @@ function scrGenerateTR(i) {
r += 'Screenshot #'+scrL[i].id+'</b>'
+'<input type="checkbox" name="scrNSFW'+i+'" id="scrNSFW'+i+'"'+(scrL[i].nsfw?' checked="checked"':'')+' style="float: left" onclick="scrSer()" /> '
+'<label for="scrNSFW'+i+'" class="checkbox">&nbsp;This screenshot is NSFW.</label>'
- +'<input type="button" value="remove" onclick="scrDel('+i+')" style="float: right; width: auto; height: auto" />';
+ +'<input type="button" value="remove" onclick="scrDel('+i+')" style="float: right; width: auto; height: auto" />'
+ +'<br /><br />Full size: '+scrL[i].width+'x'+scrL[i].height+'px';
if(scrL[i].obj) {
x('scrTr'+i).getElementsByTagName('td')[1].innerHTML = r;
@@ -729,26 +732,32 @@ function scrUploadComplete(i) {
}
}
-function scrImageFail(i) {
- if(scrL[i].timer)
- clearTimeout(scrL[i].timer);
- if(!scrL[i].load)
+function scrCheckStatus() {
+ var ids='';
+ for(var i=0;i<scrL.length;i++)
+ if(scrL[i] && scrL[i].load == 2)
+ ids+=(ids?';':'')+'id='+scrL[i].id;
+ if(!ids)
return;
- scrL[i].timer = setTimeout(function() {
- if(!scrL[i].load)
+ ajax('/xml/screenshots.xml?'+ids+';r='+(Math.floor(Math.random()*999)+1), function () {
+ if(!hr || hr.readyState != 4 || !hr.responseText)
return;
- x('scrTr'+i).getElementsByTagName('td')[0].innerHTML =
- '<img src="'+scrURL(scrL[i].id, 't')+'?'+(Math.floor(Math.random()*999)+1)+'" onload="scrImageSuccess('+i+')"'
- +' onerror="scrImageFail('+i+')" style="visibility: hidden; width: 0px; height: 0px;" id="scrImage'+i+'" />';
- setTimeout('scrImageFail('+i+')', 7000);
- }, 2000);
-}
-
-function scrImageSuccess(i) {
- scrL[i].load = 0;
- x('scrImage'+i).style.cssText = 'margin: 0; padding: 0; border: 0;';
- scrGenerateTR(i);
- scrSer();
+ if(hr.status != 200)
+ return alert('Whoops, error! :(');
+ var l = hr.responseXML.getElementsByTagName('image');
+ for(var s=0;s<l.length;s++) {
+ for(i=0;i<scrL.length;i++)
+ if(scrL[i] && scrL[i].id == l[s].getAttribute('id') && l[s].getAttribute('status') > 0) {
+ scrL[i].load = 0;
+ scrL[i].width = l[s].getAttribute('width');
+ scrL[i].height = l[s].getAttribute('height');
+ x('scrTr'+i).getElementsByTagName('td')[0].innerHTML =
+ '<img src="'+scrURL(scrL[i].id, 't')+'" style="margin: 0; padding: 0; border: 0" />';
+ scrGenerateTR(i);
+ scrSer();
+ }
+ }
+ });
}
function scrDel(i) {
diff --git a/static/files/style.css b/static/files/style.css
index 65e02102..1da16c17 100644
--- a/static/files/style.css
+++ b/static/files/style.css
@@ -651,7 +651,6 @@ div#scrView {
#scrclose { float: right; padding-left: 10px; }
#scrnext { padding-left: 5px; }
#scrprev { padding-right: 5px; }
-#preload { visibility: hidden; position: absolute; left: -9000px; top: -9000px }