From 46a684df7d8bfa5022ae15d1a6e0d5845a85168a Mon Sep 17 00:00:00 2001 From: Sinan Yasar Date: Thu, 28 Apr 2016 13:51:00 -0700 Subject: [PATCH 1/3] inputview: minor: code cleanup --- lib/components/inputs/inputview.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/components/inputs/inputview.coffee b/lib/components/inputs/inputview.coffee index 18ae4256..4330698e 100644 --- a/lib/components/inputs/inputview.coffee +++ b/lib/components/inputs/inputview.coffee @@ -91,7 +91,7 @@ module.exports = class KDInputView extends KDView @validationNotifications = {} @valid = yes @inputCallback = null - @previousHeight= null + @previousHeight = null @setName options.name @setLabel() @setCallback() @@ -449,7 +449,7 @@ module.exports = class KDInputView extends KDView # input content is copied into clone # element to get calculated height - @_clone = $ '
', class : 'invisible' + @_clone = $ '
', { class: 'invisible' } @on 'focus', => @_clone.appendTo 'body' From 4ce5f9194b0c2014b9f39ceff6af0b211052b006 Mon Sep 17 00:00:00 2001 From: Sinan Yasar Date: Thu, 28 Apr 2016 13:52:25 -0700 Subject: [PATCH 2/3] inputview: implement autogrow for single line inputs --- lib/components/inputs/inputview.coffee | 55 ++++++++++++++++++++------ 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/lib/components/inputs/inputview.coffee b/lib/components/inputs/inputview.coffee index 4330698e..078c23c1 100644 --- a/lib/components/inputs/inputview.coffee +++ b/lib/components/inputs/inputview.coffee @@ -92,6 +92,7 @@ module.exports = class KDInputView extends KDView @valid = yes @inputCallback = null @previousHeight = null + @previousWidth = null @setName options.name @setLabel() @setCallback() @@ -130,6 +131,7 @@ module.exports = class KDInputView extends KDView if o.autogrow @once "focus", => @initialHeight = @$().height() unless @initialHeight + @initialWidth = @$().width() unless @initialWidth setDomElement:(cssClass = "")-> name = "name='#{@options.name}'" @@ -451,12 +453,16 @@ module.exports = class KDInputView extends KDView # element to get calculated height @_clone = $ '
', { class: 'invisible' } + { type } = @getOptions() + isVertical = type.toLowerCase() is 'textarea' + + @on 'focus', => @_clone.appendTo 'body' @_clone.css - height : 'auto' + height : if isVertical then 'auto' else $input.css 'height' zIndex : 100000 - width : $input.css 'width' + width : if isVertical then $input.css 'width' else 'auto' boxSizing : $input.css 'box-sizing' borderTop : $input.css 'border-top' borderRight : $input.css 'border-right' @@ -472,29 +478,56 @@ module.exports = class KDInputView extends KDView fontSize : $input.css 'fontSize' fontWeight : $input.css 'fontWeight' lineHeight : $input.css 'lineHeight' - whiteSpace : 'pre-line' + whiteSpace : if isVertical then 'pre-line' else 'pre' @on 'blur', => @_clone.detach() - - @on 'input', (event) => KD.utils.defer => @resize event + @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 ') safeValue = Encoder.XSSEncode val @_clone.html safeValue - height = @_clone.height() + { type } = @getOptions() + + if type.toLowerCase() is 'textarea' + then return @_resizeVertically event + else return @_resizeHorizontally event + + _getValue = (el, rule) -> parseInt el.css(rule), 10 + + _resizeHorizontally: (event) -> + + return unless @_clone - getValue = (rule) => parseInt @_clone.css(rule), 10 + width = @_clone.width() + + if @$().css('boxSizing') is 'border-box' + padding = _getValue(@_clone, 'paddingLeft') + _getValue(@_clone, 'paddingRight') + border = _getValue(@_clone, 'borderLeftWidth') + _getValue(@_clone, 'borderRightWidth') + width = width + border + padding + + newWidth = if @initialWidth then Math.max @initialWidth, width else width + + if @previousWidth isnt newWidth + @setWidth newWidth + @emit 'InputWidthChanged' + + @previousWidth = newWidth + + + _resizeVertically: (event) -> + + return unless @_clone + + height = @_clone.height() if @$().css('boxSizing') is 'border-box' - padding = getValue('paddingTop') + getValue('paddingBottom') - border = getValue('borderTopWidth') + getValue('borderBottomWidth') + padding = _getValue(@_clone, 'paddingTop') + _getValue(@_clone, 'paddingBottom') + border = _getValue(@_clone, 'borderTopWidth') + _getValue(@_clone, 'borderBottomWidth') height = height + border + padding newHeight = if @initialHeight then Math.max @initialHeight, height else height From dc1808aafb0cfee52095c16641f4107ce6c4e8cb Mon Sep 17 00:00:00 2001 From: Sinan Yasar Date: Thu, 28 Apr 2016 13:55:29 -0700 Subject: [PATCH 3/3] npm: bump up version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22b1aa8c..baf36a7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kd.js", - "version": "1.1.20", + "version": "1.1.21", "description": "a collection of ui widgets and other nice things", "main": "build/lib/index.js", "scripts": {