Skip to content

Commit

Permalink
modal插件。
Browse files Browse the repository at this point in the history
  • Loading branch information
majian159 committed Jul 23, 2015
1 parent 599c6fc commit 3922748
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
@helper PageScripts()
{
@Scripts.Render("~/bundles/jqueryvalidate", "~/bundles/jqueryform", "~/bundles/chineseHelper")
@Scripts.Render("~/bundles/jqueryvalidate", "~/bundles/jqueryform", "~/bundles/chineseHelper", "~/bundles/rabbitAdmin")
<script src="~/Themes/TheAdmin/lib/iCheck/icheck.min.js"></script>
<script src="~/Modules/Rabbit.Blogs/Scripts/table.js"></script>
<script type="text/javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private static void RegisterResources(BundleCollection bundles)
bundles.Add(new StyleBundle("~/content/bootstrap").Include(GetContentPath("Bootstrap/bootstrap.min.css")));
bundles.Add(new StyleBundle("~/content/font-awesome").Include(GetContentPath("font-awesome/css/font-awesome.min.css")));
bundles.Add(new ScriptBundle("~/bundles/chineseHelper").Include(GetScriptPath("ChineseHelper.js")));
bundles.Add(new ScriptBundle("~/bundles/rabbitAdmin").Include(GetScriptPath("RabbitAdmin.js")));
}

private static string GetScriptPath(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
<Content Include="Scripts\jQuery\jquery.1.11.1.min.js" />
<Content Include="Scripts\jQuery\jquery.2.1.1.min.js" />
<Content Include="Scripts\RabbitAdmin.js" />
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions RabbitCMS/Web/Modules/Rabbit.Resources/Scripts/RabbitAdmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
$.modal=function(options) {
var html = '<div class="modal"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title"></h4></div><div class="modal-body"></div><div class="modal-footer"><button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button><button type="button" class="btn btn-primary">Save changes</button></div></div><!-- /.modal-content --></div><!-- /.modal-dialog --></div>';
var body = $("body");
var modal = $(html);
modal.appendTo(body);

options = $.extend({
type: "",
title: "",
cancelText: "",
okText:"",
showClose:true
}, options);

var events = {cancelEvents:[],okEvents: [] };

var controller = {
show: function () {
return this.toggle(true);
},
hide: function () {
return this.toggle(false);
},
toggle: function (b) {
if (b == null)
b = modal.is(":hidden");
if (b)
modal.fadeIn();
else
modal.fadeOut();

return controller;
},
onCancel: function (fn) {
if (fn!=null)
events.cancelEvents.push(fn);
return controller;
},
onOk: function (fn) {
if (fn != null)
events.okEvents.push(fn);
return controller;
}
};

function triggerEvents(events) {
$.each(events, function() {
this();
});
}
function triggerOkEvents() {
triggerEvents(events.okEvents);
}
function triggerCancelEvents() {
triggerEvents(events.cancelEvents);
}

modal.find("[data-dismiss=modal]").click(function() {
controller.hide();
triggerCancelEvents();
});
if (options.type != null && options.type.length != 0) {
modal.addClass("modal-" + options.type);
}
modal.find(".modal-title").append(options.title);
modal.find(".modal-body").append(options.body);

if (options.showClose == false) {
modal.find(".modal-header .close").remove();
}

return controller;
}
$.modal({
title: "test",
body: "asda"
}).show();

0 comments on commit 3922748

Please sign in to comment.