├── .github ├── PULL_REQUEST_TEMPLATE.md ├── stale.yml ├── ISSUE_TEMPLATE.md ├── CONTRIBUTING.md └── GIT-WORKFLOW.md ├── src ├── assets │ ├── js │ │ ├── dialog-yii.min.js │ │ ├── dialog-yii.js │ │ ├── dialog.min.js │ │ ├── dialog.js │ │ ├── bootstrap-dialog.min.js │ │ └── bootstrap-dialog.js │ └── css │ │ ├── bootstrap-dialog-bs4.min.css │ │ ├── bootstrap-dialog-bs3.min.css │ │ ├── bootstrap-dialog-bs4.css │ │ └── bootstrap-dialog-bs3.css ├── messages │ ├── af │ │ └── kvdialog.php │ ├── ar │ │ └── kvdialog.php │ ├── az │ │ └── kvdialog.php │ ├── bg │ │ └── kvdialog.php │ ├── bs │ │ └── kvdialog.php │ ├── ca │ │ └── kvdialog.php │ ├── cs │ │ └── kvdialog.php │ ├── da │ │ └── kvdialog.php │ ├── en │ │ └── kvdialog.php │ ├── eo │ │ └── kvdialog.php │ ├── et │ │ └── kvdialog.php │ ├── eu │ │ └── kvdialog.php │ ├── fi │ │ └── kvdialog.php │ ├── fo │ │ └── kvdialog.php │ ├── fr │ │ └── kvdialog.php │ ├── gl │ │ └── kvdialog.php │ ├── gu │ │ └── kvdialog.php │ ├── he │ │ └── kvdialog.php │ ├── hi │ │ └── kvdialog.php │ ├── hr │ │ └── kvdialog.php │ ├── hy │ │ └── kvdialog.php │ ├── id │ │ └── kvdialog.php │ ├── is │ │ └── kvdialog.php │ ├── ka │ │ └── kvdialog.php │ ├── kk │ │ └── kvdialog.php │ ├── kn │ │ └── kvdialog.php │ ├── ko │ │ └── kvdialog.php │ ├── ky │ │ └── kvdialog.php │ ├── lt │ │ └── kvdialog.php │ ├── mi │ │ └── kvdialog.php │ ├── mk │ │ └── kvdialog.php │ ├── mn │ │ └── kvdialog.php │ ├── mr │ │ └── kvdialog.php │ ├── ms │ │ └── kvdialog.php │ ├── mt │ │ └── kvdialog.php │ ├── nb │ │ └── kvdialog.php │ ├── nn │ │ └── kvdialog.php │ ├── qu │ │ └── kvdialog.php │ ├── ro │ │ └── kvdialog.php │ ├── sa │ │ └── kvdialog.php │ ├── se │ │ └── kvdialog.php │ ├── sk │ │ └── kvdialog.php │ ├── sl │ │ └── kvdialog.php │ ├── sq │ │ └── kvdialog.php │ ├── sr │ │ └── kvdialog.php │ ├── sv │ │ └── kvdialog.php │ ├── sw │ │ └── kvdialog.php │ ├── ta │ │ └── kvdialog.php │ ├── te │ │ └── kvdialog.php │ ├── th │ │ └── kvdialog.php │ ├── tj │ │ └── kvdialog.php │ ├── tl │ │ └── kvdialog.php │ ├── tn │ │ └── kvdialog.php │ ├── ts │ │ └── kvdialog.php │ ├── tt │ │ └── kvdialog.php │ ├── ur │ │ └── kvdialog.php │ ├── vi │ │ └── kvdialog.php │ ├── zu │ │ └── kvdialog.php │ ├── ja │ │ └── kvdialog.php │ ├── zh-CN │ │ └── kvdialog.php │ ├── zh-TW │ │ └── kvdialog.php │ ├── tr │ │ └── kvdialog.php │ ├── fa │ │ └── kvdialog.php │ ├── el │ │ └── kvdialog.php │ ├── hu │ │ └── kvdialog.php │ ├── it │ │ └── kvdialog.php │ ├── nl │ │ └── kvdialog.php │ ├── pl │ │ └── kvdialog.php │ ├── pt │ │ └── kvdialog.php │ ├── ru │ │ └── kvdialog.php │ ├── uk │ │ └── kvdialog.php │ ├── uz-Cy │ │ └── kvdialog.php │ ├── uz │ │ └── kvdialog.php │ ├── de │ │ └── kvdialog.php │ ├── lv │ │ └── kvdialog.php │ ├── pt-BR │ │ └── kvdialog.php │ ├── sr-Latn │ │ └── kvdialog.php │ ├── es │ │ └── kvdialog.php │ └── config.php ├── DialogYiiAsset.php ├── DialogBootstrapAsset.php ├── DialogAsset.php └── Dialog.php ├── composer.json ├── LICENSE.md ├── CHANGE.md └── README.md /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Scope 2 | This pull request includes a 3 | 4 | - [ ] Bug fix 5 | - [ ] New feature 6 | - [ ] Translation 7 | 8 | ## Changes 9 | The following changes were made (this change is also documented in the [change log](https://github.com/kartik-v/yii2-dialog/blob/master/CHANGE.md)): 10 | 11 | - 12 | - 13 | - 14 | 15 | ## Related Issues 16 | If this is related to an existing ticket, include a link to it as well. -------------------------------------------------------------------------------- /src/assets/js/dialog-yii.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Override Yii confirmation dialog with Krajee Dialog. 8 | * 9 | * For more JQuery plugins visit http://plugins.krajee.com 10 | * For more Yii related demos visit http://demos.krajee.com 11 | */ 12 | var krajeeYiiConfirm;!function(){"use strict";krajeeYiiConfirm=function(i){i=i||"krajeeDialog";var n=window[i]||"";n&&(yii.confirm=function(i,o,r){n.confirm(i,function(i){i?!o||o():!r||r()})})}}(); -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - bug 8 | - enhancement 9 | - pinned 10 | - security 11 | # Label to use when marking an issue as stale 12 | staleLabel: wontfix 13 | # Comment to post when marking an issue as stale. Set to `false` to disable 14 | markComment: > 15 | This issue has been automatically marked as stale because it has not had 16 | recent activity. It will be closed if no further activity occurs. Thank you 17 | for your contributions. 18 | # Comment to post when closing a stale issue. Set to `false` to disable 19 | closeComment: false -------------------------------------------------------------------------------- /src/messages/af/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ar/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/az/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/bg/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/bs/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ca/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/cs/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/da/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/en/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/eo/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/et/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/eu/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/fi/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/fo/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/fr/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/gl/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/gu/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/he/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/hi/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/hr/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/hy/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/id/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/is/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ka/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/kk/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/kn/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ko/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ky/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/lt/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/mi/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/mk/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/mn/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/mr/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ms/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/mt/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/nb/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/nn/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/qu/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ro/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sa/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/se/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sk/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sl/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sq/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sr/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sv/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sw/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ta/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/te/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/th/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/tj/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/tl/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/tn/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ts/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/tt/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ur/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/vi/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/zu/kvdialog.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'Confirmation' => '', 22 | 'Information' => '', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ja/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'キャンセル', 21 | 'Confirmation' => '確認', 22 | 'Information' => '情報', 23 | 'Ok' => 'OK', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/zh-CN/kvdialog.php: -------------------------------------------------------------------------------- 1 | '取消', 21 | 'Confirmation' => '确认提示', 22 | 'Information' => '信息提示', 23 | 'Ok' => '确定', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/zh-TW/kvdialog.php: -------------------------------------------------------------------------------- 1 | '取消', 21 | 'Confirmation' => '確認提示', 22 | 'Information' => '信息提示', 23 | 'Ok' => '確定', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/tr/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'İptal', 21 | 'Confirmation' => 'Onay', 22 | 'Information' => 'Bilgi', 23 | 'Ok' => 'Tamam', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/fa/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'انصراف', 21 | 'Confirmation' => 'تاییدیه', 22 | 'Information' => 'اطلاعات', 23 | 'Ok' => 'تایید', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/el/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Άκυρο', 21 | 'Confirmation' => 'Επιβεβαίωση', 22 | 'Information' => 'Πληροφορία', 23 | 'Ok' => 'Ok', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/hu/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Mégse', 21 | 'Confirmation' => 'Megerősítés', 22 | 'Information' => 'Információ', 23 | 'Ok' => 'Ok', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/it/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Annulla', 21 | 'Confirmation' => 'Conferma', 22 | 'Information' => 'Informazione', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/nl/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Annuleer', 21 | 'Confirmation' => 'Bevestiging', 22 | 'Information' => 'Informatie', 23 | 'Ok' => 'Ok', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/pl/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Anuluj', 21 | 'Confirmation' => 'Potwierdzenie', 22 | 'Information' => 'Informacja', 23 | 'Ok' => 'Ok', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/pt/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Cancelar', 21 | 'Confirmation' => 'Confirmar', 22 | 'Information' => 'Informação', 23 | 'Ok' => 'Ok', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/ru/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Отмена', 21 | 'Confirmation' => 'Подтверждение', 22 | 'Information' => 'Информация', 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/uk/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Ні', 21 | 'Confirmation' => 'Підтвердження', 22 | 'Information' => 'Інформація', 23 | 'Ok' => 'Так', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/uz-Cy/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Бекор қилиш', 21 | 'Confirmation' => 'Тасдиқлаш', 22 | 'Information' => "Маълумот", 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/uz/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Bekor qilish', 21 | 'Confirmation' => 'Tasdiqlash', 22 | 'Information' => "Ma'lumot", 23 | 'Ok' => '', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/de/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Abbrechen', 21 | 'Confirmation' => 'Bestätigung', 22 | 'Information' => 'Information', 23 | 'Ok' => 'OK', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/lv/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Atcelt', 21 | 'Confirmation' => 'Apstiprinājums', 22 | 'Information' => 'Informācija', 23 | 'Ok' => 'Labi', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/pt-BR/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Cancelar', 21 | 'Confirmation' => 'Confirmação', 22 | 'Information' => 'Informação', 23 | 'Ok' => 'Ok', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/sr-Latn/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Otkaži', 21 | 'Confirmation' => 'Potvrda', 22 | 'Information' => 'Informacije', 23 | 'Ok' => 'U redu', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/messages/es/kvdialog.php: -------------------------------------------------------------------------------- 1 | 'Cancelar', 21 | 'Confirmation' => 'Confirmar', 22 | 'Information' => 'Información', 23 | 'Ok' => 'De acuerdo', 24 | ]; 25 | -------------------------------------------------------------------------------- /src/DialogYiiAsset.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 7 | * @version 1.0.6 8 | */ 9 | 10 | namespace kartik\dialog; 11 | 12 | use kartik\base\AssetBundle; 13 | 14 | /** 15 | * Asset bundle that overrides Yii's default confirm dialog 16 | * 17 | * @author Kartik Visweswaran 18 | * @since 1.0 19 | */ 20 | class DialogYiiAsset extends AssetBundle 21 | { 22 | /** 23 | * @inheritdoc 24 | */ 25 | public $depends = [ 26 | 'kartik\dialog\DialogAsset', 27 | 'yii\web\YiiAsset', 28 | ]; 29 | 30 | /** 31 | * @inheritdoc 32 | */ 33 | public function init() 34 | { 35 | $this->setSourcePath(__DIR__ . '/assets'); 36 | $this->setupAssets('js', ['js/dialog-yii']); 37 | parent::init(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kartik-v/yii2-dialog", 3 | "description": "An asset bundle for bootstrap3-dialog for Yii 2.0 framework.", 4 | "keywords": [ 5 | "yii2", 6 | "extension", 7 | "bootstrap", 8 | "modal", 9 | "dialog", 10 | "alert" 11 | ], 12 | "homepage": "https://github.com/kartik-v/yii2-dialog", 13 | "type": "yii2-extension", 14 | "license": "BSD-3-Clause", 15 | "authors": [ 16 | { 17 | "name": "Kartik Visweswaran", 18 | "email": "kartikv2@gmail.com", 19 | "homepage": "http://www.krajee.com/" 20 | } 21 | ], 22 | "require": { 23 | "kartik-v/yii2-krajee-base": ">=3.0.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "kartik\\dialog\\": "src" 28 | } 29 | }, 30 | "extra": { 31 | "branch-alias": { 32 | "dev-master": "1.0.x-dev" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/DialogBootstrapAsset.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 7 | * @version 1.0.6 8 | */ 9 | 10 | namespace kartik\dialog; 11 | use kartik\base\PluginAssetBundle; 12 | 13 | /** 14 | * Asset bundle for Bootstrap 3 Dialog 15 | * 16 | * @author Kartik Visweswaran 17 | * @since 1.0 18 | */ 19 | class DialogBootstrapAsset extends PluginAssetBundle 20 | { 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function init() 25 | { 26 | $this->depends = array_merge(['kartik\dialog\DialogAsset'], $this->depends); 27 | $this->setSourcePath(__DIR__ . '/assets'); 28 | $this->setupAssets('js', ['js/bootstrap-dialog']); 29 | $this->setupAssets('css', ['css/bootstrap-dialog-bs' . (!$this->isBs(3) ? '4' : '3')]); 30 | parent::init(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/assets/js/dialog-yii.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Override Yii confirmation dialog with Krajee Dialog. 8 | * 9 | * For more JQuery plugins visit http://plugins.krajee.com 10 | * For more Yii related demos visit http://demos.krajee.com 11 | */ 12 | var krajeeYiiConfirm; 13 | (function () { 14 | "use strict"; 15 | krajeeYiiConfirm = function(dialog) { 16 | dialog = dialog || 'krajeeDialog'; 17 | var krajeeDialog = window[dialog] || ''; 18 | if (!krajeeDialog) { 19 | return; 20 | } 21 | yii.confirm = function (message, ok, cancel) { 22 | krajeeDialog.confirm(message, function(result) { 23 | if (result) { 24 | !ok || ok(); 25 | } else { 26 | !cancel || cancel(); 27 | } 28 | }); 29 | }; 30 | }; 31 | })(); -------------------------------------------------------------------------------- /src/DialogAsset.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 7 | * @version 1.0.6 8 | */ 9 | 10 | namespace kartik\dialog; 11 | 12 | use yii\web\View; 13 | use kartik\base\AssetBundle; 14 | 15 | /** 16 | * Asset bundle that provides a polyfill for javascript native alert, confirm, and prompt boxes. The BootstrapDialog 17 | * will be used if available or needed, else the javascript native dialogs will be rendered. 18 | * 19 | * @author Kartik Visweswaran 20 | * @since 1.0 21 | */ 22 | class DialogAsset extends AssetBundle 23 | { 24 | /** 25 | * @inheritdoc 26 | */ 27 | public $depends = []; 28 | 29 | /** 30 | * @inheritdoc 31 | */ 32 | public function init() 33 | { 34 | $this->jsOptions = ['position' => View::POS_HEAD]; 35 | $this->setSourcePath(__DIR__ . '/assets'); 36 | $this->setupAssets('js', ['js/dialog']); 37 | parent::init(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | 3 | - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate. 4 | - [ ] The issue still exists against the latest `master` branch of yii2-grid. 5 | - [ ] This is not an usage question. I confirm having gone through and read the extension [documentation and demos](http://demos.krajee.com/dialog). 6 | - [ ] This is not a general programming / coding question. (Those should be directed to the [webtips Q & A forum](http://webtips.krajee.com/questions)). 7 | - [ ] I have attempted to find the simplest possible steps to reproduce the issue. 8 | - [ ] I have included a failing test as a pull request (Optional). 9 | 10 | ## Steps to reproduce the issue 11 | 12 | 1. 13 | 2. 14 | 3. 15 | 16 | ## Expected behavior and actual behavior 17 | 18 | When I follow those steps, I see... 19 | 20 | I was expecting... 21 | 22 | ## Environment 23 | 24 | #### Browsers 25 | 26 | - [ ] Google Chrome 27 | - [ ] Mozilla Firefox 28 | - [ ] Internet Explorer 29 | - [ ] Safari 30 | 31 | #### Operating System 32 | 33 | - [ ] Windows 34 | - [ ] Mac OS X 35 | - [ ] Linux 36 | - [ ] Mobile 37 | 38 | #### Libraries 39 | 40 | - jQuery version: 41 | - yii2-grid version: 42 | 43 | ## Isolating the problem 44 | 45 | - [ ] This bug happens [on the demos page](http://demos.krajee.com/dialog) 46 | - [ ] The bug happens consistently across all tested browsers 47 | - [ ] This bug happens when using yii2-grid without other plugins. -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 - 2021, Kartik Visweswaran 2 | Krajee.com 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | * Neither the names of Kartik Visweswaran or Krajee nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/assets/css/bootstrap-dialog-bs4.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Bootstrap 4.x styling for bootstrap-dialog plugin. 8 | * 9 | * For more JQuery plugins visit http://plugins.krajee.com 10 | * For more Yii related demos visit http://demos.krajee.com 11 | */.bootstrap-dialog .modal-header{border-top-left-radius:.25rem;border-top-right-radius:.25rem}.bootstrap-dialog .btn-modal-close{padding:0 5px;margin:-5px;background:0 0;border:none;border-radius:50%}.bootstrap-dialog .modal-header.bootstrap-dialog-draggable{cursor:move}.bootstrap-dialog .bootstrap-dialog-title{display:inline-block}.bootstrap-dialog .bootstrap-dialog-message{font-size:.875rem}.bootstrap-dialog .bootstrap-dialog-button-icon{margin-right:.1875rem}.bootstrap-dialog .bootstrap-dialog-close-button:hover{cursor:pointer;opacity:1;filter:alpha(opacity=100)}@media (min-width:1172px){.bootstrap-dialog .modal-xl{max-width:95%}}.bootstrap-dialog.type-default .modal-header{background-color:#fff}.bootstrap-dialog.type-default .bootstrap-dialog-title{color:#333}.bootstrap-dialog-footer-buttons{text-align:right}.bootstrap-dialog-footer-buttons>:not(:last-child){margin-right:.25rem}.bootstrap-dialog .icon-spin{display:inline-block;-moz-animation:spin 2s infinite linear;-o-animation:spin 2s infinite linear;-webkit-animation:spin 2s infinite linear;animation:spin 2s infinite linear}@-moz-keyframes spin{0%{-moz-transform:rotate(0)}100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0)}100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0)}100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(359deg)}}.bootstrap-dialog .modal-lg .bootstrap-dialog-title{font-size:1.25rem}.bootstrap-dialog .modal-lg .bootstrap-dialog-message,.bootstrap-dialog .modal-lg .btn-lg{font-size:1.0625rem}.bootstrap-dialog .modal-lg .bootstrap-dialog-close-button .close{font-size:1.765rem} -------------------------------------------------------------------------------- /CHANGE.md: -------------------------------------------------------------------------------- 1 | Change Log: `yii2-dialog` 2 | ========================= 3 | 4 | ## Version 1.0.6 5 | 6 | **Date:** 02-Sep-2021 7 | 8 | - (enh #45): Enhancements to support Bootstrap v5.x. 9 | - (enh #44): Add Latvian Translations. 10 | - (enh #43): Add Uzbek Translations. 11 | 12 | ## Version 1.0.5 13 | 14 | **Date:** 09-Oct-2018 15 | 16 | - Update composer dependencies. 17 | - (enh #36): Enhancement to button styling for `Dialog::SIZE_WIDE`. 18 | - CSS Enhancements for Bootstrap 4.x 19 | 20 | ## Version 1.0.4 21 | 22 | **Date:** 07-Sep-2018 23 | 24 | - Enhancements to support Bootstrap v4.x. 25 | - Move all source code to `src` directory. 26 | - (enh #34): Update Persian Translations 27 | 28 | ## Version 1.0.3 29 | 30 | **Date:** 06-Nov-2017 31 | 32 | - Update contribution templates 33 | - (enh #30): Enhance and fix dialog JS options initialization 34 | - (enh #29): Add Hungarian translations 35 | 36 | ## Version 1.0.2 37 | 38 | **Date:** 20-Oct-2017 39 | 40 | - (enh #28): Add feature to override Yii `data-confirm` dialog 41 | - (enh #26): Add Russian translations 42 | - (enh #23): Add Serbian (Latin) translations 43 | - (enh #22): Add callback to alert 44 | - (enh #21): Fixed accept custom options for dialog 45 | - (enh #20): Add Italian translations 46 | - (enh #19): Allow all input attributes to be set for prompt input 47 | - (enh #17): Add Traditional Chinese translations 48 | - (enh #16): Add Turkish translations 49 | - (enh #15): Add Portugese Brazilian translations 50 | - (enh #13): Add Portugese translations 51 | - (enh #12): Correct typo in readme.md 52 | - (enh #10): Add German translations 53 | - Enhance KrajeeDialog variables to be registered in global namespace. 54 | 55 | ## Version 1.0.1 56 | 57 | **Date:** 13-Sep-2016 58 | 59 | - Initialize all common language i18n message files. 60 | - Enhance PHP Documentation for all classes and methods in the extension. 61 | - (enh #9): Allow configuration of krajee dialog JS registration position. 62 | - (enh #7): Update Polish Translations. 63 | - (enh #6): Add Polish Translations. 64 | - (enh #4,#5): Add Ukranian Translations. 65 | - Add github contribution and issue/PR logging templates. 66 | - (enh #3): Add Chinese Translations. 67 | 68 | ## Version 1.0.0 69 | 70 | **Date:** 22-Feb-2016 71 | 72 | - Initial release 73 | - (enh #1): Add Dutch translations 74 | -------------------------------------------------------------------------------- /src/assets/css/bootstrap-dialog-bs3.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Bootstrap 3.x styling for bootstrap-dialog plugin. 8 | * 9 | * For more JQuery plugins visit http://plugins.krajee.com 10 | * For more Yii related demos visit http://demos.krajee.com 11 | */.bootstrap-dialog .modal-header{border-top-left-radius:4px;border-top-right-radius:4px}.bootstrap-dialog .btn-modal-close{margin:-5px;background:0 0;border-radius:50%}.bootstrap-dialog .modal-header.bootstrap-dialog-draggable{cursor:move}.bootstrap-dialog .bootstrap-dialog-title{color:#fff;display:inline-block;font-size:16px}.bootstrap-dialog .bootstrap-dialog-message{font-size:14px}.bootstrap-dialog .bootstrap-dialog-button-icon{margin-right:3px}.bootstrap-dialog .bootstrap-dialog-close-button{font-size:20px;float:right;opacity:.9;filter:alpha(opacity=90)}.bootstrap-dialog .bootstrap-dialog-close-button:hover{cursor:pointer;opacity:1;filter:alpha(opacity=100)}.bootstrap-dialog.type-default .modal-header{background-color:#fff}.bootstrap-dialog.type-default .bootstrap-dialog-title{color:#333}.bootstrap-dialog.type-info .modal-header{background-color:#5bc0de}.bootstrap-dialog.type-primary .modal-header{background-color:#337ab7}.bootstrap-dialog.type-success .modal-header{background-color:#5cb85c}.bootstrap-dialog.type-warning .modal-header{background-color:#f0ad4e}.bootstrap-dialog.type-danger .modal-header{background-color:#d9534f}.bootstrap-dialog.size-large .bootstrap-dialog-title{font-size:24px}.bootstrap-dialog.size-large .bootstrap-dialog-close-button{font-size:30px}.bootstrap-dialog.size-large .bootstrap-dialog-message{font-size:18px}.bootstrap-dialog .icon-spin{display:inline-block;-moz-animation:spin 2s infinite linear;-o-animation:spin 2s infinite linear;-webkit-animation:spin 2s infinite linear;animation:spin 2s infinite linear}@-moz-keyframes spin{0%{-moz-transform:rotate(0)}100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0)}100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0)}100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(359deg)}} -------------------------------------------------------------------------------- /src/assets/js/dialog.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Provides a polyfill for javascript native alert, confirm, and prompt boxes. The BootstrapDialog 8 | * will be used if available or needed, else the javascript native dialogs will be rendered. 9 | * 10 | * For more JQuery plugins visit http://plugins.krajee.com 11 | * For more Yii related demos visit http://demos.krajee.com 12 | */ 13 | var KrajeeDialog;!function(){"use strict";var t,o;t=function(t,o){try{return window[t](o)}catch(o){return"confirm"===t||null}},o=function(t){return"object"==typeof t?t:{}},(KrajeeDialog=function(t,e,n){n=n||{},this.useBsDialog=t,this.options=o(e),this.defaults=o(n)}).prototype={constructor:KrajeeDialog,usePlugin:function(){return this.useBsDialog&&!!window.BootstrapDialog},getOpts:function(t){return window.jQuery.extend(!0,{},this.defaults[t],this.options)},_dialog:function(o,e,n){var a,i;if("function"!=typeof n)throw"Invalid callback passed for KrajeeDialog."+o;this.usePlugin()?"prompt"!==o?((a=this.getOpts(o)).message=e,"confirm"===o?(a.callback=n,window.BootstrapDialog.confirm(a)):window.BootstrapDialog.show(a)):this.bdPrompt(e,n):(i=t(o,e))&&n(i)},alert:function(t,o){var e=this.getOpts("alert");this.usePlugin()?(e.message=t,e.callback=o,window.BootstrapDialog.alert(e)):window.alert(t)},confirm:function(t,o){this._dialog("confirm",t,o)},prompt:function(t,o){this._dialog("prompt",t,o)},dialog:function(t,o){this._dialog("dialog",t,o)},bdPrompt:function(t,o){var e,n,a,i,l,r="",s=this.getOpts("prompt");for(e=[{id:"btn-cancel",label:"Cancel",cssClass:"btn btn-default",action:function(t){t.close(),o(null)}},{id:"btn-ok",label:"Ok",cssClass:"btn btn-primary",action:function(t){var e;e=t.getModalBody().find("input")[0].value||"",o(e),t.close()}}],n=s.buttons||[],"object"==typeof t?(a=$(document.createElement("div")),i=$(document.createElement("input")),void 0===t.name&&i.attr("name","krajee-dialog-prompt"),void 0===t.type&&i.attr("type","text"),void 0===t.class&&i.addClass("form-control"),$.each(t,function(t,o){"label"!==t&&i.attr(t,o)}),void 0!==t.label&&(r='"),a.append(i),r+=a.html(),i.remove(),a.remove()):r=t,s.message=r,l=0;l __DIR__ . DIRECTORY_SEPARATOR . '..', 5 | // string, required, root directory containing message translations. 6 | 'messagePath' => __DIR__, 7 | // array, required, list of language codes that the extracted messages 8 | // should be translated to. For example, ['zh-CN', 'de']. 9 | 'languages' => ['af', 'ar', 'az', 'bg', 'bs', 'ca', 'cs', 'da', 'de', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr', 'gl', 'gu', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'ka', 'kk', 'kn', 'ko', 'ky', 'lt', 'lv', 'mi', 'mk', 'mn', 'mr', 'ms', 'mt', 'nb', 'nl', 'nn', 'pl', 'pt', 'pt-BR', 'qu', 'ro', 'ru', 'sa', 'se', 'sk', 'sl', 'sq', 'sr', 'sr-Latn', 'sv', 'sw', 'ta', 'te', 'th', 'tj', 'tl', 'tn', 'tr', 'ts', 'tt', 'uk', 'ur', 'uz-Cy', 'vi', 'zh-CN', 'zh-TW', 'zu'], 10 | // string, the name of the function for translating messages. 11 | // Defaults to 'Yii::t'. This is used as a mark to find the messages to be 12 | // translated. You may use a string for single function name or an array for 13 | // multiple function names. 14 | 'translator' => 'Yii::t', 15 | // boolean, whether to sort messages by keys when merging new messages 16 | // with the existing ones. Defaults to false, which means the new (untranslated) 17 | // messages will be separated from the old (translated) ones. 18 | 'sort' => false, 19 | // boolean, whether the message file should be overwritten with the merged messages 20 | 'overwrite' => true, 21 | // boolean, whether to remove messages that no longer appear in the source code. 22 | // Defaults to false, which means each of these messages will be enclosed with a pair of '' marks. 23 | 'removeUnused' => false, 24 | // array, list of patterns that specify which files/directories should NOT be processed. 25 | // If empty or not set, all files/directories will be processed. 26 | // A path matches a pattern if it contains the pattern string at its end. For example, 27 | // '/a/b' will match all files and directories ending with '/a/b'; 28 | // the '*.svn' will match all files and directories whose name ends with '.svn'. 29 | // and the '.svn' will match all files and directories named exactly '.svn'. 30 | // Note, the '/' characters in a pattern matches both '/' and '\'. 31 | // See helpers/FileHelper::findFiles() description for more details on pattern matching rules. 32 | 'only' => ['*.php'], 33 | // array, list of patterns that specify which files (not directories) should be processed. 34 | // If empty or not set, all files will be processed. 35 | // Please refer to "except" for details about the patterns. 36 | // If a file/directory matches both a pattern in "only" and "except", it will NOT be processed. 37 | 'except' => [ 38 | '.svn', 39 | '.git', 40 | '.gitignore', 41 | '.gitkeep', 42 | '.hgignore', 43 | '.hgkeep', 44 | '/messages', 45 | ], 46 | // Generated file format. Can be either "php", "po" or "db". 47 | 'format' => 'php', 48 | // When format is "db", you may specify the following two options 49 | //'db' => 'db', 50 | //'sourceMessageTable' => '{{%source_message}}', 51 | ]; 52 | -------------------------------------------------------------------------------- /src/assets/css/bootstrap-dialog-bs4.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Bootstrap 4.x styling for bootstrap-dialog plugin. 8 | * 9 | * For more JQuery plugins visit http://plugins.krajee.com 10 | * For more Yii related demos visit http://demos.krajee.com 11 | */ 12 | .bootstrap-dialog .modal-header { 13 | border-top-left-radius: 0.25rem; 14 | border-top-right-radius: 0.25rem; 15 | } 16 | 17 | .bootstrap-dialog .btn-modal-close { 18 | padding: 0 5px; 19 | margin: -5px; 20 | background: none; 21 | border: none; 22 | border-radius: 50%; 23 | } 24 | 25 | .bootstrap-dialog .modal-header.bootstrap-dialog-draggable { 26 | cursor: move; 27 | } 28 | 29 | .bootstrap-dialog .bootstrap-dialog-title { 30 | display: inline-block; 31 | } 32 | 33 | .bootstrap-dialog .bootstrap-dialog-message { 34 | font-size: 0.875rem; 35 | } 36 | 37 | .bootstrap-dialog .bootstrap-dialog-button-icon { 38 | margin-right: 0.1875rem; 39 | } 40 | 41 | .bootstrap-dialog .bootstrap-dialog-close-button:hover { 42 | cursor: pointer; 43 | opacity: 1; 44 | filter: alpha(opacity=100); 45 | } 46 | 47 | @media (min-width: 1172px) { 48 | .bootstrap-dialog .modal-xl { 49 | max-width: 95%; 50 | } 51 | } 52 | 53 | .bootstrap-dialog.type-default .modal-header { 54 | background-color: #fff; 55 | } 56 | 57 | .bootstrap-dialog.type-default .bootstrap-dialog-title { 58 | color: #333; 59 | } 60 | 61 | .bootstrap-dialog-footer-buttons { 62 | text-align: right; 63 | } 64 | 65 | .bootstrap-dialog-footer-buttons > :not(:last-child) { 66 | margin-right: .25rem; 67 | } 68 | 69 | .bootstrap-dialog .icon-spin { 70 | display: inline-block; 71 | -moz-animation: spin 2s infinite linear; 72 | -o-animation: spin 2s infinite linear; 73 | -webkit-animation: spin 2s infinite linear; 74 | animation: spin 2s infinite linear; 75 | } 76 | 77 | @-moz-keyframes spin { 78 | 0% { 79 | -moz-transform: rotate(0deg); 80 | } 81 | 100% { 82 | -moz-transform: rotate(359deg); 83 | } 84 | } 85 | 86 | @-webkit-keyframes spin { 87 | 0% { 88 | -webkit-transform: rotate(0deg); 89 | } 90 | 100% { 91 | -webkit-transform: rotate(359deg); 92 | } 93 | } 94 | 95 | @-o-keyframes spin { 96 | 0% { 97 | -o-transform: rotate(0deg); 98 | } 99 | 100% { 100 | -o-transform: rotate(359deg); 101 | } 102 | } 103 | 104 | @-ms-keyframes spin { 105 | 0% { 106 | -ms-transform: rotate(0deg); 107 | } 108 | 100% { 109 | -ms-transform: rotate(359deg); 110 | } 111 | } 112 | 113 | @keyframes spin { 114 | 0% { 115 | transform: rotate(0deg); 116 | } 117 | 100% { 118 | transform: rotate(359deg); 119 | } 120 | } 121 | 122 | .bootstrap-dialog .modal-lg .bootstrap-dialog-title { 123 | font-size: 1.25rem; 124 | } 125 | 126 | .bootstrap-dialog .modal-lg .bootstrap-dialog-message, 127 | .bootstrap-dialog .modal-lg .btn-lg { 128 | font-size: 1.0625rem; 129 | } 130 | 131 | .bootstrap-dialog .modal-lg .bootstrap-dialog-close-button .close { 132 | font-size: 1.765rem; 133 | } -------------------------------------------------------------------------------- /src/assets/css/bootstrap-dialog-bs3.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Bootstrap 3.x styling for bootstrap-dialog plugin. 8 | * 9 | * For more JQuery plugins visit http://plugins.krajee.com 10 | * For more Yii related demos visit http://demos.krajee.com 11 | */ 12 | .bootstrap-dialog .modal-header { 13 | border-top-left-radius: 4px; 14 | border-top-right-radius: 4px; 15 | } 16 | .bootstrap-dialog .btn-modal-close { 17 | margin: -5px; 18 | background: none; 19 | border-radius: 50%; 20 | } 21 | .bootstrap-dialog .modal-header.bootstrap-dialog-draggable { 22 | cursor: move; 23 | } 24 | .bootstrap-dialog .bootstrap-dialog-title { 25 | color: #fff; 26 | display: inline-block; 27 | font-size: 16px; 28 | } 29 | .bootstrap-dialog .bootstrap-dialog-message { 30 | font-size: 14px; 31 | } 32 | .bootstrap-dialog .bootstrap-dialog-button-icon { 33 | margin-right: 3px; 34 | } 35 | .bootstrap-dialog .bootstrap-dialog-close-button { 36 | font-size: 20px; 37 | float: right; 38 | opacity: 0.9; 39 | filter: alpha(opacity=90); 40 | } 41 | .bootstrap-dialog .bootstrap-dialog-close-button:hover { 42 | cursor: pointer; 43 | opacity: 1; 44 | filter: alpha(opacity=100); 45 | } 46 | .bootstrap-dialog.type-default .modal-header { 47 | background-color: #ffffff; 48 | } 49 | .bootstrap-dialog.type-default .bootstrap-dialog-title { 50 | color: #333; 51 | } 52 | .bootstrap-dialog.type-info .modal-header { 53 | background-color: #5bc0de; 54 | } 55 | .bootstrap-dialog.type-primary .modal-header { 56 | background-color: #337ab7; 57 | } 58 | .bootstrap-dialog.type-success .modal-header { 59 | background-color: #5cb85c; 60 | } 61 | .bootstrap-dialog.type-warning .modal-header { 62 | background-color: #f0ad4e; 63 | } 64 | .bootstrap-dialog.type-danger .modal-header { 65 | background-color: #d9534f; 66 | } 67 | .bootstrap-dialog.size-large .bootstrap-dialog-title { 68 | font-size: 24px; 69 | } 70 | .bootstrap-dialog.size-large .bootstrap-dialog-close-button { 71 | font-size: 30px; 72 | } 73 | .bootstrap-dialog.size-large .bootstrap-dialog-message { 74 | font-size: 18px; 75 | } 76 | .bootstrap-dialog .icon-spin { 77 | display: inline-block; 78 | -moz-animation: spin 2s infinite linear; 79 | -o-animation: spin 2s infinite linear; 80 | -webkit-animation: spin 2s infinite linear; 81 | animation: spin 2s infinite linear; 82 | } 83 | @-moz-keyframes spin { 84 | 0% { 85 | -moz-transform: rotate(0deg); 86 | } 87 | 100% { 88 | -moz-transform: rotate(359deg); 89 | } 90 | } 91 | @-webkit-keyframes spin { 92 | 0% { 93 | -webkit-transform: rotate(0deg); 94 | } 95 | 100% { 96 | -webkit-transform: rotate(359deg); 97 | } 98 | } 99 | @-o-keyframes spin { 100 | 0% { 101 | -o-transform: rotate(0deg); 102 | } 103 | 100% { 104 | -o-transform: rotate(359deg); 105 | } 106 | } 107 | @-ms-keyframes spin { 108 | 0% { 109 | -ms-transform: rotate(0deg); 110 | } 111 | 100% { 112 | -ms-transform: rotate(359deg); 113 | } 114 | } 115 | @keyframes spin { 116 | 0% { 117 | transform: rotate(0deg); 118 | } 119 | 100% { 120 | transform: rotate(359deg); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/assets/js/dialog.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Provides a polyfill for javascript native alert, confirm, and prompt boxes. The BootstrapDialog 8 | * will be used if available or needed, else the javascript native dialogs will be rendered. 9 | * 10 | * For more JQuery plugins visit http://plugins.krajee.com 11 | * For more Yii related demos visit http://demos.krajee.com 12 | */ 13 | var KrajeeDialog; 14 | (function () { 15 | "use strict"; 16 | var nativeDialog, parseOptions; 17 | 18 | nativeDialog = function (type, message) { 19 | try { 20 | return window[type](message); 21 | } 22 | catch (err) { 23 | return type === 'confirm' ? true : null; 24 | } 25 | }; 26 | 27 | parseOptions = function (options) { 28 | return typeof(options) === 'object' ? options : {}; 29 | }; 30 | 31 | KrajeeDialog = function (useBsDialog, options, defaults) { 32 | var self = this; 33 | defaults = defaults || {}; 34 | self.useBsDialog = useBsDialog; 35 | self.options = parseOptions(options); 36 | self.defaults = parseOptions(defaults); 37 | }; 38 | 39 | KrajeeDialog.prototype = { 40 | constructor: KrajeeDialog, 41 | usePlugin: function () { 42 | return this.useBsDialog && !!window.BootstrapDialog; 43 | }, 44 | getOpts: function (type) { 45 | var self = this; 46 | return window.jQuery.extend(true, {}, self.defaults[type], self.options); 47 | }, 48 | _dialog: function (type, message, callback) { 49 | var self = this, opts, out; 50 | if (typeof callback !== "function") { 51 | throw "Invalid callback passed for KrajeeDialog." + type; 52 | } 53 | if (!self.usePlugin()) { 54 | out = nativeDialog(type, message); 55 | if (out) { 56 | callback(out); 57 | } 58 | return; 59 | } 60 | if (type === 'prompt') { 61 | self.bdPrompt(message, callback); 62 | return; 63 | } 64 | opts = self.getOpts(type); 65 | opts.message = message; 66 | if (type === 'confirm') { 67 | opts.callback = callback; 68 | window.BootstrapDialog.confirm(opts); 69 | } else { 70 | window.BootstrapDialog.show(opts); 71 | } 72 | }, 73 | alert: function (message, callback) { 74 | var self = this, opts = self.getOpts('alert'); 75 | if (self.usePlugin()) { 76 | opts.message = message; 77 | opts.callback = callback; 78 | window.BootstrapDialog.alert(opts); 79 | } else { 80 | window.alert(message); 81 | } 82 | }, 83 | confirm: function (message, callback) { 84 | this._dialog('confirm', message, callback); 85 | }, 86 | prompt: function (message, callback) { 87 | this._dialog('prompt', message, callback); 88 | }, 89 | dialog: function (message, callback) { 90 | this._dialog('dialog', message, callback); 91 | }, 92 | bdPrompt: function (input, callback) { 93 | var self = this, msg = '', opts = self.getOpts('prompt'), cbOk, cbCancel, defaultButtons, 94 | buttons, $inputDiv, $input, attr = '', i; 95 | cbOk = function (dialog) { 96 | var data, $body = dialog.getModalBody(); 97 | data = $body.find("input")[0].value || ''; 98 | callback(data); 99 | dialog.close(); 100 | }; 101 | cbCancel = function (dialog) { 102 | dialog.close(); 103 | callback(null); 104 | }; 105 | defaultButtons = [ 106 | {id: 'btn-cancel', label: 'Cancel', cssClass: 'btn btn-default', action: cbCancel}, 107 | {id: 'btn-ok', label: 'Ok', cssClass: 'btn btn-primary', action: cbOk} 108 | ]; 109 | buttons = opts.buttons || []; 110 | if (typeof input === "object") { 111 | $inputDiv = $(document.createElement('div')); 112 | $input = $(document.createElement('input')); 113 | if (input['name'] === undefined) { 114 | $input.attr('name', 'krajee-dialog-prompt'); 115 | } 116 | if (input['type'] === undefined) { 117 | $input.attr('type', 'text'); 118 | } 119 | if (input['class'] === undefined) { 120 | $input.addClass('form-control'); 121 | } 122 | $.each(input, function(key, val) { 123 | if (key !== 'label') { 124 | $input.attr(key, val); 125 | } 126 | }); 127 | if (input.label !== undefined) { 128 | msg = ''; 129 | } 130 | $inputDiv.append($input); 131 | msg += $inputDiv.html(); 132 | $input.remove(); 133 | $inputDiv.remove(); 134 | } else { 135 | msg = input; 136 | } 137 | opts.message = msg; 138 | for (i = 0; i < defaultButtons.length; i++) { 139 | buttons[i] = window.jQuery.extend(true, {}, defaultButtons[i], buttons[i]); 140 | } 141 | opts.buttons = buttons; 142 | window.BootstrapDialog.show(opts); 143 | } 144 | }; 145 | })(); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Krajee Logo 4 | 5 |
6 | yii2-dialog 7 |
8 | 10 | Donate 11 | 12 |

