clare485
7/28/2015 - 1:36 PM

Convert Magento to Sweet Alert popups - needs to be added to footer template file

Convert Magento to Sweet Alert popups - needs to be added to footer template file

<script type="text/javascript">
    //<![CDATA[
    function escapeHtml(text) {
        return text
            .replace("&amp;",'&' )
            .replace("&lt;", '<')
            .replace("&gt;", '>')
            .replace("&quot;", '"')
            .replace("&#039;", "'");
    }
    //Showing messages
    if ($$('.messages').length) {
        $$('.messages')[0].hide();
        if ($$('.messages span').length) {
            document.observe("dom:loaded", function() {
                var message = escapeHtml($$('.messages span')[0].innerHTML);
                if  ($$('.messages .error-msg').length) {
                    setTimeout(function() { swal("Error", message, "error");},100);
                } else {
                    if (message.indexOf('was added to your basket') > -1) {
                        setTimeout(function() {
                            swal({
                                title: "Success",
                                text: message,
                                type: "success",
                                showCancelButton: true,
                                cancelButtonText: "Continue shopping",
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "Go to basket",
                                closeOnConfirm: false
                            }, function(){
                                window.location.href = "<?php echo $this->getUrl('checkout/cart') ?>";
                            });
                        },100);
                    } else {
                        setTimeout(function() { swal("Success", message, "success");},100);
                    }
                }
            });
        }
    }
    //]]>
</script>