vendor/assets/javascripts/magnific-popup/jquery.magnific-popup.js in magnific-popup-rails-0.8.3 vs vendor/assets/javascripts/magnific-popup/jquery.magnific-popup.js in magnific-popup-rails-0.8.4
- old
+ new
@@ -1,6 +1,6 @@
-/*! Magnific Popup - v0.8.3 - 2013-05-09
+/*! Magnific Popup - v0.8.4 - 2013-05-13
* http://dimsemenov.com/plugins/magnific-popup/
* Copyright (c) 2013 Dmitry Semenov; */
;(function($) {
/*>>core*/
@@ -29,10 +29,11 @@
/**
* Private vars
*/
var mfp, // As we have only one instance of MagnificPopup object, we define it locally to not to use 'this'
MagnificPopup = function(){},
+ _isJQ = !!(window.jQuery),
_prevStatus,
_window = $(window),
_body,
_document,
_prevContentType,
@@ -80,10 +81,18 @@
if(type !== _currPopupType || !mfp.currTemplate.closeBtn) {
mfp.currTemplate.closeBtn = $( mfp.st.closeMarkup.replace('%title%', mfp.st.tClose ) );
_currPopupType = type;
}
return mfp.currTemplate.closeBtn;
+ },
+ // Initialize Magnific Popup only when called at least once
+ _checkInstance = function() {
+ if(!$.magnificPopup.instance) {
+ mfp = new MagnificPopup();
+ mfp.init();
+ $.magnificPopup.instance = mfp;
+ }
};
/**
@@ -116,11 +125,16 @@
* Opens popup
* @param data [description]
*/
open: function(data) {
- if(mfp.isOpen) return;
+ mfp.items = data.items.length ? data.items : [data.items];
+
+ if(mfp.isOpen) {
+ mfp.updateItemHTML();
+ return;
+ }
var i;
mfp.types = [];
_wrapClasses = '';
@@ -158,11 +172,11 @@
mfp.st = $.extend(true, {}, $.magnificPopup.defaults, data );
mfp.fixedContentPos = mfp.st.fixedContentPos === 'auto' ? !mfp.probablyMobile : mfp.st.fixedContentPos;
- mfp.items = data.items.length ? data.items : [data.items];
+
// Building markup
// main containers are created only once
if(!mfp.bgOverlay) {
@@ -425,20 +439,17 @@
_mfpTrigger('Resize');
},
-
/**
* Set content of popup based on current index
*/
updateItemHTML: function() {
var item = mfp.items[mfp.index];
// Detach and perform modifications
-
-
mfp.contentContainer.detach();
if(mfp.content)
mfp.content.detach();
@@ -538,11 +549,11 @@
if(!item.src) {
item.src = item.el.attr('href');
}
}
- item.type = type || mfp.st.type;
+ item.type = type || mfp.st.type || 'inline';
item.index = index;
item.parsed = true;
mfp.items[index] = item;
_mfpTrigger('ElementParse', item);
@@ -553,43 +564,21 @@
/**
* Initializes single popup or a group of popups
*/
addGroup: function(el, options) {
var eHandler = function(e) {
-
- var midClick = options.midClick !== undefined ? options.midClick : $.magnificPopup.defaults.midClick;
- if( midClick || e.which !== 2 ) {
- var disableOn = options.disableOn !== undefined ? options.disableOn : $.magnificPopup.defaults.disableOn;
-
- if(disableOn) {
- if($.isFunction(disableOn)) {
- if( !disableOn.call(mfp) ) {
- return true;
- }
- } else { // else it's number
- if( $(window).width() < disableOn ) {
- return true;
- }
- }
- }
-
- e.preventDefault();
- options.el = $(this);
- options.mainEl = el;
- if(options.delegate) {
- options.items = el.find(options.delegate);
- }
- mfp.open(options);
- }
-
+ e.mfpEl = this;
+ mfp._openClick(e, el, options);
};
if(!options) {
options = {};
}
var eName = 'click.magnificPopup';
+ options.mainEl = el;
+
if(options.items) {
options.isObj = true;
el.off(eName).on(eName, eHandler);
} else {
options.isObj = false;
@@ -599,12 +588,39 @@
options.items = el;
el.off(eName).on(eName, eHandler);
}
}
},
+ _openClick: function(e, el, options) {
+ var midClick = options.midClick !== undefined ? options.midClick : $.magnificPopup.defaults.midClick;
+ if( midClick || e.which !== 2 ) {
+ var disableOn = options.disableOn !== undefined ? options.disableOn : $.magnificPopup.defaults.disableOn;
+ if(disableOn) {
+ if($.isFunction(disableOn)) {
+ if( !disableOn.call(mfp) ) {
+ return true;
+ }
+ } else { // else it's number
+ if( _window.width() < disableOn ) {
+ return true;
+ }
+ }
+ }
+
+ if(e.type)
+ e.preventDefault();
+ options.el = $(e.mfpEl);
+ if(options.delegate) {
+ options.items = el.find(options.delegate);
+ }
+ mfp.open(options);
+ }
+ },
+
+
/**
* Updates text on preloader
*/
updateStatus: function(status, text) {
@@ -637,17 +653,10 @@
_prevStatus = status;
}
},
-
-
-
-
-
-
-
/*
"Private" helpers that aren't private at all
*/
_addClassToMFP: function(cName) {
mfp.bgOverlay.addClass(cName);
@@ -727,22 +736,17 @@
instance: null,
proto: MagnificPopup.prototype,
modules: [],
open: function(options, index) {
- if(!$.magnificPopup.instance) {
- mfp = new MagnificPopup();
- mfp.init();
- $.magnificPopup.instance = mfp;
- }
+ _checkInstance();
- if(!options) {
+ if(!options)
options = {};
- }
-
+
options.isObj = true;
- options.index = index === undefined ? 0 : index;
+ options.index = index || 0;
return this.instance.open(options);
},
close: function() {
return $.magnificPopup.instance.close();
@@ -756,11 +760,11 @@
this.modules.push(name);
},
defaults: {
- // Info about options is docs:
+ // Info about options is in docs:
// http://dimsemenov.com/plugins/magnific-popup/documentation.html#options
disableOn: 0,
key: null,
@@ -797,19 +801,54 @@
};
$.fn.magnificPopup = function(options) {
- // Initialize Magnific Popup only when called at least once
- if(!$.magnificPopup.instance) {
- mfp = new MagnificPopup();
- mfp.init();
- $.magnificPopup.instance = mfp;
- }
+ _checkInstance();
- mfp.addGroup($(this), options);
- return $(this);
+ var jqEl = $(this);
+
+ // We call some API method of first param is a string
+ if (typeof options === "string" ) {
+
+ if(options === 'open') {
+ var items,
+ itemOpts = _isJQ ? jqEl.data('magnificPopup') : jqEl[0].magnificPopup,
+ index = parseInt(arguments[1], 10) || 0;
+
+ if(itemOpts.items) {
+ items = itemOpts.items[index];
+ } else {
+ items = jqEl;
+ if(itemOpts.delegate) {
+ items = items.find(itemOpts.delegate);
+ }
+ items = items.eq( index );
+ }
+ mfp._openClick({mfpEl:items}, jqEl, itemOpts);
+ } else {
+ if(mfp.isOpen)
+ mfp[options].apply(mfp, Array.prototype.slice.call(arguments, 1));
+ }
+
+ } else {
+
+ /*
+ * As Zepto doesn't support .data() method for objects
+ * and it works only in normal browsers
+ * we assign "options" object directly to the DOM element. FTW!
+ */
+ if(_isJQ) {
+ jqEl.data('magnificPopup', options);
+ } else {
+ jqEl[0].magnificPopup = options;
+ }
+
+ mfp.addGroup(jqEl, options);
+
+ }
+ return jqEl;
};
//Quick benchmark
/*
@@ -832,75 +871,69 @@
/*>>core*/
/*>>inline*/
var INLINE_NS = 'inline',
- _hasPlaceholder;
+ _hiddenClass,
+ _inlinePlaceholder,
+ _lastInlineElement,
+ _putInlineElementsBack = function() {
+ if(_lastInlineElement) {
+ _inlinePlaceholder.after( _lastInlineElement.addClass(_hiddenClass) ).detach();
+ _lastInlineElement = null;
+ }
+ };
$.magnificPopup.registerModule(INLINE_NS, {
options: {
- hiddenClass: NS+'-hide',
+ hiddenClass: 'hide', // will be appended with `mfp-` prefix
markup: '',
tNotFound: 'Content not found'
},
proto: {
initInline: function() {
mfp.types.push(INLINE_NS);
- _hasPlaceholder = false;
_mfpOn(CLOSE_EVENT+'.'+INLINE_NS, function() {
- var item = mfp.currItem;
- if(item.type === INLINE_NS) {
- if(_hasPlaceholder) {
- for(var i = 0; i < mfp.items.length; i++) {
- item = mfp.items[i];
- if(item && item.inlinePlaceholder){
- item.inlinePlaceholder.after( item.inlineElement.addClass(mfp.st.inline.hiddenClass) ).detach();
- }
- }
- }
- item.inlinePlaceholder = item.inlineElement = null;
- }
+ _putInlineElementsBack();
});
},
getInline: function(item, template) {
- mfp.updateStatus('ready');
+ _putInlineElementsBack();
+
if(item.src) {
- var inlineSt = mfp.st.inline;
- // items.src can be String-CSS-selector or jQuery element
- if(typeof item.src !== 'string') {
- item.isElement = true;
- }
+ var inlineSt = mfp.st.inline,
+ el = $(item.src);
- if(!item.isElement && !item.inlinePlaceholder) {
- item.inlinePlaceholder = _getEl(inlineSt.hiddenClass);
- }
-
- if(item.isElement) {
- item.inlineElement = item.src;
- } else if(!item.inlineElement) {
- item.inlineElement = $(item.src);
- if(!item.inlineElement.length) {
- mfp.updateStatus('error', inlineSt.tNotFound);
- item.inlineElement = $('<div>');
+ if(el.length) {
+
+ // If target element has parent - we replace it with placeholder and put it back after popup is closed
+ if(el[0].parentNode !== null) {
+ if(!_inlinePlaceholder) {
+ _hiddenClass = inlineSt.hiddenClass;
+ _inlinePlaceholder = _getEl(_hiddenClass);
+ _hiddenClass = 'mfp-'+_hiddenClass;
+ }
+ // replace target inline element with placeholder
+ _lastInlineElement = el.after(_inlinePlaceholder).detach().removeClass(_hiddenClass);
}
- }
- if(item.inlinePlaceholder) {
- _hasPlaceholder = true;
+ mfp.updateStatus('ready');
+ } else {
+ mfp.updateStatus('error', inlineSt.tNotFound);
+ el = $('<div>');
}
-
-
- item.inlineElement.after(item.inlinePlaceholder).detach().removeClass(inlineSt.hiddenClass);
- return item.inlineElement;
- } else {
- mfp._parseMarkup(template, {}, item);
- return template;
+ item.inlineElement = el;
+ return el;
}
+
+ mfp.updateStatus('ready');
+ mfp._parseMarkup(template, {}, item);
+ return template;
}
}
});
/*>>inline*/
\ No newline at end of file