Bootstrap之BootstrapDialog

来源:http://www.cnblogs.com/my-air/archive/2016/03/30/5338125.html
-Advertisement-
Play Games

Make use of Bootstrap's modal more monkey-friendly. 參考地址:http://nakupanda.github.io/bootstrap3-dialog/ 模態彈框: <div class="modal fade"> <div class="moda ...


Make use of Bootstrap's modal more monkey-friendly.


參考地址:http://nakupanda.github.io/bootstrap3-dialog/

模態彈框:

<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Dialog彈出層:

        BootstrapDialog.alert('I want banana!');
 

 

Examples


Simplest

 

只提供信息顯示,並保持所有其他事情預設。

        BootstrapDialog.show({
            message: 'Hi Apple!'
        });

Dialog Title



        BootstrapDialog.show({
            title: 'Say-hello dialog',
            message: 'Hi Apple!'
        });
 

操作對話標題



        BootstrapDialog.show({
            title: 'Default Title',
            message: 'Click buttons below.',
            buttons: [{
                label: 'Title 1',
                action: function(dialog) {
                    dialog.setTitle('Title 1');
                }
            }, {
                label: 'Title 2',
                action: function(dialog) {
                    dialog.setTitle('Title 2');
                }
            }]
        });
 

操作對話信息



        BootstrapDialog.show({
            title: 'Default Title',
            message: 'Click buttons below.',
            buttons: [{
                label: 'Message 1',
                action: function(dialog) {
                    dialog.setMessage('Message 1');
                }
            }, {
                label: 'Message 2',
                action: function(dialog) {
                    dialog.setMessage('Message 2');
                }
            }]
        });
 

載入遠程頁面(1)

        BootstrapDialog.show({
            message: $('<div></div>').load('remote.html')
        });

載入遠程頁面 (2)

        BootstrapDialog.show({
            message: function(dialog) {
                var $message = $('<div></div>');
                var pageToLoad = dialog.getData('pageToLoad');
                $message.load(pageToLoad);
        
                return $message;
            },
            data: {
                'pageToLoad': 'remote.html'
            }
        });
 

