From 80c32d93d79d9ddbf73e881e319f27d559ee8513 Mon Sep 17 00:00:00 2001 From: Pavel Vlasov Date: Mon, 26 May 2014 21:25:17 -0400 Subject: [PATCH] Tooltip --- .../src/org/nasdanika/examples/bank/app/AppRoute.java | 8 +++++++- .../src/org/nasdanika/html/HTMLFactory.java | 11 +++++++++++ .../org/nasdanika/html/impl/DefaultHTMLFactory.java | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/org.nasdanika.examples.bank.app/src/org/nasdanika/examples/bank/app/AppRoute.java b/org.nasdanika.examples.bank.app/src/org/nasdanika/examples/bank/app/AppRoute.java index e5c7991c..8a03fb0f 100644 --- a/org.nasdanika.examples.bank.app/src/org/nasdanika/examples/bank/app/AppRoute.java +++ b/org.nasdanika.examples.bank.app/src/org/nasdanika/examples/bank/app/AppRoute.java @@ -185,7 +185,13 @@ public Action execute(WebContext context) throws Exception { // // body.content(inputGroup); - body.content(htmlFactory.label(Style.SUCCESS, "Life is good!")); + body.content( + htmlFactory.tooltip( + htmlFactory.label(Style.SUCCESS, "Life is good!").id("life_is_good"), + HTMLFactory.Placement.BOTTOM, + "A good life is even better!!!")); + body.content(htmlFactory.tag("script", "$('#life_is_good').tooltip({html:true});")); + body.content("

"); diff --git a/org.nasdanika.html/src/org/nasdanika/html/HTMLFactory.java b/org.nasdanika.html/src/org/nasdanika/html/HTMLFactory.java index d4dfd68a..ad76b329 100644 --- a/org.nasdanika.html/src/org/nasdanika/html/HTMLFactory.java +++ b/org.nasdanika.html/src/org/nasdanika/html/HTMLFactory.java @@ -152,6 +152,17 @@ enum Placement { LEFT, TOP, RIGHT, BOTTOM } */ > T popover(T element, Placement placement, String title, String text); + /** + * Adds tooltip to the element. + * This method does not initialize the tooltip, it shall be done through JavaScript $(selector).tooltip(); e.g. + * $('#my_button').tooltip(); + * @param element Element + * @param placement tooltip placement. + * @param text tooltip text + * @return + */ + > T tooltip(T element, Placement placement, String text); + enum Glyphicon { asterisk, plus, diff --git a/org.nasdanika.html/src/org/nasdanika/html/impl/DefaultHTMLFactory.java b/org.nasdanika.html/src/org/nasdanika/html/impl/DefaultHTMLFactory.java index db4ba1f1..8d470f3a 100644 --- a/org.nasdanika.html/src/org/nasdanika/html/impl/DefaultHTMLFactory.java +++ b/org.nasdanika.html/src/org/nasdanika/html/impl/DefaultHTMLFactory.java @@ -204,6 +204,16 @@ public > T popover(T element, Placement placement, String return element; } + + @Override + public > T tooltip(T element, Placement placement, String text) { + element + .attribute("data-toggle", "tooltip") + .attribute("title", text) + .attribute("data-placement", placement.name().toLowerCase()); + + return element; + } @Override public Tag input(InputType type, String name, String value, String id, String placeholder) {