better maxwidth algorithm
This commit is contained in:
parent
06ae1b66bf
commit
1be9058429
17
4chan_x.js
17
4chan_x.js
@ -1997,23 +1997,28 @@
|
|||||||
return imgExpand.resize(img);
|
return imgExpand.resize(img);
|
||||||
},
|
},
|
||||||
foo: function() {
|
foo: function() {
|
||||||
var borderLeftWidth, borderRightWidth, crap, formWidth, left, paddingLeft, paddingRight, table, td, _ref2;
|
var crap, formWidth, left, table, td;
|
||||||
formWidth = $('form[name=delform]').getBoundingClientRect().width;
|
formWidth = $('form[name=delform]').getBoundingClientRect().width;
|
||||||
td = $('td.reply');
|
td = $('td.reply');
|
||||||
table = td.parentNode.parentNode.parentNode;
|
table = td.parentNode.parentNode.parentNode;
|
||||||
left = td.getBoundingClientRect().left - table.getBoundingClientRect().left;
|
left = td.getBoundingClientRect().left - table.getBoundingClientRect().left;
|
||||||
_ref2 = getComputedStyle(td), paddingLeft = _ref2.paddingLeft, paddingRight = _ref2.paddingRight, borderLeftWidth = _ref2.borderLeftWidth, borderRightWidth = _ref2.borderRightWidth;
|
crap = td.getBoundingClientRect().width - parseInt(getComputedStyle(td).width);
|
||||||
crap = parseInt(paddingLeft) + parseInt(paddingRight) + parseInt(borderLeftWidth) + parseInt(borderRightWidth);
|
imgExpand.maxWidthOP = formWidth;
|
||||||
imgExpand.maxWidth = formWidth - left - crap;
|
imgExpand.maxWidthReply = formWidth - left - crap;
|
||||||
imgExpand.maxHeight = d.body.clientHeight;
|
imgExpand.maxHeight = d.body.clientHeight;
|
||||||
return imgExpand.type = $('#imageType').value;
|
return imgExpand.type = $('#imageType').value;
|
||||||
},
|
},
|
||||||
resize: function(img) {
|
resize: function(img) {
|
||||||
var imgHeight, imgWidth, maxHeight, maxWidth, ratio, type, _, _ref2;
|
var imgHeight, imgWidth, maxHeight, maxWidth, maxWidthOP, maxWidthReply, ratio, type, _, _ref2;
|
||||||
maxWidth = imgExpand.maxWidth, maxHeight = imgExpand.maxHeight, type = imgExpand.type;
|
maxWidthOP = imgExpand.maxWidthOP, maxWidthReply = imgExpand.maxWidthReply, maxHeight = imgExpand.maxHeight, type = imgExpand.type;
|
||||||
_ref2 = $.x("preceding::span[@class][1]/text()[2]", img).textContent.match(/(\d+)x(\d+)/), _ = _ref2[0], imgWidth = _ref2[1], imgHeight = _ref2[2];
|
_ref2 = $.x("preceding::span[@class][1]/text()[2]", img).textContent.match(/(\d+)x(\d+)/), _ = _ref2[0], imgWidth = _ref2[1], imgHeight = _ref2[2];
|
||||||
imgWidth = Number(imgWidth);
|
imgWidth = Number(imgWidth);
|
||||||
imgHeight = Number(imgHeight);
|
imgHeight = Number(imgHeight);
|
||||||
|
if (img.parentNode.parentNode.nodeName === 'TD') {
|
||||||
|
maxWidth = maxWidthReply;
|
||||||
|
} else {
|
||||||
|
maxWidth = maxWidthOP;
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'full':
|
case 'full':
|
||||||
return img.removeAttribute('style');
|
return img.removeAttribute('style');
|
||||||
|
|||||||
@ -1521,23 +1521,26 @@ imgExpand =
|
|||||||
td = $('td.reply')
|
td = $('td.reply')
|
||||||
table = td.parentNode.parentNode.parentNode
|
table = td.parentNode.parentNode.parentNode
|
||||||
left = td.getBoundingClientRect().left - table.getBoundingClientRect().left
|
left = td.getBoundingClientRect().left - table.getBoundingClientRect().left
|
||||||
|
crap = td.getBoundingClientRect().width - parseInt(getComputedStyle(td).width)
|
||||||
|
|
||||||
#XXX not sure I'm doing this right -_-;
|
imgExpand.maxWidthOP = formWidth
|
||||||
{paddingLeft, paddingRight, borderLeftWidth, borderRightWidth} = getComputedStyle(td)
|
imgExpand.maxWidthReply = formWidth - left - crap
|
||||||
crap = parseInt(paddingLeft) + parseInt(paddingRight) + parseInt(borderLeftWidth) + parseInt(borderRightWidth)
|
|
||||||
|
|
||||||
imgExpand.maxWidth = formWidth - left - crap
|
|
||||||
imgExpand.maxHeight = d.body.clientHeight
|
imgExpand.maxHeight = d.body.clientHeight
|
||||||
imgExpand.type = $('#imageType').value
|
imgExpand.type = $('#imageType').value
|
||||||
|
|
||||||
resize: (img) ->
|
resize: (img) ->
|
||||||
{maxWidth, maxHeight, type} = imgExpand
|
{maxWidthOP, maxWidthReply, maxHeight, type} = imgExpand
|
||||||
[_, imgWidth, imgHeight] = $
|
[_, imgWidth, imgHeight] = $
|
||||||
.x("preceding::span[@class][1]/text()[2]", img)
|
.x("preceding::span[@class][1]/text()[2]", img)
|
||||||
.textContent.match(/(\d+)x(\d+)/)
|
.textContent.match(/(\d+)x(\d+)/)
|
||||||
imgWidth = Number imgWidth
|
imgWidth = Number imgWidth
|
||||||
imgHeight = Number imgHeight
|
imgHeight = Number imgHeight
|
||||||
|
|
||||||
|
if img.parentNode.parentNode.nodeName == 'TD'
|
||||||
|
maxWidth = maxWidthReply
|
||||||
|
else
|
||||||
|
maxWidth = maxWidthOP
|
||||||
|
|
||||||
switch type
|
switch type
|
||||||
when 'full'
|
when 'full'
|
||||||
img.removeAttribute 'style'
|
img.removeAttribute 'style'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user