Advertisement
pelzrutsche

PrimeFaces TextArea AutoResize Patch

May 7th, 2012
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.41 KB | None | 0 0
  1. Index: src/main/resources/META-INF/resources/primefaces/forms/forms.js
  2. ===================================================================
  3. --- src/main/resources/META-INF/resources/primefaces/forms/forms.js (revision 7443)
  4. +++ src/main/resources/META-INF/resources/primefaces/forms/forms.js (working copy)
  5. @@ -58,6 +58,12 @@
  6.      },
  7.      
  8.      setupAutoResize: function() {
  9. +        var suffix = "_reference", referenceContainerId = this.jqId + suffix;
  10. +        this.referenceContainer = $(referenceContainerId);
  11. +        if (this.referenceContainer.length != 1) {
  12. +            this.referenceContainer = $(document.createElement('div')).attr('id', this.id + suffix).addClass("ui-inputfield ui-inputtextarea ui-inputtextarea-resizable-reference").appendTo($(document.body));
  13. +        }
  14. +
  15.          var _self = this;
  16.  
  17.          this.jq.keyup(function() {
  18. @@ -70,16 +76,10 @@
  19.      },
  20.      
  21.      resize: function() {
  22. -        var linesCount = 0,
  23. -        lines = this.jq.val().split('\n');
  24. -
  25. -        for(var i = lines.length-1; i >= 0 ; --i) {
  26. -            linesCount += Math.floor((lines[i].length / this.cfg.colsDefault) + 1);
  27. -        }
  28. -
  29. -        var newRows = (linesCount >= this.cfg.rowsDefault) ? (linesCount + 1) : this.cfg.rowsDefault;
  30. -
  31. -        this.jq.attr('rows', newRows);
  32. +        //Update reference container and resize text area
  33. +        this.referenceContainer.width(this.jq.width());
  34. +        this.referenceContainer.text(this.jq.val());
  35. +        this.jq.height(this.referenceContainer.innerHeight());
  36.      },
  37.      
  38.      applyMaxlength: function() {
  39. @@ -1799,4 +1799,4 @@
  40.          
  41.          this._super(cfg);
  42.      }
  43. -});
  44. \ No newline at end of file
  45. +});
  46. Index: src/main/resources/META-INF/resources/primefaces/forms/forms.css
  47. ===================================================================
  48. --- src/main/resources/META-INF/resources/primefaces/forms/forms.css    (revision 7443)
  49. +++ src/main/resources/META-INF/resources/primefaces/forms/forms.css    (working copy)
  50. @@ -15,6 +15,15 @@
  51.      resize:none;
  52.  }
  53.  
  54. +.ui-inputtextarea-resizable-reference {
  55. +    position: absolute;
  56. +    bottom: 0;
  57. +    right: 0;
  58. +    white-space: pre-wrap;
  59. +    word-wrap: break-word;
  60. +    visibility: hidden;
  61. +}
  62. +
  63.  .ui-selectonelistbox, .ui-selectmanymenu {
  64.      width:100px;
  65.      overflow:auto;
  66. @@ -367,4 +376,4 @@
  67.  
  68.  .ui-password-panel-overlay {
  69.      position: absolute;
  70. -}
  71. \ No newline at end of file
  72. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement