creative_rails 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1863 @@
1
+ $(function() {
2
+
3
+ });
4
+ /*! Magnific Popup - v1.1.0 - 2016-02-20
5
+ * http://dimsemenov.com/plugins/magnific-popup/
6
+ * Copyright (c) 2016 Dmitry Semenov; */
7
+ ;(function (factory) {
8
+ if (typeof define === 'function' && define.amd) {
9
+ // AMD. Register as an anonymous module.
10
+ define(['jquery'], factory);
11
+ } else if (typeof exports === 'object') {
12
+ // Node/CommonJS
13
+ factory(require('jquery'));
14
+ } else {
15
+ // Browser globals
16
+ factory(window.jQuery || window.Zepto);
17
+ }
18
+ }(function($) {
19
+
20
+ /*>>core*/
21
+ /**
22
+ *
23
+ * Magnific Popup Core JS file
24
+ *
25
+ */
26
+
27
+
28
+ /**
29
+ * Private static constants
30
+ */
31
+ var CLOSE_EVENT = 'Close',
32
+ BEFORE_CLOSE_EVENT = 'BeforeClose',
33
+ AFTER_CLOSE_EVENT = 'AfterClose',
34
+ BEFORE_APPEND_EVENT = 'BeforeAppend',
35
+ MARKUP_PARSE_EVENT = 'MarkupParse',
36
+ OPEN_EVENT = 'Open',
37
+ CHANGE_EVENT = 'Change',
38
+ NS = 'mfp',
39
+ EVENT_NS = '.' + NS,
40
+ READY_CLASS = 'mfp-ready',
41
+ REMOVING_CLASS = 'mfp-removing',
42
+ PREVENT_CLOSE_CLASS = 'mfp-prevent-close';
43
+
44
+
45
+ /**
46
+ * Private vars
47
+ */
48
+ /*jshint -W079 */
49
+ var mfp, // As we have only one instance of MagnificPopup object, we define it locally to not to use 'this'
50
+ MagnificPopup = function(){},
51
+ _isJQ = !!(window.jQuery),
52
+ _prevStatus,
53
+ _window = $(window),
54
+ _document,
55
+ _prevContentType,
56
+ _wrapClasses,
57
+ _currPopupType;
58
+
59
+
60
+ /**
61
+ * Private functions
62
+ */
63
+ var _mfpOn = function(name, f) {
64
+ mfp.ev.on(NS + name + EVENT_NS, f);
65
+ },
66
+ _getEl = function(className, appendTo, html, raw) {
67
+ var el = document.createElement('div');
68
+ el.className = 'mfp-'+className;
69
+ if(html) {
70
+ el.innerHTML = html;
71
+ }
72
+ if(!raw) {
73
+ el = $(el);
74
+ if(appendTo) {
75
+ el.appendTo(appendTo);
76
+ }
77
+ } else if(appendTo) {
78
+ appendTo.appendChild(el);
79
+ }
80
+ return el;
81
+ },
82
+ _mfpTrigger = function(e, data) {
83
+ mfp.ev.triggerHandler(NS + e, data);
84
+
85
+ if(mfp.st.callbacks) {
86
+ // converts "mfpEventName" to "eventName" callback and triggers it if it's present
87
+ e = e.charAt(0).toLowerCase() + e.slice(1);
88
+ if(mfp.st.callbacks[e]) {
89
+ mfp.st.callbacks[e].apply(mfp, $.isArray(data) ? data : [data]);
90
+ }
91
+ }
92
+ },
93
+ _getCloseBtn = function(type) {
94
+ if(type !== _currPopupType || !mfp.currTemplate.closeBtn) {
95
+ mfp.currTemplate.closeBtn = $( mfp.st.closeMarkup.replace('%title%', mfp.st.tClose ) );
96
+ _currPopupType = type;
97
+ }
98
+ return mfp.currTemplate.closeBtn;
99
+ },
100
+ // Initialize Magnific Popup only when called at least once
101
+ _checkInstance = function() {
102
+ if(!$.magnificPopup.instance) {
103
+ /*jshint -W020 */
104
+ mfp = new MagnificPopup();
105
+ mfp.init();
106
+ $.magnificPopup.instance = mfp;
107
+ }
108
+ },
109
+ // CSS transition detection, http://stackoverflow.com/questions/7264899/detect-css-transitions-using-javascript-and-without-modernizr
110
+ supportsTransitions = function() {
111
+ var s = document.createElement('p').style, // 's' for style. better to create an element if body yet to exist
112
+ v = ['ms','O','Moz','Webkit']; // 'v' for vendor
113
+
114
+ if( s['transition'] !== undefined ) {
115
+ return true;
116
+ }
117
+
118
+ while( v.length ) {
119
+ if( v.pop() + 'Transition' in s ) {
120
+ return true;
121
+ }
122
+ }
123
+
124
+ return false;
125
+ };
126
+
127
+
128
+
129
+ /**
130
+ * Public functions
131
+ */
132
+ MagnificPopup.prototype = {
133
+
134
+ constructor: MagnificPopup,
135
+
136
+ /**
137
+ * Initializes Magnific Popup plugin.
138
+ * This function is triggered only once when $.fn.magnificPopup or $.magnificPopup is executed
139
+ */
140
+ init: function() {
141
+ var appVersion = navigator.appVersion;
142
+ mfp.isLowIE = mfp.isIE8 = document.all && !document.addEventListener;
143
+ mfp.isAndroid = (/android/gi).test(appVersion);
144
+ mfp.isIOS = (/iphone|ipad|ipod/gi).test(appVersion);
145
+ mfp.supportsTransition = supportsTransitions();
146
+
147
+ // We disable fixed positioned lightbox on devices that don't handle it nicely.
148
+ // If you know a better way of detecting this - let me know.
149
+ mfp.probablyMobile = (mfp.isAndroid || mfp.isIOS || /(Opera Mini)|Kindle|webOS|BlackBerry|(Opera Mobi)|(Windows Phone)|IEMobile/i.test(navigator.userAgent) );
150
+ _document = $(document);
151
+
152
+ mfp.popupsCache = {};
153
+ },
154
+
155
+ /**
156
+ * Opens popup
157
+ * @param data [description]
158
+ */
159
+ open: function(data) {
160
+
161
+ var i;
162
+
163
+ if(data.isObj === false) {
164
+ // convert jQuery collection to array to avoid conflicts later
165
+ mfp.items = data.items.toArray();
166
+
167
+ mfp.index = 0;
168
+ var items = data.items,
169
+ item;
170
+ for(i = 0; i < items.length; i++) {
171
+ item = items[i];
172
+ if(item.parsed) {
173
+ item = item.el[0];
174
+ }
175
+ if(item === data.el[0]) {
176
+ mfp.index = i;
177
+ break;
178
+ }
179
+ }
180
+ } else {
181
+ mfp.items = $.isArray(data.items) ? data.items : [data.items];
182
+ mfp.index = data.index || 0;
183
+ }
184
+
185
+ // if popup is already opened - we just update the content
186
+ if(mfp.isOpen) {
187
+ mfp.updateItemHTML();
188
+ return;
189
+ }
190
+
191
+ mfp.types = [];
192
+ _wrapClasses = '';
193
+ if(data.mainEl && data.mainEl.length) {
194
+ mfp.ev = data.mainEl.eq(0);
195
+ } else {
196
+ mfp.ev = _document;
197
+ }
198
+
199
+ if(data.key) {
200
+ if(!mfp.popupsCache[data.key]) {
201
+ mfp.popupsCache[data.key] = {};
202
+ }
203
+ mfp.currTemplate = mfp.popupsCache[data.key];
204
+ } else {
205
+ mfp.currTemplate = {};
206
+ }
207
+
208
+
209
+
210
+ mfp.st = $.extend(true, {}, $.magnificPopup.defaults, data );
211
+ mfp.fixedContentPos = mfp.st.fixedContentPos === 'auto' ? !mfp.probablyMobile : mfp.st.fixedContentPos;
212
+
213
+ if(mfp.st.modal) {
214
+ mfp.st.closeOnContentClick = false;
215
+ mfp.st.closeOnBgClick = false;
216
+ mfp.st.showCloseBtn = false;
217
+ mfp.st.enableEscapeKey = false;
218
+ }
219
+
220
+
221
+ // Building markup
222
+ // main containers are created only once
223
+ if(!mfp.bgOverlay) {
224
+
225
+ // Dark overlay
226
+ mfp.bgOverlay = _getEl('bg').on('click'+EVENT_NS, function() {
227
+ mfp.close();
228
+ });
229
+
230
+ mfp.wrap = _getEl('wrap').attr('tabindex', -1).on('click'+EVENT_NS, function(e) {
231
+ if(mfp._checkIfClose(e.target)) {
232
+ mfp.close();
233
+ }
234
+ });
235
+
236
+ mfp.container = _getEl('container', mfp.wrap);
237
+ }
238
+
239
+ mfp.contentContainer = _getEl('content');
240
+ if(mfp.st.preloader) {
241
+ mfp.preloader = _getEl('preloader', mfp.container, mfp.st.tLoading);
242
+ }
243
+
244
+
245
+ // Initializing modules
246
+ var modules = $.magnificPopup.modules;
247
+ for(i = 0; i < modules.length; i++) {
248
+ var n = modules[i];
249
+ n = n.charAt(0).toUpperCase() + n.slice(1);
250
+ mfp['init'+n].call(mfp);
251
+ }
252
+ _mfpTrigger('BeforeOpen');
253
+
254
+
255
+ if(mfp.st.showCloseBtn) {
256
+ // Close button
257
+ if(!mfp.st.closeBtnInside) {
258
+ mfp.wrap.append( _getCloseBtn() );
259
+ } else {
260
+ _mfpOn(MARKUP_PARSE_EVENT, function(e, template, values, item) {
261
+ values.close_replaceWith = _getCloseBtn(item.type);
262
+ });
263
+ _wrapClasses += ' mfp-close-btn-in';
264
+ }
265
+ }
266
+
267
+ if(mfp.st.alignTop) {
268
+ _wrapClasses += ' mfp-align-top';
269
+ }
270
+
271
+
272
+
273
+ if(mfp.fixedContentPos) {
274
+ mfp.wrap.css({
275
+ overflow: mfp.st.overflowY,
276
+ overflowX: 'hidden',
277
+ overflowY: mfp.st.overflowY
278
+ });
279
+ } else {
280
+ mfp.wrap.css({
281
+ top: _window.scrollTop(),
282
+ position: 'absolute'
283
+ });
284
+ }
285
+ if( mfp.st.fixedBgPos === false || (mfp.st.fixedBgPos === 'auto' && !mfp.fixedContentPos) ) {
286
+ mfp.bgOverlay.css({
287
+ height: _document.height(),
288
+ position: 'absolute'
289
+ });
290
+ }
291
+
292
+
293
+
294
+ if(mfp.st.enableEscapeKey) {
295
+ // Close on ESC key
296
+ _document.on('keyup' + EVENT_NS, function(e) {
297
+ if(e.keyCode === 27) {
298
+ mfp.close();
299
+ }
300
+ });
301
+ }
302
+
303
+ _window.on('resize' + EVENT_NS, function() {
304
+ mfp.updateSize();
305
+ });
306
+
307
+
308
+ if(!mfp.st.closeOnContentClick) {
309
+ _wrapClasses += ' mfp-auto-cursor';
310
+ }
311
+
312
+ if(_wrapClasses)
313
+ mfp.wrap.addClass(_wrapClasses);
314
+
315
+
316
+ // this triggers recalculation of layout, so we get it once to not to trigger twice
317
+ var windowHeight = mfp.wH = _window.height();
318
+
319
+
320
+ var windowStyles = {};
321
+
322
+ if( mfp.fixedContentPos ) {
323
+ if(mfp._hasScrollBar(windowHeight)){
324
+ var s = mfp._getScrollbarSize();
325
+ if(s) {
326
+ windowStyles.marginRight = s;
327
+ }
328
+ }
329
+ }
330
+
331
+ if(mfp.fixedContentPos) {
332
+ if(!mfp.isIE7) {
333
+ windowStyles.overflow = 'hidden';
334
+ } else {
335
+ // ie7 double-scroll bug
336
+ $('body, html').css('overflow', 'hidden');
337
+ }
338
+ }
339
+
340
+
341
+
342
+ var classesToadd = mfp.st.mainClass;
343
+ if(mfp.isIE7) {
344
+ classesToadd += ' mfp-ie7';
345
+ }
346
+ if(classesToadd) {
347
+ mfp._addClassToMFP( classesToadd );
348
+ }
349
+
350
+ // add content
351
+ mfp.updateItemHTML();
352
+
353
+ _mfpTrigger('BuildControls');
354
+
355
+ // remove scrollbar, add margin e.t.c
356
+ $('html').css(windowStyles);
357
+
358
+ // add everything to DOM
359
+ mfp.bgOverlay.add(mfp.wrap).prependTo( mfp.st.prependTo || $(document.body) );
360
+
361
+ // Save last focused element
362
+ mfp._lastFocusedEl = document.activeElement;
363
+
364
+ // Wait for next cycle to allow CSS transition
365
+ setTimeout(function() {
366
+
367
+ if(mfp.content) {
368
+ mfp._addClassToMFP(READY_CLASS);
369
+ mfp._setFocus();
370
+ } else {
371
+ // if content is not defined (not loaded e.t.c) we add class only for BG
372
+ mfp.bgOverlay.addClass(READY_CLASS);
373
+ }
374
+
375
+ // Trap the focus in popup
376
+ _document.on('focusin' + EVENT_NS, mfp._onFocusIn);
377
+
378
+ }, 16);
379
+
380
+ mfp.isOpen = true;
381
+ mfp.updateSize(windowHeight);
382
+ _mfpTrigger(OPEN_EVENT);
383
+
384
+ return data;
385
+ },
386
+
387
+ /**
388
+ * Closes the popup
389
+ */
390
+ close: function() {
391
+ if(!mfp.isOpen) return;
392
+ _mfpTrigger(BEFORE_CLOSE_EVENT);
393
+
394
+ mfp.isOpen = false;
395
+ // for CSS3 animation
396
+ if(mfp.st.removalDelay && !mfp.isLowIE && mfp.supportsTransition ) {
397
+ mfp._addClassToMFP(REMOVING_CLASS);
398
+ setTimeout(function() {
399
+ mfp._close();
400
+ }, mfp.st.removalDelay);
401
+ } else {
402
+ mfp._close();
403
+ }
404
+ },
405
+
406
+ /**
407
+ * Helper for close() function
408
+ */
409
+ _close: function() {
410
+ _mfpTrigger(CLOSE_EVENT);
411
+
412
+ var classesToRemove = REMOVING_CLASS + ' ' + READY_CLASS + ' ';
413
+
414
+ mfp.bgOverlay.detach();
415
+ mfp.wrap.detach();
416
+ mfp.container.empty();
417
+
418
+ if(mfp.st.mainClass) {
419
+ classesToRemove += mfp.st.mainClass + ' ';
420
+ }
421
+
422
+ mfp._removeClassFromMFP(classesToRemove);
423
+
424
+ if(mfp.fixedContentPos) {
425
+ var windowStyles = {marginRight: ''};
426
+ if(mfp.isIE7) {
427
+ $('body, html').css('overflow', '');
428
+ } else {
429
+ windowStyles.overflow = '';
430
+ }
431
+ $('html').css(windowStyles);
432
+ }
433
+
434
+ _document.off('keyup' + EVENT_NS + ' focusin' + EVENT_NS);
435
+ mfp.ev.off(EVENT_NS);
436
+
437
+ // clean up DOM elements that aren't removed
438
+ mfp.wrap.attr('class', 'mfp-wrap').removeAttr('style');
439
+ mfp.bgOverlay.attr('class', 'mfp-bg');
440
+ mfp.container.attr('class', 'mfp-container');
441
+
442
+ // remove close button from target element
443
+ if(mfp.st.showCloseBtn &&
444
+ (!mfp.st.closeBtnInside || mfp.currTemplate[mfp.currItem.type] === true)) {
445
+ if(mfp.currTemplate.closeBtn)
446
+ mfp.currTemplate.closeBtn.detach();
447
+ }
448
+
449
+
450
+ if(mfp.st.autoFocusLast && mfp._lastFocusedEl) {
451
+ $(mfp._lastFocusedEl).focus(); // put tab focus back
452
+ }
453
+ mfp.currItem = null;
454
+ mfp.content = null;
455
+ mfp.currTemplate = null;
456
+ mfp.prevHeight = 0;
457
+
458
+ _mfpTrigger(AFTER_CLOSE_EVENT);
459
+ },
460
+
461
+ updateSize: function(winHeight) {
462
+
463
+ if(mfp.isIOS) {
464
+ // fixes iOS nav bars https://github.com/dimsemenov/Magnific-Popup/issues/2
465
+ var zoomLevel = document.documentElement.clientWidth / window.innerWidth;
466
+ var height = window.innerHeight * zoomLevel;
467
+ mfp.wrap.css('height', height);
468
+ mfp.wH = height;
469
+ } else {
470
+ mfp.wH = winHeight || _window.height();
471
+ }
472
+ // Fixes #84: popup incorrectly positioned with position:relative on body
473
+ if(!mfp.fixedContentPos) {
474
+ mfp.wrap.css('height', mfp.wH);
475
+ }
476
+
477
+ _mfpTrigger('Resize');
478
+
479
+ },
480
+
481
+ /**
482
+ * Set content of popup based on current index
483
+ */
484
+ updateItemHTML: function() {
485
+ var item = mfp.items[mfp.index];
486
+
487
+ // Detach and perform modifications
488
+ mfp.contentContainer.detach();
489
+
490
+ if(mfp.content)
491
+ mfp.content.detach();
492
+
493
+ if(!item.parsed) {
494
+ item = mfp.parseEl( mfp.index );
495
+ }
496
+
497
+ var type = item.type;
498
+
499
+ _mfpTrigger('BeforeChange', [mfp.currItem ? mfp.currItem.type : '', type]);
500
+ // BeforeChange event works like so:
501
+ // _mfpOn('BeforeChange', function(e, prevType, newType) { });
502
+
503
+ mfp.currItem = item;
504
+
505
+ if(!mfp.currTemplate[type]) {
506
+ var markup = mfp.st[type] ? mfp.st[type].markup : false;
507
+
508
+ // allows to modify markup
509
+ _mfpTrigger('FirstMarkupParse', markup);
510
+
511
+ if(markup) {
512
+ mfp.currTemplate[type] = $(markup);
513
+ } else {
514
+ // if there is no markup found we just define that template is parsed
515
+ mfp.currTemplate[type] = true;
516
+ }
517
+ }
518
+
519
+ if(_prevContentType && _prevContentType !== item.type) {
520
+ mfp.container.removeClass('mfp-'+_prevContentType+'-holder');
521
+ }
522
+
523
+ var newContent = mfp['get' + type.charAt(0).toUpperCase() + type.slice(1)](item, mfp.currTemplate[type]);
524
+ mfp.appendContent(newContent, type);
525
+
526
+ item.preloaded = true;
527
+
528
+ _mfpTrigger(CHANGE_EVENT, item);
529
+ _prevContentType = item.type;
530
+
531
+ // Append container back after its content changed
532
+ mfp.container.prepend(mfp.contentContainer);
533
+
534
+ _mfpTrigger('AfterChange');
535
+ },
536
+
537
+
538
+ /**
539
+ * Set HTML content of popup
540
+ */
541
+ appendContent: function(newContent, type) {
542
+ mfp.content = newContent;
543
+
544
+ if(newContent) {
545
+ if(mfp.st.showCloseBtn && mfp.st.closeBtnInside &&
546
+ mfp.currTemplate[type] === true) {
547
+ // if there is no markup, we just append close button element inside
548
+ if(!mfp.content.find('.mfp-close').length) {
549
+ mfp.content.append(_getCloseBtn());
550
+ }
551
+ } else {
552
+ mfp.content = newContent;
553
+ }
554
+ } else {
555
+ mfp.content = '';
556
+ }
557
+
558
+ _mfpTrigger(BEFORE_APPEND_EVENT);
559
+ mfp.container.addClass('mfp-'+type+'-holder');
560
+
561
+ mfp.contentContainer.append(mfp.content);
562
+ },
563
+
564
+
565
+ /**
566
+ * Creates Magnific Popup data object based on given data
567
+ * @param {int} index Index of item to parse
568
+ */
569
+ parseEl: function(index) {
570
+ var item = mfp.items[index],
571
+ type;
572
+
573
+ if(item.tagName) {
574
+ item = { el: $(item) };
575
+ } else {
576
+ type = item.type;
577
+ item = { data: item, src: item.src };
578
+ }
579
+
580
+ if(item.el) {
581
+ var types = mfp.types;
582
+
583
+ // check for 'mfp-TYPE' class
584
+ for(var i = 0; i < types.length; i++) {
585
+ if( item.el.hasClass('mfp-'+types[i]) ) {
586
+ type = types[i];
587
+ break;
588
+ }
589
+ }
590
+
591
+ item.src = item.el.attr('data-mfp-src');
592
+ if(!item.src) {
593
+ item.src = item.el.attr('href');
594
+ }
595
+ }
596
+
597
+ item.type = type || mfp.st.type || 'inline';
598
+ item.index = index;
599
+ item.parsed = true;
600
+ mfp.items[index] = item;
601
+ _mfpTrigger('ElementParse', item);
602
+
603
+ return mfp.items[index];
604
+ },
605
+
606
+
607
+ /**
608
+ * Initializes single popup or a group of popups
609
+ */
610
+ addGroup: function(el, options) {
611
+ var eHandler = function(e) {
612
+ e.mfpEl = this;
613
+ mfp._openClick(e, el, options);
614
+ };
615
+
616
+ if(!options) {
617
+ options = {};
618
+ }
619
+
620
+ var eName = 'click.magnificPopup';
621
+ options.mainEl = el;
622
+
623
+ if(options.items) {
624
+ options.isObj = true;
625
+ el.off(eName).on(eName, eHandler);
626
+ } else {
627
+ options.isObj = false;
628
+ if(options.delegate) {
629
+ el.off(eName).on(eName, options.delegate , eHandler);
630
+ } else {
631
+ options.items = el;
632
+ el.off(eName).on(eName, eHandler);
633
+ }
634
+ }
635
+ },
636
+ _openClick: function(e, el, options) {
637
+ var midClick = options.midClick !== undefined ? options.midClick : $.magnificPopup.defaults.midClick;
638
+
639
+
640
+ if(!midClick && ( e.which === 2 || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey ) ) {
641
+ return;
642
+ }
643
+
644
+ var disableOn = options.disableOn !== undefined ? options.disableOn : $.magnificPopup.defaults.disableOn;
645
+
646
+ if(disableOn) {
647
+ if($.isFunction(disableOn)) {
648
+ if( !disableOn.call(mfp) ) {
649
+ return true;
650
+ }
651
+ } else { // else it's number
652
+ if( _window.width() < disableOn ) {
653
+ return true;
654
+ }
655
+ }
656
+ }
657
+
658
+ if(e.type) {
659
+ e.preventDefault();
660
+
661
+ // This will prevent popup from closing if element is inside and popup is already opened
662
+ if(mfp.isOpen) {
663
+ e.stopPropagation();
664
+ }
665
+ }
666
+
667
+ options.el = $(e.mfpEl);
668
+ if(options.delegate) {
669
+ options.items = el.find(options.delegate);
670
+ }
671
+ mfp.open(options);
672
+ },
673
+
674
+
675
+ /**
676
+ * Updates text on preloader
677
+ */
678
+ updateStatus: function(status, text) {
679
+
680
+ if(mfp.preloader) {
681
+ if(_prevStatus !== status) {
682
+ mfp.container.removeClass('mfp-s-'+_prevStatus);
683
+ }
684
+
685
+ if(!text && status === 'loading') {
686
+ text = mfp.st.tLoading;
687
+ }
688
+
689
+ var data = {
690
+ status: status,
691
+ text: text
692
+ };
693
+ // allows to modify status
694
+ _mfpTrigger('UpdateStatus', data);
695
+
696
+ status = data.status;
697
+ text = data.text;
698
+
699
+ mfp.preloader.html(text);
700
+
701
+ mfp.preloader.find('a').on('click', function(e) {
702
+ e.stopImmediatePropagation();
703
+ });
704
+
705
+ mfp.container.addClass('mfp-s-'+status);
706
+ _prevStatus = status;
707
+ }
708
+ },
709
+
710
+
711
+ /*
712
+ "Private" helpers that aren't private at all
713
+ */
714
+ // Check to close popup or not
715
+ // "target" is an element that was clicked
716
+ _checkIfClose: function(target) {
717
+
718
+ if($(target).hasClass(PREVENT_CLOSE_CLASS)) {
719
+ return;
720
+ }
721
+
722
+ var closeOnContent = mfp.st.closeOnContentClick;
723
+ var closeOnBg = mfp.st.closeOnBgClick;
724
+
725
+ if(closeOnContent && closeOnBg) {
726
+ return true;
727
+ } else {
728
+
729
+ // We close the popup if click is on close button or on preloader. Or if there is no content.
730
+ if(!mfp.content || $(target).hasClass('mfp-close') || (mfp.preloader && target === mfp.preloader[0]) ) {
731
+ return true;
732
+ }
733
+
734
+ // if click is outside the content
735
+ if( (target !== mfp.content[0] && !$.contains(mfp.content[0], target)) ) {
736
+ if(closeOnBg) {
737
+ // last check, if the clicked element is in DOM, (in case it's removed onclick)
738
+ if( $.contains(document, target) ) {
739
+ return true;
740
+ }
741
+ }
742
+ } else if(closeOnContent) {
743
+ return true;
744
+ }
745
+
746
+ }
747
+ return false;
748
+ },
749
+ _addClassToMFP: function(cName) {
750
+ mfp.bgOverlay.addClass(cName);
751
+ mfp.wrap.addClass(cName);
752
+ },
753
+ _removeClassFromMFP: function(cName) {
754
+ this.bgOverlay.removeClass(cName);
755
+ mfp.wrap.removeClass(cName);
756
+ },
757
+ _hasScrollBar: function(winHeight) {
758
+ return ( (mfp.isIE7 ? _document.height() : document.body.scrollHeight) > (winHeight || _window.height()) );
759
+ },
760
+ _setFocus: function() {
761
+ (mfp.st.focus ? mfp.content.find(mfp.st.focus).eq(0) : mfp.wrap).focus();
762
+ },
763
+ _onFocusIn: function(e) {
764
+ if( e.target !== mfp.wrap[0] && !$.contains(mfp.wrap[0], e.target) ) {
765
+ mfp._setFocus();
766
+ return false;
767
+ }
768
+ },
769
+ _parseMarkup: function(template, values, item) {
770
+ var arr;
771
+ if(item.data) {
772
+ values = $.extend(item.data, values);
773
+ }
774
+ _mfpTrigger(MARKUP_PARSE_EVENT, [template, values, item] );
775
+
776
+ $.each(values, function(key, value) {
777
+ if(value === undefined || value === false) {
778
+ return true;
779
+ }
780
+ arr = key.split('_');
781
+ if(arr.length > 1) {
782
+ var el = template.find(EVENT_NS + '-'+arr[0]);
783
+
784
+ if(el.length > 0) {
785
+ var attr = arr[1];
786
+ if(attr === 'replaceWith') {
787
+ if(el[0] !== value[0]) {
788
+ el.replaceWith(value);
789
+ }
790
+ } else if(attr === 'img') {
791
+ if(el.is('img')) {
792
+ el.attr('src', value);
793
+ } else {
794
+ el.replaceWith( $('<img>').attr('src', value).attr('class', el.attr('class')) );
795
+ }
796
+ } else {
797
+ el.attr(arr[1], value);
798
+ }
799
+ }
800
+
801
+ } else {
802
+ template.find(EVENT_NS + '-'+key).html(value);
803
+ }
804
+ });
805
+ },
806
+
807
+ _getScrollbarSize: function() {
808
+ // thx David
809
+ if(mfp.scrollbarSize === undefined) {
810
+ var scrollDiv = document.createElement("div");
811
+ scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;';
812
+ document.body.appendChild(scrollDiv);
813
+ mfp.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth;
814
+ document.body.removeChild(scrollDiv);
815
+ }
816
+ return mfp.scrollbarSize;
817
+ }
818
+
819
+ }; /* MagnificPopup core prototype end */
820
+
821
+
822
+
823
+
824
+ /**
825
+ * Public static functions
826
+ */
827
+ $.magnificPopup = {
828
+ instance: null,
829
+ proto: MagnificPopup.prototype,
830
+ modules: [],
831
+
832
+ open: function(options, index) {
833
+ _checkInstance();
834
+
835
+ if(!options) {
836
+ options = {};
837
+ } else {
838
+ options = $.extend(true, {}, options);
839
+ }
840
+
841
+ options.isObj = true;
842
+ options.index = index || 0;
843
+ return this.instance.open(options);
844
+ },
845
+
846
+ close: function() {
847
+ return $.magnificPopup.instance && $.magnificPopup.instance.close();
848
+ },
849
+
850
+ registerModule: function(name, module) {
851
+ if(module.options) {
852
+ $.magnificPopup.defaults[name] = module.options;
853
+ }
854
+ $.extend(this.proto, module.proto);
855
+ this.modules.push(name);
856
+ },
857
+
858
+ defaults: {
859
+
860
+ // Info about options is in docs:
861
+ // http://dimsemenov.com/plugins/magnific-popup/documentation.html#options
862
+
863
+ disableOn: 0,
864
+
865
+ key: null,
866
+
867
+ midClick: false,
868
+
869
+ mainClass: '',
870
+
871
+ preloader: true,
872
+
873
+ focus: '', // CSS selector of input to focus after popup is opened
874
+
875
+ closeOnContentClick: false,
876
+
877
+ closeOnBgClick: true,
878
+
879
+ closeBtnInside: true,
880
+
881
+ showCloseBtn: true,
882
+
883
+ enableEscapeKey: true,
884
+
885
+ modal: false,
886
+
887
+ alignTop: false,
888
+
889
+ removalDelay: 0,
890
+
891
+ prependTo: null,
892
+
893
+ fixedContentPos: 'auto',
894
+
895
+ fixedBgPos: 'auto',
896
+
897
+ overflowY: 'auto',
898
+
899
+ closeMarkup: '<button title="%title%" type="button" class="mfp-close">&#215;</button>',
900
+
901
+ tClose: 'Close (Esc)',
902
+
903
+ tLoading: 'Loading...',
904
+
905
+ autoFocusLast: true
906
+
907
+ }
908
+ };
909
+
910
+
911
+
912
+ $.fn.magnificPopup = function(options) {
913
+ _checkInstance();
914
+
915
+ var jqEl = $(this);
916
+
917
+ // We call some API method of first param is a string
918
+ if (typeof options === "string" ) {
919
+
920
+ if(options === 'open') {
921
+ var items,
922
+ itemOpts = _isJQ ? jqEl.data('magnificPopup') : jqEl[0].magnificPopup,
923
+ index = parseInt(arguments[1], 10) || 0;
924
+
925
+ if(itemOpts.items) {
926
+ items = itemOpts.items[index];
927
+ } else {
928
+ items = jqEl;
929
+ if(itemOpts.delegate) {
930
+ items = items.find(itemOpts.delegate);
931
+ }
932
+ items = items.eq( index );
933
+ }
934
+ mfp._openClick({mfpEl:items}, jqEl, itemOpts);
935
+ } else {
936
+ if(mfp.isOpen)
937
+ mfp[options].apply(mfp, Array.prototype.slice.call(arguments, 1));
938
+ }
939
+
940
+ } else {
941
+ // clone options obj
942
+ options = $.extend(true, {}, options);
943
+
944
+ /*
945
+ * As Zepto doesn't support .data() method for objects
946
+ * and it works only in normal browsers
947
+ * we assign "options" object directly to the DOM element. FTW!
948
+ */
949
+ if(_isJQ) {
950
+ jqEl.data('magnificPopup', options);
951
+ } else {
952
+ jqEl[0].magnificPopup = options;
953
+ }
954
+
955
+ mfp.addGroup(jqEl, options);
956
+
957
+ }
958
+ return jqEl;
959
+ };
960
+
961
+ /*>>core*/
962
+
963
+ /*>>inline*/
964
+
965
+ var INLINE_NS = 'inline',
966
+ _hiddenClass,
967
+ _inlinePlaceholder,
968
+ _lastInlineElement,
969
+ _putInlineElementsBack = function() {
970
+ if(_lastInlineElement) {
971
+ _inlinePlaceholder.after( _lastInlineElement.addClass(_hiddenClass) ).detach();
972
+ _lastInlineElement = null;
973
+ }
974
+ };
975
+
976
+ $.magnificPopup.registerModule(INLINE_NS, {
977
+ options: {
978
+ hiddenClass: 'hide', // will be appended with `mfp-` prefix
979
+ markup: '',
980
+ tNotFound: 'Content not found'
981
+ },
982
+ proto: {
983
+
984
+ initInline: function() {
985
+ mfp.types.push(INLINE_NS);
986
+
987
+ _mfpOn(CLOSE_EVENT+'.'+INLINE_NS, function() {
988
+ _putInlineElementsBack();
989
+ });
990
+ },
991
+
992
+ getInline: function(item, template) {
993
+
994
+ _putInlineElementsBack();
995
+
996
+ if(item.src) {
997
+ var inlineSt = mfp.st.inline,
998
+ el = $(item.src);
999
+
1000
+ if(el.length) {
1001
+
1002
+ // If target element has parent - we replace it with placeholder and put it back after popup is closed
1003
+ var parent = el[0].parentNode;
1004
+ if(parent && parent.tagName) {
1005
+ if(!_inlinePlaceholder) {
1006
+ _hiddenClass = inlineSt.hiddenClass;
1007
+ _inlinePlaceholder = _getEl(_hiddenClass);
1008
+ _hiddenClass = 'mfp-'+_hiddenClass;
1009
+ }
1010
+ // replace target inline element with placeholder
1011
+ _lastInlineElement = el.after(_inlinePlaceholder).detach().removeClass(_hiddenClass);
1012
+ }
1013
+
1014
+ mfp.updateStatus('ready');
1015
+ } else {
1016
+ mfp.updateStatus('error', inlineSt.tNotFound);
1017
+ el = $('<div>');
1018
+ }
1019
+
1020
+ item.inlineElement = el;
1021
+ return el;
1022
+ }
1023
+
1024
+ mfp.updateStatus('ready');
1025
+ mfp._parseMarkup(template, {}, item);
1026
+ return template;
1027
+ }
1028
+ }
1029
+ });
1030
+
1031
+ /*>>inline*/
1032
+
1033
+ /*>>ajax*/
1034
+ var AJAX_NS = 'ajax',
1035
+ _ajaxCur,
1036
+ _removeAjaxCursor = function() {
1037
+ if(_ajaxCur) {
1038
+ $(document.body).removeClass(_ajaxCur);
1039
+ }
1040
+ },
1041
+ _destroyAjaxRequest = function() {
1042
+ _removeAjaxCursor();
1043
+ if(mfp.req) {
1044
+ mfp.req.abort();
1045
+ }
1046
+ };
1047
+
1048
+ $.magnificPopup.registerModule(AJAX_NS, {
1049
+
1050
+ options: {
1051
+ settings: null,
1052
+ cursor: 'mfp-ajax-cur',
1053
+ tError: '<a href="%url%">The content</a> could not be loaded.'
1054
+ },
1055
+
1056
+ proto: {
1057
+ initAjax: function() {
1058
+ mfp.types.push(AJAX_NS);
1059
+ _ajaxCur = mfp.st.ajax.cursor;
1060
+
1061
+ _mfpOn(CLOSE_EVENT+'.'+AJAX_NS, _destroyAjaxRequest);
1062
+ _mfpOn('BeforeChange.' + AJAX_NS, _destroyAjaxRequest);
1063
+ },
1064
+ getAjax: function(item) {
1065
+
1066
+ if(_ajaxCur) {
1067
+ $(document.body).addClass(_ajaxCur);
1068
+ }
1069
+
1070
+ mfp.updateStatus('loading');
1071
+
1072
+ var opts = $.extend({
1073
+ url: item.src,
1074
+ success: function(data, textStatus, jqXHR) {
1075
+ var temp = {
1076
+ data:data,
1077
+ xhr:jqXHR
1078
+ };
1079
+
1080
+ _mfpTrigger('ParseAjax', temp);
1081
+
1082
+ mfp.appendContent( $(temp.data), AJAX_NS );
1083
+
1084
+ item.finished = true;
1085
+
1086
+ _removeAjaxCursor();
1087
+
1088
+ mfp._setFocus();
1089
+
1090
+ setTimeout(function() {
1091
+ mfp.wrap.addClass(READY_CLASS);
1092
+ }, 16);
1093
+
1094
+ mfp.updateStatus('ready');
1095
+
1096
+ _mfpTrigger('AjaxContentAdded');
1097
+ },
1098
+ error: function() {
1099
+ _removeAjaxCursor();
1100
+ item.finished = item.loadError = true;
1101
+ mfp.updateStatus('error', mfp.st.ajax.tError.replace('%url%', item.src));
1102
+ }
1103
+ }, mfp.st.ajax.settings);
1104
+
1105
+ mfp.req = $.ajax(opts);
1106
+
1107
+ return '';
1108
+ }
1109
+ }
1110
+ });
1111
+
1112
+ /*>>ajax*/
1113
+
1114
+ /*>>image*/
1115
+ var _imgInterval,
1116
+ _getTitle = function(item) {
1117
+ if(item.data && item.data.title !== undefined)
1118
+ return item.data.title;
1119
+
1120
+ var src = mfp.st.image.titleSrc;
1121
+
1122
+ if(src) {
1123
+ if($.isFunction(src)) {
1124
+ return src.call(mfp, item);
1125
+ } else if(item.el) {
1126
+ return item.el.attr(src) || '';
1127
+ }
1128
+ }
1129
+ return '';
1130
+ };
1131
+
1132
+ $.magnificPopup.registerModule('image', {
1133
+
1134
+ options: {
1135
+ markup: '<div class="mfp-figure">'+
1136
+ '<div class="mfp-close"></div>'+
1137
+ '<figure>'+
1138
+ '<div class="mfp-img"></div>'+
1139
+ '<figcaption>'+
1140
+ '<div class="mfp-bottom-bar">'+
1141
+ '<div class="mfp-title"></div>'+
1142
+ '<div class="mfp-counter"></div>'+
1143
+ '</div>'+
1144
+ '</figcaption>'+
1145
+ '</figure>'+
1146
+ '</div>',
1147
+ cursor: 'mfp-zoom-out-cur',
1148
+ titleSrc: 'title',
1149
+ verticalFit: true,
1150
+ tError: '<a href="%url%">The image</a> could not be loaded.'
1151
+ },
1152
+
1153
+ proto: {
1154
+ initImage: function() {
1155
+ var imgSt = mfp.st.image,
1156
+ ns = '.image';
1157
+
1158
+ mfp.types.push('image');
1159
+
1160
+ _mfpOn(OPEN_EVENT+ns, function() {
1161
+ if(mfp.currItem.type === 'image' && imgSt.cursor) {
1162
+ $(document.body).addClass(imgSt.cursor);
1163
+ }
1164
+ });
1165
+
1166
+ _mfpOn(CLOSE_EVENT+ns, function() {
1167
+ if(imgSt.cursor) {
1168
+ $(document.body).removeClass(imgSt.cursor);
1169
+ }
1170
+ _window.off('resize' + EVENT_NS);
1171
+ });
1172
+
1173
+ _mfpOn('Resize'+ns, mfp.resizeImage);
1174
+ if(mfp.isLowIE) {
1175
+ _mfpOn('AfterChange', mfp.resizeImage);
1176
+ }
1177
+ },
1178
+ resizeImage: function() {
1179
+ var item = mfp.currItem;
1180
+ if(!item || !item.img) return;
1181
+
1182
+ if(mfp.st.image.verticalFit) {
1183
+ var decr = 0;
1184
+ // fix box-sizing in ie7/8
1185
+ if(mfp.isLowIE) {
1186
+ decr = parseInt(item.img.css('padding-top'), 10) + parseInt(item.img.css('padding-bottom'),10);
1187
+ }
1188
+ item.img.css('max-height', mfp.wH-decr);
1189
+ }
1190
+ },
1191
+ _onImageHasSize: function(item) {
1192
+ if(item.img) {
1193
+
1194
+ item.hasSize = true;
1195
+
1196
+ if(_imgInterval) {
1197
+ clearInterval(_imgInterval);
1198
+ }
1199
+
1200
+ item.isCheckingImgSize = false;
1201
+
1202
+ _mfpTrigger('ImageHasSize', item);
1203
+
1204
+ if(item.imgHidden) {
1205
+ if(mfp.content)
1206
+ mfp.content.removeClass('mfp-loading');
1207
+
1208
+ item.imgHidden = false;
1209
+ }
1210
+
1211
+ }
1212
+ },
1213
+
1214
+ /**
1215
+ * Function that loops until the image has size to display elements that rely on it asap
1216
+ */
1217
+ findImageSize: function(item) {
1218
+
1219
+ var counter = 0,
1220
+ img = item.img[0],
1221
+ mfpSetInterval = function(delay) {
1222
+
1223
+ if(_imgInterval) {
1224
+ clearInterval(_imgInterval);
1225
+ }
1226
+ // decelerating interval that checks for size of an image
1227
+ _imgInterval = setInterval(function() {
1228
+ if(img.naturalWidth > 0) {
1229
+ mfp._onImageHasSize(item);
1230
+ return;
1231
+ }
1232
+
1233
+ if(counter > 200) {
1234
+ clearInterval(_imgInterval);
1235
+ }
1236
+
1237
+ counter++;
1238
+ if(counter === 3) {
1239
+ mfpSetInterval(10);
1240
+ } else if(counter === 40) {
1241
+ mfpSetInterval(50);
1242
+ } else if(counter === 100) {
1243
+ mfpSetInterval(500);
1244
+ }
1245
+ }, delay);
1246
+ };
1247
+
1248
+ mfpSetInterval(1);
1249
+ },
1250
+
1251
+ getImage: function(item, template) {
1252
+
1253
+ var guard = 0,
1254
+
1255
+ // image load complete handler
1256
+ onLoadComplete = function() {
1257
+ if(item) {
1258
+ if (item.img[0].complete) {
1259
+ item.img.off('.mfploader');
1260
+
1261
+ if(item === mfp.currItem){
1262
+ mfp._onImageHasSize(item);
1263
+
1264
+ mfp.updateStatus('ready');
1265
+ }
1266
+
1267
+ item.hasSize = true;
1268
+ item.loaded = true;
1269
+
1270
+ _mfpTrigger('ImageLoadComplete');
1271
+
1272
+ }
1273
+ else {
1274
+ // if image complete check fails 200 times (20 sec), we assume that there was an error.
1275
+ guard++;
1276
+ if(guard < 200) {
1277
+ setTimeout(onLoadComplete,100);
1278
+ } else {
1279
+ onLoadError();
1280
+ }
1281
+ }
1282
+ }
1283
+ },
1284
+
1285
+ // image error handler
1286
+ onLoadError = function() {
1287
+ if(item) {
1288
+ item.img.off('.mfploader');
1289
+ if(item === mfp.currItem){
1290
+ mfp._onImageHasSize(item);
1291
+ mfp.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
1292
+ }
1293
+
1294
+ item.hasSize = true;
1295
+ item.loaded = true;
1296
+ item.loadError = true;
1297
+ }
1298
+ },
1299
+ imgSt = mfp.st.image;
1300
+
1301
+
1302
+ var el = template.find('.mfp-img');
1303
+ if(el.length) {
1304
+ var img = document.createElement('img');
1305
+ img.className = 'mfp-img';
1306
+ if(item.el && item.el.find('img').length) {
1307
+ img.alt = item.el.find('img').attr('alt');
1308
+ }
1309
+ item.img = $(img).on('load.mfploader', onLoadComplete).on('error.mfploader', onLoadError);
1310
+ img.src = item.src;
1311
+
1312
+ // without clone() "error" event is not firing when IMG is replaced by new IMG
1313
+ // TODO: find a way to avoid such cloning
1314
+ if(el.is('img')) {
1315
+ item.img = item.img.clone();
1316
+ }
1317
+
1318
+ img = item.img[0];
1319
+ if(img.naturalWidth > 0) {
1320
+ item.hasSize = true;
1321
+ } else if(!img.width) {
1322
+ item.hasSize = false;
1323
+ }
1324
+ }
1325
+
1326
+ mfp._parseMarkup(template, {
1327
+ title: _getTitle(item),
1328
+ img_replaceWith: item.img
1329
+ }, item);
1330
+
1331
+ mfp.resizeImage();
1332
+
1333
+ if(item.hasSize) {
1334
+ if(_imgInterval) clearInterval(_imgInterval);
1335
+
1336
+ if(item.loadError) {
1337
+ template.addClass('mfp-loading');
1338
+ mfp.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
1339
+ } else {
1340
+ template.removeClass('mfp-loading');
1341
+ mfp.updateStatus('ready');
1342
+ }
1343
+ return template;
1344
+ }
1345
+
1346
+ mfp.updateStatus('loading');
1347
+ item.loading = true;
1348
+
1349
+ if(!item.hasSize) {
1350
+ item.imgHidden = true;
1351
+ template.addClass('mfp-loading');
1352
+ mfp.findImageSize(item);
1353
+ }
1354
+
1355
+ return template;
1356
+ }
1357
+ }
1358
+ });
1359
+
1360
+ /*>>image*/
1361
+
1362
+ /*>>zoom*/
1363
+ var hasMozTransform,
1364
+ getHasMozTransform = function() {
1365
+ if(hasMozTransform === undefined) {
1366
+ hasMozTransform = document.createElement('p').style.MozTransform !== undefined;
1367
+ }
1368
+ return hasMozTransform;
1369
+ };
1370
+
1371
+ $.magnificPopup.registerModule('zoom', {
1372
+
1373
+ options: {
1374
+ enabled: false,
1375
+ easing: 'ease-in-out',
1376
+ duration: 300,
1377
+ opener: function(element) {
1378
+ return element.is('img') ? element : element.find('img');
1379
+ }
1380
+ },
1381
+
1382
+ proto: {
1383
+
1384
+ initZoom: function() {
1385
+ var zoomSt = mfp.st.zoom,
1386
+ ns = '.zoom',
1387
+ image;
1388
+
1389
+ if(!zoomSt.enabled || !mfp.supportsTransition) {
1390
+ return;
1391
+ }
1392
+
1393
+ var duration = zoomSt.duration,
1394
+ getElToAnimate = function(image) {
1395
+ var newImg = image.clone().removeAttr('style').removeAttr('class').addClass('mfp-animated-image'),
1396
+ transition = 'all '+(zoomSt.duration/1000)+'s ' + zoomSt.easing,
1397
+ cssObj = {
1398
+ position: 'fixed',
1399
+ zIndex: 9999,
1400
+ left: 0,
1401
+ top: 0,
1402
+ '-webkit-backface-visibility': 'hidden'
1403
+ },
1404
+ t = 'transition';
1405
+
1406
+ cssObj['-webkit-'+t] = cssObj['-moz-'+t] = cssObj['-o-'+t] = cssObj[t] = transition;
1407
+
1408
+ newImg.css(cssObj);
1409
+ return newImg;
1410
+ },
1411
+ showMainContent = function() {
1412
+ mfp.content.css('visibility', 'visible');
1413
+ },
1414
+ openTimeout,
1415
+ animatedImg;
1416
+
1417
+ _mfpOn('BuildControls'+ns, function() {
1418
+ if(mfp._allowZoom()) {
1419
+
1420
+ clearTimeout(openTimeout);
1421
+ mfp.content.css('visibility', 'hidden');
1422
+
1423
+ // Basically, all code below does is clones existing image, puts in on top of the current one and animated it
1424
+
1425
+ image = mfp._getItemToZoom();
1426
+
1427
+ if(!image) {
1428
+ showMainContent();
1429
+ return;
1430
+ }
1431
+
1432
+ animatedImg = getElToAnimate(image);
1433
+
1434
+ animatedImg.css( mfp._getOffset() );
1435
+
1436
+ mfp.wrap.append(animatedImg);
1437
+
1438
+ openTimeout = setTimeout(function() {
1439
+ animatedImg.css( mfp._getOffset( true ) );
1440
+ openTimeout = setTimeout(function() {
1441
+
1442
+ showMainContent();
1443
+
1444
+ setTimeout(function() {
1445
+ animatedImg.remove();
1446
+ image = animatedImg = null;
1447
+ _mfpTrigger('ZoomAnimationEnded');
1448
+ }, 16); // avoid blink when switching images
1449
+
1450
+ }, duration); // this timeout equals animation duration
1451
+
1452
+ }, 16); // by adding this timeout we avoid short glitch at the beginning of animation
1453
+
1454
+
1455
+ // Lots of timeouts...
1456
+ }
1457
+ });
1458
+ _mfpOn(BEFORE_CLOSE_EVENT+ns, function() {
1459
+ if(mfp._allowZoom()) {
1460
+
1461
+ clearTimeout(openTimeout);
1462
+
1463
+ mfp.st.removalDelay = duration;
1464
+
1465
+ if(!image) {
1466
+ image = mfp._getItemToZoom();
1467
+ if(!image) {
1468
+ return;
1469
+ }
1470
+ animatedImg = getElToAnimate(image);
1471
+ }
1472
+
1473
+ animatedImg.css( mfp._getOffset(true) );
1474
+ mfp.wrap.append(animatedImg);
1475
+ mfp.content.css('visibility', 'hidden');
1476
+
1477
+ setTimeout(function() {
1478
+ animatedImg.css( mfp._getOffset() );
1479
+ }, 16);
1480
+ }
1481
+
1482
+ });
1483
+
1484
+ _mfpOn(CLOSE_EVENT+ns, function() {
1485
+ if(mfp._allowZoom()) {
1486
+ showMainContent();
1487
+ if(animatedImg) {
1488
+ animatedImg.remove();
1489
+ }
1490
+ image = null;
1491
+ }
1492
+ });
1493
+ },
1494
+
1495
+ _allowZoom: function() {
1496
+ return mfp.currItem.type === 'image';
1497
+ },
1498
+
1499
+ _getItemToZoom: function() {
1500
+ if(mfp.currItem.hasSize) {
1501
+ return mfp.currItem.img;
1502
+ } else {
1503
+ return false;
1504
+ }
1505
+ },
1506
+
1507
+ // Get element postion relative to viewport
1508
+ _getOffset: function(isLarge) {
1509
+ var el;
1510
+ if(isLarge) {
1511
+ el = mfp.currItem.img;
1512
+ } else {
1513
+ el = mfp.st.zoom.opener(mfp.currItem.el || mfp.currItem);
1514
+ }
1515
+
1516
+ var offset = el.offset();
1517
+ var paddingTop = parseInt(el.css('padding-top'),10);
1518
+ var paddingBottom = parseInt(el.css('padding-bottom'),10);
1519
+ offset.top -= ( $(window).scrollTop() - paddingTop );
1520
+
1521
+
1522
+ /*
1523
+
1524
+ Animating left + top + width/height looks glitchy in Firefox, but perfect in Chrome. And vice-versa.
1525
+
1526
+ */
1527
+ var obj = {
1528
+ width: el.width(),
1529
+ // fix Zepto height+padding issue
1530
+ height: (_isJQ ? el.innerHeight() : el[0].offsetHeight) - paddingBottom - paddingTop
1531
+ };
1532
+
1533
+ // I hate to do this, but there is no another option
1534
+ if( getHasMozTransform() ) {
1535
+ obj['-moz-transform'] = obj['transform'] = 'translate(' + offset.left + 'px,' + offset.top + 'px)';
1536
+ } else {
1537
+ obj.left = offset.left;
1538
+ obj.top = offset.top;
1539
+ }
1540
+ return obj;
1541
+ }
1542
+
1543
+ }
1544
+ });
1545
+
1546
+
1547
+
1548
+ /*>>zoom*/
1549
+
1550
+ /*>>iframe*/
1551
+
1552
+ var IFRAME_NS = 'iframe',
1553
+ _emptyPage = '//about:blank',
1554
+
1555
+ _fixIframeBugs = function(isShowing) {
1556
+ if(mfp.currTemplate[IFRAME_NS]) {
1557
+ var el = mfp.currTemplate[IFRAME_NS].find('iframe');
1558
+ if(el.length) {
1559
+ // reset src after the popup is closed to avoid "video keeps playing after popup is closed" bug
1560
+ if(!isShowing) {
1561
+ el[0].src = _emptyPage;
1562
+ }
1563
+
1564
+ // IE8 black screen bug fix
1565
+ if(mfp.isIE8) {
1566
+ el.css('display', isShowing ? 'block' : 'none');
1567
+ }
1568
+ }
1569
+ }
1570
+ };
1571
+
1572
+ $.magnificPopup.registerModule(IFRAME_NS, {
1573
+
1574
+ options: {
1575
+ markup: '<div class="mfp-iframe-scaler">'+
1576
+ '<div class="mfp-close"></div>'+
1577
+ '<iframe class="mfp-iframe" src="//about:blank" frameborder="0" allowfullscreen></iframe>'+
1578
+ '</div>',
1579
+
1580
+ srcAction: 'iframe_src',
1581
+
1582
+ // we don't care and support only one default type of URL by default
1583
+ patterns: {
1584
+ youtube: {
1585
+ index: 'youtube.com',
1586
+ id: 'v=',
1587
+ src: '//www.youtube.com/embed/%id%?autoplay=1'
1588
+ },
1589
+ vimeo: {
1590
+ index: 'vimeo.com/',
1591
+ id: '/',
1592
+ src: '//player.vimeo.com/video/%id%?autoplay=1'
1593
+ },
1594
+ gmaps: {
1595
+ index: '//maps.google.',
1596
+ src: '%id%&output=embed'
1597
+ }
1598
+ }
1599
+ },
1600
+
1601
+ proto: {
1602
+ initIframe: function() {
1603
+ mfp.types.push(IFRAME_NS);
1604
+
1605
+ _mfpOn('BeforeChange', function(e, prevType, newType) {
1606
+ if(prevType !== newType) {
1607
+ if(prevType === IFRAME_NS) {
1608
+ _fixIframeBugs(); // iframe if removed
1609
+ } else if(newType === IFRAME_NS) {
1610
+ _fixIframeBugs(true); // iframe is showing
1611
+ }
1612
+ }// else {
1613
+ // iframe source is switched, don't do anything
1614
+ //}
1615
+ });
1616
+
1617
+ _mfpOn(CLOSE_EVENT + '.' + IFRAME_NS, function() {
1618
+ _fixIframeBugs();
1619
+ });
1620
+ },
1621
+
1622
+ getIframe: function(item, template) {
1623
+ var embedSrc = item.src;
1624
+ var iframeSt = mfp.st.iframe;
1625
+
1626
+ $.each(iframeSt.patterns, function() {
1627
+ if(embedSrc.indexOf( this.index ) > -1) {
1628
+ if(this.id) {
1629
+ if(typeof this.id === 'string') {
1630
+ embedSrc = embedSrc.substr(embedSrc.lastIndexOf(this.id)+this.id.length, embedSrc.length);
1631
+ } else {
1632
+ embedSrc = this.id.call( this, embedSrc );
1633
+ }
1634
+ }
1635
+ embedSrc = this.src.replace('%id%', embedSrc );
1636
+ return false; // break;
1637
+ }
1638
+ });
1639
+
1640
+ var dataObj = {};
1641
+ if(iframeSt.srcAction) {
1642
+ dataObj[iframeSt.srcAction] = embedSrc;
1643
+ }
1644
+ mfp._parseMarkup(template, dataObj, item);
1645
+
1646
+ mfp.updateStatus('ready');
1647
+
1648
+ return template;
1649
+ }
1650
+ }
1651
+ });
1652
+
1653
+
1654
+
1655
+ /*>>iframe*/
1656
+
1657
+ /*>>gallery*/
1658
+ /**
1659
+ * Get looped index depending on number of slides
1660
+ */
1661
+ var _getLoopedId = function(index) {
1662
+ var numSlides = mfp.items.length;
1663
+ if(index > numSlides - 1) {
1664
+ return index - numSlides;
1665
+ } else if(index < 0) {
1666
+ return numSlides + index;
1667
+ }
1668
+ return index;
1669
+ },
1670
+ _replaceCurrTotal = function(text, curr, total) {
1671
+ return text.replace(/%curr%/gi, curr + 1).replace(/%total%/gi, total);
1672
+ };
1673
+
1674
+ $.magnificPopup.registerModule('gallery', {
1675
+
1676
+ options: {
1677
+ enabled: false,
1678
+ arrowMarkup: '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',
1679
+ preload: [0,2],
1680
+ navigateByImgClick: true,
1681
+ arrows: true,
1682
+
1683
+ tPrev: 'Previous (Left arrow key)',
1684
+ tNext: 'Next (Right arrow key)',
1685
+ tCounter: '%curr% of %total%'
1686
+ },
1687
+
1688
+ proto: {
1689
+ initGallery: function() {
1690
+
1691
+ var gSt = mfp.st.gallery,
1692
+ ns = '.mfp-gallery';
1693
+
1694
+ mfp.direction = true; // true - next, false - prev
1695
+
1696
+ if(!gSt || !gSt.enabled ) return false;
1697
+
1698
+ _wrapClasses += ' mfp-gallery';
1699
+
1700
+ _mfpOn(OPEN_EVENT+ns, function() {
1701
+
1702
+ if(gSt.navigateByImgClick) {
1703
+ mfp.wrap.on('click'+ns, '.mfp-img', function() {
1704
+ if(mfp.items.length > 1) {
1705
+ mfp.next();
1706
+ return false;
1707
+ }
1708
+ });
1709
+ }
1710
+
1711
+ _document.on('keydown'+ns, function(e) {
1712
+ if (e.keyCode === 37) {
1713
+ mfp.prev();
1714
+ } else if (e.keyCode === 39) {
1715
+ mfp.next();
1716
+ }
1717
+ });
1718
+ });
1719
+
1720
+ _mfpOn('UpdateStatus'+ns, function(e, data) {
1721
+ if(data.text) {
1722
+ data.text = _replaceCurrTotal(data.text, mfp.currItem.index, mfp.items.length);
1723
+ }
1724
+ });
1725
+
1726
+ _mfpOn(MARKUP_PARSE_EVENT+ns, function(e, element, values, item) {
1727
+ var l = mfp.items.length;
1728
+ values.counter = l > 1 ? _replaceCurrTotal(gSt.tCounter, item.index, l) : '';
1729
+ });
1730
+
1731
+ _mfpOn('BuildControls' + ns, function() {
1732
+ if(mfp.items.length > 1 && gSt.arrows && !mfp.arrowLeft) {
1733
+ var markup = gSt.arrowMarkup,
1734
+ arrowLeft = mfp.arrowLeft = $( markup.replace(/%title%/gi, gSt.tPrev).replace(/%dir%/gi, 'left') ).addClass(PREVENT_CLOSE_CLASS),
1735
+ arrowRight = mfp.arrowRight = $( markup.replace(/%title%/gi, gSt.tNext).replace(/%dir%/gi, 'right') ).addClass(PREVENT_CLOSE_CLASS);
1736
+
1737
+ arrowLeft.click(function() {
1738
+ mfp.prev();
1739
+ });
1740
+ arrowRight.click(function() {
1741
+ mfp.next();
1742
+ });
1743
+
1744
+ mfp.container.append(arrowLeft.add(arrowRight));
1745
+ }
1746
+ });
1747
+
1748
+ _mfpOn(CHANGE_EVENT+ns, function() {
1749
+ if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);
1750
+
1751
+ mfp._preloadTimeout = setTimeout(function() {
1752
+ mfp.preloadNearbyImages();
1753
+ mfp._preloadTimeout = null;
1754
+ }, 16);
1755
+ });
1756
+
1757
+
1758
+ _mfpOn(CLOSE_EVENT+ns, function() {
1759
+ _document.off(ns);
1760
+ mfp.wrap.off('click'+ns);
1761
+ mfp.arrowRight = mfp.arrowLeft = null;
1762
+ });
1763
+
1764
+ },
1765
+ next: function() {
1766
+ mfp.direction = true;
1767
+ mfp.index = _getLoopedId(mfp.index + 1);
1768
+ mfp.updateItemHTML();
1769
+ },
1770
+ prev: function() {
1771
+ mfp.direction = false;
1772
+ mfp.index = _getLoopedId(mfp.index - 1);
1773
+ mfp.updateItemHTML();
1774
+ },
1775
+ goTo: function(newIndex) {
1776
+ mfp.direction = (newIndex >= mfp.index);
1777
+ mfp.index = newIndex;
1778
+ mfp.updateItemHTML();
1779
+ },
1780
+ preloadNearbyImages: function() {
1781
+ var p = mfp.st.gallery.preload,
1782
+ preloadBefore = Math.min(p[0], mfp.items.length),
1783
+ preloadAfter = Math.min(p[1], mfp.items.length),
1784
+ i;
1785
+
1786
+ for(i = 1; i <= (mfp.direction ? preloadAfter : preloadBefore); i++) {
1787
+ mfp._preloadItem(mfp.index+i);
1788
+ }
1789
+ for(i = 1; i <= (mfp.direction ? preloadBefore : preloadAfter); i++) {
1790
+ mfp._preloadItem(mfp.index-i);
1791
+ }
1792
+ },
1793
+ _preloadItem: function(index) {
1794
+ index = _getLoopedId(index);
1795
+
1796
+ if(mfp.items[index].preloaded) {
1797
+ return;
1798
+ }
1799
+
1800
+ var item = mfp.items[index];
1801
+ if(!item.parsed) {
1802
+ item = mfp.parseEl( index );
1803
+ }
1804
+
1805
+ _mfpTrigger('LazyLoad', item);
1806
+
1807
+ if(item.type === 'image') {
1808
+ item.img = $('<img class="mfp-img" />').on('load.mfploader', function() {
1809
+ item.hasSize = true;
1810
+ }).on('error.mfploader', function() {
1811
+ item.hasSize = true;
1812
+ item.loadError = true;
1813
+ _mfpTrigger('LazyLoadError', item);
1814
+ }).attr('src', item.src);
1815
+ }
1816
+
1817
+
1818
+ item.preloaded = true;
1819
+ }
1820
+ }
1821
+ });
1822
+
1823
+ /*>>gallery*/
1824
+
1825
+ /*>>retina*/
1826
+
1827
+ var RETINA_NS = 'retina';
1828
+
1829
+ $.magnificPopup.registerModule(RETINA_NS, {
1830
+ options: {
1831
+ replaceSrc: function(item) {
1832
+ return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });
1833
+ },
1834
+ ratio: 1 // Function or number. Set to 1 to disable.
1835
+ },
1836
+ proto: {
1837
+ initRetina: function() {
1838
+ if(window.devicePixelRatio > 1) {
1839
+
1840
+ var st = mfp.st.retina,
1841
+ ratio = st.ratio;
1842
+
1843
+ ratio = !isNaN(ratio) ? ratio : ratio();
1844
+
1845
+ if(ratio > 1) {
1846
+ _mfpOn('ImageHasSize' + '.' + RETINA_NS, function(e, item) {
1847
+ item.img.css({
1848
+ 'max-width': item.img[0].naturalWidth / ratio,
1849
+ 'width': '100%'
1850
+ });
1851
+ });
1852
+ _mfpOn('ElementParse' + '.' + RETINA_NS, function(e, item) {
1853
+ item.src = st.replaceSrc(item, ratio);
1854
+ });
1855
+ }
1856
+ }
1857
+
1858
+ }
1859
+ }
1860
+ });
1861
+
1862
+ /*>>retina*/
1863
+ _checkInstance(); }));