Skip to content

Commit

Permalink
first go on unobstrusive javascript, new toolbar
Browse files Browse the repository at this point in the history
darcs-hash:20051008175404-7ad00-cd640de7660825b19d5e863cc8caf5467d59b055.gz
  • Loading branch information
splitbrain committed Oct 8, 2005
1 parent b73cc7d commit 20d062c
Show file tree
Hide file tree
Showing 40 changed files with 1,369 additions and 288 deletions.
615 changes: 615 additions & 0 deletions inc/JSON.php

Large diffs are not rendered by default.

55 changes: 8 additions & 47 deletions inc/html.php
Expand Up @@ -894,37 +894,12 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
<table style="width:99%">
<tr>
<td class="toolbar" colspan="2">
<div id="toolbar"></div>

<?php if($wr){?>
<script language="javascript" type="text/javascript" charset="utf-8">
<?php /* sets changed to true when previewed */?>
textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;

formatButton('bold.png','<?php echo $lang['qb_bold']?>','**','**','<?php echo $lang['qb_bold']?>','b');
formatButton('italic.png','<?php echo $lang['qb_italic']?>',"\/\/","\/\/",'<?php echo $lang['qb_italic']?>','i');
formatButton('underline.png','<?php echo $lang['qb_underl']?>','__','__','<?php echo $lang['qb_underl']?>','u');
formatButton('code.png','<?php echo $lang['qb_code']?>','\'\'','\'\'','<?php echo $lang['qb_code']?>','c');
formatButton('strike.png','<?php echo $lang['qb_strike']?>','&lt;del&gt;','&lt;\/del&gt;','<?php echo $lang['qb_strike']?>','d');

formatButton('fonth1.png','<?php echo $lang['qb_h1']?>','====== ',' ======\n','<?php echo $lang['qb_h1']?>','1');
formatButton('fonth2.png','<?php echo $lang['qb_h2']?>','===== ',' =====\n','<?php echo $lang['qb_h2']?>','2');
formatButton('fonth3.png','<?php echo $lang['qb_h3']?>','==== ',' ====\n','<?php echo $lang['qb_h3']?>','3');
formatButton('fonth4.png','<?php echo $lang['qb_h4']?>','=== ',' ===\n','<?php echo $lang['qb_h4']?>','4');
formatButton('fonth5.png','<?php echo $lang['qb_h5']?>','== ',' ==\n','<?php echo $lang['qb_h5']?>','5');

formatButton('link.png','<?php echo $lang['qb_link']?>','[[',']]','<?php echo $lang['qb_link']?>','l');
formatButton('extlink.png','<?php echo $lang['qb_extlink']?>','[[',']]','http://www.example.com|<?php echo $lang['qb_extlink']?>');

formatButton('list.png','<?php echo $lang['qb_ol']?>',' - ','\n','<?php echo $lang['qb_ol']?>');
formatButton('list_ul.png','<?php echo $lang['qb_ul']?>',' * ','\n','<?php echo $lang['qb_ul']?>');

insertButton('rule.png','<?php echo $lang['qb_hr']?>','----\n');
mediaButton('image.png','<?php echo $lang['qb_media']?>','m','<?php echo $INFO['namespace']?>');

<?php
if($conf['useacl'] && $_SERVER['REMOTE_USER']){
echo "insertButton('sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
}
?>
</script>
<span id="spell_action"></span>
<?php } ?>
Expand Down Expand Up @@ -955,14 +930,18 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
<?php }?>
</td>
<td align="right">
<div id="sizectl"></div>

<script language="javascript" type="text/javascript" charset="utf-8">
showSizeCtl();
//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']?>');
// 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();
Expand Down Expand Up @@ -1003,24 +982,6 @@ function html_minoredit(){
print '</label>';
}

