faiq
@faiq
программист

Почему этот код не работает в IE?

Почему этот код не работает в IE?
Весь код
jQuery().ready(function () {
    alert('test');
    document.addEventListener('copy', function (e) {

        e.preventDefault();

        var selection = window.getSelection().toString();
        var escaped = selection + ' Узнать больше: ' + document.location.href;
        if (window.clipboardData) {// IE
            window.clipboardData.setData('Text', escaped);
        } else if (e.clipboardData) {
            e.clipboardData.setData('text/plain', escaped);
        }
    });

});
//типа класс догрузки и массштабирования ленты новостей (всех 3х)
class NewsLoader {
    constructor($container, $instance = undefined) {
        var that = this;
        this.$container = $container;
        this.$instance = $instance != undefined ? $instance : $container.siblings('div').eq(0);
        this.next_news = function ($data_container) {
            $data_container.attr('data-downloaded', 1);
            var action = $data_container.attr('data-action');
            var news_count = $data_container.attr('data-count');
            var news_count_delta = $data_container.attr('data-count-delta');
            var data = {
                action: action,
                news_count: news_count,
                news_count_delta: news_count_delta,
                news_expert_category: $data_container.attr('data-expert-category'),
                news_category: $data_container.attr('data-category')
            };
            jQuery.post(myajax.url, data, function (response) {
                $data_container.append(response);
                $data_container.attr('data-count', parseInt(news_count) + parseInt(news_count_delta));
                $data_container.attr('data-downloaded', 0);
            });
        };
        this.start = function () {
            $(document).ready(function () {
                if (that.$container.length > 0 && that.$instance.length > 0) {
                    var $data_container = that.$container.find(".data_container");
                    var is_mobile = $data_container.attr('data-is-mobile');
                    if ($data_container.length > 0 && !is_mobile) {
                        that.next_news($data_container);
                        $data_container.scroll(function (event) {
                            var st = $(this).scrollTop();
                            var pheight = that.$instance.height() - 104;
                            if (pheight < 600)
                                pheight = 600;
                            var phalf = pheight / 2;
                            var h = $(this).get(0).scrollHeight;
                            var is_downloaded = $data_container.attr('data-downloaded');
                            if (((h - st - pheight) < phalf) && (is_downloaded == 0)) {
                                that.next_news($data_container);
                            }
                        });
                        $(window).load(function () {
                            $data_container.height(that.$instance.height() - 104);
                            if ($(window).width() < 640) {
                                $data_container.height($(window).height() - $data_container.offset().top - 20);
                            }
                        });
                        $(window).resize(function () {
                            $data_container.height(that.$instance.height() - 104);
                            if ($(window).width() < 640) {
                                $data_container.height($(window).height() - $data_container.offset().top - 20);
                            }
                        });
                    }
                }
            });
        };
        this.start();
    }
}
$(document).ready(function () {
    var $tabswidget = $('#news3_block .scroll-pane');
    if ($tabswidget.length > 0 && !$tabswidget.attr('data-is-mobile')) {
        $tabswidget.height('950px');
        $tabswidget.scroll(function (event) {
        });
    }
});

Не работающая часть
class NewsLoader {
    constructor($container, $instance = undefined) {
        var that = this;
        this.$container = $container;
        this.$instance = $instance != undefined ? $instance : $container.siblings('div').eq(0);
        this.next_news = function ($data_container) {
            $data_container.attr('data-downloaded', 1);
            var action = $data_container.attr('data-action');
            var news_count = $data_container.attr('data-count');
            var news_count_delta = $data_container.attr('data-count-delta');
            var data = {
                action: action,
                news_count: news_count,
                news_count_delta: news_count_delta,
                news_expert_category: $data_container.attr('data-expert-category'),
                news_category: $data_container.attr('data-category')
            };
            jQuery.post(myajax.url, data, function (response) {
                $data_container.append(response);
                $data_container.attr('data-count', parseInt(news_count) + parseInt(news_count_delta));
                $data_container.attr('data-downloaded', 0);
            });
        };
        this.start = function () {
            $(document).ready(function () {
                if (that.$container.length > 0 && that.$instance.length > 0) {
                    var $data_container = that.$container.find(".data_container");
                    var is_mobile = $data_container.attr('data-is-mobile');
                    if ($data_container.length > 0 && !is_mobile) {
                        that.next_news($data_container);
                        $data_container.scroll(function (event) {
                            var st = $(this).scrollTop();
                            var pheight = that.$instance.height() - 104;
                            if (pheight < 600)
                                pheight = 600;
                            var phalf = pheight / 2;
                            var h = $(this).get(0).scrollHeight;
                            var is_downloaded = $data_container.attr('data-downloaded');
                            if (((h - st - pheight) < phalf) && (is_downloaded == 0)) {
                                that.next_news($data_container);
                            }
                        });
                        $(window).load(function () {
                            $data_container.height(that.$instance.height() - 104);
                            if ($(window).width() < 640) {
                                $data_container.height($(window).height() - $data_container.offset().top - 20);
                            }
                        });
                        $(window).resize(function () {
                            $data_container.height(that.$instance.height() - 104);
                            if ($(window).width() < 640) {
                                $data_container.height($(window).height() - $data_container.offset().top - 20);
                            }
                        });
                    }
                }
            });
        };
        this.start();
    }
}
  • Вопрос задан
  • 161 просмотр
Решения вопроса 1
0xD34F
@0xD34F Куратор тега JavaScript
Не работающая часть
class NewsLoader {

https://caniuse.com/#feat=es6-class
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы