merged branch alexandresalome/profiler-toolbar-position (PR #2114)
Commits -------132fbe3
[WebProfilerBundle] Merge position and css_positiondefdb82
[WebProfilerBundle] Remove unused line69a50ab
[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:
commit
916e4b1363
@ -116,7 +116,7 @@ class ProfilerController extends ContainerAware
|
|||||||
* Renders the Web Debug Toolbar.
|
* Renders the Web Debug Toolbar.
|
||||||
*
|
*
|
||||||
* @param string $token The profiler token
|
* @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
|
* @return Response A Response instance
|
||||||
*/
|
*/
|
||||||
@ -141,7 +141,7 @@ class ProfilerController extends ContainerAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null === $position) {
|
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;
|
$url = null;
|
||||||
|
@ -38,6 +38,13 @@ class Configuration implements ConfigurationInterface
|
|||||||
->children()
|
->children()
|
||||||
->booleanNode('verbose')->defaultTrue()->end()
|
->booleanNode('verbose')->defaultTrue()->end()
|
||||||
->booleanNode('toolbar')->defaultFalse()->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()
|
->booleanNode('intercept_redirects')->defaultFalse()->end()
|
||||||
->end()
|
->end()
|
||||||
;
|
;
|
||||||
|
@ -54,7 +54,9 @@ class WebProfilerExtension extends Extension
|
|||||||
} else {
|
} else {
|
||||||
$mode = WebDebugToolbarListener::ENABLED_MINIMAL;
|
$mode = WebDebugToolbarListener::ENABLED_MINIMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
|
$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
|
||||||
|
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,12 +37,14 @@ class WebDebugToolbarListener
|
|||||||
protected $templating;
|
protected $templating;
|
||||||
protected $interceptRedirects;
|
protected $interceptRedirects;
|
||||||
protected $mode;
|
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->templating = $templating;
|
||||||
$this->interceptRedirects = (Boolean) $interceptRedirects;
|
$this->interceptRedirects = (Boolean) $interceptRedirects;
|
||||||
$this->mode = (integer) $mode;
|
$this->mode = (integer) $mode;
|
||||||
|
$this->position = $position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isVerbose()
|
public function isVerbose()
|
||||||
@ -100,16 +102,26 @@ class WebDebugToolbarListener
|
|||||||
protected function injectToolbar(Response $response)
|
protected function injectToolbar(Response $response)
|
||||||
{
|
{
|
||||||
if (function_exists('mb_stripos')) {
|
if (function_exists('mb_stripos')) {
|
||||||
$posrFunction = 'mb_strripos';
|
$posrFunction = 'mb_strripos';
|
||||||
|
$posFunction = 'mb_stripos';
|
||||||
$substrFunction = 'mb_substr';
|
$substrFunction = 'mb_substr';
|
||||||
} else {
|
} else {
|
||||||
$posrFunction = 'strripos';
|
$posrFunction = 'strripos';
|
||||||
|
$posFunction = 'stripos';
|
||||||
$substrFunction = 'substr';
|
$substrFunction = 'substr';
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $response->getContent();
|
$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(
|
$toolbar = "\n".str_replace("\n", '', $this->templating->render(
|
||||||
'WebProfilerBundle:Profiler:toolbar_js.html.twig',
|
'WebProfilerBundle:Profiler:toolbar_js.html.twig',
|
||||||
array('token' => $response->headers->get('X-Debug-Token'))
|
array('token' => $response->headers->get('X-Debug-Token'))
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<argument type="service" id="templating.engine.twig" />
|
<argument type="service" id="templating.engine.twig" />
|
||||||
<argument>%web_profiler.debug_toolbar.intercept_redirects%</argument>
|
<argument>%web_profiler.debug_toolbar.intercept_redirects%</argument>
|
||||||
<argument>%web_profiler.debug_toolbar.mode%</argument>
|
<argument>%web_profiler.debug_toolbar.mode%</argument>
|
||||||
|
<argument>%web_profiler.debug_toolbar.position%</argument>
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
<!-- START of Symfony2 Web Debug Toolbar -->
|
<!-- START of Symfony2 Web Debug Toolbar -->
|
||||||
{% if 'normal' != position %}
|
{% if position != 'normal' %}
|
||||||
<div style="clear: both; height: 80px;"></div>
|
<div style="clear: both; height: 80px;"></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="sf-toolbarreset"
|
<div class="sf-toolbarreset"
|
||||||
{% if 'normal' != position %}
|
{% if position != 'normal' %}
|
||||||
style="position: {{ position }};
|
style="position: fixed;
|
||||||
background-color: #f7f7f7;
|
background-color: #f7f7f7;
|
||||||
background-image: -moz-linear-gradient(-90deg, #e4e4e4, #ffffff);
|
{% if position == 'bottom' %}
|
||||||
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e4e4e4), to(#ffffff));
|
background-image: -moz-linear-gradient(-90deg, #e4e4e4, #ffffff);
|
||||||
bottom: 0;
|
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;
|
left:0;
|
||||||
margin:0;
|
margin:0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
Reference in New Issue
Block a user