зеркало из https://github.com/mozilla/lightbeam.git
[Issue #336] code cleanup and bug fixes
This commit is contained in:
Родитель
c40a9e98b2
Коммит
ef84e3f661
|
@ -220,7 +220,6 @@ function stopSharing(callback){
|
||||||
'<p>By clicking OK you will no longer be uploading data.</p>'
|
'<p>By clicking OK you will no longer be uploading data.</p>'
|
||||||
},
|
},
|
||||||
function(confirmed){
|
function(confirmed){
|
||||||
console.log(confirmed);
|
|
||||||
if ( confirmed ){
|
if ( confirmed ){
|
||||||
localStorage.userHasOptedIntoSharing = false;
|
localStorage.userHasOptedIntoSharing = false;
|
||||||
if (uploadTimer){
|
if (uploadTimer){
|
||||||
|
|
|
@ -424,7 +424,11 @@ var listStageStackClickHandler = function(event){
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}else if (target.mozMatchesSelector('.hide-pref.active a')){
|
}else if (target.mozMatchesSelector('.hide-pref.active a')){
|
||||||
dialog( { "name": "hideDialog",
|
var hideDialogName = "hideDialog";
|
||||||
|
if ( doNotShowDialog(hideDialogName) ){
|
||||||
|
setPreferences('hide');
|
||||||
|
}else{
|
||||||
|
dialog( { "name": hideDialogName,
|
||||||
"dnsPrompt": true,
|
"dnsPrompt": true,
|
||||||
"title": "Hide Sites",
|
"title": "Hide Sites",
|
||||||
"message": "<p>These sites will not be shown in Collusion visualizations, including List View, unless you specifically toggle them back on with the Show Hidden Sites button.</p>" +
|
"message": "<p>These sites will not be shown in Collusion visualizations, including List View, unless you specifically toggle them back on with the Show Hidden Sites button.</p>" +
|
||||||
|
@ -435,6 +439,7 @@ var listStageStackClickHandler = function(event){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}else if (target.mozMatchesSelector('.watch-pref.active a')){
|
}else if (target.mozMatchesSelector('.watch-pref.active a')){
|
||||||
setPreferences('watch');
|
setPreferences('watch');
|
||||||
}else if(target.mozMatchesSelector('.no-pref.active a')){
|
}else if(target.mozMatchesSelector('.no-pref.active a')){
|
||||||
|
|
79
data/ui.js
79
data/ui.js
|
@ -387,51 +387,78 @@ function legendBtnClickHandler(legendElm){
|
||||||
|
|
||||||
// options: name, title, message, type, dnsPrompt(Do Not Show)
|
// options: name, title, message, type, dnsPrompt(Do Not Show)
|
||||||
function dialog(options,callback){
|
function dialog(options,callback){
|
||||||
var dnsPref = localStorage.dnsDialogs || "[]";
|
if ( doNotShowDialog(options.name) ) return; // according to user pref, do not show this dialog
|
||||||
dnsPref = JSON.parse(dnsPref);
|
createDialog(options,callback);
|
||||||
if ( dnsPref.indexOf(options.name) > -1 ) return; // according to user pref, do not show this dialog
|
|
||||||
showDialog(options,dnsPref,callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showDialog(options,dnsPref,callback){
|
function doNotShowDialog(dialogName){
|
||||||
|
var dnsPref = localStorage.dnsDialogs || "[]";
|
||||||
|
dnsPref = JSON.parse(dnsPref);
|
||||||
|
return ( dnsPref.indexOf(dialogName) > -1 ) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDialog(options,callback){
|
||||||
var titleBar = "<div class='dialog-title'>" + (options.title || " ") + "</div>";
|
var titleBar = "<div class='dialog-title'>" + (options.title || " ") + "</div>";
|
||||||
var messageBody = "<div class='dialog-message'>" + (options.message || " ") + "</div>";
|
var messageBody = "<div class='dialog-message'>" + (options.message || " ") + "</div>";
|
||||||
var controls = "<div class='dialog-controls'>"+
|
var childElems = "";
|
||||||
"<div class='dialog-dns hidden'><input type='checkbox' /> Do not show this again.</div>" +
|
if ( options.dnsPrompt ){ // show Do Not Show Again prompt
|
||||||
"<div class='pico-close dialog-cancel'>Cancel</div>" +
|
childElems += "<div class='dialog-dns'><input type='checkbox' /> Do not show this again.</div>";
|
||||||
"<div class='pico-close dialog-ok'>OK</div>" +
|
}
|
||||||
"</div>";
|
if ( navigator.appVersion.indexOf("Win") > -1 ){ // runs on Windows
|
||||||
|
childElems += "<div class='pico-close dialog-cancel'>Cancel</div>";
|
||||||
|
childElems += "<div class='pico-close dialog-ok'>OK</div>";
|
||||||
|
}else{
|
||||||
|
childElems += "<div class='pico-close dialog-ok'>OK</div>";
|
||||||
|
childElems += "<div class='pico-close dialog-cancel'>Cancel</div>";
|
||||||
|
}
|
||||||
|
var controls = "<div class='dialog-controls'>" + childElems + "</div>";
|
||||||
|
|
||||||
|
// create dialog
|
||||||
var modal = picoModal({
|
var modal = picoModal({
|
||||||
content: titleBar + messageBody + controls,
|
content: titleBar + messageBody + controls,
|
||||||
closeButton: false,
|
closeButton: false,
|
||||||
overlayClose: false,
|
overlayClose: false,
|
||||||
// width: 400,
|
|
||||||
overlayStyles: {
|
overlayStyles: {
|
||||||
backgroundColor: "#000",
|
backgroundColor: "#000",
|
||||||
opacity: 0.75
|
opacity: 0.75
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( options.dnsPrompt ){ // show Do Not Show Again prompt
|
|
||||||
document.querySelector(".dialog-dns").classList.remove("hidden");
|
|
||||||
}
|
|
||||||
if ( options.type == "alert" ){
|
if ( options.type == "alert" ){
|
||||||
document.querySelector(".dialog-cancel").classList.add("hidden");
|
document.querySelector(".dialog-cancel").classList.add("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
toArray(document.querySelectorAll(".pico-close")).forEach(function(btn){
|
addDialogEventHandlers(modal,options,function(userResponse){
|
||||||
btn.addEventListener("click", function(event){
|
callback(userResponse);
|
||||||
if ( options.dnsPrompt && (event.target.innerHTML == "OK") ){ // Do Not Show
|
|
||||||
var checked = document.querySelector(".dialog-dns input").checked;
|
|
||||||
if ( checked ){ // user does not want this dialog to show again
|
|
||||||
dnsPref.push(options.name);
|
|
||||||
localStorage.dnsDialogs = JSON.stringify(dnsPref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modal.close();
|
|
||||||
callback( (event.target.innerHTML == "OK") ? true : false );
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addDialogEventHandlers(modal,options,callback){
|
||||||
|
// press Esc to close the dialog (functions the same as clicking Cancel)
|
||||||
|
var escapeDialogKeyHandler = function(e){
|
||||||
|
if ( e.keyCode == "27" ){ // Esc key pressed
|
||||||
|
modal.close();
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener("keydown", escapeDialogKeyHandler);
|
||||||
|
modal.onClose(function(){
|
||||||
|
document.removeEventListener("keydown", escapeDialogKeyHandler);
|
||||||
|
});
|
||||||
|
// OK button click event handler
|
||||||
|
document.querySelector(".pico-close.dialog-ok").addEventListener("click",function(){
|
||||||
|
if ( document.querySelector(".dialog-dns input") && document.querySelector(".dialog-dns input").checked ){ // Do Not Show
|
||||||
|
var dnsPref = localStorage.dnsDialogs || "[]";
|
||||||
|
dnsPref = JSON.parse(dnsPref);
|
||||||
|
dnsPref.push(options.name);
|
||||||
|
localStorage.dnsDialogs = JSON.stringify(dnsPref);
|
||||||
|
}
|
||||||
|
modal.close();
|
||||||
|
callback(true);
|
||||||
|
});
|
||||||
|
// Cancel button click event handler
|
||||||
|
document.querySelector(".pico-close.dialog-cancel").addEventListener("click",function(){
|
||||||
|
modal.close();
|
||||||
|
callback(false);
|
||||||
|
});
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче