{"version":3,"file":"tooltip.bundle.js","sources":["../src/tooltip.js","../src/balloon.js","../src/index.js"],"sourcesContent":["export class Tooltip\n{\n\tstatic disabled = false;\n\tstatic tooltipsList = {};\n\n\tstatic disable()\n\t{\n\t\tthis.disabled = true;\n\t}\n\n\tstatic enable()\n\t{\n\t\tthis.disabled = false;\n\t}\n\n\tstatic getDisabledStatus()\n\t{\n\t\treturn this.disabled;\n\t}\n\n\tstatic getLoader()\n\t{\n\t\treturn '/bitrix/tools/tooltip.php';\n\t}\n\n\tstatic getIdPrefix()\n\t{\n\t\treturn 'bx-ui-tooltip-';\n\t}\n}\n","import {Type, ajax, Loc} from 'main.core';\nimport {BaseEvent, EventEmitter} from 'main.core.events';\n\nimport {Tooltip} from './tooltip';\n\n\nexport class TooltipBalloon\n{\n\tconstructor(params)\n\t{\n\t\tthis.node = null;\n\t\tthis.userId = null;\n\t\tthis.loader = null;\n\t\tthis.version = null;\n\t\tthis.tracking = false;\n\t\tthis.active = false;\n\t\tthis.width = 364; // 393\n\t\tthis.height = 215; // 302\n\t\tthis.realAnchor = null;\n\t\tthis.coordsLeft = 0;\n\t\tthis.coordsTop = 0;\n\t\tthis.anchorRight = 0;\n\t\tthis.anchorTop = 0;\n\t\tthis.hMirror = false;\n\t\tthis.vMirror = false;\n\t\tthis.rootClassName = '';\n\t\tthis.INFO = null;\n\t\tthis.DIV = null;\n\t\tthis.ROOT_DIV = null;\n\t\tthis.params = {};\n\t\tthis.trackMouseHandle = this.trackMouse.bind(this);\n\n\t\tthis.init(params);\n\t\tthis.create();\n\t\treturn this;\n\t}\n\n\tinit(params)\n\t{\n\t\tthis.node = params.node;\n\t\tthis.userId = params.userId;\n\t\tthis.loader = (Type.isStringFilled(params.loader) ? params.loader : '');\n\n\t\tthis.version = (\n\t\t\t!Type.isUndefined(params.version)\n\t\t\t&& parseInt(params.version) > 0\n\t\t\t\t? parseInt(params.version)\n\t\t\t\t: (Type.isStringFilled(this.loader) ? 2 : 3)\n\t\t);\n\n\t\tthis.rootClassName = this.node.getAttribute('bx-tooltip-classname');\n\n\t\tconst paramsString = this.node.getAttribute('bx-tooltip-params');\n\n\t\tlet anchorParams = {};\n\t\tif (Type.isStringFilled(paramsString))\n\t\t{\n\t\t\tanchorParams = JSON.parse(paramsString);\n\t\t\tif (!Type.isPlainObject(anchorParams))\n\t\t\t{\n\t\t\t\tanchorParams = {};\n\t\t\t}\n\t\t}\n\n\t\tthis.params = anchorParams;\n\t}\n\n\tcreate()\n\t{\n\t\tif (!Tooltip.getDisabledStatus())\n\t\t{\n\t\t\tthis.startTrackMouse();\n\t\t}\n\n\t\tthis.node.addEventListener('mouseout', this.stopTrackMouse.bind(this));\n\t\tEventEmitter.subscribe('SidePanel.Slider:onOpen', this.onSliderOpen.bind(this));\n\t}\n\n\tonSliderOpen()\n\t{\n\t\tif (this.tracking)\n\t\t{\n\t\t\tthis.stopTrackMouse();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthis.hideTooltip();\n\t\t}\n\t}\n\n\tstartTrackMouse()\n\t{\n\t\tif (this.tracking)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\tconst elCoords = BX.pos(this.node);\n\t\tthis.realAnchor = this.node;\n\n\t\tthis.coordsLeft = (\n\t\t\telCoords.width < 40\n\t\t\t\t? (elCoords.left - 35)\n\t\t\t\t: (elCoords.left + 0)\n\t\t);\n\t\tthis.coordsTop = elCoords.top - 245; // 325\n\t\tthis.anchorRight = elCoords.right;\n\t\tthis.anchorTop = elCoords.top;\n\n\t\tthis.tracking = true;\n\n\t\tdocument.addEventListener('mousemove', this.trackMouseHandle);\n\n\t\tsetTimeout(() => {\n\t\t\tthis.tickTimer();\n\t\t}, 500);\n\n\t\tthis.node.addEventListener('mouseout', this.stopTrackMouse.bind(this));\n\t}\n\n\tstopTrackMouse()\n\t{\n\t\tif (!this.tracking)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tdocument.removeEventListener('mousemove', this.trackMouseHandle);\n\n\t\tthis.active = false;\n\t\tsetTimeout(() => {\n\t\t\tthis.hideTooltip()\n\t\t}, 500);\n\t\tthis.tracking = false;\n\t}\n\n\ttrackMouse(e)\n\t{\n\t\tif (!this.tracking)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\tconst current = (\n\t\t\te && e.pageX\n\t\t\t\t? {\n\t\t\t\t\tx: e.pageX,\n\t\t\t\t\ty: e.pageY,\n\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\tx: e.clientX + document.body.scrollLeft,\n\t\t\t\t\ty: e.clientY + document.body.scrollTop,\n\t\t\t\t}\n\t\t);\n\n\t\tif (current.x < 0)\n\t\t{\n\t\t\tcurrent.x = 0;\n\t\t}\n\n\t\tif (current.y < 0)\n\t\t{\n\t\t\tcurrent.y = 0;\n\t\t}\n\n\t\tcurrent.time = this.tracking;\n\n\t\tif (!this.active)\n\t\t{\n\t\t\tthis.active = current;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (\n\t\t\t\tthis.active.x >= (current.x - 1) && this.active.x <= (current.x + 1)\n\t\t\t\t&& this.active.y >= (current.y - 1) && this.active.y <= (current.y + 1)\n\t\t\t)\n\t\t\t{\n\t\t\t\tif ((this.active.time + 20/*2sec*/) <= current.time)\n\t\t\t\t{\n\t\t\t\t\tthis.showTooltip();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthis.active = current;\n\t\t\t}\n\t\t}\n\t}\n\n\ttickTimer()\n\t{\n\t\tif (!this.tracking)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\tthis.tracking++;\n\t\tif (this.active)\n\t\t{\n\t\t\tif ((this.active.time + 5/*0.5sec*/) <= this.tracking)\n\t\t\t{\n\t\t\t\tthis.showTooltip();\n\t\t\t}\n\t\t}\n\n\t\tsetTimeout(() => {\n\t\t\tthis.tickTimer();\n\t\t}, 100);\n\t}\n\n\thideTooltip()\n\t{\n\t\tif (this.tracking)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\tthis.showOpacityEffect(1);\n\t}\n\n\tshowOpacityEffect(bFade)\n\t{\n\t\tconst steps = 3;\n\t\tconst period = 1;\n\t\tconst delta = 1 / steps;\n\t\tlet i = 0;\n\n\t\tconst intId = setInterval(() => {\n\t\t\ti++;\n\t\t\tif (i > steps)\n\t\t\t{\n\t\t\t\tclearInterval(intId);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst op = (\n\t\t\t\tbFade\n\t\t\t\t\t? 1 - i * delta\n\t\t\t\t\t: i * delta\n\t\t\t);\n\n\t\t\tif (this.DIV != null)\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tthis.DIV.style.opacity = op;\n\t\t\t\t}\n\t\t\t\tcatch(e)\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\tfinally\n\t\t\t\t{\n\t\t\t\t\tif (\n\t\t\t\t\t\t!bFade\n\t\t\t\t\t\t&& i == 1\n\t\t\t\t\t)\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.DIV.classList.add('ui-tooltip-info-shadow-show');\n\t\t\t\t\t\tthis.DIV.style.display = 'block';\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tbFade\n\t\t\t\t\t\t&& i == steps\n\t\t\t\t\t\t&& this.DIV\n\t\t\t\t\t)\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.DIV.classList.remove('ui-tooltip-info-shadow-show');\n\t\t\t\t\t\tthis.DIV.classList.add('ui-tooltip-info-shadow-hide');\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tthis.DIV.style.display = 'none';\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (bFade)\n\t\t\t\t\t{\n\t\t\t\t\t\tEventEmitter.emit('onTooltipHide', new BaseEvent({\n\t\t\t\t\t\t\tcompatData: [ this ],\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, period);\n\t}\n\n\tshowTooltip()\n\t{\n\t\tconst old = document.getElementById(`${Tooltip.getIdPrefix()}${this.userId}`);\n\n\t\tif (\n\t\t\tTooltip.getDisabledStatus()\n\t\t\t|| (\n\t\t\t\told\n\t\t\t\t&& old.classList.contains('ui-tooltip-info-shadow-show')\n\t\t\t)\n\t\t)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tnull == this.DIV\n\t\t\t&& null == this.ROOT_DIV\n\t\t)\n\t\t{\n\t\t\tthis.ROOT_DIV = document.body.appendChild(document.createElement('DIV'));\n\t\t\tthis.ROOT_DIV.style.position = 'absolute';\n\n\t\t\tBX.ZIndexManager.register(this.ROOT_DIV);\n\n\t\t\tthis.DIV = this.ROOT_DIV.appendChild(document.createElement('DIV'));\n\t\t\tthis.DIV.className = 'bx-ui-tooltip-info-shadow';\n\n\t\t\tthis.DIV.style.width = `${this.width}px`;\n\t\t}\n\n\t\tlet left = this.coordsLeft;\n\t\tconst top = this.coordsTop + 30;\n\t\tconst arScroll = BX.GetWindowScrollPos();\n\t\tconst body = document.body;\n\n\t\tthis.hMirror = false;\n\t\tthis.vMirror = ((top - arScroll.scrollTop - 50) < 0);\n\n\t\tif ((body.clientWidth + arScroll.scrollLeft) < (left + this.width))\n\t\t{\n\t\t\tleft = this.anchorRight - this.width;\n\t\t\tthis.hMirror = true;\n\t\t}\n\n\t\tthis.ROOT_DIV.style.left = `${parseInt(left)}px`;\n\t\tthis.ROOT_DIV.style.top = `${parseInt(top)}px`;\n\n\t\tBX.ZIndexManager.bringToFront(this.ROOT_DIV);\n\n\t\tthis.ROOT_DIV.addEventListener('click', (e) => { e.stopPropagation(); });\n\n\t\tif (Type.isStringFilled(this.rootClassName))\n\t\t{\n\t\t\tthis.ROOT_DIV.className = this.rootClassName;\n\t\t}\n\n\t\tconst loader = (\n\t\t\tType.isStringFilled(this.loader)\n\t\t\t\t? this.loader\n\t\t\t\t: Tooltip.getLoader()\n\t\t);\n\n\t\t// create stub\n\t\tlet stubCreated = false;\n\n\t\tif ('' == this.DIV.innerHTML)\n\t\t{\n\t\t\tstubCreated = true;\n\n\t\t\tif (this.version >= 3)\n\t\t\t{\n\t\t\t\tajax.runComponentAction('bitrix:ui.tooltip', 'getData', {\n\t\t\t\t\tmode: 'ajax',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tuserId: this.userId,\n\t\t\t\t\t\tparams: (!Type.isUndefined(this.params) ? this.params : {}),\n\t\t\t\t\t}\n\t\t\t\t}).then((response) => {\n\n\t\t\t\t\tconst detailUrl = (Type.isStringFilled(response.data.user.detailUrl) ? response.data.user.detailUrl : '');\n\t\t\t\t\tlet cardUserName = '';\n\n\t\t\t\t\tif (Type.isStringFilled(response.data.user.nameFormatted))\n\t\t\t\t\t{\n\t\t\t\t\t\tconst {nameFormatted = ''} = response.data.user;\n\n\t\t\t\t\t\tif (Type.isStringFilled(detailUrl))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcardUserName = `\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t${response.data.user.nameFormatted}\n\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcardUserName = `\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tresponse.data.user.nameFormatted\n\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlet cardFields = '