From 5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 15 Oct 2005 20:44:04 +0200 Subject: more unobstrusive javascript The edit form now is free of inline event handlers. There are still other places where inline javascript and even document.write is used which should be fixed as well. Currently the window.onload event is used to initialize everything which may not the best way to do so. Dean Edwards may have a solution: http://dean.edwards.name/weblog/2005/09/busted/ darcs-hash:20051015184404-7ad00-2404744d008e5ea7e1b5800c96800824b532ff47.gz --- inc/html.php | 28 ++------- inc/parser/xhtml.php | 10 +-- inc/template.php | 78 +++++++++++++---------- lib/images/toolbar/bold.png | Bin 479 -> 433 bytes lib/images/toolbar/chars.png | Bin 636 -> 594 bytes lib/images/toolbar/h1.png | Bin 429 -> 387 bytes lib/images/toolbar/h2.png | Bin 500 -> 453 bytes lib/images/toolbar/h3.png | Bin 501 -> 464 bytes lib/images/toolbar/h4.png | Bin 461 -> 429 bytes lib/images/toolbar/h5.png | Bin 478 -> 437 bytes lib/images/toolbar/hr.png | Bin 372 -> 329 bytes lib/images/toolbar/image.png | Bin 680 -> 594 bytes lib/images/toolbar/italic.png | Bin 363 -> 322 bytes lib/images/toolbar/link.png | Bin 574 -> 554 bytes lib/images/toolbar/linkextern.png | Bin 1138 -> 962 bytes lib/images/toolbar/mono.png | Bin 426 -> 385 bytes lib/images/toolbar/ol.png | Bin 435 -> 403 bytes lib/images/toolbar/sig.png | Bin 606 -> 569 bytes lib/images/toolbar/smiley.png | Bin 860 -> 730 bytes lib/images/toolbar/spellcheck.png | Bin 738 -> 709 bytes lib/images/toolbar/strike.png | Bin 450 -> 415 bytes lib/images/toolbar/ul.png | Bin 409 -> 383 bytes lib/images/toolbar/underline.png | Bin 405 -> 375 bytes lib/scripts/edit.js | 106 +++++++++++++++++++++++++++++++- lib/scripts/script.js | 126 +------------------------------------- lib/scripts/spellcheck.js | 8 +-- lib/tpl/default/design.css | 4 ++ 27 files changed, 172 insertions(+), 188 deletions(-) diff --git a/inc/html.php b/inc/html.php index d03815f00..b559b84bb 100644 --- a/inc/html.php +++ b/inc/html.php @@ -224,7 +224,7 @@ function html_btn($name,$id,$akey,$params,$method='get'){ $params['id'] = $id; } - $ret .= '
'; + $ret .= ''; reset($params); while (list($key, $val) = each($params)) { @@ -885,7 +885,7 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? ?> - + @@ -911,42 +911,26 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
- + - - + + : - +
- - diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 037bb24d6..73ef58767 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -503,7 +503,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['pre'] = ''; $link['suf'] = ''; } - $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; + $link['more'] = ''; $link['class'] = $class; $link['url'] = wl($id); $link['name'] = $name; @@ -545,7 +545,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['style'] = ''; $link['pre'] = ''; $link['suf'] = ''; - $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; + $link['more'] = ''; $link['class'] = $class; $link['url'] = $url; $link['name'] = $name; @@ -565,7 +565,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['target'] = $conf['target']['interwiki']; $link['pre'] = ''; $link['suf'] = ''; - $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; + $link['more'] = ''; $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); if ( !$isImage ) { @@ -703,7 +703,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['style'] = ''; $link['pre'] = ''; $link['suf'] = ''; - $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; + $link['more'] = ''; $link['target'] = $conf['target']['media']; $link['title'] = $this->_xmlEntities($src); @@ -746,7 +746,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['style'] = ''; $link['pre'] = ''; $link['suf'] = ''; - $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; + $link['more'] = ''; $link['target'] = $conf['target']['media']; $link['title'] = $this->_xmlEntities($src); diff --git a/inc/template.php b/inc/template.php index 8c84515c2..9d0d3ef9a 100644 --- a/inc/template.php +++ b/inc/template.php @@ -225,42 +225,55 @@ function tpl_metaheaders(){ ptln('',$it); - // add size control - ptln('',$it); // editing functions - if(($ACT=='edit' || $ACT=='preview') && $INFO['writable']){ - // load toolbar functions - ptln('',$it); + if($ACT=='edit' || $ACT=='preview'){ + // add size control + ptln('',$it); - // load spellchecker functions if wanted - if($conf['spellchecker']){ + if($INFO['writable']){ + // load toolbar functions ptln('',$it+2); - } + DOKU_BASE.'lib/scripts/edit.js">',$it); - ptln('',$it+2); + } + + ptln('',$it); } - ptln('',$it); } // plugin stylesheets and Scripts @@ -270,13 +283,12 @@ function tpl_metaheaders(){ /** * Print a link * - * Just builds a link but adds additional JavaScript needed for - * the unsaved data check needed in the edit form. + * Just builds a link. * * @author Andreas Gohr */ function tpl_link($url,$name,$more=''){ - print '$name"; } @@ -522,7 +534,7 @@ function tpl_searchform(){ global $lang; global $ACT; - print ''; + print ''; print ''; print ' */ function initToolbar(tbid,edid,tb){ + if(!document.getElementById) return; var toolbar = document.getElementById(tbid); var cnt = tb.length; for(i=0; i + */ +function summaryCheck(){ + var sum = document.getElementById('summary'); + if(sum.value == ''){ + sum.className='missing'; + }else{ + sum.className='edit'; + } +} + + +/** + * global variable for the locktimer + */ +var locktimerID; + +/** + * This starts a timer to remind the user of an expiring lock + * Accepts the delay in seconds and a text to display. + */ +function init_locktimer(delay,txt){ + txt = escapeQuotes(txt); + locktimerID = self.setTimeout("locktimer('"+txt+"')", delay*1000); +} + +/** + * This stops the timer and displays a message about the expiring lock + */ +function locktimer(txt){ + clearTimeout(locktimerID); + alert(txt); +} + + + diff --git a/lib/scripts/script.js b/lib/scripts/script.js index 490394dfb..44409c712 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -131,102 +131,16 @@ function hideLoadBar(){ } } -/** - * Checks if a summary was entered - if not the style is changed - * - * @author Andreas Gohr - */ -function summaryCheck(){ - if(document.getElementById){ - var sum = document.getElementById('summary'); - if(sum.value == ''){ - sum.className='missing'; - }else{ - sum.className='edit'; - } - } -} - -/** - * This function generates the actual toolbar buttons with localized text - * we use it to avoid creating the toolbar where javascript is not enabled - * @deprecated - */ -function formatButton(imageFile, speedTip, tagOpen, tagClose, sampleText, accessKey) { - speedTip=escapeQuotes(speedTip); - tagOpen=escapeQuotes(tagOpen); - tagClose=escapeQuotes(tagClose); - sampleText=escapeQuotes(sampleText); - - document.write(""); - - document.write("\""+"); - document.write(""); - return; -} - -/** - * This function generates the actual toolbar buttons with localized text - * we use it to avoid creating the toolbar where javascript is not enabled - * @deprecated - */ -function insertButton(imageFile, speedTip, value, accessKey) { - speedTip=escapeQuotes(speedTip); - value=escapeQuotes(value); - - document.write(""); - - document.write("\""+"); - document.write(""); - return; -} - -/** - * This adds a button for the MediaSelection Popup - * @deprecated - */ -function mediaButton(imageFile, speedTip, accessKey, namespace) { - speedTip=escapeQuotes(speedTip); - document.write(""); - document.write("\""+"); - document.write(""); - return; -} - /* * Insert the selected filename and close the window * * @see http://www.alexking.org/index.php?content=software/javascript/content.php */ function mediaSelect(file){ - insertAtCarret(opener.document.editform.wikitext,'{{'+file+'}}'); + opener.insertAtCarret('wikitext','{{'+file+'}}'); window.close(); } - /** * For the upload Dialog. Prefills the wikiname. */ @@ -274,42 +188,6 @@ function toggleToc() { } } - -/** - * global var used for not saved yet warning - */ -var textChanged = false; - -function svchk(){ - if(textChanged){ - return confirm(notSavedYet); - }else{ - return true; - } -} - -/** - * global variable for the locktimer - */ -var locktimerID; - -/** - * This starts a timer to remind the user of an expiring lock - * Accepts the delay in seconds and a text to display. - */ -function init_locktimer(delay,txt){ - txt = escapeQuotes(txt); - locktimerID = self.setTimeout("locktimer('"+txt+"')", delay*1000); -} - -/** - * This stops the timer and displays a message about the expiring lock - */ -function locktimer(txt){ - clearTimeout(locktimerID); - alert(txt); -} - /* * This sets a cookie by JavaScript * @@ -424,6 +302,8 @@ function fnt(id, e, evt) { * Add the edit window size controls */ function initSizeCtl(ctlid,edid){ + if(!document.getElementById) return; + var ctl = document.getElementById(ctlid); var textarea = document.getElementById(edid); diff --git a/lib/scripts/spellcheck.js b/lib/scripts/spellcheck.js index d47430c31..308b3dd1f 100644 --- a/lib/scripts/spellcheck.js +++ b/lib/scripts/spellcheck.js @@ -171,25 +171,25 @@ function ajax_spell_class(){ case 'stop': ajax_spell.buttonObj.onclick = function(){ ajax_spell.resume(); return false; }; ajax_spell.buttonObj.title = ajax_spell.txtStop; - ajax_spell.buttonObj.accesskey = ''; + ajax_spell.buttonObj.accessKey = ''; ajax_spell.imageObj.src = DOKU_BASE+'lib/images/toolbar/spellstop.png'; break; case 'noerr': ajax_spell.buttonObj.onclick = function(){ajax_spell.setState('start'); return false; }; ajax_spell.buttonObj.title = ajax_spell.txtNoErr; - ajax_spell.buttonObj.accesskey = ''; + ajax_spell.buttonObj.accessKey = ''; ajax_spell.imageObj.src = DOKU_BASE+'lib/images/toolbar/spellnoerr.png'; break; case 'run': ajax_spell.buttonObj.onclick = function(){return false;}; ajax_spell.buttonObj.title = ajax_spell.txtRun; - ajax_spell.buttonObj.accesskey = ''; + ajax_spell.buttonObj.accessKey = ''; ajax_spell.imageObj.src = DOKU_BASE+'lib/images/toolbar/spellwait.gif'; break; default: ajax_spell.buttonObj.onclick = function(){ ajax_spell.run(); return false; }; ajax_spell.buttonObj.title = ajax_spell.txtStart+' [ALT-K]'; - ajax_spell.buttonObj.accesskey = 'k'; + ajax_spell.buttonObj.accessKey = 'k'; ajax_spell.imageObj.src = DOKU_BASE+'lib/images/toolbar/spellcheck.png'; break; } diff --git a/lib/tpl/default/design.css b/lib/tpl/default/design.css index 7bc6085f2..7b84ea614 100644 --- a/lib/tpl/default/design.css +++ b/lib/tpl/default/design.css @@ -637,6 +637,10 @@ div.search_quickhits { opacity: 1; } +#sizectl img { + cursor: pointer; +} + /* ---- Admin --- */ div.acladmin label { -- cgit v1.2.3