Skip to content

Commit

Permalink
v3.1.1-
Browse files Browse the repository at this point in the history
   - added window size as a configurable and persistent option
   - added highlight to move/delete buttons on hover
   - fixed issue with error displaying when a note title starts with a number
   - fixed issue with horizontal scroll bar sometimes appearing
  • Loading branch information
freginold authored Dec 7, 2016
1 parent 9d03376 commit 239dc4f
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 21 deletions.
3 changes: 3 additions & 0 deletions _note.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ h4 {
padding-right: 0.2em;
vertical-align: middle;
}
.moveButtons:hover {
background: #dbdbdb;
}
.uBut {
margin-left: 1px;
margin-right: 2px;
Expand Down
113 changes: 106 additions & 7 deletions _note.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var coords = document.getElementById('coords');
var undeleteButton = document.getElementById('undeleteButton');
var statusBar = document.getElementById('statusBar');
var statusBarText = document.getElementById('statusBarText');
var defSize = document.getElementById('defSize');
var localFontDiv = [
document.getElementById('localFontDiv0'),
document.getElementById('localFontDiv1'),
Expand Down Expand Up @@ -81,6 +82,7 @@ var uneditedString = '';
var currentVer = 'Note v' + Note.version + '\nPublic Domain';
var timer = 0;
var lastScrollPos = 0;
var firstCall = true;
var currentNote, dummyVar, bgColor, i, currentX, currentY, oldX, oldY, offsetX, offsetY;
var lastLine, itemToEdit, itemTotal, statusTimer, prevNote;
var done;
Expand Down Expand Up @@ -191,7 +193,8 @@ function saveOptions() {
else { Opt9 = 'mm'; Opt10 = 0; Opt11 = 0; }
if (document.getElementsByName('statusOption')[0].checked) { Opt12 = 'hide'; }
else { Opt12 = 'show'; }
WriteOptions()

WriteOptions();
applyOptions();
showOptions();
}
Expand All @@ -206,14 +209,20 @@ function savePos() {
if (optionsDiv.style.display != 'none') { showOptions(); }
}

function saveSize() {
// stripped-down save function to only save screen size -- will combine this w/ savePos in the future
WriteOptions();
if (optionsDiv.style.display != 'none') { showOptions(); }
}

function showOptions() {
clearAll();
noteBody.style.display='none';
noteTitle.innerText = 'Options:';
optionsDiv.style.display='block';
for (i = 0; i<document.getElementsByTagName('td').length; i++) {
if (document.getElementsByTagName('td')[i].className == 'optionsColumn') {
document.getElementsByTagName('td')[i].style.width = (document.documentElement.clientWidth / 3);
document.getElementsByTagName('td')[i].style.width = (document.body.clientWidth / 3);
}
}
switch (Opt2) {
Expand Down Expand Up @@ -270,12 +279,18 @@ function showOptions() {
else { document.getElementsByName('screenPos')[0].checked = true; }
if (Opt12 == 'hide') { document.getElementsByName('statusOption')[0].checked = true; }
else { document.getElementsByName('statusOption')[1].checked = true; }
if (Opt14 == NoteWidth && Opt15 == NoteHeight) {
// default width and height
document.getElementById('screenSizeResetButton').disabled = true;
}
checkCoords();
showCoords();
}

function clearAll() {
// clear all text/fields
firstCall = false;
setTimeout(function(){ firstCall = true; } , 250);
GetFileList()
newNoteDiv.style.display = 'none';
optionsDiv.style.display='none';
Expand Down Expand Up @@ -303,7 +318,7 @@ function showNotes(cNote) {
prevNote = currentNote;
currentNote = cNote;
editing = false;
window[currentNote].className='noteButton activeNote';
window[currentNote].className = 'noteButton activeNote';
var currentNoteDisplay = currentNote;
if (currentNote == "&") { currentNoteDisplay = "&#38;"; } // to deal w/ & as only char in title
noteTitle.innerHTML = "<div id='delBox'>" + renButtonHTML + delButtonHTML + "</div>" + currentNoteDisplay;
Expand Down Expand Up @@ -390,6 +405,7 @@ function createNewNote(newNoteName) {
newNoteName = checkForLeadingSpaces(newNoteName);
newNoteName = checkForTrailingSpaces(newNoteName);
if (newNoteName == '') { showNewNoteBox(); showStatus("No text entered"); return; }
if (checkFor1stCharNum(newNoteName.slice(0,1))) { return; } // if 1st char is a number
var fileCreated = CreateNewFile(newNoteName)
if (!!fileCreated) { showNotes(newNoteName); showStatus("New note, " + AbbrevText(newNoteName) + " created"); }
else { newNoteInputBox.value = ''; }
Expand Down Expand Up @@ -631,12 +647,87 @@ function getTime() {

function checkOverflow(thisLine) {
// check to see if just-added line causes horizontal scroll
if (noteBody.scrollWidth > noteBody.offsetWidth) {
if (noteBody.scrollWidth >= noteBody.offsetWidth) {
document.getElementById(thisLine).className = document.getElementById(thisLine).className + " overflowClass";
}

}

function getCurrentSize() {
// get current size w/ document.documentElement
var tempRect = document.documentElement.getBoundingClientRect();
Opt14 = tempRect.right - tempRect.left;
Opt15 = tempRect.bottom - tempRect.top;
if ((Opt14 == NoteWidth) && (Opt15 == NoteHeight)) { document.getElementById('screenSizeResetButton').disabled = true; }
else { document.getElementById('screenSizeResetButton').disabled = false; }
}

function checkSize() {
// get current window size
if (!firstCall) { return; }
firstCall = false;
var oldW = Opt14;
var oldH = Opt15;
getCurrentSize();
if ((oldW != Opt14) || (oldH != Opt15)) {
// size has changed
saveSize();
firstCall = true;
}
else { firstCall = true; }
}

function getDefaultSize() {
// get default width & height
window.resizeTo(NoteWidth, NoteHeight);
var tempRect = document.documentElement.getBoundingClientRect();
// NoteWidth = NoteWidth + (tempRect.right - tempRect.left - NoteWidth);
// NoteHeight = NoteHeight + (tempRect.bottom - tempRect.top - NoteHeight);
var percentW = (NoteWidth / (tempRect.right - tempRect.left));
var percentH = (NoteHeight / (tempRect.bottom - tempRect.top));
newOpt14 = Math.floor(NoteWidth * percentW);
newOpt15 = Math.floor(NoteHeight * percentH);
}

function resetSize() {
// reset window size
// Opt14 = NoteWidth;
// Opt15 = NoteHeight;
getDefaultSize();
correctSize();
window.resizeTo(NoteWidth, NoteHeight);
Opt14 = newOpt14;
Opt15 = newOpt15;
saveSize();
document.getElementById('screenSizeResetButton').disabled = true;
firstCall = true;
}

function correctSize() {
// to correct for getBoundingClientRect() and resizeTo() not matching up exactly
var tempRect = document.documentElement.getBoundingClientRect();
// Opt14 = tempRect.right - tempRect.left;
// Opt15 = tempRect.bottom - tempRect.top;
// Opt14 = Opt14 + (Opt14 - tempRect.right - tempRect.left);
// Opt15 = Opt15 + (Opt15 - tempRect.bottom - tempRect.top);
var percentW = (Opt14 / (tempRect.right - tempRect.left));
var percentH = (Opt15 / (tempRect.bottom - tempRect.top));
newOpt14 = Math.floor(Opt14 * percentW);
newOpt15 = Math.floor(Opt15 * percentH);
window.resizeTo(newOpt14, newOpt15); // set initial size
}

function checkFor1stCharNum(thisChar) {
// to see if 1st char of file name is a number
if (!isNaN(thisChar)) {
alert('The note title can not start with a number. If you want to use a number, you can prepend it with "#".');
return true;
}
else { return false; }
}

function showSize() { alert("O: " + Opt14 + " " + Opt15 + "\nDef: " + NoteWidth + " " + NoteHeight); }
// for testing


// ----------- declare event handlers ----------

Expand Down Expand Up @@ -696,6 +787,14 @@ noteBody.attachEvent('onscroll', function() { setTimeout(function(){lastScrollPo
clearAll();
getOffset();
applyOptions();
setPos();
getDefaultSize();
//Opt14 = NoteWidth;
//Opt15 = NoteHeight;
window.resizeTo(Opt14, Opt15); // set initial size
correctSize(); // to get correct window size
setPos(); // set initial position
var checkTimerInt = setInterval(checkTimer, 500);
getTime();
getTime();
setTimeout(function(){
window.attachEvent('onresize', checkSize); // to get new size when edges are dragged
}, 1000);
48 changes: 34 additions & 14 deletions _note.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
' 6. User Font 2
' 7. User Font 3
' 8. User Font 4
' 9. Screen Postion: mm-centered/cc-custom
' 9. Window Postion: mm-centered/cc-custom
' 10. Custom x coord
' 11. Custom y coord
' 12. Status Bar: hide/show
' 13. Backup Location: current folder or user choice
' 14. Window width
' 15. Window height


' ----- set up variables, constants, & objects ------

Option Explicit
Dim fs, NewFileWithPath, rfile, afile, tfile, rofile, line, BackupLoc
Dim Opt1, Opt2, Opt3, Opt4, Opt5, Opt6, Opt7, Opt8, Opt9, Opt10, Opt11, Opt12, Opt13
Dim Opt1, Opt2, Opt3, Opt4, Opt5, Opt6, Opt7, Opt8, Opt9, Opt10, Opt11, Opt12, Opt13, Opt14, Opt15
Dim NoteWidth, NoteHeight, MidXPos, MidYPos
Dim EditedString

Expand All @@ -38,6 +40,7 @@ Const Default10 = "0"
Const Default11 = "0"
Const Default12 = "show"
Const Default13 = ".\"
' no Default14/Default15; use NoteWidth & NoteHeight
Const OptionsFile = "config.txt"
Const EOFConst = "<<<EOF>>>"
Const BackupPrefix = "backup_notes_"
Expand All @@ -47,6 +50,13 @@ Const OptionsFileErrorMsg = "<br /><p style='vertical-align: middle; text-align:
Const InvalidFNMsg1 = "Invalid File Name."
Const InvalidFNMsg2 = "The following characters are prohibited:"

NewFileWithPath = ""
NoteWidth = round(screen.availWidth/1.5)
NoteHeight = round(screen.availHeight/1.31)
MidXPos = screen.availWidth/2 - NoteWidth/2
MidYPos = screen.availHeight/2 - NoteHeight/2
EditedString = ""

Opt1 = Default1
Opt2 = Default2
Opt3 = Default3
Expand All @@ -60,12 +70,8 @@ Opt10 = Default10
Opt11 = Default11
Opt12 = Default12
Opt13 = Default13
NewFileWithPath = ""
NoteWidth = screen.availWidth/1.6
NoteHeight = screen.availHeight/1.41
MidXPos = screen.availWidth/2 - NoteWidth/2
MidYPos = screen.availHeight/2 - NoteHeight/2
EditedString = ""
Opt14 = NoteWidth ' <-- get the correct values later, after determine default h&w
Opt15 = NoteHeight


' ------ subroutines & functions -----------
Expand Down Expand Up @@ -138,9 +144,9 @@ Function GetLine(dummyVar)
line = rfile.Readline
if LCase(Opt1) = "hide" then line = HideStamp(line)
' preserve spacing but don't prevent line breaking
line = Replace(line, " ", "&emsp;&ensp;")
line = Replace(line, " ", "&emsp;")
line = Replace(line, " ", "&ensp;")
line = Replace(line, " ", " ")
line = Replace(line, " ", " ")
line = Replace(line, " ", " ")
Case Else
line = EOFConst
End Select
Expand Down Expand Up @@ -234,6 +240,14 @@ Sub GetOptions(dummyVar)
if rofile.AtEndOfStream then rofile.close : OptionsCorrupted(12) : Exit Sub
Opt13 = rofile.Readline
if Opt13 = "" then Opt13 = Default13
' get option 14 - window width
if rofile.AtEndOfStream then rofile.close : OptionsCorrupted(13) : Exit Sub
Opt14 = int(rofile.Readline)
if Opt14 = "" then Opt14 = NoteWidth
' get option 15 - window height
if rofile.AtEndOfStream then rofile.close : OptionsCorrupted(14) : Exit Sub
Opt15 = int(rofile.Readline)
if Opt15 = "" then Opt15 = NoteHeight
' close file
rofile.close
Else
Expand All @@ -256,12 +270,16 @@ Function GetOption(ThisOption)
if ThisOption = "11" then GetOption = Opt11
if ThisOption = "12" then GetOption = Opt12
if ThisOption = "13" then GetOption = Opt13
if ThisOption = "14" then GetOption = Opt14
if ThisOption = "15" then GetOption = Opt15
End Function

Sub OptionsCorrupted(numCorr)
' if options file not present or not formatted correctly, pass in any missing values & recreate it
' numCorr = number of options loaded succesfully
if numCorr < 13 then Opt12 = Default13
if numCorr < 15 then Opt15 = NoteHeight
if numCorr < 14 then Opt14 = NoteWidth
if numCorr < 13 then Opt13 = Default13
if numCorr < 12 then Opt12 = Default12
if numCorr < 11 then Opt11 = Default11
if numCorr < 10 then Opt10 = Default10
Expand Down Expand Up @@ -296,6 +314,8 @@ Sub WriteOptions
tfile.WriteLine(Opt11)
tfile.WriteLine(Opt12)
tfile.WriteLine(Opt13)
tfile.WriteLine(Opt14)
tfile.WriteLine(Opt15)
tfile.close
if fs.FileExists(OptionsFile) then fs.DeleteFile(OptionsFile)
fs.MoveFile TempFile, OptionsFile
Expand Down Expand Up @@ -428,6 +448,8 @@ Sub RenameThisNote()
NewName = checkForTrailingSpaces(NewName)
if NewName = "" then showStatus("No text entered") : exit sub
if NewName = currentNote then showStatus("New name is same as current name") : exit sub
if IsNumeric(NewName) then checkFor1stCharNum(NewName) : exit sub
if checkFor1stCharNum(mid(NewName,1,1)) then exit sub
if CreateNewFile(NewName) = false then exit sub
OpenRFile(currentNote)
On Error Resume Next
Expand Down Expand Up @@ -580,7 +602,5 @@ End Function

' ---------- execution --------------

window.resizeTo NoteWidth, NoteHeight
CheckForNotesFolder()
CheckForOptionsFile()
GetFileList()
Loading

0 comments on commit 239dc4f

Please sign in to comment.