mozilla firefox-扩展名有时无法运行

时间:2018-09-27 09:35:41

标签: javascript firefox-addon mozilla

我对mozilla扩展有问题。当鼠标悬停图像default_width> 150px和default_height> 150时,扩展名允许在线设计图像。当将扩展名添加到firefox中时,页面上的某个时间未运行,尽管添加了图像事件。请告诉我问题。

JAVASCRIPT

DBSDK_EXTENSION.init_hover_action = function(items) {
    var images = document.querySelectorAll("img");
    if (images.length > 0) {
        for (var i = 0; i < images.length; i++) {
            items.minWidth = parseInt(items.minWidth);
            items.maxWidth = parseInt(items.maxWidth);
            items.minHeight = parseInt(items.minHeight);
            items.maxHeight = parseInt(items.maxHeight);
            items.hoverButtonStatus = parseInt(items.hoverButtonStatus);
            images[i].db_config = items;
            images[i].addEventListener("mouseover", DBSDK_EXTENSION.mouseover_function, false);
            images[i].addEventListener("mouseleave", DBSDK_EXTENSION.mouseleave_function, false);
        }
    }
};

// When mouse over image.
DBSDK_EXTENSION.mouseover_function = function(event) {
    var el = event.target;
    var rect = el.getBoundingClientRect();
    var image_src = el.src;
    var button = document.querySelector("#design_bold_hover_button");
    var scroll_top = document.documentElement.scrollTop;
    var db_config = el.db_config;
    if (rect.width >= db_config.minWidth && rect.width <= db_config.maxWidth && rect.height >= db_config.minHeight && rect.height <= db_config.maxHeight) {
        if (db_config.hoverButtonStatus) {
            switch (db_config.hoverButtonPosition) {
                case "1":
                    button.style.top = (scroll_top + rect.top + 10) + "px";
                    button.style.left = (rect.left + 10) + "px";
                    break;
                case "2":
                    button.style.top = (scroll_top + rect.top + 10) + "px";
                    button.style.left = (rect.left + rect.width - 90) + "px";
                    break;
                case "3":
                    button.style.top = (scroll_top + rect.top + rect.height - 40) + "px";
                    button.style.left = (rect.left + 10) + "px";
                    break;
                case "4":
                    button.style.top = (scroll_top + rect.top + rect.height - 40) + "px";
                    button.style.left = (rect.left + rect.width - 90) + "px";
                    break;
                default:
                    button.style.top = (scroll_top + rect.top + 10) + "px";
                    button.style.left = (rect.left + 10) + "px";
                    break;
            }
            button.style.display = "block !important";
            button.removeEventListener("click", DBSDK_EXTENSION.start_design_tool, false);
            button.dataset.image = el.src;
            button.onclick = DBSDK_EXTENSION.start_design_tool;
        }
        getPort().postMessage({
            action: 'create'
        });
    }
};

// When mouse leave image.
DBSDK_EXTENSION.mouseleave_function = function(event) {
    var el = event.target;
    var rect = el.getBoundingClientRect();
    var image_src = el.src;
    var button = document.querySelector("#design_bold_hover_button");
    var scroll_top = document.documentElement.scrollTop;
    if ((event.clientX >= rect.left + rect.width) || (event.clientX <= rect.left) || event.clientY <= rect.top || event.clientY >= (rect.top + rect.height)) {

        button.style.display = "none";
        button.dataset.image = "";
        button.onclick = function() {
            return false;
        };
    }
    getPort().postMessage({
        action: 'remove'
    });
};

链接firefox扩展名: https://addons.mozilla.org/en-US/firefox/addon/designbold/

0 个答案:

没有答案