001/* 002 * Copyright 2012 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.github.gwtbootstrap.client.ui; 017 018import com.github.gwtbootstrap.client.ui.base.HoverBase; 019import com.github.gwtbootstrap.client.ui.constants.Placement; 020import com.github.gwtbootstrap.client.ui.constants.VisibilityChange; 021import com.google.gwt.dom.client.Element; 022 023//@formatter:off 024/** 025 * Popover that 026 * 027 * @since 2.0.4.0 028 * 029 * @author Dominik Mayer 030 * @author ohashi keisuke 031 * 032 * @see <a 033 * href="http://twitter.github.com/bootstrap/javascript.html#popovers">Bootstrap 034 * documentation</a> 035 * @see Tooltip 036 */ 037// @formatter:on 038public class Popover extends HoverBase { 039 040 private String content; 041 private String heading; 042 private boolean html = false; 043 044 /** 045 * Creates an empty Popover. 046 */ 047 public Popover() { 048 super(); 049 placement = Placement.RIGHT; 050 } 051 052 /** 053 * {@inheritDoc} 054 */ 055 public void setText(String content) { 056 this.content = content; 057 } 058 059 /** 060 * {@inheritDoc} 061 */ 062 public String getText() { 063 return this.content; 064 } 065 066 public void setHeading(String heading) { 067 this.heading = heading; 068 } 069 070 public String getHeading() { 071 return this.heading; 072 } 073 074 /** 075 * {@inheritDoc} 076 */ 077 @Override 078 public void reconfigure() { 079 080 removeDataIfExists(); 081 082 setDataAttribute(getWidget().getElement(), "original-title", heading); 083 084 setDataAttribute(getWidget().getElement(), "content", content); 085 086 configure(getWidget().getElement(), getAnimation(), getPlacement().get(), getTrigger().get(), getShowDelay(), 087 getHideDelay(), isHtml()); 088 } 089 090 /** 091 * {@inheritDoc} 092 */ 093 @Override 094 protected void changeVisibility(VisibilityChange visibilityChange) { 095 changeVisibility(getWidget().getElement(), visibilityChange.get()); 096 } 097 098 private native void configure(Element element, boolean animated, String placement, String trigger, int showDelay, 099 int hideDelay, boolean html) /*-{ 100 $wnd.jQuery(element).popover({ 101 animation : animated, 102 placement : placement, 103 html : html, 104 trigger : trigger, 105 delay : { 106 show : showDelay, 107 hide : hideDelay 108 } 109 }); 110 }-*/; 111 112 /** 113 * Change Visibility 114 * 115 * @param e 116 * target 117 * @param visibility 118 * please use VisibilityChange enum. 119 */ 120 public static native void changeVisibility(Element e, String visibility) /*-{ 121 $wnd.jQuery(e).popover(visibility); 122 }-*/; 123 124 @Override 125 protected String getDataName() { 126 return "popover"; 127 } 128 129 public boolean isHtml() { 130 return html; 131 } 132 133 public void setHtml(boolean html) { 134 this.html = html; 135 } 136 137 @Override 138 protected void removeDataIfExists(Element e, String dataName) { 139 doRemoveDataIfExists(e, dataName); 140 } 141 142 private native void doRemoveDataIfExists(Element e, String dataName) /*-{ 143 var element = $wnd.jQuery(e); 144 if(element.data(dataName)) { 145 element.popover('destroy'); 146 } 147 }-*/; 148}