13 | 14 | [![Stable Version](https://poser.pugx.org/kartik-v/yii2-dialog/v/stable)](https://packagist.org/packages/kartik-v/yii2-dialog) 15 | [![Unstable Version](https://poser.pugx.org/kartik-v/yii2-dialog/v/unstable)](https://packagist.org/packages/kartik-v/yii2-dialog) 16 | [![License](https://poser.pugx.org/kartik-v/yii2-dialog/license)](https://packagist.org/packages/kartik-v/yii2-dialog) 17 | [![Total Downloads](https://poser.pugx.org/kartik-v/yii2-dialog/downloads)](https://packagist.org/packages/kartik-v/yii2-dialog) 18 | [![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-dialog/d/monthly)](https://packagist.org/packages/kartik-v/yii2-dialog) 19 | [![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-dialog/d/daily)](https://packagist.org/packages/kartik-v/yii2-dialog) 20 | 21 | A widget component for Yii Framework 2.0 to easily configure and initialize popup notification dialog boxes. It provides a polyfill for 22 | the native javascript alert, confirm, and prompt dialog boxes. It includes inbuilt support for rendering rich dialog boxes via a customized 23 | plugin by Krajee based on and enhanced from [bootstrap3-dialog](http://nakupanda.github.io/bootstrap3-dialog/). This plugin makes using Bootstrap's 24 | modal more monkey-friendly. The Krajee enhancements also includes enhanced support for Bootstrap 5.x, 4.x and 3.x. The key features provided by 25 | the library are: 26 | 27 | - Control how you want to render JAVASCRIPT dialogs. Inbuilt quick support for following dialog types: 28 | - ALERT dialog 29 | - CONFIRM dialog 30 | - PROMPT dialog 31 | - CUSTOM dialog 32 | - Includes a jQuery plugin `krajeeDialog` (created by Krajee), that allows one to configure the bootstrap3-dialog library easily, or use the native JS alerting component, OR also configure any third party JS Notification Library to be used. 33 | - Ability to render pretty dialogs by overriding and enhancing confirmation dialog for links that use yii's `data-confirm` methods. 34 | - Advanced configuration via `kartik\dialog\Dialog` widget. This widget allows one to globally setup the native JS alert OR bootstrap3-dialog settings. 35 | 36 | How to contribute via a pull request? 37 | ------------------------------------- 38 | Refer this [git workflow for contributors](.github/GIT-WORKFLOW.md). 39 | 40 | ## Installation 41 | 42 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 43 | 44 | ### Pre-requisites 45 | > Note: Check the [composer.json](https://github.com/kartik-v/yii2-dialog/blob/master/composer.json) for this extension's requirements and dependencies. 46 | You must set the `minimum-stability` to `dev` in the **composer.json** file in your application root folder before installation of this extension OR 47 | if your `minimum-stability` is set to any other value other than `dev`, then set the following in the require section of your composer.json file 48 | 49 | ``` 50 | kartik-v/yii2-dialog: "@dev" 51 | ``` 52 | 53 | Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json. 54 | 55 | ### Release Changes 56 | Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-dialog/blob/master/CHANGE.md) for details of various releases. 57 | 58 | ### Install 59 | 60 | Either run 61 | 62 | ``` 63 | $ php composer.phar require kartik-v/yii2-dialog "@dev" 64 | ``` 65 | 66 | or add 67 | 68 | ``` 69 | "kartik-v/yii2-dialog": "@dev" 70 | ``` 71 | 72 | to the ```require``` section of your `composer.json` file. 73 | 74 | ## Documentation and Demo 75 | 76 | View the [documentation and demos](http://demos.krajee.com/dialog) at Krajee Yii 2 Demos for details on using the extension. 77 | 78 | ## Usage 79 | 80 | ### Basic Usage 81 | 82 | In your view you can load the asset bundle and render the javascript to load the bootstrap 3 modal dialog. 83 | 84 | ```php 85 | // view.php 86 | use kartik\dialog\DialogAsset; 87 | DialogAsset::register($this); 88 | $this->registerJs("\$('#your-btn-id').on('click', function(){BootstrapDialog.alert('I want banana!');});"); 89 | ``` 90 | 91 | ### Advanced Usage (Widget) 92 | 93 | In your view OR view layout file, you can render the widget like this. This will not display any content directly - but will render all the javascript and css needed for initializing the BootstrapDialog as per your customized settings. 94 | 95 | ```php 96 | use kartik\dialog\Dialog; 97 | 98 | // Example 1 99 | echo Dialog::widget([ 100 | 'libName' => 'krajeeDialog', 101 | 'options' => [], // default options 102 | ]); 103 | 104 | // Example 2 105 | echo Dialog::widget([ 106 | 'libName' => 'krajeeDialogCust', 107 | 'options' => ['draggable' => true, 'closable' => true], // custom options 108 | ]); 109 | ``` 110 | 111 | Then in your view, you can write your own javascript to render your alert, confirm, and prompt boxes (or a custom dialog box). For example on click of HTML buttons `btn-1` and `btn-2`, the dialogs can be popped up as shown below: 112 | 113 | ```js 114 | // NOTE: This is a javascript code and must be run in Yii via 'registerJs' 115 | // or via a JS File in an AssetBundle 116 | 117 | // use krajeeDialog object instance initialized by the widget 118 | $('#btn-1').on('click', function() { 119 | krajeeDialog.alert('An alert'); 120 | // or show a confirm 121 | krajeeDialog.confirm('Are you sure', function(out){ 122 | if(out) { 123 | alert('Yes'); // or do something on confirmation 124 | } 125 | }); 126 | }); 127 | 128 | // use krajeeDialogCust object instance 129 | $('#btn-2').on('click', function() { 130 | krajeeDialogCust.alert('An alert'); 131 | // or show a prompt 132 | krajeeDialogCust.prompt({label:'Provide reason', placeholder:'Upto 30 characters...'}, function(out){ 133 | if (out) { 134 | alert('Yes'); // or do something based on the value of out 135 | } 136 | }); 137 | }); 138 | ``` 139 | 140 | ### Overriding Yii's Confirmation Dialog 141 | 142 | Yii renders the native confirmation dialog on links that are rendered by setting `data-confirm` property on links. This widget 143 | enhances and beautifies the native confirmation dialog using Krajee Dialog. This behavior can be controlled via the `overrideYiiConfirm` 144 | property which defaults to `true`. This can be useful in rendering links and action buttons like the GridView ActionColumn 145 | delete button. 146 | 147 | ```php 148 | // the rendered link will automatically show a Krajee Dialog Confirmation dialog 149 | use kartik\dialog\Dialog; 150 | echo Dialog::widget(['overrideYiiConfirm' => true]); 151 | echo Html::a( 152 | 'Delete', 153 | ['/item/delete', 'id' => $model->id], 154 | [ 155 | 'data-confirm' => 'Are you sure to delete this item?' 156 | 'data-method' => 'post' 157 | ] 158 | ); 159 | ``` 160 | 161 | ## License 162 | 163 | **yii2-dialog** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details. -------------------------------------------------------------------------------- /.github/GIT-WORKFLOW.md: -------------------------------------------------------------------------------- 1 | Git workflow for yii2-dialog contributors 2 | ========================================= 3 | 4 | So you want to contribute to yii2-dialog? Great! But to increase the chances of your changes being accepted quickly, please 5 | follow the following steps. If you are new to Git and GitHub, you might want to first check out [GitHub help](http://help.github.com/), [try Git](https://try.github.com) 6 | or learn something about [Git internal data model](http://nfarina.com/post/9868516270/git-is-simpler). 7 | 8 | Setup the development environment 9 | --------------------------------- 10 | 11 | Assuming you already have a yii2 development environment, carry out the following steps to create a development environment for the repo. 12 | 13 | ### 1. [Fork](http://help.github.com/fork-a-repo/) the yii2-dialog repository on GitHub and clone your fork to your development environment 14 | 15 | ``` 16 | git clone git@github.com:YOUR-GITHUB-USERNAME/yii2-dialog.git 17 | ``` 18 | 19 | If you have trouble setting up Git with GitHub in Linux, or are getting errors like "Permission Denied (publickey)", 20 | then you must [setup your Git installation to work with GitHub](http://help.github.com/linux-set-up-git/) 21 | 22 | > Tip: if you're not fluent with Git, we recommend reading excellent free [Pro Git book](https://git-scm.com/book/en/v2). 23 | 24 | ### 2. Add the main yii2-dialog repository as an additional git remote called "upstream" 25 | 26 | Change to the directory where you cloned yii2-dialog, normally, "yii2-dialog". Then enter the following command: 27 | 28 | ``` 29 | git remote add upstream git://github.com/kartik-v/yii2-dialog.git 30 | ``` 31 | 32 | ### 3. Prepare the testing environment 33 | 34 | - You should have a working yii 2 development environment in which you have already installed `yii2-dialog` and includes latest and updated `yii2-dialog` fork from source. 35 | - Ensure you have the latest `dev-master` releases of all dependent extensions via your composer updates 36 | - Ensure you use the above cloned latest `yii2-dialog` code in your testing environment 37 | 38 | **Now you have a working playground for hacking on yii2-dialog.** 39 | 40 | Working on bugs and features 41 | ---------------------------- 42 | 43 | Having prepared your development environment as explained above you can now start working on the feature or bugfix. 44 | 45 | ### 1. Make sure there is an issue created for the thing you are working on if it requires significant effort to fix 46 | 47 | All new features and bug fixes should have an associated issue to provide a single point of reference for discussion 48 | and documentation. Take a few minutes to look through the existing issue list for one that matches the contribution you 49 | intend to make. If you find one already on the issue list, then please leave a comment on that issue indicating you 50 | intend to work on that item. If you do not find an existing issue matching what you intend to work on, please 51 | open a new issue or create a pull request directly if it is straightforward fix. This will allow the team to 52 | review your suggestion, and provide appropriate feedback along the way. 53 | 54 | > For small changes or documentation issues or straightforward fixes, you don't need to create an issue, a pull request is enough in this case. 55 | 56 | ### 2. Fetch the latest code from the main yii2-dialog branch 57 | 58 | ``` 59 | git fetch upstream 60 | ``` 61 | 62 | You should start at this point for every new contribution to make sure you are working on the latest code. 63 | 64 | ### 3. Create a new branch for your feature based on the current yii2-dialog master branch 65 | 66 | > That's very important since you will not be able to submit more than one pull request from your account if you'll 67 | use master. 68 | 69 | Each separate bug fix or change should go in its own branch. Branch names should be descriptive and start with 70 | the number of the issue that your code relates to. If you aren't fixing any particular issue, just skip number. 71 | For example: 72 | 73 | ``` 74 | git checkout upstream/master 75 | git checkout -b 999-name-of-your-branch-goes-here 76 | ``` 77 | 78 | ### 4. Do your magic, write your code 79 | 80 | Make sure you have first updated the testing environment as mentioned in [prepare-the-testing-environment][prepare-the-testing-environment]. 81 | 82 | Then make sure you have the updated code with your change and it works :). 83 | 84 | Unit tests are always welcome. Tested and well covered code greatly simplifies the task of checking your contributions. 85 | Failing unit tests as issue description are also accepted. 86 | 87 | ### 5. Update the CHANGE log 88 | 89 | Edit the `CHANGE.md` file to include your change, you should insert this at the top of the file under the 90 | first heading (the version that is currently under development), the line in the change log should look like one of the following: 91 | 92 | ``` 93 | Bug #999: a description of the bug fix (Your Name) 94 | Enh #999: a description of the enhancement (Your Name) 95 | ``` 96 | 97 | `#999` is the issue number that the `Bug` or `Enh` is referring to. 98 | The changelog should be grouped by type (`Bug`,`Enh`) and ordered by issue number. 99 | 100 | For very small fixes, e.g. typos and documentation changes, there is no need to update the `CHANGE.md`. 101 | 102 | ### 6. Commit your changes 103 | 104 | add the files/changes you want to commit to the [staging area](http://gitref.org/basic/#add) with 105 | 106 | ``` 107 | git add path/to/my/file.php 108 | ``` 109 | 110 | You can use the `-p` option to select the changes you want to have in your commit. 111 | 112 | Commit your changes with a descriptive commit message. Make sure to mention the ticket number with `#XXX` so GitHub will 113 | automatically link your commit with the ticket: 114 | 115 | ``` 116 | git commit -m "A brief description of this change which fixes #999 goes here" 117 | ``` 118 | 119 | ### 7. Pull the latest yii2-dialog code from upstream into your branch 120 | 121 | ``` 122 | git pull upstream master 123 | ``` 124 | 125 | This ensures you have the latest code in your branch before you open your pull request. If there are any merge conflicts, 126 | you should fix them now and commit the changes again. This ensures that it's easy for the yii2-dialog team to merge your changes 127 | with one click. 128 | 129 | ### 8. Having resolved any conflicts, push your code to GitHub 130 | 131 | ``` 132 | git push -u origin 999-name-of-your-branch-goes-here 133 | ``` 134 | 135 | The `-u` parameter ensures that your branch will now automatically push and pull from the GitHub branch. That means 136 | if you type `git push` the next time it will know where to push to. This is useful if you want to later add more commits 137 | to the pull request. 138 | 139 | ### 9. Open a [pull request](http://help.github.com/send-pull-requests/) against upstream. 140 | 141 | Go to your repository on GitHub and click "Pull Request", choose your branch on the right and enter some more details 142 | in the comment box. To link the pull request to the issue put anywhere in the pull comment `#999` where 999 is the 143 | issue number. 144 | 145 | > Note that each pull-request should fix a single change. For multiple, unrelated changes, please open multiple pull requests. 146 | 147 | ### 10. Someone will review your code 148 | 149 | Someone will review your code, and you might be asked to make some changes, if so go to step #6 (you don't need to open 150 | another pull request if your current one is still open). If your code is accepted it will be merged into the main branch 151 | and become part of the next yii2-dialog release. If not, don't be disheartened, different people need different features and yii2-dialog 152 | can't be everything to everyone, your code will still be available on GitHub as a reference for people who need it. 153 | 154 | ### 11. Cleaning it up 155 | 156 | After your code was either accepted or declined you can delete branches you've worked with from your local repository 157 | and `origin`. 158 | 159 | ``` 160 | git checkout master 161 | git branch -D 999-name-of-your-branch-goes-here 162 | git push origin --delete 999-name-of-your-branch-goes-here 163 | ``` 164 | 165 | ### Command overview (for advanced contributors) 166 | 167 | ``` 168 | git clone git@github.com:YOUR-GITHUB-USERNAME/yii2-dialog.git 169 | git remote add upstream git://github.com/kartik-v/yii2-dialog.git 170 | ``` 171 | 172 | ``` 173 | git fetch upstream 174 | git checkout upstream/master 175 | git checkout -b 999-name-of-your-branch-goes-here 176 | 177 | /* do your magic, update changelog if needed */ 178 | 179 | git add path/to/my/file.php 180 | git commit -m "A brief description of this change which fixes #999 goes here" 181 | git pull upstream master 182 | git push -u origin 999-name-of-your-branch-goes-here 183 | ``` 184 | 185 | [prepare-the-testing-environment]: #3-prepare-the-testing-environment -------------------------------------------------------------------------------- /src/Dialog.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 7 | * @version 1.0.6 8 | */ 9 | 10 | namespace kartik\dialog; 11 | 12 | use Exception; 13 | use ReflectionException; 14 | use Yii; 15 | use kartik\base\Widget; 16 | use yii\base\InvalidConfigException; 17 | use yii\helpers\Json; 18 | use yii\web\View; 19 | 20 | /** 21 | * Dialog widget allows an easy configuration to control javascript dialogs and also generate rich styled bootstrap 22 | * modal dialogs using [bootstrap3-dialog](https://github.com/nakupanda/bootstrap3-dialog) plugin. The widget provides 23 | * its own advanced javascript library `KrajeeDialog` that acts a polyfill for the native javascript alert, confirm, and 24 | * prompt dialog boxes. 25 | * 26 | * **Example 1: ** Usage for a default dialog. 27 | * 28 | * ```php 29 | * echo Dialog::widget([ 30 | * 'libName' => 'krajeeDialog', 31 | * 'options => [], // default options 32 | * ]); 33 | *``` 34 | * 35 | * **Example 2: ** Usage for a customized dialog. 36 | * 37 | * ```php 38 | * echo Dialog::widget([ 39 | * 'libName' => 'krajeeDialogCust', 40 | * 'options => ['draggable' => true, 'closable' => true], // custom options 41 | * ]); 42 | * ``` 43 | * 44 | * Then you can use your own javascript as shown below to render your alert, confirm, and prompt boxes: 45 | * 46 | * ```js 47 | * // use krajeeDialog object instance 48 | * $('#btn-1').on('click', function() { 49 | * krajeeDialog.alert('An alert'); 50 | * // or show a confirm 51 | * krajeeDialog.confirm('Are you sure', function(out){ 52 | * if(out) { 53 | * alert('Yes'); // or do something on confirmation 54 | * } 55 | * }); 56 | * 57 | * }); 58 | * 59 | * // use krajeeDialogCust object instance 60 | * $('#btn-2').on('click', function() { 61 | * krajeeDialogCust.alert('An alert'); 62 | * // or show a prompt 63 | * krajeeDialogCust.prompt({label:'Provide reason', placeholder:'Upto 30 characters...'}, function(out){ 64 | * if (out) { 65 | * alert('Yes'); // or do something based on the value of out 66 | * } 67 | * }); 68 | * 69 | * }); 70 | * ``` 71 | * 72 | * @author Kartik Visweswaran 73 | * @since 1.0 74 | */ 75 | class Dialog extends Widget 76 | { 77 | /** 78 | * Krajee JS dialog library class name. 79 | */ 80 | const LIBRARY = 'krajeeDialog'; 81 | /** 82 | * Alert method name in the KrajeeDialog JS class. 83 | */ 84 | const DIALOG_ALERT = 'alert'; 85 | /** 86 | * Confirm method name in the KrajeeDialog JS class. 87 | */ 88 | const DIALOG_CONFIRM = 'confirm'; 89 | /** 90 | * Prompt method name in the KrajeeDialog JS class. 91 | */ 92 | const DIALOG_PROMPT = 'prompt'; 93 | /** 94 | * Other dialog method name in the KrajeeDialog JS class. 95 | */ 96 | const DIALOG_OTHER = 'dialog'; 97 | /** 98 | * The **default** bootstrap contextual color type. 99 | */ 100 | const TYPE_DEFAULT = 'type-default'; 101 | /** 102 | * The **primary** bootstrap contextual color type. 103 | */ 104 | const TYPE_PRIMARY = 'type-primary'; 105 | /** 106 | * The **information** bootstrap contextual color type. 107 | */ 108 | const TYPE_INFO = 'type-info'; 109 | /** 110 | * The **danger** bootstrap contextual color type. 111 | */ 112 | const TYPE_DANGER = 'type-danger'; 113 | /** 114 | * The **warning** bootstrap contextual color type. 115 | */ 116 | const TYPE_WARNING = 'type-warning'; 117 | /** 118 | * The **success** bootstrap contextual color type. 119 | */ 120 | const TYPE_SUCCESS = 'type-success'; 121 | /** 122 | * Bootstrap **normal** modal dialog size. 123 | */ 124 | const SIZE_NORMAL = 'size-normal'; 125 | /** 126 | * Bootstrap **small** modal dialog size. 127 | */ 128 | const SIZE_SMALL = 'size-small'; 129 | /** 130 | * Bootstrap **large** modal dialog size. 131 | */ 132 | const SIZE_LARGE = 'size-large'; 133 | /** 134 | * Bootstrap **wide** modal dialog size. The `size-wide` is equal to bootstrap `modal-lg` size. 135 | */ 136 | const SIZE_WIDE = 'size-wide'; 137 | 138 | /** 139 | * @var string icon CSS suffix to be added for the OK button in the dialog. 140 | */ 141 | public $iconOk; 142 | 143 | /** 144 | * @var string icon CSS suffix to be added for the CANCEL button in the dialog. 145 | */ 146 | public $iconCancel; 147 | 148 | /** 149 | * @var string icon CSS suffix to be added for the SPINNER button in the dialog. 150 | */ 151 | public $iconSpinner; 152 | 153 | /** 154 | * @var boolean whether to use the native javascript dialog for rendering the popup prompts. If set to `false`, the 155 | * bootstrap3-dialog library will be used for rendering the prompts as a modal dialog. 156 | */ 157 | public $useNative = false; 158 | 159 | /** 160 | * @var boolean whether to override the yii javascript confirmation dialog (set via `data-confirm`) 161 | * with KrajeeDialog confirmation dialog. 162 | */ 163 | public $overrideYiiConfirm = true; 164 | 165 | /** 166 | * @var string the identifying name of the public javascript id that will hold the settings for KrajeeDialog 167 | * javascript object instance. Defaults to `krajeeDialog`. 168 | */ 169 | public $libName = self::LIBRARY; 170 | 171 | /** 172 | * @var boolean (DEPRECATED) applicable only for versions v1.0.3 and below, where if set to `true` 173 | * will enable a draggable cursor for draggable dialog boxes when dragging. 174 | * 175 | * for v1.0.6 and above the cursor will always be displayed irrespective of this setting 176 | * (which can be controlled via CSS). 177 | */ 178 | public $showDraggable = true; 179 | 180 | /** 181 | * @var array the configuration options for the bootstrap dialog (applicable when [[useNative]] is `false`). You can 182 | * set the configuration settings as key value pairs that can be recognized by the BootstrapDialog plugin. 183 | */ 184 | public $options = []; 185 | 186 | /** 187 | * @var array the default dialog settings for alert, confirm, and prompt. 188 | */ 189 | public $dialogDefaults = []; 190 | 191 | /** 192 | * @var integer the registration position for the Krajee dialog JS client code. 193 | */ 194 | public $jsPosition = View::POS_HEAD; 195 | 196 | /** 197 | * @inheritdoc 198 | */ 199 | protected $_msgCat = 'kvdialog'; 200 | 201 | /** 202 | * @inheritdoc 203 | * @throws ReflectionException 204 | * @throws InvalidConfigException 205 | */ 206 | public function run() 207 | { 208 | $this->initI18N(); 209 | $this->initOptions(); 210 | $this->registerAssets(); 211 | } 212 | 213 | /** 214 | * Initialize the dialog buttons. 215 | * @throws InvalidConfigException|Exception 216 | */ 217 | public function initOptions() 218 | { 219 | $notBs3 = !$this->isBs(3); 220 | $defaultBtnCss = $notBs3 ? 'btn-outline-secondary' : 'btn-default'; 221 | $this->iconOk = $notBs3 ? 'fas fa-check' : 'glyphicon glyphicon-ok'; 222 | $this->iconCancel = $notBs3 ? 'fas fa-ban' : 'glyphicon glyphicon-ban-circle'; 223 | $this->iconSpinner = $notBs3 ? 'fas fa-asterisk' : 'glyphicon glyphicon-asterisk'; 224 | $ok = Yii::t('kvdialog', 'Ok'); 225 | $cancel = Yii::t('kvdialog', 'Cancel'); 226 | $info = Yii::t('kvdialog', 'Information'); 227 | $okLabel = ' ' . $ok; 228 | $cancelLabel = ' ' . ' ' . $cancel; 229 | $promptDialog = $otherDialog = [ 230 | 'draggable' => false, 231 | 'title' => $info, 232 | 'buttons' => [ 233 | ['label' => $cancel, 'icon' => $this->iconCancel, 'cssClass' => $defaultBtnCss], 234 | ['label' => $ok, 'icon' => $this->iconOk, 'cssClass' => 'btn-primary'], 235 | ], 236 | ]; 237 | $otherDialog['draggable'] = true; 238 | $promptDialog['closable'] = false; 239 | $this->dialogDefaults = array_replace_recursive([ 240 | self::DIALOG_ALERT => [ 241 | 'type' => self::TYPE_INFO, 242 | 'title' => $info, 243 | 'buttonLabel' => $okLabel, 244 | ], 245 | self::DIALOG_CONFIRM => [ 246 | 'type' => self::TYPE_WARNING, 247 | 'title' => Yii::t('kvdialog', 'Confirmation'), 248 | 'btnOKClass' => 'btn-warning', 249 | 'btnOKLabel' => $okLabel, 250 | 'btnCancelLabel' => $cancelLabel 251 | ], 252 | self::DIALOG_PROMPT => $promptDialog, 253 | self::DIALOG_OTHER => $otherDialog, 254 | ], $this->dialogDefaults); 255 | } 256 | 257 | /** 258 | * Registers the client assets for [[Dialog]] widget. 259 | */ 260 | public function registerAssets() 261 | { 262 | $view = $this->getView(); 263 | if (!$this->useNative) { 264 | DialogBootstrapAsset::registerBundle($view, $this->bsVersion); 265 | } 266 | DialogAsset::register($view); 267 | $flag = $this->useNative ? 'false' : 'true'; 268 | $opts = Json::encode($this->options); 269 | $optsVar = self::LIBRARY . '_' . hash('crc32', $opts); 270 | $defaults = Json::encode($this->dialogDefaults); 271 | $defaultsVar = self::LIBRARY . 'Defaults_' . hash('crc32', $defaults); 272 | $pos = $this->jsPosition; 273 | $view->registerJs("var {$defaultsVar} = {$defaults};", $pos); 274 | $view->registerJs("var {$optsVar} = {$opts};", $pos); 275 | $view->registerJs("var {$this->libName}=new KrajeeDialog({$flag},{$optsVar},{$defaultsVar});", $pos); 276 | if ($this->overrideYiiConfirm) { 277 | DialogYiiAsset::register($view); 278 | $view->registerJs("krajeeYiiConfirm('{$this->libName}');"); 279 | } 280 | } 281 | } 282 | -------------------------------------------------------------------------------- /src/assets/js/bootstrap-dialog.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2021 5 | * @version 1.0.6 6 | * 7 | * Make use of Bootstrap's modal more monkey-friendly. 8 | * Sourced from: https://github.com/nakupanda/bootstrap3-dialog 9 | * 10 | * Modifications to library by Kartik Visweswaran, Krajee.com 11 | * For yii2-dialog v1.0.6 - adds Bootstrap 4.x & 5.x support. 12 | */!function(t,e){"use strict";"undefined"!=typeof module&&module.exports?module.exports=e(require("jquery"),require("bootstrap")):"function"==typeof define&&define.amd?define("bootstrap-dialog",["jquery","bootstrap"],function(t){return e(t)}):t.BootstrapDialog=e(t.jQuery)}(this,function(t){"use strict";var e=t.fn.modal?t.fn.modal.Constructor:bootstrap?bootstrap.Modal:{},n=function(t,n){return/4\.\d+\.\d+/.test(e.VERSION)||/5\.\d+\.\d+/.test(e.VERSION)?new e(t,n):void e.call(this,t,n)};n.getModalVersion=function(){var t=null;return t="undefined"==typeof e.VERSION?"v3.1":/3\.2\.\d+/.test(e.VERSION)?"v3.2":/3\.3\.[1,2]/.test(e.VERSION)?"v3.3":/4\.\d+\.\d+/.test(e.VERSION)?"v4.1":/5\.\d+\.\d+/.test(e.VERSION)?"v5.1":"v3.3.4"},n.ORIGINAL_BODY_PADDING=parseInt(t("body").css("padding-right")||0,10),n.METHODS_TO_OVERRIDE={},n.METHODS_TO_OVERRIDE["v3.1"]={},n.METHODS_TO_OVERRIDE["v3.2"]={hide:function(e){if(e&&e.preventDefault(),e=t.Event("hide.bs.modal"),this.$element.trigger(e),this.isShown&&!e.isDefaultPrevented()){this.isShown=!1;var n=this.getGlobalOpenedDialogs();0===n.length&&this.$body.removeClass("modal-open"),this.resetScrollbar(),this.escape(),t(document).off("focusin.bs.modal"),this.$element.removeClass("in").attr("aria-hidden",!0).off("click.dismiss.bs.modal"),t.support.transition&&this.$element.hasClass("fade")?this.$element.one("bsTransitionEnd",t.proxy(this.hideModal,this)).emulateTransitionEnd(300):this.hideModal()}}},n.METHODS_TO_OVERRIDE["v3.3"]={setScrollbar:function(){var t=n.ORIGINAL_BODY_PADDING;this.bodyIsOverflowing&&this.$body.css("padding-right",t+this.scrollbarWidth)},resetScrollbar:function(){var t=this.getGlobalOpenedDialogs();0===t.length&&this.$body.css("padding-right",n.ORIGINAL_BODY_PADDING)},hideModal:function(){this.$element.hide(),this.backdrop(t.proxy(function(){var t=this.getGlobalOpenedDialogs();0===t.length&&this.$body.removeClass("modal-open"),this.resetAdjustments(),this.resetScrollbar(),this.$element.trigger("hidden.bs.modal")},this))}},n.METHODS_TO_OVERRIDE["v3.3.4"]=t.extend({},n.METHODS_TO_OVERRIDE["v3.3"]),n.METHODS_TO_OVERRIDE["v4.1"]=t.extend({},n.METHODS_TO_OVERRIDE["v3.3"]),n.METHODS_TO_OVERRIDE["v5.1"]=t.extend({},n.METHODS_TO_OVERRIDE["v4.1"]),n.prototype={constructor:n,getGlobalOpenedDialogs:function(){var e=[];return t.each(i.dialogs,function(t,n){n.isRealized()&&n.isOpened()&&e.push(n)}),e}};var o=e.prototype||null;n.prototype=t.extend(n.prototype,o,n.METHODS_TO_OVERRIDE[n.getModalVersion()]);var i=function(e){this.defaultOptions=t.extend(!0,{id:i.newGuid(),buttons:[],data:{},onshow:null,onshown:null,onhide:null,onhidden:null},i.defaultOptions),this.indexedButtons={},this.registeredButtonHotkeys={},this.draggableData={isMouseDown:!1,mouseOffset:{}},this.realized=!1,this.opened=!1,this.initOptions(e),this.holdThisInstance()};return i.BootstrapDialogModal=n,i.NAMESPACE="bootstrap-dialog",i.TYPE_DEFAULT="type-default",i.TYPE_INFO="type-info",i.TYPE_PRIMARY="type-primary",i.TYPE_SECONDARY="type-secondary",i.TYPE_SUCCESS="type-success",i.TYPE_WARNING="type-warning",i.TYPE_DANGER="type-danger",i.TYPE_DARK="type-dark",i.TYPE_LIGHT="type-light",i.DEFAULT_TEXTS={},i.DEFAULT_TEXTS[i.TYPE_DEFAULT]="Default",i.DEFAULT_TEXTS[i.TYPE_INFO]="Information",i.DEFAULT_TEXTS[i.TYPE_PRIMARY]="Primary",i.DEFAULT_TEXTS[i.TYPE_SECONDARY]="Secondary",i.DEFAULT_TEXTS[i.TYPE_SUCCESS]="Success",i.DEFAULT_TEXTS[i.TYPE_WARNING]="Warning",i.DEFAULT_TEXTS[i.TYPE_DANGER]="Danger",i.DEFAULT_TEXTS[i.TYPE_DARK]="Dark",i.DEFAULT_TEXTS[i.TYPE_LIGHT]="Light",i.DEFAULT_TEXTS.OK="OK",i.DEFAULT_TEXTS.CANCEL="Cancel",i.DEFAULT_TEXTS.CONFIRM="Confirmation",i.SIZE_NORMAL="size-normal",i.SIZE_SMALL="size-small",i.SIZE_LARGE="size-large",i.SIZE_WIDE="size-wide",i.BUTTON_SIZES={},i.BUTTON_SIZES[i.SIZE_NORMAL]="",i.BUTTON_SIZES[i.SIZE_SMALL]="btn-sm",i.BUTTON_SIZES[i.SIZE_LARGE]="btn-lg",i.BUTTON_SIZES[i.SIZE_WIDE]="",i.ICON_SPINNER="glyphicon glyphicon-asterisk",i.BUTTONS_ORDER_CANCEL_OK="btns-order-cancel-ok",i.BUTTONS_ORDER_OK_CANCEL="btns-order-ok-cancel",i.defaultOptions={type:i.TYPE_PRIMARY,size:i.SIZE_NORMAL,cssClass:"",title:null,message:null,nl2br:!0,closable:!0,closeByBackdrop:!0,closeByKeyboard:!0,closeIcon:"✕",spinicon:i.ICON_SPINNER,autodestroy:!0,draggable:!1,animate:!0,description:"",tabindex:-1,btnsOrder:i.BUTTONS_ORDER_CANCEL_OK},i.configDefaultOptions=function(e){i.defaultOptions=t.extend(!0,i.defaultOptions,e)},i.dialogs={},i.openAll=function(){t.each(i.dialogs,function(t,e){e.open()})},i.closeAll=function(){t.each(i.dialogs,function(t,e){e.close()})},i.getDialog=function(t){var e=null;return"undefined"!=typeof i.dialogs[t]&&(e=i.dialogs[t]),e},i.setDialog=function(t){return i.dialogs[t.getId()]=t,t},i.addDialog=function(t){return i.setDialog(t)},i.moveFocus=function(){var e=null;t.each(i.dialogs,function(t,n){n.isRealized()&&n.isOpened()&&(e=n)}),null!==e&&e.getModal().focus()},i.METHODS_TO_OVERRIDE={},i.METHODS_TO_OVERRIDE["v3.1"]={handleModalBackdropEvent:function(){return this.getModal().on("click",{dialog:this},function(t){t.target===this&&t.data.dialog.isClosable()&&t.data.dialog.canCloseByBackdrop()&&t.data.dialog.close()}),this},updateZIndex:function(){if(this.isOpened()){var e=1040,n=1050,o=0;t.each(i.dialogs,function(t,e){e.isRealized()&&e.isOpened()&&o++});var a=this.getModal(),s=this.getModalBackdrop(a);a.css("z-index",n+20*(o-1)),s.css("z-index",e+20*(o-1))}return this},open:function(){return!this.isRealized()&&this.realize(),this.getModal().modal("show"),this.updateZIndex(),this}},i.METHODS_TO_OVERRIDE["v3.2"]={handleModalBackdropEvent:i.METHODS_TO_OVERRIDE["v3.1"].handleModalBackdropEvent,updateZIndex:i.METHODS_TO_OVERRIDE["v3.1"].updateZIndex,open:i.METHODS_TO_OVERRIDE["v3.1"].open},i.METHODS_TO_OVERRIDE["v3.3"]={},i.METHODS_TO_OVERRIDE["v3.3.4"]=t.extend({},i.METHODS_TO_OVERRIDE["v3.1"]),i.METHODS_TO_OVERRIDE["v4.0"]=i.METHODS_TO_OVERRIDE["v4.1"]=i.METHODS_TO_OVERRIDE["v5.1"]={defaultButtonCss:"btn-outline-secondary",getModalBackdrop:function(e){return t(e.data("bs.modal")._backdrop)},handleModalBackdropEvent:i.METHODS_TO_OVERRIDE["v3.1"].handleModalBackdropEvent,updateZIndex:i.METHODS_TO_OVERRIDE["v3.1"].updateZIndex,open:i.METHODS_TO_OVERRIDE["v3.1"].open,getModalForBootstrapDialogModal:function(){return this.getModal().get(0)},createHeaderContent:function(){var e=t("
");return e.append(this.createTitleContent()).append(this.createCloseButton()),e.html()}},i.prototype={constructor:i,defaultButtonCss:"btn-default",initOptions:function(e){return this.options=t.extend(!0,this.defaultOptions,e),this},holdThisInstance:function(){return i.addDialog(this),this},initModalStuff:function(){return this.setModal(this.createModal()).setModalDialog(this.createModalDialog()).setModalContent(this.createModalContent()).setModalHeader(this.createModalHeader()).setModalBody(this.createModalBody()).setModalFooter(this.createModalFooter()),this.getModal().append(this.getModalDialog()),this.getModalDialog().append(this.getModalContent()),this.getModalContent().append(this.getModalHeader()).append(this.getModalBody()).append(this.getModalFooter()),this},createModal:function(){var e=t('');return e.prop("id",this.getId()),e.attr("aria-labelledby",this.getId()+"_title"),e},getModal:function(){return this.$modal},setModal:function(t){return this.$modal=t,this},getModalBackdrop:function(t){return t.data("bs.modal").$backdrop},getModalForBootstrapDialogModal:function(){return this.getModal()},createModalDialog:function(){return t('')},getModalDialog:function(){return this.$modalDialog},setModalDialog:function(t){return this.$modalDialog=t,this},createModalContent:function(){return t('')},getModalContent:function(){return this.$modalContent},setModalContent:function(t){return this.$modalContent=t,this},createModalHeader:function(){var e=this.getNamespace("header")+" "+this.getColor();return t('')},getModalHeader:function(){return this.$modalHeader},setModalHeader:function(t){return this.$modalHeader=t,this},createModalBody:function(){return t('')},getModalBody:function(){return this.$modalBody},setModalBody:function(t){return this.$modalBody=t,this},createModalFooter:function(){return t('')},getModalFooter:function(){return this.$modalFooter},setModalFooter:function(t){return this.$modalFooter=t,this},createDynamicContent:function(t){var e=null;return e="function"==typeof t?t.call(t,this):t,"string"==typeof e&&(e=this.formatStringContent(e)),e},formatStringContent:function(t){return this.options.nl2br?t.replace(/\r\n/g,"
").replace(/[\r\n]/g,"
"):t},setData:function(t,e){return this.options.data[t]=e,this},getData:function(t){return this.options.data[t]},setId:function(t){return this.options.id=t,this},getId:function(){return this.options.id},getColor:function(){return this.getType().replace("type-","btn-")},getType:function(){return this.options.type},setType:function(t){return this.options.type=t,this.updateType(),this},updateType:function(){if(this.isRealized()){var t=[i.TYPE_DEFAULT,i.TYPE_INFO,i.TYPE_PRIMARY,i.TYPE_SECONDARY,i.TYPE_SUCCESS,i.TYPE_WARNING,i.TYPE_DARK,i.TYPE_LIGHT,i.TYPE_DANGER];this.getModal().removeClass(t.join(" ")).addClass(this.getType())}return this},getSize:function(){return this.options.size},setSize:function(t){return this.options.size=t,this.updateSize(),this},updateSize:function(){if(this.isRealized()){var e=this,n=this.getSize();this.getModal().removeClass(i.SIZE_NORMAL).removeClass(i.SIZE_SMALL).removeClass(i.SIZE_LARGE).removeClass(i.SIZE_WIDE),this.getModal().addClass(n),this.getModalDialog().removeClass("modal-sm"),n===i.SIZE_SMALL&&this.getModalDialog().addClass("modal-sm"),this.getModalDialog().removeClass("modal-lg"),n===i.SIZE_LARGE&&this.getModalDialog().addClass("modal-lg"),this.getModalDialog().removeClass("modal-xl"),n===i.SIZE_WIDE&&this.getModalDialog().addClass("modal-xl"),t.each(this.options.buttons,function(n,o){var i=e.getButton(o.id),a=["btn-lg","btn-sm","btn-xs"],s=!1;if("string"==typeof o.cssClass){var d=o.cssClass.split(" ");t.each(d,function(e,n){-1!==t.inArray(n,a)&&(s=!0)})}s||(i.removeClass(a.join(" ")),i.addClass(e.getButtonSize()))})}return this},getCssClass:function(){return this.options.cssClass},setCssClass:function(t){return this.options.cssClass=t,this},getTitle:function(){return this.options.title},setTitle:function(t){return this.options.title=t,this.updateTitle(),this},updateTitle:function(){if(this.isRealized()){var t=null!==this.getTitle()?this.createDynamicContent(this.getTitle()):this.getDefaultText();this.getModalHeader().find("."+this.getNamespace("title")).html("").append(t).prop("id",this.getId()+"_title")}return this},getMessage:function(){return this.options.message},setMessage:function(t){return this.options.message=t,this.updateMessage(),this},updateMessage:function(){if(this.isRealized()){var t=this.createDynamicContent(this.getMessage());this.getModalBody().find("."+this.getNamespace("message")).html("").append(t)}return this},isClosable:function(){return this.options.closable},setClosable:function(t){return this.options.closable=t,this.updateClosable(),this},setCloseByBackdrop:function(t){return this.options.closeByBackdrop=t,this},canCloseByBackdrop:function(){return this.options.closeByBackdrop},setCloseByKeyboard:function(t){return this.options.closeByKeyboard=t,this},canCloseByKeyboard:function(){return this.options.closeByKeyboard},isAnimate:function(){return this.options.animate},setAnimate:function(t){return this.options.animate=t,this},updateAnimate:function(){return this.isRealized()&&this.getModal().toggleClass("fade",this.isAnimate()),this},getSpinicon:function(){return this.options.spinicon},setSpinicon:function(t){return this.options.spinicon=t,this},addButton:function(t){return this.options.buttons.push(t),this},addButtons:function(e){var n=this;return t.each(e,function(t,e){n.addButton(e)}),this},getButtons:function(){return this.options.buttons},setButtons:function(t){return this.options.buttons=t,this.updateButtons(),this},getButton:function(t){return"undefined"!=typeof this.indexedButtons[t]?this.indexedButtons[t]:null},getButtonSize:function(){return"undefined"!=typeof i.BUTTON_SIZES[this.getSize()]?i.BUTTON_SIZES[this.getSize()]:""},updateButtons:function(){return this.isRealized()&&(0===this.getButtons().length?this.getModalFooter().hide():this.getModalFooter().show().find("."+this.getNamespace("footer")).html("").append(this.createFooterButtons())),this},isAutodestroy:function(){return this.options.autodestroy},setAutodestroy:function(t){this.options.autodestroy=t},getDescription:function(){return this.options.description},setDescription:function(t){return this.options.description=t,this},setTabindex:function(t){return this.options.tabindex=t,this},getTabindex:function(){return this.options.tabindex},updateTabindex:function(){return this.isRealized()&&this.getModal().attr("tabindex",this.getTabindex()),this},getDefaultText:function(){return i.DEFAULT_TEXTS[this.getType()]},getNamespace:function(t){return i.NAMESPACE+"-"+t},createHeaderContent:function(){var e=t("
");return e.addClass(this.getNamespace("header")),e.append(this.createTitleContent()),e.prepend(this.createCloseButton()),e},createTitleContent:function(){var e=t("
");return e.addClass(this.getNamespace("title")),e},createCloseButton:function(){var e,n=t("
");return n.addClass(this.getNamespace("close-button")),e=t(''),e.append(this.options.closeIcon),n.append(e),n.on("click",{dialog:this},function(t){t.data.dialog.close()}),n},createBodyContent:function(){var e=t("
");return e.addClass(this.getNamespace("body")),e.append(this.createMessageContent()),e},createMessageContent:function(){var e=t("
");return e.addClass(this.getNamespace("message")),e},createFooterContent:function(){var e=t("
");return e.addClass(this.getNamespace("footer")),e},createFooterButtons:function(){var e=this,n=t("
");return n.addClass(this.getNamespace("footer-buttons")),this.indexedButtons={},t.each(this.options.buttons,function(t,o){o.id||(o.id=i.newGuid());var a=e.createButton(o);e.indexedButtons[o.id]=a,n.append(a)}),n},createButton:function(e){var n=t('');return n.prop("id",e.id),n.data("button",e),"undefined"!=typeof e.icon&&""!==t.trim(e.icon)&&n.append(this.createButtonIcon(e.icon)),"undefined"!=typeof e.label&&n.append(e.label),"undefined"!=typeof e.title&&n.attr("title",e.title),"undefined"!=typeof e.cssClass&&""!==t.trim(e.cssClass)?n.addClass(e.cssClass):n.addClass(this.defaultButtonCss),"object"==typeof e.data&&e.data.constructor==={}.constructor&&t.each(e.data,function(t,e){n.attr("data-"+t,e)}),"undefined"!=typeof e.hotkey&&(this.registeredButtonHotkeys[e.hotkey]=n),n.on("click",{dialog:this,$button:n,button:e},function(t){var e=t.data.dialog,n=t.data.$button,o=n.data("button");return o.autospin&&n.toggleSpin(!0),"function"==typeof o.action?o.action.call(n,e,t):void 0}),this.enhanceButton(n),"undefined"!=typeof e.enabled&&n.toggleEnable(e.enabled),n},enhanceButton:function(t){return t.dialog=this,t.toggleEnable=function(t){var e=this;return"undefined"!=typeof t?e.prop("disabled",!t).toggleClass("disabled",!t):e.prop("disabled",!e.prop("disabled")),e},t.enable=function(){var t=this;return t.toggleEnable(!0),t},t.disable=function(){var t=this;return t.toggleEnable(!1),t},t.toggleSpin=function(e){var n=this,o=n.dialog,i=n.find("."+o.getNamespace("button-icon"));return"undefined"==typeof e&&(e=!(t.find(".icon-spin").length>0)),e?(i.hide(),t.prepend(o.createButtonIcon(o.getSpinicon()).addClass("icon-spin"))):(i.show(),t.find(".icon-spin").remove()),n},t.spin=function(){var t=this;return t.toggleSpin(!0),t},t.stopSpin=function(){var t=this;return t.toggleSpin(!1),t},this},createButtonIcon:function(e){var n=t("");return n.addClass(this.getNamespace("button-icon")).addClass(e),n},enableButtons:function(e){return t.each(this.indexedButtons,function(t,n){n.toggleEnable(e)}),this},updateClosable:function(){return this.isRealized()&&this.getModalHeader().find("."+this.getNamespace("close-button")).toggle(this.isClosable()),this},onShow:function(t){return this.options.onshow=t,this},onShown:function(t){return this.options.onshown=t,this},onHide:function(t){return this.options.onhide=t,this},onHidden:function(t){return this.options.onhidden=t,this},isRealized:function(){return this.realized},setRealized:function(t){return this.realized=t,this},isOpened:function(){return this.opened},setOpened:function(t){return this.opened=t,this},handleModalEvents:function(){return this.getModal().on("show.bs.modal",{dialog:this},function(t){var e=t.data.dialog;if(e.setOpened(!0),e.isModalEvent(t)&&"function"==typeof e.options.onshow){var n=e.options.onshow(e);return n===!1&&e.setOpened(!1),n}}),this.getModal().on("shown.bs.modal",{dialog:this},function(t){var e=t.data.dialog;e.isModalEvent(t)&&"function"==typeof e.options.onshown&&e.options.onshown(e)}),this.getModal().on("hide.bs.modal",{dialog:this},function(t){var e=t.data.dialog;if(e.setOpened(!1),e.isModalEvent(t)&&"function"==typeof e.options.onhide){var n=e.options.onhide(e);return n===!1&&e.setOpened(!0),n}}),this.getModal().on("hidden.bs.modal",{dialog:this},function(e){var n=e.data.dialog;n.isModalEvent(e)&&"function"==typeof n.options.onhidden&&n.options.onhidden(n),n.isAutodestroy()&&(n.setRealized(!1),delete i.dialogs[n.getId()],t(this).remove()),i.moveFocus(),t(".modal").hasClass("in")&&t("body").addClass("modal-open")}),this.handleModalBackdropEvent(),this.getModal().on("keyup",{dialog:this},function(t){27===t.which&&t.data.dialog.isClosable()&&t.data.dialog.canCloseByKeyboard()&&t.data.dialog.close()}),this.getModal().on("keyup",{dialog:this},function(e){var n=e.data.dialog;if("undefined"!=typeof n.registeredButtonHotkeys[e.which]){var o=t(n.registeredButtonHotkeys[e.which]);!o.prop("disabled")&&!o.is(":focus")&&o.focus().trigger("click")}}),this},handleModalBackdropEvent:function(){return this.getModal().on("click",{dialog:this},function(e){t(e.target).hasClass("modal-backdrop")&&e.data.dialog.isClosable()&&e.data.dialog.canCloseByBackdrop()&&e.data.dialog.close()}),this},isModalEvent:function(t){return"undefined"!=typeof t.namespace&&"bs.modal"===t.namespace},makeModalDraggable:function(){return this.options.draggable&&(this.getModalHeader().addClass(this.getNamespace("draggable")).on("mousedown",{dialog:this},function(t){var e=t.data.dialog;e.draggableData.isMouseDown=!0;var n=e.getModalDialog().offset();e.draggableData.mouseOffset={top:t.clientY-n.top,left:t.clientX-n.left}}),this.getModal().on("mouseup mouseleave",{dialog:this},function(t){t.data.dialog.draggableData.isMouseDown=!1}),t("body").on("mousemove",{dialog:this},function(t){var e=t.data.dialog;e.draggableData.isMouseDown&&e.getModalDialog().offset({top:t.clientY-e.draggableData.mouseOffset.top,left:t.clientX-e.draggableData.mouseOffset.left})})),this},realize:function(){return this.initModalStuff(),this.getModal().addClass(i.NAMESPACE).addClass(this.getCssClass()),this.updateSize(),this.getDescription()&&this.getModal().attr("aria-describedby",this.getDescription()),this.getModalFooter().append(this.createFooterContent()),this.getModalHeader().append(this.createHeaderContent()),this.getModalBody().append(this.createBodyContent()),this.getModal().data("bs.modal",new n(this.getModalForBootstrapDialogModal(),{backdrop:"static",keyboard:!1,show:!1})),this.makeModalDraggable(),this.handleModalEvents(),this.setRealized(!0),this.updateButtons(),this.updateType(),this.updateTitle(),this.updateMessage(),this.updateClosable(),this.updateAnimate(),this.updateSize(),this.updateTabindex(),this},open:function(){return!this.isRealized()&&this.realize(),this.getModal().modal("show"),this},close:function(){return!this.isRealized()&&this.realize(),this.getModal().modal("hide"),this}},i.prototype=t.extend(i.prototype,i.METHODS_TO_OVERRIDE[n.getModalVersion()]),i.newGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0,n="x"===t?e:3&e|8;return n.toString(16)})},i.show=function(t){return new i(t).open()},i.alert=function(){var e={},n={type:i.TYPE_PRIMARY,title:null,message:null,closable:!1,draggable:!1,buttonLabel:i.DEFAULT_TEXTS.OK,buttonHotkey:null,callback:null};e="object"==typeof arguments[0]&&arguments[0].constructor==={}.constructor?t.extend(!0,n,arguments[0]):t.extend(!0,n,{message:arguments[0],callback:"undefined"!=typeof arguments[1]?arguments[1]:null});var o=new i(e);return o.setData("callback",e.callback),o.addButton({label:e.buttonLabel,hotkey:e.buttonHotkey,action:function(t){return"function"==typeof t.getData("callback")&&t.getData("callback").call(this,!0)===!1?!1:(t.setData("btnClicked",!0),t.close())}}),"function"==typeof o.options.onhide?o.onHide(function(t){var e=!0;return!t.getData("btnClicked")&&t.isClosable()&&"function"==typeof t.getData("callback")&&(e=t.getData("callback")(!1)),e===!1?!1:e=this.onhide(t)}.bind({onhide:o.options.onhide})):o.onHide(function(t){var e=!0;return!t.getData("btnClicked")&&t.isClosable()&&"function"==typeof t.getData("callback")&&(e=t.getData("callback")(!1)),e}),o.open()},i.confirm=function(){var e={},n={type:i.TYPE_PRIMARY,title:null,message:null,closable:!1,draggable:!1,btnCancelLabel:i.DEFAULT_TEXTS.CANCEL,btnCancelClass:null,btnCancelHotkey:null,btnOKLabel:i.DEFAULT_TEXTS.OK,btnOKClass:null,btnOKHotkey:null,btnsOrder:i.defaultOptions.btnsOrder,callback:null};e="object"==typeof arguments[0]&&arguments[0].constructor==={}.constructor?t.extend(!0,n,arguments[0]):t.extend(!0,n,{message:arguments[0],callback:"undefined"!=typeof arguments[1]?arguments[1]:null}),null===e.btnOKClass&&(e.btnOKClass=["btn",e.type.split("-")[1]].join("-"));var o=new i(e);o.setData("callback",e.callback);var a=[{label:e.btnCancelLabel,cssClass:e.btnCancelClass,hotkey:e.btnCancelHotkey,action:function(t){return"function"==typeof t.getData("callback")&&t.getData("callback").call(this,!1)===!1?!1:t.close()}},{label:e.btnOKLabel,cssClass:e.btnOKClass,hotkey:e.btnOKHotkey,action:function(t){return"function"==typeof t.getData("callback")&&t.getData("callback").call(this,!0)===!1?!1:t.close()}}];return e.btnsOrder===i.BUTTONS_ORDER_OK_CANCEL&&a.reverse(),o.addButtons(a),o.open()},i.warning=function(t){return new i({type:i.TYPE_WARNING,message:t}).open()},i.danger=function(t){return new i({type:i.TYPE_DANGER,message:t}).open()},i.success=function(t){return new i({type:i.TYPE_SUCCESS,message:t}).open()},i}); -------------------------------------------------------------------------------- /src/assets/js/bootstrap-dialog.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @package yii2-dialog 3 | * @author Kartik Visweswaran 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2018 5 | * @version 1.0.6 6 | * 7 | * Make use of Bootstrap's modal more monkey-friendly. 8 | * Sourced from: https://github.com/nakupanda/bootstrap3-dialog 9 | * 10 | * Modifications to library by Kartik Visweswaran, Krajee.com 11 | * For yii2-dialog v1.0.6 - adds Bootstrap 4.x & 5.x support. 12 | */ 13 | (function (root, factory) { 14 | 15 | "use strict"; 16 | 17 | // CommonJS module is definedc 18 | if (typeof module !== 'undefined' && module.exports) { 19 | module.exports = factory(require('jquery'), require('bootstrap')); 20 | } 21 | // AMD module is defined 22 | else if (typeof define === "function" && define.amd) { 23 | define("bootstrap-dialog", ["jquery", "bootstrap"], function ($) { 24 | return factory($); 25 | }); 26 | } else { 27 | // planted over the root! 28 | root.BootstrapDialog = factory(root.jQuery); 29 | } 30 | 31 | }(this, function ($) { 32 | 33 | "use strict"; 34 | 35 | /* ================================================ 36 | * Definition of BootstrapDialogModal. 37 | * Extend Bootstrap Modal and override some functions. 38 | * BootstrapDialogModal === Modified Modal. 39 | * ================================================ */ 40 | var bsModal = $.fn.modal ? $.fn.modal.Constructor : (bootstrap ? bootstrap.Modal : {}); 41 | var BootstrapDialogModal = function (element, options) { 42 | if (/4\.\d+\.\d+/.test(bsModal.VERSION) || /5\.\d+\.\d+/.test(bsModal.VERSION)) { //FIXME for BootstrapV4 & 5 43 | return new bsModal(element, options); 44 | } else { 45 | bsModal.call(this, element, options); 46 | } 47 | }; 48 | BootstrapDialogModal.getModalVersion = function () { 49 | var version = null; 50 | if (typeof bsModal.VERSION === 'undefined') { 51 | version = 'v3.1'; 52 | } else if (/3\.2\.\d+/.test(bsModal.VERSION)) { 53 | version = 'v3.2'; 54 | } else if (/3\.3\.[1,2]/.test(bsModal.VERSION)) { 55 | version = 'v3.3'; // v3.3.1, v3.3.2 56 | } else if (/4\.\d+\.\d+/.test(bsModal.VERSION)) { //FIXME for BootstrapV4 57 | version = 'v4.1'; 58 | } else if (/5\.\d+\.\d+/.test(bsModal.VERSION)) { //FIXME for BootstrapV5 59 | version = 'v5.1'; 60 | } else { 61 | version = 'v3.3.4'; 62 | } 63 | 64 | return version; 65 | }; 66 | BootstrapDialogModal.ORIGINAL_BODY_PADDING = parseInt(($('body').css('padding-right') || 0), 10); 67 | BootstrapDialogModal.METHODS_TO_OVERRIDE = {}; 68 | BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.1'] = {}; 69 | BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.2'] = { 70 | hide: function (e) { 71 | if (e) { 72 | e.preventDefault(); 73 | } 74 | e = $.Event('hide.bs.modal'); 75 | 76 | this.$element.trigger(e); 77 | 78 | if (!this.isShown || e.isDefaultPrevented()) { 79 | return; 80 | } 81 | 82 | this.isShown = false; 83 | 84 | // Remove css class 'modal-open' when the last opened dialog is closing. 85 | var openedDialogs = this.getGlobalOpenedDialogs(); 86 | if (openedDialogs.length === 0) { 87 | this.$body.removeClass('modal-open'); 88 | } 89 | 90 | this.resetScrollbar(); 91 | this.escape(); 92 | 93 | $(document).off('focusin.bs.modal'); 94 | 95 | this.$element 96 | .removeClass('in') 97 | .attr('aria-hidden', true) 98 | .off('click.dismiss.bs.modal'); 99 | 100 | $.support.transition && this.$element.hasClass('fade') ? 101 | this.$element 102 | .one('bsTransitionEnd', $.proxy(this.hideModal, this)) 103 | .emulateTransitionEnd(300) : 104 | this.hideModal(); 105 | } 106 | }; 107 | BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3'] = { 108 | /** 109 | * Overrided. 110 | * 111 | * @returns {undefined} 112 | */ 113 | setScrollbar: function () { 114 | var bodyPad = BootstrapDialogModal.ORIGINAL_BODY_PADDING; 115 | if (this.bodyIsOverflowing) { 116 | this.$body.css('padding-right', bodyPad + this.scrollbarWidth); 117 | } 118 | }, 119 | /** 120 | * Overrided. 121 | * 122 | * @returns {undefined} 123 | */ 124 | resetScrollbar: function () { 125 | var openedDialogs = this.getGlobalOpenedDialogs(); 126 | if (openedDialogs.length === 0) { 127 | this.$body.css('padding-right', BootstrapDialogModal.ORIGINAL_BODY_PADDING); 128 | } 129 | }, 130 | /** 131 | * Overrided. 132 | * 133 | * @returns {undefined} 134 | */ 135 | hideModal: function () { 136 | this.$element.hide(); 137 | this.backdrop($.proxy(function () { 138 | var openedDialogs = this.getGlobalOpenedDialogs(); 139 | if (openedDialogs.length === 0) { 140 | this.$body.removeClass('modal-open'); 141 | } 142 | this.resetAdjustments(); 143 | this.resetScrollbar(); 144 | this.$element.trigger('hidden.bs.modal'); 145 | }, this)); 146 | } 147 | }; 148 | BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3.4'] = $.extend({}, BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3']); 149 | BootstrapDialogModal.METHODS_TO_OVERRIDE['v4.1'] = $.extend({}, BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3']); //FIXME for BootstrapV4 150 | BootstrapDialogModal.METHODS_TO_OVERRIDE['v5.1'] = $.extend({}, BootstrapDialogModal.METHODS_TO_OVERRIDE['v4.1']); //FIXME for BootstrapV5 151 | BootstrapDialogModal.prototype = { 152 | constructor: BootstrapDialogModal, 153 | /** 154 | * New function, to get the dialogs that opened by BootstrapDialog. 155 | * 156 | * @returns {undefined} 157 | */ 158 | getGlobalOpenedDialogs: function () { 159 | var openedDialogs = []; 160 | $.each(BootstrapDialog.dialogs, function (id, dialogInstance) { 161 | if (dialogInstance.isRealized() && dialogInstance.isOpened()) { 162 | openedDialogs.push(dialogInstance); 163 | } 164 | }); 165 | 166 | return openedDialogs; 167 | } 168 | }; 169 | 170 | // Add compatible methods. 171 | var modalPrototype = bsModal.prototype || null; 172 | BootstrapDialogModal.prototype = $.extend(BootstrapDialogModal.prototype, modalPrototype, BootstrapDialogModal.METHODS_TO_OVERRIDE[BootstrapDialogModal.getModalVersion()]); 173 | 174 | /* ================================================ 175 | * Definition of BootstrapDialog. 176 | * ================================================ */ 177 | var BootstrapDialog = function (options) { 178 | this.defaultOptions = $.extend(true, { 179 | id: BootstrapDialog.newGuid(), 180 | buttons: [], 181 | data: {}, 182 | onshow: null, 183 | onshown: null, 184 | onhide: null, 185 | onhidden: null 186 | }, BootstrapDialog.defaultOptions); 187 | this.indexedButtons = {}; 188 | this.registeredButtonHotkeys = {}; 189 | this.draggableData = { 190 | isMouseDown: false, 191 | mouseOffset: {} 192 | }; 193 | this.realized = false; 194 | this.opened = false; 195 | this.initOptions(options); 196 | this.holdThisInstance(); 197 | }; 198 | 199 | BootstrapDialog.BootstrapDialogModal = BootstrapDialogModal; 200 | 201 | /** 202 | * Some constants. 203 | */ 204 | BootstrapDialog.NAMESPACE = 'bootstrap-dialog'; 205 | BootstrapDialog.TYPE_DEFAULT = 'type-default'; 206 | BootstrapDialog.TYPE_INFO = 'type-info'; 207 | BootstrapDialog.TYPE_PRIMARY = 'type-primary'; 208 | BootstrapDialog.TYPE_SECONDARY = 'type-secondary'; 209 | BootstrapDialog.TYPE_SUCCESS = 'type-success'; 210 | BootstrapDialog.TYPE_WARNING = 'type-warning'; 211 | BootstrapDialog.TYPE_DANGER = 'type-danger'; 212 | BootstrapDialog.TYPE_DARK = 'type-dark'; 213 | BootstrapDialog.TYPE_LIGHT = 'type-light'; 214 | BootstrapDialog.DEFAULT_TEXTS = {}; 215 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DEFAULT] = 'Default'; 216 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_INFO] = 'Information'; 217 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_PRIMARY] = 'Primary'; 218 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_SECONDARY] = 'Secondary'; 219 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_SUCCESS] = 'Success'; 220 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_WARNING] = 'Warning'; 221 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DANGER] = 'Danger'; 222 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DARK] = 'Dark'; 223 | BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_LIGHT] = 'Light'; 224 | BootstrapDialog.DEFAULT_TEXTS['OK'] = 'OK'; 225 | BootstrapDialog.DEFAULT_TEXTS['CANCEL'] = 'Cancel'; 226 | BootstrapDialog.DEFAULT_TEXTS['CONFIRM'] = 'Confirmation'; 227 | BootstrapDialog.SIZE_NORMAL = 'size-normal'; 228 | BootstrapDialog.SIZE_SMALL = 'size-small'; 229 | BootstrapDialog.SIZE_LARGE = 'size-large'; 230 | BootstrapDialog.SIZE_WIDE = 'size-wide'; 231 | BootstrapDialog.BUTTON_SIZES = {}; 232 | BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_NORMAL] = ''; 233 | BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_SMALL] = 'btn-sm'; 234 | BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_LARGE] = 'btn-lg'; 235 | BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_WIDE] = ''; 236 | BootstrapDialog.ICON_SPINNER = 'glyphicon glyphicon-asterisk'; 237 | BootstrapDialog.BUTTONS_ORDER_CANCEL_OK = 'btns-order-cancel-ok'; 238 | BootstrapDialog.BUTTONS_ORDER_OK_CANCEL = 'btns-order-ok-cancel'; 239 | 240 | /** 241 | * Default options. 242 | */ 243 | BootstrapDialog.defaultOptions = { 244 | type: BootstrapDialog.TYPE_PRIMARY, 245 | size: BootstrapDialog.SIZE_NORMAL, 246 | cssClass: '', 247 | title: null, 248 | message: null, 249 | nl2br: true, 250 | closable: true, 251 | closeByBackdrop: true, 252 | closeByKeyboard: true, 253 | closeIcon: '✕', 254 | spinicon: BootstrapDialog.ICON_SPINNER, 255 | autodestroy: true, 256 | draggable: false, 257 | animate: true, 258 | description: '', 259 | tabindex: -1, 260 | btnsOrder: BootstrapDialog.BUTTONS_ORDER_CANCEL_OK 261 | }; 262 | 263 | /** 264 | * Config default options. 265 | */ 266 | BootstrapDialog.configDefaultOptions = function (options) { 267 | BootstrapDialog.defaultOptions = $.extend(true, BootstrapDialog.defaultOptions, options); 268 | }; 269 | 270 | /** 271 | * Open / Close all created dialogs all at once. 272 | */ 273 | BootstrapDialog.dialogs = {}; 274 | BootstrapDialog.openAll = function () { 275 | $.each(BootstrapDialog.dialogs, function (id, dialogInstance) { 276 | dialogInstance.open(); 277 | }); 278 | }; 279 | BootstrapDialog.closeAll = function () { 280 | $.each(BootstrapDialog.dialogs, function (id, dialogInstance) { 281 | dialogInstance.close(); 282 | }); 283 | }; 284 | 285 | /** 286 | * Get dialog instance by given id. 287 | * 288 | * @returns dialog instance 289 | */ 290 | BootstrapDialog.getDialog = function (id) { 291 | var dialog = null; 292 | if (typeof BootstrapDialog.dialogs[id] !== 'undefined') { 293 | dialog = BootstrapDialog.dialogs[id]; 294 | } 295 | 296 | return dialog; 297 | }; 298 | 299 | /** 300 | * Set a dialog. 301 | * 302 | * @returns the dialog that has just been set. 303 | */ 304 | BootstrapDialog.setDialog = function (dialog) { 305 | BootstrapDialog.dialogs[dialog.getId()] = dialog; 306 | 307 | return dialog; 308 | }; 309 | 310 | /** 311 | * Alias of BootstrapDialog.setDialog(dialog) 312 | * 313 | * @param {type} dialog 314 | * @returns {unresolved} 315 | */ 316 | BootstrapDialog.addDialog = function (dialog) { 317 | return BootstrapDialog.setDialog(dialog); 318 | }; 319 | 320 | /** 321 | * Move focus to next visible dialog. 322 | */ 323 | BootstrapDialog.moveFocus = function () { 324 | var lastDialogInstance = null; 325 | $.each(BootstrapDialog.dialogs, function (id, dialogInstance) { 326 | if (dialogInstance.isRealized() && dialogInstance.isOpened()) { 327 | lastDialogInstance = dialogInstance; 328 | } 329 | }); 330 | if (lastDialogInstance !== null) { 331 | lastDialogInstance.getModal().focus(); 332 | } 333 | }; 334 | 335 | BootstrapDialog.METHODS_TO_OVERRIDE = {}; 336 | BootstrapDialog.METHODS_TO_OVERRIDE['v3.1'] = { 337 | handleModalBackdropEvent: function () { 338 | this.getModal().on('click', {dialog: this}, function (event) { 339 | event.target === this && event.data.dialog.isClosable() && event.data.dialog.canCloseByBackdrop() && event.data.dialog.close(); 340 | }); 341 | 342 | return this; 343 | }, 344 | /** 345 | * To make multiple opened dialogs look better. 346 | * 347 | * Will be removed in later version, after Bootstrap Modal >= 3.3.0, updating z-index is unnecessary. 348 | */ 349 | updateZIndex: function () { 350 | if (this.isOpened()) { 351 | var zIndexBackdrop = 1040; 352 | var zIndexModal = 1050; 353 | var dialogCount = 0; 354 | $.each(BootstrapDialog.dialogs, function (dialogId, dialogInstance) { 355 | if (dialogInstance.isRealized() && dialogInstance.isOpened()) { 356 | dialogCount++; 357 | } 358 | }); 359 | var $modal = this.getModal(); 360 | var $backdrop = this.getModalBackdrop($modal); //FIXME for BootstrapV4 361 | $modal.css('z-index', zIndexModal + (dialogCount - 1) * 20); 362 | $backdrop.css('z-index', zIndexBackdrop + (dialogCount - 1) * 20); 363 | } 364 | 365 | return this; 366 | }, 367 | open: function () { 368 | !this.isRealized() && this.realize(); 369 | this.getModal().modal('show'); 370 | this.updateZIndex(); 371 | 372 | return this; 373 | } 374 | }; 375 | BootstrapDialog.METHODS_TO_OVERRIDE['v3.2'] = { 376 | handleModalBackdropEvent: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['handleModalBackdropEvent'], 377 | updateZIndex: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['updateZIndex'], 378 | open: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['open'] 379 | }; 380 | BootstrapDialog.METHODS_TO_OVERRIDE['v3.3'] = {}; 381 | BootstrapDialog.METHODS_TO_OVERRIDE['v3.3.4'] = $.extend({}, BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']); 382 | /** 383 | * BEGIN: Fixes and enhancements for Bootstrap v4.x 384 | * By Kartik Visweswaran 385 | */ 386 | BootstrapDialog.METHODS_TO_OVERRIDE['v4.0'] = BootstrapDialog.METHODS_TO_OVERRIDE['v4.1'] = BootstrapDialog.METHODS_TO_OVERRIDE['v5.1'] = { 387 | defaultButtonCss: 'btn-outline-secondary', 388 | getModalBackdrop: function ($modal) { 389 | return $($modal.data('bs.modal')._backdrop); 390 | }, 391 | handleModalBackdropEvent: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['handleModalBackdropEvent'], 392 | updateZIndex: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['updateZIndex'], 393 | open: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['open'], 394 | getModalForBootstrapDialogModal: function () { 395 | return this.getModal().get(0); 396 | }, 397 | createHeaderContent: function () { 398 | var $container = $('
'); 399 | // title & button 400 | $container.append(this.createTitleContent()).append(this.createCloseButton()); 401 | return $container.html(); 402 | } 403 | }; 404 | /** 405 | * END: Fixes and enhancements for Bootstrap v4.x 406 | * By Kartik Visweswaran 407 | */ 408 | BootstrapDialog.prototype = { 409 | constructor: BootstrapDialog, 410 | defaultButtonCss: 'btn-default', // Enhancement by Kartik 411 | initOptions: function (options) { 412 | this.options = $.extend(true, this.defaultOptions, options); 413 | return this; 414 | }, 415 | holdThisInstance: function () { 416 | BootstrapDialog.addDialog(this); 417 | 418 | return this; 419 | }, 420 | initModalStuff: function () { 421 | this.setModal(this.createModal()) 422 | .setModalDialog(this.createModalDialog()) 423 | .setModalContent(this.createModalContent()) 424 | .setModalHeader(this.createModalHeader()) 425 | .setModalBody(this.createModalBody()) 426 | .setModalFooter(this.createModalFooter()); 427 | 428 | this.getModal().append(this.getModalDialog()); 429 | this.getModalDialog().append(this.getModalContent()); 430 | this.getModalContent() 431 | .append(this.getModalHeader()) 432 | .append(this.getModalBody()) 433 | .append(this.getModalFooter()); 434 | 435 | return this; 436 | }, 437 | createModal: function () { 438 | var $modal = $(''); 439 | $modal.prop('id', this.getId()); 440 | $modal.attr('aria-labelledby', this.getId() + '_title'); 441 | 442 | return $modal; 443 | }, 444 | getModal: function () { 445 | return this.$modal; 446 | }, 447 | setModal: function ($modal) { 448 | this.$modal = $modal; 449 | 450 | return this; 451 | }, 452 | getModalBackdrop: function ($modal) { //FIXME for BootstrapV4 453 | return $modal.data('bs.modal').$backdrop; 454 | }, 455 | getModalForBootstrapDialogModal: function () { //FIXME for BootstrapV4 456 | return this.getModal(); 457 | }, 458 | createModalDialog: function () { 459 | return $(''); 460 | }, 461 | getModalDialog: function () { 462 | return this.$modalDialog; 463 | }, 464 | setModalDialog: function ($modalDialog) { 465 | this.$modalDialog = $modalDialog; 466 | 467 | return this; 468 | }, 469 | createModalContent: function () { 470 | return $(''); 471 | }, 472 | getModalContent: function () { 473 | return this.$modalContent; 474 | }, 475 | setModalContent: function ($modalContent) { 476 | this.$modalContent = $modalContent; 477 | 478 | return this; 479 | }, 480 | createModalHeader: function () { 481 | var css = this.getNamespace('header') + ' ' + this.getColor(); 482 | return $(''); 483 | }, 484 | getModalHeader: function () { 485 | return this.$modalHeader; 486 | }, 487 | setModalHeader: function ($modalHeader) { 488 | this.$modalHeader = $modalHeader; 489 | 490 | return this; 491 | }, 492 | createModalBody: function () { 493 | return $(''); 494 | }, 495 | getModalBody: function () { 496 | return this.$modalBody; 497 | }, 498 | setModalBody: function ($modalBody) { 499 | this.$modalBody = $modalBody; 500 | 501 | return this; 502 | }, 503 | createModalFooter: function () { 504 | return $(''); 505 | }, 506 | getModalFooter: function () { 507 | return this.$modalFooter; 508 | }, 509 | setModalFooter: function ($modalFooter) { 510 | this.$modalFooter = $modalFooter; 511 | 512 | return this; 513 | }, 514 | createDynamicContent: function (rawContent) { 515 | var content = null; 516 | if (typeof rawContent === 'function') { 517 | content = rawContent.call(rawContent, this); 518 | } else { 519 | content = rawContent; 520 | } 521 | if (typeof content === 'string') { 522 | content = this.formatStringContent(content); 523 | } 524 | 525 | return content; 526 | }, 527 | formatStringContent: function (content) { 528 | if (this.options.nl2br) { 529 | return content.replace(/\r\n/g, '
').replace(/[\r\n]/g, '
'); 530 | } 531 | 532 | return content; 533 | }, 534 | setData: function (key, value) { 535 | this.options.data[key] = value; 536 | 537 | return this; 538 | }, 539 | getData: function (key) { 540 | return this.options.data[key]; 541 | }, 542 | setId: function (id) { 543 | this.options.id = id; 544 | 545 | return this; 546 | }, 547 | getId: function () { 548 | return this.options.id; 549 | }, 550 | getColor: function () { 551 | return this.getType().replace('type-', 'btn-'); 552 | }, 553 | getType: function () { 554 | return this.options.type; 555 | }, 556 | setType: function (type) { 557 | this.options.type = type; 558 | this.updateType(); 559 | 560 | return this; 561 | }, 562 | updateType: function () { 563 | if (this.isRealized()) { 564 | var types = [BootstrapDialog.TYPE_DEFAULT, 565 | BootstrapDialog.TYPE_INFO, 566 | BootstrapDialog.TYPE_PRIMARY, 567 | BootstrapDialog.TYPE_SECONDARY, 568 | BootstrapDialog.TYPE_SUCCESS, 569 | BootstrapDialog.TYPE_WARNING, 570 | BootstrapDialog.TYPE_DARK, 571 | BootstrapDialog.TYPE_LIGHT, 572 | BootstrapDialog.TYPE_DANGER]; 573 | 574 | this.getModal().removeClass(types.join(' ')).addClass(this.getType()); 575 | } 576 | 577 | return this; 578 | }, 579 | getSize: function () { 580 | return this.options.size; 581 | }, 582 | setSize: function (size) { 583 | this.options.size = size; 584 | this.updateSize(); 585 | 586 | return this; 587 | }, 588 | updateSize: function () { 589 | if (this.isRealized()) { 590 | var dialog = this, size = this.getSize(); 591 | 592 | // Dialog size 593 | this.getModal().removeClass(BootstrapDialog.SIZE_NORMAL) 594 | .removeClass(BootstrapDialog.SIZE_SMALL) 595 | .removeClass(BootstrapDialog.SIZE_LARGE) 596 | .removeClass(BootstrapDialog.SIZE_WIDE); 597 | this.getModal().addClass(size); 598 | 599 | // Smaller dialog. 600 | this.getModalDialog().removeClass('modal-sm'); 601 | if (size === BootstrapDialog.SIZE_SMALL) { 602 | this.getModalDialog().addClass('modal-sm'); 603 | } 604 | 605 | // Wider dialog. 606 | this.getModalDialog().removeClass('modal-lg'); 607 | if (size === BootstrapDialog.SIZE_LARGE) { 608 | this.getModalDialog().addClass('modal-lg'); 609 | } 610 | // Extra Wide Dialog. 611 | this.getModalDialog().removeClass('modal-xl'); 612 | if (size === BootstrapDialog.SIZE_WIDE) { 613 | this.getModalDialog().addClass('modal-xl'); 614 | } 615 | 616 | // Button size 617 | $.each(this.options.buttons, function (index, button) { 618 | var $button = dialog.getButton(button.id); 619 | var buttonSizes = ['btn-lg', 'btn-sm', 'btn-xs']; 620 | var sizeClassSpecified = false; 621 | if (typeof button['cssClass'] === 'string') { 622 | var btnClasses = button['cssClass'].split(' '); 623 | $.each(btnClasses, function (index, btnClass) { 624 | if ($.inArray(btnClass, buttonSizes) !== -1) { 625 | sizeClassSpecified = true; 626 | } 627 | }); 628 | } 629 | if (!sizeClassSpecified) { 630 | $button.removeClass(buttonSizes.join(' ')); 631 | $button.addClass(dialog.getButtonSize()); 632 | } 633 | }); 634 | } 635 | 636 | return this; 637 | }, 638 | getCssClass: function () { 639 | return this.options.cssClass; 640 | }, 641 | setCssClass: function (cssClass) { 642 | this.options.cssClass = cssClass; 643 | 644 | return this; 645 | }, 646 | getTitle: function () { 647 | return this.options.title; 648 | }, 649 | setTitle: function (title) { 650 | this.options.title = title; 651 | this.updateTitle(); 652 | 653 | return this; 654 | }, 655 | updateTitle: function () { 656 | if (this.isRealized()) { 657 | var title = this.getTitle() !== null ? this.createDynamicContent(this.getTitle()) : this.getDefaultText(); 658 | this.getModalHeader().find('.' + this.getNamespace('title')).html('').append(title).prop('id', this.getId() + '_title'); 659 | } 660 | 661 | return this; 662 | }, 663 | getMessage: function () { 664 | return this.options.message; 665 | }, 666 | setMessage: function (message) { 667 | this.options.message = message; 668 | this.updateMessage(); 669 | 670 | return this; 671 | }, 672 | updateMessage: function () { 673 | if (this.isRealized()) { 674 | var message = this.createDynamicContent(this.getMessage()); 675 | this.getModalBody().find('.' + this.getNamespace('message')).html('').append(message); 676 | } 677 | 678 | return this; 679 | }, 680 | isClosable: function () { 681 | return this.options.closable; 682 | }, 683 | setClosable: function (closable) { 684 | this.options.closable = closable; 685 | this.updateClosable(); 686 | 687 | return this; 688 | }, 689 | setCloseByBackdrop: function (closeByBackdrop) { 690 | this.options.closeByBackdrop = closeByBackdrop; 691 | 692 | return this; 693 | }, 694 | canCloseByBackdrop: function () { 695 | return this.options.closeByBackdrop; 696 | }, 697 | setCloseByKeyboard: function (closeByKeyboard) { 698 | this.options.closeByKeyboard = closeByKeyboard; 699 | 700 | return this; 701 | }, 702 | canCloseByKeyboard: function () { 703 | return this.options.closeByKeyboard; 704 | }, 705 | isAnimate: function () { 706 | return this.options.animate; 707 | }, 708 | setAnimate: function (animate) { 709 | this.options.animate = animate; 710 | 711 | return this; 712 | }, 713 | updateAnimate: function () { 714 | if (this.isRealized()) { 715 | this.getModal().toggleClass('fade', this.isAnimate()); 716 | } 717 | 718 | return this; 719 | }, 720 | getSpinicon: function () { 721 | return this.options.spinicon; 722 | }, 723 | setSpinicon: function (spinicon) { 724 | this.options.spinicon = spinicon; 725 | 726 | return this; 727 | }, 728 | addButton: function (button) { 729 | this.options.buttons.push(button); 730 | 731 | return this; 732 | }, 733 | addButtons: function (buttons) { 734 | var that = this; 735 | $.each(buttons, function (index, button) { 736 | that.addButton(button); 737 | }); 738 | 739 | return this; 740 | }, 741 | getButtons: function () { 742 | return this.options.buttons; 743 | }, 744 | setButtons: function (buttons) { 745 | this.options.buttons = buttons; 746 | this.updateButtons(); 747 | 748 | return this; 749 | }, 750 | /** 751 | * If there is id provided for a button option, it will be in dialog.indexedButtons list. 752 | * 753 | * In that case you can use dialog.getButton(id) to find the button. 754 | * 755 | * @param {type} id 756 | * @returns {undefined} 757 | */ 758 | getButton: function (id) { 759 | if (typeof this.indexedButtons[id] !== 'undefined') { 760 | return this.indexedButtons[id]; 761 | } 762 | 763 | return null; 764 | }, 765 | getButtonSize: function () { 766 | if (typeof BootstrapDialog.BUTTON_SIZES[this.getSize()] !== 'undefined') { 767 | return BootstrapDialog.BUTTON_SIZES[this.getSize()]; 768 | } 769 | 770 | return ''; 771 | }, 772 | updateButtons: function () { 773 | if (this.isRealized()) { 774 | if (this.getButtons().length === 0) { 775 | this.getModalFooter().hide(); 776 | } else { 777 | this.getModalFooter().show().find('.' + this.getNamespace('footer')).html('').append(this.createFooterButtons()); 778 | } 779 | } 780 | 781 | return this; 782 | }, 783 | isAutodestroy: function () { 784 | return this.options.autodestroy; 785 | }, 786 | setAutodestroy: function (autodestroy) { 787 | this.options.autodestroy = autodestroy; 788 | }, 789 | getDescription: function () { 790 | return this.options.description; 791 | }, 792 | setDescription: function (description) { 793 | this.options.description = description; 794 | 795 | return this; 796 | }, 797 | setTabindex: function (tabindex) { 798 | this.options.tabindex = tabindex; 799 | 800 | return this; 801 | }, 802 | getTabindex: function () { 803 | return this.options.tabindex; 804 | }, 805 | updateTabindex: function () { 806 | if (this.isRealized()) { 807 | this.getModal().attr('tabindex', this.getTabindex()); 808 | } 809 | 810 | return this; 811 | }, 812 | getDefaultText: function () { 813 | return BootstrapDialog.DEFAULT_TEXTS[this.getType()]; 814 | }, 815 | getNamespace: function (name) { 816 | return BootstrapDialog.NAMESPACE + '-' + name; 817 | }, 818 | createHeaderContent: function () { 819 | var $container = $('
'); 820 | $container.addClass(this.getNamespace('header')); 821 | 822 | // title 823 | $container.append(this.createTitleContent()); 824 | 825 | // Close button 826 | $container.prepend(this.createCloseButton()); 827 | 828 | return $container; 829 | }, 830 | createTitleContent: function () { 831 | var $title = $('
'); 832 | $title.addClass(this.getNamespace('title')); 833 | 834 | return $title; 835 | }, 836 | createCloseButton: function () { 837 | var $container = $('
'), $icon; 838 | $container.addClass(this.getNamespace('close-button')); 839 | $icon = $(''); 840 | $icon.append(this.options.closeIcon); 841 | $container.append($icon); 842 | $container.on('click', {dialog: this}, function (event) { 843 | event.data.dialog.close(); 844 | }); 845 | 846 | return $container; 847 | }, 848 | createBodyContent: function () { 849 | var $container = $('
'); 850 | $container.addClass(this.getNamespace('body')); 851 | 852 | // Message 853 | $container.append(this.createMessageContent()); 854 | 855 | return $container; 856 | }, 857 | createMessageContent: function () { 858 | var $message = $('
'); 859 | $message.addClass(this.getNamespace('message')); 860 | 861 | return $message; 862 | }, 863 | createFooterContent: function () { 864 | var $container = $('
'); 865 | $container.addClass(this.getNamespace('footer')); 866 | 867 | return $container; 868 | }, 869 | createFooterButtons: function () { 870 | var that = this; 871 | var $container = $('
'); 872 | $container.addClass(this.getNamespace('footer-buttons')); 873 | this.indexedButtons = {}; 874 | $.each(this.options.buttons, function (index, button) { 875 | if (!button.id) { 876 | button.id = BootstrapDialog.newGuid(); 877 | } 878 | var $button = that.createButton(button); 879 | that.indexedButtons[button.id] = $button; 880 | $container.append($button); 881 | }); 882 | 883 | return $container; 884 | }, 885 | createButton: function (button) { 886 | var $button = $(''); 887 | $button.prop('id', button.id); 888 | $button.data('button', button); 889 | 890 | // Icon 891 | if (typeof button.icon !== 'undefined' && $.trim(button.icon) !== '') { 892 | $button.append(this.createButtonIcon(button.icon)); 893 | } 894 | 895 | // Label 896 | if (typeof button.label !== 'undefined') { 897 | $button.append(button.label); 898 | } 899 | 900 | // title 901 | if (typeof button.title !== 'undefined') { 902 | $button.attr('title', button.title); 903 | } 904 | 905 | // Css class 906 | if (typeof button.cssClass !== 'undefined' && $.trim(button.cssClass) !== '') { 907 | $button.addClass(button.cssClass); 908 | } else { 909 | $button.addClass(this.defaultButtonCss); 910 | } 911 | 912 | // Data attributes 913 | if (typeof button.data === 'object' && button.data.constructor === {}.constructor) { 914 | $.each(button.data, function (key, value) { 915 | $button.attr('data-' + key, value); 916 | }); 917 | } 918 | 919 | // Hotkey 920 | if (typeof button.hotkey !== 'undefined') { 921 | this.registeredButtonHotkeys[button.hotkey] = $button; 922 | } 923 | 924 | // Button on click 925 | $button.on('click', {dialog: this, $button: $button, button: button}, function (event) { 926 | var dialog = event.data.dialog; 927 | var $button = event.data.$button; 928 | var button = $button.data('button'); 929 | if (button.autospin) { 930 | $button.toggleSpin(true); 931 | } 932 | if (typeof button.action === 'function') { 933 | return button.action.call($button, dialog, event); 934 | } 935 | }); 936 | 937 | // Dynamically add extra functions to $button 938 | this.enhanceButton($button); 939 | 940 | //Initialize enabled or not 941 | if (typeof button.enabled !== 'undefined') { 942 | $button.toggleEnable(button.enabled); 943 | } 944 | 945 | return $button; 946 | }, 947 | /** 948 | * Dynamically add extra functions to $button 949 | * 950 | * Using '$this' to reference 'this' is just for better readability. 951 | * 952 | * @param {type} $button 953 | * @returns {_L13.BootstrapDialog.prototype} 954 | */ 955 | enhanceButton: function ($button) { 956 | $button.dialog = this; 957 | 958 | // Enable / Disable 959 | $button.toggleEnable = function (enable) { 960 | var $this = this; 961 | if (typeof enable !== 'undefined') { 962 | $this.prop("disabled", !enable).toggleClass('disabled', !enable); 963 | } else { 964 | $this.prop("disabled", !$this.prop("disabled")); 965 | } 966 | 967 | return $this; 968 | }; 969 | $button.enable = function () { 970 | var $this = this; 971 | $this.toggleEnable(true); 972 | 973 | return $this; 974 | }; 975 | $button.disable = function () { 976 | var $this = this; 977 | $this.toggleEnable(false); 978 | 979 | return $this; 980 | }; 981 | 982 | // Icon spinning, helpful for indicating ajax loading status. 983 | $button.toggleSpin = function (spin) { 984 | var $this = this; 985 | var dialog = $this.dialog; 986 | var $icon = $this.find('.' + dialog.getNamespace('button-icon')); 987 | if (typeof spin === 'undefined') { 988 | spin = !($button.find('.icon-spin').length > 0); 989 | } 990 | if (spin) { 991 | $icon.hide(); 992 | $button.prepend(dialog.createButtonIcon(dialog.getSpinicon()).addClass('icon-spin')); 993 | } else { 994 | $icon.show(); 995 | $button.find('.icon-spin').remove(); 996 | } 997 | 998 | return $this; 999 | }; 1000 | $button.spin = function () { 1001 | var $this = this; 1002 | $this.toggleSpin(true); 1003 | 1004 | return $this; 1005 | }; 1006 | $button.stopSpin = function () { 1007 | var $this = this; 1008 | $this.toggleSpin(false); 1009 | 1010 | return $this; 1011 | }; 1012 | 1013 | return this; 1014 | }, 1015 | createButtonIcon: function (icon) { 1016 | var $icon = $(''); 1017 | $icon.addClass(this.getNamespace('button-icon')).addClass(icon); 1018 | 1019 | return $icon; 1020 | }, 1021 | /** 1022 | * Invoke this only after the dialog is realized. 1023 | * 1024 | * @param {type} enable 1025 | * @returns {undefined} 1026 | */ 1027 | enableButtons: function (enable) { 1028 | $.each(this.indexedButtons, function (id, $button) { 1029 | $button.toggleEnable(enable); 1030 | }); 1031 | 1032 | return this; 1033 | }, 1034 | /** 1035 | * Invoke this only after the dialog is realized. 1036 | * 1037 | * @returns {undefined} 1038 | */ 1039 | updateClosable: function () { 1040 | if (this.isRealized()) { 1041 | // Close button 1042 | this.getModalHeader().find('.' + this.getNamespace('close-button')).toggle(this.isClosable()); 1043 | } 1044 | 1045 | return this; 1046 | }, 1047 | /** 1048 | * Set handler for modal event 'show.bs.modal'. 1049 | * This is a setter! 1050 | */ 1051 | onShow: function (onshow) { 1052 | this.options.onshow = onshow; 1053 | 1054 | return this; 1055 | }, 1056 | /** 1057 | * Set handler for modal event 'shown.bs.modal'. 1058 | * This is a setter! 1059 | */ 1060 | onShown: function (onshown) { 1061 | this.options.onshown = onshown; 1062 | 1063 | return this; 1064 | }, 1065 | /** 1066 | * Set handler for modal event 'hide.bs.modal'. 1067 | * This is a setter! 1068 | */ 1069 | onHide: function (onhide) { 1070 | this.options.onhide = onhide; 1071 | 1072 | return this; 1073 | }, 1074 | /** 1075 | * Set handler for modal event 'hidden.bs.modal'. 1076 | * This is a setter! 1077 | */ 1078 | onHidden: function (onhidden) { 1079 | this.options.onhidden = onhidden; 1080 | 1081 | return this; 1082 | }, 1083 | isRealized: function () { 1084 | return this.realized; 1085 | }, 1086 | setRealized: function (realized) { 1087 | this.realized = realized; 1088 | 1089 | return this; 1090 | }, 1091 | isOpened: function () { 1092 | return this.opened; 1093 | }, 1094 | setOpened: function (opened) { 1095 | this.opened = opened; 1096 | 1097 | return this; 1098 | }, 1099 | handleModalEvents: function () { 1100 | this.getModal().on('show.bs.modal', {dialog: this}, function (event) { 1101 | var dialog = event.data.dialog; 1102 | dialog.setOpened(true); 1103 | if (dialog.isModalEvent(event) && typeof dialog.options.onshow === 'function') { 1104 | var openIt = dialog.options.onshow(dialog); 1105 | if (openIt === false) { 1106 | dialog.setOpened(false); 1107 | } 1108 | 1109 | return openIt; 1110 | } 1111 | }); 1112 | this.getModal().on('shown.bs.modal', {dialog: this}, function (event) { 1113 | var dialog = event.data.dialog; 1114 | dialog.isModalEvent(event) && typeof dialog.options.onshown === 'function' && dialog.options.onshown(dialog); 1115 | }); 1116 | this.getModal().on('hide.bs.modal', {dialog: this}, function (event) { 1117 | var dialog = event.data.dialog; 1118 | dialog.setOpened(false); 1119 | if (dialog.isModalEvent(event) && typeof dialog.options.onhide === 'function') { 1120 | var hideIt = dialog.options.onhide(dialog); 1121 | if (hideIt === false) { 1122 | dialog.setOpened(true); 1123 | } 1124 | 1125 | return hideIt; 1126 | } 1127 | }); 1128 | this.getModal().on('hidden.bs.modal', {dialog: this}, function (event) { 1129 | var dialog = event.data.dialog; 1130 | dialog.isModalEvent(event) && typeof dialog.options.onhidden === 'function' && dialog.options.onhidden(dialog); 1131 | if (dialog.isAutodestroy()) { 1132 | dialog.setRealized(false); 1133 | delete BootstrapDialog.dialogs[dialog.getId()]; 1134 | $(this).remove(); 1135 | } 1136 | BootstrapDialog.moveFocus(); 1137 | if ($('.modal').hasClass('in')) { 1138 | $('body').addClass('modal-open'); 1139 | } 1140 | }); 1141 | 1142 | // Backdrop, I did't find a way to change bs3 backdrop option after the dialog is popped up, so here's a new wheel. 1143 | this.handleModalBackdropEvent(); 1144 | 1145 | // ESC key support 1146 | this.getModal().on('keyup', {dialog: this}, function (event) { 1147 | event.which === 27 && event.data.dialog.isClosable() && event.data.dialog.canCloseByKeyboard() && event.data.dialog.close(); 1148 | }); 1149 | 1150 | // Button hotkey 1151 | this.getModal().on('keyup', {dialog: this}, function (event) { 1152 | var dialog = event.data.dialog; 1153 | if (typeof dialog.registeredButtonHotkeys[event.which] !== 'undefined') { 1154 | var $button = $(dialog.registeredButtonHotkeys[event.which]); 1155 | !$button.prop('disabled') && !$button.is(':focus') && $button.focus().trigger('click'); 1156 | } 1157 | }); 1158 | 1159 | return this; 1160 | }, 1161 | handleModalBackdropEvent: function () { 1162 | this.getModal().on('click', {dialog: this}, function (event) { 1163 | $(event.target).hasClass('modal-backdrop') && event.data.dialog.isClosable() && event.data.dialog.canCloseByBackdrop() && event.data.dialog.close(); 1164 | }); 1165 | 1166 | return this; 1167 | }, 1168 | isModalEvent: function (event) { 1169 | return typeof event.namespace !== 'undefined' && event.namespace === 'bs.modal'; 1170 | }, 1171 | makeModalDraggable: function () { 1172 | if (this.options.draggable) { 1173 | this.getModalHeader().addClass(this.getNamespace('draggable')).on('mousedown', {dialog: this}, function (event) { 1174 | var dialog = event.data.dialog; 1175 | dialog.draggableData.isMouseDown = true; 1176 | var dialogOffset = dialog.getModalDialog().offset(); 1177 | dialog.draggableData.mouseOffset = { 1178 | top: event.clientY - dialogOffset.top, 1179 | left: event.clientX - dialogOffset.left 1180 | }; 1181 | }); 1182 | this.getModal().on('mouseup mouseleave', {dialog: this}, function (event) { 1183 | event.data.dialog.draggableData.isMouseDown = false; 1184 | }); 1185 | $('body').on('mousemove', {dialog: this}, function (event) { 1186 | var dialog = event.data.dialog; 1187 | if (!dialog.draggableData.isMouseDown) { 1188 | return; 1189 | } 1190 | dialog.getModalDialog().offset({ 1191 | top: event.clientY - dialog.draggableData.mouseOffset.top, 1192 | left: event.clientX - dialog.draggableData.mouseOffset.left 1193 | }); 1194 | }); 1195 | } 1196 | 1197 | return this; 1198 | }, 1199 | realize: function () { 1200 | this.initModalStuff(); 1201 | this.getModal().addClass(BootstrapDialog.NAMESPACE) 1202 | .addClass(this.getCssClass()); 1203 | this.updateSize(); 1204 | if (this.getDescription()) { 1205 | this.getModal().attr('aria-describedby', this.getDescription()); 1206 | } 1207 | this.getModalFooter().append(this.createFooterContent()); 1208 | this.getModalHeader().append(this.createHeaderContent()); 1209 | this.getModalBody().append(this.createBodyContent()); 1210 | this.getModal().data('bs.modal', new BootstrapDialogModal(this.getModalForBootstrapDialogModal(), { //FIXME for BootstrapV4 1211 | backdrop: 'static', 1212 | keyboard: false, 1213 | show: false 1214 | })); 1215 | this.makeModalDraggable(); 1216 | this.handleModalEvents(); 1217 | this.setRealized(true); 1218 | this.updateButtons(); 1219 | this.updateType(); 1220 | this.updateTitle(); 1221 | this.updateMessage(); 1222 | this.updateClosable(); 1223 | this.updateAnimate(); 1224 | this.updateSize(); 1225 | this.updateTabindex(); 1226 | 1227 | return this; 1228 | }, 1229 | open: function () { 1230 | !this.isRealized() && this.realize(); 1231 | this.getModal().modal('show'); 1232 | 1233 | return this; 1234 | }, 1235 | close: function () { 1236 | !this.isRealized() && this.realize(); 1237 | this.getModal().modal('hide'); 1238 | 1239 | return this; 1240 | } 1241 | }; 1242 | 1243 | // Add compatible methods. 1244 | BootstrapDialog.prototype = $.extend(BootstrapDialog.prototype, BootstrapDialog.METHODS_TO_OVERRIDE[BootstrapDialogModal.getModalVersion()]); 1245 | 1246 | /** 1247 | * RFC4122 version 4 compliant unique id creator. 1248 | * 1249 | * Added by https://github.com/tufanbarisyildirim/ 1250 | * 1251 | * @returns {String} 1252 | */ 1253 | BootstrapDialog.newGuid = function () { 1254 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 1255 | var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); 1256 | return v.toString(16); 1257 | }); 1258 | }; 1259 | 1260 | /* ================================================ 1261 | * For lazy people 1262 | * ================================================ */ 1263 | 1264 | /** 1265 | * Shortcut function: show 1266 | * 1267 | * @param {type} options 1268 | * @returns the created dialog instance 1269 | */ 1270 | BootstrapDialog.show = function (options) { 1271 | return new BootstrapDialog(options).open(); 1272 | }; 1273 | 1274 | /** 1275 | * Alert window 1276 | * 1277 | * @returns the created dialog instance 1278 | */ 1279 | BootstrapDialog.alert = function () { 1280 | var alertOptions = {}; 1281 | var defaultAlertOptions = { 1282 | type: BootstrapDialog.TYPE_PRIMARY, 1283 | title: null, 1284 | message: null, 1285 | closable: false, 1286 | draggable: false, 1287 | buttonLabel: BootstrapDialog.DEFAULT_TEXTS.OK, 1288 | buttonHotkey: null, 1289 | callback: null 1290 | }; 1291 | 1292 | if (typeof arguments[0] === 'object' && arguments[0].constructor === {}.constructor) { 1293 | alertOptions = $.extend(true, defaultAlertOptions, arguments[0]); 1294 | } else { 1295 | alertOptions = $.extend(true, defaultAlertOptions, { 1296 | message: arguments[0], 1297 | callback: typeof arguments[1] !== 'undefined' ? arguments[1] : null 1298 | }); 1299 | } 1300 | 1301 | var dialog = new BootstrapDialog(alertOptions); 1302 | dialog.setData('callback', alertOptions.callback); 1303 | dialog.addButton({ 1304 | label: alertOptions.buttonLabel, 1305 | hotkey: alertOptions.buttonHotkey, 1306 | action: function (dialog) { 1307 | if (typeof dialog.getData('callback') === 'function' && dialog.getData('callback').call(this, true) === false) { 1308 | return false; 1309 | } 1310 | dialog.setData('btnClicked', true); 1311 | 1312 | return dialog.close(); 1313 | } 1314 | }); 1315 | if (typeof dialog.options.onhide === 'function') { 1316 | dialog.onHide(function (dialog) { 1317 | var hideIt = true; 1318 | if (!dialog.getData('btnClicked') && dialog.isClosable() && typeof dialog.getData('callback') === 'function') { 1319 | hideIt = dialog.getData('callback')(false); 1320 | } 1321 | if (hideIt === false) { 1322 | return false; 1323 | } 1324 | hideIt = this.onhide(dialog); 1325 | 1326 | return hideIt; 1327 | }.bind({ 1328 | onhide: dialog.options.onhide 1329 | })); 1330 | } else { 1331 | dialog.onHide(function (dialog) { 1332 | var hideIt = true; 1333 | if (!dialog.getData('btnClicked') && dialog.isClosable() && typeof dialog.getData('callback') === 'function') { 1334 | hideIt = dialog.getData('callback')(false); 1335 | } 1336 | 1337 | return hideIt; 1338 | }); 1339 | } 1340 | 1341 | return dialog.open(); 1342 | }; 1343 | 1344 | /** 1345 | * Confirm window 1346 | * 1347 | * @returns the created dialog instance 1348 | */ 1349 | BootstrapDialog.confirm = function () { 1350 | var confirmOptions = {}; 1351 | var defaultConfirmOptions = { 1352 | type: BootstrapDialog.TYPE_PRIMARY, 1353 | title: null, 1354 | message: null, 1355 | closable: false, 1356 | draggable: false, 1357 | btnCancelLabel: BootstrapDialog.DEFAULT_TEXTS.CANCEL, 1358 | btnCancelClass: null, 1359 | btnCancelHotkey: null, 1360 | btnOKLabel: BootstrapDialog.DEFAULT_TEXTS.OK, 1361 | btnOKClass: null, 1362 | btnOKHotkey: null, 1363 | btnsOrder: BootstrapDialog.defaultOptions.btnsOrder, 1364 | callback: null 1365 | }; 1366 | if (typeof arguments[0] === 'object' && arguments[0].constructor === {}.constructor) { 1367 | confirmOptions = $.extend(true, defaultConfirmOptions, arguments[0]); 1368 | } else { 1369 | confirmOptions = $.extend(true, defaultConfirmOptions, { 1370 | message: arguments[0], 1371 | callback: typeof arguments[1] !== 'undefined' ? arguments[1] : null 1372 | }); 1373 | } 1374 | if (confirmOptions.btnOKClass === null) { 1375 | confirmOptions.btnOKClass = ['btn', confirmOptions.type.split('-')[1]].join('-'); 1376 | } 1377 | 1378 | var dialog = new BootstrapDialog(confirmOptions); 1379 | dialog.setData('callback', confirmOptions.callback); 1380 | 1381 | var buttons = [{ 1382 | label: confirmOptions.btnCancelLabel, 1383 | cssClass: confirmOptions.btnCancelClass, 1384 | hotkey: confirmOptions.btnCancelHotkey, 1385 | action: function (dialog) { 1386 | if (typeof dialog.getData('callback') === 'function' && dialog.getData('callback').call(this, false) === false) { 1387 | return false; 1388 | } 1389 | 1390 | return dialog.close(); 1391 | } 1392 | }, { 1393 | label: confirmOptions.btnOKLabel, 1394 | cssClass: confirmOptions.btnOKClass, 1395 | hotkey: confirmOptions.btnOKHotkey, 1396 | action: function (dialog) { 1397 | if (typeof dialog.getData('callback') === 'function' && dialog.getData('callback').call(this, true) === false) { 1398 | return false; 1399 | } 1400 | 1401 | return dialog.close(); 1402 | } 1403 | }]; 1404 | if (confirmOptions.btnsOrder === BootstrapDialog.BUTTONS_ORDER_OK_CANCEL) { 1405 | buttons.reverse(); 1406 | } 1407 | dialog.addButtons(buttons); 1408 | 1409 | return dialog.open(); 1410 | 1411 | }; 1412 | 1413 | /** 1414 | * Warning window 1415 | * 1416 | * @param {type} message 1417 | * @returns the created dialog instance 1418 | */ 1419 | BootstrapDialog.warning = function (message, callback) { 1420 | return new BootstrapDialog({ 1421 | type: BootstrapDialog.TYPE_WARNING, 1422 | message: message 1423 | }).open(); 1424 | }; 1425 | 1426 | /** 1427 | * Danger window 1428 | * 1429 | * @param {type} message 1430 | * @returns the created dialog instance 1431 | */ 1432 | BootstrapDialog.danger = function (message, callback) { 1433 | return new BootstrapDialog({ 1434 | type: BootstrapDialog.TYPE_DANGER, 1435 | message: message 1436 | }).open(); 1437 | }; 1438 | 1439 | /** 1440 | * Success window 1441 | * 1442 | * @param {type} message 1443 | * @returns the created dialog instance 1444 | */ 1445 | BootstrapDialog.success = function (message, callback) { 1446 | return new BootstrapDialog({ 1447 | type: BootstrapDialog.TYPE_SUCCESS, 1448 | message: message 1449 | }).open(); 1450 | }; 1451 | 1452 | return BootstrapDialog; 1453 | 1454 | })); 1455 | --------------------------------------------------------------------------------