<?php

Yii::import('ext.bootstrap.widgets.TbButton');
/**
 * TbButton class file.
 * @author Ayman AL AZYZY 12/17/2012
 */

/**
 * Bootstrap button widget + tooltips .
 */
class FTbButton extends TbButton
    {

    // ayman update
    public $tooltips = false;

    /**
     * Initializes the widget.
     */
    public function init()
    {
        parent::init();
        // remove button class and give empty class for display as label 
        $this->htmlOptions['class'] = '';
        $this->htmlOptions['required'] = true;

        if (isset($this->htmlOptions['tooltips']))
        {
            $this->tooltips = $this->htmlOptions['tooltips'];
            if ($this->htmlOptions['tooltips'] == true)
            {
                $this->htmlOptions['data-trigger'] = 'manual';
            }
        }
    }

    /**
     * Runs the widget.
     */
    public function run()
    {
        parent::run();

        if ($this->htmlOptions['tooltips'] == true)
        {
?>
            <script type="text/javascript">
                // Display tooltips when mouse be over the label
                // Disapper tooltips when click mouse out tooltips 
//                $("a[rel=popover]")
//                .popover({
//                    template: '<div class="popover"   style="width:200px; " ><div class="arrow"  ></div><div class="popover-inner"   >'/*<h3 class="popover-title"></h3>*/+'<div class="popover-content" ><p></p></div></div></div>'
//                })
//                .mouseenter(function(e) {
//                    $(".popover").hide();
//                    $(this).popover('show');
//                }).css("text-decoration","none").css("margin-bottom","5px").css("hight","30px");
//
//                $("*:not(.popover-title)").mousedown(function(e){
//                    var par = $(e.target).parent();
//                    var b = par.hasClass('popover-inner');
//                    if (b){
//                    }else{
//                        $("a[rel=popover]").popover('hide');
//                    }
//                });


                $("a[rel=popover]")
                .popover({
                    template: '<div class="popover"   style="width:200px; " ><div class="arrow"  ></div><div class="popover-inner"   >'/*<h3 class="popover-title"></h3>*/+'<div class="popover-content" ><p></p></div></div></div>'
                })
                .mouseenter(function(e) {
                    $(".popover").hide();
                    $(this).popover('show');
                }).css("text-decoration","none").css("margin-bottom","5px").css("hight","30px");


$("a[rel=popover]").mouseout(function(e){
                    var par = $(e.target).parent();
                    var b = par.hasClass('popover-inner');
                    if (b){
                    }else{
                        $("a[rel=popover]").popover('hide');
                    }
                });
            </script>
<?php

        }
    }

    }
