ilhamsabir
12/5/2017 - 4:53 AM

new-pixel-template.js

$(document).ready(function() {
    
    function detectmob() {
        if( navigator.userAgent.match(/Android/i)
        || navigator.userAgent.match(/webOS/i)
        || navigator.userAgent.match(/iPhone/i)
        || navigator.userAgent.match(/iPad/i)
        || navigator.userAgent.match(/iPod/i)
        || navigator.userAgent.match(/BlackBerry/i)
        || navigator.userAgent.match(/Windows Phone/i)
        )
       {
               return true;
       }
       else {
               return false;
       }
    };
    

    
    
    // wa button
    buttonWa.forEach(function(item) {
        $('body').on('click', '.'+item.className, function(e) {
            e.preventDefault();
            
           fbq('track', item.pixelevent);
           var text = $(this).text();
           $(this).text('loading ...');
    
           var linkMobile    = 'https://api.whatsapp.com/send?phone='+item.number+'&text='+item.message;
           var linkDekstop   = 'https://web.whatsapp.com/send?phone='+item.number+'&text='+item.message;
    
           if (detectmob() == true) {
               var link = linkMobile;
           } else {
               var link = linkDekstop;
           }
           window.setTimeout(function() {
               window.location.href = link;
           }, 3000)
        });
    });
    
    // sms button
    buttonSms.forEach(function(item) {
        var selector = '.'+item.className;
        $('body').on('click', selector, function(e) {
            e.preventDefault();
            fbq('track', item.pixelevent);
            
            if (detectmob() == true) {
                var text = $(this).text();
                $(this).text('loading ...');
                var link =  'sms://'+item.number;
            }  else {
                var link =  " ";
                swal("Silahkan Kirim Sms Ke Nomor "+item.number);
            }
            
            window.setTimeout(function() {
                window.location.href = link;
            }, 3000)
            
        });  
    });

    
    
    
    
    // // pixel event link redirect
    // for (var i = 0; i < buttonLink.length; i++) {
    //   $('.'+buttonLink[i].class).on('click', function(e) {
    //       e.preventDefault();
    //       fbq('track', buttonLink[i].pixelevent);
    
    //       var text = $(this).text();
    //       $(this).text('loading ...');
           
    //       var link = buttonLink[i].link;
    
    //       window.setTimeout(function() {
    //           window.location.href = link;
    //       }, 3000)
    //   });
    // };


})