/**
* prepares the signature string as configured in the config
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_signature(){
global $conf;
global $INFO;

$sig = $conf['signature'];
$sig = strftime($sig);
$sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
$sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
$sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
$sig = str_replace('@DATE@',date($conf['dformat']),$sig);
return addslashes($sig);
}

/**
* prints some debug info
*
Expand Down
3 changes: 3 additions & 0 deletions inc/lang/en/lang.php
Expand Up @@ -123,6 +123,9 @@
$lang['qb_ul'] = 'Unordered List Item';
$lang['qb_media'] = 'Add Images and other files';
$lang['qb_sig'] = 'Insert Signature';
$lang['qb_smileys'] = 'Smileys';
$lang['qb_chars'] = 'Special Chars';


$lang['del_confirm']= 'Delete this entry?';

Expand Down
44 changes: 39 additions & 5 deletions inc/template.php
Expand Up @@ -207,6 +207,7 @@ function tpl_metaheaders(){
ptln(" var alertText = '".str_replace('\\\\n','\\n',addslashes($lang['qb_alert']))."'",$it);
ptln(" var notSavedYet = '".str_replace('\\\\n','\\n',addslashes($lang['notsavedyet']))."'",$it);
ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it);

ptln('</script>',$it);

// load the default JavaScript files
Expand All @@ -217,18 +218,51 @@ function tpl_metaheaders(){
ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
DOKU_BASE.'lib/scripts/ajax.js"></script>',$it);

// load spellchecker script if wanted
if($conf['spellchecker'] && ($ACT=='edit' || $ACT=='preview')){
ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it);
}

// dom tool tip library, for insitu footnotes
ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
DOKU_BASE.'lib/scripts/domLib.js"></script>',$it);
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);

// 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 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);
}

// plugin stylesheets and Scripts
plugin_printCSSJS();
}
Expand Down
202 changes: 202 additions & 0 deletions inc/toolbar.php
@@ -0,0 +1,202 @@
<?php
/**
* Editing toolbar functions
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/

if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');

require_once(DOKU_INC.'inc/JSON.php');


/**
* Prepares and prints an JavaScript array with all toolbar buttons
*
* @todo add toolbar plugins
* @param string $varname Name of the JS variable to fill
* @author Andreas Gohr <andi@splitbrain.org>
*/
function toolbar_JSdefines($varname){
global $ID;
global $conf;
global $lang;

// build button array
$menu = array(
array(
'type' => 'format',
'title' => $lang['qb_bold'],
'icon' => 'bold.png',
'key' => 'b',
'open' => '**',
'close' => '**',
),
array(
'type' => 'format',
'title' => $lang['qb_italic'],
'icon' => 'italic.png',
'key' => 'i',
'open' => '//',
'close' => '//',
),
array(
'type' => 'format',
'title' => $lang['qb_underl'],
'icon' => 'underline.png',
'key' => 'u',
'open' => '__',
'close' => '__',
),
array(
'type' => 'format',
'title' => $lang['qb_code'],
'icon' => 'mono.png',
'key' => 'c',
'open' => "''",
'close' => "''",
),
array(
'type' => 'format',
'title' => $lang['qb_strike'],
'icon' => 'strike.png',
'key' => 'd',
'open' => '<del>',
'close' => '<del>',
),
array(
'type' => 'format',
'title' => $lang['qb_h1'],
'icon' => 'h1.png',
'key' => '1',
'open' => '====== ',
'close' => '======\n',
),
array(
'type' => 'format',
'title' => $lang['qb_h2'],
'icon' => 'h2.png',
'key' => '2',
'open' => '===== ',
'close' => '=====\n',
),
array(
'type' => 'format',
'title' => $lang['qb_h3'],
'icon' => 'h3.png',
'key' => '3',
'open' => '==== ',
'close' => '====\n',
),
array(
'type' => 'format',
'title' => $lang['qb_h4'],
'icon' => 'h4.png',
'key' => '4',
'open' => '=== ',
'close' => '===\n',
),
array(
'type' => 'format',
'title' => $lang['qb_h5'],
'icon' => 'h5.png',
'key' => '5',
'open' => '== ',
'close' => '==\n',
),
array(
'type' => 'format',
'title' => $lang['qb_link'],
'icon' => 'link.png',
'key' => 'l',
'open' => '[[',
'close' => ']]',
),
array(
'type' => 'format',
'title' => $lang['qb_extlink'],
'icon' => 'linkextern.png',
'open' => '[[',
'close' => ']]',
'sample' => 'http://example.com|'.$lang['qb_extlink'],
),
array(
'type' => 'format',
'title' => $lang['qb_ol'],
'icon' => 'ol.png',
'open' => ' - ',
'close' => '\n',
),
array(
'type' => 'format',
'title' => $lang['qb_ul'],
'icon' => 'ul.png',
'open' => ' * ',
'close' => '\n',
),
array(
'type' => 'insert',
'title' => $lang['qb_hr'],
'icon' => 'hr.png',
'insert' => '----\n',
),
array(
'type' => 'popup',
'title' => $lang['qb_media'],
'icon' => 'image.png',
'url' => DOKU_BASE.'lib/exe/media.php?ns='.getNS($ID),
'name' => 'mediaselect',
'options'=> 'width=600,height=320,left=70,top=50,scrollbars=yes,resizable=yes',
),
array(
'type' => 'picker',
'title' => $lang['qb_smileys'],
'icon' => 'smiley.png',
'list' => getSmileys(),
'icobase'=> 'smileys',
),
array(
'type' => 'picker',
'title' => $lang['qb_chars'],
'icon' => 'chars.png',
'list' => explode(' ','À à Á á Â â Ã ã Ä ä Ǎ ǎ Ă ă Å å Ā ā Ą ą Æ æ Ć ć Ç ç Č č Ĉ ĉ Ċ ċ Ð đ ð Ď ď È è É é Ê ê Ë ë Ě ě Ē ē Ė ė Ę ę Ģ ģ Ĝ ĝ Ğ ğ Ġ ġ Ĥ ĥ Ì ì Í í Î î Ï ï Ǐ ǐ Ī ī İ ı Į į Ĵ ĵ Ķ ķ Ĺ ĺ Ļ ļ Ľ ľ Ł ł Ŀ ŀ Ń ń Ñ ñ Ņ ņ Ň ň Ò ò Ó ó Ô ô Õ õ Ö ö Ǒ ǒ Ō ō Ő ő Ø ø Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ş ş Š š Ŝ ŝ Ţ ţ Ť ť Ù ù Ú ú Û û Ü ü Ǔ ǔ Ŭ ŭ Ū ū Ů ů ǖ ǘ ǚ ǜ Ų ų Ű ű Ŵ ŵ Ý ý Ÿ ÿ Ŷ ŷ Ź ź Ž ž Ż ż Þ þ ß Ħ ħ ¿ ¡ ¢ £ ¤ ¥ € ¦ § ª ¬ ¯ ° ± ÷ ‰ ¼ ½ ¾ ¹ ² ³ µ ¶ † ‡ · • º ∀ ∂ ∃ Ə ə ∅ ∇ ∈ ∉ ∋ ∏ ∑ ‾ − ∗ √ ∝ ∞ ∠ ∧ ∨ ∩ ∪ ∫ ∴ ∼ ≅ ≈ ≠ ≡ ≤ ≥ ⊂ ⊃ ⊄ ⊆ ⊇ ⊕ ⊗ ⊥ ⋅ ◊ ℘ ℑ ℜ ℵ ♠ ♣ ♥ ♦'),
),
);

// if logged in add sig button
if($conf['useacl'] && $_SERVER['REMOTE_USER']){
$menu[] = array(
'type' => 'insert',
'title' => $lang['qb_sig'],
'icon' => 'sig.png',
'key' => 'y',
'insert' => toolbar_signature(),
);
}

// use JSON to build the JavaScript array
$json = new JSON();
print "var $varname = ".$json->encode($menu).";\n";
}

