Skip to content

Commit c30abf4

Browse files
committed
bugfixes mostly
1 parent 46a491e commit c30abf4

File tree

11 files changed

+607
-195
lines changed

11 files changed

+607
-195
lines changed

javascripts/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var extData = {
1717
API : true,
1818
CM : true,
1919
Timestamp : true,
20-
GA : true
20+
GA : true,
2121
alertExc : true
2222
},
2323

javascripts/lib/codemirror1/editor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ var Editor = (function(){
552552
},
553553

554554
checkLine: function(node) {
555-
if (node === false || !(node == null || node.parentNode == this.container || node.hackBR))
555+
if (node === false || !(node == null || node.parentNode == this.container || node.hackBR)) {
556556
throw parent.CodeMirror.InvalidLineHandle;
557+
}
557558
},
558559

559560
cursorPosition: function(start) {

javascripts/options.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
var SM = new SimplenoteSM();
2-
31
$(document).ready(function() {
42

5-
$("#email").val(SM.email != undefined?SM.email:"");
6-
$("#password").val(SM.password != undefined?SM.password:"");
3+
$("#email").val(SimplenoteSM.email() != undefined?SimplenoteSM.email():"");
4+
$("#password").val(SimplenoteSM.password() != undefined?SimplenoteSM.password():"");
75

86
$("#abstractlines").val(localStorage.option_abstractlines == undefined?"3":localStorage.option_abstractlines);
97

@@ -36,7 +34,9 @@ $(document).ready(function() {
3634
$("#editorfontsize").val(localStorage.option_editorfontsize);
3735
}
3836

39-
setCBval("#editorfontshadow", localStorage.option_editorfontshadow != undefined && localStorage.option_editorfontshadow == "true");
37+
if (localStorage.option_editorfontshadow != undefined) {
38+
$("#editorfontshadow").val(localStorage.option_editorfontshadow);
39+
}
4040

4141
// if (localStorage.option_aes_enable!= undefined && localStorage.option_aes_enable == "true")
4242
// $("#aes_enable").attr("checked","true");
@@ -80,20 +80,13 @@ $(document).ready(function() {
8080
$("#save").click(save_clicked);
8181
$("#clear").click(clear_clicked);
8282
$("#reset").click(reset_clicked);
83-
$("#donate").click(function () { _gaq.push(['_trackEvent', 'Options', 'donate_clicked']); });
83+
$("#donate").click(function () {_gaq.push(['_trackEvent', 'Options', 'donate_clicked']);});
8484

8585
get_manifest(function (mf) {
8686
$("#version").html(mf.version);
8787
});
8888

89-
(function() {
90-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
91-
if (extData.debugFlags.GA)
92-
ga.src = 'https://ssl.google-analytics.com/u/ga_debug.js';
93-
else
94-
ga.src = 'https://ssl.google-analytics.com/ga.js';
95-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
96-
})();
89+
scheduleGA();
9790

9891
});
9992

@@ -165,7 +158,7 @@ function save_options() {
165158
localStorage.option_editorfont = $("#editorfont").val();
166159
localStorage.option_editorfontsize = $("#editorfontsize").val();
167160
// font stuff
168-
var fontinfo = { size: localStorage.option_editorfontsize + "px", letter_spacing: "0em", word_spacing: "0em", line_height: "1.5"};
161+
var fontinfo = {size: localStorage.option_editorfontsize + "px", letter_spacing: "0em", word_spacing: "0em", line_height: "1.5"};
169162
switch (localStorage.option_editorfont) {
170163
case "Droid Sans Mono":
171164
fontinfo.family = "Droid Sans Mono";
@@ -185,7 +178,7 @@ function save_options() {
185178
}
186179

187180
// font shadow
188-
localStorage.option_editorfontshadow = getCBval('#editorfontshadow');
181+
localStorage.option_editorfontshadow = $('#editorfontshadow').val();
189182

190183
localStorage.option_color_index = $('#color_index').val();
191184
localStorage.option_color_editor = $('#color_editor').val();
@@ -210,7 +203,7 @@ function save_clicked() {
210203

211204
$("#save").attr("disabled","disabled");
212205

213-
if (email == SM.email && password == SM.password) {
206+
if (email == SimplenoteSM.email() && password == SimplenoteSM.password() && SimplenoteSM.credentialsValid()) {
214207
$("#loginmessage").html("");
215208
$("#loginmessage").css("color","black");
216209
$("#save").removeAttr("disabled");
@@ -235,20 +228,20 @@ function save_clicked() {
235228

236229
_gaq.push(['_trackEvent', 'Options', 'save_clicked']);
237230

238-
if (email != SM.email && (localStorage._syncKeys)) {
231+
if (email != SimplenoteSM.email() && (localStorage._syncKeys)) {
239232
if (!confirm("You are about to switch your Simplenote login!\n\nThere are notes stored locally that have not been synchronized to the server.\n\nIf you switch accounts now, those changes will be lost.\n\nContinue?")) {
240233
$("#loginmessage").html("Changes not saved");
241234
$("#loginmessage").css("color","black");
242-
$("#email").val(SM.email);
243-
$("#password").val(SM.password);
235+
$("#email").val(SimplenoteSM.email());
236+
$("#password").val(SimplenoteSM.password());
244237
$("#save").removeAttr("disabled");
245238
_gaq.push(['_trackEvent', 'Options', 'save_clicked','synckeyspresent_reverted']);
246239
return;
247240
} else
248241
_gaq.push(['_trackEvent', 'Options', 'save_clicked','synckeyspresent_overridden']);
249242
}
250243

251-
SM.setLogin(email,password);
244+
SimplenoteSM.setLogin(email,password);
252245

253246
$("#loginmessage").html("Logging in..");
254247
$("#loginmessage").css("color","black");
@@ -288,7 +281,7 @@ function save_clicked() {
288281
}
289282
});
290283
} else {
291-
SM.clear();
284+
SimplenoteSM.clear();
292285

293286
if (successObj.reason=="timeout") {
294287
_gaq.push(['_trackEvent', 'Options', 'save_clicked','login_timeout']);
@@ -321,6 +314,7 @@ function reset_clicked() {
321314

322315
closeTabAnd(function() {
323316
localStorage.clear();
317+
chrome.extension.getBackgroundPage().location.reload();
324318
window.location.reload();
325319
});
326320
}

javascripts/popup.js

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ $.extend(extData,{
5858
// ---------------------------------------
5959

6060
var snEditor;
61-
var snSM = new SimplenoteSM();
6261

6362
// ---------------------------------------
6463
function log(s) {
@@ -72,10 +71,9 @@ function log(s) {
7271
// event listener for popup close
7372
// defer save to background
7473
addEventListener("unload", unloadListener, true);
75-
7674
function unloadListener() {
7775
try {
78-
if (snEditor.isNoteDirty()) {
76+
if (snEditor && snEditor.isNoteDirty()) {
7977
var note = {};
8078
log("(unload): requesting background save");
8179

@@ -104,7 +102,8 @@ function unloadListener() {
104102
} else
105103
log("(unload): no background save");
106104

107-
snEditor.saveCaretScroll();
105+
if (snEditor)
106+
snEditor.saveCaretScroll();
108107

109108
if (extData.isTab)
110109
extData.background.SimplenoteBG.setOpenPopup(true);
@@ -175,7 +174,7 @@ function uiEventListener(eventData, sender, sendResponse) {
175174
snEditor.needCMRefresh("pinned");
176175

177176
fillTags(false);
178-
snEditor.hideIfNotInIndex();
177+
snEditor.hideIfNotInIndex(eventData.newnote.key);
179178
} else if (undeleted) {
180179
log("EventListener:noteupdated: undeleted");
181180
if (noteRowInIndex(eventData.newnote.key)) {
@@ -186,7 +185,7 @@ function uiEventListener(eventData, sender, sendResponse) {
186185
snEditor.needCMRefresh("pinned");
187186

188187
fillTags(false);
189-
snEditor.hideIfNotInIndex();
188+
snEditor.hideIfNotInIndex(eventData.newnote.key);
190189
} else if (eventData.changes.changed.indexOf("tags")>=0) {
191190
log("EventListener:noteupdated:tags");
192191
fillTags(true);
@@ -247,7 +246,7 @@ function uiEventListener(eventData, sender, sendResponse) {
247246
log("EventListener:notedeleted:" + eventData.key);
248247
$('div.noterow#' + eventData.key).remove();
249248
fillTags(false);
250-
snEditor.hideIfNotInIndex();
249+
snEditor.hideIfNotInIndex(eventData.key);
251250
} else {
252251
log("EventListener:");
253252
log(eventData);
@@ -368,7 +367,7 @@ function readyListener() {
368367
extData.times.ready = (new Date())-start;
369368

370369
try {
371-
370+
372371
extData.background = chrome.extension.getBackgroundPage();
373372
chrome.browserAction.setBadgeText({
374373
text:""
@@ -395,19 +394,19 @@ function readyListener() {
395394
var signUpLink = "<a href='https://simple-note.appspot.com/create/'>" + chrome.i18n.getMessage("signup") + "</a>";
396395
var optionsLink = "<a href='options.html'>" + chrome.i18n.getMessage("options_page") + "</a>";
397396

398-
if ( !snSM.haveLogin() ) {
397+
if ( !SimplenoteSM.haveLogin() ) {
399398

400399
_gaq.push(['_trackEvent', 'popup', 'ready', 'no_email_or_password']);
401400

402401
log("(ready): no email or password");
403402
displayStatusMessage(chrome.i18n.getMessage("welcometext", [signUpLink, optionsLink]));
404403

405-
} else if ( !snSM.credentialsValid ) {
404+
} else if ( !SimplenoteSM.credentialsValid() ) {
406405

407406
_gaq.push(['_trackEvent', 'popup', 'ready', 'credentails_not_valid']);
408407

409408
log("(ready): credentials not valid");
410-
displayStatusMessage("Login for email '" + snSM.email + "' failed, please check your Simplenote email address and password on the " + optionsLink + "!");
409+
displayStatusMessage("Login for email '" + SimplenoteSM.email() + "' failed, please check your Simplenote email address and password on the " + optionsLink + "!");
411410

412411
} else {
413412
extData.times.startsetup = (new Date())-start;
@@ -455,9 +454,13 @@ function readyListener() {
455454
fillTags(true);
456455
// bind ADD button
457456
$('div#index div#toolbar div#add').click(function(event) {
458-
457+
459458
if (event.shiftKey) {
460459
_gaq.push(['_trackEvent', 'popup', 'addwebnoteclicked']);
460+
461+
if (extData.isTab) {
462+
return;
463+
}
461464
chrome.extension.sendRequest({
462465
action: "webnotes",
463466
request: {
@@ -476,7 +479,12 @@ function readyListener() {
476479

477480
// bind ADD WEBNOTE button
478481
$('div#index div#toolbar div#add_webnote').click(function(event) {
482+
483+
if (extData.isTab)
484+
return;
485+
479486
_gaq.push(['_trackEvent', 'popup', 'addwebnoteclicked']);
487+
480488
chrome.extension.sendRequest({
481489
action: "webnotes",
482490
request: {
@@ -612,14 +620,7 @@ function readyListener() {
612620

613621
}
614622

615-
setTimeout(function() {
616-
var ga = document.createElement('script');ga.type = 'text/javascript';ga.async = true;
617-
if (extData.debugFlags.GA)
618-
ga.src = 'https://ssl.google-analytics.com/u/ga_debug.js';
619-
else
620-
ga.src = 'https://ssl.google-analytics.com/ga.js';
621-
var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga, s);
622-
},10);
623+
scheduleGA();
623624

624625
} catch (e) {
625626
exceptionCaught(e);
@@ -828,7 +829,7 @@ function noteRowCMfn(contextmenu) {
828829
function(note) {
829830
chrome.extension.sendRequest({action : "delete", key : note.key},
830831
function() {
831-
snEditor.hideIfNotInIndex();
832+
snEditor.hideIfNotInIndex(key);
832833
snHelpers.checkInView();
833834
});
834835
});
@@ -851,7 +852,7 @@ function noteRowCMfn(contextmenu) {
851852
if (confirm("Permanently delete note '" + notename + "'?"))
852853
chrome.extension.sendRequest({action : "delete", key : $(this).attr("id")},
853854
function() {
854-
snEditor.hideIfNotInIndex();
855+
snEditor.hideIfNotInIndex(key);
855856
snHelpers.checkInView();
856857
});
857858
},
@@ -1084,7 +1085,8 @@ function indexFillNoteReqComplete(note) {
10841085
$noterow.addClass("fullhit")
10851086
}
10861087
$noteheading.html(heading); // dont need more than 100 chars
1087-
$noteheading.attr("title",headingtext);
1088+
if (headingtext.length > 25)
1089+
$noteheading.attr("title",headingtext);
10881090

10891091
// deleted note css style
10901092
if (note.deleted == 1) {
@@ -1127,9 +1129,6 @@ function indexFillNoteReqComplete(note) {
11271129
$noteabstract.prepend("[" + url + "]<br>");
11281130
if (note.deleted == 0) {
11291131
$("#" + note.key + "webnoteicon").attr("title",chrome.i18n.getMessage("webnote_icon",url));
1130-
1131-
//$("#" + note.key + "webnoteicon").tipTip({defaultPosition:"left"});
1132-
11331132
$("#" + note.key + "webnoteicon").bind("click",url,snHelpers.genericUrlOpenHandler);
11341133
}
11351134
}
@@ -1296,9 +1295,13 @@ SNEditor.prototype.setFont = function() {
12961295
}
12971296

12981297
// set font shadow
1299-
if (localStorage.option_editorfontshadow && localStorage.option_editorfontshadow == "true")
1300-
$editbox.css("text-shadow","0px 0px 1px #ccc" );
1301-
1298+
if (localStorage.option_editorfontshadow && localStorage.option_editorfontshadow != "false") {
1299+
if (localStorage.option_editorfontshadow == "true")
1300+
$editbox.css("text-shadow","0px 0px 1px #ccc" );
1301+
else
1302+
$editbox.css("text-shadow", localStorage.option_editorfontshadow);
1303+
}
1304+
//
13021305
// set colors
13031306
if (localStorage.option_color_editor)
13041307
$editbox.css("background-color",localStorage.option_color_editor);
@@ -1531,9 +1534,11 @@ SNEditor.prototype.restoreCaretScroll = function (caretScroll) {
15311534
var lineH;
15321535
if (caretScroll.line == "lastline")
15331536
lineH = this.codeMirror.lastLine();
1534-
else
1537+
else {
15351538
lineH = this.codeMirror.nthLine(caretScroll.line);
1536-
1539+
if (!lineH)
1540+
lineH = this.codeMirror.lastLine();
1541+
}
15371542
var character = Math.min(this.codeMirror.lineContent(lineH).length,caretScroll.character);
15381543

15391544
// cs2str("target ",caretScroll);
@@ -1586,7 +1591,7 @@ SNEditor.prototype.searchForSelection = function () {
15861591
}
15871592

15881593
// ---------------------------------------
1589-
SNEditor.prototype.hideIfNotInIndex = function () {
1594+
SNEditor.prototype.hideIfNotInIndex = function (key) {
15901595
if (!extData.isTab)
15911596
return;
15921597

@@ -1597,18 +1602,19 @@ SNEditor.prototype.hideIfNotInIndex = function () {
15971602
return "";
15981603
else
15991604
return this.id;
1600-
}).get();
1605+
}).filter(function(e) {return e.id != "";}).get();
16011606

16021607
if (!this.note || (this.note.key != "" && keys.indexOf(this.note.key)<0)) {
1603-
if (keys.length > 0)
1604-
chrome.extension.sendRequest({action:"note", key:keys[0]}, function(note) {
1608+
if (keys.length > 0) {
1609+
key = key?key:keys[0];
1610+
chrome.extension.sendRequest({action:"note", key:key}, function(note) {
16051611
if (note.deleted != 1) {
16061612

16071613
//that.setNote(note,{focus:false});
16081614
} else
16091615
$("div#note").hide();
16101616
});
1611-
else
1617+
} else
16121618
$("div#note").hide();
16131619
} else if (this.note)
16141620
this.show();
@@ -1742,6 +1748,9 @@ SNEditor.prototype.setNote = function(note, options) {
17421748
}
17431749

17441750
that.$CMbody().one("focus", function() {
1751+
if (!that.note)
1752+
return;
1753+
17451754
if (that.note.key)
17461755
that.restoreCaretScroll();
17471756
else if (options.isnewnote)

0 commit comments

Comments
 (0)