Ejemplo n.º 1
0
  onClick: function (e) {
    e.preventDefault();

    var contactUrl = this.url;
    if (contactUrl === null) {
      return false;
    }

    var $el = $(e.target),
        sP = $el.data(sel.data.subjectPrefix),
        subjectPrefix = sP ? ['[', sP, '] '].join('') : sP,
        subject = $el.data(sel.data.subject),
        body = $el.data(sel.data.body);

    $.magnificPopup.open({
      items: {
        src: contactUrl,
        type: 'ajax'
      },
      callbacks: {
        ajaxContentAdded: function () {
          var newSubject = [];
          subjectPrefix && newSubject.push(subjectPrefix);
          subject && newSubject.push(subject);

          newSubject.length && $(sel.subject).val(newSubject.join(''));
          body && $(sel.body).val(body);
        }
      },
      mainClass: 'popup-ajax'
    });
  },
Ejemplo n.º 2
0
  open: function (opts) {
    opts = opts || {};

    var contactUrl = opts.url || this.url;
    if (contactUrl === null) {
      return false;
    }

    $.magnificPopup.open({
      items: {
        src: contactUrl,
        type: 'ajax'
      },
      callbacks: {
        ajaxContentAdded: function () {
          var newSubject = [];
          opts.subjectPrefix && newSubject.push(opts.subjectPrefix);
          opts.subject && newSubject.push(opts.subject);

          newSubject.length && $(sel.subject).val(newSubject.join(''));
          opts.body && $(sel.body).val(opts.body);
        }
      },
      mainClass: 'popup-ajax'
    });
  },
Ejemplo n.º 3
0
function display(html) {
  $(document).on('submit', '#js-captcha', onSubmit);

  $.magnificPopup.open({
    items: {
      src: html,
      type: 'inline',
    },
    focus: '#id_captcha_answer',
  });
}
Ejemplo n.º 4
0
function display(html) {
  // we need to remove existing handlers which can exist after wrong captcha input
  $(document).off('submit', '#js-captcha');
  $(document).on('submit', '#js-captcha', onSubmit);

  $.magnificPopup.open({
    items: {
      src: html,
      type: 'inline',
    },
    focus: '#id_captcha_answer',
  });
}
Ejemplo n.º 5
0
function onSubmit(e) {
  e.preventDefault();
  const $form = $(this);
  const reqData = $form.serializeObject();
  const successFn = reqData.sfn;
  const errorFn = reqData.efn;
  const url = $form.attr('action');

  $.ajax({
    url,
    type: 'POST',
    data: reqData,
    success() {
      utils.executeFunctionByName(successFn, window, e);
      $.magnificPopup.close();
    },
    error(xhr) {
      onError(xhr, errorFn);
    },
  });
}
Ejemplo n.º 6
0
    if (contactUrl === null) {
      return false;
    }

    $.magnificPopup.open({
      items: {
        src: contactUrl,
        type: 'ajax',
      },
      callbacks: {
        ajaxContentAdded() {
          const newSubject = [];
          if (opts.subjectPrefix) {
            newSubject.push(opts.subjectPrefix);
          }
          if (opts.subject) {
            newSubject.push(opts.subject);
          }
          if (newSubject.length) {
            $(sel.subject).val(newSubject.join(''));
          }
          if (opts.body) {
            $(sel.body).val(opts.body);
          }
        },
      },
      mainClass: 'popup-ajax',
    });
    return true;
  },

  onSubmit(e) {
Ejemplo n.º 7
0
define(function(require) {

  var $ = require('jquery');
  var magnificPopup = require('magnific');

  // Get popup constants
  var RETINA_NS = 'retina';
  var mfp = $.magnificPopup.instance;
  var NS = 'mfp';
  var EVENT_NS = '.' + NS;
  var _mfpOn = function(name, f) {
    mfp.ev.on(NS + name + EVENT_NS, f);
  };

  $.magnificPopup.registerModule(RETINA_NS, {
    options: {
      replaceSrc: function(item) {
        return item.src.replace(/\.\w+$/, function(m) { return '@2x' + m; });
      },
      ratio: 1 // Function or number.  Set to 1 to disable.
    },
    proto: {
      initRetina: function() {
        if (window.devicePixelRatio > 1.1) {

          var st = mfp.st.retina;
          var ratio = st.ratio;

          ratio = !isNaN(ratio) ? ratio : ratio();

          var handleChange = function() {
            var item = mfp.currItem;
            if (item.type === 'image') {
              mfp.updateStatus('loading');
              setImageSize(item.img);
            }
          };

          var handleResize = function() {
            var item = mfp.currItem;
            if (item.type === 'image') {
              setImageSize(item.img);
            }
          };

          var setImageSize = function(image) {
            var imageSize = image[0].naturalWidth / ratio;
            // MFP has 8px of padding on either side (6 @ < 900px).
            var viewportWithPadding = window.innerWidth - 16;
            image.css('maxWidth', Math.min(imageSize, viewportWithPadding));
          };

          if (ratio > 1) {
            // This sets the max width to zero as soon as the new content is
            // appened to the DOM, making the content invisible.
            _mfpOn('AfterChange' + '.' + RETINA_NS, handleChange);

            // Next, a resize event is triggered, which probably still sets
            // it to zero.
            _mfpOn('Resize' + '.' + RETINA_NS, handleResize);

            // Finally, the image loads and "has a size". This now correctly
            // sets the max-width based on the viewport and image size, going
            // from zero to the natural width / ratio or the viewport width,
            // whichever is smaller. This prevents the popping effect from
            // setting the max-width to a smaller value than when the image loads.
            _mfpOn('ImageHasSize' + '.' + RETINA_NS, function(e, item) {
              mfp.updateStatus('ready');
              setImageSize(item.img);
            });

            _mfpOn('ElementParse' + '.' + RETINA_NS, function(e, item) {
              item.src = st.replaceSrc(item, ratio);
            });
          }
        }

      }
    }
  });

});