@@ -58,7 +58,6 @@ $.extend(extData,{
5858// ---------------------------------------
5959
6060var snEditor ;
61- var snSM = new SimplenoteSM ( ) ;
6261
6362// ---------------------------------------
6463function log ( s ) {
@@ -72,10 +71,9 @@ function log(s) {
7271// event listener for popup close
7372// defer save to background
7473addEventListener ( "unload" , unloadListener , true ) ;
75-
7674function 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