forked from DubFriend/jquery.repeater
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Detering
authored and
Brian Detering
committed
Oct 1, 2016
1 parent
abd1acf
commit d94abd2
Showing
9 changed files
with
102 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="complex-repeater"> | ||
<div> | ||
<div> | ||
<button data-repeater-create>create</button> | ||
</div> | ||
<div> | ||
<div data-repeater-list="complex-repeater"> | ||
<div data-repeater-item> | ||
<div> | ||
<input type="text" name="text-input" value="A"/> | ||
</div> | ||
<div> | ||
<button data-repeater-delete></button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// jquery.repeater version 1.1.3 | ||
// jquery.repeater version 1.1.4 | ||
// https://github.com/DubFriend/jquery.repeater | ||
// (MIT) 06-12-2015 | ||
// (MIT) 01-10-2016 | ||
// Brian Detering <[email protected]> (http://www.briandetering.net/) | ||
(function ($) { | ||
'use strict'; | ||
|
@@ -960,19 +960,7 @@ $.fn.repeater = function (fig) { | |
show.call($item.get(0)); | ||
}; | ||
|
||
$self.children().each(function () { | ||
if( | ||
!$(this).is('[data-repeater-list]') && | ||
$(this).find('[data-repeater-list]').length === 0 | ||
) { | ||
if($(this).is('[data-repeater-create]')) { | ||
$(this).click(addItem); | ||
} | ||
else if($(this).find('[data-repeater-create]').length !== 0) { | ||
$(this).find('[data-repeater-create]').click(addItem); | ||
} | ||
} | ||
}); | ||
$filterNested($self.find('[data-repeater-create]'), fig.repeaters).click(addItem); | ||
|
||
$list.on('click', '[data-repeater-delete]', function () { | ||
var self = $(this).closest('[data-repeater-item]').get(0); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
QUnit.module('complex-repeater', { | ||
setup: function () { | ||
this.$fixture = $('#qunit-fixture'); | ||
this.$fixture.html($('#template').html()); | ||
this.$repeater = this.$fixture.find('.complex-repeater'); | ||
this.$addButton = this.$repeater.find('[data-repeater-create]'); | ||
this.$fixture.append($('#template').html()); | ||
} | ||
}); | ||
|
||
QUnit.test('add item', function (assert) { | ||
this.$repeater.repeater(); | ||
this.$addButton.click(); | ||
var $items = this.$repeater.find('[data-repeater-item]'); | ||
assert.strictEqual($items.length, 2, 'adds a second item to list'); | ||
|
||
assert.deepEqual( | ||
getNamedInputValues($items.last()), | ||
{ 'complex-repeater[1][text-input]': '' }, | ||
'added items inputs are clear' | ||
); | ||
|
||
assert.deepEqual( | ||
getNamedInputValues($items.first()), | ||
{ 'complex-repeater[0][text-input]': 'A' }, | ||
'does not clear other inputs' | ||
); | ||
}); | ||
|
||
QUnit.test('delete item', function (assert) { | ||
this.$repeater.repeater(); | ||
this.$repeater.find('[data-repeater-delete]').first().click(); | ||
assert.strictEqual( | ||
this.$repeater.find('[data-repeater-item]').length, 0, | ||
'deletes item' | ||
); | ||
}); | ||
|
||
QUnit.test('delete item that has been added', function (assert) { | ||
this.$repeater.repeater(); | ||
this.$addButton.click(); | ||
assert.strictEqual( | ||
this.$repeater.find('[data-repeater-item]').length, 2, | ||
'item added' | ||
); | ||
this.$repeater.find('[data-repeater-delete]').last().click(); | ||
assert.strictEqual( | ||
this.$repeater.find('[data-repeater-item]').length, 1, | ||
'item deleted' | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters