Popover Function – Twitter Bootstrap

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:

  1.   <div class="span4">
  2.     <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :class => 'form-vertical') do |f| %>
  3.     <fieldset class="well">
  4.       <div class="control-group">
  5.         <%= f.label :email, 'Email:' %>
  6.         <div class="controls">
  7.           <%= f.email_field :email %>
  8.         </div>
  9.       </div>
  10.       <div class="control-group">
  11.         <%= f.label :display_name, 'Display Name:' %>
  12.         <div class="controls">
  13.           <%= f.text_field :display_name %>
  14.         </div>
  15.       </div>
  16.       <div class="control-group">
  17.         <%= f.label :password, 'Password:' %>
  18.         <div class="controls">
  19.           <%= f.password_field :password %>
  20.         </div>
  21.       </div>
  22.       <div class="control-group">
  23.         <%= f.label :password_confirmation, 'Password Confirmation:'%>
  24.         <div class="controls">
  25.           <%= f.password_field :password_confirmation %>
  26.         </div>
  27.       </div>
  28.       <div class="control-group">
  29.         <%= f.submit "Sign up", :class => 'btn btn-success' %>
  30.       </div>
  31.     </fieldset>
  32.     <% end %>
  33.   </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.

One thought on “Popover Function – Twitter Bootstrap

  1. Pingback: Cameron Stitt

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.