suyiScreen/public/htWeb/lib/plugin/ht-palette.js

1 line
14 KiB
JavaScript

!function(b,J,m){"use strict";var s="px",N="0",K="innerHTML",g="className",d=ht.Default,H=ht.Color,x=ht.Node,n="position",Z="top",l="left",E=d.animate,W=d.getInternal(),z="width",N="0",v="none",U="max-height",c="font",D="background",V="border-box",k="user-select",L="box-sizing",o="overflow",h=d.isTouchable,T=d.isTouchEvent,W=d.getInternal(),f=H.titleIconBackground,j=d.scrollBarInteractiveSize,r=/msie 9/.test(b.navigator?b.navigator.userAgent.toLowerCase():""),S=null,B=function(){return document},Y=function(Y){return B().createElement(Y)},X=function(){return Y("div")},p=function(){var Y=X(),l=Y.style;return l.msTouchAction=v,l.cursor="default",h&&l.setProperty("-webkit-tap-highlight-color","rgba(0, 0, 0, 0)",S),l.position="absolute",l.left=N,l.top=N,Y},t=function(){return Y("canvas")},C=function(){return document.body},q=function(A,e,C){A.style.setProperty(e,C,S)},e=function(G,M){G.style.removeProperty(M)},P=function(e,V,X){d.def(ht.widget[e],V,X)},I=function(V,i){V.appendChild(i)},R=function(G,C){G.removeChild(C)},u=W.addEventListener;W.removeEventListener,W.addMethod(d,{paletteExpandIcon:{width:16,height:16,comps:[{type:"triangle",rect:[4,4,10,8],background:f,rotation:3.14}]},paletteCollapseIcon:{width:16,height:16,comps:[{type:"triangle",rect:[4,4,10,8],background:f}]},paletteTitleLabelColor:d.labelSelectColor,paletteTitleLabelFont:d.labelFont,paletteContentLabelFont:d.labelFont,paletteContentLabelColor:"#777",paletteContentBackground:"#fff",paletteTitleHeight:d.widgetTitleHeight,paletteTitleBackground:H.titleBackground,paletteTitleHoverBackground:H.titleBackground,paletteSeparatorWidth:1,paletteSeparatorColor:m,paletteItemHoverBorderColor:H.highlight,paletteItemSelectBackground:H.highlight},!0);var A=".palette-item:hover{border: 1px solid "+d.paletteItemHoverBorderColor+" !important}"+" .palette-header:hover{background: "+d.paletteTitleHoverBackground+" !important}",w=document.createElement("style");h||(w.styleSheet?w.styleSheet.cssText=A:w.appendChild(B().createTextNode(A))),B().getElementsByTagName("head")[0].appendChild(w);var Q=function(K){var i=this;i.$22h=K,i.addListeners()};d.def(Q,J,{ms_listener:1,getView:function(){return this.$22h.getView()},$26h:function(){var V=this;V.$36h&&C().removeChild(V.$36h),V.$23h=V.$24h=V.$25h=V.$35h=V.$36h=S},handle_touchstart:function(Y){for(var w,r=this,i=r.$22h,s=Y.target,f=i.sm(),C=i.dm(),F="palette-header",X="palette-header-tool",b="palette-item",_=!1,V=!1,q=!1;s&&(s[g]||"").indexOf(F)<0&&(s[g]||"").indexOf(b)<0;)s=s.parentNode;if(s&&s[g].indexOf(X)>=0?_=!0:s&&s[g].indexOf(F)>=0?q=!0:s&&s[g].indexOf(b)>=0&&(V=!0),d.isLeftButton(Y))if(r.$27h(Y))r.$24h=d.getClientPoint(Y),r.$25h=i.ty();else if(_){d.preventDefault(Y),w=s.parentNode.$11h;var P=C.getDataById(w),R=P.s("tools")[s.toolIndex];R.action&&R.action.call(i)}else if(q){d.preventDefault(Y),w=s.$11h;var P=C.getDataById(w);P.isExpanded()?P.setExpanded(!1):P.setExpanded(!0)}else if(V){w=s.$11h;var z=C.getDataById(w);f.ss(z),i.handleDragAndDrop&&(d.preventDefault(Y),z.s("draggable")&&(i.handleDragAndDrop(Y,"prepare"),r.$35h=0)),z.s("draggable")||(d.preventDefault(Y),r.$24h=d.getClientPoint(Y),r.$25h=i.ty())}else d.preventDefault(Y),r.$24h=d.getClientPoint(Y),r.$25h=i.ty();else r.$26h(Y)},handle_mousedown:function(L){this.handle_touchstart(L)},handle_mousewheel:function(r){this.handleScroll(r,r.wheelDelta/40,r.wheelDelta!==r.wheelDeltaX)},handle_DOMMouseScroll:function(i){this.handleScroll(i,-i.detail,1)},handleScroll:function(Y,H,W){var B=this.$22h;d.preventDefault(Y),W&&B._41o()&&B.ty(B.ty()+20*H)},handle_mouseup:function(f){this.handle_touchend(f)},handle_touchend:function(H){var g=this;g.$37h(H),g.$26h(H)},handleWindowMouseUp:function(Y){this.handleWindowTouchEnd(Y)},handleWindowTouchEnd:function(M){var a=this;a.$37h(M),a.$26h(M)},$37h:function(Z){var E=this,N=E.$22h;2===E.$35h&&(E.$35h=3,N.handleDragAndDrop(Z,"end"))},handleWindowMouseMove:function(Y){this.handleWindowTouchMove(Y)},handleWindowTouchMove:function(g){var N=this,e=N.$22h,Y=N.$23h,B=N.$24h,k=N.$25h,p=d.getClientPoint(g),m=e._29I,U=N.$36h;if(1===N.$35h||2===N.$35h){if(N.$35h=2,e.handleDragAndDrop(g,"between"),T(g)){var H=g.touches[0];g=H?H:g.changedTouches[0]}U.style.left=g.pageX-parseInt(U.width)/2+s,U.style.top=g.pageY-parseInt(U.height)/2+s}else"p"===Y?e.ty(k+p.y-B.y):"v"===Y&&e.ty(k+(B.y-p.y)/m.height*e._59I)},handle_mousemove:function(s){this.handle_touchmove(s)},handle_touchmove:function(V){if(!d.isDragging()&&d.isLeftButton(V)){var F=this,M=F.$22h,f=F.$27h(V);if(F.$24h){if(!F.$23h){if(d.getDistance(d.getClientPoint(V),F.$24h)<2)return;F.$23h=f?"v":"p",d.startDragging(F,V)}}else if(f)M._43o();else if(0===F.$35h){if(F.$35h=1,M.handleDragAndDrop(V,"begin"),d.startDragging(F,V),T(V)){var G=V.touches[0];V=G?G:V.changedTouches[0]}var g=F.$36h=new Image,O=M.$10h[M.sm().ld().getId()].querySelector(".image-box"),p=parseInt(O.style.width),z=parseInt(O.style.height);g.draggable=!1,g.src=O.toDataURL(),g.width=p,g.height=z,g.style.position="absolute",g.style.left=V.pageX-p/2+s,g.style.top=V.pageY-z/2+s,C().appendChild(g)}}},$27h:function(E){var k=this.$22h,h=k.getView(),O=h.getBoundingClientRect(),I=k._29I,l=E.clientX-O.left+h.scrollLeft;return k._41o()&&I.x+I.width-l<j}}),ht.widget.Palette=function(e){var f=this,B=f._view=W.createView(null,f);f.$9h={},f.$10h={},f.$4h={},f._29I={x:0,y:0,width:0,height:0},f._59I=0,f.dm(e?e:new ht.DataModel),B[g]="ht-widget-palette",f.$29h=new Q(f),q(B,D,d.paletteContentBackground),q(B,o,"auto"),q(B,L,V),q(B,"-moz-"+L,V),q(B,"-webkit-"+k,v),q(B,"-moz-"+k,v),q(B,"-ms-"+k,v),q(B,k,v),q(B,"position","absolute"),q(B,"overflow","hidden"),I(B,f._79O=p()),u(B,"dragstart",function(N){N.dataTransfer&&(N.dataTransfer.setData("Text","nodeid:"+N.target.$11h),N.dataTransfer.effectAllowed="all",f.$29h.$26h())})},P("Palette",J,{ms_v:1,ms_fire:1,ms_dm:1,ms_sm:1,ms_vs:1,ms_bnb:1,ms_ac:["itemImageWidth","itemImageHeight","itemImagePadding","itemMargin","layout","autoHideScrollBar","scrollBarSize","scrollBarColor"],$30h:0,_itemImagePadding:4,_itemImageWidth:70,_itemImageHeight:50,_itemMargin:10,_layout:"largeicons",_autoHideScrollBar:d.autoHideScrollBar,_scrollBarSize:d.scrollBarSize,_scrollBarColor:d.scrollBarColor,getViewRect:function(){return this._29I},ty:function(h){return h==S?this.getTranslateY():(this.setTranslateY(h),void 0)},setTranslateY:function(N){if(this.$32h==S){var n=this,T=n.$33h(N),b=n.$30h;n.$30h=T,n.fp("translateY",b,T)}},getTranslateY:function(){return this.$30h},setLayout:function(f){var p,A,y=this,V=y._layout;y._layout=f,"smallicons"===f?p=A=20:"iconsonly"===f?p=A=50:(p=70,A=50),y.setItemImageWidth(p),y.setItemImageHeight(A),y.setItemImagePadding(4),y.fp("layout",V,f)},getDataAt:function(O){for(var T=O.target;T&&T.$11h==S;)T=T.parentNode;return T&&T.$11h!=S?this.getDataModel().getDataById(T.$11h):void 0},$20h:function(){var b=16;return h&&(b*=1.2),b},$19h:function(){return d.paletteTitleHeight},$18h:function(){var g=d.paletteSeparatorWidth,$=d.paletteTitleBackground,j=d.paletteSeparatorColor||d.brighter($);return g+s+" solid "+j},$17h:function(y){q(y,"cursor","pointer"),q(y,"display","inline-block"),q(y,"margin-right",(h?8:4)+s),q(y,"vertical-align",Z)},$1h:function(F){var i=this,a=X(),B=X(),$=Y("span");a[g]="palette-header",q(a,n,"relative"),q(a,D,d.paletteTitleBackground),q(a,"color",d.paletteTitleLabelColor),q(a,Z,N),q(a,L,V),q(a,"-moz-"+L,V),q(a,"padding","0 5px 0 0"),q(a,"border-top",i.$18h()),q(a,z,"100%"),q(a,"cursor","pointer"),q(a,"white-space","nowrap"),q(a,o,"hidden"),q(a,c,d.paletteTitleLabelFont),q(a,"line-height",i.$19h()+s),a.$11h=F.getId();var w=t(),k=i.$19h(),e=i.$20h();i.$17h(w),W.setCanvas(w,e,k),I(a,w);var p=F.s("tools");if(p)for(var b=0;b<p.length;b++){var E=t();i.$17h(E),W.setCanvas(E,e,k),E[g]="palette-header-tool palette-header-tool"+F.getId()+"-"+b,E.style.position="absolute",E.style.right=(e+10)*b+"px",E.toolIndex=b,I(a,E)}return w[g]="palette-toggle-icon-"+F.getId(),B[g]="palette-content",q(B,"max-height",0+s),q(B,c,d.paletteContentLabelFont),q(B,o,"hidden"),B.$11h=F.getId(),i.$9h[F.getId()]=B,$[K]=F.getName(),q($,c,d.paletteTitleLabelFont),I(a,w),I(a,$),[a,B]},$2h:function(m){var F=this,U=F._layout,z=r&&m.s("draggable")?Y("a"):X(),B=t(),J=X(),V=m.getName()||"",a=m.s("title")||m.getToolTip()||V,p=F._itemMargin;B[g]="image-box";var u=F.getItemImageWidth(),k=F.getItemImageHeight();return W.setCanvas(B,u,k),I(z,B),J[K]=V,J[g]="label-box","iconsonly"!==U&&I(z,J),z[g]="palette-item",q(z,"vertical-align",Z),q(z,"cursor","pointer"),q(z,"border-radius",5+s),q(z,"border","1px solid transparent"),q(z,"text-align","center"),q(z,"display","inline-block"),q(z,"margin-left",p+s),q(z,"margin-top",p+s),q(z,"color",d.paletteContentLabelColor),"smallicons"===U?(q(B,"vertical-align","middle"),q(z,"margin-left",2+s),q(z,"margin-top",2+s),q(z,"padding",2+s),q(z,"text-align",l),q(J,"display","inline-block"),q(J,"min-width",F.$21h+F._itemMargin+s)):"largeicons"===U&&(q(J,"max-width",u+s),q(J,"overflow","hidden")),z.$11h=m.getId(),a&&(z.title=a),m.s("draggable")&&!F.handleDragAndDrop&&(r?(z.href="#",q(z,"text-decoration",v)):z.draggable="true"),z},$16h:function(V,f,X,Q){var t=W.initContext(V);W.translateAndScale(t,0,0,1),t.clearRect(0,0,X,X);var G=(X-Q)/2;d.drawStretchImage(t,d.getImage(f),"fill",0,G,Q,Q),t.restore()},$15h:function(h){var D=this,K=h.getId(),E=D._view.querySelector(".palette-toggle-icon-"+K),o=h.isExpanded()?d.paletteCollapseIcon:d.paletteExpandIcon;if(E&&o){var g=D.$19h(),J=D.$20h();D.$16h(E,o,g,J)}},_drawToolsIcon:function(b){var V=this,s=b.s("tools");if(s)for(var h=0;h<s.length;h++){var I=V._view.querySelector(".palette-header-tool"+b.getId()+"-"+h),N=s[h].icon,k=V.$19h(),q=V.$20h();V.$16h(I,N,k,q)}},$14h:function(C){var R=this,E=C.getId(),F=R.$10h[E].querySelector(".image-box"),S=C.getImage(),h=C.s("image.stretch");if(F&&S){var u=W.initContext(F),Y=R.getItemImagePadding();Y="smallicons"===R._layout?Y/2:Y;var H=R.getItemImageWidth()-2*Y,w=R.getItemImageHeight()-2*Y;W.translateAndScale(u,0,0,1),u.clearRect(0,0,H,w),d.drawStretchImage(u,d.getImage(S),h,Y,Y,H,w,C,R,R.getBodyColor(C)),u.restore()}},validateImpl:function(){var k,n,v,g=this,l=g.$9h,B=g._layout,j=g.$10h,b=g.$4h,J=g._view,p=g.dm();if(g.$13h&&(delete g.$13h,b={},p.each(function(Q){b[Q.getId()]=Q})),"smallicons"===B)for(var i in b){var r=b[i];if(r instanceof x){var Z=r.getName()||"",t=d.getTextSize(d.paletteContentLabelFont,Z).width;g.$21h!=S&&g.$21h>t||(g.$21h=t)}}for(var i in b){v=b[i];var W,u;if(p.contains(v)){if(v instanceof ht.Group){var h,o=g.$1h(v),c=j[v.getId()];c&&(h=c.nextSibling,R(J,h),R(J,c)),n=p.getSiblings(v).indexOf(v);var C=J.children[2*n]||g._79O;C&&C.parentNode?(J.insertBefore(o[0],C),J.insertBefore(h||o[1],C)):(J.appendChild(o[0]),J.appendChild(h||o[1])),j[v.getId()]=o[0],k=l[v.getId()]=h||o[1],u=v.$12h;var V=v.s("promptText");u||(v.$12h=Y("div"),v.$12h[K]=V||"",u=v.$12h),0===v.getChildren().size()?k.contains(u)||I(k,u):k.contains(u)&&R(k,u)}else if(W=v.getParent()){var T=g.$2h(v),a=j[v.getId()];k=l[W.getId()],a&&R(a.parentNode,a),n=p.getSiblings(v).indexOf(v);var w=k.children[n];w?k.insertBefore(T,w):I(k,T),j[v.getId()]=T,g.$14h(v)}}else{var P=j[v.getId()],D=P.parentNode;if(v instanceof ht.Group){var M=P.nextSibling;R(J,P),R(J,M),delete l[v.getId()]}else R(D,P),0===D.children.length&&(W=p.getDataById(D.$11h),W&&(u=W.$12h,u&&!D.contains(u)&&I(D,u)));delete j[v.getId()]}}g.$4h={};var e=function(){var z=g._59I,f=0;g.$32h!=S&&(clearInterval(g.$32h),f=0,delete g.$32h),g.$32h=setInterval(function(){g.$31h(),z===g._59I?(f++,f>=2&&(clearInterval(g.$32h),delete g.$32h)):(f=0,z=g._59I)},30)};for(var F in l)if(k=l[F],v=p.getDataById(l[F].$11h),g.$15h(v),g._drawToolsIcon(v),v.isExpanded()){if(k.style.maxHeight===0+s){var m=k.scrollHeight+g._itemMargin+s;E(k).duration(200).set(U,m).set("padding-bottom",g._itemMargin+s).end(function(){return function(){e()}}(m))}else k.style.maxHeight=k.scrollHeight+s;k.style.paddingBottom=g._itemMargin+s}else k.style.maxHeight!==0+s&&E(k).duration(200).set(U,N).set("padding-bottom",N).end(function(){return function(){e()}}(k));g.$28h(),g.$31h()},$31h:function(){for(var x=this,m=x._view,w=0,d=m.children,c=0;c<d.length;c++){var l=d[c];l.className&&l.className.indexOf("palette-")>=0&&(w+=l.offsetHeight)}x._59I=w,x.$30h=x.$33h(x.ty());var S=x.ty();m.scrollTop=-S,x._29I={x:0,y:-S,width:m.clientWidth,height:m.clientHeight},q(x._79O,Z,-S+s),x._93I()},$33h:function(p){var $=this,E=$._29I.height-$._59I;return E>p&&(p=E),p>0?0:Math.round(p)},redraw:function(){this.$13h||(this.$13h=1,this.iv())},onPropertyChanged:function(u){["autoHideScrollBar","scrollBarSize","scrollBarColor","translateY"].indexOf(u.property)<0&&this.redraw(),"translateY"===u.property&&(this.iv(),this._43o())},findDataByName:function(W){for(var V=this.dm().getDatas(),C=0;C<V.size();C++){var c=V.get(C);if(c.getName()===W)return c}},setDataModel:function(C){var b=this,o=b._dataModel,O=b._selectionModel;o!==C&&(o&&(o.umm(b.$6h,b),o.umd(b.$8h,b),o.umh(b.$7h,b),O||o.sm().ums(b.$28h,b)),b._dataModel=C,C.mm(b.$6h,b),C.md(b.$8h,b),C.mh(b.$7h,b),O?O._21I(C):C.sm().ms(b.$28h,b),b.sm().setSelectionMode("single"),b.fp("dataModel",o,C))},$6h:function(z){var k=this,r=k._view,W=z.data,s=k.$4h;"add"===z.kind?s[W.getId()]=W:"remove"===z.kind?s[W.getId()]=W:"clear"===z.kind&&(k.$10h={},k.$9h={},k.$4h={},r[K]=""),k.iv()},$7h:function(t){var l=this,H=t.data;l.$4h[H.getId()]=H,l.iv()},$8h:function(R){var S=this,Y=R.data,l=R.property;"expanded"===l?S.iv():(S.$4h[Y.getId()]=Y,S.iv())},$28h:function(){var y,$=this,j=$.sm(),c="palette-item",m=j.ld();this.dm().each(function(N){y=$.$10h[N.getId()],y&&y[g].indexOf(c)>=0&&(N===m?q(y,D,d.paletteItemSelectBackground):e(y,D))})}})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:(0,eval)("this"),Object);