mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-06-19 20:35:16 +00:00
created textarea 2.0 object
This commit is contained in:
@ -602,6 +602,13 @@ var ComunicWeb = {
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Modern textarea handler
|
||||
*/
|
||||
textarea: {
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -27,14 +27,15 @@ function createElem(nodeType, appendTo){
|
||||
* @param {Object} infos Informations about the HTML node to create
|
||||
* @info {String} type The type of the new node
|
||||
* @info {HTMLElement} appendTo HTML Element that will receive the new node
|
||||
* @info {HTMLElement} insertBefore Insert before specified HTML element
|
||||
* @info {HTMLElement} class The class of the new element
|
||||
* @info {HTMLElement} id The ID of the new element
|
||||
* @info {HTMLElement} title The title of the new element
|
||||
* @info {HTMLElement} src The src attribute of the new element
|
||||
* @info {HTMLElement} type The type of the new element
|
||||
* @info {HTMLElement} value The value of the new element
|
||||
* @info {HTMLElement} innerHTML Specify the html content of the newly created element
|
||||
* @info {String} insertBefore Insert before specified HTML element
|
||||
* @info {String} class The class of the new element
|
||||
* @info {String} id The ID of the new element
|
||||
* @info {String} title The title of the new element
|
||||
* @info {String} src The src attribute of the new element
|
||||
* @info {String} type The type of the new element
|
||||
* @info {String} value The value of the new element
|
||||
* @info {String} placeholder The placeholder of the new element
|
||||
* @info {String} innerHTML Specify the html content of the newly created element
|
||||
* @return {HTMLElement} The newly created element
|
||||
*/
|
||||
function createElem2(infos){
|
||||
@ -73,6 +74,10 @@ function createElem2(infos){
|
||||
if(infos.value)
|
||||
newElem.value = infos.value;
|
||||
|
||||
//Specify element placeholder
|
||||
if(infos.placeholder)
|
||||
newElem.placeholder = infos.placeholder;
|
||||
|
||||
//Specify node content
|
||||
if(infos.innerHTML)
|
||||
newElem.innerHTML = infos.innerHTML;
|
||||
@ -214,6 +219,23 @@ function createFormGroup(infos){
|
||||
if(infos.placeholder) //Placeholder if required
|
||||
input.setAttribute("data-placeholder", infos.placeholder);
|
||||
|
||||
}
|
||||
//In case of textarea
|
||||
else if(infos.type = "textarea"){
|
||||
//Fill label value
|
||||
if(infos.label)
|
||||
labelElem.innerHTML = infos.label;
|
||||
else
|
||||
labelElem.remove(); //Remove useless label element
|
||||
|
||||
//Create textarea element
|
||||
var input = createElem2({
|
||||
appendTo: formGroup,
|
||||
type: "textarea",
|
||||
class: "form-control",
|
||||
placeholder: infos.placeholder,
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
//Else continue the function as a normal input type
|
||||
|
43
assets/js/components/textarea.js
Normal file
43
assets/js/components/textarea.js
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
textArea2.prototype.init = function(infos){
|
||||
|
||||
//Save Textarea element
|
||||
this.element = infos.element;
|
||||
|
||||
//Adapt textarea style
|
||||
this.element.style.overflow = "hidden";
|
||||
|
||||
//Initializate textarea auto-size
|
||||
$(this.element).textareaAutoSize();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the textarea value
|
||||
*
|
||||
* @return {String} Textarea value
|
||||
*/
|
||||
textArea2.prototype.getValue = function(){
|
||||
return this.element.innerText;
|
||||
};
|
||||
|
||||
//Save the function in the system
|
||||
ComunicWeb.components.textarea = textArea2;
|
@ -28,6 +28,8 @@ ComunicWeb.pages.home.home = {
|
||||
loginButton.innerHTML="Logout";
|
||||
targetElement.appendChild(loginButton);
|
||||
|
||||
|
||||
|
||||
//Dev feature emojies
|
||||
var emojiesArea = createElem2({
|
||||
appendTo: targetElement,
|
||||
@ -40,6 +42,23 @@ ComunicWeb.pages.home.home = {
|
||||
ComunicWeb.components.emoji.parser.parse({
|
||||
element: emojiesArea,
|
||||
});
|
||||
|
||||
//Create textarea element
|
||||
var textarea = createFormGroup({
|
||||
target: targetElement,
|
||||
type: "textarea",
|
||||
label: "Textarea",
|
||||
placeholder: "New message",
|
||||
});
|
||||
textarea.style.width = "200px";
|
||||
|
||||
//Initializate textarea
|
||||
var textarea2 = new ComunicWeb.components.textarea();
|
||||
textarea2.init({
|
||||
element: textarea
|
||||
});
|
||||
|
||||
console.log(textarea2);
|
||||
}
|
||||
else{
|
||||
//Display landing page
|
||||
|
Reference in New Issue
Block a user