Buttons

        BootstrapDialog.show({
            message: 'Hi Apple!',
            buttons: [{
                label: 'Button 1'
            }, {
                label: 'Button 2',
                cssClass: 'btn-primary',
                action: function(){
                    alert('Hi Orange!');
                }
            }, {
                icon: 'glyphicon glyphicon-ban-circle',
                label: 'Button 3',
                cssClass: 'btn-warning'
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
 

操作Buttons

通過bootstrapdialog創建按鈕有一些額外的功能:
$button.toggleEnable(true|false);
$button.enable(); // 相當於 $button.toggleEnable(true);
$button.disable(); // 相當於  $button.toggleEnable(false);
$button.toggleSpin(true|false);
$button.spin(); // 相當於 $button.toggleSpin(true);
$button.stopSpin(); // 相當於  $button.toggleSpin(false);

        BootstrapDialog.show({
            title: 'Manipulating Buttons',
            message: function(dialog) {
                var $content = $('<div><button class="btn btn-success">Revert button status right now.</button></div>');
                var $footerButton = dialog.getButton('btn-1');
                $content.find('button').click({$footerButton: $footerButton}, function(event) {
                    event.data.$footerButton.enable();
                    event.data.$footerButton.stopSpin();
                    dialog.setClosable(true);
                });
                
                return $content;
            },
            buttons: [{
                id: 'btn-1',
                label: 'Click to disable and spin.',
                action: function(dialog) {
                    var $button = this; // 'this' here is a jQuery object that wrapping the <button> DOM element.
                    $button.disable();
                    $button.spin();
                    dialog.setClosable(false);
                }
            }]
        });
 

按鈕的熱鍵

試著按下麵的按鈕。
最後一個按鈕被禁用,所以沒有事情發生,當按下熱鍵。
請註意,如果您的對話框中有一些需要鍵盤操作的組件,可能會出現衝突,您可以嘗試下一個示例。

        BootstrapDialog.show({
            title: 'Button Hotkey',
            message: 'Try to press some keys...',
            onshow: function(dialog) {
                dialog.getButton('button-c').disable();
            },
            buttons: [{
                label: '(A) Button A',
                hotkey: 65, // Keycode of keyup event of key 'A' is 65.
                action: function() {
                    alert('Finally, you loved Button A.');
                }
            }, {
                label: '(B) Button B',
                hotkey: 66,
                action: function() {
                    alert('Hello, this is Button B!');
                }
            }, {
                id: 'button-c',
                label: '(C) Button C',
                hotkey: 67,
                action: function(){
                    alert('This is Button C but you won\'t see me dance.');
                }
            }]
        });
 

 

創建 dialog 實例

BootstrapDialog.show(...) 只是一個快捷方式,如果你需要對話框實例,用“新”。


        
        // Using init options
        var dialogInstance1 = new BootstrapDialog({
            title: 'Dialog instance 1',
            message: 'Hi Apple!'
        });
        dialogInstance1.open();
        
        // Construct by using setters
        var dialogInstance2 = new BootstrapDialog();
        dialogInstance2.setTitle('Dialog instance 2');
        dialogInstance2.setMessage('Hi Orange!');
        dialogInstance2.setType(BootstrapDialog.TYPE_SUCCESS);
        dialogInstance2.open();
        
        // Using chain callings
        var dialogInstance3 = new BootstrapDialog()
            .setTitle('Dialog instance 3')
            .setMessage('Hi Everybody!')
            .setType(BootstrapDialog.TYPE_INFO)
            .open();
 

事實上BootstrapDialog.show(...) 也將返回創建的對話框實例。


        
        // You can use dialogInstance later.
        var dialogInstance = BootstrapDialog.show({
            message: 'Hello Banana!'
        });

Button with identifier


        
        var dialog = new BootstrapDialog({
            message: 'Hi Apple!',
            buttons: [{
                id: 'btn-1',
                label: 'Button 1'
            }]
        });
        dialog.realize();
        var btn1 = dialog.getButton('btn-1');
        btn1.click({'name': 'Apple'}, function(event){
            alert('Hi, ' + event.data.name);
        });
        dialog.open();
 

較大的對話框

預設情況下,對話框的大小是 'size-normal' 或 BootstrapDialog.SIZE_NORMAL, 但你可以通過設置選項的 'size' 的'size-large' 或BootstrapDialog.SIZE_LARGE.


        
        BootstrapDialog.show({
            size: BootstrapDialog.SIZE_LARGE,
            message: 'Hi Apple!',
            buttons: [{
                label: 'Button 1'
            }, {
                label: 'Button 2',
                cssClass: 'btn-primary',
                action: function(){
                    alert('Hi Orange!');
                }
            }, {
                icon: 'glyphicon glyphicon-ban-circle',
                label: 'Button 3',
                cssClass: 'btn-warning'
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
 

More dialog sizes

Please note that specifying BootstrapDialog.SIZE_WIDE is equal to using css class 'modal-lg' on Bootstrap Modal.


        
        BootstrapDialog.show({
            title: 'More dialog sizes',
            message: 'Hi Apple!',
            buttons: [{
                label: 'Normal',
                action: function(dialog){
                    dialog.setTitle('Normal');
                    dialog.setSize(BootstrapDialog.SIZE_NORMAL);
                }
            }, {
                label: 'Small',
                action: function(dialog){
                    dialog.setTitle('Small');
                    dialog.setSize(BootstrapDialog.SIZE_SMALL);
                }
            }, {
                label: 'Wide',
                action: function(dialog){
                    dialog.setTitle('Wide');
                    dialog.setSize(BootstrapDialog.SIZE_WIDE);
                }
            }, {
                label: 'Large',
                action: function(dialog){
                    dialog.setTitle('Large');
                    dialog.setSize(BootstrapDialog.SIZE_LARGE);
                }
            }]
        });
 

更多信息

bootstrapdialog支持顯示豐富的內容,所以你甚至可以使用一個視頻剪輯你的對話框中的消息。

        
        var $textAndPic = $('<div></div>');
        $textAndPic.append('Who\'s this? <br />');
        $textAndPic.append('<img src="./images/pig.ico" />');
        
        BootstrapDialog.show({
            title: 'Guess who that is',
            message: $textAndPic,
            buttons: [{
                label: 'Acky',
                action: function(dialogRef){
                    dialogRef.close();
                }
            }, {
                label: 'Robert',
                action: function(dialogRef){
                    dialogRef.close();
                }
            }]
        });
 

Dialog closable / unclosable

If option 'closable' is set to false, the default closing behaviors will be disabled, but you can still close the dialog by using dialog.close().


        
        BootstrapDialog.show({
            message: 'Hi Apple!',
            closable: false,
            buttons: [{
                label: 'Dialog CLOSABLE!',
                cssClass: 'btn-success',
                action: function(dialogRef){
                    dialogRef.setClosable(true);
                }
            }, {
                label: 'Dialog UNCLOSABLE!',
                cssClass: 'btn-warning',
                action: function(dialogRef){
                    dialogRef.setClosable(false);
                }
            }, {
                label: 'Close the dialog',
                action: function(dialogRef){
                    dialogRef.close();
                }
            }]
        });
 

關閉對話框的更多控制項

 

預設情況下,當選擇 'closable' 設置為true,對話框可以通過這些方式關閉:點擊在對話框中,按ESC鍵,點擊對話框標題右側的關閉圖標。

如果你想讓你的對話框關閉時,對話框標題的關閉圖標被點擊,可以設置的選項 'closeByBackdrop' and 'closeByKeyboard' 為 false.


        
        BootstrapDialog.show({
            message: 'Hi Apple!',
            message: 'You can not close this dialog by clicking outside and pressing ESC key.',
            closable: true,
            closeByBackdrop: false,
            closeByKeyboard: false,
            buttons: [{
                label: 'Close the dialog',
                action: function(dialogRef){
                    dialogRef.close();
                }
            }]
        });

Confirm

  BootstrapDialog.confirm('Hi Apple, are you sure?');

Confirm with callback

        BootstrapDialog.confirm('Hi Apple, are you sure?', function(result){
            if(result) {
                alert('Yup.');
            }else {
                alert('Nope.');
            }
        });

 

 

Available options


Please note that all options described below are optional, but you will have a weird dialog if you don't even give it a message to display.
Most options can be set via init options or property setters.

Option Possible values Description
type BootstrapDialog.TYPE_DEFAULT or 'type-default'
BootstrapDialog.TYPE_INFO or 'type-info'
BootstrapDialog.TYPE_PRIMARY or 'type-primary' (default)
BootstrapDialog.TYPE_SUCCESS or 'type-success'
BootstrapDialog.TYPE_WARNING or 'type-warning'
BootstrapDialog.TYPE_DANGER or 'type-danger'
Give your dialog a specific look, color scheme can be seen on Bootstrap's Button.
size BootstrapDialog.SIZE_NORMAL or 'size-normal' (default)
BootstrapDialog.SIZE_WIDE or 'size-wide'
BootstrapDialog.SIZE_LARGE or 'size-large'
-
cssClass - Additional css classes that will be added to your dialog.
title String or Object(html) -
message String or Object(html) -
buttons array Examples:

BootstrapDialog.show({
    title: 'Say-hello dialog',
    message: 'Hello world!',
    buttons: [{
        id: 'btn-ok',   
        icon: 'glyphicon glyphicon-check',       
        label: 'OK',
        cssClass: 'btn-primary', 
        autospin: false,
        action: function(dialogRef){    
            dialogRef.close();
        }
    }]
});
  id: optional, if id is set, you can use dialogInstance.getButton(id) to get the button later.
icon: optional, if set, the specified icon will be added to the button.
cssClass: optional, additional css class to be added to the button.
autospin: optinal, if it's true, after clicked the button a spinning icon appears.
action: optional, if provided, the callback will be invoked after the button is clicked, and the dialog instance will be passed to the callback function.
closable true | false When set to true, you can close the dialog by:
  • Clicking the close icon in dialog header.
  • Clicking outside the dialog.
  • ESC key.
spinicon Icon class name, for example 'glyphicon glyphicon-check'.
Default value is 'glyphicon glyphicon-asterisk'.
Specify what icon to be used as the spinning icon when button's 'autospin' is set to true.
data Key-value object. For example {'id' : '100'} Data to be bound to the dialog.
onshow function If provided, it will be invoked when the dialog is popping up.
onshown function If provided, it will be invoked when the dialog is popped up.
onhide function If provided, it will be invoked when the dialog is popping down.
onhidden function If provided, it will be invoked when the dialog is popped down.
autodestroy true (default) | false When it's true, all modal stuff will be removed from the DOM tree after the dialog is popped down, set it to false if you need your dialog (same instance) pups up and down again and again.
description String If provided, 'aria-describedby' attribute will be added to the dialog with the description string as its value. This can improve accessibility, as the description can be read by screen readers.
nl2br true | false Automatically convert line breaking character to <br /> if it's set to true, everything keeps original if it's false.

Available methods


Method Description
open() Open the dialog. Usage: dialogInstance.open()
close() Close the dialog. Usage: dialogInstance.close()
getModal() Return the raw modal, equivalent to $('<div class='modal fade'...></div>')
getModalDialog() Return the raw modal dialog.
getModalContent() Return the raw modal content.
getModalHeader() Return the raw modal header.
getModalBody() Return the raw modal body.
getModalFooter() Return the raw modal footer.
getData(key) Get data entry according to the given key, returns null if no data entry found.
setData(key, value) Bind data entry to dialog instance, value can be any types that javascript supports.
enableButtons(boolean) Disable all buttons in dialog footer when it's false, enable all when it's true.
setClosable(boolean) When set to true (default), dialog can be closed by clicking close icon in dialog header, or by clicking outside the dialog, or, ESC key is pressed.
realize() Calling dialog.open() will automatically get this method called first, but if you want to do something on your dialog before it's shown, you can manually call dialog.realize() before calling dialog.open().

Go to the project. | Contact me if you can help to improve this example page.
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 回到目錄 web api越來越火,因為它的跨平臺,因為它的簡單,因為它支持xml,json等流行的數據協議,我們在開發基於面向服務的API時,有個問題一直在困擾著我們,那就是數據的安全,請求的安全,一般所說的安全也無非就是請求的防篡改和請求的防復用,例如,你向API發一個查詢用戶賬戶的請求,在這個過 ...
  • Atitit.嵌入式web 伺服器 java android最佳實踐 1. Android4.4.21 2. 自己的webserver1 3. CyberHTTP for Java cybergarage6 1. Android4.4.2 First使用jetty9,三說jdk編譯級別非常高的... ...
  • 需求: 上圖中,如果我們想用實體類來實現的話,明顯實現不了 原因很簡單,要顯示的數據包含的三張表(Student,Subject,Result)中的數據 我們無法單純的用某個實體類來解決,這時我們就可以擴展實體類來解決這個問題 我們可添加ResultBusiness類繼承Result實體類 這樣我們 ...
  • 原文地址:http://www.infoq.com/cn/articles/flash-deal-architecture-optimization 一、秒殺業務為什麼難做 IM系統,例如QQ或者微博,每個人都讀自己的數據(好友列表、群列表、個人信息)。 微博系統,每個人讀你關註的人的數據,一個人讀 ...
  • 單例模式(Singleton) 類圖 描述 單例模式: 保證一個類僅有一個實例,並提供一個訪問它的全局訪問點; 構造函數修飾符為private。 應用場景 懶漢模式:第一次調用的時候才產生一個新的實例,併在以後返回此實例。 非線程安全的單例模式 線程安全的單例模式,需加線程鎖 線程安全的單例模式,雙 ...
  • 1、在MyEclipse下建立Web Project,找到根目錄建立Database文件夾和Doc文件夾,Database用於保存資料庫信息,Doc用於保存資料庫表信息。 2、打開SQL Server 2008 ,新建資料庫CRUD,將路徑添加到Database文件夾下。 3、寫SQL語句添加資料庫 ...
  • 來到了開源中國的第二個星期,雖然只是實習,但是數了數,這也是我大學生涯裡面的第四個實習工作了。 專業學的是軟體工程,然而課程裡面卻沒有一門課程是直接跟前端相關的。因此在大學期間,只能靠實習來學習,獲得經驗,每當技術在該公司遇到瓶頸的時候,我就知道,我要準備去另一家公司實習了~~誰叫我現在才大三呢.. ...
  • 網上看過很多配置思路,自己總結了以下, 就把我個人配置的順序以及材料分享下,webstrom以下簡稱WB 1、配置less需要安裝nodejs,自行安裝。因為要用到npm.我是直接把npm解壓到C盤根目錄的,先下載解壓好待用 npm解壓包百度雲下載地址:http://pan.baidu.com/s/ ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...