| Index: lib/survey.js | 
| =================================================================== | 
| --- a/lib/survey.js | 
| +++ b/lib/survey.js | 
| @@ -6,60 +6,32 @@ | 
| let {Prefs} = require("prefs"); | 
| -let win = null; | 
| let surveyLang = null; | 
| -let surveyUrl = "http://urlfixer.org"; //"http://adblockplus.org/usersurvey/index.php?sid=68316"; | 
| - | 
| -let langData = { | 
| - en: { | 
| - title: "Tell us your opinion", | 
| - question: "We would like to ask you a few questions about URL Fixer to help us improve it. If you can spare 5 minutes please click the button below to take the survey.", | 
| - note: "This is a one-time message and will not appear again.", | 
| - accept: "Take the survey", | 
| - decline: "Maybe some other time" | 
| - }, | 
| - de: { | 
| - title: "Sagen Sie uns Ihre Meinung", | 
| - question: "Wir w\xFCrden Ihnen gerne einige Fragen zu URL Fixer stellen, um es verbessern zu k\xF6nnen. Falls Sie gerade 5 Minuten haben, dr\xFCcken Sie bitte die Taste unten, um an der Nutzerumfrage teilzunehmen.", | 
| - note: "Das ist eine einmalige Nachricht, die nicht wieder erscheinen wird.", | 
| - accept: "An der Umfrage teilnehmen", | 
| - decline: "Vielleicht ein anderes Mal" | 
| - }, | 
| - ru: { | 
| - title: decodeURIComponent("%D0%9F%D0%BE%D0%B4%D0%B5%D0%BB%D0%B8%D1%82%D0%B5%D1%81%D1%8C%20%D1%81%20%D0%BD%D0%B0%D0%BC%D0%B8%20%D1%81%D0%B2%D0%BE%D0%B8%D0%BC%20%D0%BC%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5%D0%BC"), | 
| - question: decodeURIComponent("%D0%9C%D1%8B%20%D1%85%D0%BE%D1%82%D0%B5%D0%BB%D0%B8%20%D0%B1%D1%8B%20%D0%B7%D0%B0%D0%B4%D0%B0%D1%82%D1%8C%20%D0%B2%D0%B0%D0%BC%20%D0%BD%D0%B5%D0%BA%D0%BE%D1%82%D0%BE%D1%80%D1%8B%D0%B5%20%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81%D1%8B%20%D0%BE%D0%B1%20URL%20Fixer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%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B5%20%D0%BD%D0%B5%20%D0%B1%D1%83%D0%B4%D0%B5%D1%82%20%D0%BF%D0%BE%D0%BA%D0%B0%D0%B7%D1%8B%D0%B2%D0%B0%D1%82%D1%8C%D1%81%D1%8F."), | 
| - accept: decodeURIComponent("%D0%9F%D1%80%D0%B8%D0%BD%D1%8F%D1%82%D1%8C%20%D1%83%D1%87%D0%B0%D1%81%D1%82%D0%B8%D0%B5%20%D0%B2%20%D0%BE%D0%BF%D1%80%D0%BE%D1%81%D0%B5"), | 
| - decline: decodeURIComponent("%D0%9C%D0%BE%D0%B6%D0%B5%D1%82%20%D0%B2%20%D0%B4%D1%80%D1%83%D0%B3%D0%BE%D0%B9%20%D1%80%D0%B0%D0%B7") | 
| - } | 
| -}; | 
| +let surveyUrl = null; //"http://urlfixer.org/usersurvey/..."; | 
| exports.incrementCorrectionsCounter = incrementCorrectionsCounter; | 
| -function incrementCorrectionsCounter(window) | 
| +function incrementCorrectionsCounter() | 
| { | 
| - let count = typeof(Prefs.corrections_count)!="undefined" && JSON.parse(Prefs.corrections_count) || 0; | 
| + // Only if survey exists | 
| + if (!surveyUrl) | 
| + return; | 
| // Only users with 5 URL corrections | 
| - if(++count == 5) | 
| + if (++Prefs.corrections_count == 5) | 
| { | 
| - initSurvey(window); | 
| + initSurvey(); | 
| } | 
| - | 
| - Prefs.corrections_count = count; | 
| } | 
| -function initSurvey(window) | 
| +function initSurvey() | 
| { | 
| - // Don't do anything on Fennec. | 
| - if ("Browser" in window || "BrowserApp" in window) | 
| - return; | 
| - | 
| // Don't ask after 2012-10-15 | 
| if (Date.now() > 1350259200000) | 
| return; | 
| // Only Firefox users | 
| - if (Services.appinfo.ID != "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}") | 
| + let {application} = require("info"); | 
| + if (application != "firefox") | 
| return; | 
| // Only Firefox 4 and higher | 
| @@ -74,26 +46,56 @@ | 
| // Delay survey question by 5 seconds | 
| surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 
| surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); | 
| - | 
| - win = window; | 
| } | 
| function runSurvey() | 
| { | 
| - win.openDialog("chrome://url-fixer/content/survey.xul", "survey", "top=100,left=300,chrome,dialog,dependent"); | 
| + //open panel | 
| + let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); | 
| + request.open("GET", "chrome://url-fixer/content/survey.xul"); | 
| + request.addEventListener("load", function(event) | 
| + { | 
| + let window = Services.wm.getMostRecentWindow("navigator:browser"); | 
| + let document = window.document; | 
| + | 
| + let style = document.createProcessingInstruction('xml-stylesheet', 'href="chrome://url-fixer/skin/survey.css" type="text/css"'); | 
| + document.insertBefore(style, document.firstChild); | 
| + | 
| + let panel = new window.DOMParser().parseFromString(request.responseText, "text/xml").documentElement; | 
| + let oldPanel = document.getElementById(panel.id); | 
| + if (oldPanel) | 
| + oldPanel.parentNode.removeChild(oldPanel); | 
| + document.getElementById("mainPopupSet").appendChild(panel); | 
| + document.getElementById("url-fixer-icon").setAttribute("src", require("info").addonRoot + "icon64.png"); | 
| + document.getElementById("url-fixer-accept-button").addEventListener("command", function() | 
| + { | 
| + openSurvey(); | 
| + panel.hidePopup(); | 
| + }); | 
| + document.getElementById("url-fixer-cancel-button").addEventListener("command", function() | 
| + { | 
| + panel.hidePopup(); | 
| + }); | 
| + panel.addEventListener("popuphidden", function() | 
| + { | 
| + panel.parentNode.removeChild(panel); | 
| 
 
Wladimir Palant
2012/09/28 13:31:26
Please remove the style node as well.
 
 | 
| + }); | 
| + | 
| + let anchor = document.getElementById("identity-box"); | 
| + panel.openPopup(anchor, "after_start", 0, 0, false, true); | 
| + }, false); | 
| + request.send(null); | 
| } | 
| -exports.openSurvey = openSurvey; | 
| function openSurvey() | 
| { | 
| - require("appIntegration").getBrowser(win).loadOneTab(surveyUrl + "&lang=" + surveyLang, { | 
| - referrerURI: Services.io.newURI("http://url.fixer/", null, null), | 
| - inBackground: false | 
| - }); | 
| + let window = Services.wm.getMostRecentWindow("navigator:browser"); | 
| + if (window) | 
| + { | 
| + let browser = require("appIntegration").getBrowser(window); | 
| + browser.loadOneTab(surveyUrl + "&lang=" + surveyLang, { | 
| + referrerURI: Services.io.newURI("http://url.fixer/", null, null), | 
| + inBackground: false | 
| + }); | 
| + } | 
| } | 
| - | 
| -exports.getSurveyDialogTexts = getSurveyDialogTexts; | 
| -function getSurveyDialogTexts() | 
| -{ | 
| - return langData[surveyLang]; | 
| -} |