-
-
Save tobijibu/5706c14630c6317c2f25a36761d7df16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* DokuWiki Default Template 2012 | |
* | |
* @link http://dokuwiki.org/template | |
* @author Anika Henke <anika@selfthinker.org> | |
* @author Clarence Lee <clarencedglee@gmail.com> | |
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) | |
*/ | |
if (!defined('DOKU_INC')) die(); /* must be run from within DokuWiki */ | |
require_once(dirname(__FILE__).'/my_template.php'); | |
header('X-UA-Compatible: IE=edge,chrome=1'); | |
$hasSidebar = page_findnearest($conf['sidebar']); | |
$showSidebar = $hasSidebar && ($ACT=='show'); | |
?> | |
<?php | |
/** | |
* pjaxアクセスかどうかの判別をします。 | |
* pjaxでは各ページ共通となる情報を読込こまないことで通信データ量を減らします。 | |
* pjaxかどうかを判定し、pjaxでない場合のみhtmlヘッダーを表示させます。 | |
*/ | |
if ('true'!=$_SERVER['HTTP_X_PJAX']): | |
?> | |
<!DOCTYPE html> | |
<html lang="<?php echo $conf['lang'] ?>" dir="<?php echo $lang['direction'] ?>" class="no-js"> | |
<head> | |
<meta charset="utf-8" /> | |
<title><?php tpl_pagetitle() ?> [<?php echo strip_tags($conf['title']) ?>]</title> | |
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script> | |
<?php tpl_metaheaders() ?> | |
<meta name="viewport" content="width=device-width,initial-scale=1" /> | |
<?php echo tpl_favicon(array('favicon', 'mobile')) ?> | |
<?php tpl_includeFile('meta.html') ?> | |
</head> | |
<body> | |
<div id="dokuwiki__site"><div id="dokuwiki__top" class="site <?php echo tpl_classes(); ?> <?php | |
echo ($showSidebar) ? 'showSidebar' : ''; ?> <?php echo ($hasSidebar) ? 'hasSidebar' : ''; ?>"> | |
<?php | |
/** | |
* pjaxの対象範囲をdivで囲みます。 | |
* ページ毎に内容が変化する部分を囲む必要があるので、 | |
* 基本的にヘッダー、フッター以外のコンテンツを全て含めることになると思います。 | |
*/ | |
?> | |
<div id="pjax_container"> | |
<?php | |
/** | |
* pjax判定の終了 | |
*/ | |
?> | |
<?php endif; ?> | |
<?php include('tpl_header.php') ?> | |
<?php | |
/** | |
* jokuWiki Pluginの機能を使い、タイトルを更新する処理を設定します。 | |
*/ | |
?> | |
<div id='pjaxTitle' | |
data-jw='{ "jokuwiki" : "pjaxTitle", "data" : { "id" : "pjaxTitle", "title" : "<?php | |
$pjaxTitle=htmlentities(tpl_pagetitle($ID, true) . ' [' . strip_tags($conf['title']). ']'); | |
echo $pjaxTitle; | |
?>"}}' | |
class='pjaxTitle'></div> | |
<div class="wrapper group"> | |
<?php if($showSidebar): ?> | |
<!-- ********** ASIDE ********** --> | |
<div id="dokuwiki__aside"><div class="pad aside include group"> | |
<h3 class="toggle"><?php echo $lang['sidebar'] ?></h3> | |
<div class="content"><div class="group"> | |
<?php tpl_flush() ?> | |
<?php tpl_includeFile('sidebarheader.html') ?> | |
<?php tpl_include_page($conf['sidebar'], true, true) ?> | |
<?php tpl_includeFile('sidebarfooter.html') ?> | |
</div></div> | |
</div></div><!-- /aside --> | |
<?php endif; ?> | |
<!-- ********** CONTENT ********** --> | |
<div id="dokuwiki__content"><div class="pad group"> | |
<?php html_msgarea() ?> | |
<div class="pageId"><span><?php echo hsc($ID) ?></span></div> | |
<div class="page group"> | |
<?php tpl_flush() ?> | |
<?php tpl_includeFile('pageheader.html') ?> | |
<!-- wikipage start --> | |
<?php tpl_content() ?> | |
<!-- wikipage stop --> | |
<?php tpl_includeFile('pagefooter.html') ?> | |
</div> | |
<div class="docInfo"><?php tpl_pageinfo() ?></div> | |
<?php tpl_flush() ?> | |
</div></div><!-- /content --> | |
<hr class="a11y" /> | |
<!-- PAGE ACTIONS --> | |
<div id="dokuwiki__pagetools"> | |
<h3 class="a11y"><?php echo $lang['page_tools']; ?></h3> | |
<div class="tools"> | |
<ul> | |
<?php | |
$data = array( | |
'view' => 'main', | |
'items' => array( | |
'edit' => tpl_action('edit', true, 'li', true, '<span>', '</span>'), | |
'revert' => tpl_action('revert', true, 'li', true, '<span>', '</span>'), | |
'revisions' => tpl_action('revisions', true, 'li', true, '<span>', '</span>'), | |
'backlink' => tpl_action('backlink', true, 'li', true, '<span>', '</span>'), | |
'subscribe' => tpl_action('subscribe', true, 'li', true, '<span>', '</span>'), | |
'top' => tpl_action('top', true, 'li', true, '<span>', '</span>') | |
) | |
); | |
// the page tools can be amended through a custom plugin hook | |
$evt = new Doku_Event('TEMPLATE_PAGETOOLS_DISPLAY', $data); | |
if($evt->advise_before()){ | |
foreach($evt->data['items'] as $k => $html) echo $html; | |
} | |
$evt->advise_after(); | |
unset($data); | |
unset($evt); | |
?> | |
</ul> | |
</div> | |
</div> | |
</div><!-- /wrapper --> | |
<div class="no"><?php tpl_indexerWebBug() /* provide DokuWiki housekeeping, required in all templates */ ?></div> | |
<?php if ('true'!==$_SERVER['HTTP_X_PJAX']) : ?> | |
<?php | |
/** | |
* pjax対象範囲divの閉じタグです | |
*/ | |
?> | |
</div> | |
<?php include('tpl_footer.php') ?> | |
</div></div><!-- /site --> | |
<script src="<?php print DOKU_TPL . 'jquery.pjax.js'; ?>" defer></script> | |
<script src="<?php print DOKU_TPL . 'util.js'; ?>" defer></script> | |
<div id="screen__mode" class="no"></div><?php /* helper to detect CSS media query in script.js */ ?> | |
</body> | |
</html> | |
<?php endif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Jokuwiki - a tool for managing javascript widgets | |
* | |
* Jokuwiki is intended to provide a framework (initially for Dokuwiki) to | |
* 1) isolate widgets from having to deal with dependencies (widget declared before dependencies available) | |
* 2) handle a strict Content Security Policy (i.e. no inline scripts) | |
* 3) non-standard content loading techniques (e.g. pjax) | |
* | |
* For simplicity the PJax page initializaton plugin is appended below | |
*/ | |
var jokuwiki= | |
{ | |
widgets: [], /* contains a list of [widgetname]=initFunction */ | |
failcount: 0, /* limits frequent re-running after failures */ | |
urls: [], /* maintains a list of script URLs loaded or about to be loaded */ | |
iters: 0, /* track number of times worklist has been scanned */ | |
pjaxloads: 0, /* count of times jokuwiki has been initialised */ | |
attempts: 10, /* maximum number of attempts at runQueue per init invocation */ | |
maxPjax: 200, /* max number of consecutive pjax loads before a full page load */ | |
pjaxContainer: 'pjax_content', /* element ID used for pjax container (optional -see disablePjax below) */ | |
/** | |
* init should be called when the page is loaded or content injected | |
*/ | |
init: function () { | |
jokuwiki.iters=0; | |
jokuwiki.failcount=0; | |
jokuwiki.pjaxloads++; | |
jokuwiki.attempts=10; | |
jokuwiki.runQueue(); | |
}, | |
/** | |
* private method | |
* | |
* scans the DOM for widgets to invoke | |
* automatically reschedules itself for stuff which throws an exception | |
*/ | |
runQueue: function () { | |
if (jQuery.pjax && jokuwiki.pjaxloads>jokuwiki.maxPjax) { | |
jokuwiki.disablePjax(); | |
} | |
jokuwiki.iters++; | |
console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ") jokuwiki.runQueue iteration"); | |
var els=jQuery("[data-jw]"); | |
var success=false; | |
for(var i=0; i<els.length; i++) { | |
success=false; | |
try { | |
payload=jQuery.parseJSON(els[i].getAttribute('data-jw')); | |
jokuwiki.widgets[payload.jokuwiki](payload.data); | |
success=true; | |
} catch(e) { | |
jokuwiki.failcount++; | |
console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ") Error processing " + els[i].getAttribute('data-jw')); | |
} | |
console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ") still here - success = " + success); | |
if (success) { | |
/* our work here is done - remove from the list */ | |
console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ') removing' + els[i].id + ' from jokuwiki queue'); | |
els[i].removeAttribute('data-jw'); | |
} | |
} | |
if (jQuery("[data-jw]").length && --jokuwiki.attempts) { | |
/* try to process the failed ones later */ | |
console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ") scheduling for another go"); | |
setTimeout(jokuwiki.runQueue, 200 + Math.min(jokuwiki.iters*100,1000)); | |
} | |
}, | |
/** | |
* public method for creating mappings between widgetnames and initfunctions | |
* @param string widgetname - the 'name' attribute of the widget | |
* @param function handler - the function to call (with the data from the parsed json) to invoke | |
* @param string url - optional url to load (will only be loaded once) | |
*/ | |
register: function (widgetname, handler, url) { | |
if (url) { | |
jokuwiki.loadScript(url); | |
} | |
jokuwiki.widgets[widgetname]=handler; | |
}, | |
/** | |
* public method for deleting mappings between widgetnames and initfunctions | |
* @param string widgetname - the 'name' attribute of the widget | |
* | |
* Not really sure why this is here. | |
* Note that this does not remove any scripts which have been added | |
*/ | |
unregister: function (name) { /* removes mapping between names and initFunctions */ | |
delete jokuwiki.widgets[name]; | |
}, | |
/** | |
* public method for loading a script asynchnronously | |
* @param string url | |
* | |
* There are some issues with jQuery's getScript, notably | |
* it doesn't intrinsically prevent the same script being | |
* injected multiple times | |
*/ | |
loadScript: function (url) { | |
if (!jokuwiki.urls[url]) { | |
jokuwiki.urls[url]=1; | |
jQuery(document).ready(function () { | |
var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.src = url; | |
document.body.appendChild(script); | |
}); | |
} | |
}, | |
/** | |
* public method to allow full page loads/break pjax loading | |
* | |
*/ | |
disablePjax: function () { /* do a full page load occasionally to clean up leaks */ | |
try { | |
console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ') next page should be full reload'); | |
document.getElementById(jokuwiki.pjaxContainer).id='DoNotReload'; | |
} catch (e) { console.log('....or not');} | |
} | |
}; | |
// --------- initialize the jokuwiki ------- | |
/* for full page load */ | |
jQuery(document).ready(jokuwiki.init); | |
/* for pjax load */ | |
jQuery(document).on('pjax:success', jokuwiki.init); | |
/* -------- register handler to update title ---- */ | |
/* NB has no dependencies therefore run in its own try....catch */ | |
/* - if it doesn't work the first time then it aint gonna work! */ | |
jokuwiki.register('pjaxTitle', function(jw) { | |
try { | |
document.title=jw.title; | |
} catch (e) { | |
} | |
}); | |
/* ------------ add a widget -------- */ | |
/* | |
* jokuwiki.register('slideshow',function (jw) { | |
* var i = new fadeSlideShow(jw); | |
* }, 'res/fader.js'); | |
*/ | |
/* ------ consol.log hack ---------- */ | |
if (!window.console) console = {log: function() {}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment