Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* jshint undef: true, unused: true */
- /* global define: false */
- define(['jquery', 'bPopup'], function($){
- 'use strict';
- var GetinTouch = {
- data: {
- form: $('.form-popup-block'),
- error: $('.error-block'),
- succes: $('.success-block'),
- order: $('.order-form-block')
- },
- init: function() {
- this.bindUiActions();
- },
- bindUiActions: function() {
- $('form').submit(function(event) {
- event.preventDefault();
- });
- $(".checkout").click(function() {
- GetinTouch.validateForm($(this));
- });
- $('input.required').focus(function(){
- var thisElem = $(this);
- thisElem.removeClass('error');
- });
- },
- validateForm: function(submit) {
- var formValid = true,
- thisForm = submit.closest('form');
- $('input.required', thisForm).each(function() {
- var thisInput = $(this);
- if(thisInput.val()===""){
- if(thisForm.parent().hasClass('products-form-block')){
- thisInput.addClass('error');
- }
- formValid = false;
- }
- });
- GetinTouch.sendForm(thisForm, formValid);
- },
- sendForm: function(thisForm, formValid) {
- if(formValid){
- var url = "sendmail.php";
- $.ajax({
- type: "POST",
- url: url,
- data: thisForm.serialize(), // serializes the form's elements.
- success: function(){
- $('input', thisForm).each(function(){
- $('.required', thisForm).val('');
- });
- $('.products-form').trigger('sent');
- var onOpen = function() {
- $('.form-popup-block').bPopup().close();
- };
- if (thisForm.parent().hasClass('form-popup-block') && thisForm.parent().hasClass('order-form-block')) {
- GetinTouch.bindPopup(GetinTouch.data.succes, onOpen);
- } else {
- GetinTouch.bindPopup(GetinTouch.data.succes);
- }
- }
- });
- }else{
- if (!thisForm.parent().hasClass('products-form-block')) {
- GetinTouch.bindPopup(GetinTouch.data.error);
- }
- }
- return false;
- },
- bindPopup: function(container, onOpen) {
- container.bPopup({
- closeClass: 'close-popup',
- onOpen: onOpen
- });
- }
- };
- return GetinTouch;
- $('.js-pre-order').click(function(e) {
- e.preventDefault();
- console.log("triggered popup");
- $('#pre-order-now').bPopup();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement