Skip to content

Commit

Permalink
Not possible to re-init to a href if selector is there, closes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamkou committed Jan 6, 2016
1 parent 40a5bd4 commit 8ef2e56
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
21 changes: 13 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,23 @@ <h3>API (<a href="https://github.com/kkamkou/jqFenster/blob/master/src/jquery.fe
<tr>
<td>
2. <button id="api2">reInit()</button>
<div class="code">// this file
<div class="code">// #1 example with an in-dom element
var $link = $('#simplelink'), modal;
modal = $.fensterFinder($link.click())
// it is possible to use {selector: '#targetSecond'} INSTEAD OF href
.setOptions({href: 'remote.html', options: {animationSpeed: 300}})
.reInit();
// later
modal.destroy();

// #2 example with a remote file
// this file
$.fenster({href: 'remote-reinit.html'}).open();

// remote-reinit.html
$('#reinitAnother').bind('click', function () {
$.fensterFinder(this)
.setOptions({
href: 'remote.html',
options: {callbackOpen: "myOpen", animationSpeed: 300}
})
.reInit();

// you can use the current element (this)
$.fensterFinder(this).setOptions(...).reInit();
return false;
});
</div>
Expand Down
14 changes: 6 additions & 8 deletions src/jquery.fenster.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,13 @@
},

_init: function () {
if (this.options.href !== null) {
this.element.data('href', this.options.href);
}
if (this.options.selector !== null) {
this.element.data('selector', this.options.selector);
}
if (this.options.options) {
this.element.data('options', this.options.options);
// it is not possible to use href and selector in the same time
if (this.options.href && this.options.selector) {
this.options.selector = null;
}
this.element.data('href', this.options.href || null);
this.element.data('selector', this.options.selector || null);
this.element.data('options', this.options.options || null);
return this;
}
};
Expand Down
17 changes: 17 additions & 0 deletions src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,22 @@ QUnit.module("DOM", function (hooks) {
done();
}, animationDelay);
});

QUnit.test('Issue #16', 7, function (assert) {
var modal, done = assert.async(), $link = $('#simplelink').click();
setTimeout(function () {
modal = $.fensterFinder($link);
assert.ok(modal.element.data('selector'), '"selector" exists in the data');
assert.equal(countHoldersVisible(), 1, 'The first modal is visible');
modal.setOptions({href: 'remote.html'}).reInit();
setTimeout(function () {
assert.notOk(modal.element.data('selector'), '"selector" does not exist in the data');
assert.ok($('.jqFensterModalContent:visible').text().indexOf("I'm remote one!") !== -1, 'The second modal is visible');
assert.notOk(modal.destroy(), 'destroy() returns false');
modal.close();
done();
}, animationDelay);
}, animationDelay);
});
});
});

0 comments on commit 8ef2e56

Please sign in to comment.