function createDialog() { if (!dialog) { dialog = $('<div class="modal fade w-online-dialog">' + '<div class="modal-dialog">' + '<div class="modal-content">' + '<div class="modal-body">' + '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>' + '<div class="w-online-dialog-ctn"></div>' + '</div>' + '<div class="modal-footer">' + '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>' + '</div>' + '</div>' + '</div>' + '</div>').appendTo(document.body); } return dialog; }
__.each(this.imgHashes, (hash, i) => { if (i < subImageDivs.length){ $(subImageDivs[i]).css('background-image', 'url(' + this.getImageUrl(hash) + ')'); } else { $('<div class="itemImg itemImg-small js-editItemSubImage floatLeft" style="background-image: url(' + this.getImageUrl(hash) + ');"><div class="btn btn-corner btn-cornerTR btn-cornerTRSmall btn-flushTop btn-c1 fade btn-shadow1 js-editItemDeleteImage"><i class="ion-close-round icon-centered icon-small"></i></div></div>') .appendTo(self.$('.js-subImageWrap')); } });
QUnit.test('should not close a collapse when initialized with "show" option if already shown', function (assert) { assert.expect(0) var done = assert.async() var $test = $('<div id="test1" class="show"/>') .appendTo('#qunit-fixture') .on('hide.bs.collapse', function () { assert.ok(false) }) $test.bootstrapCollapse('show') setTimeout(done, 0) })
QUnit.test('should activate element by tab id in ordered list', function (assert) { assert.expect(2) var pillsHTML = '<ol class="nav nav-pills">' + '<li><a href="#home">Home</a></li>' + '<li><a href="#profile">Profile</a></li>' + '</ol>' $('<ol><li id="home"/><li id="profile"/></ol>').appendTo('#qunit-fixture') $(pillsHTML).find('li:last-child a').bootstrapTab('show') assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') $(pillsHTML).find('li:first-child a').bootstrapTab('show') assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home') })
QUnit.test('should not call _slide if the carousel is sliding', function (assert) { assert.expect(1) var carouselHTML = '<div class="carousel" data-interval="false"></div>' var $carousel = $(carouselHTML) $carousel.appendTo('#qunit-fixture') $carousel.bootstrapCarousel() var carousel = $carousel.data('bs.carousel') var spy = sinon.spy(carousel, '_slide') carousel._isSliding = true carousel.next() assert.strictEqual(spy.called, false) })
QUnit.test('should cycle when there is data-ride attribute', function (assert) { assert.expect(1) var spy = sinon.spy(Carousel.prototype, 'cycle') var carouselHTML = '<div class="carousel" data-ride="carousel"></div>' var $carousel = $(carouselHTML) $carousel.appendTo('#qunit-fixture') $carousel.bootstrapCarousel() assert.strictEqual(spy.called, true) spy.restore() })
QUnit.test('selected tab should deactivate previous selected tab', function (assert) { assert.expect(2) var tabsHTML = '<ul class="nav nav-tabs">' + '<li class="nav-item"><a class="nav-link active" href="#home" data-toggle="tab">Home</a></li>' + '<li class="nav-item"><a class="nav-link" href="#profile" data-toggle="tab">Profile</a></li>' + '</ul>' var $tabs = $(tabsHTML).appendTo('#qunit-fixture') $tabs.find('li:last-child a').trigger('click') assert.notOk($tabs.find('li:first-child a').hasClass('active')) assert.ok($tabs.find('li:last-child a').hasClass('active')) })
QUnit.test('should remove "collapsed" class from target when collapse is shown', function (assert) { assert.expect(1) var done = assert.async() var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1"/>').appendTo('#qunit-fixture') $('<div id="test1"/>') .appendTo('#qunit-fixture') .on('shown.bs.collapse', function () { assert.ok(!$target.hasClass('collapsed'), 'target does not have collapsed class') done() }) $target.trigger('click') })
QUnit.test('should throw explicit error on undefined method', function (assert) { assert.expect(1) var $el = $('<div/>').appendTo('#qunit-fixture') $el.bootstrapScrollspy() try { $el.bootstrapScrollspy('noMethod') } catch (err) { assert.strictEqual(err.message, 'No method named "noMethod"') } })
QUnit.test('should not show a collapse when initialized with "hide" option if already hidden', function (assert) { assert.expect(0) var done = assert.async() $('<div class="collapse"></div>') .appendTo('#qunit-fixture') .on('show.bs.collapse', function () { assert.ok(false, 'showing a previously-uninitialized hidden collapse when the "hide" method is called') }) .bootstrapCollapse('hide') setTimeout(done, 0) })
QUnit.test('should store popover trigger in popover instance data object', function (assert) { assert.expect(1) var $popover = $('<a href="#" title="ResentedHook">@ResentedHook</a>') .appendTo('#qunit-fixture') .bootstrapPopover() $popover.bootstrapPopover('show') assert.ok($('.popover').data('bs.popover'), 'popover trigger stored in instance data') })
QUnit.test('Util.getSelectorFromElement should return the correct element', function (assert) { assert.expect(2) var $el = $('<div data-target="body"></div>').appendTo($('#qunit-fixture')) assert.strictEqual(Util.getSelectorFromElement($el[0]), 'body') // Not found element var $el2 = $('<div data-target="#fakeDiv"></div>').appendTo($('#qunit-fixture')) assert.strictEqual(Util.getSelectorFromElement($el2[0]), null) })
QUnit.test('should toggle active when btn children are clicked', function (assert) { assert.expect(2) var $btn = $('<button class="btn" data-toggle="button">mdo</button>') var $inner = $('<i/>') $btn .append($inner) .appendTo('#qunit-fixture') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') $inner.trigger('click') assert.ok($btn.hasClass('active'), 'btn has class active') })
QUnit.test('should do nothing when an attempt is made to hide an uninitialized popover', function (assert) { assert.expect(1) var $popover = $('<span data-toggle="popover" data-title="some title" data-content="some content">some text</span>') .appendTo('#qunit-fixture') .on('hidden.bs.popover shown.bs.popover', function () { assert.ok(false, 'should not fire any popover events') }) .bootstrapPopover('hide') assert.strictEqual(typeof $popover.data('bs.popover'), 'undefined', 'should not initialize the popover') })
QUnit.test('should not add touch event listeners when touch option set to false', function (assert) { assert.expect(1) var spy = sinon.spy(Carousel.prototype, '_addTouchEventListeners') var $carousel = $('<div class="carousel" data-ride="carousel" data-touch="false"></div>') $carousel.appendTo('#qunit-fixture') $carousel.bootstrapCarousel() assert.strictEqual(spy.called, false) spy.restore() })