Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

inputview minor autogrow fix #156

Merged
merged 3 commits into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions lib/components/inputs/inputview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -443,49 +443,52 @@ module.exports = class KDInputView extends KDView

setAutoGrow:->

$input = @$()

$input.css 'overflow', 'hidden'

@setClass 'autogrow'

# input content is copied into clone
# element to get calculated height
@_clone = $ '<div/>', { class: 'invisible' }

@on 'focus', @bound 'prepareClone'
@on 'blur', => @_clone.detach()
@on 'input', @bound 'resize'


prepareClone: ->

$input = @$()
$input.css 'overflow', 'hidden'
{ type } = @getOptions()
isVertical = type.toLowerCase() is 'textarea'

@_clone.appendTo 'body'
@_clone.css
height : if isVertical then 'auto' else $input.css 'height'
zIndex : 100000
width : if isVertical then $input.css 'width' else 'auto'
boxSizing : $input.css 'box-sizing'
borderTop : $input.css 'border-top'
borderRight : $input.css 'border-right'
borderBottom : $input.css 'border-bottom'
borderLeft : $input.css 'border-left'
minHeight : $input.css 'minHeight'
maxHeight : $input.css 'maxHeight'
paddingTop : $input.css 'padding-top'
paddingRight : $input.css 'padding-right'
paddingBottom : $input.css 'padding-bottom'
paddingLeft : $input.css 'padding-left'
wordBreak : $input.css 'wordBreak'
fontSize : $input.css 'fontSize'
fontWeight : $input.css 'fontWeight'
lineHeight : $input.css 'lineHeight'
whiteSpace : if isVertical then 'pre-line' else 'pre'

@on 'focus', =>
@_clone.appendTo 'body'
@_clone.css
height : if isVertical then 'auto' else $input.css 'height'
zIndex : 100000
width : if isVertical then $input.css 'width' else 'auto'
boxSizing : $input.css 'box-sizing'
borderTop : $input.css 'border-top'
borderRight : $input.css 'border-right'
borderBottom : $input.css 'border-bottom'
borderLeft : $input.css 'border-left'
minHeight : $input.css 'minHeight'
maxHeight : $input.css 'maxHeight'
paddingTop : $input.css 'padding-top'
paddingRight : $input.css 'padding-right'
paddingBottom : $input.css 'padding-bottom'
paddingLeft : $input.css 'padding-left'
wordBreak : $input.css 'wordBreak'
fontSize : $input.css 'fontSize'
fontWeight : $input.css 'fontWeight'
lineHeight : $input.css 'lineHeight'
whiteSpace : if isVertical then 'pre-line' else 'pre'

@on 'blur', => @_clone.detach()
@on 'input', @bound 'resize'


resize: (event) ->

return unless @_clone

@_clone.appendTo 'body' unless document.body.contains @_clone[0]
val = @getElement().value.replace(/\n/g,'\n&nbsp;')
safeValue = Encoder.XSSEncode val
Expand All @@ -501,8 +504,6 @@ module.exports = class KDInputView extends KDView

_resizeHorizontally: (event) ->

return unless @_clone

width = @_clone.width()

if @$().css('boxSizing') is 'border-box'
Expand All @@ -521,8 +522,6 @@ module.exports = class KDInputView extends KDView

_resizeVertically: (event) ->

return unless @_clone

height = @_clone.height()

if @$().css('boxSizing') is 'border-box'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kd.js",
"version": "1.1.21",
"version": "1.1.22",
"description": "a collection of ui widgets and other nice things",
"main": "build/lib/index.js",
"scripts": {
Expand Down