|
1 | 1 | (function($){ |
2 | 2 | $.fn.bootstrap_dialog = function(options){ |
3 | | - var title, ok, cancel; |
| 3 | + var title, content, ok, cancel, remove, hide_close; |
4 | 4 | var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; |
5 | 5 |
|
6 | 6 | if(typeof options == "string"){ |
7 | 7 | switch(options){ |
8 | 8 | case "close": |
9 | 9 | $(this).data("current_dialog").hide(); |
10 | 10 | $("#modal_background").hide(); |
| 11 | + $("#modal").hide(); |
11 | 12 | break; |
12 | 13 | case "destroy": |
13 | 14 | $(this).data("current_dialog").remove(); |
14 | | - $("#modal_background").hide(); |
| 15 | + $("#modal_background").remove(); |
| 16 | + $("#modal").remove(); |
15 | 17 | break; |
16 | 18 | } |
17 | 19 | return $(this); |
18 | 20 | } |
19 | 21 | if(options) { |
20 | 22 | title=options.title; |
| 23 | + content=options.content; |
| 24 | + hide_close=options.hide_close; |
21 | 25 | if(options.ok) |
22 | 26 | ok=__bind(options.ok,this); |
23 | 27 | if(options.cancel) |
24 | 28 | cancel=__bind(options.cancel,this); |
| 29 | + if(options.remove) |
| 30 | + remove=__bind(options.remove,this); |
25 | 31 | } |
26 | 32 | else { |
27 | 33 | title=""; |
|
34 | 40 | current_dialog=$("<div class='modal'></div>").appendTo("body").attr("style","position:absolute; z-index: 25000; margin: 0"); |
35 | 41 | current_dialog.css("top",($(window).height()-current_dialog.height())/2); |
36 | 42 | 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) { |
42 | 56 | footer = $("<div class='modal-footer'>").appendTo(current_dialog); |
43 | 57 | 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();}); |
45 | 59 | } |
46 | 60 | 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();}); |
48 | 65 | } |
49 | 66 | } |
50 | 67 | $(current_dialog.find(".modal-header a.close")).click(function(){ |
|
54 | 71 | return $(this); |
55 | 72 | }; |
56 | 73 | })(jQuery); |
| 74 | + |
| 75 | + |
0 commit comments