Created
December 13, 2012 06:09
-
-
Save piayo/4274463 to your computer and use it in GitHub Desktop.
toggle popup for Chrome Extension like Official Google+ notifications extensions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _timer = null; | |
var _flg_opened = false; | |
var _func_toggle = function(flg){ | |
_flg_opened = flg; | |
clearTimeout(_timer); | |
_timer = setTimeout(function(){ | |
console.log(">>_flg_opened: "+ _flg_opened); | |
if(_flg_opened){ | |
chrome.browserAction.setPopup({"popup": ""}); | |
chrome.browserAction.setBadgeText({text:"OFF"}); | |
chrome.browserAction.setTitle({"title": "NextClick: Close"}); | |
clearTimeout(_timer); | |
}else{ | |
chrome.browserAction.setPopup({"popup": "popup.html"}); | |
chrome.browserAction.setBadgeText({text:"ON"}); | |
chrome.browserAction.setTitle({"title": "NextClick: OPEN"}); | |
clearTimeout(_timer); | |
} | |
}, 200); | |
}; | |
;(function(_WIN, _DOC){ | |
var _init = function(){ | |
console.log(">>onload: background"); | |
_func_toggle(false); | |
} | |
_WIN.onload = _init | |
})(window, document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(_WIN, _DOC){ | |
var _BG; | |
var _init = function(){ | |
console.log(">>onload: popup"); | |
_BG = chrome.extension.getBackgroundPage(); | |
_BG._func_toggle(true); | |
_WIN.addEventListener("unload", function(){ | |
_BG._func_toggle(false); | |
}, false); | |
} | |
_WIN.onload = _init; | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment