1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-29 02:38:22 +01:00
antd-web-apps/blog/assets/afx.js

1 line
64 KiB
JavaScript
Raw Normal View History

var OS;!function(t){let e;!function(t){t.zindex=10;class e extends HTMLElement{constructor(){super(),this.observable||(this.observable=new Ant.OS.API.Announcer),this._mounted=!1,this.refs={}}set(t){for(let e in t){let s=this.descriptor_of(e);s&&s.set&&(this[e]=t[e])}}set tooltip(t){t&&$(this).attr("tooltip",t)}descriptor_of(t){let e,s=this;do{e=Object.getOwnPropertyDescriptor(s,t)}while(!e&&(s=Object.getPrototypeOf(s)));return e}set aid(t){$(this).attr("data-id",t)}get aid(){return $(this).attr("data-id")}sync(){this._mounted||(this._mounted=!0,this.mount(),super.sync())}afxml(t){t&&(this.observable=t),this.aid||(this.aid=(Math.floor(1e5*Math.random())+1).toString());const e=$(this).children();for(let t of this.layout()){const e=this.mkui(t);e&&$(e).appendTo(this)}if(this.refs.yield)for(let t of e)$(t).detach().appendTo(this.refs.yield);const s={};for(let t=0;t<this.attributes.length;t++){const e=this.attributes[t];let i=this.descriptor_of(e.nodeName);if(i&&i.set){let t="";try{t=JSON.parse(e.nodeValue)}catch(s){t=e.nodeValue}s[e.nodeName]=t}}super.afxml(this.observable),this.init();for(let t in s)this[t]=s[t]}update(t){this.reload(t),super.update(t)}calibrate(){}mkui(t){if(!t)return;const e=$(`<${t.el}>`);if(t.class&&$(e).addClass(t.class),t.id&&$(e).attr("data-id",t.id),t.height&&$(e).attr("data-height",t.height),t.width&&$(e).attr("data-width",t.width),t.tooltip&&$(e).attr("tooltip",t.tooltip.__()),t.children)for(let s of t.children)$(this.mkui(s)).appendTo(e);return t.ref&&(this.refs[t.ref]=e[0]),e[0]}attsw(t,e,s){t?this.atton(e,s):this.attoff(e,s)}atton(t,e){$(e||this).attr(t,"")}attoff(t,e){(e||this).removeAttribute(t)}hasattr(t,e){return(e||this).hasAttribute(t)}}let s;t.AFXTag=e,HTMLElement.prototype.update=function(t){$(this).children().each((function(){if(this.update)return this.update(t)}))},HTMLElement.prototype.sync=function(){$(this).children().each((function(){return this.sync()}))},HTMLElement.prototype.afxml=function(t){$(this).children().each((function(){return this.afxml(t)}))},HTMLElement.prototype.uify=function(t,e){this.afxml(t),this.sync(),t&&e&&t.trigger("mounted",this.aid)},function(t){t.define=function(t,e){try{customElements.define(t,e)}catch(s){const i=customElements.get(t);if(e){const t=Object.getOwnPropertyNames(e.prototype);for(let s of t)i.prototype[s]=e.prototype[s];return}throw s}}}(s=t.tag||(t.tag={}))}(e=t.GUI||(t.GUI={}))}(OS||(OS={})),function(t){let e;!function(t){let e;!function(e){class s extends t.AFXTag{constructor(){super()}init(){this._shown=!1,this._isMaxi=!1,this._history={},this.desktop=t.workspace,this._desktop_pos=$(this.desktop).offset(),this.minimizable=!0,this.resizable=!0,this.apptitle="Untitled"}calibrate(){}reload(t){}set width(t){this._width=t,t&&this.setsize({w:t,h:this.height})}get width(){return this._width}set height(t){this._height=t,t&&this.setsize({w:this.width,h:t})}get height(){return this._height}set minimizable(t){this.attsw(t,"minimizable"),t?$(this.refs.minbt).show():$(this.refs.minbt).hide()}get minimizable(){return this.hasattr("minimizable")}set resizable(t){this.attsw(t,"resizable"),t?($(this.refs.maxbt).show(),$(this.refs.grip).show()):($(this.refs.maxbt).hide(),$(this.refs.grip).hide())}get resizable(){return this.hasattr("resizable")}set apptitle(t){$(this).attr("apptitle",t.__()),t&&(this.refs.txtTitle.text=t)}get apptitle(){return $(this).attr("apptitle")}resize(){const t=$(this.refs.yield).height()/$(this.refs.yield).children().length;$(this.refs.yield).children().each((function(e){$(this).css("height",t+"px")}))}mount(){this.contextmenuHandle=function(t){},$(this.refs.minbt).click(t=>this.observable.trigger("hide",{id:this.aid})),$(this.refs.maxbt).click(t=>this.toggle_window()),$(this.refs.closebt).click(t=>this.observable.trigger("exit",{id:this.aid}));const t=($(this.desktop).width()-this.width)/2,e=($(this.desktop).height()-this.height)/2;return $(this).css("position","absolute").css("left",t+"px").css("top",e+"px").css("z-index",Ant.OS.GUI.zindex++),$(this).on("mousedown",t=>{if(!this._shown)return this.observable.trigger("focus",{id:th