( function( $, elementorFrontend ) {
'use strict';
var JetPopup = {
init: function() {
var $popup_list = $( '.jet-popup:not(.jet-popup--single-preview)' ),
editMode = Boolean( elementorFrontend.isEditMode() );
if ( ! editMode ) {
$popup_list.each( function( index ) {
var $target = $( this ),
instance = null,
settings = $target.data( 'settings' );
instance = new window.jetPopup( $target, settings );
instance.init();
} );
}
elementorFrontend.hooks.addAction( 'frontend/element_ready/widget', JetPopup.elementorWidget );
var widgets = {
'jet-popup-action-button.default' : JetPopup.widgetPopupActionButton,
'jet-popup-mailchimp.default' : JetPopup.widgetPopupMailchimp
};
$.each( widgets, function( widget, callback ) {
elementorFrontend.hooks.addAction( 'frontend/element_ready/' + widget, callback );
});
},
elementorWidget: function( $scope ) {
var widget_id = $scope.data( 'id' ),
widgetType = $scope.data( 'element_type' ),
widgetsData = jetPopupData.elements_data.widgets,
popupSettings = $scope.data( 'jet-popup' ) || false;
if ( widgetsData.hasOwnProperty( widget_id ) || popupSettings ) {
var widgetData = widgetsData[ widget_id ] || popupSettings,
opentEvent = widgetData[ 'trigger-type' ],
customSelector = widgetData[ 'trigger-custom-selector' ],
popupData = {
popupId: widgetData[ 'attached-popup' ]
};
if ( $scope.hasClass( 'jet-popup-attach-event-inited' ) ) {
return false;
}
$scope.addClass( 'jet-popup-attach-event-inited' );
switch( opentEvent ) {
case 'click-self':
$scope.addClass( 'jet-popup-cursor-pointer' );
$scope.on( 'click.JetPopup', function( event ) {
event.preventDefault();
var $target = $( this );
if ( window.elementorFrontend.hooks ) {
popupData = elementorFrontend.hooks.applyFilters(
'jet-popup/widget-extensions/popup-data',
popupData,
widgetData,
$scope,
event
);
}
$( window ).trigger( {
type: 'jet-popup-open-trigger',
popupData: popupData
} );
return false;
} );
break;
case 'click':
$scope.on( 'click.JetPopup', '.elementor-button, .jet-button__instance .jet-popup-action-button__instance', function( event ) {
event.preventDefault();
if ( window.elementorFrontend.hooks ) {
popupData = elementorFrontend.hooks.applyFilters(
'jet-popup/widget-extensions/popup-data',
popupData,
widgetData,
$scope,
event
);
}
$( window ).trigger( {
type: 'jet-popup-open-trigger',
popupData: popupData
} );
return false;
} );
break;
case 'click-selector':
if ( '' !== customSelector ) {
$( customSelector ).addClass( 'jet-popup-cursor-pointer' );
$scope.on( 'click.JetPopup', customSelector, function( event ) {
event.preventDefault();
var $target = $( event.currentTarget );
$target.addClass( 'jet-popup-cursor-pointer' );
if ( window.elementorFrontend.hooks ) {
popupData = elementorFrontend.hooks.applyFilters(
'jet-popup/widget-extensions/popup-data',
popupData,
widgetData,
$scope,
event
);
}
$( window ).trigger( {
type: 'jet-popup-open-trigger',
popupData: popupData
} );
return false;
} );
}
break;
case 'hover':
$scope.on( 'mouseenter.JetPopup', function( event ) {
if ( window.elementorFrontend.hooks ) {
popupData = elementorFrontend.hooks.applyFilters(
'jet-popup/widget-extensions/popup-data',
popupData,
widgetData,
$scope,
event
);
}
$( window ).trigger( {
type: 'jet-popup-open-trigger',
popupData: popupData
} );
} );
break;
case 'scroll-to':
elementorFrontend.waypoint( $scope, function( event ) {
if ( window.elementorFrontend.hooks ) {
popupData = elementorFrontend.hooks.applyFilters(
'jet-popup/widget-extensions/popup-data',
popupData,
widgetData,
$scope,
event
);
}
$( window ).trigger( {
type: 'jet-popup-open-trigger',
popupData: popupData
} );
}, {
offset: 'bottom-in-view'
} );
break;
}
}
},
widgetPopupActionButton: function( $scope ) {
var $button = $( '.jet-popup-action-button__instance', $scope ),
settings = $button.data( 'settings' ),
actionType = settings['action-type'];
switch ( actionType ) {
case 'link':
$button.on( 'click.JetPopup', function( event ) {
event.preventDefault();
var $currentPopup = $button.closest( '.jet-popup ' ),
link = $( this ).attr( 'href' ),
popupId = $currentPopup.attr( 'id' );
$( window ).trigger( {
type: 'jet-popup-close-trigger',
popupData: {
popupId: popupId,
constantly: false
}
} );
window.location = link;
return false;
} );
break;
case 'leave':
$button.on( 'click.JetPopup', function( event ) {
event.preventDefault();
window.history.back();
} );
break;
case 'close-popup':
$button.on( 'click.JetPopup', function( event ) {
event.preventDefault();
var $currentPopup = $button.closest( '.jet-popup ' ),
popupId = $currentPopup.attr( 'id' );
$( window ).trigger( {
type: 'jet-popup-close-trigger',
popupData: {
popupId: popupId,
constantly: false
}
} );
} );
break;
case 'close-all-popups':
$button.on( 'click.JetPopup', function( event ) {
event.preventDefault();
var $popups = $( '.jet-popup' );
if ( $popups[0] ) {
$popups.each( function( index ) {
var $popup = $( this ),
popupId = $popup.attr( 'id' );
$( window ).trigger( {
type: 'jet-popup-close-trigger',
popupData: {
popupId: popupId,
constantly: false
}
} );
} );
}
} );
break;
case 'close-constantly':
$button.on( 'click.JetPopup', function( event ) {
event.preventDefault();
var $currentPopup = $button.closest( '.jet-popup ' ),
popupId = $currentPopup.attr( 'id' );
$( window ).trigger( {
type: 'jet-popup-close-trigger',
popupData: {
popupId: popupId,
constantly: true
}
} );
} );
break;
case 'close-all-constantly':
$button.on( 'click.JetPopup', function( event ) {
event.preventDefault();
var $popups = $( '.jet-popup' );
if ( $popups[0] ) {
$popups.each( function( index ) {
var $popup = $( this ),
popupId = $popup.attr( 'id' );
$( window ).trigger( {
type: 'jet-popup-close-trigger',
popupData: {
popupId: popupId,
constantly: true
}
} );
} );
}
} );
break;
}
},
widgetPopupMailchimp: function( $scope ) {
var $target = $scope.find( '.jet-popup-mailchimp' ),
scoreId = $scope.data( 'id' ),
settings = $target.data( 'settings' ),
$subscribeForm = $( '.jet-popup-mailchimp__form', $target ),
$fields = $( '.jet-popup-mailchimp__fields', $target ),
$mailField = $( '.jet-popup-mailchimp__mail-field', $target ),
$inputData = $mailField.data( 'instance-data' ),
$submitButton = $( '.jet-popup-mailchimp__submit', $target ),
$subscribeFormMessage = $( '.jet-popup-mailchimp__message', $target ),
invalidMailMessage = 'Please specify a valid email',
timeout = null,
ajaxRequest = null,
$currentPopup = $target.closest( '.jet-popup' );
$mailField.on( 'focus', function() {
$mailField.removeClass( 'mail-invalid' );
} );
$( document ).keydown( function( event ) {
if ( 13 === event.keyCode && $mailField.is( ':focus' ) ) {
subscribeHandle();
return false;
}
} );
$submitButton.on( 'click', function() {
subscribeHandle();
return false;
} );
self.subscribeHandle = function() {
var inputValue = $mailField.val(),
sendData = {
'email': inputValue,
'target_list_id': settings['target_list_id'] || '',
'data': $inputData
},
serializeArray = $subscribeForm.serializeArray(),
additionalFields = {};
if ( validateEmail( inputValue ) ) {
Loading ...