slightly simplifiy expansion math
This commit is contained in:
parent
d7e533d3db
commit
ce4f7a2ef7
33
4chan_x.js
33
4chan_x.js
@ -1915,14 +1915,6 @@
|
|||||||
return _results;
|
return _results;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
foo: function() {
|
|
||||||
var bodyWidth, formLeft;
|
|
||||||
formLeft = $('form[name=delform]').getBoundingClientRect().left;
|
|
||||||
bodyWidth = d.body.clientWidth;
|
|
||||||
imgExpand.cw = bodyWidth - formLeft;
|
|
||||||
imgExpand.ch = d.body.clientHeight;
|
|
||||||
return imgExpand.type = $('#imageType').value;
|
|
||||||
},
|
|
||||||
toggle: function(img) {
|
toggle: function(img) {
|
||||||
var thumb;
|
var thumb;
|
||||||
thumb = img.parentNode.firstChild;
|
thumb = img.parentNode.firstChild;
|
||||||
@ -1947,25 +1939,30 @@
|
|||||||
a.appendChild(img);
|
a.appendChild(img);
|
||||||
return imgExpand.resize(img);
|
return imgExpand.resize(img);
|
||||||
},
|
},
|
||||||
|
foo: function() {
|
||||||
|
imgExpand.formRight = $('form[name=delform]').getBoundingClientRect().right;
|
||||||
|
imgExpand.maxHeight = d.body.clientHeight;
|
||||||
|
return imgExpand.type = $('#imageType').value;
|
||||||
|
},
|
||||||
resize: function(img) {
|
resize: function(img) {
|
||||||
var ch, cw, ih, iw, ratio, type, _, _ref2;
|
var formRight, imgHeight, imgWidth, maxHeight, maxWidth, ratio, type, _, _ref2;
|
||||||
cw = imgExpand.cw, ch = imgExpand.ch, type = imgExpand.type;
|
formRight = imgExpand.formRight, maxHeight = imgExpand.maxHeight, type = imgExpand.type;
|
||||||
_ref2 = $.x("preceding::span[@class][1]/text()[2]", img).textContent.match(/(\d+)x(\d+)/), _ = _ref2[0], iw = _ref2[1], ih = _ref2[2];
|
_ref2 = $.x("preceding::span[@class][1]/text()[2]", img).textContent.match(/(\d+)x(\d+)/), _ = _ref2[0], imgWidth = _ref2[1], imgHeight = _ref2[2];
|
||||||
iw = Number(iw);
|
imgWidth = Number(imgWidth);
|
||||||
ih = Number(ih);
|
imgHeight = Number(imgHeight);
|
||||||
cw = cw - img.getBoundingClientRect().left;
|
maxWidth = formRight - img.getBoundingClientRect().left;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'full':
|
case 'full':
|
||||||
return img.removeAttribute('style');
|
return img.removeAttribute('style');
|
||||||
case 'fit width':
|
case 'fit width':
|
||||||
if (iw > cw) {
|
if (imgWidth > maxWidth) {
|
||||||
return img.style.width = cw;
|
return img.style.width = maxWidth;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'fit screen':
|
case 'fit screen':
|
||||||
ratio = Math.min(cw / iw, ch / ih);
|
ratio = Math.min(maxWidth / imgWidth, maxHeight / imgHeight);
|
||||||
if (ratio < 1) {
|
if (ratio < 1) {
|
||||||
return img.style.width = Math.floor(ratio * iw);
|
return img.style.width = Math.floor(ratio * imgWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1448,13 +1448,6 @@ imgExpand =
|
|||||||
for img in $$ 'img[md5] + img'
|
for img in $$ 'img[md5] + img'
|
||||||
imgExpand.resize img
|
imgExpand.resize img
|
||||||
|
|
||||||
foo: ->
|
|
||||||
formLeft = $('form[name=delform]').getBoundingClientRect().left
|
|
||||||
bodyWidth = d.body.clientWidth
|
|
||||||
imgExpand.cw = bodyWidth - formLeft
|
|
||||||
imgExpand.ch = d.body.clientHeight
|
|
||||||
imgExpand.type = $('#imageType').value
|
|
||||||
|
|
||||||
toggle: (img) ->
|
toggle: (img) ->
|
||||||
thumb = img.parentNode.firstChild
|
thumb = img.parentNode.firstChild
|
||||||
imgExpand.foo()
|
imgExpand.foo()
|
||||||
@ -1476,26 +1469,32 @@ imgExpand =
|
|||||||
|
|
||||||
imgExpand.resize img
|
imgExpand.resize img
|
||||||
|
|
||||||
resize: (img) ->
|
foo: ->
|
||||||
{cw, ch, type} = imgExpand
|
imgExpand.formRight = $('form[name=delform]').getBoundingClientRect().right
|
||||||
[_, iw, ih] =
|
imgExpand.maxHeight = d.body.clientHeight
|
||||||
$.x("preceding::span[@class][1]/text()[2]", img)
|
imgExpand.type = $('#imageType').value
|
||||||
.textContent.match(/(\d+)x(\d+)/)
|
|
||||||
iw = Number iw
|
|
||||||
ih = Number ih
|
|
||||||
|
|
||||||
cw = cw - img.getBoundingClientRect().left
|
resize: (img) ->
|
||||||
|
{formRight, maxHeight, type} = imgExpand
|
||||||
|
[_, imgWidth, imgHeight] = $
|
||||||
|
.x("preceding::span[@class][1]/text()[2]", img)
|
||||||
|
.textContent.match(/(\d+)x(\d+)/)
|
||||||
|
imgWidth = Number imgWidth
|
||||||
|
imgHeight = Number imgHeight
|
||||||
|
|
||||||
|
# from image's left bound to form's right bound
|
||||||
|
maxWidth = formRight - img.getBoundingClientRect().left
|
||||||
|
|
||||||
switch type
|
switch type
|
||||||
when 'full'
|
when 'full'
|
||||||
img.removeAttribute 'style'
|
img.removeAttribute 'style'
|
||||||
when 'fit width'
|
when 'fit width'
|
||||||
if iw > cw
|
if imgWidth > maxWidth
|
||||||
img.style.width = cw
|
img.style.width = maxWidth
|
||||||
when 'fit screen'
|
when 'fit screen'
|
||||||
ratio = Math.min cw/iw, ch/ih
|
ratio = Math.min maxWidth/imgWidth, maxHeight/imgHeight
|
||||||
if ratio < 1
|
if ratio < 1
|
||||||
img.style.width = Math.floor ratio * iw
|
img.style.width = Math.floor ratio * imgWidth
|
||||||
|
|
||||||
dialog: ->
|
dialog: ->
|
||||||
controls = $.el 'div',
|
controls = $.el 'div',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user