/// <summary> returns tooltipcontainer and tooltip</summary> private Tuple <HTMLElement, HTMLElement> GetOrCreateTooltipOn(HTMLElement tooltipOn, string content, TooltipMode mode) { if (_tooltips.ContainsKey(tooltipOn)) { var oldTt = _tooltips.Get(tooltipOn).Item1; oldTt.TextContent = content; return(Tuple.Create(oldTt.ParentElement, oldTt)); } //tooltips need to be in container so that relative positioning works in both: //inline scenario: <label><input><tooltip> and in //'display:table' scenario those three have "display: table-cell" var ttCont = Document.CreateElement("span"); ttCont.ClassName = Magics.CssClassTooltipContainer; var tt = Document.CreateElement("span"); tt.Id = UniqueIdGenerator.GenerateAsString(); tt.TextContent = content; tt.ClassName = Magics.CssClassTooltip; tt.ClassList.Add(Magics.CssClassDisabled); ttCont.AppendChild(tt); Logger.Debug(GetType(), "created tooltip to show it {0}", tt.Id); _tooltips[tooltipOn] = Tuple.Create(tt, mode); return(Tuple.Create(ttCont, tt)); }
private void ShowTooltipOn(HTMLElement tooltipOn, TooltipMode mode, bool forceFullCycle = false) { var content = GetTooltipsOfElementOrNull(tooltipOn, mode); Logger.Debug(GetType(), "ShowTooltipOn starting forceFullCycle={0} mode={1}", forceFullCycle, mode); if (content == null) { Logger.Debug(GetType(), "tooltip show ignored as it would be empty"); return; } var contAndTt = GetOrCreateTooltipOn(tooltipOn, content, mode); var cont = contAndTt.Item1; var tt = contAndTt.Item2; Logger.Debug(GetType(), "ShowTooltipOn gotOrCreated id={0}", tt.Id); //tooltipOn.ParentElement.Style.Position = Position.Relative; tooltipOn.Style.Position = Position.Relative; if (!tooltipOn.HasAttribute(Magics.AttrDataMayBeTooltipContainer)) { if (tooltipOn.ParentElement != null) { tooltipOn.ParentElement.InsertAfter(cont, tooltipOn); } } else { tooltipOn.AppendChild(cont); } var ops = new List <TooltipOper>(); _pendingTooltipOps[tt] = ops; _tooltips.Set(tt, Tuple.Create(tt, mode)); if (forceFullCycle) { tt.ClassList.Remove(Magics.CssClassActive); tt.ClassList.Remove(Magics.CssClassInactive); tt.ClassList.Add(Magics.CssClassDisabled); } switch (GetTooltipState(tt)) { case TooltipState.EnabledShown: break; //already in the right state case TooltipState.Disabled: ops.AddRange( Immediate(Magics.CssClassDisabled, Magics.CssClassInactive), Lasting(Magics.CssClassInactive, Magics.CssClassActive, Magics.TooltipFadeInMs)); break; case TooltipState.EnabledHidden: //interrupted showning or hiding ops.Add(Lasting(Magics.CssClassInactive, Magics.CssClassActive, Magics.TooltipFadeInMs)); break; default: throw new ArgumentException("ShowTooltipOn unknown state"); } //autohide? if (mode == TooltipMode.PeekIntoErrors) { ops.AddRange( Lasting(Magics.CssClassActive, Magics.CssClassInactive, Magics.TooltipFadeOutMs), Immediate(Magics.CssClassInactive, Magics.CssClassDisabled)); } Logger.Debug(GetType(), "ShowTooltipOn scheduled {0} opers", ops.Count); ScheduleNextOperation(tt); }