dimsemenov / Magnific-Popup

Light and responsive lightbox script with focus on performance.
http://dimsemenov.com/plugins/magnific-popup/
MIT License
11.38k stars 3.49k forks source link

Inline does not properly empty out undefined fields #334

Open ckoppelman opened 10 years ago

ckoppelman commented 10 years ago

See this fiddle for an example. The summary is that if you are populating a template with an array like so:

[
  {number: "one", ordinal: "first"},
  {number: "two"},
  {number: "three", ordinal: "third"},
  {number: "four", ordinal: null}
]

and a template like:

<div class='mfp-number'></div>
<div class='mfp-ordinal'></div>

then the .mfp-ordinal div for number = 'two' doesn't get emptied out. On the other hand, it does get emptied out for number = 'four'.

ckoppelman commented 10 years ago

As a workaround for this issue (if others come across this), I was able to create an intermediary between my data and the mfp processor that, for each needed mfp field, does something ugly like:

var newObj = {
  number: oldObj.number || null,
  ordinal: oldObj.ordinal || null
};