Skip to content
Snippets Groups Projects
Commit 6392c3b6 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

simplify JavaScript loading

Ignore-this: 7637977e042ed8ba7e9e9097f9e9f03f

This patch removes the differences between the JavaScript loaded in
edit and view modes.

  * increases the amount of JavaScript that is loaded initially
  * decreases the number of requests
  * only one cache for all javascript
  * all javascript is available in view mode

The last point is the most important as it makes a lot of functionality
available to plugins working in the view mode. The discussion plugin
now can reuse the toolbar code for example.

Note: development is part of ICKE 2.0 project
      http://www.icke-projekt.de

darcs-hash:20090812194007-6e07b-c8a71dedf506065a95d8b84b55aafce67810236c.gz
parent 0071aa21
No related branches found
No related tags found
No related merge requests found
......@@ -33,13 +33,11 @@ if(!defined('SIMPLE_TEST')){
function js_out(){
global $conf;
global $lang;
$edit = (bool) $_REQUEST['edit']; // edit or preview mode?
$write = (bool) $_REQUEST['write']; // writable?
// The generated script depends on some dynamic options
$cache = getCacheName('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$edit.'x'.$write,'.js');
$cache = getCacheName('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.js');
// Array of needed files
// array of core files
$files = array(
DOKU_INC.'lib/scripts/helpers.js',
DOKU_INC.'lib/scripts/events.js',
......@@ -49,37 +47,33 @@ function js_out(){
DOKU_INC.'lib/scripts/ajax.js',
DOKU_INC.'lib/scripts/index.js',
DOKU_INC.'lib/scripts/drag.js',
);
if($edit){
if($write){
$files[] = DOKU_INC.'lib/scripts/textselection.js';
$files[] = DOKU_INC.'lib/scripts/toolbar.js';
$files[] = DOKU_INC.'lib/scripts/edit.js';
$files[] = DOKU_INC.'lib/scripts/linkwiz.js';
}
$files[] = DOKU_INC.'lib/scripts/media.js';
}
$files[] = DOKU_TPLINC.'script.js';
// get possible plugin scripts
$plugins = js_pluginscripts();
DOKU_INC.'lib/scripts/textselection.js',
DOKU_INC.'lib/scripts/toolbar.js',
DOKU_INC.'lib/scripts/edit.js',
DOKU_INC.'lib/scripts/linkwiz.js',
DOKU_INC.'lib/scripts/media.js',
DOKU_TPLINC.'script.js',
);
// add possible plugin scripts and userscript
$files = array_merge($files,js_pluginscripts());
$files[] = DOKU_CONF.'userscript.js';
// check cache age & handle conditional request
header('Cache-Control: public, max-age=3600');
header('Pragma: public');
if(js_cacheok($cache,array_merge($files,$plugins))){
if(js_cacheok($cache,$files)){
http_conditionalRequest(filemtime($cache));
if($conf['allowdebug']) header("X-CacheUsed: $cache");
// finally send output
if ($conf['gzip_output'] && http_gzip_valid($cache)) {
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
readfile($cache.".gz");
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
readfile($cache.".gz");
} else {
if (!http_sendfile($cache)) readfile($cache);
if (!http_sendfile($cache)) readfile($cache);
}
return;
} else {
http_conditionalRequest(time());
......@@ -92,18 +86,15 @@ function js_out(){
print "var DOKU_BASE = '".DOKU_BASE."';";
print "var DOKU_TPL = '".DOKU_TPL."';";
//FIXME: move thes into LANG
print "var alertText = '".js_escape($lang['qb_alert'])."';";
print "var notSavedYet = '".js_escape($lang['notsavedyet'])."';";
print "var reallyDel = '".js_escape($lang['del_confirm'])."';";
// load JS strings form plugins
$lang['js']['plugins'] = js_pluginstrings();
// load JS specific translations
$json = new JSON();
$lang['js']['plugins'] = js_pluginstrings();
echo 'LANG = '.$json->encode($lang['js']).";\n";
// load toolbar
require_once(DOKU_INC.'inc/toolbar.php');
toolbar_JSdefines('toolbar');
// load files
foreach($files as $file){
echo "\n\n/* XXXXXXXXXX begin of $file XXXXXXXXXX */\n\n";
......@@ -111,41 +102,15 @@ function js_out(){
echo "\n\n/* XXXXXXXXXX end of $file XXXXXXXXXX */\n\n";
}
// init stuff
js_runonstart("ajax_qsearch.init('qsearch__in','qsearch__out')");
js_runonstart("addEvent(document,'click',closePopups)");
js_runonstart('addTocToggle()');
if($edit){
// size controls
js_runonstart("initSizeCtl('size__ctl','wiki__text')");
if($write){
require_once(DOKU_INC.'inc/toolbar.php');
toolbar_JSdefines('toolbar');
js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)");
// add pageleave check
js_runonstart("initChangeCheck('".js_escape($lang['notsavedyet'])."')");
// add lock timer
js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
}
}
// load plugin scripts (suppress warnings for missing ones)
foreach($plugins as $plugin){
if (@file_exists($plugin)) {
echo "\n\n/* XXXXXXXXXX begin of $plugin XXXXXXXXXX */\n\n";
js_load($plugin);
echo "\n\n/* XXXXXXXXXX end of $plugin XXXXXXXXXX */\n\n";
}
}
// load user script
@readfile(DOKU_CONF.'userscript.js');
// add scroll event and tooltip rewriting
js_runonstart("initSizeCtl('size__ctl','wiki__text')");
js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)");
js_runonstart("initChangeCheck('".js_escape($lang['notsavedyet'])."')");
js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
js_runonstart('scrollToMarker()');
js_runonstart('focusMarker()');
......@@ -166,11 +131,11 @@ function js_out(){
// finally send output
if ($conf['gzip_output']) {
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
print gzencode($js,9,FORCE_GZIP);
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
print gzencode($js,9,FORCE_GZIP);
} else {
print $js;
print $js;
}
}
......
......@@ -341,9 +341,13 @@ function changeCheck(msg){
* JSnocheck class), add handlers to monitor changes
*
* Sets focus to the editbox as well
*
* @fixme this is old and crappy code. needs to be redone
*/
function initChangeCheck(msg){
if(!document.getElementById){ return false; }
var edit_text = document.getElementById('wiki__text');
if(!edit_text) return;
// add change check for links
var links = document.getElementsByTagName('a');
for(var i=0; i < links.length; i++){
......@@ -374,7 +378,6 @@ function initChangeCheck(msg){
btn_prev.onclick = function(){ textChanged = false; };
// add change memory setter
var edit_text = document.getElementById('wiki__text');
edit_text.onchange = function(){
textChanged = true; //global var
summaryCheck();
......
......@@ -17,9 +17,6 @@ if (clientPC.indexOf('opera')!=-1) {
var is_opera_seven = (window.opera && document.childNodes);
}
// prepare empty toolbar for checks by lazy plugins
var toolbar = '';
/**
* Handy shortcut to document.getElementById
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment