Skip to content

Commit

Permalink
+ onResize callback [#43]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Feb 8, 2015
1 parent ef99420 commit c89c92e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Featherlight – Changelog

Master
-----------------------------------
### Features
- New callback: onResize called for new content and when the window is resized

### Changes
- current() now returns null if no lightbox is currently opened
- now avoids memory leaks
- onKeyDown() renamed onKeyUp()
Expand Down
9 changes: 8 additions & 1 deletion src/featherlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
};

/* document wide key handler */
var eventMap = { keyup: 'onKeyUp' };
var eventMap = { keyup: 'onKeyUp', resize: 'onResize' };

var globalEventHandler = function(event) {
$.each(Featherlight.opened().reverse(), function() {
Expand Down Expand Up @@ -101,6 +101,7 @@
afterContent: $.noop, /* Called after content is ready and has been set. Gets event as parameter, this contains all data */
afterClose: $.noop, /* Called after close. Gets event as parameter, this contains all data */
onKeyUp: $.noop, /* Called on key down for the frontmost featherlight */
onResize: $.noop, /* Called after new content and when a window is resized */
type: null, /* Specify type of lightbox. If unset, it will check for the targetAttrs value. */
contentFilters: ['jquery', 'image', 'html', 'ajax', 'text'], /* List of content filters to use to determine the content */

Expand Down Expand Up @@ -441,6 +442,12 @@
} else {
return _super(event);
}
},

afterContent: function(_super, event){
var r = _super(event);
this.onResize(event);
return r;
}
}
});
Expand Down
18 changes: 18 additions & 0 deletions test/featherlight_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ var expect = chai.expect;
expect($.featherlight.current()).to.be.null;
});

it('can specify a resize handler', function() {
var resizes = [],
open = function() {
$.featherlight('<p/>', {
onResize: function(event) { resizes.push(this.id); }
});
}
open();
open();
$(window).trigger('resize');
open();
$.featherlight.current().close();
$.featherlight.current().close();
$(window).trigger('resize');
resizes = $.map(resizes, function(id) { return id - $.featherlight.current().id });
expect(resizes).to.eql([0, 1, 1, 0, 2, 0]);
});

it('can specify a filter for events', function() {
$("#filter-test .group").featherlight({filter: '.yes', type: 'text'})
.append('<span class="yes" href="filter Appended">Photo</span>');
Expand Down

0 comments on commit c89c92e

Please # to comment.