<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_SeoRule
 * @copyright   Copyright (c) Mageplaza (http://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */
?>
<script type="text/javascript">
    require(['jquery'], function ($) {
        $(document).ready(function () {
            $("img").each(function () {
                if (!$(this).attr("alt")) {
                    var src = $(this).attr("src");
                    var fileName = src.substring(src.lastIndexOf('/'));
                    /**
                     * Replace .jpg|.png|.bmp|.svg|/|-| of filename equal whitespace
                     * @type {string}
                     */
                    var alt = fileName.replace(/.jpg|.png|.gif|.bmp|.svg|\/|-/gi, '');
                    $(this).attr("alt", alt.trim());
                }
            });
        });
    });
</script>
