diff options
author | Andreas Gohr <andi@splitbrain.org> | 2005-10-15 20:44:04 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2005-10-15 20:44:04 +0200 |
commit | 5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63 (patch) | |
tree | c204ba3e934a2e64928d4d59395516b7c0bb881f /inc | |
parent | 20d062ca5220daf6606e2b1bcdd73d84eebafa45 (diff) | |
download | rpg-5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63.tar.gz rpg-5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63.tar.bz2 |
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
Diffstat (limited to 'inc')
-rw-r--r-- | inc/html.php | 28 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 10 | ||||
-rw-r--r-- | inc/template.php | 78 |
3 files changed, 56 insertions, 60 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 .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">'; + $ret .= '<form class="button" method="'.$method.'" action="'.$script.'">'; reset($params); while (list($key, $val) = each($params)) { @@ -885,7 +885,7 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? ?> - <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" onsubmit="return svchk()"> + <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"> <input type="hidden" name="id" value="<?php echo $ID?>" /> <input type="hidden" name="rev" value="<?php echo $REV?>" /> <input type="hidden" name="date" value="<?php echo $DATE?>" /> @@ -911,42 +911,26 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? <tr> <td colspan="3"> <div id="spell_result"></div> - <textarea name="wikitext" id="wikitext" <?php echo $ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" onkeyup="summaryCheck();" tabindex="1"><?php echo "\n".formText($text)?></textarea> + <textarea name="wikitext" id="wikitext" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea> </td> </tr> <tr id="wikieditbar"> <td> <?php if($wr){?> - <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" /> - <input class="button" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="5" /> + <input class="button" id="edbtn_save" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" tabindex="4" /> + <input class="button" id="edbtn_preview" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" tabindex="5" /> <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="5" /> <?php } ?> </td> <td> <?php if($wr){ ?> <?php echo $lang['summary']?>: - <input type="text" class="edit" name="summary" id="summary" size="50" onkeyup="summaryCheck();" value="<?php echo formText($SUM)?>" tabindex="2" /> + <input type="text" class="edit" name="summary" id="summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" /> <?php html_minoredit()?> <?php }?> </td> <td align="right"> <div id="sizectl"></div> - - <script language="javascript" type="text/javascript" charset="utf-8"> - //showSizeCtl(); - <?php if($wr){ ?> - init_locktimer(<?php echo $conf['locktime']-60?>,'<?php echo $lang['willexpire']?>'); - - //initToolbar('toolbar','wikitext',toolbar); - - //initialize spellchecker - <?php if($conf['spellchecker']){ ?> -// ajax_spell.init('<?php echo $lang['spell_start']?>','<?php echo $lang['spell_stop']?>','<?php echo $lang['spell_wait']?>','<?php echo $lang['spell_noerr']?>','<?php echo $lang['spell_nosug']?>','<?php echo $lang['spell_change']?>'); - <?php } ?> - - document.editform.wikitext.focus(); - <?php } ?> - </script> </td> </tr> </table> 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'] = '<span class="curid">'; $link['suf'] = '</span>'; } - $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('<script language="javascript" type="text/javascript" charset="utf-8" src="'. DOKU_BASE.'lib/scripts/domTT.js"></script>',$it); - // add size control - ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); - ptln("addEvent(window,'onload',function(){initSizeCtl('sizectl','wikitext')});",$it+2); - ptln('</script>',$it); // editing functions - if(($ACT=='edit' || $ACT=='preview') && $INFO['writable']){ - // load toolbar functions - ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. - DOKU_BASE.'lib/scripts/edit.js"></script>',$it); + if($ACT=='edit' || $ACT=='preview'){ + // add size control + ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); + ptln("addEvent(window,'onload',function(){initSizeCtl('sizectl','wikitext')});",$it+2); + ptln('</script>',$it); - // load spellchecker functions if wanted - if($conf['spellchecker']){ + if($INFO['writable']){ + // load toolbar functions ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. - DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it+2); - } + DOKU_BASE.'lib/scripts/edit.js"></script>',$it); - ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); - - // add toolbar - require_once(DOKU_INC.'inc/toolbar.php'); - toolbar_JSdefines('toolbar'); - ptln("addEvent(window,'onload',function(){initToolbar('toolbar','wikitext',toolbar);});",$it+2); - - // add spellchecker - if($conf['spellchecker']){ - //init here - ptln("addEvent(window,'onload',function(){ ajax_spell.init('".$lang['spell_start']."','". - $lang['spell_stop']."','". - $lang['spell_wait']."','". - $lang['spell_noerr']."','". - $lang['spell_nosug']."','". - $lang['spell_change']."'); });"); + // load spellchecker functions if wanted + if($conf['spellchecker']){ + ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. + DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it+2); + } + + ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); + + // add toolbar + require_once(DOKU_INC.'inc/toolbar.php'); + toolbar_JSdefines('toolbar'); + ptln("addEvent(window,'onload',function(){initToolbar('toolbar','wikitext',toolbar);});",$it+2); + + // add pageleave check + ptln("addEvent(window,'onload',function(){initChangeCheck('". + str_replace('\\\\n','\\n',addslashes($lang['notsavedyet']))."');});",$it); + + // add lock timer + ptln("addEvent(window,'onload',function(){init_locktimer(". + ($conf['locktime']-60).",'". + str_replace('\\\\n','\\n',addslashes($lang['willexpire']))."');});",$it); + + // add spellchecker + if($conf['spellchecker']){ + //init here + ptln("addEvent(window,'onload',function(){ ajax_spell.init('". + $lang['spell_start']."','". + $lang['spell_stop']."','". + $lang['spell_wait']."','". + $lang['spell_noerr']."','". + $lang['spell_nosug']."','". + $lang['spell_change']."'); });"); + } + ptln('</script>',$it); } - ptln('</script>',$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 <andi@splitbrain.org> */ function tpl_link($url,$name,$more=''){ - print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; + print '<a href="'.$url.'" '; if ($more) print ' '.$more; print ">$name</a>"; } @@ -522,7 +534,7 @@ function tpl_searchform(){ global $lang; global $ACT; - print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search" onsubmit="return svchk()">'; + print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search">'; print '<input type="hidden" name="do" value="search" />'; print '<input type="text" '; |