Skip to content

Commit

Permalink
Merge pull request #21 from adrianolaru/spinner
Browse files Browse the repository at this point in the history
Spinner Custom Events
  • Loading branch information
kylefox committed Apr 20, 2012
2 parents eb2dadc + 9af1c83 commit a4a325d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions examples/index.html
Expand Up @@ -178,6 +178,8 @@ <h2>Example 5: the un-closable window</h2>
$(document).on($.modal.OPEN, log_modal_event);
$(document).on($.modal.BEFORE_CLOSE, log_modal_event);
$(document).on($.modal.CLOSE, log_modal_event);
$(document).on($.modal.SHOW_SPINNER, log_modal_event);
$(document).on($.modal.HIDE_SPINNER, log_modal_event);

$('#more').click(function() {
$(this).parent().after($(this).parent().next().clone());
Expand Down
16 changes: 10 additions & 6 deletions jquery.modal.js
Expand Up @@ -8,6 +8,7 @@

$.modal = function(el, options) {
var remove, target;
this.$body = $('body');
this.options = $.extend({}, $.modal.defaults, options);
if (el.is('a')) {
target = el.attr('href');
Expand All @@ -19,16 +20,15 @@
//AJAX
} else {
this.$elm = $('<div>');
this.$body.append(this.$elm);
remove = function(event, modal) { modal.elm.remove(); };
this.showSpinner();
$.get(target).done(function(html) {
if (!current) return;
current.$elm.empty().append(html).appendTo('body').on($.modal.CLOSE, remove);
current.$elm.empty().append(html).on($.modal.CLOSE, remove);
current.hideSpinner();
current.open();
}).fail(function(error) {
current.hideSpinner();
});
}).fail(function() { current.hideSpinner(); });
}
} else {
this.$elm = el;
Expand Down Expand Up @@ -66,7 +66,7 @@
background: this.options.overlay,
opacity: this.options.opacity
});
$('body').append(this.blocker);
this.$body.append(this.blocker);
this.$elm.trigger($.modal.BLOCK, [this._ctx()]);
},

Expand All @@ -93,14 +93,16 @@
},

showSpinner: function() {
this.$elm.trigger($.modal.SHOW_SPINNER, [this._ctx()]);
if (!this.options.showSpinner) return;
this.spinner = $('<div class="' + this.options.modalClass + '-spinner"></div>')
.append(this.options.spinnerHtml);
$('body').append(this.spinner);
this.$body.append(this.spinner);
this.spinner.show();
},

hideSpinner: function() {
this.$elm.trigger($.modal.HIDE_SPINNER, [this._ctx()]);
if (this.spinner) this.spinner.fadeOut();
},

Expand Down Expand Up @@ -156,6 +158,8 @@
$.modal.OPEN = 'modal:open';
$.modal.BEFORE_CLOSE = 'modal:before-close';
$.modal.CLOSE = 'modal:close';
$.modal.SHOW_SPINNER = 'modal:show-spinner';
$.modal.HIDE_SPINNER = 'modal:hide-spinner';

$.fn.modal = function(options){
if (this.length === 1) {
Expand Down

0 comments on commit a4a325d

Please sign in to comment.