feat: placeholder
This commit is contained in:
parent
0b9e0de79f
commit
7f339a1638
|
@ -15,7 +15,6 @@ class Container {
|
||||||
private options: Options;
|
private options: Options;
|
||||||
private node: NodeInterface;
|
private node: NodeInterface;
|
||||||
private _focused: boolean = false;
|
private _focused: boolean = false;
|
||||||
#styleElement?: Element;
|
|
||||||
|
|
||||||
constructor(selector: Selector, options: Options) {
|
constructor(selector: Selector, options: Options) {
|
||||||
this.node = $(selector);
|
this.node = $(selector);
|
||||||
|
@ -133,29 +132,18 @@ class Container {
|
||||||
showPlaceholder() {
|
showPlaceholder() {
|
||||||
const { placeholder } = this.options;
|
const { placeholder } = this.options;
|
||||||
if (placeholder) {
|
if (placeholder) {
|
||||||
if (this.#styleElement && this.#styleElement.parentNode)
|
|
||||||
document.body.removeChild(this.#styleElement);
|
|
||||||
this.#styleElement = document.createElement('style');
|
|
||||||
//const left = this.node.css('padding-left');
|
//const left = this.node.css('padding-left');
|
||||||
//const top = this.node.css('padding-top');
|
//const top = this.node.css('padding-top');
|
||||||
const styleText = document.createTextNode(`.am-engine:before {
|
|
||||||
content: attr(data-placeholder);
|
|
||||||
pointer-events: none;
|
|
||||||
position: absolute;
|
|
||||||
color: #bbbfc4;
|
|
||||||
height: 0;
|
|
||||||
}`);
|
|
||||||
this.#styleElement.appendChild(styleText);
|
|
||||||
document.body.appendChild(this.#styleElement);
|
|
||||||
this.node.attributes({
|
this.node.attributes({
|
||||||
'data-placeholder': placeholder,
|
'data-placeholder': placeholder,
|
||||||
});
|
});
|
||||||
} else if (this.#styleElement && this.#styleElement.parentNode)
|
this.node.addClass('am-engine-placeholder');
|
||||||
document.body.removeChild(this.#styleElement);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hidePlaceholder() {
|
hidePlaceholder() {
|
||||||
this.node.removeAttributes('data-placeholder');
|
this.node.removeAttributes('data-placeholder');
|
||||||
|
this.node.removeClass('am-engine-placeholder');
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
@ -169,7 +157,6 @@ class Container {
|
||||||
this.node.removeAttributes('data-gramm');
|
this.node.removeAttributes('data-gramm');
|
||||||
this.node.removeAttributes('tabindex');
|
this.node.removeAttributes('tabindex');
|
||||||
this.node.removeAttributes('data-placeholder');
|
this.node.removeAttributes('data-placeholder');
|
||||||
if (this.#styleElement) document.body.removeChild(this.#styleElement);
|
|
||||||
if (this.options.className) {
|
if (this.options.className) {
|
||||||
(Array.isArray(className)
|
(Array.isArray(className)
|
||||||
? className
|
? className
|
||||||
|
|
|
@ -598,6 +598,14 @@
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.am-engine.am-engine-placeholder:before {
|
||||||
|
content: attr(data-placeholder);
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
color: #bbbfc4;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.am-engine ::selection {
|
.am-engine ::selection {
|
||||||
background: rgba(180, 213, 254, 0.5) !important;
|
background: rgba(180, 213, 254, 0.5) !important;
|
||||||
color: inherit!important;
|
color: inherit!important;
|
||||||
|
|
Loading…
Reference in New Issue