提交 e281f11f 编写于 作者: C Catouse

+ added popover.

上级 e4ff46c5
此差异已折叠。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="ZUI,一个简单吸引人的前端框架。">
<meta name="author" content="Zentao">
<title>ZUI</title>
<link href="../dist/css/zui.css" rel="stylesheet">
<link href="../assets/css/doc.css" rel="stylesheet">
<script src="../assets/js/jquery.js"></script>
<script src="../src/js/tooltip.js"></script>
<script src="../src/js/popover.js"></script>
<script src="../assets/js/google-code-prettify/prettify.js"></script>
<script>
$(function ()
{
prettyPrint();
$("[data-toggle=popover]")
.popover();
});
</script>
<style>
.popover-examples .popover
{
position: relative;
display: block;
float: left;
width: 260px;
margin: 20px;
}
</style>
</head>
<body>
<article>
<section class="page-section">
<h1>Popover</h1>
<div class="alert alert-danger">
<h4>插件依赖</h4>
<p>弹出框依赖<a href="#tooltips">工具提示插件</a>,因此需要先加载工具提示插件。</p>
</div>
<div class="alert alert-danger">
<h4>选择性加入的功能</h4>
<p>出于性能方面的考虑,工具提示和弹框组件的data属性api是选择性加入的,也就是说<strong>你必须自己初始化他们</strong></p>
</div>
<div class="alert alert-info">
<h4>弹出框在按钮组和输入框组中使用时,需要额外的设置</h4>
<p>当提示框与<code>.btn-group</code><code>.input-group</code>联合使用时,你需要指定<code>container: 'body'</code>选项(见下面的文档)以避免不需要的副作用(例如,当弹出框显示之后,与其合作的页面元素可能变得更宽或是去圆角)。</p>
</div>
<div class="alert alert-info">
<h4>在禁止使用的页面元素上使用弹出框时需要额外增加一个元素将其包裹起来</h4>
<p>为了给<code>disabled</code><code>.disabled</code>元素添加弹出框时,将需要增加弹出框的页面元素包裹在一个<code>&lt;div&gt;</code>中,然后对这个<code>&lt;div&gt;</code>元素应用弹出框。 </p>
</div>
<h2>类型</h2>
<h3>静态类型</h3>
<div class="segment popover-examples">
<div class="popover top">
<div class="arrow"></div>
<h3 class="popover-title">Popover top</h3>
<div class="popover-content">
<p>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
<div class="popover right">
<div class="arrow"></div>
<h3 class="popover-title">Popover right</h3>
<div class="popover-content">
<p>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
<div class="popover bottom">
<div class="arrow"></div>
<h3 class="popover-title">Popover bottom</h3>
<div class="popover-content">
<p>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
<div class="popover left">
<div class="arrow"></div>
<h3 class="popover-title">Popover left</h3>
<div class="popover-content">
<p>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
<div class="clearfix"></div>
</div>
<h3>不带箭头指示</h3>
<div class="segment popover-examples">
<div class="popover top">
<div class="arrow"></div>
<h3 class="popover-title">Popover top</h3>
<div class="popover-content">
<p>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
</div>
<h3>动态演示</h3>
<div class="segment">
<a href="#" class="btn btn-lg btn-danger" data-toggle="popover" title="" data-content="And here's some amazing content. It's very engaging. right?" data-original-title="A Title">Click to toggle popover</a>
</div>
<h4>不同方向</h4>
<div class="segment text-center">
<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="left" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">
左侧弹框
</button>
<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="top" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">
上方弹框
</button>
<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">
下方弹框
</button>
<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="right" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." data-original-title="" title="">
右侧弹框
</button>
</div>
<h2 id="popovers-usage">用法</h2>
<p>通过JavaScript启用弹出框:</p>
<div class="segment">
<p><code>js$(&#39;#example&#39;).popover(options)</code></p>
</div>
<h3>选项</h3>
<p>可以将选项通过data属性或JavaScript传递。对于data属性,需要将选项名称放到<code>data-</code>之后,例如<code>data-animation=""</code></p>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 100px;">名称</th>
<th style="width: 100px;">类型</th>
<th style="width: 50px;">默认值</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>animation</td>
<td>boolean</td>
<td>true</td>
<td>apply a CSS fade transition to the tooltip</td>
</tr>
<tr>
<td>html</td>
<td>boolean</td>
<td>false</td>
<td>Insert HTML into the popover. If false, jQuery's <code>text</code> method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.</td>
</tr>
<tr>
<td>placement</td>
<td>string | function</td>
<td>'right'</td>
<td>how to position the popover - top | bottom | left | right | auto.<br> When "auto" is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.</td>
</tr>
<tr>
<td>selector</td>
<td>string</td>
<td>false</td>
<td>if a selector is provided, tooltip objects will be delegated to the specified targets. in practice, this is used to enable dynamic HTML content to have popovers added. See <a href="https://github.com/twbs/bootstrap/issues/4215">this</a> and <a href="http://jsfiddle.net/fScua/">an informative example</a>.</td>
</tr>
<tr>
<td>trigger</td>
<td>string</td>
<td>'click'</td>
<td>how popover is triggered - click | hover | focus | manual</td>
</tr>
<tr>
<td>title</td>
<td>string | function</td>
<td>''</td>
<td>default title value if <code>title</code> attribute isn't present</td>
</tr>
<tr>
<td>content</td>
<td>string | function</td>
<td>''</td>
<td>default content value if <code>data-content</code> attribute isn't present</td>
</tr>
<tr>
<td>delay</td>
<td>number | object</td>
<td>0</td>
<td>
<p>delay showing and hiding the popover (ms) - does not apply to manual trigger type</p>
<p>If a number is supplied, delay is applied to both hide/show</p>
<p>Object structure is: <code>delay: { show: 500, hide: 100 }</code></p>
</td>
</tr>
<tr>
<td>container</td>
<td>string | false</td>
<td>false</td>
<td>
<p>Appends the popover to a specific element. Example: <code>container: 'body'</code>. This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.</p>
</td>
</tr>
</tbody>
</table>
</div><!-- /.table-responsive -->
<div class="bs-callout bs-callout-info">
<h4>为单个弹出框应用data属性</h4>
<p>对单个弹出框可以通过data属性单独指定选项,如上所示。</p>
</div>
<h3>方法</h3>
<h4>$().popover(options)</h4>
<p>为一组元素初始化弹出框。</p>
<h4>.popover('show')</h4>
<p>显示弹出框。</p>
<div class="segment">
<p><code>js$(&#39;#element&#39;).popover(&#39;show&#39;)</code></p>
</div>
<h4>.popover('hide')</h4>
<p>隐藏弹出框。</p>
<div class="segment">
<p><code>js$(&#39;#element&#39;).popover(&#39;hide&#39;)</code></p>
</div>
<h4>.popover('toggle')</h4>
<p>展示或隐藏弹出框。</p>
<div class="segment">
<p><code>js$(&#39;#element&#39;).popover(&#39;toggle&#39;)</code></p>
</div>
<h4>.popover('destroy')</h4>
<p>隐藏并销毁弹出框。</p>
<div class="segment">
<p><code>js$(&#39;#element&#39;).popover(&#39;destroy&#39;)</code></p>
</div>
<h3>事件</h3>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 150px;">事件类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>show.bs.popover</td>
<td><code>show</code>方法被调用之后,此事件将被立即触发。</td>
</tr>
<tr>
<td>shown.bs.popover</td>
<td>当弹出框展示到用户面前之后(同时CSS过渡效果执行完之后)此事件被触发。</td>
</tr>
<tr>
<td>hide.bs.popover</td>
<td><code>hide</code>方法被调用之后,此事件被触发。</td>
</tr>
<tr>
<td>hidden.bs.popover</td>
<td>当弹出框被隐藏之后(同时CSS过渡效果执行完之后),此事件被触发。</td>
</tr>
</tbody>
</table>
</div><!-- /.table-responsive -->
<div class="segment">
<pre class="prettyprint linenums"><code class="language-js">$(<span class="string">'#myPopover'</span>).on(<span class="string">'hidden.bs.popover'</span>, <span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span>
<span class="comment">// do something…</span>
})</code></pre>
</div>
</section>
</article>
</body>
</html>
\ No newline at end of file
/* ========================================================================
* Bootstrap: popover.js v3.0.0
* http://twbs.github.com/bootstrap/javascript.html#popovers
* ========================================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ======================================================================== */
+function ($) { "use strict";
// POPOVER PUBLIC CLASS DEFINITION
// ===============================
var Popover = function (element, options) {
this.init('popover', element, options)
}
if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
Popover.DEFAULTS = $.extend({} , $.fn.tooltip.Constructor.DEFAULTS, {
placement: 'right'
, trigger: 'click'
, content: ''
, template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
})
// NOTE: POPOVER EXTENDS tooltip.js
// ================================
Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
Popover.prototype.constructor = Popover
Popover.prototype.getDefaults = function () {
return Popover.DEFAULTS
}
Popover.prototype.setContent = function () {
var $tip = this.tip()
var title = this.getTitle()
var content = this.getContent()
$tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
$tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
$tip.removeClass('fade top bottom left right in')
// IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
// this manually by checking the contents.
if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
}
Popover.prototype.hasContent = function () {
return this.getTitle() || this.getContent()
}
Popover.prototype.getContent = function () {
var $e = this.$element
var o = this.options
return $e.attr('data-content')
|| (typeof o.content == 'function' ?
o.content.call($e[0]) :
o.content)
}
Popover.prototype.arrow = function () {
return this.$arrow = this.$arrow || this.tip().find('.arrow')
}
Popover.prototype.tip = function () {
if (!this.$tip) this.$tip = $(this.options.template)
return this.$tip
}
// POPOVER PLUGIN DEFINITION
// =========================
var old = $.fn.popover
$.fn.popover = function (option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.popover')
var options = typeof option == 'object' && option
if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.popover.Constructor = Popover
// POPOVER NO CONFLICT
// ===================
$.fn.popover.noConflict = function () {
$.fn.popover = old
return this
}
}(window.jQuery);
......@@ -654,4 +654,20 @@
@tooltip-bg: @color-fore;
@tooltip-arrow-width: 5px;
@tooltip-arrow-color: @tooltip-bg;
\ No newline at end of file
@tooltip-arrow-color: @tooltip-bg;
// Popovers
// -------------------------
@popover-bg: #fff;
@popover-max-width: 276px;
@popover-border-color: rgba(0,0,0,.2);
@popover-fallback-border-color: #ccc;
@popover-title-bg: darken(@popover-bg, 3%);
@popover-arrow-width: 10px;
@popover-arrow-color: #fff;
@popover-arrow-outer-width: (@popover-arrow-width + 1);
@popover-arrow-outer-color: rgba(0,0,0,.25);
@popover-arrow-outer-fallback-color: #999;
......@@ -193,71 +193,3 @@
}
}
}
// Sub menus
// ---------------------------
.dropdown-submenu { position: relative; }
// Default dropdowns
.dropdown-submenu > .dropdown-menu
{
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: @border-radius-base;
}
.dropdown-submenu:hover > .dropdown-menu { display: block; }
// Dropups
.dropup .dropdown-submenu > .dropdown-menu
{
top: auto;
bottom: 0;
margin-top: 0;
margin-bottom: -2px;
border-radius: @border-radius-base;
}
// Caret to indicate there is a submenu
.dropdown-submenu > a:after
{
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: darken(@dropdown-bg, 20%);
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover > a:after { border-left-color: @dropdown-link-hover-color; }
// Left aligned submenus
.dropdown-submenu.pull-left
{
> a {min-width:160px;} // compatibly width the min-widht:160px of .dropdown-menu.
// Undo the float
// Yes, this is awkward since .pull-left adds a float, but it sticks to our conventions elsewhere.
float: none;
// Positioning the submenu
> .dropdown-menu
{
left: -100%;
border-radius: @border-radius-base;
}
}
.dropdown-submenu:hover > a,
.dropdown-submenu:focus > a
{
text-decoration: none;
color: @dropdown-link-hover-color;
#gradient > .vertical(@dropdown-link-hover-bg, darken(@dropdown-link-hover-bg, 5%));
}
//
// Popovers
// --------------------------------------------------
.popover
{
position: absolute;
top: 0;
left: 0;
z-index: @zindex-popover;
display: none;
max-width: @popover-max-width;
padding: 1px;
text-align: left; // Reset given new insertion method
background-color: @popover-bg;
background-clip: padding-box;
border: 1px solid @popover-fallback-border-color;
border: 1px solid @popover-border-color;
border-radius: @border-radius-large;
.box-shadow(0 5px 10px rgba(0,0,0,.2));
// Overrides for proper insertion
white-space: normal;
// Offset the popover to account for the popover arrow
&.top { margin-top: -10px; }
&.right { margin-left: 10px; }
&.bottom { margin-top: 10px; }
&.left { margin-left: -10px; }
}
.popover-title
{
margin: 0; // reset heading margin
padding: 8px 14px;
font-size: @font-size-base;
font-weight: normal;
line-height: 18px;
background-color: @popover-title-bg;
border-bottom: 1px solid darken(@popover-title-bg, 5%);
border-radius: 5px 5px 0 0;
}
.popover-content
{
padding: 9px 14px;
}
// Arrows
//
// .arrow is outer, .arrow:after is inner
.popover .arrow
{
&,
&:after
{
position: absolute;
display: block;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
}
}
.popover .arrow
{
border-width: @popover-arrow-outer-width;
}
.popover .arrow:after
{
border-width: @popover-arrow-width;
content: "";
}
.popover
{
&.top .arrow
{
left: 50%;
margin-left: -@popover-arrow-outer-width;
border-bottom-width: 0;
border-top-color: @popover-arrow-outer-fallback-color; // IE8 fallback
border-top-color: @popover-arrow-outer-color;
bottom: -@popover-arrow-outer-width;
&:after
{
content: " ";
bottom: 1px;
margin-left: -@popover-arrow-width;
border-bottom-width: 0;
border-top-color: @popover-arrow-color;
}
}
&.right .arrow
{
top: 50%;
left: -@popover-arrow-outer-width;
margin-top: -@popover-arrow-outer-width;
border-left-width: 0;
border-right-color: @popover-arrow-outer-fallback-color; // IE8 fallback
border-right-color: @popover-arrow-outer-color;
&:after
{
content: " ";
left: 1px;
bottom: -@popover-arrow-width;
border-left-width: 0;
border-right-color: @popover-arrow-color;
}
}
&.bottom .arrow
{
left: 50%;
margin-left: -@popover-arrow-outer-width;
border-top-width: 0;
border-bottom-color: @popover-arrow-outer-fallback-color; // IE8 fallback
border-bottom-color: @popover-arrow-outer-color;
top: -@popover-arrow-outer-width;
&:after
{
content: " ";
top: 1px;
margin-left: -@popover-arrow-width;
border-top-width: 0;
border-bottom-color: @popover-arrow-color;
}
}
&.left .arrow
{
top: 50%;
right: -@popover-arrow-outer-width;
margin-top: -@popover-arrow-outer-width;
border-right-width: 0;
border-left-color: @popover-arrow-outer-fallback-color; // IE8 fallback
border-left-color: @popover-arrow-outer-color;
&:after {
content: " ";
right: 1px;
border-right-width: 0;
border-left-color: @popover-arrow-color;
bottom: -@popover-arrow-width;
}
}
}
......@@ -64,6 +64,7 @@
// --------------------------------------------------
@import "components/modals.less";
@import "modules/tooltip.less";
@import "modules/popovers.less";
//
// ASSETS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册