Retina.js中未捕获的引用错误

时间:2016-12-27 作者:thunder

我正在努力准备好我的主题视网膜。我在我的主题文件中包含了以下代码。但它引起了以下关注

Uncaught reference Error: Exports is not defined 
.............js/retina.js?ver=4.6.1 line 12.
我想知道为什么它说错误在脚本文件中。因为我一次又一次地下载了脚本文件,我非常确定视网膜中没有错误。js文件。有人能帮忙解决这个问题吗?以下是我的代码:

<?php 
add_action( \'wp_enqueue_scripts\', \'retina_support_enqueue_scripts\' );
/**
 * Enqueueing retina.js
 *
 * This function is attached to the \'wp_enqueue_scripts\' action hook.
 */
function retina_support_enqueue_scripts() {
    wp_enqueue_script( \'retina_js\', get_template_directory_uri() . \'/js/retina.js\', \'\', \'\', true );
}
add_filter( \'wp_generate_attachment_metadata\', \'retina_support_attachment_meta\', 10, 2 );
/**
 * Retina images
 *
 * This function is attached to the \'wp_generate_attachment_metadata\' filter hook.
 */
function retina_support_attachment_meta( $metadata, $attachment_id ) {
    foreach ( $metadata as $key => $value ) {
        if ( is_array( $value ) ) {
            foreach ( $value as $image => $attr ) {
                if ( is_array( $attr ) )
                    retina_support_create_images( get_attached_file( $attachment_id ), $attr[\'width\'], $attr[\'height\'], true );
            }
        }
    }

    return $metadata;
}

/**
 * Create retina-ready images
 *
 * Referenced via retina_support_attachment_meta().
 */
function retina_support_create_images( $file, $width, $height, $crop = false ) {
    if ( $width || $height ) {
        $resized_file = wp_get_image_editor( $file );
        if ( ! is_wp_error( $resized_file ) ) {
            $filename = $resized_file->generate_filename( $width . \'x\' . $height . \'@2x\' );

            $resized_file->resize( $width * 2, $height * 2, $crop );
            $resized_file->save( $filename );

            $info = $resized_file->get_size();

            return array(
                \'file\' => wp_basename( $filename ),
                \'width\' => $info[\'width\'],
                \'height\' => $info[\'height\'],
            );
        }
    }
    return false;
}

add_filter( \'delete_attachment\', \'delete_retina_support_images\' );
/**
 * Delete retina-ready images
 *
 * This function is attached to the \'delete_attachment\' filter hook.
 */
function delete_retina_support_images( $attachment_id ) {
    $meta = wp_get_attachment_metadata( $attachment_id );
    $upload_dir = wp_upload_dir();
    $path = pathinfo( $meta[\'file\'] );
    foreach ( $meta as $key => $value ) {
        if ( \'sizes\' === $key ) {
            foreach ( $value as $sizes => $size ) {
                $original_filename = $upload_dir[\'basedir\'] . \'/\' . $path[\'dirname\'] . \'/\' . $size[\'file\'];
                $retina_filename = substr_replace( $original_filename, \'@2x.\', strrpos( $original_filename, \'.\' ), strlen( \'.\' ) );
                if ( file_exists( $retina_filename ) )
                    unlink( $retina_filename );
            }
        }
    }
}

1 个回复
最合适的回答,由SO网友:Jami Gibbs 整理而成

听起来可能是脚本的分布式版本的编译方式有问题。我发现this issue 报告了可能相关的Github回购。

尝试使用下载zip包中包含的缩小版(retina.min.js)。如果使用的文件名称不同,请记住更新脚本排队路径。

相关推荐

Images with overlay

我有一些图片在一个容器中,我想添加一个覆盖和图标。这不是现成的,但我找到了一些有用的代码:HTML:<div class=\"main\"> <span class=\"featured\"><img src=\"http://joshrodg.com/IMG_001-258x258.jpg\" title=\"\" alt=\"\"></span> </div> CSS:.featured {