Templating toggleButton() and getDivForSliderEffect()

Signed-off-by: Piyush Agrawal <poush12@gmail.com>
This commit is contained in:
Piyush Agrawal 2016-02-23 01:05:11 +05:30
parent 23b1337bdf
commit 2e64aec16e
4 changed files with 64 additions and 61 deletions

View File

@ -16,6 +16,7 @@ use stdClass;
use SqlParser\Utils\Error as ParserError;
use PMA\libraries\URL;
use PMA\libraries\Sanitize;
use PMA\libraries\Template;
if (! defined('PHPMYADMIN')) {
exit;
@ -2879,26 +2880,11 @@ class Util
*/
public static function getDivForSliderEffect($id = '', $message = '')
{
if ($GLOBALS['cfg']['InitialSlidersState'] == 'disabled') {
return '<div' . ($id ? ' id="' . $id . '"' : '') . '>';
}
/**
* Bad hack on the next line. document.write() conflicts with jQuery,
* hence, opening the <div> with PHP itself instead of JavaScript.
*
* @todo find a better solution that uses $.append(), the recommended
* method maybe by using an additional param, the id of the div to
* append to
*/
return '<div'
. ($id ? ' id="' . $id . '"' : '')
. (($GLOBALS['cfg']['InitialSlidersState'] == 'closed')
? ' style="display: none; overflow:auto;"'
: '')
. ' class="pma_auto_slider"'
. ($message ? ' title="' . htmlspecialchars($message) . '"' : '')
. '>';
return Template::get('getDivForSliderEffect')->render([
'id' => $id,
'InitialSlidersState' => $GLOBALS['cfg']['InitialSlidersState'],
'message' => $message,
]);
}
/**
@ -2928,42 +2914,19 @@ class Util
$state = 'on';
}
// Generate output
return "<!-- TOGGLE START -->\n"
. "<div class='wrapper toggleAjax hide'>\n"
. " <div class='toggleButton'>\n"
. " <div title='" . __('Click to toggle')
. "' class='container $state'>\n"
. " <img src='" . htmlspecialchars($GLOBALS['pmaThemeImage'])
. "toggle-" . htmlspecialchars($GLOBALS['text_dir']) . ".png'\n"
. " alt='' />\n"
. " <table class='nospacing nopadding'>\n"
. " <tbody>\n"
. " <tr>\n"
. " <td class='toggleOn'>\n"
. " <span class='hide'>$link_on</span>\n"
. " <div>"
. str_replace(' ', '&nbsp;', htmlspecialchars($options[1]['label']))
. "\n" . " </div>\n"
. " </td>\n"
. " <td><div>&nbsp;</div></td>\n"
. " <td class='toggleOff'>\n"
. " <span class='hide'>$link_off</span>\n"
. " <div>"
. str_replace(' ', '&nbsp;', htmlspecialchars($options[0]['label']))
. "\n" . " </div>\n"
. " </tr>\n"
. " </tbody>\n"
. " </table>\n"
. " <span class='hide callback'>"
. htmlspecialchars($callback) . "</span>\n"
. " <span class='hide text_direction'>"
. htmlspecialchars($GLOBALS['text_dir']) . "</span>\n"
. " </div>\n"
. " </div>\n"
. "</div>\n"
. "<!-- TOGGLE END -->";
return Template::get('toggleButton')->render(
[
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'link_on' => $link_on,
'toggleOn' => str_replace(' ', '&nbsp;', htmlspecialchars(
$options[1]['label'])),
'toggleOff' => str_replace(' ', '&nbsp;', htmlspecialchars(
$options[0]['label'])),
'link_off' => $link_off,
'callback' => $callback,
'state' => $state
]);
} // end toggleButton()
/**

View File

@ -0,0 +1,15 @@
<?php if($InitialSlidersState == 'disabled'): ?>
<div <?= $id? "id=\"$id\"": '' ?>>
<?php else: ?>
<?php /**
* Bad hack on the next line. document.write() conflicts with jQuery,
* hence, opening the <div> with PHP itself instead of JavaScript.
*
* @todo find a better solution that uses $.append(), the recommended
* method maybe by using an additional param, the id of the div to
* append to
*/ ?>
<div <?= $id? "id=\"$id\"": '' ?>
<?= ($InitialSlidersState == 'closed')? ' style="display: none; overflow:auto;"':'' ?> class="pma_auto_slider"
<?= $message? 'title="'. htmlspecialchars($message) . '"': ""?> >
<?php endif; ?>

View File

@ -0,0 +1,27 @@
<!-- TOGGLE START -->
<div class='wrapper toggleAjax hide'>
<div class='toggleButton'>
<div title=" <?= __('Click to toggle') ?>" class='container <?=$state?>'>
<img src="<?= htmlspecialchars($pmaThemeImage) ?>toggle-<?= htmlspecialchars($text_dir) ?>.png" alt='' />
<table class='nospacing nopadding'>
<tbody>
<tr>
<td class='toggleOn'>
<span class='hide'><?= $link_on ?></span>
<div><?= $toggleOn ?></div>
</td>
<td><div>&nbsp;</div></td>
<td class='toggleOff'>
<span class='hide'><?= $link_off ?></span>
<div><?= $toggleOff ?></div>
</td>
</tr>
</tbody>
</table>
<span class='hide callback'><?= htmlspecialchars($callback) ?></span>
<span class='hide text_direction'><?= $text_dir ?></span>
</div>
</div>
</div>
<!-- TOGGLE END -->

View File

@ -35,8 +35,7 @@ class PMA_GetDivForSliderEffectTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
PMA\libraries\Util::getDivForSliderEffect($id, $message),
'<div id="' . $id . '" class="pma_auto_slider" title="'
. htmlspecialchars($message) . '">'
"<div id=\"$id\" class=\"pma_auto_slider\"\ntitle=\"" . htmlspecialchars($message) . "\" >"
);
}
@ -55,8 +54,7 @@ class PMA_GetDivForSliderEffectTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
PMA\libraries\Util::getDivForSliderEffect($id, $message),
'<div id="' . $id . '" style="display: none; overflow:auto;" '
. 'class="pma_auto_slider" title="' . htmlspecialchars($message) . '">'
"<div id=\"$id\" style=\"display: none; overflow:auto;\" class=\"pma_auto_slider\"\ntitle=\"" . htmlspecialchars($message) . "\" >"
);
}
@ -76,7 +74,7 @@ class PMA_GetDivForSliderEffectTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
PMA\libraries\Util::getDivForSliderEffect($id, $message),
'<div id="' . $id . '">'
"<div id=\"$id\">"
);
}
}