Skip to content

Instantly share code, notes, and snippets.

@demonio
Last active March 14, 2016 15:59
Show Gist options
  • Save demonio/494e8e03a7e67ffe7fdb to your computer and use it in GitHub Desktop.
Save demonio/494e8e03a7e67ffe7fdb to your computer and use it in GitHub Desktop.
Kubar es una lib que añade una barra personalizable y modular a tu template con info relevante de tu aplicación.

Poner kubar.php en la carpeta libs y en el template lo siguiente:

<?php
/**
*/
class Kubar
{
public static $bar_bg = '#FE4747';
public static $menu_bg = '#00A1CB';
public static $td_border = '1px dotted #EEE';
public static $td_color = 'white';
public static $button_selected = '#FFFC19';
public static $icons = array(
'Config'=>'settings',
'Vars'=>'storage',
'Controller'=>'storage',
);
/**
*/
public static function css()
{
?>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
body { margin: 0; }
.kubar
{
background: <?=self::$bar_bg?>;
bottom: 0;
position: fixed;
width: 100%;
}
.kubar button
{
padding: 4px;
text-align: left;
white-space: nowrap;
}
.kubar button span { vertical-align: super; }
.kubar div
{
background: <?=self::$menu_bg?>;
position: absolute;
}
.kubar > div button
{
width: 100%;
}
.kubar td
{
border: <?=self::$td_border?>;
color: <?=self::$td_color?>;
padding: 8px;
}
.kubar .hide { display: none; }
</style>
<?php
}
/**
*/
public static function show()
{
self::css()?>
<div class="kubar">
<?php
$a['Config'] = Config::getAll();
$a['Vars'] = array('GET'=>$_GET, 'POST'=>$_POST, 'SESSION'=>$_SESSION);
$a['Controller'] = View::getVar();
self::menu($a)?>
</div>
<?self::jquery();
}
/**
*/
public static function jquery()
{
?>
<script>
if (typeof jQuery == 'undefined')
{
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
}
window.onload = function()
{
$('body').on('click', 'button', function()
{
$('.kubar button').css('background', '');
$(this).css('background', '<?=self::$button_selected?>');
var div = $(this).next('div');
$(this).siblings('div').not(div).addClass('hide');
$(div).children('div').addClass('hide');
$(div).toggleClass('hide');
var height = $(div).height();
var width = $(div).width();
var left = $(div).parents('div').width();
$(div).css({
'height':height+'px',
'left':left+'px',
'bottom':0,
'width':width+'px',
});
if (height>400)
{
$(div).css({
'height':'400px',
'overflow':'auto',
'width':'800px',
});
}
var div_first = $('.kubar > div').not('.hide');
var height_first = $(div_first).height();
$(div_first).css({
'left':0,
'bottom':'39px',
});
});
}
</script>
<?php
}
/**
*/
public static function menu($a)
{
$c = count($a);
$i = 1?>
<?foreach($a as $k=>$v):
if( is_array($v) ){
$icon = empty(self::$icons[$k]) ? 'keyboard_arrow_right' : self::$icons[$k];
?>
<button>
<i class="material-icons right"><?=$icon?></i>
<span><?=$k?></span>
</button>
<div class="hide">
<?if ( is_array($v) ) self::menu($v)?>
</div>
<?}else{
$v = is_object($v) ? '<pre>' . print_r($v, 1) . '</pre>' : $v;
if (!$v) $v = is_null($v) ? 'NULL' :'(empty)';
if ($i==1){?><table><?}?>
<tr>
<td><?=$k?></td>
<td><?=$v?></td>
</tr>
<?if ($i==$c){?></table><?}
++$i;
}
endforeach;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment