inline.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var INLINE_NS = 'inline',
  2. _hiddenClass,
  3. _inlinePlaceholder,
  4. _lastInlineElement,
  5. _putInlineElementsBack = function() {
  6. if(_lastInlineElement) {
  7. _inlinePlaceholder.after( _lastInlineElement.addClass(_hiddenClass) ).detach();
  8. _lastInlineElement = null;
  9. }
  10. };
  11. $.magnificPopup.registerModule(INLINE_NS, {
  12. options: {
  13. hiddenClass: 'hide', // will be appended with `mfp-` prefix
  14. markup: '',
  15. tNotFound: 'Content not found'
  16. },
  17. proto: {
  18. initInline: function() {
  19. mfp.types.push(INLINE_NS);
  20. _mfpOn(CLOSE_EVENT+'.'+INLINE_NS, function() {
  21. _putInlineElementsBack();
  22. });
  23. },
  24. getInline: function(item, template) {
  25. _putInlineElementsBack();
  26. if(item.src) {
  27. var inlineSt = mfp.st.inline,
  28. el = $(item.src);
  29. if(el.length) {
  30. // If target element has parent - we replace it with placeholder and put it back after popup is closed
  31. var parent = el[0].parentNode;
  32. if(parent && parent.tagName) {
  33. if(!_inlinePlaceholder) {
  34. _hiddenClass = inlineSt.hiddenClass;
  35. _inlinePlaceholder = _getEl(_hiddenClass);
  36. _hiddenClass = 'mfp-'+_hiddenClass;
  37. }
  38. // replace target inline element with placeholder
  39. _lastInlineElement = el.after(_inlinePlaceholder).detach().removeClass(_hiddenClass);
  40. }
  41. mfp.updateStatus('ready');
  42. } else {
  43. mfp.updateStatus('error', inlineSt.tNotFound);
  44. el = $('<div>');
  45. }
  46. item.inlineElement = el;
  47. return el;
  48. }
  49. mfp.updateStatus('ready');
  50. mfp._parseMarkup(template, {}, item);
  51. return template;
  52. }
  53. }
  54. });