DynamicTextarea Example

by Durtto

HTML

<script src="http://github.com/amadeus/DynamicTextarea-Mootools-Class/raw/master/Source/DynamicTextarea.js"></script>
<div>
    <h1>Default TextArea <small>(No styling or custom options)</small></h1>
    <textarea id="default"></textarea>
</div>

<div>
    <h1>Custom TextArea 1 <small>(CSS Styles, custom onBlur and onFocus events, 2 row minimum height)</small></h1>
    <textarea id="customEvents">I am at least 2 rows high</textarea>
</div>

<div>
    <h1>Custom TextArea 2 <small>(Preloaded with lots of content)</small></h1>
    <textarea id="customFilled">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</textarea>
</div>

CSS

body {
    font-family:Helvetica,Arial,sans-serif;
    -webkit-text-size-adjust:none;
}

h1 {
    font-size:20px;
    font-weight:bold;
    margin-bottom:5px;
}

small {
    display:block;
    font-size:12px;
}

div {
    margin-bottom:20px;
}

textarea#customEvents,
textarea#customExtra {
    font-family:Helvetica,Arial,sans-serif;
    padding:5px;
    font-size:18px;
    line-height:1.5em;
    width:300px;
    border:2px dashed red;
}

.default textarea#customEvents {
    color:#999;
}

textarea#customExtra {
    padding-bottom:1.5em;
    border:2px solid blue;
}

textarea#customFilled {
    padding:5px;
    font-size:14px;
    line-height:1.3em;
    width:400px;
    font-weight:bold;
    font-family:Helvetica,Arial,sans-serif;
}

JavaScript

// Default Textarea, takes no options
new DynamicTextarea('default');

// Custom Textarea, takes options object
new DynamicTextarea('customEvents', {
    minRows: 2,
    onLoad: function() {
        if (this.textarea.value == 'I am at least 2 rows high')
            this.textarea.addClass('default');
    },
    onFocus: function() {
        if (this.textarea.value == 'I am at least 2 rows high')
            this.textarea.value = '';
    },
    onBlur: function() {
        if (this.textarea.value == '')
            this.textarea.value = 'I am at least 2 rows high';
    }
});

new DynamicTextarea('customFilled');