Add Control class.

This commit is contained in:
Tipx-L 2023-10-09 23:07:27 -07:00
parent 0e2864e9dc
commit 03445f5772
1 changed files with 61 additions and 90 deletions

View File

@ -31188,8 +31188,52 @@
return this; return this;
} }
}, },
control:{ Control:class extends HTMLDivElement{
open:function(){ constructor(){
const nc=!ui.control.querySelector('div:not(.removing):not(.stayleft)');
const controls=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);
const control=ui.create.div('.control');
Object.setPrototypeOf(control,lib.element.Control.prototype);
ui.control.insertBefore(control,_status.createControl||ui.confirm);
controls.forEach(argument=>{
if(argument=='nozoom') return;
if(typeof argument=='function') control.custom=argument;
else if(argument=='stayleft'){
control.stayleft=true;
control.classList.add('stayleft');
}
else control.add(argument);
});
ui.controls.unshift(control);
if(nc) ui.control.animate('nozoom',100);
if(control.childNodes.length){
control.style.transition='opacity 0.5s';
control.animate('controlpressdownx',500);
ui.refresh(control);
if(!control.stayleft) control.style.transform=`translateX(-${control.offsetWidth/2}px)`;
control.style.opacity=1;
ui.refresh(control);
control.style.transition='';
}
control.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control2);
if(lib.config.button_press){
control.addEventListener(lib.config.touchscreen?'touchstart':'mousedown',function(){
if(this.classList.contains('disabled')) return;
this.classList.add('controlpressdown');
if(typeof this._offset=='number') this.style.transform=`translateX(${this._offset}px) scale(0.97)`;
});
control.addEventListener(lib.config.touchscreen?'touchend':'mouseup',function(){
this.classList.remove('controlpressdown');
if(typeof this._offset=='number') this.style.transform=`translateX(${this._offset}px)`;
});
}
ui.updatec();
return control;
}
open(){
ui.control.insertBefore(this,_status.createControl||ui.confirm); ui.control.insertBefore(this,_status.createControl||ui.confirm);
ui.controls.unshift(this); ui.controls.unshift(this);
if(this.childNodes.length){ if(this.childNodes.length){
@ -31205,15 +31249,15 @@
} }
ui.updatec(); ui.updatec();
return this; return this;
}, }
add:function(item){ add(item){
var node=document.createElement('div'); var node=document.createElement('div');
this.appendChild(node); this.appendChild(node);
node.link=item; node.link=item;
node.innerHTML=get.translation(item); node.innerHTML=get.translation(item);
node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control); node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control);
}, }
close:function(){ close(){
this.animate('controlpressdownx',500); this.animate('controlpressdownx',500);
ui.controls.remove(this); ui.controls.remove(this);
@ -31226,8 +31270,8 @@
if(ui.skills==this) delete ui.skills; if(ui.skills==this) delete ui.skills;
if(ui.skills2==this) delete ui.skills2; if(ui.skills2==this) delete ui.skills2;
if(ui.skills3==this) delete ui.skills3; if(ui.skills3==this) delete ui.skills3;
}, }
replace:function(){ replace(){
// this.animate('controlpressdownx',500); // this.animate('controlpressdownx',500);
if(this.replaceTransition===false){ if(this.replaceTransition===false){
this.style.transitionProperty='none'; this.style.transitionProperty='none';
@ -31412,6 +31456,12 @@
*/ */
get dialog(){ get dialog(){
return this.Dialog.prototype; return this.Dialog.prototype;
},
/**
* @legacy Use `lib.element.Control.prototype` instead.
*/
get control(){
return this.Control.prototype;
} }
}, },
card:{ card:{
@ -50775,88 +50825,7 @@
return caption; return caption;
}, },
control:function(){ control:function(){
var nc=!ui.control.querySelector('div:not(.removing):not(.stayleft)'); return new lib.element.Control(...arguments);
// for(var i=0;i<ui.control.childNodes.length;i++){
// if(ui.control.childNodes[i].classList.contains('removing')){
// var that=ui.control.childNodes[i];
// var width=that.offsetWidth;
// that.style.marginLeft=(-width/2)+'px';
// that.style.marginRight=(-width/2)+'px';
// that.style.transitionDuration=0.8*parseFloat(getComputedStyle(that).opacity)+'s';
// }
// }
var i,controls;
var nozoom=false;
if(Array.isArray(arguments[0])) controls=arguments[0];
else controls=arguments;
var control=ui.create.div('.control');
ui.control.insertBefore(control,_status.createControl||ui.confirm);
for(i in lib.element.control){
control[i]=lib.element.control[i];
}
for(i=0;i<controls.length;i++){
if(typeof controls[i]=='function'){
control.custom=controls[i];
}
else if(controls[i]=='nozoom'){
nozoom=true;
}
else if(controls[i]=='stayleft'){
control.stayleft=true;
control.classList.add('stayleft');
}
else{
control.add(controls[i]);
}
}
ui.controls.unshift(control);
if(nc){
ui.control.animate('nozoom',100);
}
// if(ui.control.classList.contains('nozoom')){
// nozoom=true;
// }
// if(nozoom){
// control.classList.add('nozoom');
// }
if(control.childNodes.length){
// if(nozoom||true){
control.style.transition='opacity 0.5s';
control.animate('controlpressdownx',500);
// }
// else{
// control.style.transition='';
// control.style.transform='scale(0.8)';
// }
ui.refresh(control);
if(!control.stayleft){
control.style.transform='translateX(-'+(control.offsetWidth/2)+'px)';
}
control.style.opacity=1;
ui.refresh(control);
control.style.transition='';
}
control.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control2);
if(lib.config.button_press){
control.addEventListener(lib.config.touchscreen?'touchstart':'mousedown',function(){
if(this.classList.contains('disabled')) return;
this.classList.add('controlpressdown');
if(typeof this._offset=='number'){
this.style.transform='translateX('+this._offset+'px) scale(0.97)';
}
});
control.addEventListener(lib.config.touchscreen?'touchend':'mouseup',function(){
this.classList.remove('controlpressdown');
if(typeof this._offset=='number'){
this.style.transform='translateX('+this._offset+'px)';
}
});
}
ui.updatec();
return control;
}, },
confirm:function(str,func){ confirm:function(str,func){
if(ui.confirm&&ui.confirm.str==str){ if(ui.confirm&&ui.confirm.str==str){
@ -61486,6 +61455,8 @@
setAllPropertiesEnumerable(lib.element.Player.prototype); setAllPropertiesEnumerable(lib.element.Player.prototype);
setAllPropertiesEnumerable(lib.element.Card.prototype); setAllPropertiesEnumerable(lib.element.Card.prototype);
setAllPropertiesEnumerable(lib.element.Event.prototype); setAllPropertiesEnumerable(lib.element.Event.prototype);
setAllPropertiesEnumerable(lib.element.Dialog.prototype);
setAllPropertiesEnumerable(lib.element.Control.prototype);
if('__core-js_shared__' in window) lib.init.init(); if('__core-js_shared__' in window) lib.init.init();
else{ else{
const coreJSBundle=document.createElement('script'); const coreJSBundle=document.createElement('script');