magnific-popup-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e64d58ff6bce2c5317de41ef5e14c3cb5a33f557
4
+ data.tar.gz: 85d79b8f06f0713a56aed9b2c753b886edcc4b47
5
+ SHA512:
6
+ metadata.gz: ab7a50d73b6b335f86b0d1b5c0c03d68d367e890c0baf85277338185a9b46dc168e416450576f7ae6219feb15a7a89d529a940bf46551ffc0b8bdfa632474622
7
+ data.tar.gz: 58115a89f63d6d4fe0e8512c48d50e889d94bcfbd7ebbce6b4a57d065302fdd8cd765eea8a54b32679e6d053a5a4ca3f861f4123cc9fd9052e537fdf57ef2ca3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in magnific-popup-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Public domain
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Magnific-Popup-Rails
2
+
3
+ Integrates [magnific-popup.css](http://dimsemenov.com/plugins/magnific-popup/) with the rails asset pipeline.
4
+
5
+ Magnific Popup is a free responsive jQuery lightbox plugin that is focused on performance and providing best experience for user with any device (Zepto.js compatible).
6
+
7
+ The magnific popup is created by Created by Dmitry Semenov.
8
+
9
+ I used [markmcconachie's](https://github.com/markmcconachie) [normalize-rails](https://github.com/markmcconachie/normalize-rails) gem as an example for setting up this magnific popup gem.
10
+
11
+ # For Rails 3.1+ only
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'magnific-popup-rails', github: "joshuajansen/magnific-popup-rails"
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+
26
+ And then in your application.css
27
+
28
+ *= require magnific-popup
29
+
30
+ And then in your application.js
31
+
32
+ //= require magnific-popup
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'open-uri'
4
+
5
+ desc "Download the latest magnific-popup.css and magnific-popup.js"
6
+ task :update do
7
+ # CSS
8
+ url = "https://raw.github.com/dimsemenov/Magnific-Popup/master/dist/magnific-popup.css"
9
+ outputfile = "vendor/assets/stylesheets/magnific-popup-rails/magnific-popup.css"
10
+
11
+ open(outputfile, 'wb') do |file|
12
+ file << open(url).read
13
+ end
14
+
15
+ # JS
16
+ url = "https://raw.github.com/dimsemenov/Magnific-Popup/master/dist/jquery.magnific-popup.js"
17
+ outputfile = "vendor/assets/javascripts/magnific-popup-rails/jquery.magnific-popup.js"
18
+
19
+ open(outputfile, 'wb') do |file|
20
+ file << open(url).read
21
+ end
22
+
23
+ end
@@ -0,0 +1,8 @@
1
+ require "magnific-popup-rails/version"
2
+ require "magnific-popup-rails/engine"
3
+
4
+ module MagnificPopup
5
+ module Rails
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module MagnificPopup
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ initializer "configure assets of magnific-popup-rails", :group => :all do |app|
5
+ app.config.assets.precompile += %w( magnific-popup-rails/*.css magnific-popup-rails/*.js )
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module MagnificPopup
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/magnific-popup-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Joshua Jansen"]
6
+ gem.email = ["joshua@itflows.nl"]
7
+ gem.description = %q{Magnific Popup is a free responsive jQuery lightbox plugin that is focused on performance and providing best experience for user with any device}
8
+ gem.summary = %q{Magnific Popup displays images before they're completely loaded to take full advantage of progressive loading. For in and out transitions CSS3 is used instead of slow JavaScript animation.}
9
+ gem.homepage = "https://github.com/joshuajansen/magnific-popup-rails"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "magnific-popup-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MagnificPopup::Rails::VERSION
17
+
18
+ gem.add_development_dependency "rake"
19
+ end
@@ -0,0 +1 @@
1
+ //= require ./jquery.magnific-popup
@@ -0,0 +1,1644 @@
1
+ /*! Magnific Popup - v0.8.1 - 2013-05-02
2
+ * http://dimsemenov.com/plugins/magnific-popup/
3
+ * Copyright (c) 2013 Dmitry Semenov; */
4
+ ;(function($) {
5
+
6
+ /*>>core*/
7
+ /**
8
+ *
9
+ * Magnific Popup Core JS file
10
+ *
11
+ */
12
+
13
+
14
+ /**
15
+ * Private static constants
16
+ */
17
+ var CLOSE_EVENT = 'Close',
18
+ BEFORE_APPEND_EVENT = 'BeforeAppend',
19
+ MARKUP_PARSE_EVENT = 'MarkupParse',
20
+ OPEN_EVENT = 'Open',
21
+ CHANGE_EVENT = 'Change',
22
+ NS = 'mfp',
23
+ EVENT_NS = '.' + NS,
24
+ READY_CLASS = 'mfp-ready',
25
+ REMOVING_CLASS = 'mfp-removing',
26
+ PREVENT_CLOSE_CLASS = 'mfp-prevent-close';
27
+
28
+
29
+ /**
30
+ * Private vars
31
+ */
32
+ var mfp, // As we have only one instance of MagnificPopup object, we define it locally to not to use 'this'
33
+ MagnificPopup = function(){},
34
+ _prevStatus,
35
+ _window = $(window),
36
+ _body,
37
+ _document,
38
+ _prevContentType,
39
+ _wrapClasses,
40
+ _currPopupType;
41
+
42
+
43
+ /**
44
+ * Private functions
45
+ */
46
+ var _mfpOn = function(name, f) {
47
+ mfp.ev.on(NS + name + EVENT_NS, f);
48
+ },
49
+ _getEl = function(className, appendTo, html, raw) {
50
+ var el = document.createElement('div');
51
+ el.className = 'mfp-'+className;
52
+ if(html) {
53
+ el.innerHTML = html;
54
+ }
55
+ if(!raw) {
56
+ el = $(el);
57
+ if(appendTo) {
58
+ el.appendTo(appendTo);
59
+ }
60
+ } else if(appendTo) {
61
+ appendTo.appendChild(el);
62
+ }
63
+ return el;
64
+ },
65
+ _mfpTrigger = function(e, data) {
66
+ mfp.ev.triggerHandler(NS + e, data);
67
+
68
+ if(mfp.st.callbacks) {
69
+ // converts "mfpEventName" to "eventName" callback and triggers it if it's present
70
+ e = e.charAt(0).toLowerCase() + e.slice(1);
71
+ if(mfp.st.callbacks[e]) {
72
+ mfp.st.callbacks[e].apply(mfp, $.isArray(data) ? data : [data]);
73
+ }
74
+ }
75
+ },
76
+ _setFocus = function() {
77
+ (mfp.st.focus ? mfp.content.find(mfp.st.focus).eq(0) : mfp.wrap).focus();
78
+ },
79
+ _getCloseBtn = function(type) {
80
+ if(type !== _currPopupType || !mfp.currTemplate.closeBtn) {
81
+ mfp.currTemplate.closeBtn = $( mfp.st.closeMarkup.replace('%title%', mfp.st.tClose ) );
82
+ _currPopupType = type;
83
+ }
84
+ return mfp.currTemplate.closeBtn;
85
+ };
86
+
87
+
88
+
89
+ /**
90
+ * Public functions
91
+ */
92
+ MagnificPopup.prototype = {
93
+
94
+ constructor: MagnificPopup,
95
+
96
+ /**
97
+ * Initializes Magnific Popup plugin.
98
+ * This function is triggered only once when $.fn.magnificPopup or $.magnificPopup is executed
99
+ */
100
+ init: function() {
101
+ var appVersion = navigator.appVersion;
102
+ mfp.isIE7 = appVersion.indexOf("MSIE 7.") !== -1;
103
+ mfp.isAndroid = (/android/gi).test(appVersion);
104
+ mfp.isIOS = (/iphone|ipad|ipod/gi).test(appVersion);
105
+
106
+ // We disable fixed positioned lightbox on devices that don't handle it nicely.
107
+ // If you know a better way of detecting this - let me know.
108
+ mfp.probablyMobile = (mfp.isAndroid || mfp.isIOS || /(Opera Mini)|Kindle|webOS|BlackBerry|(Opera Mobi)|(Windows Phone)|IEMobile/i.test(navigator.userAgent) );
109
+ _body = $(document.body);
110
+ _document = $(document);
111
+
112
+ mfp.popupsCache = {};
113
+ },
114
+
115
+ /**
116
+ * Opens popup
117
+ * @param data [description]
118
+ */
119
+ open: function(data) {
120
+
121
+ if(mfp.isOpen) return;
122
+
123
+ var i;
124
+
125
+ mfp.types = [];
126
+ _wrapClasses = '';
127
+
128
+ mfp.ev = data.el || _document;
129
+
130
+ if(data.isObj) {
131
+ mfp.index = data.index || 0;
132
+ } else {
133
+ mfp.index = 0;
134
+ var items = data.items,
135
+ item;
136
+ for(i = 0; i < items.length; i++) {
137
+ item = items[i];
138
+ if(item.parsed) {
139
+ item = item.el[0];
140
+ }
141
+ if(item === data.el[0]) {
142
+ mfp.index = i;
143
+ break;
144
+ }
145
+ }
146
+ }
147
+
148
+
149
+ if(data.key) {
150
+ if(!mfp.popupsCache[data.key]) {
151
+ mfp.popupsCache[data.key] = {};
152
+ }
153
+ mfp.currTemplate = mfp.popupsCache[data.key];
154
+ } else {
155
+ mfp.currTemplate = {};
156
+ }
157
+
158
+
159
+
160
+ mfp.st = $.extend(true, {}, $.magnificPopup.defaults, data );
161
+ mfp.fixedContentPos = mfp.st.fixedContentPos === 'auto' ? !mfp.probablyMobile : mfp.st.fixedContentPos;
162
+
163
+ mfp.items = data.items.length ? data.items : [data.items];
164
+
165
+ // Building markup
166
+ // main containers are created only once
167
+ if(!mfp.bgOverlay) {
168
+
169
+ // Dark overlay
170
+ mfp.bgOverlay = _getEl('bg').on('click'+EVENT_NS, function() {
171
+ mfp.close();
172
+ });
173
+
174
+ mfp.wrap = _getEl('wrap').attr('tabindex', -1).on('click'+EVENT_NS, function(e) {
175
+
176
+ var target = e.target;
177
+ if($(target).hasClass(PREVENT_CLOSE_CLASS)) {
178
+ return;
179
+ }
180
+
181
+ if(mfp.st.closeOnContentClick) {
182
+ mfp.close();
183
+ } else {
184
+ // close popup if click is not on a content, on close button, or content does not exist
185
+ if( !mfp.content ||
186
+ $(target).hasClass('mfp-close') ||
187
+ (mfp.preloader && e.target === mfp.preloader[0]) ||
188
+ (target !== mfp.content[0] && !$.contains(mfp.content[0], target)) ) {
189
+ mfp.close();
190
+ }
191
+ }
192
+ });
193
+
194
+ mfp.container = _getEl('container', mfp.wrap);
195
+ }
196
+ if(mfp.st.preloader) {
197
+ mfp.preloader = _getEl('preloader', mfp.container, mfp.st.tLoading);
198
+ }
199
+ mfp.contentContainer = _getEl('content', mfp.container);
200
+
201
+
202
+
203
+ // Initializing modules
204
+ var modules = $.magnificPopup.modules;
205
+ for(i = 0; i < modules.length; i++) {
206
+ var n = modules[i];
207
+ n = n.charAt(0).toUpperCase() + n.slice(1);
208
+ mfp['init'+n].call(mfp);
209
+ }
210
+ _mfpTrigger('BeforeOpen');
211
+
212
+
213
+ // Close button
214
+ if(!mfp.st.closeBtnInside) {
215
+ mfp.wrap.append( _getCloseBtn() );
216
+ } else {
217
+ _mfpOn(MARKUP_PARSE_EVENT, function(e, template, values, item) {
218
+ values.close_replaceWith = _getCloseBtn(item.type);
219
+ });
220
+ _wrapClasses += ' mfp-close-btn-in';
221
+ }
222
+
223
+ if(mfp.st.alignTop) {
224
+ _wrapClasses += ' mfp-align-top';
225
+ }
226
+
227
+
228
+
229
+ if(mfp.fixedContentPos) {
230
+ mfp.wrap.css({
231
+ overflow: mfp.st.overflowY,
232
+ overflowX: 'hidden',
233
+ overflowY: mfp.st.overflowY
234
+ });
235
+ } else {
236
+ mfp.wrap.css({
237
+ top: _window.scrollTop(),
238
+ position: 'absolute'
239
+ });
240
+ }
241
+ if( mfp.st.fixedBgPos === false || (mfp.st.fixedBgPos === 'auto' && !mfp.fixedContentPos) ) {
242
+ mfp.bgOverlay.css({
243
+ height: _document.height(),
244
+ position: 'absolute'
245
+ });
246
+ }
247
+
248
+
249
+
250
+ // Close on ESC key
251
+ _document.on('keyup' + EVENT_NS, function(e) {
252
+ if(e.keyCode === 27) {
253
+ mfp.close();
254
+ }
255
+ });
256
+
257
+ _window.on('resize' + EVENT_NS, function() {
258
+ mfp.updateSize();
259
+ });
260
+
261
+
262
+ if(!mfp.st.closeOnContentClick) {
263
+ _wrapClasses += ' mfp-auto-cursor';
264
+ }
265
+
266
+ if(_wrapClasses)
267
+ mfp.wrap.addClass(_wrapClasses);
268
+
269
+
270
+ // this triggers recalculation of layout, so we get it once to not to trigger twice
271
+ var windowHeight = mfp.wH = _window.height();
272
+
273
+
274
+ var bodyStyles = {};
275
+
276
+ if( mfp.fixedContentPos ) {
277
+ var s = mfp._getScrollbarSize();
278
+ if(s) {
279
+ bodyStyles.paddingRight = s;
280
+ }
281
+ }
282
+
283
+ if(mfp.fixedContentPos) {
284
+ if(!mfp.isIE7) {
285
+ bodyStyles.overflow = 'hidden';
286
+ } else {
287
+ // ie7 double-scroll bug
288
+ $('body, html').css('overflow', 'hidden');
289
+ }
290
+ }
291
+
292
+
293
+
294
+ var classesToadd = mfp.st.mainClass;
295
+ if(mfp.isIE7) {
296
+ classesToadd += ' mfp-ie7';
297
+ }
298
+ if(classesToadd) {
299
+ mfp._addClassToMFP( classesToadd );
300
+ }
301
+
302
+ // add content
303
+ mfp.updateItemHTML();
304
+
305
+ // remove scrollbar, add padding e.t.c
306
+
307
+
308
+
309
+ _body.css(bodyStyles);
310
+
311
+ // add everything to DOM
312
+ mfp.bgOverlay.add(mfp.wrap).prependTo( document.body );
313
+
314
+
315
+
316
+ // Save last focused element
317
+ mfp._lastFocusedEl = document.activeElement;
318
+
319
+ // Wait for next cycle to allow CSS transition
320
+ setTimeout(function() {
321
+
322
+ if(mfp.content) {
323
+ mfp._addClassToMFP(READY_CLASS);
324
+ _setFocus();
325
+ } else {
326
+ // if content is not defined (not loaded e.t.c) we add class only for BG
327
+ mfp.bgOverlay.addClass(READY_CLASS);
328
+ }
329
+
330
+ // Trap the focus in popup
331
+ _document.on('focusin' + EVENT_NS, function (e) {
332
+ if( e.target !== mfp.wrap[0] && !$.contains(mfp.wrap[0], e.target) ) {
333
+ _setFocus();
334
+ return false;
335
+ }
336
+ });
337
+
338
+ }, 16);
339
+
340
+ mfp.isOpen = true;
341
+ mfp.updateSize(windowHeight);
342
+ _mfpTrigger(OPEN_EVENT);
343
+ },
344
+
345
+ /**
346
+ * Closes the popup
347
+ */
348
+ close: function() {
349
+ if(!mfp.isOpen) return;
350
+
351
+ mfp.isOpen = false;
352
+ // for CSS3 animation
353
+ if(mfp.st.removalDelay) {
354
+ mfp._addClassToMFP(REMOVING_CLASS);
355
+ setTimeout(function() {
356
+ mfp._close();
357
+ }, mfp.st.removalDelay);
358
+ } else {
359
+ mfp._close();
360
+ }
361
+ },
362
+
363
+ /**
364
+ * Helper for close() function
365
+ */
366
+ _close: function() {
367
+ _mfpTrigger(CLOSE_EVENT);
368
+
369
+ var classesToRemove = REMOVING_CLASS + ' ' + READY_CLASS + ' ';
370
+
371
+ mfp.bgOverlay.detach();
372
+ mfp.wrap.detach();
373
+ mfp.container.empty();
374
+
375
+ if(mfp.st.mainClass) {
376
+ classesToRemove += mfp.st.mainClass + ' ';
377
+ }
378
+
379
+ mfp._removeClassFromMFP(classesToRemove);
380
+
381
+ if(mfp.fixedContentPos) {
382
+ var bodyStyles = {paddingRight: 0};
383
+ if(mfp.isIE7) {
384
+ $('body, html').css('overflow', 'auto');
385
+ } else {
386
+ bodyStyles.overflow = 'visible';
387
+ }
388
+ _body.css(bodyStyles);
389
+ }
390
+
391
+ _document.off('keyup' + EVENT_NS + ' focusin' + EVENT_NS);
392
+ mfp.ev.off(EVENT_NS);
393
+
394
+ // clean up DOM elements that aren't removed
395
+ mfp.wrap.attr('class', 'mfp-wrap').removeAttr('style');
396
+ mfp.bgOverlay.attr('class', 'mfp-bg');
397
+ mfp.container.attr('class', 'mfp-container');
398
+
399
+ // remove close button from target element
400
+ if(!mfp.st.closeBtnInside || mfp.currTemplate[mfp.currItem.type] === true ) {
401
+ if(mfp.currTemplate.closeBtn)
402
+ mfp.currTemplate.closeBtn.detach();
403
+ }
404
+
405
+
406
+ if(mfp._lastFocusedEl) {
407
+ $(mfp._lastFocusedEl).focus(); // put tab focus back
408
+ }
409
+ mfp.currTemplate = null;
410
+ mfp.prevHeight = 0;
411
+ },
412
+
413
+ updateSize: function(winHeight) {
414
+
415
+ if(mfp.isIOS) {
416
+ // fixes iOS nav bars https://github.com/dimsemenov/Magnific-Popup/issues/2
417
+ var zoomLevel = document.documentElement.clientWidth / window.innerWidth;
418
+ var height = window.innerHeight * zoomLevel;
419
+ mfp.wrap.css('height', height);
420
+ mfp.wH = height;
421
+ } else {
422
+ mfp.wH = winHeight || _window.height();
423
+ }
424
+
425
+ _mfpTrigger('Resize');
426
+
427
+ },
428
+
429
+
430
+ /**
431
+ * Set content of popup based on current index
432
+ */
433
+ updateItemHTML: function() {
434
+ var item = mfp.items[mfp.index];
435
+
436
+ if(!item.parsed) {
437
+ item = mfp.parseEl( mfp.index );
438
+ }
439
+
440
+ mfp.currItem = item;
441
+
442
+ var type = item.type;
443
+ if(!mfp.currTemplate[type]) {
444
+ var markup = mfp.st[type] ? mfp.st[type].markup : false;
445
+ if(markup) {
446
+ _mfpTrigger('FirstMarkupParse', markup);
447
+ mfp.currTemplate[type] = $(markup);
448
+ } else {
449
+ // if there is no markup found we just define that template is parsed
450
+ mfp.currTemplate[type] = true;
451
+ }
452
+ }
453
+
454
+ if(_prevContentType && _prevContentType !== item.type) {
455
+ mfp.container.removeClass('mfp-'+_prevContentType+'-holder');
456
+ }
457
+
458
+ var newContent = mfp['get' + type.charAt(0).toUpperCase() + type.slice(1)](item, mfp.currTemplate[type]);
459
+ mfp.appendContent(newContent, type);
460
+
461
+ item.preloaded = true;
462
+
463
+ _mfpTrigger(CHANGE_EVENT, item);
464
+ _prevContentType = item.type;
465
+ },
466
+
467
+
468
+ /**
469
+ * Set HTML content of popup
470
+ */
471
+ appendContent: function(newContent, type) {
472
+ mfp.content = newContent;
473
+
474
+ if(newContent) {
475
+ if(mfp.st.closeBtnInside && mfp.currTemplate[type] === true) {
476
+ // if there is no markup, we just append close button element inside
477
+ if(!mfp.content.find('.mfp-close').length) {
478
+ mfp.content.append(_getCloseBtn());
479
+ }
480
+ } else {
481
+ mfp.content = newContent;
482
+ }
483
+ } else {
484
+ mfp.content = '';
485
+ }
486
+
487
+ _mfpTrigger(BEFORE_APPEND_EVENT);
488
+ mfp.container.addClass('mfp-'+type+'-holder');
489
+
490
+ mfp.contentContainer.html(mfp.content);
491
+ },
492
+
493
+
494
+
495
+
496
+ /**
497
+ * Creates Magnific Popup data object based on given data
498
+ * @param {int} index Index of item to parse
499
+ */
500
+ parseEl: function(index) {
501
+ var item = mfp.items[index],
502
+ type = item.type;
503
+
504
+
505
+ if(item.tagName) {
506
+ item = { el: $(item) };
507
+ } else {
508
+ item = { data: item, src: item.src };
509
+ }
510
+
511
+ if(item.el) {
512
+ var types = mfp.types;
513
+
514
+ // check for 'mfp-TYPE' class
515
+ for(var i = 0; i < types.length; i++) {
516
+ if( item.el.hasClass('mfp-'+types[i]) ) {
517
+ type = types[i];
518
+ break;
519
+ }
520
+ }
521
+
522
+ item.src = item.el.attr('data-mfp-src');
523
+ if(!item.src) {
524
+ item.src = item.el.attr('href');
525
+ }
526
+ }
527
+
528
+ item.type = type || mfp.st.type;
529
+ item.index = index;
530
+ item.parsed = true;
531
+ mfp.items[index] = item;
532
+ _mfpTrigger('ElementParse', item);
533
+
534
+ return mfp.items[index];
535
+ },
536
+
537
+
538
+ /**
539
+ * Initializes single popup or a group of popups
540
+ */
541
+ addGroup: function(el, options) {
542
+ var eHandler = function(e) {
543
+
544
+ var midClick = options.midClick !== undefined ? options.midClick : $.magnificPopup.defaults.midClick;
545
+ if( midClick || e.which !== 2 ) {
546
+ var disableOn = options.disableOn !== undefined ? options.disableOn : $.magnificPopup.defaults.disableOn;
547
+
548
+ if(disableOn) {
549
+ if($.isFunction(disableOn)) {
550
+ if( !disableOn.call(mfp) ) {
551
+ return true;
552
+ }
553
+ } else { // else it's number
554
+ if( $(window).width() < disableOn ) {
555
+ return true;
556
+ }
557
+ }
558
+ }
559
+
560
+ e.preventDefault();
561
+ options.el = $(this);
562
+ mfp.open(options);
563
+ }
564
+
565
+ };
566
+
567
+ if(!options) {
568
+ options = {};
569
+ }
570
+
571
+ var eName = 'click.magnificPopup';
572
+ if(options.items) {
573
+ options.isObj = true;
574
+ el.off(eName).on(eName, eHandler);
575
+ } else {
576
+ options.isObj = false;
577
+ if(options.delegate) {
578
+ options.items = el.find(options.delegate);
579
+ el.off(eName).on(eName, options.delegate , eHandler);
580
+ } else {
581
+ options.items = el;
582
+ el.off(eName).on(eName, eHandler);
583
+ }
584
+ }
585
+ },
586
+
587
+
588
+ /**
589
+ * Updates text on preloader
590
+ */
591
+ updateStatus: function(status, text) {
592
+
593
+ if(mfp.preloader) {
594
+ if(_prevStatus !== status) {
595
+ mfp.container.removeClass('mfp-s-'+_prevStatus);
596
+ }
597
+
598
+ if(!text && status === 'loading') {
599
+ text = mfp.st.tLoading;
600
+ }
601
+
602
+ var data = {
603
+ status: status,
604
+ text: text
605
+ };
606
+ // allows to modify status
607
+ _mfpTrigger('UpdateStatus', data);
608
+
609
+ status = data.status;
610
+ text = data.text;
611
+
612
+ mfp.preloader.html(text);
613
+
614
+ mfp.preloader.find('a').click(function(e) {
615
+ e.stopImmediatePropagation();
616
+ });
617
+
618
+ mfp.container.addClass('mfp-s-'+status);
619
+ _prevStatus = status;
620
+ }
621
+ },
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+ /*
632
+ "Private" helpers that aren't private at all
633
+ */
634
+ _addClassToMFP: function(cName) {
635
+ mfp.bgOverlay.addClass(cName);
636
+ mfp.wrap.addClass(cName);
637
+ },
638
+ _removeClassFromMFP: function(cName) {
639
+ this.bgOverlay.removeClass(cName);
640
+ mfp.wrap.removeClass(cName);
641
+ },
642
+ _hasScrollBar: function(winHeight) {
643
+ if(document.body.clientHeight > (winHeight || _window.height()) ) {
644
+ return true;
645
+ }
646
+ return false;
647
+ },
648
+
649
+ _parseMarkup: function(template, values, item) {
650
+ var arr;
651
+ if(item.data) {
652
+ values = $.extend(item.data, values);
653
+ }
654
+ _mfpTrigger(MARKUP_PARSE_EVENT, [template, values, item] );
655
+
656
+ $.each(values, function(key, value) {
657
+ if(value === undefined || value === false) {
658
+ return true;
659
+ }
660
+ arr = key.split('_');
661
+ if(arr.length > 1) {
662
+ var el = template.find(EVENT_NS + '-'+arr[0]);
663
+
664
+ if(el.length > 0) {
665
+ var attr = arr[1];
666
+ if(attr === 'replaceWith') {
667
+ if(el[0] !== value[0]) {
668
+ el.replaceWith(value);
669
+ }
670
+ } else if(attr === 'img') {
671
+ if(el.is('img')) {
672
+ el.attr('src', value);
673
+ } else {
674
+ el.replaceWith( '<img src="'+value+'" class="' + el.attr('class') + '" />' );
675
+ }
676
+ } else {
677
+ el.attr(arr[1], value);
678
+ }
679
+ }
680
+
681
+ } else {
682
+ template.find(EVENT_NS + '-'+key).html(value);
683
+ }
684
+ });
685
+ },
686
+
687
+ _getScrollbarSize: function() {
688
+ // thx David
689
+ if(mfp.scrollbarSize === undefined) {
690
+ var scrollDiv = document.createElement("div");
691
+ scrollDiv.id = "mfp-sbm";
692
+ scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;';
693
+ document.body.appendChild(scrollDiv);
694
+ mfp.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth;
695
+ document.body.removeChild(scrollDiv);
696
+ }
697
+ return mfp.scrollbarSize;
698
+ }
699
+
700
+ }; /* MagnificPopup core prototype end */
701
+
702
+
703
+
704
+
705
+ /**
706
+ * Public static functions
707
+ */
708
+ $.magnificPopup = {
709
+ instance: null,
710
+ proto: MagnificPopup.prototype,
711
+ modules: [],
712
+
713
+ open: function(options, index) {
714
+ if(!$.magnificPopup.instance) {
715
+ mfp = new MagnificPopup();
716
+ mfp.init();
717
+ $.magnificPopup.instance = mfp;
718
+ }
719
+
720
+ if(!options) {
721
+ options = {};
722
+ }
723
+
724
+ options.isObj = true;
725
+ options.index = index === undefined ? 0 : index;
726
+ return this.instance.open(options);
727
+ },
728
+
729
+ close: function() {
730
+ return $.magnificPopup.instance.close();
731
+ },
732
+
733
+ registerModule: function(name, module) {
734
+ if(module.options) {
735
+ $.magnificPopup.defaults[name] = module.options;
736
+ }
737
+ $.extend(this.proto, module.proto);
738
+ this.modules.push(name);
739
+ },
740
+
741
+ defaults: {
742
+
743
+ // Info about options is docs:
744
+ // http://dimsemenov.com/plugins/magnific-popup/documentation.html#options
745
+
746
+ disableOn: 0,
747
+
748
+ key: null,
749
+
750
+ midClick: false,
751
+
752
+ mainClass: '',
753
+
754
+ preloader: true,
755
+
756
+ focus: '', // CSS selector of input to focus after popup is opened
757
+
758
+ closeOnContentClick: false,
759
+
760
+ closeBtnInside: true,
761
+
762
+ alignTop: false,
763
+
764
+ removalDelay: 0,
765
+
766
+ fixedContentPos: 'auto',
767
+
768
+ fixedBgPos: 'auto',
769
+
770
+ overflowY: 'auto',
771
+
772
+ closeMarkup: '<button title="%title%" type="button" class="mfp-close">&times;</button>',
773
+
774
+ tClose: 'Close (Esc)',
775
+
776
+ tLoading: 'Loading...'
777
+
778
+ }
779
+ };
780
+
781
+
782
+
783
+ $.fn.magnificPopup = function(options) {
784
+ // Initialize Magnific Popup only when called at least once
785
+ if(!$.magnificPopup.instance) {
786
+ mfp = new MagnificPopup();
787
+ mfp.init();
788
+ $.magnificPopup.instance = mfp;
789
+ }
790
+
791
+ mfp.addGroup($(this), options);
792
+ return $(this);
793
+ };
794
+
795
+
796
+ //Quick benchmark
797
+ /*
798
+ var start = performance.now(),
799
+ i,
800
+ rounds = 1000;
801
+
802
+ for(i = 0; i < rounds; i++) {
803
+
804
+ }
805
+ console.log('Test #1:', performance.now() - start);
806
+
807
+ start = performance.now();
808
+ for(i = 0; i < rounds; i++) {
809
+
810
+ }
811
+ console.log('Test #2:', performance.now() - start);
812
+ */
813
+
814
+ /*>>core*/
815
+
816
+ /*>>inline*/
817
+
818
+ var INLINE_NS = 'inline',
819
+ _hasPlaceholder;
820
+
821
+ $.magnificPopup.registerModule(INLINE_NS, {
822
+ options: {
823
+ hiddenClass: NS+'-hide',
824
+ markup: '',
825
+ tNotFound: 'Content not found'
826
+ },
827
+ proto: {
828
+
829
+ initInline: function() {
830
+ mfp.types.push(INLINE_NS);
831
+ _hasPlaceholder = false;
832
+
833
+ _mfpOn(CLOSE_EVENT+'.'+INLINE_NS, function() {
834
+ var item = mfp.currItem;
835
+ if(item.type === INLINE_NS) {
836
+ if(_hasPlaceholder) {
837
+ for(var i = 0; i < mfp.items.length; i++) {
838
+ item = mfp.items[i];
839
+ if(item && item.inlinePlaceholder){
840
+ item.inlinePlaceholder.after( item.inlineElement.addClass(mfp.st.inline.hiddenClass) ).detach();
841
+ }
842
+ }
843
+ }
844
+ item.inlinePlaceholder = item.inlineElement = null;
845
+ }
846
+ });
847
+ },
848
+
849
+ getInline: function(item, template) {
850
+ mfp.updateStatus('ready');
851
+
852
+ if(item.src) {
853
+ var inlineSt = mfp.st.inline;
854
+ // items.src can be String-CSS-selector or jQuery element
855
+ if(typeof item.src !== 'string') {
856
+ item.isElement = true;
857
+ }
858
+
859
+ if(!item.isElement && !item.inlinePlaceholder) {
860
+ item.inlinePlaceholder = _getEl(inlineSt.hiddenClass);
861
+ }
862
+
863
+ if(item.isElement) {
864
+ item.inlineElement = item.src;
865
+ } else if(!item.inlineElement) {
866
+ item.inlineElement = $(item.src);
867
+ if(!item.inlineElement.length) {
868
+ mfp.updateStatus('error', inlineSt.tNotFound);
869
+ item.inlineElement = $('<div>');
870
+ }
871
+ }
872
+
873
+ if(item.inlinePlaceholder) {
874
+ _hasPlaceholder = true;
875
+ }
876
+
877
+
878
+
879
+ item.inlineElement.after(item.inlinePlaceholder).detach().removeClass(inlineSt.hiddenClass);
880
+ return item.inlineElement;
881
+ } else {
882
+ mfp._parseMarkup(template, {}, item);
883
+ return template;
884
+ }
885
+ }
886
+ }
887
+ });
888
+
889
+ /*>>inline*/
890
+
891
+ /*>>ajax*/
892
+ var AJAX_NS = 'ajax',
893
+ _ajaxCur,
894
+ _removeAjaxCursor = function() {
895
+ if(_ajaxCur) {
896
+ _body.removeClass(_ajaxCur);
897
+ }
898
+ };
899
+
900
+ $.magnificPopup.registerModule(AJAX_NS, {
901
+
902
+ options: {
903
+ settings: null,
904
+ cursor: 'mfp-ajax-cur',
905
+ tError: '<a href="%url%">The content</a> could not be loaded.'
906
+ },
907
+
908
+ proto: {
909
+ initAjax: function() {
910
+ mfp.types.push(AJAX_NS);
911
+ _ajaxCur = mfp.st.ajax.cursor;
912
+
913
+ _mfpOn(CLOSE_EVENT+'.'+AJAX_NS, function() {
914
+ _removeAjaxCursor();
915
+ if(mfp.req) {
916
+ mfp.req.abort();
917
+ }
918
+ });
919
+ },
920
+
921
+ getAjax: function(item) {
922
+
923
+ if(_ajaxCur)
924
+ _body.addClass(_ajaxCur);
925
+
926
+ mfp.updateStatus('loading');
927
+
928
+ var opts = $.extend({
929
+ url: item.src,
930
+ success: function(data, textStatus, jqXHR) {
931
+
932
+ _mfpTrigger('ParseAjax', jqXHR);
933
+
934
+ mfp.appendContent( $(jqXHR.responseText), AJAX_NS );
935
+
936
+ item.finished = true;
937
+
938
+ _removeAjaxCursor();
939
+
940
+ _setFocus();
941
+
942
+ setTimeout(function() {
943
+ mfp.wrap.addClass(READY_CLASS);
944
+ }, 16);
945
+
946
+ mfp.updateStatus('ready');
947
+
948
+ },
949
+ error: function() {
950
+ _removeAjaxCursor();
951
+ item.finished = item.loadError = true;
952
+ mfp.updateStatus('error', mfp.st.ajax.tError.replace('%url%', item.src));
953
+ }
954
+ }, mfp.st.ajax.settings);
955
+
956
+ mfp.req = $.ajax(opts);
957
+
958
+ return '';
959
+ }
960
+ }
961
+ });
962
+
963
+
964
+
965
+
966
+
967
+
968
+
969
+ /*>>ajax*/
970
+
971
+ /*>>image*/
972
+ var _imgInterval,
973
+ _getTitle = function(item) {
974
+ if(item.data && item.data.title !== undefined)
975
+ return item.data.title;
976
+
977
+ var src = mfp.st.image.titleSrc;
978
+
979
+ if(src) {
980
+ if($.isFunction(src)) {
981
+ return src.call(mfp, item);
982
+ } else if(item.el) {
983
+ return item.el.attr(src) || '';
984
+ }
985
+ }
986
+ return '';
987
+ };
988
+
989
+ $.magnificPopup.registerModule('image', {
990
+
991
+ options: {
992
+ markup: '<div class="mfp-figure">'+
993
+ '<div class="mfp-close"></div>'+
994
+ '<div class="mfp-img"></div>'+
995
+ '<div class="mfp-bottom-bar">'+
996
+ '<div class="mfp-title"></div>'+
997
+ '<div class="mfp-counter"></div>'+
998
+ '</div>'+
999
+ '</div>',
1000
+ cursor: 'mfp-zoom-out-cur',
1001
+ titleSrc: 'title',
1002
+ verticalFit: true,
1003
+ tError: '<a href="%url%">The image</a> could not be loaded.'
1004
+ },
1005
+
1006
+ proto: {
1007
+ initImage: function() {
1008
+ var imgSt = mfp.st.image,
1009
+ ns = '.image';
1010
+
1011
+ mfp.types.push('image');
1012
+
1013
+ _mfpOn(OPEN_EVENT+ns, function() {
1014
+ if(mfp.currItem.type === 'image' && imgSt.cursor) {
1015
+ _body.addClass(imgSt.cursor);
1016
+ }
1017
+ });
1018
+
1019
+ _mfpOn(CLOSE_EVENT+ns, function() {
1020
+ if(imgSt.cursor) {
1021
+ _body.removeClass(imgSt.cursor);
1022
+ }
1023
+ _window.off('resize' + EVENT_NS);
1024
+ });
1025
+
1026
+ _mfpOn('Resize'+ns, function() {
1027
+ mfp.resizeImage();
1028
+ });
1029
+ },
1030
+ resizeImage: function() {
1031
+ var item = mfp.currItem;
1032
+ if(!item.img) return;
1033
+ if(mfp.st.image.verticalFit) {
1034
+ item.img.css('max-height', mfp.wH + 'px');
1035
+ }
1036
+ },
1037
+ _onImageHasSize: function(item) {
1038
+ if(item.img) {
1039
+
1040
+ item.hasSize = true;
1041
+
1042
+ if(_imgInterval) {
1043
+ clearInterval(_imgInterval);
1044
+ }
1045
+
1046
+ item.isCheckingImgSize = false;
1047
+
1048
+ _mfpTrigger('ImageHasSize', item);
1049
+
1050
+ if(item.imgHidden) {
1051
+ mfp.content.removeClass('mfp-loading');
1052
+ item.imgHidden = false;
1053
+ }
1054
+
1055
+ }
1056
+ },
1057
+
1058
+ /**
1059
+ * Function that loops until the image has size to display elements that rely on it asap
1060
+ */
1061
+ findImageSize: function(item) {
1062
+
1063
+ var counter = 0,
1064
+ img = item.img[0],
1065
+ mfpSetInterval = function(delay) {
1066
+
1067
+ if(_imgInterval) {
1068
+ clearInterval(_imgInterval);
1069
+ }
1070
+ // decelerating interval that checks for size of an image
1071
+ _imgInterval = setInterval(function() {
1072
+ if(img.naturalWidth > 0) {
1073
+ mfp._onImageHasSize(item);
1074
+ return;
1075
+ }
1076
+
1077
+ if(counter > 200) {
1078
+ clearInterval(_imgInterval);
1079
+ }
1080
+
1081
+ counter++;
1082
+ if(counter === 3) {
1083
+ mfpSetInterval(10);
1084
+ } else if(counter === 40) {
1085
+ mfpSetInterval(50);
1086
+ } else if(counter === 100) {
1087
+ mfpSetInterval(500);
1088
+ }
1089
+ }, delay);
1090
+ };
1091
+
1092
+ mfpSetInterval(1);
1093
+ },
1094
+
1095
+ getImage: function(item, template) {
1096
+
1097
+ var guard = 0,
1098
+
1099
+ // image load complete handler
1100
+ onLoadComplete = function() {
1101
+ if(item) {
1102
+ if (item.img[0].complete) {
1103
+ item.img.off('.mfploader');
1104
+
1105
+ if(item === mfp.currItem){
1106
+ mfp._onImageHasSize(item);
1107
+
1108
+ mfp.updateStatus('ready');
1109
+ }
1110
+
1111
+ item.hasSize = true;
1112
+ item.loaded = true;
1113
+
1114
+ }
1115
+ else {
1116
+ // if image complete check fails 200 times (20 sec), we assume that there was an error.
1117
+ guard++;
1118
+ if(guard < 200) {
1119
+ setTimeout(onLoadComplete,100);
1120
+ } else {
1121
+ onLoadError();
1122
+ }
1123
+ }
1124
+ }
1125
+ },
1126
+
1127
+ // image error handler
1128
+ onLoadError = function() {
1129
+ if(item) {
1130
+ item.img.off('.mfploader');
1131
+ if(item === mfp.currItem){
1132
+ mfp._onImageHasSize(item);
1133
+ mfp.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
1134
+ }
1135
+
1136
+ item.hasSize = true;
1137
+ item.loaded = true;
1138
+ item.loadError = true;
1139
+ }
1140
+ },
1141
+ imgSt = mfp.st.image;
1142
+
1143
+
1144
+ var el = template.find('.mfp-img');
1145
+ if(el.length) {
1146
+ var img = new Image();
1147
+ img.className = 'mfp-img';
1148
+ item.img = $(img).on('load.mfploader', onLoadComplete).on('error.mfploader', onLoadError);
1149
+ img.src = item.src;
1150
+
1151
+ // without clone() "error" event is not firing when IMG is replaced by new IMG
1152
+ // TODO: find a way to avoid such cloning
1153
+ if(el.is('img')) {
1154
+ item.img = item.img.clone();
1155
+ }
1156
+ }
1157
+
1158
+ mfp._parseMarkup(template, {
1159
+ title: _getTitle(item),
1160
+ img_replaceWith: item.img
1161
+ }, item);
1162
+
1163
+ mfp.resizeImage();
1164
+
1165
+ if(item.hasSize) {
1166
+ if(_imgInterval) clearInterval(_imgInterval);
1167
+
1168
+ if(item.loadError) {
1169
+ template.addClass('mfp-loading');
1170
+ mfp.updateStatus('error', imgSt.tError.replace('%url%', item.src) );
1171
+ } else {
1172
+ template.removeClass('mfp-loading');
1173
+ mfp.updateStatus('ready');
1174
+ }
1175
+ return template;
1176
+ }
1177
+
1178
+ mfp.updateStatus('loading');
1179
+ item.loading = true;
1180
+
1181
+ if(!item.hasSize) {
1182
+ item.imgHidden = true;
1183
+ template.addClass('mfp-loading');
1184
+ mfp.findImageSize(item);
1185
+ }
1186
+
1187
+ return template;
1188
+ }
1189
+ }
1190
+ });
1191
+
1192
+
1193
+
1194
+ /*>>image*/
1195
+
1196
+ /*>>iframe*/
1197
+
1198
+ var IFRAME_NS = 'iframe',
1199
+
1200
+ // IE black screen bug fix
1201
+ toggleIframeInIE = function(show) {
1202
+ if(mfp.isIE7 && mfp.currItem && mfp.currItem.type === IFRAME_NS) {
1203
+ var el = mfp.content.find('iframe');
1204
+ if(el.length) {
1205
+ el.css('display', show ? 'block' : 'none');
1206
+ }
1207
+ }
1208
+ };
1209
+
1210
+ $.magnificPopup.registerModule(IFRAME_NS, {
1211
+
1212
+ options: {
1213
+ markup: '<div class="mfp-iframe-scaler">'+
1214
+ '<div class="mfp-close"></div>'+
1215
+ '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
1216
+ '</div>',
1217
+
1218
+ srcAction: 'iframe_src',
1219
+
1220
+ // we don't care and support only one default type of URL by default
1221
+ patterns: {
1222
+ youtube: {
1223
+ index: 'youtube.com',
1224
+ id: 'v=',
1225
+ src: '//www.youtube.com/embed/%id%?autoplay=1'
1226
+ },
1227
+ vimeo: {
1228
+ index: 'vimeo.com/',
1229
+ id: '/',
1230
+ src: '//player.vimeo.com/video/%id%?autoplay=1'
1231
+ },
1232
+ gmaps: {
1233
+ index: '//maps.google.',
1234
+ src: '%id%&output=embed'
1235
+ }
1236
+ }
1237
+ },
1238
+
1239
+ proto: {
1240
+ initIframe: function() {
1241
+ mfp.types.push(IFRAME_NS);
1242
+ toggleIframeInIE(true);
1243
+ _mfpOn(CLOSE_EVENT + '.' + IFRAME_NS, function() {
1244
+ toggleIframeInIE();
1245
+ });
1246
+ },
1247
+
1248
+ getIframe: function(item, template) {
1249
+ var embedSrc = item.src;
1250
+ var iframeSt = mfp.st.iframe;
1251
+
1252
+ $.each(iframeSt.patterns, function() {
1253
+ if(embedSrc.indexOf( this.index ) > -1) {
1254
+ if(this.id) {
1255
+ if(typeof this.id === 'string') {
1256
+ embedSrc = embedSrc.substr(embedSrc.lastIndexOf(this.id)+this.id.length, embedSrc.length);
1257
+ } else {
1258
+ embedSrc = this.id.call( this, embedSrc );
1259
+ }
1260
+ }
1261
+ embedSrc = this.src.replace('%id%', embedSrc );
1262
+ return false; // break;
1263
+ }
1264
+ });
1265
+
1266
+ var dataObj = {};
1267
+ if(iframeSt.srcAction) {
1268
+ dataObj[iframeSt.srcAction] = embedSrc;
1269
+ }
1270
+ mfp._parseMarkup(template, dataObj, item);
1271
+
1272
+ mfp.updateStatus('ready');
1273
+
1274
+ return template;
1275
+ }
1276
+ }
1277
+ });
1278
+
1279
+
1280
+
1281
+ /*>>iframe*/
1282
+
1283
+ /*>>gallery*/
1284
+ /**
1285
+ * Get looped index depending on number of slides
1286
+ */
1287
+ var _getLoopedId = function(index) {
1288
+ var numSlides = mfp.items.length;
1289
+ if(index > numSlides - 1) {
1290
+ return index - numSlides;
1291
+ } else if(index < 0) {
1292
+ return numSlides + index;
1293
+ }
1294
+ return index;
1295
+ },
1296
+ _replaceCurrTotal = function(text, curr, total) {
1297
+ return text.replace('%curr%', curr + 1).replace('%total%', total);
1298
+ };
1299
+
1300
+ $.magnificPopup.registerModule('gallery', {
1301
+
1302
+ options: {
1303
+ enabled: false,
1304
+ arrowMarkup: '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',
1305
+ preload: [0,2],
1306
+ navigateByImgClick: true,
1307
+ arrows: true,
1308
+
1309
+ tPrev: 'Previous (Left arrow key)',
1310
+ tNext: 'Next (Right arrow key)',
1311
+ tCounter: '%curr% of %total%'
1312
+ },
1313
+
1314
+ proto: {
1315
+ initGallery: function() {
1316
+
1317
+ var gSt = mfp.st.gallery,
1318
+ ns = '.mfp-gallery',
1319
+ supportsFastClick = Boolean($.fn.mfpFastClick);
1320
+
1321
+ mfp.direction = true; // true - next, false - prev
1322
+
1323
+ if(!gSt || !gSt.enabled ) return false;
1324
+
1325
+ _wrapClasses += ' mfp-gallery';
1326
+
1327
+ _mfpOn(OPEN_EVENT+ns, function() {
1328
+
1329
+ if(gSt.navigateByImgClick) {
1330
+ mfp.wrap.on('click'+ns, '.mfp-img', function() {
1331
+ mfp.next();
1332
+ return false;
1333
+ });
1334
+ }
1335
+
1336
+ _document.on('keydown'+ns, function(e) {
1337
+ if (e.keyCode === 37) {
1338
+ mfp.prev();
1339
+ } else if (e.keyCode === 39) {
1340
+ mfp.next();
1341
+ }
1342
+ });
1343
+ });
1344
+
1345
+ _mfpOn('UpdateStatus'+ns, function(e, data) {
1346
+ if(data.text) {
1347
+ data.text = _replaceCurrTotal(data.text, mfp.currItem.index, mfp.items.length);
1348
+ }
1349
+ });
1350
+
1351
+ _mfpOn(MARKUP_PARSE_EVENT+ns, function(e, element, values, item) {
1352
+ var l = mfp.items.length;
1353
+ values.counter = l ? _replaceCurrTotal(gSt.tCounter, item.index, l) : '';
1354
+ });
1355
+
1356
+ _mfpOn(CHANGE_EVENT+ns, function() {
1357
+
1358
+ if(mfp._preloadTimeout) clearTimeout(mfp._preloadTimeout);
1359
+
1360
+ mfp._preloadTimeout = setTimeout(function() {
1361
+ mfp.preloadNearbyImages();
1362
+ mfp._preloadTimeout = null;
1363
+ }, 16);
1364
+
1365
+ if(gSt.arrows && !mfp.arrowLeft) {
1366
+
1367
+ var markup = gSt.arrowMarkup,
1368
+ arrowLeft = mfp.arrowLeft = $( markup.replace('%title%', gSt.tPrev).replace('%dir%', 'left') ).addClass(PREVENT_CLOSE_CLASS),
1369
+ arrowRight = mfp.arrowRight = $( markup.replace('%title%', gSt.tNext).replace('%dir%', 'right') ).addClass(PREVENT_CLOSE_CLASS);
1370
+
1371
+ var eName = supportsFastClick ? 'mfpFastClick' : 'click';
1372
+ arrowLeft[eName](function() {
1373
+ mfp.prev();
1374
+ });
1375
+ arrowRight[eName](function() {
1376
+ mfp.next();
1377
+ });
1378
+
1379
+ // Polyfill for :before and :after (adds elements with classes mfp-a and mfp-b)
1380
+ if(mfp.isIE7) {
1381
+ _getEl('b', arrowLeft[0], false, true);
1382
+ _getEl('a', arrowLeft[0], false, true);
1383
+ _getEl('b', arrowRight[0], false, true);
1384
+ _getEl('a', arrowRight[0], false, true);
1385
+ }
1386
+
1387
+ mfp.container.append(arrowLeft.add(arrowRight));
1388
+ }
1389
+ });
1390
+
1391
+
1392
+ _mfpOn(CLOSE_EVENT+ns, function() {
1393
+ _document.off(ns);
1394
+ mfp.wrap.off('click'+ns);
1395
+
1396
+ if(supportsFastClick) {
1397
+ mfp.arrowLeft.add(mfp.arrowRight).destroyMfpFastClick();
1398
+ }
1399
+ mfp.arrowRight = mfp.arrowLeft = null;
1400
+ });
1401
+
1402
+ },
1403
+ next: function() {
1404
+ mfp.direction = true;
1405
+ mfp.index = _getLoopedId(mfp.index + 1);
1406
+ mfp.updateItemHTML();
1407
+ },
1408
+ prev: function() {
1409
+ mfp.direction = false;
1410
+ mfp.index = _getLoopedId(mfp.index - 1);
1411
+ mfp.updateItemHTML();
1412
+ },
1413
+ preloadNearbyImages: function() {
1414
+ var p = mfp.st.gallery.preload,
1415
+ preloadBefore = Math.min(p[0], mfp.items.length),
1416
+ preloadAfter = Math.min(p[1], mfp.items.length),
1417
+ i;
1418
+
1419
+ for(i = 1; i <= (mfp.direction ? preloadAfter : preloadBefore); i++) {
1420
+ mfp._preloadItem(mfp.index+i);
1421
+ }
1422
+ for(i = 1; i <= (mfp.direction ? preloadBefore : preloadAfter); i++) {
1423
+ mfp._preloadItem(mfp.index-i);
1424
+ }
1425
+ },
1426
+ _preloadItem: function(index) {
1427
+ index = _getLoopedId(index);
1428
+
1429
+ if(mfp.items[index].preloaded) {
1430
+ return;
1431
+ }
1432
+
1433
+ var item = mfp.items[index];
1434
+ if(!item.parsed) {
1435
+ item = mfp.parseEl( index );
1436
+ }
1437
+
1438
+ _mfpTrigger('LazyLoad', item);
1439
+
1440
+ if(item.type === 'image') {
1441
+ item.img = $('<img class="mfp-img" />').on('load.mfploader', function() {
1442
+ item.hasSize = true;
1443
+ }).on('error.mfploader', function() {
1444
+ item.hasSize = true;
1445
+ item.loadError = true;
1446
+ }).attr('src', item.src);
1447
+ }
1448
+
1449
+
1450
+ item.preloaded = true;
1451
+ }
1452
+ }
1453
+ });
1454
+
1455
+ /*
1456
+ Touch Support that might be implemented some day
1457
+
1458
+ addSwipeGesture: function() {
1459
+ var startX,
1460
+ moved,
1461
+ multipleTouches;
1462
+
1463
+ return;
1464
+
1465
+ var namespace = '.mfp',
1466
+ addEventNames = function(pref, down, move, up, cancel) {
1467
+ mfp._tStart = pref + down + namespace;
1468
+ mfp._tMove = pref + move + namespace;
1469
+ mfp._tEnd = pref + up + namespace;
1470
+ mfp._tCancel = pref + cancel + namespace;
1471
+ };
1472
+
1473
+ if(window.navigator.msPointerEnabled) {
1474
+ addEventNames('MSPointer', 'Down', 'Move', 'Up', 'Cancel');
1475
+ } else if('ontouchstart' in window) {
1476
+ addEventNames('touch', 'start', 'move', 'end', 'cancel');
1477
+ } else {
1478
+ return;
1479
+ }
1480
+ _window.on(mfp._tStart, function(e) {
1481
+ var oE = e.originalEvent;
1482
+ multipleTouches = moved = false;
1483
+ startX = oE.pageX || oE.changedTouches[0].pageX;
1484
+ }).on(mfp._tMove, function(e) {
1485
+ if(e.originalEvent.touches.length > 1) {
1486
+ multipleTouches = e.originalEvent.touches.length;
1487
+ } else {
1488
+ //e.preventDefault();
1489
+ moved = true;
1490
+ }
1491
+ }).on(mfp._tEnd + ' ' + mfp._tCancel, function(e) {
1492
+ if(moved && !multipleTouches) {
1493
+ var oE = e.originalEvent,
1494
+ diff = startX - (oE.pageX || oE.changedTouches[0].pageX);
1495
+
1496
+ if(diff > 20) {
1497
+ mfp.next();
1498
+ } else if(diff < -20) {
1499
+ mfp.prev();
1500
+ }
1501
+ }
1502
+ });
1503
+ },
1504
+ */
1505
+
1506
+
1507
+ /*>>gallery*/
1508
+
1509
+ /*>>retina*/
1510
+
1511
+ var RETINA_NS = 'retina';
1512
+
1513
+ $.magnificPopup.registerModule(RETINA_NS, {
1514
+ options: {
1515
+ replaceSrc: function(item) {
1516
+ return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });
1517
+ },
1518
+ ratio: 1 // Function or number. Set to 1 to disable.
1519
+ },
1520
+ proto: {
1521
+ initRetina: function() {
1522
+ if(window.devicePixelRatio > 1) {
1523
+
1524
+ var st = mfp.st.retina,
1525
+ ratio = st.ratio;
1526
+
1527
+ ratio = !isNaN(ratio) ? ratio : ratio();
1528
+
1529
+ if(ratio > 1) {
1530
+ _mfpOn('ImageHasSize' + '.' + RETINA_NS, function(e, item) {
1531
+ item.img.css({
1532
+ 'max-width': item.img[0].naturalWidth / ratio,
1533
+ 'width': '100%'
1534
+ });
1535
+ });
1536
+ _mfpOn('ElementParse' + '.' + RETINA_NS, function(e, item) {
1537
+ item.src = st.replaceSrc(item, ratio);
1538
+ });
1539
+ }
1540
+ }
1541
+
1542
+ }
1543
+ }
1544
+ });
1545
+
1546
+ /*>>retina*/
1547
+
1548
+ /*>>fastclick*/
1549
+ /**
1550
+ * FastClick event implementation. (removes 300ms delay on touch devices)
1551
+ * Based on https://developers.google.com/mobile/articles/fast_buttons
1552
+ *
1553
+ * You may use it outside the Magnific Popup by calling just:
1554
+ *
1555
+ * $('.your-el').mfpFastClick(function() {
1556
+ * console.log('Clicked!');
1557
+ * });
1558
+ *
1559
+ * To unbind:
1560
+ * $('.your-el').destroyMfpFastClick();
1561
+ *
1562
+ *
1563
+ * Note that it's a very basic and simple implementation, it blocks ghost click on the same element where it was bound.
1564
+ * If you need something more advanced, use plugin by FT Labs https://github.com/ftlabs/fastclick
1565
+ *
1566
+ */
1567
+
1568
+ (function() {
1569
+ var ghostClickDelay = 1000,
1570
+ supportsTouch = 'ontouchstart' in window,
1571
+ unbindTouchMove = function() {
1572
+ _window.off('touchmove'+ns+' touchend'+ns);
1573
+ },
1574
+ eName = 'mfpFastClick',
1575
+ ns = '.'+eName;
1576
+
1577
+
1578
+ // As Zepto.js doesn't have an easy way to add custom events (like jQuery), so we implement it in this way
1579
+ $.fn.mfpFastClick = function(callback) {
1580
+
1581
+ return $(this).each(function() {
1582
+
1583
+ var elem = $(this),
1584
+ lock;
1585
+
1586
+ if( supportsTouch ) {
1587
+
1588
+ var timeout,
1589
+ startX,
1590
+ startY,
1591
+ pointerMoved,
1592
+ point,
1593
+ numPointers;
1594
+
1595
+ elem.on('touchstart' + ns, function(e) {
1596
+ pointerMoved = false;
1597
+ numPointers = 1;
1598
+
1599
+ point = e.originalEvent ? e.originalEvent.touches[0] : e.touches[0];
1600
+ startX = point.clientX;
1601
+ startY = point.clientY;
1602
+
1603
+ _window.on('touchmove'+ns, function(e) {
1604
+ point = e.originalEvent ? e.originalEvent.touches : e.touches;
1605
+ numPointers = point.length;
1606
+ point = point[0];
1607
+ if (Math.abs(point.clientX - startX) > 10 ||
1608
+ Math.abs(point.clientY - startY) > 10) {
1609
+ pointerMoved = true;
1610
+ unbindTouchMove();
1611
+ }
1612
+ }).on('touchend'+ns, function(e) {
1613
+ unbindTouchMove();
1614
+ if(pointerMoved || numPointers > 1) {
1615
+ return;
1616
+ }
1617
+ lock = true;
1618
+ e.preventDefault();
1619
+ clearTimeout(timeout);
1620
+ timeout = setTimeout(function() {
1621
+ lock = false;
1622
+ }, ghostClickDelay);
1623
+ callback();
1624
+ });
1625
+ });
1626
+
1627
+ }
1628
+
1629
+ elem.on('click' + ns, function() {
1630
+ if(!lock) {
1631
+ callback();
1632
+ }
1633
+ });
1634
+ });
1635
+ };
1636
+
1637
+ $.fn.destroyMfpFastClick = function() {
1638
+ $(this).off('touchstart' + ns + ' click' + ns);
1639
+ if(supportsTouch) _window.off('touchmove'+ns+' touchend'+ns);
1640
+ };
1641
+ })();
1642
+
1643
+ /*>>fastclick*/
1644
+ })(window.jQuery || window.Zepto);