跳转到主要内容

动态应用工具提示

项目描述

简介

使用 ftw.tooltip,您可以动态地将工具提示添加到每个DOM元素,这些元素可以通过jQuery选择,并允许使用title属性。

http://onegov.ch/approved.png/image

认证: 01/2013

安装

ftw.tooltip 添加到您的buildout配置中

[instance]
eggs =
  ftw.tooltip

导入 ftw.tooltip 默认配置文件。

用法

基本上,您需要注册命名的 ITooltipSource 适配器。它们将被视图查询,视图将生成必要的JS代码。

有两个示例工具提示源适配器,以展示它们的工作方式

  • 静态文本示例。

  • 动态文本示例,读取所选DOM元素的title属性。

您可以通过注册以下适配器在您的网站上加载这两个示例

>>> from ftw.tooltip.demo_tooltip_source import (DemoStaticTooltipSource,
...    DemoDynamicTooltipSource)
>>> from zope.component import provideAdapter
>>> provideAdapter(DemoStaticTooltipSource, name="demo1")
>>> provideAdapter(DemoDynamicTooltipSource, name="demo2")

或者如果您正在使用zcml

<adapter
    factory="ftw.tooltip.demo_tooltip_source.DemoStaticTooltipSource" name="demo1" />
<adapter
    factory="ftw.tooltip.demo_tooltip_source.DemoDynamicTooltipSource" name="demo2" />
  • “demo1”在 #portal-logo 上放置工具提示。

  • “demo2”在所有全局导航元素上放置工具提示,并显示给定的title属性作为工具提示。

示例

定义一个新的 ITooltipSource 适配器很容易。以下示例将只对文件夹类型显示工具提示“这是编辑栏”(检查global_condition),当然,只有当“documentEditable” CSS类可用时才会显示。

>>> from zope.component import adapts
>>> from zope.interface import implements, Interface
>>> from ftw.tooltip.interfaces import ITooltipSource
>>> from plone.app.layout.navigation.interfaces import INavigationRoot
>>> from Products.CMFCore.interfaces import IFolderish

>>> class EditBarTooltip(object):
...     """Base demo static tooltip source. Use a given text"""
...     implements(ITooltipSource)
...     adapts(Interface, Interface)
...
...     def __init__(self, context, request):
...         self.context = context
...         self.request = request
...
...     def global_condition(self):
...         return bool(IFolderish.providedBy(self.context))
...
...     def tooltips(self):
...         return [{
...             'selector': u'#edit-bar',
...             'text': u'This is the edit bar',
...             'condition': 'div.documentEditable'}]

使用ZCML注册适配器

>>> <adapter
...    factory="your.module.EditBarTooltip" name="my_edit_bar_tooltip" />

您可能想使用自己的工具提示布局:只需注册一个名为“ftw_tooltip_layout”的浏览器视图并返回您偏好的工具提示布局。

或者,您可以通过注册一个名为“ftw_tooltip_custom_config”的浏览器视图完全自定义工具提示参数 - 查看jQuerytools文档以获取更多详细信息。

小型定制示例

{
    offset: [-10, 10],
    position: 'right center',
    opacity: '0.7',
}

示例:使用现有HTML的工具提示

还可以使用一个HTML标签作为数据源(必须是选择器的兄弟元素),而不是使用title属性。在这种情况下,只需要进行小小的调整。

ITooltipSource适配器应将js-selector返回到content属性中,而不是text属性中。

>>> from zope.component import adapts
>>> from zope.interface import implements, Interface
>>> from ftw.tooltip.interfaces import ITooltipSource
>>> from plone.app.layout.navigation.interfaces import INavigationRoot
>>> from Products.CMFCore.interfaces import IFolderish

>>> class EditBarTooltip(object):
...     """Base demo static tooltip source. Use a given text"""
...     implements(ITooltipSource)
...     adapts(Interface, Interface)
...
...     def __init__(self, context, request):
...         self.context = context
...         self.request = request
...
...     def global_condition(self):
...         return bool(IFolderish.providedBy(self.context))
...
...     def tooltips(self):
...         return [{
...             'selector': u'#edit-bar',
...             'condition': 'div.documentEditable',
...             'content': u'.tabbedview-tooltip-data'}]

HTML结构中唯一需要关注的约束是,content标签必须是selector标签的兄弟元素。例如:

... <a href="/edit_bar" id="edit_bar"></a>
... <div class="tabbedview-tooltip-data">
...     <div class="tooltip-content">
...         <div class="tooltip-header">Tooltip Headeer</div>
...         <div class="tooltip-breadcrumb">Lorem ipsum ...</div>
...     </div>
... </div>

兼容性

在Plone 4.3上运行。

变更日志

2.0.0 (2020-02-06)

  • 放弃对Plone 4.2的支持。[busykoala]

  • 放弃对Plone 4.1的支持。[jone]

  • 添加卸载配置文件。[tinagerber]

1.1.4 (2014-03-27)

  • 不要内联渲染dynamic_tooltips.js。[mathias.leimgruber]

1.1.3 (2014-02-10)

  • 激活动态提示以重新定位它,使其始终可见。[elio.schmutz]

1.1.2 (2013-10-21)

  • 尚未有任何更改。

1.1.1 (2013-01-21)

  • 更改ajax调用初始化提示的行为。

  • onegov.ch批准:向readme添加徽章。[jone]

1.1 (2012-11-28)

  • 添加翻译。[jone]

  • 调整javascript:使用$代替已弃用的jq。[phgross]

  • 添加了允许使用HTML标签作为提示数据的函数。[phgross]

1.0.5 (2012-10-16)

  • 将内联javascript包装在

  • 修复页面模板文件结尾错误。[Julian Infanger]

1.0.4 (2012-06-14)

  • 转义提示。HTML不应渲染,而应显示。这可以防止JS注入。[jone]

1.0.3 (2012-05-09)

  • 使用新的测试buildout配置。[mathias.leimgruber]

  • 代码清理(pep8/pylint)[mathias.leimgruber]

1.0.2 (2012-04-23)

  • 默认将延迟设置为0。[mathias.leimgruber]

  • 触发鼠标悬停事件以激活提示,否则某些提示配置将无法正常工作(例如predelay)[mathias.leimgruber]

1.0.1 (2012-03-26)

  • 隐藏默认提示以从浏览器中删除。[mathias.leimgruber]

1.0 (2012-03-19)

  • 初始化发布 [mathias.leimgruber]

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页