Popover Function - Twitter Bootstrap

BootstrapGuidesjQueryRuby on RailsWeb Development

Just a quick post on how easy it is to implement a popover with twitter bootsrap:

JavaScript:

//Create tooltips for login/signup forms
function create_tooltips(){

    //Create vars
    var titles = ['test title']
    var contents = ['test content'];
    var fields = ['#user_email'];

    //Loop through each field and assign tooltip
    for(var i = 0; i < fields.length; i++){

        //Create vars
        var field = $(fields[i]);
        var title = titles[i];
        var content = contents[i];

        //Ensure field found
        if(field){

            //Create popover
            $(field).popover(
                {
                    animation: true,
                    placement: 'right',
                    selector: false,
                    trigger: 'hover',
                    title: title,
                    content: content,
                    delay: 0
                });
        }
    }
}

Form:

  <div class="span4">
     resource_name, :url => registration_path(resource_name), :class => 'form-vertical') do |f| %>
    
      <div class="control-group">
        
        <div class="controls">
          
        </div>
      </div>
      <div class="control-group">
        
        <div class="controls">
          
        </div>
      </div>
      <div class="control-group">
        
        <div class="controls">
          
        </div>
      </div>
      <div class="control-group">
        
        <div class="controls">
          
        </div>
      </div>
      <div class="control-group">
         'btn btn-success' %>
      </div>
    
    
  </div>

Result:

Popover - Twitter Bootstrap

Popover - Twitter Bootstrap

That’s all there is to it, if you haven’t had a chance to check it out yet make sure you head on over to the official site – there are some pretty neat features.

1 comment

Comments from the original blog are preserved here. New comments are closed.

  1. Cameron Stitt

    [...] friend of mine recently shared how he suggests to implement Popover functions using twitter bootstrap. I have a different way of doing this after [...]