UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 4.92 kB
import domEvtHandler from'../../dom-event';import{hasTouch,isIE9}from'../../lib';export default function(a){var b,c,d,e,f=window,g=f.document,h=/msie/i.test(f.navigator.userAgent)&&!f.opera,j='VML'===a.type,k={cursor:'cursor'},l={x:'left',y:'top',strokeWidth:'borderThickness',"stroke-width":'borderThickness',width:'width',height:'height'},m={fill:'backgroundColor',stroke:'borderColor',color:'color'},i={left:0,top:0,padding:0,border:'none',margin:0,outline:'none',"-webkit-apperance":'none',position:'absolute',zIndex:20},n=function(a){return a&&a.replace(/^#?([a-f0-9]+)/ig,'#$1')||'none'},o=function(a,b,c,d){var e,f=g.createElement(a);for(e in b)l[e]?f.style[e]=b[e]:f.setAttribute(e,b[e]);for(e in c)f.style[e]=c[e];return d&&d.appendChild&&d.appendChild(f),f},p=function(a){d||(d=o('div')),a&&d.appendChild(a),d.innerHTML=''},q=function(a,c,d){var e,f;if('string'==typeof c)d!==b&&null!==d?a.setAttribute(c,d):a&&a.getAttribute&&(f=a.getAttribute(c));else if(c!==b&&null!==c&&'object'==typeof c)for(e in c)a.setAttribute(e,c[e]);return f};e=function(a,b,c){var d=this;b&&b instanceof e&&(b=b.element),d.element=o(a,c,i,b),d.nodeName=a.toLowerCase(),d.added=!!b,d.attrs={}},c=e.prototype={attr:function(a){var c,d,e,f,o,p,r,s,t,u,v=this,w=v.element,x={};if('object'!=typeof a)return v[a]===b?q(w,a):v[a];for(c in a){if(e=a[c],k[c])'cursor'===c?'pointer'===e&&j&&(e='hand'):void 0,w.style[k[c]]=e,f=!0;else if(l[c])w.style[l[c]]=e+'px',f=!0;else if(m[c])w.style[m[c]]=n(e),f=!0;else if(/^visibility$/i.test(c))o='hidden'===e,w.style.display=o?'none':'',v.hidden=o,f=!0;else if(/^opacity$/i.test(c))w.style.opacity=e,h&&(d=100*+e,w.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity='+d+')'),f=!0;else if(/^innerhtml$/i.test(c)){if(j&&'select'==w.nodeName.toLowerCase()){for(p=e.match(/<option\s?[\s\S]*?(\/>|><\/option>|>[\s\S]*?<\/option>)/ig);w.firstChild;)w.removeChild(w.firstChild);for(s=0,t=p.length;s<t;s+=1)r=p[s],u=g.createElement('option'),/<option\s([\s\S]*[\'\"])\s*?(\/>|>[\s\S]*<\/option>)/ig.test(r)&&(u.value=r.replace(/<option\s([\s\S]*[\'\"])\s*?(\/>|>[\s\S]*<\/option>)/ig,'$1').replace(/[\s\S]*value\s*\=\s*[\'\"]([\s\S]*)[\'\"]/,'$1')),u.text=r.replace(/<option\s*[\s\S]*[\'\"]?\s*?[\/>|\>]([\s\S]*)<\/option>/ig,'$1 '),w.options.add(u)}else'input'!==w.nodeName.toLowerCase()&&e!==b&&(w.innerHTML=e||'');f=!0}else /^text$/i.test(c)?('input'!==w.nodeName.toLowerCase()&&(w.innerHTML='',e!==b&&w.appendChild(g.createTextNode(e))),f=!0):/^type$/i.test(c)&&h&&v.added&&(f=!0);f&&(x[c]=e,delete a[c],f=!1)}for(c in a)w.setAttribute(c,a[c]);for(c in x)v[c]=v.attrs[c]=a[c]=x[c],delete x[c];return this},val:function(a){var c=this,d=c.element,e=a===b;if('input'===c.nodeName&&'checkbox'===d.getAttribute('type'))return e?c.checked()?1:0:c.checked(a);if('select'===c.nodeName){let b=d.childNodes,f=d.selectedIndex,g=b.length;if(''===a)return;if(!e)for(let c=0;c<g;c++)if(b[c].value===a)return d.selectedIndex=c,b[c].value;return isIE9&&(f=0),e?b[f].value:(b[g-1].value=a,d.selectedIndex=g-1,c)}return e?d.value:(d.value=a,c)},checked:function(a){var c=this,d=c.element;return a===b?d.checked:(a?d.setAttribute('checked','checked'):d.removeAttribute('checked'),c)},css:function(a,c){var d,e=this,f=e.element,g=f.style;if('object'==typeof a)for(d in a)g[d]=a[d];else d&&c!==b&&(g[d]=c);return e},translate:function(a,c){var d=this,e=d.element;return a!==b&&(e.style.left=a+'px'),c!==b&&(e.style.top=c+'px'),d},add:function(a,b){var c=this,d=this.element,e=a.element;return b?e.insertBefore(d,e.firstChild):e.appendChild(d),c.added=!0,c},hide:function(){return this.element.style.display='none',this},show:function(){return this.element.style.display='',this},isVisible:function(){return'none'!==this.element.style.display},focus:function(){'function'==typeof this.element.focus?this.element.focus():domEvtHandler.fire(this.element,'focus')},destroy:function(){var b,c=this,d=c.element||{};for(b in d.onclick=d.onmouseout=d.onmouseover=d.onmousemove=d.onblur=d.onfocus=null,d=p(d),delete c.element,c)c[b]='function'==typeof c[b]?a._removedFactory(b):null;return c.removed=!0,null},on:j?function(a,b){var c=this;return c.element['on'+a]=function(){var a=f.event;a.target=a.srcElement,b(a)},c}:function(a,b){var c=b,d=this;return hasTouch&&'click'===a&&(a='touchstart',c=function(a){a.preventDefault(),b()}),d.element['on'+a]=c,d},bind:function(a,b,c){return domEvtHandler.listen(this.element,a,b,c),this},unbind:function(a,b){return domEvtHandler.unlisten(this.element,a,b),this},trigger:function(a,b){return domEvtHandler.fire(this.element,a,b),this}},c.remove=c.destroy,c.constructor=e,a.fn.html=function(b,c,d,f){var g,h,i={};for(h in c&&'type'in c&&(i.type=c.type,delete c.type),g=new e(b,f,i).css(d).attr(c),i)c[h]=i[h];return g.ca=function(){return!1},g.appendTo=function(a){this.parent=a,a&&a instanceof e&&(a=a.element),a.appendChild(this.element)},g.animateWith=a.el.animateWith,g}}