BootstrapDialogのブートストラップ
Bootstrap Bootstrapdialog
Bootstrapのモーダルをよりサルにやさしいものにしてください。
参照アドレス: http://nakupanda.github.io/bootstrap3-dialog/
モーダルシェルフレーム:
Dialog pop-up layer:
BootstrapDialog.alert('I want banana!')
BootstrapDialog.show({ message: 'Hi Apple!' })
例
最も単純な
表示は提供情報のみを表示し、その他はすべてデフォルトのままにします。
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') } }] })
操作ダイアログのタイトル
BootstrapDialog.show({ message: $(' ').load('remote.html') })
BootstrapDialog.show({ message: function(dialog) { var $message = $(' ') var pageToLoad = dialog.getData('pageToLoad') $message.load(pageToLoad) return $message }, data: { 'pageToLoad': 'remote.html' } })
アクションダイアログ情報
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() } }] })
BootstrapDialog.show({ title: 'Manipulating Buttons', message: function(dialog) { var $content = $(' Revert button status right now. ') 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 DOM element. $button.disable() $button.spin() dialog.setClosable(false) } }] })
リモートページをロードする(1)
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.') } }] })
リモートページをロードする(2)
// 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()
ボタン
// You can use dialogInstance later. var dialogInstance = BootstrapDialog.show({ message: 'Hello Banana!' })
操作ボタン
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)と同等
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()
ボタンのホットキー
下のボタンをクリックしてみてください。
最後のボタンが無効になっているため、ホットキーを押しても何も起こりません。
ボックスにキーボードを必要とするコンポーネントがいくつかある場合、競合が発生する可能性があることに注意してください。次の例を試すことができます。
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() } }] })
ダイアログインスタンスを作成する
BootstrapDialog.show(...)は単なるショートカットです。ダイアログインスタンスが必要な場合は、「new」を使用してください。
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.show(...)も、作成されたダイアログインスタンスに戻ります。
var $textAndPic = $(' ') $textAndPic.append('Who's this?
') $textAndPic.append(' ') BootstrapDialog.show({ title: 'Guess who that is', message: $textAndPic, buttons: [{ label: 'Acky', action: function(dialogRef){ dialogRef.close() } }, { label: 'Robert', action: function(dialogRef){ dialogRef.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() } }] })
大きな箱
デフォルトでは、ダイアログのサイズは「size-normal」またはBootstrapDialog.SIZE_NORMALですが、「size-large」またはBootstrapDialog.SIZE_LARGEのオプション「size」を設定できます。
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() } }] })
その他のダイアログサイズ
BootstrapDialog.SIZE_WIDEを指定することは、BootstrapModalでcssクラス「modal-lg」を使用することと同じであることに注意してください。
BootstrapDialog.confirm('Hi Apple, are you sure?')
詳しくは
bootstrapdialogはリッチコンテンツの表示をサポートしているため、ダイアログボックスメッセージのビデオクリップを使用することもできます。
BootstrapDialog.confirm('Hi Apple, are you sure?', function(result){ if(result) { alert('Yup.') }else { alert('Nope.') } })
ダイアログを閉じることができる/閉じることができない
オプション 'closable'がfalseに設定されている場合、デフォルトの閉じる動作は無効になりますが、dialog.close()を使用してダイアログを閉じることができます。
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() } }] })
ダイアログボックスのコントロールをさらに閉じる
デフォルトでは、'Closable'をtrueに設定すると、ダイアログボックスは次の方法で閉じることができます。ダイアログボックスをクリックし、ESCを押して、ダイアログボックスのタイトルの右側にある閉じるアイコンをクリックします。
ダイアログボックスを閉じたい場合は、ダイアログを閉じるアイコンのタイトルをクリックします。「closeByBackdrop」と「closeByKeyboard」を設定するオプションはfalseです。
class='modal fade'>
class='modal-dialog'>
class='modal-content'>
class='modal-header'>