merged branch alexandresalome/profiler-toolbar-position (PR #2114)

Commits
-------

132fbe3 [WebProfilerBundle] Merge position and css_position
defdb82 [WebProfilerBundle] Remove unused line
69a50ab [WebProfilerBundle] Add the posibility to specify position of toolbar

Discussion
----------

[WebProfilerBundle] Add the posibility to specify position of toolbar

I'm facing a project where everything is at the bottom of the page, positioned with CSS.

This PR adds the possibility to specify the position of the toolbar, with configuration :

    web_profiler:
        toolbar: true
        intercept_redirects: false
        css_position:        top

---------------------------------------------------------------------------

by stof at 2011/09/06 12:11:27 -0700

Looking at the code rendering the toolbar, there is already a ``position`` parameter used to display the toolbar on top in the profiler. Maybe we could look into reusing it instead of having a second one named ``css_position``.
But the phpdoc says ``bottom, normal, or null -- automatically guessed``. Using ``bottom`` will result in ``position: bottom`` in the CSS, which is broken. @fabpot is it simply a left-over of a previous version ?

---------------------------------------------------------------------------

by alexandresalome at 2011/09/16 00:56:11 -0700

I merged parameters and changed the documentation for 3 values : ```bottom, top or normal```.
This commit is contained in:
Fabien Potencier 2011-09-22 08:14:15 +02:00
commit 916e4b1363
6 changed files with 40 additions and 12 deletions

View File

@ -116,7 +116,7 @@ class ProfilerController extends ContainerAware
* Renders the Web Debug Toolbar.
*
* @param string $token The profiler token
* @param string $position The toolbar position (bottom, normal, or null -- automatically guessed)
* @param string $position The toolbar position (top, bottom, normal, or null -- use the configuration)
*
* @return Response A Response instance
*/
@ -141,7 +141,7 @@ class ProfilerController extends ContainerAware
}
if (null === $position) {
$position = false === strpos($this->container->get('request')->headers->get('user-agent'), 'Mobile') ? 'fixed' : 'absolute';
$position = $this->container->getParameter('web_profiler.debug_toolbar.position');
}
$url = null;

View File

@ -38,6 +38,13 @@ class Configuration implements ConfigurationInterface
->children()
->booleanNode('verbose')->defaultTrue()->end()
->booleanNode('toolbar')->defaultFalse()->end()
->scalarNode('position')
->defaultValue('bottom')
->validate()
->ifNotInArray(array('normal', 'bottom', 'top'))
->thenInvalid('The CSS position %s is not supported')
->end()
->end()
->booleanNode('intercept_redirects')->defaultFalse()->end()
->end()
;

View File

@ -54,7 +54,9 @@ class WebProfilerExtension extends Extension
} else {
$mode = WebDebugToolbarListener::ENABLED_MINIMAL;
}
$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
}
/**

View File

@ -37,12 +37,14 @@ class WebDebugToolbarListener
protected $templating;
protected $interceptRedirects;
protected $mode;
protected $position;
public function __construct(TwigEngine $templating, $interceptRedirects = false, $mode = self::ENABLED)
public function __construct(TwigEngine $templating, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom')
{
$this->templating = $templating;
$this->interceptRedirects = (Boolean) $interceptRedirects;
$this->mode = (integer) $mode;
$this->position = $position;
}
public function isVerbose()
@ -100,16 +102,26 @@ class WebDebugToolbarListener
protected function injectToolbar(Response $response)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$posrFunction = 'mb_strripos';
$posFunction = 'mb_stripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$posrFunction = 'strripos';
$posFunction = 'stripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
if (false !== $pos = $posrFunction($content, '</body>')) {
if ($this->position === 'bottom') {
$pos = $posrFunction($content, '</body>');
} else {
$pos = $posFunction($content, '<body');
if (false !== $pos) {
$pos = $posFunction($content, '>', $pos) + 1;
}
}
if (false !== $pos) {
$toolbar = "\n".str_replace("\n", '', $this->templating->render(
'WebProfilerBundle:Profiler:toolbar_js.html.twig',
array('token' => $response->headers->get('X-Debug-Token'))

View File

@ -14,6 +14,7 @@
<argument type="service" id="templating.engine.twig" />
<argument>%web_profiler.debug_toolbar.intercept_redirects%</argument>
<argument>%web_profiler.debug_toolbar.mode%</argument>
<argument>%web_profiler.debug_toolbar.position%</argument>
</service>
</services>
</container>

View File

@ -1,15 +1,21 @@
<!-- START of Symfony2 Web Debug Toolbar -->
{% if 'normal' != position %}
{% if position != 'normal' %}
<div style="clear: both; height: 80px;"></div>
{% endif %}
<div class="sf-toolbarreset"
{% if 'normal' != position %}
style="position: {{ position }};
{% if position != 'normal' %}
style="position: fixed;
background-color: #f7f7f7;
background-image: -moz-linear-gradient(-90deg, #e4e4e4, #ffffff);
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e4e4e4), to(#ffffff));
bottom: 0;
{% if position == 'bottom' %}
background-image: -moz-linear-gradient(-90deg, #e4e4e4, #ffffff);
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e4e4e4), to(#ffffff));
bottom: 0;
{% else %} {# top #}
background-image: -moz-linear-gradient(-90deg, #ffffff, #e4e4e4);
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ffffff), to(#e4e4e4));
top: 0;
{% endif %}
left:0;
margin:0;
padding: 0;