Skip to content

Commit 8d1cd84

Browse files
committed
Merge pull request #2 from willywos/master
Updated pull request with changes
2 parents 2eada13 + b7aec7b commit 8d1cd84

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

jquery.bootstrap.dialog.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
(function($){
22
$.fn.bootstrap_dialog = function(options){
3-
var title, ok, cancel;
3+
var title, content, ok, cancel, remove, hide_close;
44
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
55

66
if(typeof options == "string"){
77
switch(options){
88
case "close":
99
$(this).data("current_dialog").hide();
1010
$("#modal_background").hide();
11+
$("#modal").hide();
1112
break;
1213
case "destroy":
1314
$(this).data("current_dialog").remove();
14-
$("#modal_background").hide();
15+
$("#modal_background").remove();
16+
$("#modal").remove();
1517
break;
1618
}
1719
return $(this);
1820
}
1921
if(options) {
2022
title=options.title;
23+
content=options.content;
24+
hide_close=options.hide_close;
2125
if(options.ok)
2226
ok=__bind(options.ok,this);
2327
if(options.cancel)
2428
cancel=__bind(options.cancel,this);
29+
if(options.remove)
30+
remove=__bind(options.remove,this);
2531
}
2632
else {
2733
title="";
@@ -34,17 +40,28 @@
3440
current_dialog=$("<div class='modal'></div>").appendTo("body").attr("style","position:absolute; z-index: 25000; margin: 0");
3541
current_dialog.css("top",($(window).height()-current_dialog.height())/2);
3642
current_dialog.css("left",($(window).width()-current_dialog.width())/2);
37-
$(this).data("current_dialog",current_dialog)
38-
$("<div class='modal-header'/>").appendTo(current_dialog).append("<h3>"+title+"</h3").append("<a href='#' class='close'>x</a>");
39-
console.log(current_dialog)
40-
$("<div class='modal-body'>").appendTo(current_dialog).append($(this));
41-
if(ok || cancel) {
43+
$(this).data("current_dialog",current_dialog);
44+
if(options.hide_close) {
45+
$("<div class='modal-header'/>").appendTo(current_dialog).append("<h3>"+title+"</h3");
46+
} else {
47+
$("<div class='modal-header'/>").appendTo(current_dialog).append("<h3>"+title+"</h3").append("<a href='#' class='close'>x</a>");
48+
}
49+
if(options.content) {
50+
$("<div class='modal-body'>").appendTo(current_dialog).append(options.content);
51+
} else {
52+
$("<div class='modal-body'>").appendTo(current_dialog).append($(this));
53+
}
54+
console.log(current_dialog)
55+
if(ok || cancel || remove) {
4256
footer = $("<div class='modal-footer'>").appendTo(current_dialog);
4357
if(ok) {
44-
$("<a href='#' class='btn primary'>Save</a>").appendTo(footer).click(function(){ok();});
58+
$("<a href='#' class='btn btn-primary'>Save</a>").appendTo(footer).click(function(e){ e.preventDefault(); ok();});
4559
}
4660
if(cancel) {
47-
$("<a href='#' class='btn'>Cancel</a>").appendTo(footer).click(function(){cancel();});
61+
$("<a href='#' class='btn'>Cancel</a>").appendTo(footer).click(function(e){ e.preventDefault(); cancel();});
62+
}
63+
if(remove) {
64+
$("<a href='#' class='btn btn-danger'>Delete</a>").appendTo(footer).click(function(e){ e.preventDefault(); remove();});
4865
}
4966
}
5067
$(current_dialog.find(".modal-header a.close")).click(function(){
@@ -54,3 +71,5 @@
5471
return $(this);
5572
};
5673
})(jQuery);
74+
75+

0 commit comments

Comments
 (0)