Skip to content

Commit

Permalink
0.8.3
Browse files Browse the repository at this point in the history
- Added: `goTo` public method.
- Custom events that are added to popup are now not lost when
navigating through gallery.
- If `delegate` option is used, events are now dispatched on main
element instead of children.
  • Loading branch information
dimsemenov committed May 9, 2013
1 parent 8f06fbf commit 5e7f6a7
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 36 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Optionally:

## Changelog

### 0.8.3 (May 9, 2013)

- Added: `goTo` public method.
- Custom events that are added to popup are now not lost when navigating through gallery.
- If `delegate` option is used, events are now dispatched on main element instead of children.


### 0.8.2 (May 5, 2013)

- Added !important to mfp-hide class
Expand Down
49 changes: 33 additions & 16 deletions dist/jquery.magnific-popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Magnific Popup - v0.8.2 - 2013-05-05
/*! Magnific Popup - v0.8.3 - 2013-05-09
* http://dimsemenov.com/plugins/magnific-popup/
* Copyright (c) 2013 Dmitry Semenov; */
;(function($) {
Expand Down Expand Up @@ -302,10 +302,10 @@ MagnificPopup.prototype = {
// add content
mfp.updateItemHTML();

// remove scrollbar, add padding e.t.c

_mfpTrigger('BuildControls');


// remove scrollbar, add padding e.t.c
_body.css(bodyStyles);

// add everything to DOM
Expand Down Expand Up @@ -406,6 +406,7 @@ MagnificPopup.prototype = {
if(mfp._lastFocusedEl) {
$(mfp._lastFocusedEl).focus(); // put tab focus back
}
mfp.content = null;
mfp.currTemplate = null;
mfp.prevHeight = 0;
},
Expand Down Expand Up @@ -434,8 +435,13 @@ MagnificPopup.prototype = {
var item = mfp.items[mfp.index];

// Detach and perform modifications


mfp.contentContainer.detach();

if(mfp.content)
mfp.content.detach();

if(!item.parsed) {
item = mfp.parseEl( mfp.index );
}
Expand All @@ -445,8 +451,11 @@ MagnificPopup.prototype = {
var type = item.type;
if(!mfp.currTemplate[type]) {
var markup = mfp.st[type] ? mfp.st[type].markup : false;

// allows to modify markup
_mfpTrigger('FirstMarkupParse', markup);

if(markup) {
_mfpTrigger('FirstMarkupParse', markup);
mfp.currTemplate[type] = $(markup);
} else {
// if there is no markup found we just define that template is parsed
Expand Down Expand Up @@ -493,7 +502,7 @@ MagnificPopup.prototype = {
_mfpTrigger(BEFORE_APPEND_EVENT);
mfp.container.addClass('mfp-'+type+'-holder');

mfp.contentContainer.html(mfp.content);
mfp.contentContainer.append(mfp.content);
},


Expand Down Expand Up @@ -565,6 +574,7 @@ MagnificPopup.prototype = {

e.preventDefault();
options.el = $(this);
options.mainEl = el;
if(options.delegate) {
options.items = el.find(options.delegate);
}
Expand Down Expand Up @@ -1056,7 +1066,9 @@ $.magnificPopup.registerModule('image', {
_mfpTrigger('ImageHasSize', item);

if(item.imgHidden) {
mfp.content.removeClass('mfp-loading');
if(mfp.content)
mfp.content.removeClass('mfp-loading');

item.imgHidden = false;
}

Expand Down Expand Up @@ -1361,17 +1373,8 @@ $.magnificPopup.registerModule('gallery', {
values.counter = l ? _replaceCurrTotal(gSt.tCounter, item.index, l) : '';
});

_mfpOn(CHANGE_EVENT+ns, function() {

if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);

mfp._preloadTimeout = setTimeout(function() {
mfp.preloadNearbyImages();
mfp._preloadTimeout = null;
}, 16);

_mfpOn('BuildControls' + ns, function() {
if(gSt.arrows && !mfp.arrowLeft) {

var markup = gSt.arrowMarkup,
arrowLeft = mfp.arrowLeft = $( markup.replace('%title%', gSt.tPrev).replace('%dir%', 'left') ).addClass(PREVENT_CLOSE_CLASS),
arrowRight = mfp.arrowRight = $( markup.replace('%title%', gSt.tNext).replace('%dir%', 'right') ).addClass(PREVENT_CLOSE_CLASS);
Expand All @@ -1396,6 +1399,15 @@ $.magnificPopup.registerModule('gallery', {
}
});

_mfpOn(CHANGE_EVENT+ns, function() {
if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);

mfp._preloadTimeout = setTimeout(function() {
mfp.preloadNearbyImages();
mfp._preloadTimeout = null;
}, 16);
});


_mfpOn(CLOSE_EVENT+ns, function() {
_document.off(ns);
Expand All @@ -1418,6 +1430,11 @@ $.magnificPopup.registerModule('gallery', {
mfp.index = _getLoopedId(mfp.index - 1);
mfp.updateItemHTML();
},
goTo: function(newIndex) {
mfp.direction = (newIndex >= mfp.index);
mfp.index = newIndex;
mfp.updateItemHTML();
},
preloadNearbyImages: function() {
var p = mfp.st.gallery.preload,
preloadBefore = Math.min(p[0], mfp.items.length),
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.magnific-popup.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion magnific-popup.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magnific-popup",
"title": "Magnific Popup",
"description": "Fast, light and responsive lightbox plugin with focus on performance",
"version": "0.8.2",
"version": "0.8.3",
"homepage": "http://dimsemenov.com/plugins/magnific-popup/",
"demo": "http://dimsemenov.com/plugins/magnific-popup/",
"docs": "http://dimsemenov.com/plugins/magnific-popup/documentation.html",
Expand Down
18 changes: 14 additions & 4 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ MagnificPopup.prototype = {
// add content
mfp.updateItemHTML();

// remove scrollbar, add padding e.t.c

_mfpTrigger('BuildControls');


// remove scrollbar, add padding e.t.c
_body.css(bodyStyles);

// add everything to DOM
Expand Down Expand Up @@ -400,6 +400,7 @@ MagnificPopup.prototype = {
if(mfp._lastFocusedEl) {
$(mfp._lastFocusedEl).focus(); // put tab focus back
}
mfp.content = null;
mfp.currTemplate = null;
mfp.prevHeight = 0;
},
Expand Down Expand Up @@ -428,8 +429,13 @@ MagnificPopup.prototype = {
var item = mfp.items[mfp.index];

// Detach and perform modifications


mfp.contentContainer.detach();

if(mfp.content)
mfp.content.detach();

if(!item.parsed) {
item = mfp.parseEl( mfp.index );
}
Expand All @@ -439,8 +445,11 @@ MagnificPopup.prototype = {
var type = item.type;
if(!mfp.currTemplate[type]) {
var markup = mfp.st[type] ? mfp.st[type].markup : false;

// allows to modify markup
_mfpTrigger('FirstMarkupParse', markup);

if(markup) {
_mfpTrigger('FirstMarkupParse', markup);
mfp.currTemplate[type] = $(markup);
} else {
// if there is no markup found we just define that template is parsed
Expand Down Expand Up @@ -487,7 +496,7 @@ MagnificPopup.prototype = {
_mfpTrigger(BEFORE_APPEND_EVENT);
mfp.container.addClass('mfp-'+type+'-holder');

mfp.contentContainer.html(mfp.content);
mfp.contentContainer.append(mfp.content);
},


Expand Down Expand Up @@ -559,6 +568,7 @@ MagnificPopup.prototype = {

e.preventDefault();
options.el = $(this);
options.mainEl = el;
if(options.delegate) {
options.items = el.find(options.delegate);
}
Expand Down
25 changes: 15 additions & 10 deletions src/js/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,8 @@ $.magnificPopup.registerModule('gallery', {
values.counter = l ? _replaceCurrTotal(gSt.tCounter, item.index, l) : '';
});

_mfpOn(CHANGE_EVENT+ns, function() {

if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);

mfp._preloadTimeout = setTimeout(function() {
mfp.preloadNearbyImages();
mfp._preloadTimeout = null;
}, 16);

_mfpOn('BuildControls' + ns, function() {
if(gSt.arrows && !mfp.arrowLeft) {

var markup = gSt.arrowMarkup,
arrowLeft = mfp.arrowLeft = $( markup.replace('%title%', gSt.tPrev).replace('%dir%', 'left') ).addClass(PREVENT_CLOSE_CLASS),
arrowRight = mfp.arrowRight = $( markup.replace('%title%', gSt.tNext).replace('%dir%', 'right') ).addClass(PREVENT_CLOSE_CLASS);
Expand All @@ -105,6 +96,15 @@ $.magnificPopup.registerModule('gallery', {
}
});

_mfpOn(CHANGE_EVENT+ns, function() {
if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);

mfp._preloadTimeout = setTimeout(function() {
mfp.preloadNearbyImages();
mfp._preloadTimeout = null;
}, 16);
});


_mfpOn(CLOSE_EVENT+ns, function() {
_document.off(ns);
Expand All @@ -127,6 +127,11 @@ $.magnificPopup.registerModule('gallery', {
mfp.index = _getLoopedId(mfp.index - 1);
mfp.updateItemHTML();
},
goTo: function(newIndex) {
mfp.direction = (newIndex >= mfp.index);
mfp.index = newIndex;
mfp.updateItemHTML();
},
preloadNearbyImages: function() {
var p = mfp.st.gallery.preload,
preloadBefore = Math.min(p[0], mfp.items.length),
Expand Down
4 changes: 3 additions & 1 deletion src/js/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ $.magnificPopup.registerModule('image', {
_mfpTrigger('ImageHasSize', item);

if(item.imgHidden) {
mfp.content.removeClass('mfp-loading');
if(mfp.content)
mfp.content.removeClass('mfp-loading');

item.imgHidden = false;
}

Expand Down
2 changes: 1 addition & 1 deletion website/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ exclude: [".json", ".rvmrc", ".rbenv-version", "README.md", "Rakefile", "changel
auto: true
pygments: true

mfpversion: 0.8.2
mfpversion: 0.8.3
3 changes: 2 additions & 1 deletion website/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ $('.image-link').magnificPopup({
// Name of event should start from `mfp` and the first letter should be uppercase.
// e.g. 'open' becomes 'mfpOpen', 'beforeOpen' becomes 'mfpBeforeOpen'.
$('.image-link').on('mfpOpen', function(e /*, params */) {
console.log('Popup opened');
console.log('Popup opened', $.magnificPopup.instance);
});
{% endhighlight %}

Expand Down Expand Up @@ -828,6 +828,7 @@ magnificPopup.close();
// Navigation when gallery is enabled
magnificPopup.next(); // go to next item
magnificPopup.prev(); // go to prev item
magnificPopup.goTo(4); // go to item #4


// Update status of popup
Expand Down

0 comments on commit 5e7f6a7

Please sign in to comment.