| Index: chrome/content/ui/popup.js | 
| =================================================================== | 
| new file mode 100644 | 
| --- /dev/null | 
| +++ b/chrome/content/ui/popup.js | 
| @@ -0,0 +1,116 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <http://adblockplus.org/>, | 
| + * Copyright (C) 2006-2014 Eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +var backgroundPage = ext.backgroundPage.getWindow(); | 
| +window["openOptions"] = backgroundPage["openOptions"]; | 
| +var tab = null; | 
| + | 
| +function init() | 
| +{ | 
| +  // Mark page as local to hide non-relevant elements | 
| +  ext.windows.getLastFocused(function(win) | 
| +  { | 
| +    win.getActiveTab(function(t) | 
| +    { | 
| +      tab = t; | 
| +      document.body.classList.toggle("local", !/^https?:\/\//.test(tab.url)); | 
| +    }); | 
| +  }); | 
| + | 
| +  // Initialize features | 
| +  initClickHide(); | 
| +  initReportIssue(); | 
| +  initBlockable(); | 
| + | 
| +  document.getElementById("options").addEventListener("click", function() | 
| +  { | 
| +    openOptions(); | 
| +  }, false); | 
| +} | 
| +window.addEventListener("DOMContentLoaded", init, false); | 
| + | 
| +function initClickHide() | 
| +{ | 
| +  if (!("activateClickHide" in ext)) | 
| +    return; | 
| + | 
| +  var menuItemActivate = document.getElementById("clickhide"); | 
| +  menuItemActivate.addEventListener("click", activateClickHide, false); | 
| +  menuItemActivate.removeAttribute("hidden"); | 
| +  var menuItemCancel = document.getElementById("clickhide-cancel"); | 
| +  menuItemCancel.addEventListener("click", cancelClickHide, false); | 
| +  menuItemCancel.removeAttribute("hidden"); | 
| + | 
| +  // Ask content script whether clickhide is active. If so, show cancel button. | 
| +  ext.windows.getLastFocused(function(win) | 
| +  { | 
| +    win.getActiveTab(function(tab) | 
| +    { | 
| +      tab.sendMessage({type: "get-clickhide-state"}, function(response) | 
| +      { | 
| +        if (response && response.active) | 
| +          document.body.classList.add("clickhide-active"); | 
| +      }); | 
| +    }); | 
| +  }); | 
| +} | 
| + | 
| +function initReportIssue() | 
| +{ | 
| +  if (!("reportIssue" in ext) || !ext.showReportIssue()) | 
| +    return; | 
| + | 
| +  var menuItem = document.getElementById("report-issue"); | 
| +  menuItem.addEventListener("click", function() | 
| +  { | 
| +    ext.reportIssue(); | 
| +  }, false); | 
| +  menuItem.removeAttribute("hidden"); | 
| +} | 
| + | 
| +function initBlockable() | 
| +{ | 
| +  if (!ext.showBlockable()) | 
| +    return; | 
| + | 
| +  var menuItem = document.getElementById("blockable"); | 
| +  menuItem.addEventListener("click", function() | 
| +  { | 
| +    ext.openBlockable(); | 
| +  }, false); | 
| +  menuItem.removeAttribute("hidden"); | 
| +} | 
| + | 
| +function activateClickHide() | 
| +{ | 
| +  document.body.classList.add("clickhide-active"); | 
| +  ext.activateClickHide(true); | 
| + | 
| +  // Close the popup after a few seconds, so user doesn't have to | 
| +  activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); | 
| +} | 
| + | 
| +function cancelClickHide() | 
| +{ | 
| +  if (activateClickHide.timeout) | 
| +  { | 
| +    window.clearTimeout(activateClickHide.timeout); | 
| +    activateClickHide.timeout = null; | 
| +  } | 
| +  document.body.classList.remove("clickhide-active"); | 
| +  ext.activateClickHide(false); | 
| +} | 
|  |