- File
[Edit](notepad.htm#)[View](notepad.htm#)-
var browser; var area; var selectedText = ""; var selectionStart,selectionEnd; var isIE = false; var txt_hist,pos_hist,ihist,nhist,Nhist; var ctrlDown=false; var key={tabKey:9, ctrlKey:17, upKey:33, downKey:34, delKey:46, aKey:65, cKey:67, sKey:83, vKey:86, xKey:88, yKey:89, zKey:90};
window.onblur = function() { selectedText=""; LocalSave(); };
window.onunload = function() //$(window).unload( function() { LocalSave(); }; window.onload = function() //$(window).load( function() { //$("#area").width = area = document.getElementById("area"); txt_hist = new Array(); pos_hist = new Array(); Nhist = 10; nhist = 0; ihist = 0; browser = get_browser(); if (navigator.appName == 'Microsoft Internet Explorer') isIE = true; if( typeof(localStorage.notepad_text) == 'undefined' ) { if( typeof(localStorage.text) == 'undefined' ) localStorage.notepad_text = ''; else localStorage.notepad_text = localStorage.text; } area.value = localStorage.notepad_text; if( typeof(localStorage.notepad_fontSize) == 'undefined' ) { if( typeof(localStorage.fontSize) == 'undefined' ) localStorage.notepad_fontSize = 15; else localStorage.notepad_fontSize = localStorage.fontSize; } if( typeof(localStorage.notepad_filename) == 'undefined' ) localStorage.notepad_filename = ''; SetDocTitle(); SetFontSize(); window.onkeydown = keydown; window.onkeyup = keyup; Snapshot(); area.addEventListener('click', function() { pos = getCaret(); if( pos!=pos_hist[ihist] ) Snapshot(); }, false); };
function keydown(e) { OSName = GetOS(); if( OSName=="MacOS" ) { if( browser=='Firefox' && e.keyCode==224 ) ctrlDown=true; else if( browser=='Chrome' && (e.keyCode==91 || e.keyCode==93)) ctrlDown=true; else if( browser=='Opera' && e.keyCode==key.ctrlKey ) ctrlDown=true; } else if( e.keyCode==key.ctrlKey ) { ctrlDown=true; } if( ctrlDown ) { if( e.keyCode==key.aKey ) { area.focus(); } if( e.keyCode==key.sKey ) { e.preventDefault(); Save(); } // Ctrl+Z if( e.keyCode==key.zKey ) { e.preventDefault(); Undo(); } // Ctrl+Y if( e.keyCode==key.yKey ) { e.preventDefault(); Redo(); } // Ctrl+C if( e.keyCode==key.cKey ) { //e.preventDefault(); Copy(); } // Ctrl+V if( e.keyCode==key.vKey ) { if( selectedText.length!=0 ) e.preventDefault(); Paste(); } // Ctrl+X if( e.keyCode==key.xKey ) { //e.preventDefault(); Cut(); } } // page up/down if( e.keyCode==key.upKey || e.keyCode==key.downKey ) { area.focus(); } // tab if( e.keyCode==key.tabKey ) { e.preventDefault(); Snapshot(); s = getSelect(area); var text = area.value; fillString(text, '\u0009', s.start, s.end); pos = s.start+1; setCaret(pos); } // delete if( e.keyCode==key.delKey ) { Del2(); } } function keyup(e) { if( e.keyCode==key.ctrlKey ) { ctrlDown=false; } } function Print() { childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes'); childWindow.document.open(); childWindow.document.write(''); childWindow.document.write(document.getElementById('area').value.replace(/\n/gi,'
')); childWindow.document.write('