src/ztfy/myams/resources/js/ext/bootstrap-modal.js
changeset 118 c87d242a1176
parent 0 8a19e25e39e4
child 174 8d81f90f1d08
--- a/src/ztfy/myams/resources/js/ext/bootstrap-modal.js	Fri Mar 27 15:59:45 2015 +0100
+++ b/src/ztfy/myams/resources/js/ext/bootstrap-modal.js	Fri Mar 27 16:00:30 2015 +0100
@@ -1,5 +1,5 @@
 /* ===========================================================
- * bootstrap-modal.js v2.2.4+
+ * bootstrap-modal.js v2.2.5
  * ===========================================================
  * Copyright 2012 Jordan Schroter
  *
@@ -142,15 +142,15 @@
 
 			var modalOverflow = $(window).height() - 10 < this.$element.height();
 
-			if (modalOverflow || this.options.modalOverflow) {
+//			if (modalOverflow || this.options.modalOverflow) {
 				this.$element
 					.css('margin-top', 0)
 					.addClass('modal-overflow');
-			} else {
-				this.$element
-					.css('margin-top', 0 - this.$element.height() / 2)
-					.removeClass('modal-overflow');
-			}
+//			} else {
+//				this.$element
+//					.css('margin-top', 0 - this.$element.height() / 2)
+//					.removeClass('modal-overflow');
+//			}
 		},
 
 		tab: function () {
@@ -159,23 +159,24 @@
 			if (this.isShown && this.options.consumeTab) {
 				this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
 					if (e.keyCode && e.keyCode == 9) {
-						var $next = $(this),
-							$rollover = $(this);
+						var elements = [],
+							tabindex = Number($(this).data('tabindex'));
+
+						that.$element.find('[data-tabindex]:enabled:visible:not([readonly])').each(function (ev) {
+							elements.push(Number($(this).data('tabindex')));
+						});
+						elements.sort(function(a,b){return a-b});
 
-						that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
-							if (!e.shiftKey) {
-								$next = $next.data('tabindex') < $(this).data('tabindex') ?
-									$next = $(this) :
-									$rollover = $(this);
-							} else {
-								$next = $next.data('tabindex') > $(this).data('tabindex') ?
-									$next = $(this) :
-									$rollover = $(this);
-							}
-						});
-
-						$next[0] !== $(this)[0] ?
-							$next.focus() : $rollover.focus();
+						var arrayPos = $.inArray(tabindex, elements);
+						if (!e.shiftKey){
+							arrayPos < elements.length-1 ?
+								that.$element.find('[data-tabindex='+elements[arrayPos+1]+']').focus() :
+								that.$element.find('[data-tabindex='+elements[0]+']').focus();
+						} else {
+							arrayPos == 0 ?
+								that.$element.find('[data-tabindex='+elements[elements.length-1]+']').focus() :
+								that.$element.find('[data-tabindex='+elements[arrayPos-1]+']').focus();
+						}
 
 						e.preventDefault();
 					}
@@ -233,8 +234,7 @@
 		},
 
 		loading: function (callback) {
-			callback = callback || function () {
-			};
+			callback = callback || function () {};
 
 			var animate = this.$element.hasClass('fade') ? 'fade' : '';
 
@@ -305,26 +305,21 @@
 			this.$element.trigger(e);
 			if (e.isDefaultPrevented()) return;
 
-			this.teardown();
-		},
-
-		teardown: function () {
-			if (!this.$parent.length) {
-				this.$element.remove();
-				this.$element = null;
-				return;
-			}
+			this.$element
+				.off('.modal')
+				.removeData('modal')
+				.removeClass('in')
+				.attr('aria-hidden', true);
 
 			if (this.$parent !== this.$element.parent()) {
 				this.$element.appendTo(this.$parent);
+			} else if (!this.$parent.length) {
+				// modal is not part of the DOM so remove it.
+				this.$element.remove();
+				this.$element = null;
 			}
 
-			this.$element.off('.modal');
-			this.$element.removeData('modal');
-			this.$element
-				.removeClass('in')
-				.attr('aria-hidden', true)
-				.trigger('destroyed');
+			this.$element.trigger('destroyed');
 		}
 	};
 
@@ -381,8 +376,8 @@
 			$target
 				.modal(option)
 				.one('hide', function () {
-						 $this.focus();
-					 })
+					$this.focus();
+				});
 		});
 	});