From e6de59003e82e552226f447e3000e2d172b593d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bolila?= Date: Thu, 19 Jun 2014 18:37:29 +0100 Subject: [PATCH] Module loaded without dependency of window.jQuery and one build Gulp script. --- .eslintignore | 1 + .eslintrc | 24 +++ README.md | 17 +- dist/css/bootstrap-dialog.css | 152 +++++++++--------- dist/css/bootstrap-dialog.min.css | 2 +- dist/js/bootstrap-dialog.js | 38 +++-- dist/js/bootstrap-dialog.min.js | 2 +- .../bootstrap-dialog/css/bootstrap-dialog.css | 152 +++++++++--------- .../css/bootstrap-dialog.min.css | 2 +- .../bootstrap-dialog/js/bootstrap-dialog.js | 38 +++-- .../js/bootstrap-dialog.min.js | 2 +- gulpfile.js | 58 +++++++ js/bootstrap-dialog.js | 38 +++-- package.json | 39 +++++ 14 files changed, 360 insertions(+), 205 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 gulpfile.js create mode 100644 package.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a860310 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +node_modules/** diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..9233a42 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,24 @@ +{ + "env": { + "node": true + }, + + "rules": { + "brace-style": [2, "1tbs"], + "default-case": 2, + "func-style": [2, "declaration"], + "guard-for-in": 2, + "no-floating-decimal": 2, + "no-nested-ternary": 2, + "radix": 2, + "space-unary-word-ops": 2, + "space-after-keywords": [2, "always"], + "valid-jsdoc": [2, { + "prefer": { + "return": "returns" + } + }], + "quotes": [1, "single", "allow-avoiding-escaped-quotes"], + "wrap-iife": 2 + } +} diff --git a/README.md b/README.md index e79a4d7..a1ca6cd 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,25 @@ Thanks for [akinoniku](https://github.com/akinoniku)'s suggestions on dialog app ## Use Guidances from contributors -How to use bootstrap-dialog as Rails 4 confirm - @[Genkilabs](https://github.com/Genkilabs) +How to use bootstrap-dialog as Rails 4 confirm - @[Genkilabs](https://github.com/Genkilabs) ================ +## Build instructions: + +Prepare: + +``` +npm install +``` + +Build: + +``` +gulp dist +``` + +================ Licensed under The MIT License. diff --git a/dist/css/bootstrap-dialog.css b/dist/css/bootstrap-dialog.css index 32a001d..4313956 100644 --- a/dist/css/bootstrap-dialog.css +++ b/dist/css/bootstrap-dialog.css @@ -1,120 +1,120 @@ .bootstrap-dialog { - + /* dialog types */ + /* dialog sizes */ + /** + * Icon animation + * Copied from font-awesome: http://fontawesome.io/ + **/ + /** End of icon animation **/ } .bootstrap-dialog .modal-header { - border-top-left-radius: 4px; - border-top-right-radius: 4px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; } .bootstrap-dialog .bootstrap-dialog-title { - color: #fff; - display: inline-block; + color: #fff; + display: inline-block; } -.bootstrap-dialog.type-default .bootstrap-dialog-title { - color: #333; -} -.bootstrap-dialog.size-normal .bootstrap-dialog-title { - font-size: 16px; -} -.bootstrap-dialog.size-large .bootstrap-dialog-title { - font-size: 24px; +.bootstrap-dialog .bootstrap-dialog-button-icon { + margin-right: 3px; } .bootstrap-dialog .bootstrap-dialog-close-button { - float: right; - filter:alpha(opacity=90); - -moz-opacity:0.9; - -khtml-opacity: 0.9; - opacity: 0.9; -} -.bootstrap-dialog.size-normal .bootstrap-dialog-close-button { - font-size: 20px; -} -.bootstrap-dialog.size-large .bootstrap-dialog-close-button { - font-size: 30px; + float: right; + filter: alpha(opacity=90); + -moz-opacity: 0.9; + -khtml-opacity: 0.9; + opacity: 0.9; } .bootstrap-dialog .bootstrap-dialog-close-button:hover { - cursor: pointer; - filter: alpha(opacity=100); - -moz-opacity: 1; - -khtml-opacity: 1; - opacity: 1; -} -.bootstrap-dialog.size-normal .bootstrap-dialog-message { - font-size: 14px; -} -.bootstrap-dialog.size-large .bootstrap-dialog-message { - font-size: 18px; + cursor: pointer; + filter: alpha(opacity=100); + -moz-opacity: 1; + -khtml-opacity: 1; + opacity: 1; } .bootstrap-dialog.type-default .modal-header { - background-color: #fff; + background-color: #fff; +} +.bootstrap-dialog.type-default .bootstrap-dialog-title { + color: #333; } .bootstrap-dialog.type-info .modal-header { - background-color: #5bc0de; + background-color: #5bc0de; } .bootstrap-dialog.type-primary .modal-header { - background-color: #428bca; + background-color: #428bca; } .bootstrap-dialog.type-success .modal-header { - background-color: #5cb85c; + background-color: #5cb85c; } .bootstrap-dialog.type-warning .modal-header { - background-color: #f0ad4e; + background-color: #f0ad4e; } .bootstrap-dialog.type-danger .modal-header { - background-color: #d9534f; + background-color: #d9534f; } -.bootstrap-dialog .bootstrap-dialog-button-icon { - margin-right: 3px; -} - -/** - * Icon animation - * Copied from font-awesome: http://fontawesome.io/ - **/ -.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; +.bootstrap-dialog.size-normal .bootstrap-dialog-title { + font-size: 16px; +} +.bootstrap-dialog.size-normal .bootstrap-dialog-close-button { + font-size: 20px; +} +.bootstrap-dialog.size-normal .bootstrap-dialog-message { + font-size: 14px; +} +.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% { + 0% { -moz-transform: rotate(0deg); -} -100% { + } + 100% { -moz-transform: rotate(359deg); -} + } } @-webkit-keyframes spin { - 0% { + 0% { -webkit-transform: rotate(0deg); -} -100% { + } + 100% { -webkit-transform: rotate(359deg); -} + } } @-o-keyframes spin { - 0% { + 0% { -o-transform: rotate(0deg); -} -100% { + } + 100% { -o-transform: rotate(359deg); -} + } } @-ms-keyframes spin { - 0% { + 0% { -ms-transform: rotate(0deg); -} -100% { + } + 100% { -ms-transform: rotate(359deg); -} + } } @keyframes spin { - 0% { + 0% { transform: rotate(0deg); -} -100% { + } + 100% { transform: rotate(359deg); + } } -} -/** End of icon animation **/ \ No newline at end of file diff --git a/dist/css/bootstrap-dialog.min.css b/dist/css/bootstrap-dialog.min.css index d71349f..b038a38 100644 --- a/dist/css/bootstrap-dialog.min.css +++ b/dist/css/bootstrap-dialog.min.css @@ -1 +1 @@ -.bootstrap-dialog .modal-header{border-top-left-radius:4px;border-top-right-radius:4px}.bootstrap-dialog .bootstrap-dialog-title{color:#fff;display:inline-block}.bootstrap-dialog.type-default .bootstrap-dialog-title{color:#333}.bootstrap-dialog.size-normal .bootstrap-dialog-title{font-size:16px}.bootstrap-dialog.size-large .bootstrap-dialog-title{font-size:24px}.bootstrap-dialog .bootstrap-dialog-close-button{float:right;filter:alpha(opacity=90);-moz-opacity:.9;-khtml-opacity:.9;opacity:.9}.bootstrap-dialog.size-normal .bootstrap-dialog-close-button{font-size:20px}.bootstrap-dialog.size-large .bootstrap-dialog-close-button{font-size:30px}.bootstrap-dialog .bootstrap-dialog-close-button:hover{cursor:pointer;filter:alpha(opacity=100);-moz-opacity:1;-khtml-opacity:1;opacity:1}.bootstrap-dialog.size-normal .bootstrap-dialog-message{font-size:14px}.bootstrap-dialog.size-large .bootstrap-dialog-message{font-size:18px}.bootstrap-dialog.type-default .modal-header{background-color:#fff}.bootstrap-dialog.type-info .modal-header{background-color:#5bc0de}.bootstrap-dialog.type-primary .modal-header{background-color:#428bca}.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 .bootstrap-dialog-button-icon{margin-right:3px}.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)}} \ No newline at end of file +.bootstrap-dialog .modal-header{border-top-left-radius:4px;border-top-right-radius:4px}.bootstrap-dialog .bootstrap-dialog-title{color:#fff;display:inline-block}.bootstrap-dialog .bootstrap-dialog-button-icon{margin-right:3px}.bootstrap-dialog .bootstrap-dialog-close-button{float:right;filter:alpha(opacity=90);-moz-opacity:.9;-khtml-opacity:.9;opacity:.9}.bootstrap-dialog .bootstrap-dialog-close-button:hover{cursor:pointer;filter:alpha(opacity=100);-moz-opacity:1;-khtml-opacity:1;opacity:1}.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:#428bca}.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-normal .bootstrap-dialog-title{font-size:16px}.bootstrap-dialog.size-normal .bootstrap-dialog-close-button{font-size:20px}.bootstrap-dialog.size-normal .bootstrap-dialog-message{font-size:14px}.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(0deg)}100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg)}100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0deg)}100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(359deg)}} \ No newline at end of file diff --git a/dist/js/bootstrap-dialog.js b/dist/js/bootstrap-dialog.js index 84abdb4..db8f258 100644 --- a/dist/js/bootstrap-dialog.js +++ b/dist/js/bootstrap-dialog.js @@ -1,3 +1,5 @@ +/* global define */ + /* ================================================ * Make use of Bootstrap's modal more monkey-friendly. * @@ -9,7 +11,25 @@ * * Licensed under The MIT License. * ================================================ */ -(function($) { +(function(root, factory) { + + "use strict"; + + // CommonJS module is defined + if (typeof module !== 'undefined' && module.exports) { + module.exports = factory(require('jquery')(root)); + } + // AMD module is defined + else if (typeof define === "function" && define.amd) { + define("bootstrap-dialog", ["jquery"], function($) { + return factory($); + }); + } else { + // planted over the root! + root.BootstrapDialog = factory(root.jQuery); + } + +}(this, function($) { "use strict"; @@ -900,20 +920,6 @@ }).open(); }; - BootstrapDialog.init = function() { - // check for nodeJS - var hasModule = (typeof module !== 'undefined' && module.exports); - - // CommonJS module is defined - if (hasModule) - module.exports = BootstrapDialog; - else if (typeof define === "function" && define.amd) - define("bootstrap-dialog", function() { return BootstrapDialog; - }); - else - window.BootstrapDialog = BootstrapDialog; - }; - BootstrapDialog.init(); -})(window.jQuery); +})); diff --git a/dist/js/bootstrap-dialog.min.js b/dist/js/bootstrap-dialog.min.js index 8b750f3..9b4f071 100644 --- a/dist/js/bootstrap-dialog.min.js +++ b/dist/js/bootstrap-dialog.min.js @@ -1 +1 @@ -(function(b){var a=function(c){this.defaultOptions=b.extend(true,{id:a.newGuid(),buttons:[],data:{},onshow:null,onshown:null,onhide:null,onhidden:null},a.defaultOptions);this.indexedButtons={};this.registeredButtonHotkeys={};this.draggableData={isMouseDown:false,mouseOffset:{}};this.realized=false;this.opened=false;this.initOptions(c);this.holdThisInstance()};a.NAMESPACE="bootstrap-dialog";a.TYPE_DEFAULT="type-default";a.TYPE_INFO="type-info";a.TYPE_PRIMARY="type-primary";a.TYPE_SUCCESS="type-success";a.TYPE_WARNING="type-warning";a.TYPE_DANGER="type-danger";a.DEFAULT_TEXTS={};a.DEFAULT_TEXTS[a.TYPE_DEFAULT]="Information";a.DEFAULT_TEXTS[a.TYPE_INFO]="Information";a.DEFAULT_TEXTS[a.TYPE_PRIMARY]="Information";a.DEFAULT_TEXTS[a.TYPE_SUCCESS]="Success";a.DEFAULT_TEXTS[a.TYPE_WARNING]="Warning";a.DEFAULT_TEXTS[a.TYPE_DANGER]="Danger";a.SIZE_NORMAL="size-normal";a.SIZE_LARGE="size-large";a.BUTTON_SIZES={};a.BUTTON_SIZES[a.SIZE_NORMAL]="";a.BUTTON_SIZES[a.SIZE_LARGE]="btn-lg";a.ICON_SPINNER="glyphicon glyphicon-asterisk";a.ZINDEX_BACKDROP=1040;a.ZINDEX_MODAL=1050;a.defaultOptions={type:a.TYPE_PRIMARY,size:a.SIZE_NORMAL,cssClass:"",title:null,message:null,nl2br:true,closable:true,closeByBackdrop:true,closeByKeyboard:true,spinicon:a.ICON_SPINNER,autodestroy:true,draggable:false};a.configDefaultOptions=function(c){a.defaultOptions=b.extend(true,a.defaultOptions,c)};a.dialogs={};a.openAll=function(){b.each(a.dialogs,function(d,c){c.open()})};a.closeAll=function(){b.each(a.dialogs,function(d,c){c.close()})};a.prototype={constructor:a,initOptions:function(c){this.options=b.extend(true,this.defaultOptions,c);return this},holdThisInstance:function(){a.dialogs[this.getId()]=this;return this},initModalStuff:function(){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());return this},createModal:function(){var c=b('');c.prop("id",this.getId());return c},getModal:function(){return this.$modal},setModal:function(c){this.$modal=c;return this},createModalDialog:function(){return b('')},getModalDialog:function(){return this.$modalDialog},setModalDialog:function(c){this.$modalDialog=c;return this},createModalContent:function(){return b('')},getModalContent:function(){return this.$modalContent},setModalContent:function(c){this.$modalContent=c;return this},createModalHeader:function(){return b('')},getModalHeader:function(){return this.$modalHeader},setModalHeader:function(c){this.$modalHeader=c;return this},createModalBody:function(){return b('')},getModalBody:function(){return this.$modalBody},setModalBody:function(c){this.$modalBody=c;return this},createModalFooter:function(){return b('')},getModalFooter:function(){return this.$modalFooter},setModalFooter:function(c){this.$modalFooter=c;return this},createDynamicContent:function(d){var c=null;if(typeof d==="function"){c=d.call(d,this)}else{c=d}if(typeof c==="string"){c=this.formatStringContent(c)}return c},formatStringContent:function(c){if(this.options.nl2br){return c.replace(/\r\n/g,"
").replace(/[\r\n]/g,"
")}return c},setData:function(c,d){this.options.data[c]=d;return this},getData:function(c){return this.options.data[c]},setId:function(c){this.options.id=c;return this},getId:function(){return this.options.id},getType:function(){return this.options.type},setType:function(c){this.options.type=c;return this},getSize:function(){return this.options.size},setSize:function(c){this.options.size=c;return this},getCssClass:function(){return this.options.cssClass},setCssClass:function(c){this.options.cssClass=c;return this},getTitle:function(){return this.options.title},setTitle:function(c){this.options.title=c;this.updateTitle();return this},updateTitle:function(){if(this.isRealized()){var c=this.getTitle()!==null?this.createDynamicContent(this.getTitle()):this.getDefaultText();this.getModalHeader().find("."+this.getNamespace("title")).html("").append(c)}return this},getMessage:function(){return this.options.message},setMessage:function(c){this.options.message=c;this.updateMessage();return this},updateMessage:function(){if(this.isRealized()){var c=this.createDynamicContent(this.getMessage());this.getModalBody().find("."+this.getNamespace("message")).html("").append(c)}return this},isClosable:function(){return this.options.closable},setClosable:function(c){this.options.closable=c;this.updateClosable();return this},setCloseByBackdrop:function(c){this.options.closeByBackdrop=c;return this},canCloseByBackdrop:function(){return this.options.closeByBackdrop},setCloseByKeyboard:function(c){this.options.closeByKeyboard=c;return this},canCloseByKeyboard:function(){return this.options.closeByKeyboard},getSpinicon:function(){return this.options.spinicon},setSpinicon:function(c){this.options.spinicon=c;return this},addButton:function(c){this.options.buttons.push(c);return this},addButtons:function(d){var c=this;b.each(d,function(e,f){c.addButton(f)});return this},getButtons:function(){return this.options.buttons},setButtons:function(c){this.options.buttons=c;this.updateButtons();return this},getButton:function(c){if(typeof this.indexedButtons[c]!=="undefined"){return this.indexedButtons[c]}return null},getButtonSize:function(){if(typeof a.BUTTON_SIZES[this.getSize()]!=="undefined"){return a.BUTTON_SIZES[this.getSize()]}return""},updateButtons:function(){if(this.isRealized()){if(this.getButtons().length===0){this.getModalFooter().hide()}else{this.getModalFooter().find("."+this.getNamespace("footer")).html("").append(this.createFooterButtons())}}return this},isAutodestroy:function(){return this.options.autodestroy},setAutodestroy:function(c){this.options.autodestroy=c},getDefaultText:function(){return a.DEFAULT_TEXTS[this.getType()]},getNamespace:function(c){return a.NAMESPACE+"-"+c},createHeaderContent:function(){var c=b("
");c.addClass(this.getNamespace("header"));c.append(this.createTitleContent());c.prepend(this.createCloseButton());return c},createTitleContent:function(){var c=b("
");c.addClass(this.getNamespace("title"));return c},createCloseButton:function(){var d=b("
");d.addClass(this.getNamespace("close-button"));var c=b('');d.append(c);d.on("click",{dialog:this},function(e){e.data.dialog.close()});return d},createBodyContent:function(){var c=b("
");c.addClass(this.getNamespace("body"));c.append(this.createMessageContent());return c},createMessageContent:function(){var c=b("
");c.addClass(this.getNamespace("message"));return c},createFooterContent:function(){var c=b("
");c.addClass(this.getNamespace("footer"));return c},createFooterButtons:function(){var c=this;var d=b("
");d.addClass(this.getNamespace("footer-buttons"));this.indexedButtons={};b.each(this.options.buttons,function(e,f){if(!f.id){f.id=a.newGuid()}var g=c.createButton(f);c.indexedButtons[f.id]=g;d.append(g)});return d},createButton:function(c){var d=b('');d.addClass(this.getButtonSize());d.prop("id",c.id);if(typeof c.icon!=="undefined"&&b.trim(c.icon)!==""){d.append(this.createButtonIcon(c.icon))}if(typeof c.label!=="undefined"){d.append(c.label)}if(typeof c.cssClass!=="undefined"&&b.trim(c.cssClass)!==""){d.addClass(c.cssClass)}else{d.addClass("btn-default")}if(typeof c.hotkey!=="undefined"){this.registeredButtonHotkeys[c.hotkey]=d}d.on("click",{dialog:this,$button:d,button:c},function(g){var f=g.data.dialog;var h=g.data.$button;var e=g.data.button;if(typeof e.action==="function"){e.action.call(h,f)}if(e.autospin){h.toggleSpin(true)}});this.enhanceButton(d);return d},enhanceButton:function(c){c.dialog=this;c.toggleEnable=function(d){var e=this;e.prop("disabled",!d).toggleClass("disabled",!d);return e};c.enable=function(){var d=this;d.toggleEnable(true);return d};c.disable=function(){var d=this;d.toggleEnable(false);return d};c.toggleSpin=function(g){var f=this;var e=f.dialog;var d=f.find("."+e.getNamespace("button-icon"));if(g){d.hide();c.prepend(e.createButtonIcon(e.getSpinicon()).addClass("icon-spin"))}else{d.show();c.find(".icon-spin").remove()}return f};c.spin=function(){var d=this;d.toggleSpin(true);return d};c.stopSpin=function(){var d=this;d.toggleSpin(false);return d};return this},createButtonIcon:function(d){var c=b("");c.addClass(this.getNamespace("button-icon")).addClass(d);return c},enableButtons:function(c){b.each(this.indexedButtons,function(e,d){d.toggleEnable(c)});return this},updateClosable:function(){if(this.isRealized()){this.getModalHeader().find("."+this.getNamespace("close-button")).toggle(this.isClosable())}return this},onShow:function(c){this.options.onshow=c;return this},onShown:function(c){this.options.onshown=c;return this},onHide:function(c){this.options.onhide=c;return this},onHidden:function(c){this.options.onhidden=c;return this},isRealized:function(){return this.realized},setRealized:function(c){this.realized=c;return this},isOpened:function(){return this.opened},setOpened:function(c){this.opened=c;return this},handleModalEvents:function(){this.getModal().on("show.bs.modal",{dialog:this},function(d){var c=d.data.dialog;c.showPageScrollBar(true);if(typeof c.options.onshow==="function"){return c.options.onshow(c)}});this.getModal().on("shown.bs.modal",{dialog:this},function(d){var c=d.data.dialog;typeof c.options.onshown==="function"&&c.options.onshown(c);c.showPageScrollBar(true)});this.getModal().on("hide.bs.modal",{dialog:this},function(d){var c=d.data.dialog;if(typeof c.options.onhide==="function"){return c.options.onhide(c)}});this.getModal().on("hidden.bs.modal",{dialog:this},function(d){var c=d.data.dialog;typeof c.options.onhidden==="function"&&c.options.onhidden(c);c.isAutodestroy()&&b(this).remove();c.showPageScrollBar(false)});this.getModal().on("click",{dialog:this},function(c){c.target===this&&c.data.dialog.isClosable()&&c.data.dialog.canCloseByBackdrop()&&c.data.dialog.close()});this.getModal().on("keyup",{dialog:this},function(c){c.which===27&&c.data.dialog.isClosable()&&c.data.dialog.canCloseByKeyboard()&&c.data.dialog.close()});this.getModal().on("keyup",{dialog:this},function(d){var c=d.data.dialog;if(typeof c.registeredButtonHotkeys[d.which]!=="undefined"){var e=b(c.registeredButtonHotkeys[d.which]);!e.prop("disabled")&&e.focus().trigger("click")}});return this},makeModalDraggable:function(){if(this.options.draggable){this.getModalHeader().addClass(this.getNamespace("draggable")).on("mousedown",{dialog:this},function(e){var d=e.data.dialog;d.draggableData.isMouseDown=true;var c=d.getModalContent().offset();d.draggableData.mouseOffset={top:e.clientY-c.top,left:e.clientX-c.left}});this.getModal().on("mouseup mouseleave",{dialog:this},function(c){c.data.dialog.draggableData.isMouseDown=false});b("body").on("mousemove",{dialog:this},function(d){var c=d.data.dialog;if(!c.draggableData.isMouseDown){return}c.getModalContent().offset({top:d.clientY-c.draggableData.mouseOffset.top,left:d.clientX-c.draggableData.mouseOffset.left})})}return this},showPageScrollBar:function(c){b(document.body).toggleClass("modal-open",c)},updateZIndex:function(){var e=Object.keys(a.dialogs).length;if(e>1){var d=this.getModal();var c=d.data("bs.modal").$backdrop;d.css("z-index",a.ZINDEX_MODAL+(e-1)*20);c.css("z-index",a.ZINDEX_BACKDROP+(e-1)*20)}return this},realize:function(){this.initModalStuff();this.getModal().addClass(a.NAMESPACE).addClass(this.getType()).addClass(this.getSize()).addClass(this.getCssClass());this.getModalFooter().append(this.createFooterContent());this.getModalHeader().append(this.createHeaderContent());this.getModalBody().append(this.createBodyContent());this.getModal().modal({backdrop:"static",keyboard:false,show:false});this.makeModalDraggable();this.handleModalEvents();this.setRealized(true);this.updateButtons();this.updateTitle();this.updateMessage();this.updateClosable();return this},open:function(){!this.isRealized()&&this.realize();this.getModal().modal("show");this.updateZIndex();this.setOpened(true);return this},close:function(){this.getModal().modal("hide");if(this.isAutodestroy()){delete a.dialogs[this.getId()]}this.setOpened(false);return this}};a.newGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(f){var e=Math.random()*16|0,d=f==="x"?e:(e&3|8);return d.toString(16)})};a.show=function(c){return new a(c).open()};a.alert=function(){var d={};var c={type:a.TYPE_PRIMARY,title:null,message:null,closable:true,buttonLabel:"OK",callback:null};if(typeof arguments[0]==="object"&&arguments[0].constructor==={}.constructor){d=b.extend(true,c,arguments[0])}else{d=b.extend(true,c,{message:arguments[0],closable:false,buttonLabel:"OK",callback:typeof arguments[1]!=="undefined"?arguments[1]:null})}return new a({type:d.type,title:d.title,message:d.message,closable:d.closable,data:{callback:d.callback},onhide:function(e){!e.getData("btnClicked")&&e.isClosable()&&typeof e.getData("callback")==="function"&&e.getData("callback")(false)},buttons:[{label:d.buttonLabel,action:function(e){e.setData("btnClicked",true);typeof e.getData("callback")==="function"&&e.getData("callback")(true);e.close()}}]}).open()};a.confirm=function(c,d){return new a({title:"Confirmation",message:c,closable:false,data:{callback:d},buttons:[{label:"Cancel",action:function(e){typeof e.getData("callback")==="function"&&e.getData("callback")(false);e.close()}},{label:"OK",cssClass:"btn-primary",action:function(e){typeof e.getData("callback")==="function"&&e.getData("callback")(true);e.close()}}]}).open()};a.init=function(){var c=(typeof module!=="undefined"&&module.exports);if(c){module.exports=a}else{if(typeof define==="function"&&define.amd){define("bootstrap-dialog",function(){return a})}else{window.BootstrapDialog=a}}};a.init()})(window.jQuery); \ No newline at end of file +!function(t,e){"use strict";"undefined"!=typeof module&&module.exports?module.exports=e(require("jquery")(t)):"function"==typeof define&&define.amd?define("bootstrap-dialog",["jquery"],function(t){return e(t)}):t.BootstrapDialog=e(t.jQuery)}(this,function(t){"use strict";var e=function(n){this.defaultOptions=t.extend(!0,{id:e.newGuid(),buttons:[],data:{},onshow:null,onshown:null,onhide:null,onhidden:null},e.defaultOptions),this.indexedButtons={},this.registeredButtonHotkeys={},this.draggableData={isMouseDown:!1,mouseOffset:{}},this.realized=!1,this.opened=!1,this.initOptions(n),this.holdThisInstance()};return e.NAMESPACE="bootstrap-dialog",e.TYPE_DEFAULT="type-default",e.TYPE_INFO="type-info",e.TYPE_PRIMARY="type-primary",e.TYPE_SUCCESS="type-success",e.TYPE_WARNING="type-warning",e.TYPE_DANGER="type-danger",e.DEFAULT_TEXTS={},e.DEFAULT_TEXTS[e.TYPE_DEFAULT]="Information",e.DEFAULT_TEXTS[e.TYPE_INFO]="Information",e.DEFAULT_TEXTS[e.TYPE_PRIMARY]="Information",e.DEFAULT_TEXTS[e.TYPE_SUCCESS]="Success",e.DEFAULT_TEXTS[e.TYPE_WARNING]="Warning",e.DEFAULT_TEXTS[e.TYPE_DANGER]="Danger",e.SIZE_NORMAL="size-normal",e.SIZE_LARGE="size-large",e.BUTTON_SIZES={},e.BUTTON_SIZES[e.SIZE_NORMAL]="",e.BUTTON_SIZES[e.SIZE_LARGE]="btn-lg",e.ICON_SPINNER="glyphicon glyphicon-asterisk",e.ZINDEX_BACKDROP=1040,e.ZINDEX_MODAL=1050,e.defaultOptions={type:e.TYPE_PRIMARY,size:e.SIZE_NORMAL,cssClass:"",title:null,message:null,nl2br:!0,closable:!0,closeByBackdrop:!0,closeByKeyboard:!0,spinicon:e.ICON_SPINNER,autodestroy:!0,draggable:!1},e.configDefaultOptions=function(n){e.defaultOptions=t.extend(!0,e.defaultOptions,n)},e.dialogs={},e.openAll=function(){t.each(e.dialogs,function(t,e){e.open()})},e.closeAll=function(){t.each(e.dialogs,function(t,e){e.close()})},e.prototype={constructor:e,initOptions:function(e){return this.options=t.extend(!0,this.defaultOptions,e),this},holdThisInstance:function(){return e.dialogs[this.getId()]=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},getModal:function(){return this.$modal},setModal:function(t){return this.$modal=t,this},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(){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},getType:function(){return this.options.type},setType:function(t){return this.options.type=t,this},getSize:function(){return this.options.size},setSize:function(t){return this.options.size=t,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)}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},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 e.BUTTON_SIZES[this.getSize()]?e.BUTTON_SIZES[this.getSize()]:""},updateButtons:function(){return this.isRealized()&&(0===this.getButtons().length?this.getModalFooter().hide():this.getModalFooter().find("."+this.getNamespace("footer")).html("").append(this.createFooterButtons())),this},isAutodestroy:function(){return this.options.autodestroy},setAutodestroy:function(t){this.options.autodestroy=t},getDefaultText:function(){return e.DEFAULT_TEXTS[this.getType()]},getNamespace:function(t){return e.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=t("
");e.addClass(this.getNamespace("close-button"));var n=t('');return e.append(n),e.on("click",{dialog:this},function(t){t.data.dialog.close()}),e},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 n=this,o=t("
");return o.addClass(this.getNamespace("footer-buttons")),this.indexedButtons={},t.each(this.options.buttons,function(t,i){i.id||(i.id=e.newGuid());var s=n.createButton(i);n.indexedButtons[i.id]=s,o.append(s)}),o},createButton:function(e){var n=t('');return n.addClass(this.getButtonSize()),n.prop("id",e.id),"undefined"!=typeof e.icon&&""!==t.trim(e.icon)&&n.append(this.createButtonIcon(e.icon)),"undefined"!=typeof e.label&&n.append(e.label),n.addClass("undefined"!=typeof e.cssClass&&""!==t.trim(e.cssClass)?e.cssClass:"btn-default"),"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=t.data.button;"function"==typeof o.action&&o.action.call(n,e),o.autospin&&n.toggleSpin(!0)}),this.enhanceButton(n),n},enhanceButton:function(t){return t.dialog=this,t.toggleEnable=function(t){var e=this;return e.prop("disabled",!t).toggleClass("disabled",!t),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 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;return e.showPageScrollBar(!0),"function"==typeof e.options.onshow?e.options.onshow(e):void 0}),this.getModal().on("shown.bs.modal",{dialog:this},function(t){var e=t.data.dialog;"function"==typeof e.options.onshown&&e.options.onshown(e),e.showPageScrollBar(!0)}),this.getModal().on("hide.bs.modal",{dialog:this},function(t){var e=t.data.dialog;return"function"==typeof e.options.onhide?e.options.onhide(e):void 0}),this.getModal().on("hidden.bs.modal",{dialog:this},function(e){var n=e.data.dialog;"function"==typeof n.options.onhidden&&n.options.onhidden(n),n.isAutodestroy()&&t(this).remove(),n.showPageScrollBar(!1)}),this.getModal().on("click",{dialog:this},function(t){t.target===this&&t.data.dialog.isClosable()&&t.data.dialog.canCloseByBackdrop()&&t.data.dialog.close()}),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.focus().trigger("click")}}),this},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.getModalContent().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.getModalContent().offset({top:t.clientY-e.draggableData.mouseOffset.top,left:t.clientX-e.draggableData.mouseOffset.left})})),this},showPageScrollBar:function(e){t(document.body).toggleClass("modal-open",e)},updateZIndex:function(){var t=Object.keys(e.dialogs).length;if(t>1){var n=this.getModal(),o=n.data("bs.modal").$backdrop;n.css("z-index",e.ZINDEX_MODAL+20*(t-1)),o.css("z-index",e.ZINDEX_BACKDROP+20*(t-1))}return this},realize:function(){return this.initModalStuff(),this.getModal().addClass(e.NAMESPACE).addClass(this.getType()).addClass(this.getSize()).addClass(this.getCssClass()),this.getModalFooter().append(this.createFooterContent()),this.getModalHeader().append(this.createHeaderContent()),this.getModalBody().append(this.createBodyContent()),this.getModal().modal({backdrop:"static",keyboard:!1,show:!1}),this.makeModalDraggable(),this.handleModalEvents(),this.setRealized(!0),this.updateButtons(),this.updateTitle(),this.updateMessage(),this.updateClosable(),this},open:function(){return!this.isRealized()&&this.realize(),this.getModal().modal("show"),this.updateZIndex(),this.setOpened(!0),this},close:function(){return this.getModal().modal("hide"),this.isAutodestroy()&&delete e.dialogs[this.getId()],this.setOpened(!1),this}},e.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)})},e.show=function(t){return new e(t).open()},e.alert=function(){var n={},o={type:e.TYPE_PRIMARY,title:null,message:null,closable:!0,buttonLabel:"OK",callback:null};return n="object"==typeof arguments[0]&&arguments[0].constructor==={}.constructor?t.extend(!0,o,arguments[0]):t.extend(!0,o,{message:arguments[0],closable:!1,buttonLabel:"OK",callback:"undefined"!=typeof arguments[1]?arguments[1]:null}),new e({type:n.type,title:n.title,message:n.message,closable:n.closable,data:{callback:n.callback},onhide:function(t){!t.getData("btnClicked")&&t.isClosable()&&"function"==typeof t.getData("callback")&&t.getData("callback")(!1)},buttons:[{label:n.buttonLabel,action:function(t){t.setData("btnClicked",!0),"function"==typeof t.getData("callback")&&t.getData("callback")(!0),t.close()}}]}).open()},e.confirm=function(t,n){return new e({title:"Confirmation",message:t,closable:!1,data:{callback:n},buttons:[{label:"Cancel",action:function(t){"function"==typeof t.getData("callback")&&t.getData("callback")(!1),t.close()}},{label:"OK",cssClass:"btn-primary",action:function(t){"function"==typeof t.getData("callback")&&t.getData("callback")(!0),t.close()}}]}).open()},e}); \ No newline at end of file diff --git a/examples/assets/bootstrap-dialog/css/bootstrap-dialog.css b/examples/assets/bootstrap-dialog/css/bootstrap-dialog.css index 32a001d..4313956 100644 --- a/examples/assets/bootstrap-dialog/css/bootstrap-dialog.css +++ b/examples/assets/bootstrap-dialog/css/bootstrap-dialog.css @@ -1,120 +1,120 @@ .bootstrap-dialog { - + /* dialog types */ + /* dialog sizes */ + /** + * Icon animation + * Copied from font-awesome: http://fontawesome.io/ + **/ + /** End of icon animation **/ } .bootstrap-dialog .modal-header { - border-top-left-radius: 4px; - border-top-right-radius: 4px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; } .bootstrap-dialog .bootstrap-dialog-title { - color: #fff; - display: inline-block; + color: #fff; + display: inline-block; } -.bootstrap-dialog.type-default .bootstrap-dialog-title { - color: #333; -} -.bootstrap-dialog.size-normal .bootstrap-dialog-title { - font-size: 16px; -} -.bootstrap-dialog.size-large .bootstrap-dialog-title { - font-size: 24px; +.bootstrap-dialog .bootstrap-dialog-button-icon { + margin-right: 3px; } .bootstrap-dialog .bootstrap-dialog-close-button { - float: right; - filter:alpha(opacity=90); - -moz-opacity:0.9; - -khtml-opacity: 0.9; - opacity: 0.9; -} -.bootstrap-dialog.size-normal .bootstrap-dialog-close-button { - font-size: 20px; -} -.bootstrap-dialog.size-large .bootstrap-dialog-close-button { - font-size: 30px; + float: right; + filter: alpha(opacity=90); + -moz-opacity: 0.9; + -khtml-opacity: 0.9; + opacity: 0.9; } .bootstrap-dialog .bootstrap-dialog-close-button:hover { - cursor: pointer; - filter: alpha(opacity=100); - -moz-opacity: 1; - -khtml-opacity: 1; - opacity: 1; -} -.bootstrap-dialog.size-normal .bootstrap-dialog-message { - font-size: 14px; -} -.bootstrap-dialog.size-large .bootstrap-dialog-message { - font-size: 18px; + cursor: pointer; + filter: alpha(opacity=100); + -moz-opacity: 1; + -khtml-opacity: 1; + opacity: 1; } .bootstrap-dialog.type-default .modal-header { - background-color: #fff; + background-color: #fff; +} +.bootstrap-dialog.type-default .bootstrap-dialog-title { + color: #333; } .bootstrap-dialog.type-info .modal-header { - background-color: #5bc0de; + background-color: #5bc0de; } .bootstrap-dialog.type-primary .modal-header { - background-color: #428bca; + background-color: #428bca; } .bootstrap-dialog.type-success .modal-header { - background-color: #5cb85c; + background-color: #5cb85c; } .bootstrap-dialog.type-warning .modal-header { - background-color: #f0ad4e; + background-color: #f0ad4e; } .bootstrap-dialog.type-danger .modal-header { - background-color: #d9534f; + background-color: #d9534f; } -.bootstrap-dialog .bootstrap-dialog-button-icon { - margin-right: 3px; -} - -/** - * Icon animation - * Copied from font-awesome: http://fontawesome.io/ - **/ -.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; +.bootstrap-dialog.size-normal .bootstrap-dialog-title { + font-size: 16px; +} +.bootstrap-dialog.size-normal .bootstrap-dialog-close-button { + font-size: 20px; +} +.bootstrap-dialog.size-normal .bootstrap-dialog-message { + font-size: 14px; +} +.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% { + 0% { -moz-transform: rotate(0deg); -} -100% { + } + 100% { -moz-transform: rotate(359deg); -} + } } @-webkit-keyframes spin { - 0% { + 0% { -webkit-transform: rotate(0deg); -} -100% { + } + 100% { -webkit-transform: rotate(359deg); -} + } } @-o-keyframes spin { - 0% { + 0% { -o-transform: rotate(0deg); -} -100% { + } + 100% { -o-transform: rotate(359deg); -} + } } @-ms-keyframes spin { - 0% { + 0% { -ms-transform: rotate(0deg); -} -100% { + } + 100% { -ms-transform: rotate(359deg); -} + } } @keyframes spin { - 0% { + 0% { transform: rotate(0deg); -} -100% { + } + 100% { transform: rotate(359deg); + } } -} -/** End of icon animation **/ \ No newline at end of file diff --git a/examples/assets/bootstrap-dialog/css/bootstrap-dialog.min.css b/examples/assets/bootstrap-dialog/css/bootstrap-dialog.min.css index d71349f..b038a38 100644 --- a/examples/assets/bootstrap-dialog/css/bootstrap-dialog.min.css +++ b/examples/assets/bootstrap-dialog/css/bootstrap-dialog.min.css @@ -1 +1 @@ -.bootstrap-dialog .modal-header{border-top-left-radius:4px;border-top-right-radius:4px}.bootstrap-dialog .bootstrap-dialog-title{color:#fff;display:inline-block}.bootstrap-dialog.type-default .bootstrap-dialog-title{color:#333}.bootstrap-dialog.size-normal .bootstrap-dialog-title{font-size:16px}.bootstrap-dialog.size-large .bootstrap-dialog-title{font-size:24px}.bootstrap-dialog .bootstrap-dialog-close-button{float:right;filter:alpha(opacity=90);-moz-opacity:.9;-khtml-opacity:.9;opacity:.9}.bootstrap-dialog.size-normal .bootstrap-dialog-close-button{font-size:20px}.bootstrap-dialog.size-large .bootstrap-dialog-close-button{font-size:30px}.bootstrap-dialog .bootstrap-dialog-close-button:hover{cursor:pointer;filter:alpha(opacity=100);-moz-opacity:1;-khtml-opacity:1;opacity:1}.bootstrap-dialog.size-normal .bootstrap-dialog-message{font-size:14px}.bootstrap-dialog.size-large .bootstrap-dialog-message{font-size:18px}.bootstrap-dialog.type-default .modal-header{background-color:#fff}.bootstrap-dialog.type-info .modal-header{background-color:#5bc0de}.bootstrap-dialog.type-primary .modal-header{background-color:#428bca}.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 .bootstrap-dialog-button-icon{margin-right:3px}.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)}} \ No newline at end of file +.bootstrap-dialog .modal-header{border-top-left-radius:4px;border-top-right-radius:4px}.bootstrap-dialog .bootstrap-dialog-title{color:#fff;display:inline-block}.bootstrap-dialog .bootstrap-dialog-button-icon{margin-right:3px}.bootstrap-dialog .bootstrap-dialog-close-button{float:right;filter:alpha(opacity=90);-moz-opacity:.9;-khtml-opacity:.9;opacity:.9}.bootstrap-dialog .bootstrap-dialog-close-button:hover{cursor:pointer;filter:alpha(opacity=100);-moz-opacity:1;-khtml-opacity:1;opacity:1}.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:#428bca}.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-normal .bootstrap-dialog-title{font-size:16px}.bootstrap-dialog.size-normal .bootstrap-dialog-close-button{font-size:20px}.bootstrap-dialog.size-normal .bootstrap-dialog-message{font-size:14px}.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(0deg)}100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg)}100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0deg)}100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(359deg)}} \ No newline at end of file diff --git a/examples/assets/bootstrap-dialog/js/bootstrap-dialog.js b/examples/assets/bootstrap-dialog/js/bootstrap-dialog.js index 84abdb4..db8f258 100644 --- a/examples/assets/bootstrap-dialog/js/bootstrap-dialog.js +++ b/examples/assets/bootstrap-dialog/js/bootstrap-dialog.js @@ -1,3 +1,5 @@ +/* global define */ + /* ================================================ * Make use of Bootstrap's modal more monkey-friendly. * @@ -9,7 +11,25 @@ * * Licensed under The MIT License. * ================================================ */ -(function($) { +(function(root, factory) { + + "use strict"; + + // CommonJS module is defined + if (typeof module !== 'undefined' && module.exports) { + module.exports = factory(require('jquery')(root)); + } + // AMD module is defined + else if (typeof define === "function" && define.amd) { + define("bootstrap-dialog", ["jquery"], function($) { + return factory($); + }); + } else { + // planted over the root! + root.BootstrapDialog = factory(root.jQuery); + } + +}(this, function($) { "use strict"; @@ -900,20 +920,6 @@ }).open(); }; - BootstrapDialog.init = function() { - // check for nodeJS - var hasModule = (typeof module !== 'undefined' && module.exports); - - // CommonJS module is defined - if (hasModule) - module.exports = BootstrapDialog; - else if (typeof define === "function" && define.amd) - define("bootstrap-dialog", function() { return BootstrapDialog; - }); - else - window.BootstrapDialog = BootstrapDialog; - }; - BootstrapDialog.init(); -})(window.jQuery); +})); diff --git a/examples/assets/bootstrap-dialog/js/bootstrap-dialog.min.js b/examples/assets/bootstrap-dialog/js/bootstrap-dialog.min.js index 8b750f3..9b4f071 100644 --- a/examples/assets/bootstrap-dialog/js/bootstrap-dialog.min.js +++ b/examples/assets/bootstrap-dialog/js/bootstrap-dialog.min.js @@ -1 +1 @@ -(function(b){var a=function(c){this.defaultOptions=b.extend(true,{id:a.newGuid(),buttons:[],data:{},onshow:null,onshown:null,onhide:null,onhidden:null},a.defaultOptions);this.indexedButtons={};this.registeredButtonHotkeys={};this.draggableData={isMouseDown:false,mouseOffset:{}};this.realized=false;this.opened=false;this.initOptions(c);this.holdThisInstance()};a.NAMESPACE="bootstrap-dialog";a.TYPE_DEFAULT="type-default";a.TYPE_INFO="type-info";a.TYPE_PRIMARY="type-primary";a.TYPE_SUCCESS="type-success";a.TYPE_WARNING="type-warning";a.TYPE_DANGER="type-danger";a.DEFAULT_TEXTS={};a.DEFAULT_TEXTS[a.TYPE_DEFAULT]="Information";a.DEFAULT_TEXTS[a.TYPE_INFO]="Information";a.DEFAULT_TEXTS[a.TYPE_PRIMARY]="Information";a.DEFAULT_TEXTS[a.TYPE_SUCCESS]="Success";a.DEFAULT_TEXTS[a.TYPE_WARNING]="Warning";a.DEFAULT_TEXTS[a.TYPE_DANGER]="Danger";a.SIZE_NORMAL="size-normal";a.SIZE_LARGE="size-large";a.BUTTON_SIZES={};a.BUTTON_SIZES[a.SIZE_NORMAL]="";a.BUTTON_SIZES[a.SIZE_LARGE]="btn-lg";a.ICON_SPINNER="glyphicon glyphicon-asterisk";a.ZINDEX_BACKDROP=1040;a.ZINDEX_MODAL=1050;a.defaultOptions={type:a.TYPE_PRIMARY,size:a.SIZE_NORMAL,cssClass:"",title:null,message:null,nl2br:true,closable:true,closeByBackdrop:true,closeByKeyboard:true,spinicon:a.ICON_SPINNER,autodestroy:true,draggable:false};a.configDefaultOptions=function(c){a.defaultOptions=b.extend(true,a.defaultOptions,c)};a.dialogs={};a.openAll=function(){b.each(a.dialogs,function(d,c){c.open()})};a.closeAll=function(){b.each(a.dialogs,function(d,c){c.close()})};a.prototype={constructor:a,initOptions:function(c){this.options=b.extend(true,this.defaultOptions,c);return this},holdThisInstance:function(){a.dialogs[this.getId()]=this;return this},initModalStuff:function(){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());return this},createModal:function(){var c=b('');c.prop("id",this.getId());return c},getModal:function(){return this.$modal},setModal:function(c){this.$modal=c;return this},createModalDialog:function(){return b('')},getModalDialog:function(){return this.$modalDialog},setModalDialog:function(c){this.$modalDialog=c;return this},createModalContent:function(){return b('')},getModalContent:function(){return this.$modalContent},setModalContent:function(c){this.$modalContent=c;return this},createModalHeader:function(){return b('')},getModalHeader:function(){return this.$modalHeader},setModalHeader:function(c){this.$modalHeader=c;return this},createModalBody:function(){return b('')},getModalBody:function(){return this.$modalBody},setModalBody:function(c){this.$modalBody=c;return this},createModalFooter:function(){return b('')},getModalFooter:function(){return this.$modalFooter},setModalFooter:function(c){this.$modalFooter=c;return this},createDynamicContent:function(d){var c=null;if(typeof d==="function"){c=d.call(d,this)}else{c=d}if(typeof c==="string"){c=this.formatStringContent(c)}return c},formatStringContent:function(c){if(this.options.nl2br){return c.replace(/\r\n/g,"
").replace(/[\r\n]/g,"
")}return c},setData:function(c,d){this.options.data[c]=d;return this},getData:function(c){return this.options.data[c]},setId:function(c){this.options.id=c;return this},getId:function(){return this.options.id},getType:function(){return this.options.type},setType:function(c){this.options.type=c;return this},getSize:function(){return this.options.size},setSize:function(c){this.options.size=c;return this},getCssClass:function(){return this.options.cssClass},setCssClass:function(c){this.options.cssClass=c;return this},getTitle:function(){return this.options.title},setTitle:function(c){this.options.title=c;this.updateTitle();return this},updateTitle:function(){if(this.isRealized()){var c=this.getTitle()!==null?this.createDynamicContent(this.getTitle()):this.getDefaultText();this.getModalHeader().find("."+this.getNamespace("title")).html("").append(c)}return this},getMessage:function(){return this.options.message},setMessage:function(c){this.options.message=c;this.updateMessage();return this},updateMessage:function(){if(this.isRealized()){var c=this.createDynamicContent(this.getMessage());this.getModalBody().find("."+this.getNamespace("message")).html("").append(c)}return this},isClosable:function(){return this.options.closable},setClosable:function(c){this.options.closable=c;this.updateClosable();return this},setCloseByBackdrop:function(c){this.options.closeByBackdrop=c;return this},canCloseByBackdrop:function(){return this.options.closeByBackdrop},setCloseByKeyboard:function(c){this.options.closeByKeyboard=c;return this},canCloseByKeyboard:function(){return this.options.closeByKeyboard},getSpinicon:function(){return this.options.spinicon},setSpinicon:function(c){this.options.spinicon=c;return this},addButton:function(c){this.options.buttons.push(c);return this},addButtons:function(d){var c=this;b.each(d,function(e,f){c.addButton(f)});return this},getButtons:function(){return this.options.buttons},setButtons:function(c){this.options.buttons=c;this.updateButtons();return this},getButton:function(c){if(typeof this.indexedButtons[c]!=="undefined"){return this.indexedButtons[c]}return null},getButtonSize:function(){if(typeof a.BUTTON_SIZES[this.getSize()]!=="undefined"){return a.BUTTON_SIZES[this.getSize()]}return""},updateButtons:function(){if(this.isRealized()){if(this.getButtons().length===0){this.getModalFooter().hide()}else{this.getModalFooter().find("."+this.getNamespace("footer")).html("").append(this.createFooterButtons())}}return this},isAutodestroy:function(){return this.options.autodestroy},setAutodestroy:function(c){this.options.autodestroy=c},getDefaultText:function(){return a.DEFAULT_TEXTS[this.getType()]},getNamespace:function(c){return a.NAMESPACE+"-"+c},createHeaderContent:function(){var c=b("
");c.addClass(this.getNamespace("header"));c.append(this.createTitleContent());c.prepend(this.createCloseButton());return c},createTitleContent:function(){var c=b("
");c.addClass(this.getNamespace("title"));return c},createCloseButton:function(){var d=b("
");d.addClass(this.getNamespace("close-button"));var c=b('');d.append(c);d.on("click",{dialog:this},function(e){e.data.dialog.close()});return d},createBodyContent:function(){var c=b("
");c.addClass(this.getNamespace("body"));c.append(this.createMessageContent());return c},createMessageContent:function(){var c=b("
");c.addClass(this.getNamespace("message"));return c},createFooterContent:function(){var c=b("
");c.addClass(this.getNamespace("footer"));return c},createFooterButtons:function(){var c=this;var d=b("
");d.addClass(this.getNamespace("footer-buttons"));this.indexedButtons={};b.each(this.options.buttons,function(e,f){if(!f.id){f.id=a.newGuid()}var g=c.createButton(f);c.indexedButtons[f.id]=g;d.append(g)});return d},createButton:function(c){var d=b('');d.addClass(this.getButtonSize());d.prop("id",c.id);if(typeof c.icon!=="undefined"&&b.trim(c.icon)!==""){d.append(this.createButtonIcon(c.icon))}if(typeof c.label!=="undefined"){d.append(c.label)}if(typeof c.cssClass!=="undefined"&&b.trim(c.cssClass)!==""){d.addClass(c.cssClass)}else{d.addClass("btn-default")}if(typeof c.hotkey!=="undefined"){this.registeredButtonHotkeys[c.hotkey]=d}d.on("click",{dialog:this,$button:d,button:c},function(g){var f=g.data.dialog;var h=g.data.$button;var e=g.data.button;if(typeof e.action==="function"){e.action.call(h,f)}if(e.autospin){h.toggleSpin(true)}});this.enhanceButton(d);return d},enhanceButton:function(c){c.dialog=this;c.toggleEnable=function(d){var e=this;e.prop("disabled",!d).toggleClass("disabled",!d);return e};c.enable=function(){var d=this;d.toggleEnable(true);return d};c.disable=function(){var d=this;d.toggleEnable(false);return d};c.toggleSpin=function(g){var f=this;var e=f.dialog;var d=f.find("."+e.getNamespace("button-icon"));if(g){d.hide();c.prepend(e.createButtonIcon(e.getSpinicon()).addClass("icon-spin"))}else{d.show();c.find(".icon-spin").remove()}return f};c.spin=function(){var d=this;d.toggleSpin(true);return d};c.stopSpin=function(){var d=this;d.toggleSpin(false);return d};return this},createButtonIcon:function(d){var c=b("");c.addClass(this.getNamespace("button-icon")).addClass(d);return c},enableButtons:function(c){b.each(this.indexedButtons,function(e,d){d.toggleEnable(c)});return this},updateClosable:function(){if(this.isRealized()){this.getModalHeader().find("."+this.getNamespace("close-button")).toggle(this.isClosable())}return this},onShow:function(c){this.options.onshow=c;return this},onShown:function(c){this.options.onshown=c;return this},onHide:function(c){this.options.onhide=c;return this},onHidden:function(c){this.options.onhidden=c;return this},isRealized:function(){return this.realized},setRealized:function(c){this.realized=c;return this},isOpened:function(){return this.opened},setOpened:function(c){this.opened=c;return this},handleModalEvents:function(){this.getModal().on("show.bs.modal",{dialog:this},function(d){var c=d.data.dialog;c.showPageScrollBar(true);if(typeof c.options.onshow==="function"){return c.options.onshow(c)}});this.getModal().on("shown.bs.modal",{dialog:this},function(d){var c=d.data.dialog;typeof c.options.onshown==="function"&&c.options.onshown(c);c.showPageScrollBar(true)});this.getModal().on("hide.bs.modal",{dialog:this},function(d){var c=d.data.dialog;if(typeof c.options.onhide==="function"){return c.options.onhide(c)}});this.getModal().on("hidden.bs.modal",{dialog:this},function(d){var c=d.data.dialog;typeof c.options.onhidden==="function"&&c.options.onhidden(c);c.isAutodestroy()&&b(this).remove();c.showPageScrollBar(false)});this.getModal().on("click",{dialog:this},function(c){c.target===this&&c.data.dialog.isClosable()&&c.data.dialog.canCloseByBackdrop()&&c.data.dialog.close()});this.getModal().on("keyup",{dialog:this},function(c){c.which===27&&c.data.dialog.isClosable()&&c.data.dialog.canCloseByKeyboard()&&c.data.dialog.close()});this.getModal().on("keyup",{dialog:this},function(d){var c=d.data.dialog;if(typeof c.registeredButtonHotkeys[d.which]!=="undefined"){var e=b(c.registeredButtonHotkeys[d.which]);!e.prop("disabled")&&e.focus().trigger("click")}});return this},makeModalDraggable:function(){if(this.options.draggable){this.getModalHeader().addClass(this.getNamespace("draggable")).on("mousedown",{dialog:this},function(e){var d=e.data.dialog;d.draggableData.isMouseDown=true;var c=d.getModalContent().offset();d.draggableData.mouseOffset={top:e.clientY-c.top,left:e.clientX-c.left}});this.getModal().on("mouseup mouseleave",{dialog:this},function(c){c.data.dialog.draggableData.isMouseDown=false});b("body").on("mousemove",{dialog:this},function(d){var c=d.data.dialog;if(!c.draggableData.isMouseDown){return}c.getModalContent().offset({top:d.clientY-c.draggableData.mouseOffset.top,left:d.clientX-c.draggableData.mouseOffset.left})})}return this},showPageScrollBar:function(c){b(document.body).toggleClass("modal-open",c)},updateZIndex:function(){var e=Object.keys(a.dialogs).length;if(e>1){var d=this.getModal();var c=d.data("bs.modal").$backdrop;d.css("z-index",a.ZINDEX_MODAL+(e-1)*20);c.css("z-index",a.ZINDEX_BACKDROP+(e-1)*20)}return this},realize:function(){this.initModalStuff();this.getModal().addClass(a.NAMESPACE).addClass(this.getType()).addClass(this.getSize()).addClass(this.getCssClass());this.getModalFooter().append(this.createFooterContent());this.getModalHeader().append(this.createHeaderContent());this.getModalBody().append(this.createBodyContent());this.getModal().modal({backdrop:"static",keyboard:false,show:false});this.makeModalDraggable();this.handleModalEvents();this.setRealized(true);this.updateButtons();this.updateTitle();this.updateMessage();this.updateClosable();return this},open:function(){!this.isRealized()&&this.realize();this.getModal().modal("show");this.updateZIndex();this.setOpened(true);return this},close:function(){this.getModal().modal("hide");if(this.isAutodestroy()){delete a.dialogs[this.getId()]}this.setOpened(false);return this}};a.newGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(f){var e=Math.random()*16|0,d=f==="x"?e:(e&3|8);return d.toString(16)})};a.show=function(c){return new a(c).open()};a.alert=function(){var d={};var c={type:a.TYPE_PRIMARY,title:null,message:null,closable:true,buttonLabel:"OK",callback:null};if(typeof arguments[0]==="object"&&arguments[0].constructor==={}.constructor){d=b.extend(true,c,arguments[0])}else{d=b.extend(true,c,{message:arguments[0],closable:false,buttonLabel:"OK",callback:typeof arguments[1]!=="undefined"?arguments[1]:null})}return new a({type:d.type,title:d.title,message:d.message,closable:d.closable,data:{callback:d.callback},onhide:function(e){!e.getData("btnClicked")&&e.isClosable()&&typeof e.getData("callback")==="function"&&e.getData("callback")(false)},buttons:[{label:d.buttonLabel,action:function(e){e.setData("btnClicked",true);typeof e.getData("callback")==="function"&&e.getData("callback")(true);e.close()}}]}).open()};a.confirm=function(c,d){return new a({title:"Confirmation",message:c,closable:false,data:{callback:d},buttons:[{label:"Cancel",action:function(e){typeof e.getData("callback")==="function"&&e.getData("callback")(false);e.close()}},{label:"OK",cssClass:"btn-primary",action:function(e){typeof e.getData("callback")==="function"&&e.getData("callback")(true);e.close()}}]}).open()};a.init=function(){var c=(typeof module!=="undefined"&&module.exports);if(c){module.exports=a}else{if(typeof define==="function"&&define.amd){define("bootstrap-dialog",function(){return a})}else{window.BootstrapDialog=a}}};a.init()})(window.jQuery); \ No newline at end of file +!function(t,e){"use strict";"undefined"!=typeof module&&module.exports?module.exports=e(require("jquery")(t)):"function"==typeof define&&define.amd?define("bootstrap-dialog",["jquery"],function(t){return e(t)}):t.BootstrapDialog=e(t.jQuery)}(this,function(t){"use strict";var e=function(n){this.defaultOptions=t.extend(!0,{id:e.newGuid(),buttons:[],data:{},onshow:null,onshown:null,onhide:null,onhidden:null},e.defaultOptions),this.indexedButtons={},this.registeredButtonHotkeys={},this.draggableData={isMouseDown:!1,mouseOffset:{}},this.realized=!1,this.opened=!1,this.initOptions(n),this.holdThisInstance()};return e.NAMESPACE="bootstrap-dialog",e.TYPE_DEFAULT="type-default",e.TYPE_INFO="type-info",e.TYPE_PRIMARY="type-primary",e.TYPE_SUCCESS="type-success",e.TYPE_WARNING="type-warning",e.TYPE_DANGER="type-danger",e.DEFAULT_TEXTS={},e.DEFAULT_TEXTS[e.TYPE_DEFAULT]="Information",e.DEFAULT_TEXTS[e.TYPE_INFO]="Information",e.DEFAULT_TEXTS[e.TYPE_PRIMARY]="Information",e.DEFAULT_TEXTS[e.TYPE_SUCCESS]="Success",e.DEFAULT_TEXTS[e.TYPE_WARNING]="Warning",e.DEFAULT_TEXTS[e.TYPE_DANGER]="Danger",e.SIZE_NORMAL="size-normal",e.SIZE_LARGE="size-large",e.BUTTON_SIZES={},e.BUTTON_SIZES[e.SIZE_NORMAL]="",e.BUTTON_SIZES[e.SIZE_LARGE]="btn-lg",e.ICON_SPINNER="glyphicon glyphicon-asterisk",e.ZINDEX_BACKDROP=1040,e.ZINDEX_MODAL=1050,e.defaultOptions={type:e.TYPE_PRIMARY,size:e.SIZE_NORMAL,cssClass:"",title:null,message:null,nl2br:!0,closable:!0,closeByBackdrop:!0,closeByKeyboard:!0,spinicon:e.ICON_SPINNER,autodestroy:!0,draggable:!1},e.configDefaultOptions=function(n){e.defaultOptions=t.extend(!0,e.defaultOptions,n)},e.dialogs={},e.openAll=function(){t.each(e.dialogs,function(t,e){e.open()})},e.closeAll=function(){t.each(e.dialogs,function(t,e){e.close()})},e.prototype={constructor:e,initOptions:function(e){return this.options=t.extend(!0,this.defaultOptions,e),this},holdThisInstance:function(){return e.dialogs[this.getId()]=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},getModal:function(){return this.$modal},setModal:function(t){return this.$modal=t,this},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(){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},getType:function(){return this.options.type},setType:function(t){return this.options.type=t,this},getSize:function(){return this.options.size},setSize:function(t){return this.options.size=t,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)}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},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 e.BUTTON_SIZES[this.getSize()]?e.BUTTON_SIZES[this.getSize()]:""},updateButtons:function(){return this.isRealized()&&(0===this.getButtons().length?this.getModalFooter().hide():this.getModalFooter().find("."+this.getNamespace("footer")).html("").append(this.createFooterButtons())),this},isAutodestroy:function(){return this.options.autodestroy},setAutodestroy:function(t){this.options.autodestroy=t},getDefaultText:function(){return e.DEFAULT_TEXTS[this.getType()]},getNamespace:function(t){return e.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=t("
");e.addClass(this.getNamespace("close-button"));var n=t('');return e.append(n),e.on("click",{dialog:this},function(t){t.data.dialog.close()}),e},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 n=this,o=t("
");return o.addClass(this.getNamespace("footer-buttons")),this.indexedButtons={},t.each(this.options.buttons,function(t,i){i.id||(i.id=e.newGuid());var s=n.createButton(i);n.indexedButtons[i.id]=s,o.append(s)}),o},createButton:function(e){var n=t('');return n.addClass(this.getButtonSize()),n.prop("id",e.id),"undefined"!=typeof e.icon&&""!==t.trim(e.icon)&&n.append(this.createButtonIcon(e.icon)),"undefined"!=typeof e.label&&n.append(e.label),n.addClass("undefined"!=typeof e.cssClass&&""!==t.trim(e.cssClass)?e.cssClass:"btn-default"),"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=t.data.button;"function"==typeof o.action&&o.action.call(n,e),o.autospin&&n.toggleSpin(!0)}),this.enhanceButton(n),n},enhanceButton:function(t){return t.dialog=this,t.toggleEnable=function(t){var e=this;return e.prop("disabled",!t).toggleClass("disabled",!t),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 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;return e.showPageScrollBar(!0),"function"==typeof e.options.onshow?e.options.onshow(e):void 0}),this.getModal().on("shown.bs.modal",{dialog:this},function(t){var e=t.data.dialog;"function"==typeof e.options.onshown&&e.options.onshown(e),e.showPageScrollBar(!0)}),this.getModal().on("hide.bs.modal",{dialog:this},function(t){var e=t.data.dialog;return"function"==typeof e.options.onhide?e.options.onhide(e):void 0}),this.getModal().on("hidden.bs.modal",{dialog:this},function(e){var n=e.data.dialog;"function"==typeof n.options.onhidden&&n.options.onhidden(n),n.isAutodestroy()&&t(this).remove(),n.showPageScrollBar(!1)}),this.getModal().on("click",{dialog:this},function(t){t.target===this&&t.data.dialog.isClosable()&&t.data.dialog.canCloseByBackdrop()&&t.data.dialog.close()}),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.focus().trigger("click")}}),this},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.getModalContent().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.getModalContent().offset({top:t.clientY-e.draggableData.mouseOffset.top,left:t.clientX-e.draggableData.mouseOffset.left})})),this},showPageScrollBar:function(e){t(document.body).toggleClass("modal-open",e)},updateZIndex:function(){var t=Object.keys(e.dialogs).length;if(t>1){var n=this.getModal(),o=n.data("bs.modal").$backdrop;n.css("z-index",e.ZINDEX_MODAL+20*(t-1)),o.css("z-index",e.ZINDEX_BACKDROP+20*(t-1))}return this},realize:function(){return this.initModalStuff(),this.getModal().addClass(e.NAMESPACE).addClass(this.getType()).addClass(this.getSize()).addClass(this.getCssClass()),this.getModalFooter().append(this.createFooterContent()),this.getModalHeader().append(this.createHeaderContent()),this.getModalBody().append(this.createBodyContent()),this.getModal().modal({backdrop:"static",keyboard:!1,show:!1}),this.makeModalDraggable(),this.handleModalEvents(),this.setRealized(!0),this.updateButtons(),this.updateTitle(),this.updateMessage(),this.updateClosable(),this},open:function(){return!this.isRealized()&&this.realize(),this.getModal().modal("show"),this.updateZIndex(),this.setOpened(!0),this},close:function(){return this.getModal().modal("hide"),this.isAutodestroy()&&delete e.dialogs[this.getId()],this.setOpened(!1),this}},e.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)})},e.show=function(t){return new e(t).open()},e.alert=function(){var n={},o={type:e.TYPE_PRIMARY,title:null,message:null,closable:!0,buttonLabel:"OK",callback:null};return n="object"==typeof arguments[0]&&arguments[0].constructor==={}.constructor?t.extend(!0,o,arguments[0]):t.extend(!0,o,{message:arguments[0],closable:!1,buttonLabel:"OK",callback:"undefined"!=typeof arguments[1]?arguments[1]:null}),new e({type:n.type,title:n.title,message:n.message,closable:n.closable,data:{callback:n.callback},onhide:function(t){!t.getData("btnClicked")&&t.isClosable()&&"function"==typeof t.getData("callback")&&t.getData("callback")(!1)},buttons:[{label:n.buttonLabel,action:function(t){t.setData("btnClicked",!0),"function"==typeof t.getData("callback")&&t.getData("callback")(!0),t.close()}}]}).open()},e.confirm=function(t,n){return new e({title:"Confirmation",message:t,closable:!1,data:{callback:n},buttons:[{label:"Cancel",action:function(t){"function"==typeof t.getData("callback")&&t.getData("callback")(!1),t.close()}},{label:"OK",cssClass:"btn-primary",action:function(t){"function"==typeof t.getData("callback")&&t.getData("callback")(!0),t.close()}}]}).open()},e}); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..936baf7 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,58 @@ +// Gulpfile.js + +"use strict"; + +var gulp = require("gulp"), + eslint = require("gulp-eslint"), + less = require("gulp-less"), + minifyCSS = require("gulp-minify-css"), + path = require("path"), + notify = require("gulp-notify"), + clean = require("gulp-clean"), + rename = require("gulp-rename"), + uglify = require("gulp-uglify"); + + +gulp.task("less", function() { + gulp.src("less/bootstrap-dialog.less") + .pipe(gulp.dest("dist/less")) + .pipe(less({ + paths: [path.join(__dirname, "less", "includes")] + })) + .pipe(gulp.dest("dist/css")) + .pipe(gulp.dest("examples/assets/bootstrap-dialog/css")) + .pipe(rename("bootstrap-dialog.min.css")) + .pipe(minifyCSS()) + .pipe(gulp.dest("dist/css")) + .pipe(gulp.dest("examples/assets/bootstrap-dialog/css")); +}); + +gulp.task("lint", function() { + gulp.src(["js/bootstrap-dialog.js"]) + .pipe(eslint()) + .pipe(eslint.format()); +}); + +gulp.task("dist", ["clean", "less"], function() { + gulp.src(["js/bootstrap-dialog.js"]) + .pipe(gulp.dest("dist/js")) + .pipe(gulp.dest("examples/assets/bootstrap-dialog/js")) + .pipe(rename("bootstrap-dialog.min.js")) + .pipe(uglify()) + .pipe(gulp.dest("dist/js")) + .pipe(gulp.dest("examples/assets/bootstrap-dialog/js")) + .pipe(notify({ + message: "Build task completed." + })); +}); + +gulp.task("clean", function() { + return gulp.src(["dist/"], { + read: false + }) + .pipe(clean()); +}); + +gulp.task("default", ["clean"], function() { + gulp.start("dist"); +}); diff --git a/js/bootstrap-dialog.js b/js/bootstrap-dialog.js index 84abdb4..db8f258 100644 --- a/js/bootstrap-dialog.js +++ b/js/bootstrap-dialog.js @@ -1,3 +1,5 @@ +/* global define */ + /* ================================================ * Make use of Bootstrap's modal more monkey-friendly. * @@ -9,7 +11,25 @@ * * Licensed under The MIT License. * ================================================ */ -(function($) { +(function(root, factory) { + + "use strict"; + + // CommonJS module is defined + if (typeof module !== 'undefined' && module.exports) { + module.exports = factory(require('jquery')(root)); + } + // AMD module is defined + else if (typeof define === "function" && define.amd) { + define("bootstrap-dialog", ["jquery"], function($) { + return factory($); + }); + } else { + // planted over the root! + root.BootstrapDialog = factory(root.jQuery); + } + +}(this, function($) { "use strict"; @@ -900,20 +920,6 @@ }).open(); }; - BootstrapDialog.init = function() { - // check for nodeJS - var hasModule = (typeof module !== 'undefined' && module.exports); - - // CommonJS module is defined - if (hasModule) - module.exports = BootstrapDialog; - else if (typeof define === "function" && define.amd) - define("bootstrap-dialog", function() { return BootstrapDialog; - }); - else - window.BootstrapDialog = BootstrapDialog; - }; - BootstrapDialog.init(); -})(window.jQuery); +})); diff --git a/package.json b/package.json new file mode 100644 index 0000000..e984d8d --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "bootstrap3-dialog", + "version": "1.30.0", + "description": "Make use of Twitter Bootstrap's modal more monkey-friendly.", + "private": true, + "directories": { + "example": "examples" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/nakupanda/bootstrap3-dialog.git" + }, + "keywords": [ + "bootstrap", + "dialog" + ], + "author": "nakupanda", + "license": "MIT", + "bugs": { + "url": "https://github.com/nakupanda/bootstrap3-dialog/issues" + }, + "homepage": "http://nakupanda.github.io/bootstrap3-dialog", + "devDependencies": { + "eslint": ">=0.6.2", + "gulp": ">=3.8.1", + "gulp-clean": ">=0.3.0", + "gulp-eslint": ">=0.1.7", + "gulp-less": ">=1.2.3", + "gulp-minify-css": "^0.3.4", + "gulp-notify": ">=1.3.1", + "gulp-rename": ">=1.2.0", + "gulp-streamify": "0.0.5", + "gulp-uglify": ">=0.3.0", + "vinyl-source-stream": "^0.1.1" + } +}