<?php if (!defined('PmWiki')) exit();

/*
  Copyright 2004-2018 Patrick R. Michaud (pmichaud@pobox.com)
  This file is jumpbox.php; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 
  as published by the Free Software Foundation.
  
  Contributions to this recipe were made by Dominique Faure and Petko Yotov
  
  Version 2015-10-02 - converted to work with PHP 5.5 
  Version 2018-06-07 - converted to work with PHP 7.2
*/

$FmtPV['$_UniqId_'] = '($GLOBALS["_UniqId_"] = uniqid("id"))';
$FmtPV['$_PrevId_'] = '$GLOBALS["_UniqId_"]';
$InputTags['jumpbox'] = array(
  'name' => 'n',
  ':html' =>
    "<form action='{$PageUrl}' method='get'>
     <select onchange='window.location.href=this.options[this.selectedIndex].value'
       \$InputSelectArgs class='inputbox' >\$InputSelectOptions</select>
     <input id='{\$_UniqId_}' type='submit' value='$[Jump to page]' class='inputbutton' />
     <script type='text/javascript'><!--
document.getElementById('{\$_PrevId_}').style.display = 'none';
//--></script></form>");

Markup('input-jumpbox', '<split',
  '/\\(:input\\s+jumpbox\\s.*?:\\)(?:\\s*\\(:input\\s+jumpbox\\s.*?:\\))*/i',
  "muJumpBox");

function muJumpBox($m) {
  extract($GLOBALS["MarkupToHTML"]);
  return InputSelect($pagename, 'jumpbox', $m[0]);
}