Created
January 23, 2015 08:31
-
-
Save baio/b4f67a869127d203a5fb to your computer and use it in GitHub Desktop.
calculate element height for collection-repeat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
calcDim = (template, scope, containerElement) -> | |
exp = $interpolate(template) | |
html = exp(scope) | |
html = "<div class='item item-text-wrap' style='width: 100%; position: absolute;'>" + html + "</div>" | |
newElement = angular.element(html) | |
newElement.css(ionic.CSS.TRANSFORM, 'translate3d(-2000px,-2000px,0)') | |
containerElement.append(newElement) | |
offsetHeight = newElement[0].offsetHeight | |
offsetWidth = newElement[0].children[0].offsetWidth | |
newElement.remove() | |
width : offsetWidth, height : offsetHeight | |
getThreadContentDim = (thread, containerElement) -> | |
calcDim boardThreadType.getThreadTemplate(thread), {thread : thread}, containerElement | |
getImageHeigth = (thread, contentWidth) -> | |
if thread.data.img | |
regex = /^.*-(\d{1,4}x\d{1,4})\.(gif|jpg|png)$/g | |
match = regex.exec thread.data.img | |
if match | |
dim = match[1] | |
spts = dim.split "x" | |
width = parseInt spts[0] | |
height = parseInt spts[1] | |
#scale to thumb size | |
h = (contentWidth / width) * height | |
return h | |
else | |
return 300 | |
return 0 | |
getMessageHeigth = (thread, containerElement) -> | |
contentDim = getThreadContentDim thread, containerElement | |
imgHeight = getImageHeigth thread, contentDim.width | |
contentDim.height + imgHeight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment