[Issue #336] code cleanup and bug fixes

This commit is contained in:
Mavis Ou 2013-08-01 12:33:02 -07:00
Родитель c40a9e98b2
Коммит ef84e3f661
3 изменённых файлов: 68 добавлений и 37 удалений

Просмотреть файл

@ -220,7 +220,6 @@ function stopSharing(callback){
'<p>By clicking OK you will no longer be uploading data.</p>'
},
function(confirmed){
console.log(confirmed);
if ( confirmed ){
localStorage.userHasOptedIntoSharing = false;
if (uploadTimer){

Просмотреть файл

@ -424,17 +424,22 @@ var listStageStackClickHandler = function(event){
}
);
}else if (target.mozMatchesSelector('.hide-pref.active a')){
dialog( { "name": "hideDialog",
"dnsPrompt": true,
"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>" +
"<p>You can use this to ignore trusted sites from the data.</p>"
},function(confirmed){
if ( confirmed ){
setPreferences('hide');
var hideDialogName = "hideDialog";
if ( doNotShowDialog(hideDialogName) ){
setPreferences('hide');
}else{
dialog( { "name": hideDialogName,
"dnsPrompt": true,
"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>" +
"<p>You can use this to ignore trusted sites from the data.</p>"
},function(confirmed){
if ( confirmed ){
setPreferences('hide');
}
}
}
);
);
}
}else if (target.mozMatchesSelector('.watch-pref.active a')){
setPreferences('watch');
}else if(target.mozMatchesSelector('.no-pref.active a')){

Просмотреть файл

@ -387,51 +387,78 @@ function legendBtnClickHandler(legendElm){
// options: name, title, message, type, dnsPrompt(Do Not Show)
function dialog(options,callback){
var dnsPref = localStorage.dnsDialogs || "[]";
dnsPref = JSON.parse(dnsPref);
if ( dnsPref.indexOf(options.name) > -1 ) return; // according to user pref, do not show this dialog
showDialog(options,dnsPref,callback);
if ( doNotShowDialog(options.name) ) return; // according to user pref, do not show this dialog
createDialog(options,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 || "&nbsp;") + "</div>";
var messageBody = "<div class='dialog-message'>" + (options.message || "&nbsp;") + "</div>";
var controls = "<div class='dialog-controls'>"+
"<div class='dialog-dns hidden'><input type='checkbox' /> Do not show this again.</div>" +
"<div class='pico-close dialog-cancel'>Cancel</div>" +
"<div class='pico-close dialog-ok'>OK</div>" +
"</div>";
var childElems = "";
if ( options.dnsPrompt ){ // show Do Not Show Again prompt
childElems += "<div class='dialog-dns'><input type='checkbox' /> Do not show this again.</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({
content: titleBar + messageBody + controls,
closeButton: false,
overlayClose: false,
// width: 400,
overlayStyles: {
backgroundColor: "#000",
opacity: 0.75
}
});
if ( options.dnsPrompt ){ // show Do Not Show Again prompt
document.querySelector(".dialog-dns").classList.remove("hidden");
}
if ( options.type == "alert" ){
document.querySelector(".dialog-cancel").classList.add("hidden");
}
toArray(document.querySelectorAll(".pico-close")).forEach(function(btn){
btn.addEventListener("click", function(event){
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 );
});
addDialogEventHandlers(modal,options,function(userResponse){
callback(userResponse);
});
}
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);
});
}