/**
* prepares the signature string as configured in the config
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function toolbar_signature(){
global $conf;
global $INFO;

$sig = $conf['signature'];
$sig = strftime($sig);
$sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
$sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
$sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
$sig = str_replace('@DATE@',date($conf['dformat']),$sig);
return $sig;
}


//Setup VIM: ex: et ts=4 enc=utf-8 :
Binary file modified lib/images/toolbar/bold.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/chars.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed lib/images/toolbar/code.png
Binary file not shown.
Binary file removed lib/images/toolbar/empty.png
Binary file not shown.
Binary file removed lib/images/toolbar/extlink.png
Binary file not shown.
Binary file removed lib/images/toolbar/fonth1.png
Binary file not shown.
Binary file removed lib/images/toolbar/fonth2.png
Binary file not shown.
Binary file removed lib/images/toolbar/fonth3.png
Binary file not shown.
Binary file removed lib/images/toolbar/fonth4.png
Binary file not shown.
Binary file removed lib/images/toolbar/fonth5.png
Binary file not shown.
Binary file added lib/images/toolbar/h1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/h2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/h3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/h4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/h5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/hr.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/toolbar/image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/toolbar/italic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/toolbar/link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/linkextern.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed lib/images/toolbar/list.png
Binary file not shown.
Binary file removed lib/images/toolbar/list_ul.png
Binary file not shown.
Binary file added lib/images/toolbar/mono.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/toolbar/ol.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed lib/images/toolbar/rule.png
Binary file not shown.
Binary file modified lib/images/toolbar/sig.png
Binary file added lib/images/toolbar/smiley.png
Binary file modified lib/images/toolbar/spellcheck.png
Binary file modified lib/images/toolbar/strike.png
Binary file added lib/images/toolbar/ul.png
Binary file modified lib/images/toolbar/underline.png

0 comments on commit 20d062c

Please sign in to comment.