| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  | $(function () { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |   module('modal') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should provide no conflict', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       var modal = $.fn.modal.noConflict() | 
					
						
							|  |  |  |       ok(!$.fn.modal, 'modal was set back to undefined (org value)') | 
					
						
							|  |  |  |       $.fn.modal = modal | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should be defined on jquery object', function () { | 
					
						
							|  |  |  |       var div = $('<div id="modal-test"></div>') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       ok(div.modal, 'modal method is defined') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should return element', function () { | 
					
						
							|  |  |  |       var div = $('<div id="modal-test"></div>') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       ok(div.modal() == div, 'document.body returned') | 
					
						
							|  |  |  |       $('#modal-test').remove() | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should expose defaults var for settings', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should insert into dom when show method is called', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       $('<div id="modal-test"></div>') | 
					
						
							|  |  |  |         .on('shown.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           ok($('#modal-test').length, 'modal inserted into dom') | 
					
						
							|  |  |  |           $(this).remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should fire show event', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       $('<div id="modal-test"></div>') | 
					
						
							|  |  |  |         .on('show.bs.modal', function () { | 
					
						
							|  |  |  |           ok(true, 'show was called') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('shown.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           $(this).remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should not fire shown when default prevented', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       $('<div id="modal-test"></div>') | 
					
						
							|  |  |  |         .on('show.bs.modal', function (e) { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           e.preventDefault() | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |           ok(true, 'show was called') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('shown.bs.modal', function () { | 
					
						
							|  |  |  |           ok(false, 'shown was called') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should hide modal when hide is called', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       $('<div id="modal-test"></div>') | 
					
						
							|  |  |  |         .on('shown.bs.modal', function () { | 
					
						
							|  |  |  |           ok($('#modal-test').is(':visible'), 'modal visible') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           ok($('#modal-test').length, 'modal inserted into dom') | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |           $(this).modal('hide') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('hidden.bs.modal', function () { | 
					
						
							|  |  |  |           ok(!$('#modal-test').is(':visible'), 'modal hidden') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           $('#modal-test').remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should toggle when toggle is called', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       var div = $('<div id="modal-test"></div>') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       div | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('shown.bs.modal', function () { | 
					
						
							|  |  |  |           ok($('#modal-test').is(':visible'), 'modal visible') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           ok($('#modal-test').length, 'modal inserted into dom') | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |           div.modal('toggle') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('hidden.bs.modal', function () { | 
					
						
							|  |  |  |           ok(!$('#modal-test').is(':visible'), 'modal hidden') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           div.remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('toggle') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should remove from dom when click [data-dismiss=modal]', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       var div = $('<div id="modal-test"><span class="close" data-dismiss="modal"></span></div>') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       div | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('shown.bs.modal', function () { | 
					
						
							|  |  |  |           ok($('#modal-test').is(':visible'), 'modal visible') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           ok($('#modal-test').length, 'modal inserted into dom') | 
					
						
							|  |  |  |           div.find('.close').click() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('hidden.bs.modal', function () { | 
					
						
							|  |  |  |           ok(!$('#modal-test').is(':visible'), 'modal hidden') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           div.remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('toggle') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should allow modal close with "backdrop:false"', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       var div = $('<div>', { id: 'modal-test', 'data-backdrop': false }) | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       div | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('shown.bs.modal', function () { | 
					
						
							|  |  |  |           ok($('#modal-test').is(':visible'), 'modal visible') | 
					
						
							|  |  |  |           div.modal('hide') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .on('hidden.bs.modal', function () { | 
					
						
							|  |  |  |           ok(!$('#modal-test').is(':visible'), 'modal hidden') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           div.remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should close modal when clicking outside of modal-content', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       var div = $('<div id="modal-test"><div class="contents"></div></div>') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       div | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .bind('shown.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           ok($('#modal-test').length, 'modal insterted into dom') | 
					
						
							|  |  |  |           $('.contents').click() | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |           ok($('#modal-test').is(':visible'), 'modal visible') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           $('#modal-test').click() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .bind('hidden.bs.modal', function () { | 
					
						
							|  |  |  |           ok(!$('#modal-test').is(':visible'), 'modal hidden') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           div.remove() | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should trigger hide event once when clicking outside of modal-content', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       var triggered | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       var div = $('<div id="modal-test"><div class="contents"></div></div>') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       div | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .bind('shown.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           triggered = 0 | 
					
						
							|  |  |  |           $('#modal-test').click() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .bind('hide.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           triggered += 1 | 
					
						
							|  |  |  |           ok(triggered === 1, 'modal hide triggered once') | 
					
						
							|  |  |  |           start() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |     test('should close reopened modal with [data-dismiss=modal] click', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       stop() | 
					
						
							|  |  |  |       $.support.transition = false | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |       var div = $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"></div></div></div>') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |       div | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .bind('shown.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           $('#close').click() | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |           ok(!$('#modal-test').is(':visible'), 'modal hidden') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .one('hidden.bs.modal', function () { | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |           div.one('hidden.bs.modal', function () { | 
					
						
							|  |  |  |             start() | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |           }).modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:36:17 +03:00
										 |  |  |         .modal('show') | 
					
						
							| 
									
										
										
										
											2014-01-24 11:24:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       div.remove() | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | }) |