匿名
未登录
创建账户
登录
小鱼君和他的朋友们
搜索
正在查找
将来过去时
的官方设定集?不如看看
万界大百科
吧!
《将来过去时》第一部分
现在 魔科纪元的少年少女
即将正式发布!
让我偷偷看一眼
小鱼君的博客
……
服务器已成功迁移到
阿里云(杭州)
!
查看“Help:Tooltips”的源代码
来自小鱼君和他的朋友们
名字空间
帮助
讨论
更多
更多
语言
变种
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
台灣正體
页面选项
Read
查看源代码
历史
←
Help:Tooltips
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
== Usage == To make the script show a tooltip when hovered over a specific element you have to add a special class to it. Some types of tooltips also support additional parameters specified via ''<code>data-</code>'' attributes (see section [[#Configuration|Configuration]] for more) There are three distinct types of tooltips: '''Basic tooltips – class: ''<code>basic-tooltip</code>''''' :This type of tooltip will only show the contents of ''<code>title</code>'' of this element. :<source lang="html5"><span class="basic-tooltip" title="Text to show inside tooltip">Basic tooltips</span></source> ::<span class="basic-tooltip" title="Text to show inside tooltip">Basic tooltips</span> '''Advanced tooltips – class: ''<code>advanced-tooltip</code>''''' :Contents of this tooltip are taken from inside the element with ''<code>tooltip-contents</code>'' class. Contents of the element are taken as rendered - this allow to use wiki markup and HTML elements to format tooltip. Remember that contents of these tooltips are loaded on page load. This can drastically slow down page load times with big amounts of tooltips (including repeated uses of the same one). :<source lang="html5"><div style="display:inline-block" class="advanced-tooltip">Advanced tooltips<div class="tooltip-contents">Tooltip content<br/><code>Including HTML tags</code></div></div></source> ::<div style="display:inline-block" class="advanced-tooltip">Advanced tooltips<div class="tooltip-contents">Tooltip content<br/><code>Including HTML tags</code></div></div> '''Custom tooltips – class: ''your own''''' :This type allows the most control over contents of the tooltip with reduced page load times. You can use templates to generate tooltips and pass parameters to the template through ''<code>data-</code>'' attributes of the element you hover over. Its advantage over advanced tooltips is that the content of the tooltip is loaded when needed, and the same tooltip for multiple elements (same parameters) will be loaded once. :<source lang="html5"><span class="custom-tooltip-text" data-parameter="Some value">Custom tooltips – text</span></source> ::<span class="custom-tooltip-text" data-parameter="Some value">Custom tooltips – text</span> :<source lang="html5"><span class="custom-tooltip-parse" data-parameter="Some value">Custom tooltips – parse</span></source> ::<span class="custom-tooltip-parse" data-parameter="Some value">Custom tooltips – parse</span> === Combining === Different types of tooltips can be combined to display them simultaneously. Order of tooltips is same as the order of classes. :<source lang="html5"><div style="display:inline-block" class="basic-tooltip advanced-tooltip custom-tooltip-text custom-tooltip-parse" data-parameter="Parameter">Combined tooltips<div class="tooltip-contents">Advanced tooltip</div></div></source> ::<div style="display:inline-block" class="basic-tooltip advanced-tooltip custom-tooltip-text custom-tooltip-parse" title="Basic tooltip" data-parameter="Parameter">Combined tooltips<div class="tooltip-contents">Advanced tooltip</div></div> == Configuration == Without any setup, script will only support basic and advanced tooltips. There are 3 variables that contain config for the script. You can specify them in '''MediaWiki:Common.js''' on your wiki. === Main config – ''<code>tooltips_config</code>'' === Here you can adjust some core features using this object: * '''offsetX''' and '''offsetY''': These are values that the tooltip will be moved right and down (respectively) from where the cursor is pointing (remember that margin of tooltip itself can move it further). Default value is '''8''' for both and values below 5 are not recommended. * '''waitForImages''': It will alter how tooltips behave when they have images inside. By default (''<code>false</code>'') tooltips will show up even if images aren't fully loaded yet. Images will eventually show up when they are loaded (lazy loading). Setting this value to ''<code>true</code>'' will make the script wait for all images to be fully loaded before showing the tooltip. * '''events''': Is a list of JavaScript events of the window object that will trigger the search for tooltips that weren't present when script was initialized. This way you can make tooltips work in custom interface element that are added after the page is loaded and tooltips initialized. For example in a custom right rail module. * '''noCSS''': If you want to disable import of default CSS, set it to true Example of the config object: <source lang="javascript">var tooltips_config = { offsetX: 5, offsetY: 10, waitForImages: true, events: ['CustomEvent'], noCSS: true, }</source> === Creating custom tooltip types – ''<code>tooltips_list</code>'' === You can add your own tooltips to this array. Every type of tooltip is an object with these properties: * '''classname''': CSS class that will trigger the tooltip of this type. This property is required. * '''text''': This ''string'' or ''function'' will be used as content of the tooltip. * '''parse''': Similar to '''text''' but the resulting text will be [[mw:API:Parse|parsed]], allowing the use of wiki syntax, at the cost of a short delay. * '''onParsed''': This ''function'' will be executed when the parsed has been fetched (with the tooltip being its context - ''<code>this</code>'') Both '''text''' and '''parse''' can be either a ''string'' or a ''function''. If the value is a ''string'', you can use parameters that will be taken from the element the cursor is pointing at. To use a parameter, you need to add this in the text: <code><#parameter-name#></code>. This ''tag'' will be replaced with value of the <code>data-parameter-name</code> attribute of the element. You can use multiple parameters, and one parameter multiple times. <pre>{{Template|<#value#>}} // <#value#> will be replaced with content of data-value attribute</pre> Other way is to specify a ''function'' that will be executed whenever a new element without the tooltip is hovered-over. This function has that element as its context and should '''''return''''' contents of the tooltip (or wikitext to parse). Returned string doesn't support parameters like above since you can access any attributes yourself (ex: <code>$(this).data('parameter-name')</code>) Example of a object with settings for one type of tooltip <source lang="javascript"> { classname: 'custom-tooltip', parse: '{'+'{Tooltip|<#name#>|<#value#>}}', // '+' makes MediaWiki ignore the template on the page with settings delay: 500, }</source> ==== Common properties ==== These properties can be used for all types, including the built in ones (''<code>basic-tooltip</code>'' and ''<code>advanced-tooltip</code>'') * '''delay''': Just like the name says. It'll make the tooltip appear after the specified delay in milliseconds. '''Tip:''' 1 second = 1000 milliseconds. * '''onShow''' and '''onHide''': Are pseudo-events that will be triggered (respectively) right after the tooltip is shown and right before it'll be hidden. These are callback functions with the tooltip itself being their context (''<code>this</code>'') and the hover handle that triggered the tooltip as an argument. Example of settings for two custom tooltips and modifying behavior of basic tooltips: <source lang="javascript">var tooltips_list = [ { classname: 'custom-tooltip-text', text: "Parameter: <#parameter#><br/>This is just text and HTML - wikitext '''won't''' be parsed", }, { classname: 'custom-tooltip-parse', parse: '{|style="white-space:nowrap;"\n!Parameter:\n|<#parameter#>\n|-\n!Lc:\n|{'+'{lc:<#parameter#>}}\n|-\n!Uc:\n|{'+'{uc:<#parameter#>}}\n|-\n!PAGENAME:\n|{'+'{PAGENAME}}\n|}', }, { classname: 'basic-tooltip', delay: 500, onHide: function(handle) { $(this).html($(handle).html()) }, }, ]</source> === Debug mode – ''<code>tooltips_debug</code>'' === Setting it to ''<code>true</code>'' will make some elements visible making it easier to spot problems. Debug mode can also be turned on temporarily by adding <code>?ttdebug=true</code> at the end of the URL. Like so: http://dev.wikia.com/wiki/Tooltips?ttdebug=true == Other notes and tips == * Additional classes to tooltips: ** <code>has-redlinks</code>: given to tooltips that (as the name says) have redlinks inside – this can be used to hide tooltips with missing templates. ** <code>tooltip-loading</code>: given to tooltips that are still waiting for parsed contents to load – you can use it to show loading indicator or just hide the tooltip until it's ready. ** <code>tt-<span style="color:#999">''tooltip-type''</span></code>: every tooltip recives class based on its type (ex: <code>tt-basic-tooltip</code>) – great for having different looking tooltip types. * If your tooltips has shadow you might want to make space for it by adding margin to them or by adding padding to the div that contains active tooltips (<code>#tooltip-wrapper</code>).
返回至
Help:Tooltips
。
导航
欢迎光临
主页
召唤SILI(求助)
讨论版
关于
关于本站
联系我们
分类导览
创建词条
万界规划局雇员
角色一览
规划局书库
游戏中心
随机页面
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志
其他项目
变种
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
台灣正體