2017-06-21 10:10:22 +00:00
|
|
|
/**
|
|
|
|
* Modern textarea handler
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a modern textarea element object
|
|
|
|
*/
|
|
|
|
var textArea2 = function(infos){
|
|
|
|
//Nothing now
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializate textarea 2.0 element
|
|
|
|
*
|
|
|
|
* @param {Object} infos Informations about the textarea to enable
|
|
|
|
* @info {HTMLElement} element The element to make modern
|
2017-06-21 14:17:45 +00:00
|
|
|
* @info {Integer} minHeight The minimal height for the textarea
|
|
|
|
* @info {Integer} maxHeight The maximal height for the textarea
|
2017-06-21 16:29:14 +00:00
|
|
|
* @info {Boolean} autosize Enable textarea auto-size plugin
|
2017-06-21 14:17:45 +00:00
|
|
|
* @return {Boolean} True for a success
|
2017-06-21 10:10:22 +00:00
|
|
|
*/
|
|
|
|
textArea2.prototype.init = function(infos){
|
|
|
|
|
|
|
|
//Save Textarea element
|
|
|
|
this.element = infos.element;
|
|
|
|
|
|
|
|
//Adapt textarea style
|
|
|
|
this.element.style.overflow = "hidden";
|
2017-06-21 14:17:45 +00:00
|
|
|
this.element.style.resize = "none";
|
|
|
|
|
|
|
|
//Check for minimal and maximal height
|
|
|
|
if(infos.minHeight){
|
|
|
|
this.element.style.height = infos.minHeight;
|
|
|
|
this.element.style.minHeight = infos.minHeight;
|
|
|
|
}
|
|
|
|
if(infos.maxHeight)
|
|
|
|
this.element.style.maxHeight = infos.maxHeight;
|
2017-06-21 10:10:22 +00:00
|
|
|
|
|
|
|
//Initializate textarea auto-size
|
2017-06-21 16:29:14 +00:00
|
|
|
if(infos.autosize === undefined || infos.autosize)
|
|
|
|
$(this.element).textareaAutoSize();
|
2017-06-21 10:10:22 +00:00
|
|
|
|
2017-06-21 14:17:45 +00:00
|
|
|
//Success
|
|
|
|
return true;
|
2017-06-21 10:10:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the textarea value
|
|
|
|
*
|
|
|
|
* @return {String} Textarea value
|
|
|
|
*/
|
|
|
|
textArea2.prototype.getValue = function(){
|
|
|
|
return this.element.innerText;
|
|
|
|
};
|
|
|
|
|
2017-06-22 09:16:53 +00:00
|
|
|
/**
|
|
|
|
* Reset textarea height to its minimal height
|
|
|
|
*/
|
|
|
|
textArea2.prototype.resetHeight = function(){
|
|
|
|
this.element.style.height = this.element.style.minHeight;
|
|
|
|
}
|
|
|
|
|
2017-06-21 10:10:22 +00:00
|
|
|
//Save the function in the system
|
|
|
|
ComunicWeb.components.textarea = textArea2;
|