Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update backbone.bootstrap-modal adapter

  • Loading branch information...
commit 565e696b46c4ffad60781fbfef7fccf95c655ef1 1 parent 461c3c7
@powmedia authored
View
1  README.md
@@ -905,6 +905,7 @@ Writing a custom editor is simple. They must extend from Backbone.Form.editors.B
###0.10.0
+- Update backbone.bootstrap-modal adapter
- Refactor rendering.
- <legend> tags are now defined in the template.
- Where a template is used, (e.g. advanced editors, field etc.), the entirety of the HTML is now defined in the template to make custom templating easier.
View
35 distribution/adapters/backbone.bootstrap-modal.js
@@ -30,7 +30,7 @@
<h3>{{title}}</h3>\
</div>\
<% } %>\
- <div class="modal-body"><p>{{content}}</p></div>\
+ <div class="modal-body">{{content}}</div>\
<div class="modal-footer">\
<% if (allowCancel) { %>\
<% if (cancelText) { %>\
@@ -54,13 +54,11 @@
event.preventDefault();
this.trigger('cancel');
- this.close();
},
'click .cancel': function(event) {
event.preventDefault();
this.trigger('cancel');
- this.close();
},
'click .ok': function(event) {
event.preventDefault();
@@ -110,11 +108,11 @@
//Create the modal container
$el.html(options.template(options));
- var $content = this.$content = $el.find('.modal-body p')
+ var $content = this.$content = $el.find('.modal-body')
//Insert the main content if it's a view
if (content.$el) {
- $el.find('.modal-body p').html(content.render().$el);
+ $el.find('.modal-body').html(content.render().$el);
}
if (options.animate) $el.addClass('fade');
@@ -126,8 +124,10 @@
/**
* Renders and shows the modal
+ *
+ * @param {Function} [cb] Optional callback that runs only when OK is pressed.
*/
- open: function() {
+ open: function(cb) {
if (!this.isRendered) this.render();
var self = this,
@@ -155,7 +155,26 @@
$backdrop.css('z-index', backdropIndex + numModals);
this.$el.css('z-index', elIndex + numModals);
+ if (this.options.allowCancel) {
+ $backdrop.one('click', function() {
+ self.trigger('cancel');
+ });
+
+ $(document).one('keyup.dismiss.modal', function (e) {
+ e.which == 27 && self.trigger('cancel');
+ });
+ }
+
+ this.on('cancel', function() {
+ self.close();
+ });
+
Modal.count++;
+
+ //Run callback on OK if provided
+ if (cb) {
+ self.on('ok', cb);
+ }
return this;
},
@@ -201,14 +220,14 @@
//EXPORTS
//CommonJS
- if (typeof require == 'function' && module && exports) {
+ if (typeof require == 'function' && typeof module !== 'undefined' && exports) {
module.exports = Modal;
}
//AMD / RequireJS
if (typeof define === 'function' && define.amd) {
return define(function() {
- return Modal;
+ Backbone.BootstrapModal = Modal;
})
}
View
2  distribution/adapters/backbone.bootstrap-modal.min.js
@@ -1 +1 @@
-(function($,_,Backbone){var _interpolateBackup=_.templateSettings;_.templateSettings={interpolate:/\{\{(.+?)\}\}/g,evaluate:/<%([\s\S]+?)%>/g};var template=_.template(' <% if (title) { %> <div class="modal-header"> <% if (allowCancel) { %> <a class="close">×</a> <% } %> <h3>{{title}}</h3> </div> <% } %> <div class="modal-body"><p>{{content}}</p></div> <div class="modal-footer"> <% if (allowCancel) { %> <% if (cancelText) { %> <a href="#" class="btn cancel">{{cancelText}}</a> <% } %> <% } %> <a href="#" class="btn ok btn-primary">{{okText}}</a> </div> ');_.templateSettings=_interpolateBackup;var Modal=Backbone.View.extend({className:"modal",events:{"click .close":function(event){event.preventDefault(),this.trigger("cancel"),this.close()},"click .cancel":function(event){event.preventDefault(),this.trigger("cancel"),this.close()},"click .ok":function(event){event.preventDefault(),this.trigger("ok"),this.close()}},initialize:function(options){this.options=_.extend({title:null,okText:"OK",cancelText:"Cancel",allowCancel:!0,escape:!0,animate:!1,template:template},options)},render:function(){var $el=this.$el,options=this.options,content=options.content;$el.html(options.template(options));var $content=this.$content=$el.find(".modal-body p");return content.$el&&$el.find(".modal-body p").html(content.render().$el),options.animate&&$el.addClass("fade"),this.isRendered=!0,this},open:function(){this.isRendered||this.render();var self=this,$el=this.$el;$el.modal({keyboard:this.options.allowCancel,backdrop:this.options.allowCancel?!0:"static"}),$el.one("shown",function(){$el.find(".btn.ok").focus(),self.trigger("shown")});var numModals=Modal.count,$backdrop=$(".modal-backdrop:eq("+numModals+")"),backdropIndex=$backdrop.css("z-index"),elIndex=$backdrop.css("z-index");return $backdrop.css("z-index",backdropIndex+numModals),this.$el.css("z-index",elIndex+numModals),Modal.count++,this},close:function(){var self=this,$el=this.$el;if(this._preventClose){this._preventClose=!1;return}$el.modal("hide"),$el.one("hidden",function(){self.remove(),self.trigger("hidden")}),Modal.count--},preventClose:function(){this._preventClose=!0}},{count:0});typeof require=="function"&&module&&exports&&(module.exports=Modal);if(typeof define=="function"&&define.amd)return define(function(){return Modal});Backbone.BootstrapModal=Modal})(jQuery,_,Backbone)
+(function($,_,Backbone){var _interpolateBackup=_.templateSettings;_.templateSettings={interpolate:/\{\{(.+?)\}\}/g,evaluate:/<%([\s\S]+?)%>/g};var template=_.template(' <% if (title) { %> <div class="modal-header"> <% if (allowCancel) { %> <a class="close">×</a> <% } %> <h3>{{title}}</h3> </div> <% } %> <div class="modal-body">{{content}}</div> <div class="modal-footer"> <% if (allowCancel) { %> <% if (cancelText) { %> <a href="#" class="btn cancel">{{cancelText}}</a> <% } %> <% } %> <a href="#" class="btn ok btn-primary">{{okText}}</a> </div> ');_.templateSettings=_interpolateBackup;var Modal=Backbone.View.extend({className:"modal",events:{"click .close":function(event){event.preventDefault(),this.trigger("cancel")},"click .cancel":function(event){event.preventDefault(),this.trigger("cancel")},"click .ok":function(event){event.preventDefault(),this.trigger("ok"),this.close()}},initialize:function(options){this.options=_.extend({title:null,okText:"OK",cancelText:"Cancel",allowCancel:!0,escape:!0,animate:!1,template:template},options)},render:function(){var $el=this.$el,options=this.options,content=options.content;$el.html(options.template(options));var $content=this.$content=$el.find(".modal-body");return content.$el&&$el.find(".modal-body").html(content.render().$el),options.animate&&$el.addClass("fade"),this.isRendered=!0,this},open:function(cb){this.isRendered||this.render();var self=this,$el=this.$el;$el.modal({keyboard:this.options.allowCancel,backdrop:this.options.allowCancel?!0:"static"}),$el.one("shown",function(){$el.find(".btn.ok").focus(),self.trigger("shown")});var numModals=Modal.count,$backdrop=$(".modal-backdrop:eq("+numModals+")"),backdropIndex=$backdrop.css("z-index"),elIndex=$backdrop.css("z-index");return $backdrop.css("z-index",backdropIndex+numModals),this.$el.css("z-index",elIndex+numModals),this.options.allowCancel&&($backdrop.one("click",function(){self.trigger("cancel")}),$(document).one("keyup.dismiss.modal",function(e){e.which==27&&self.trigger("cancel")})),this.on("cancel",function(){self.close()}),Modal.count++,cb&&self.on("ok",cb),this},close:function(){var self=this,$el=this.$el;if(this._preventClose){this._preventClose=!1;return}$el.modal("hide"),$el.one("hidden",function(){self.remove(),self.trigger("hidden")}),Modal.count--},preventClose:function(){this._preventClose=!0}},{count:0});typeof require=="function"&&typeof module!="undefined"&&exports&&(module.exports=Modal);if(typeof define=="function"&&define.amd)return define(function(){Backbone.BootstrapModal=Modal});Backbone.BootstrapModal=Modal})(jQuery,_,Backbone)
2  lib/backbone.bootstrap-modal
@@ -1 +1 @@
-Subproject commit 24509716145b178cc2c091f8b51ac231bcf73f8e
+Subproject commit aa8f4b8d3e5637f8d527deebd7f3f567c79bc0d1
2  node_modules/buildify
@@ -1 +1 @@
-Subproject commit aa318c229fb2c89000c1b2a1f3721f915f8daf97
+Subproject commit 0cacbb986397d93e08aeadbbcda318012e7ec419
Please sign in to comment.
Something went wrong with that request. Please try again.