Advertisement
Guest User

Triablo bPopup Customisation

a guest
Nov 28th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* jshint undef: true, unused: true */
  2. /* global define: false */
  3. define(['jquery', 'bPopup'], function($){
  4.     'use strict';
  5.    
  6.     var GetinTouch = {
  7.         data: {
  8.             form: $('.form-popup-block'),
  9.             error: $('.error-block'),
  10.             succes: $('.success-block'),
  11.             order: $('.order-form-block')
  12.         },
  13.  
  14.         init: function() {
  15.             this.bindUiActions();
  16.         },
  17.  
  18.         bindUiActions: function() {
  19.             $('form').submit(function(event) {
  20.                 event.preventDefault();
  21.             });
  22.  
  23.             $(".checkout").click(function() {
  24.                 GetinTouch.validateForm($(this));
  25.             });
  26.  
  27.             $('input.required').focus(function(){
  28.                 var thisElem = $(this);
  29.                 thisElem.removeClass('error');
  30.             });
  31.         },
  32.  
  33.         validateForm: function(submit) {
  34.             var formValid = true,
  35.                 thisForm = submit.closest('form');
  36.  
  37.             $('input.required', thisForm).each(function() {
  38.                 var thisInput = $(this);
  39.  
  40.                 if(thisInput.val()===""){
  41.                     if(thisForm.parent().hasClass('products-form-block')){
  42.                         thisInput.addClass('error');
  43.                     }
  44.                     formValid = false;
  45.                 }
  46.             });
  47.  
  48.             GetinTouch.sendForm(thisForm, formValid);
  49.         },
  50.  
  51.         sendForm: function(thisForm, formValid) {
  52.             if(formValid){
  53.                 var url = "sendmail.php";
  54.  
  55.                 $.ajax({
  56.                     type: "POST",
  57.                     url: url,
  58.                     data: thisForm.serialize(), // serializes the form's elements.
  59.                     success: function(){
  60.                         $('input', thisForm).each(function(){
  61.                             $('.required', thisForm).val('');
  62.                         });
  63.  
  64.                         $('.products-form').trigger('sent');
  65.  
  66.                         var onOpen = function() {
  67.                             $('.form-popup-block').bPopup().close();
  68.                         };
  69.                        
  70.                         if (thisForm.parent().hasClass('form-popup-block') && thisForm.parent().hasClass('order-form-block')) {
  71.                             GetinTouch.bindPopup(GetinTouch.data.succes, onOpen);
  72.                         } else {
  73.                             GetinTouch.bindPopup(GetinTouch.data.succes);
  74.                         }
  75.  
  76.                        
  77.                     }
  78.                 });
  79.             }else{
  80.                 if (!thisForm.parent().hasClass('products-form-block')) {
  81.                     GetinTouch.bindPopup(GetinTouch.data.error);
  82.                 }
  83.             }
  84.             return false;
  85.         },
  86.  
  87.         bindPopup: function(container, onOpen) {
  88.             container.bPopup({
  89.                 closeClass: 'close-popup',
  90.                 onOpen: onOpen
  91.             });
  92.         }
  93.     };
  94.  
  95.     return GetinTouch;
  96.    
  97.     $('.js-pre-order').click(function(e) {
  98.         e.preventDefault();
  99.         console.log("triggered popup");
  100.         $('#pre-order-now').bPopup();
  101.     });
  102.  
  103. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement